From 74cfcf73a26f9d06151e8acb469b335937922e7e Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 21 Oct 2024 13:45:05 +0200 Subject: [PATCH 01/39] Add fix NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST to address issue 943 --- lib_com/options.h | 1 + lib_dec/ivas_stereo_dft_plc_fx.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 93908a861..5df2d052b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -187,6 +187,7 @@ #define FIX_918_WRONG_SCALING_ON_MODE_SWITCHING /* VA: Fix wrong scaling of secondary channel when switching from stereo DFT to TD */ #define FIX_924_IGF_ROUNDFX_SAT #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ +#define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index f6551e090..a8bb5a6e6 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -83,6 +83,9 @@ void stereo_dft_res_ecu_fx( Word16 trigo_dec[STEREO_DFT32MS_N_8k / 2 + 1]; Word16 trigo_step; Word16 q_fac; +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + Word16 time_offs; +#endif set32_fx( pDFT_RES, 0, L_FRAME8k ); @@ -122,7 +125,12 @@ void stereo_dft_res_ecu_fx( IF( k == 0 ) { Copy32( pDFT_RES, res_buf, L_FRAME8k ); /* hStereoDft->q_dft */ +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + time_offs = add_sat( hStereoDft->time_offs, output_frame ); + stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, time_offs, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#else stereo_dft_res_subst_spec_fx( hStereoDft, res_buf, DFT_PRED_RES, hStereoDft->time_offs + output_frame, L_res, L_FRAME8k, k, num_plocs, plocs, plocsi, FALSE ); +#endif rfft_fx( res_buf, trigo_dec, L_FRAME8k, +1 ); @@ -162,7 +170,11 @@ void stereo_dft_res_ecu_fx( } /*in case of burst error*/ +#ifdef NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST + hStereoDft->time_offs = add_sat( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#else hStereoDft->time_offs = add( hStereoDft->time_offs, L_FRAME8k ); /* Q0 */ +#endif move16(); } -- GitLab From 9fce618c817ee978d9e9986f002d324f0a412994 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 10:53:01 +0530 Subject: [PATCH 02/39] Q info addition for decoder and renderer files - 1 --- lib_com/prot_fx.h | 183 ++++---- lib_dec/dec_pit_exc_fx.c | 25 +- lib_dec/dec_post_fx.c | 278 ++++++------ lib_dec/dec_ppp_fx.c | 2 +- lib_dec/dec_prm_fx.c | 579 +++++++++++++----------- lib_dec/dec_tcx_fx.c | 187 ++++---- lib_dec/decision_matrix_dec_fx.c | 93 ++-- lib_dec/gs_dec_amr_wb_fx.c | 184 ++++---- lib_dec/gs_dec_fx.c | 398 ++++++++-------- lib_dec/hdecnrm_fx.c | 162 +++---- lib_dec/ivas_stereo_dft_dec_fx.c | 4 +- lib_dec/stat_dec.h | 2 +- lib_rend/ivas_prot_rend.h | 56 +-- lib_rend/ivas_reverb_delay_line.c | 60 +-- lib_rend/ivas_reverb_fft_filter.c | 117 ++--- lib_rend/ivas_rom_binaural_crend_head.c | 4 +- lib_rend/ivas_rom_rend.c | 10 +- 17 files changed, 1207 insertions(+), 1137 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 20a851b29..1a1b8a81a 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -827,7 +827,7 @@ void compute_poly_product_fx( Word16 *coef, Word32 *p, Word16 order ); void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ); void msvq_dec( const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) (0Q15) */ @@ -6358,9 +6358,9 @@ void TonalMDCTConceal_SaveTimeSignal( // 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 */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ); // hf_synth_fx.c @@ -6627,60 +6627,60 @@ void PulseResynchronization_fx( // 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 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + 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*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , 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 */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , 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_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ); 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 */ + Decoder_State *st_fx, /* i/o: State structure */ + Word16 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ 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 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ); void GSC_dec_init( @@ -7647,8 +7647,8 @@ void dequantize_norms_fx( // 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 */ + const Word16 numNorms, /* (i) number of norms Q0*/ + Word16 *index ); /* (o) indices of quantized norms Q0*/ Word16 decode_huff_context_fx( @@ -7658,31 +7658,32 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ); + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +); 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 */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ); 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 */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ); 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 Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ); #endif @@ -8129,24 +8130,24 @@ void music_postfilt_init( // 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 clas, /* i : signal frame class Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -8715,13 +8716,13 @@ 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 ); + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ); void dec_prm_fx( Word16 *coder_type, Word16 param[], /* (o) : decoded parameters */ @@ -8732,11 +8733,11 @@ void dec_prm_fx( Word16 *bitsRead ); void getLPCparam_fx( - Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ - Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + Decoder_State *st, /* i/o: decoder memory state */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ + Decoder_State *st0, /* i : bitstream */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ); // ari_hm_fx.c diff --git a/lib_dec/dec_pit_exc_fx.c b/lib_dec/dec_pit_exc_fx.c index 3328839ea..d04dc1b30 100644 --- a/lib_dec/dec_pit_exc_fx.c +++ b/lib_dec/dec_pit_exc_fx.c @@ -21,7 +21,7 @@ /*--------------------------------------------------------------------------*/ /* OUTPUT ARGUMENTS : */ /* _ (Word16*) pitch_buf_fx : floating pitch values for each subframe Q6 */ -/* _ (Word16*) code_fx : innovation */ +/* _ (Word16*) code_fx : innovation Q12 */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* Decoder_State_fx *st_fx : decoder state structure */ @@ -80,6 +80,7 @@ void dec_pit_exc_fx( Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif use_fcb = 0; @@ -269,7 +270,7 @@ 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[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), 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*/ @@ -285,8 +286,8 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_tmp ); /*Q_exc*/ + 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*/ @@ -300,7 +301,7 @@ void dec_pit_exc_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( 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 @@ -695,7 +696,7 @@ void dec_pit_exc_ivas_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 /*0.5.Q15*/ ), 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*/ #endif @@ -704,7 +705,7 @@ void dec_pit_exc_ivas_fx( /*----------------------------------------------------------------------* * Find the total excitation *----------------------------------------------------------------------*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[( i_subfr_fx * ( 2 * HIBND_ACB_L_FAC ) ) / 2], hGSCDec->last_exc_dct_in_fx, L_subfr_fx, shr( imult1616( L_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 ), 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*/ @@ -726,8 +727,8 @@ void dec_pit_exc_ivas_fx( { FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[add( i, i_subfr_fx )] ), 1 ); /*Q16+Q_exc*/ - exc_fx[add( 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*/ move16(); } } @@ -737,8 +738,8 @@ void dec_pit_exc_ivas_fx( FOR( i = 0; i < L_subfr_fx; i++ ) { - L_tmp = L_mult( gain_pitx2, exc_fx[add( i, i_subfr_fx )] ); /*Q16+Q_exc*/ - exc_fx[add( 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*/ move16(); } } @@ -859,7 +860,7 @@ void dec_pit_exc_ivas_fx( p_Aq_fx += 4 * ( M + 1 ); /* update gains for FEC - equivalent to lp_gain_updt() */ - st_fx->lp_gainp_fx = gain_pit_fx; + st_fx->lp_gainp_fx = gain_pit_fx; // Q14 move16(); st_fx->lp_gainc_fx = 0; move16(); diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 977146b34..296b5cef7 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -103,7 +103,7 @@ void nb_post_filt_fx( /* update long-term background noise energy during inactive frames */ 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 /*0.95.Q15*/, *psf_lp_noise ), 26214 /*0.05 Q19*/, shl( tmp_noise, 4 ) ) ); /*Q8*Q15 + Q19*Q4 -> Q8 */ } } @@ -112,17 +112,17 @@ void nb_post_filt_fx( 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_pf_in, L_SYN_MEM ); // Qsyn Copy( &Synth[L_frame - L_SYN_MEM], hPFstat->mem_stp, L_SYN_MEM ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); hPFstat->reset = 0; move16(); return; } Pf_in = &pf_in_buffer[M]; - Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); - Copy( Synth, Pf_in, L_frame ); + Copy( hPFstat->mem_pf_in + L_SYN_MEM - M, &Pf_in[-M], M ); // Qsyn + Copy( Synth, Pf_in, L_frame ); // Qsyn 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 ) ) @@ -137,13 +137,13 @@ void nb_post_filt_fx( /* run the post filter */ - p_Aq = Aq; + p_Aq = Aq; // Q12 move16(); j = 0; move16(); FOR( i = 0; i < L_frame; i += L_SUBFR ) { - T0_first = Pitch_buf[j]; + T0_first = Pitch_buf[j]; // Q6 move16(); Dec_postfilt_fx( hPFstat, T0_first, &Pf_in[i], p_Aq, &Synth[i], Post_G1, Post_G2, Gain_factor, disable_hpf ); @@ -180,26 +180,26 @@ void nb_post_filt_fx( *----------------------------------------------------------------------------*/ 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 t0, /* i : pitch delay given by coder Q6 */ + const Word16 *signal_ptr, /* i : input signal (pointer to current subframe Q0 */ + const Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ + Word16 *sig_out, /* o : postfiltered output Q15*/ + const Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + const Word16 gamma2, /* i : short term postfilt. num. weighting factor Q15*/ 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 apond2[LONG_H_ST]; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 Word16 sig_ltp[L_SUBFR + 1]; /* H0 output signal */ - Word16 res2[SIZ_RES2]; + Word16 res2[SIZ_RES2]; // Q0 Word16 *sig_ltp_ptr; Word16 *res2_ptr; Word16 *ptr_mem_stp; - Word16 parcor0; + Word16 parcor0; // Q15 /* Init pointers and restore memories */ @@ -259,7 +259,7 @@ static void Dec_postfilt_fx( 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 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -269,7 +269,7 @@ void formant_post_filt_fx( { Word16 i_subfr; Word16 *p_Aq; - Word16 post_G1, post_G2; + Word16 post_G1, post_G2; // Q15 /*default parameter for noisy speech and high bit-rates*/ @@ -351,7 +351,7 @@ void formant_post_filt_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -361,7 +361,7 @@ void formant_post_filt_fx( 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 ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -373,7 +373,7 @@ void formant_post_filt_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 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 ); @@ -385,7 +385,7 @@ void formant_post_filt_fx( 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 *Aq, /* i : LP filter coefficient Q12 */ Word16 *synth_out, /* i/o: input signal */ Word16 L_frame, Word32 lp_noise, /* (i) : background noise energy (15Q16) */ @@ -477,7 +477,7 @@ void formant_post_filt_ivas_fx( } /* Reset post filter */ - if ( hPFstat->reset != 0 ) + IF( hPFstat->reset != 0 ) { post_G1 = MAX16B; move16(); @@ -487,7 +487,7 @@ void formant_post_filt_ivas_fx( 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 ); - hPFstat->gain_prec = 16384; + hPFstat->gain_prec = 16384; // 1.Q14 move16(); Copy( synth_in, synth_out, L_frame ); @@ -499,7 +499,7 @@ void formant_post_filt_ivas_fx( Copy( &synth_in[L_frame - L_SYN_MEM], hPFstat->mem_pf_in, L_SYN_MEM ); move16(); - p_Aq = Aq; + p_Aq = Aq; // Q12 FOR( i_subfr = 0; i_subfr < L_frame; i_subfr += L_SUBFR ) { Dec_formant_postfilt_ivas_fx( hPFstat, &synth_in[i_subfr], p_Aq, &synth_out[i_subfr], post_G1, post_G2 ); @@ -524,19 +524,19 @@ void formant_post_filt_ivas_fx( *----------------------------------------------------------------------------*/ 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 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -545,14 +545,14 @@ static void Dec_formant_postfilt_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -604,19 +604,19 @@ 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 *signal_ptr, /* i : input signal (pointer to current subframe Q14*/ + Word16 *coeff, /* i : LPC coefficients for current subframe Q12 */ Word16 *sig_out, /* o : postfiltered output */ - Word16 gamma1, /* i : short term postfilt. den. weighting factor*/ - Word16 gamma2 /* i : short term postfilt. num. weighting factor*/ + Word16 gamma1, /* i : short term postfilt. den. weighting factor Q15*/ + Word16 gamma2 /* i : short term postfilt. num. weighting factor Q15*/ ) { /* Local variables and arrays */ - Word16 apond1[M + 1]; /* s.t. denominator coeff. */ - Word16 apond2[LONG_H_ST]; - Word16 res2[L_SUBFR]; - Word16 resynth[L_SUBFR + 1]; - Word16 parcor0; + Word16 apond1[M + 1]; /* s.t. denominator coeff. Q12*/ + Word16 apond2[LONG_H_ST]; // Q12 + Word16 res2[L_SUBFR]; // Q14 + Word16 resynth[L_SUBFR + 1]; // Qy + Word16 parcor0; // Q15 Word16 i, max; Word16 scale_down; @@ -625,14 +625,14 @@ static void Dec_formant_postfilt_ivas_fx( weight_a_fx( coeff, apond2, gamma2, M ); set16_fx( &apond2[M + 1], 0, LONG_H_ST - ( M + 1 ) ); - max = abs_s( signal_ptr[0] ); + max = abs_s( signal_ptr[0] ); // Q14 FOR( i = 1; i < L_SUBFR; i++ ) { max = s_max( max, abs_s( signal_ptr[i] ) ); } scale_down = 0; move16(); - if ( GT_16( max, 16384 ) ) + if ( GT_16( max, 16384 /*1.Q14*/ ) ) { scale_down = 1; move16(); @@ -693,7 +693,7 @@ static void modify_pst_param_fx( 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 *gain_factor /* o : Gain factor applied in post filtering Q15 */ ) { Word16 tmp; @@ -758,9 +758,9 @@ 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 t0, /* i : pitch delay given by coder Q6 */ + Word16 *ptr_sig_in, /* i : postfilter i filter (residu2) Qx */ + Word16 *ptr_sig_pst0, /* o : harmonic postfilter o Qx */ Word16 gain_factor /* i : Gain Factor (Q15) */ ) { @@ -790,8 +790,8 @@ static void pst_ltp_fx( /* i signal justified on 13 bits */ - ptr_sig = ptr_sig_in - DECMEM_RES2; - nb_sh_sig = getScaleFactor16( ptr_sig, add( DECMEM_RES2, L_SUBFR ) ); + ptr_sig = ptr_sig_in - DECMEM_RES2; // Qx + nb_sh_sig = getScaleFactor16( ptr_sig, DECMEM_RES2 + L_SUBFR ); nb_sh_sig = sub( 3, nb_sh_sig ); FOR( i = 0; i < DECMEM_RES2 + L_SUBFR; i++ ) @@ -814,7 +814,7 @@ static void pst_ltp_fx( { IF( phase == 0 ) { - ptr_y_up = ptr_sig_in - ltpdel; + ptr_y_up = ptr_sig_in - ltpdel; // Qx } ELSE { @@ -890,7 +890,7 @@ static void pst_ltp_fx( /* 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 ); // Q15 #else gain_plt = msu_r( L_msu( L_deposit_h( gain_plt ), gain_plt, gain_factor ), -32768, gain_factor ); #endif @@ -906,12 +906,12 @@ 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 t0, /* i : pitch delay given by coder Q0 */ 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 *num_gltp, /* o : 16 bits numerator of LTP gain Q(sh_num_gltp) */ + Word16 *den_gltp, /* o : 16 bits denominator of LTP gain Q(sh_den_gltp) */ 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 */ @@ -933,10 +933,10 @@ static void search_del_fx( Word16 *ptr1, *ptr_y_up; Word16 i, n; - Word16 num, den0, den1; + Word16 num /*Q(sh_num)*/, den0 /*Q(sh_den)*/, den1 /*Q(sh_den)*/; Word16 den_max, num_max; Word32 L_numsq_max; - Word16 ener; + Word16 ener; // Q(sh_ener) Word16 sh_num, sh_den, sh_ener; Word16 i_max, lambda, phi, phi_max, ioff; Word16 temp; @@ -1320,7 +1320,7 @@ static void search_del_fx( } ELSE { - if ( temp > 0 ) + IF( temp > 0 ) { L_temp1 = L_shr( L_temp1, temp ); } @@ -1365,10 +1365,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 Qx */ + Word16 *s_ltp, /* i : filtered signal with gain 1 Qx*/ + Word16 *s_out, /* o : signal Qx */ + Word16 gain_plt /* i : filter gain Q15 */ ) { @@ -1379,15 +1379,15 @@ 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 ); // Q15 + gain_plt_1 = add( gain_plt_1, 1 ); /* 2**15 (1 - g) */ 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] ); - move16(); /* no overflow */ + L_acc = L_mult( gain_plt, s_in[n] ); // Qx + Q15 + 1 + s_out[n] = mac_r( L_acc, gain_plt_1, s_ltp[n] ); // Qx + move16(); /* no overflow */ } @@ -1406,8 +1406,8 @@ static void compute_ltp_l_fx( 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 *num, /* i : numerator of LTP gain Q(sh_num) */ + Word16 *den, /* i : denominator of LTP gain Q(sh_den) */ Word16 *sh_num, /* i : justification factor of num */ Word16 *sh_den /* i : justification factor of den */ ) @@ -1420,7 +1420,7 @@ static void compute_ltp_l_fx( temp = sub( phase, 1 ); temp = shl( temp, L2_LH2_L ); - ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ + ptr_h = tab_hup_l_fx + temp; /* tab_hup_l_fx + LH2_L * (phase-1) */ // Q15 temp = sub( LH_UP_L, ltpdel ); ptr2 = s_in + temp; @@ -1459,6 +1459,7 @@ static void compute_ltp_l_fx( *num = extract_l( L_acc ); *sh_num = temp; move16(); + move16(); } /* Compute den */ @@ -1477,6 +1478,7 @@ static void compute_ltp_l_fx( *den = extract_l( L_acc ); *sh_den = temp; move16(); + move16(); return; @@ -1490,12 +1492,12 @@ static void compute_ltp_l_fx( * 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 num1, /* i : numerator of gain1 Q(sh_num1) */ + Word16 den1, /* i : denominator of gain1 Q(sh_den1) */ 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 num2, /* i : numerator of gain2 Q(sh_num2) */ + Word16 den2, /* i : denominator of gain2 Q(sh_den2) */ Word16 sh_num2, /* i : just. factor for num2 */ Word16 sh_den2 /* i : just. factor for den2 */ ) @@ -1506,7 +1508,7 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain Word16 temp1, temp2; - if ( den2 == 0 ) + IF( den2 == 0 ) { return 1; } @@ -1526,11 +1528,11 @@ static Word16 select_ltp_fx( /* o : 1 = 1st gain, 2 = 2nd gain temp2 = add( temp2, sh_den1 ); temp2 = sub( temp2, temp1 ); - if ( temp2 > 0 ) + IF( 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 */ } @@ -1555,10 +1557,10 @@ 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 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15*/ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx */ Word16 *mem_zero /* i : All zero memory */ ) { @@ -1579,20 +1581,20 @@ static void calc_st_filt_local_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 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] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ 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 ); // Qx move16(); } } @@ -1603,17 +1605,17 @@ 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 *apond2, /* i : coefficients of numerator Q12 */ + Word16 *apond1, /* i : coefficients of denominator Q12 */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter Q15 */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 Qx*/ Word16 *mem_zero, /* i : All zero memory */ const Word16 extl /* i : extension layer info */ ) { Word32 L_g0; - Word16 h[LONG_H_ST]; + Word16 h[LONG_H_ST]; // Q12 Word16 g0, temp; Word16 i; @@ -1635,20 +1637,20 @@ static void calc_st_filt_ivas_fx( Calc_rc0_h( h, parcor0 ); /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); + L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 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] ) ); // Q12 } - g0 = extract_h( L_shl( L_g0, 14 ) ); + g0 = extract_h( L_shl( L_g0, 14 ) ); // Q10 /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) + IF( GT_16( g0, 1024 ) ) /*1024 = 1.Q10*/ { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ + temp = div_s( 1024, g0 ); /* temp => Q15 / gain0 */ /*1024 = 1.Q10*/ 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 ); // Qx move16(); } } @@ -1685,34 +1687,34 @@ void Filt_mu_fx( IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* GAMMA3_PLUS_FX < 0.5 */ sh_fact = 14; move16(); /* sh_fact */ fact = (Word16) 0x4000; - move16(); /* 2**sh_fact */ + move16(); /* Q(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 ); // Q15 /* GAMMA3_MINUS_FX < 0.9375 */ sh_fact = 11; move16(); /* sh_fact */ fact = (Word16) 0x0800; - move16(); /* 2**sh_fact */ + move16(); /* Q(sh_fact) */ L_fact = (Word32) L_deposit_l( 0x0400 ); /* fact >> 1 */ } 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 ); /* Q15 (1 - |mu|) */ #else 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 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1748,7 +1750,7 @@ void Filt_mu_fx( 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 parcor0, /* i : parcor0 (mu = parcor0 * gamma3) Q15 */ Word16 L_subfr, /* i : the length of subframe */ const Word16 extl ) { @@ -1768,58 +1770,58 @@ void Filt_mu_ivas_fx( { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_WB_FX ); // Q15 /* 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(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_WB_FX ); // Q15 /* 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(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } ELSE { IF( parcor0 > 0 ) { - mu = mult_r( parcor0, GAMMA3_PLUS_FX ); + mu = mult_r( parcor0, GAMMA3_PLUS_FX ); // Q15 /* 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(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x2000 ); /* fact >> 1 */ } ELSE { - mu = mult_r( parcor0, GAMMA3_MINUS_FX ); + mu = mult_r( parcor0, GAMMA3_MINUS_FX ); // Q15 /* 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(); /* Q(sh_fact) */ + L_fact = L_deposit_l( 0x0400 ); /* fact >> 1 */ } } 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 ); /* Q15 (1 - |mu|) */ #else 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 ); /* Q(sh_fact) / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ @@ -1854,9 +1856,9 @@ 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 */ + const Word16 *sig_in, /* i : postfilter i signal Qx */ + Word16 *sig_out, /* i/o: postfilter o signal Qx */ + Word16 *gain_prec, /* i/o: last value of gain for subframe Q14*/ Word16 L_subfr ) { Word32 L_acc, L_temp; @@ -1871,11 +1873,11 @@ void scale_st_fx( 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] ); } - if ( sig_in[i] < 0 ) + IF( sig_in[i] < 0 ) { L_acc = L_msu0( L_acc, 1, sig_in[i] ); } @@ -1948,6 +1950,7 @@ void scale_st_fx( L_temp = L_shl( L_temp, 1 ); sig_out[i] = round_fx( L_temp ); #endif + move16(); } *gain_prec = gain; move16(); @@ -1963,26 +1966,26 @@ void scale_st_fx( *---------------------------------------------------------------------------*/ void blend_subfr2_fx( - Word16 *sigIn1, - Word16 *sigIn2, - Word16 *sigOut ) + Word16 *sigIn1, // Qx + Word16 *sigIn2, // Qx + Word16 *sigOut // Qx +) { - Word16 fac1 = 32768 - 512; - Word16 fac2 = 0 + 512; - Word16 step = 1024; + Word16 fac1 = 32768 - 512; // 1.Q15 - ( 1.Q15 / L_SUBFR ); + Word16 fac2 = 0 + 512; // 0.Q15 + ( 1.Q15 / L_SUBFR ); + Word16 step = 1024; // 1.Q15 / ( L_SUBFR / 2 ); Word16 i; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif move16(); +#endif move16(); move16(); move16(); FOR( i = 0; i < L_SUBFR / 2; i++ ) { #ifdef BASOP_NOGLOB - sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); - move16(); + sigOut[i] = mac_ro( L_mult_o( fac1, sigIn1[i], &Overflow ), fac2, sigIn2[i], &Overflow ); // Qx fac1 = sub_o( fac1, step, &Overflow ); fac2 = add_o( fac2, step, &Overflow ); #else @@ -1990,6 +1993,7 @@ void blend_subfr2_fx( fac1 = sub( fac1, step ); fac2 = add( fac2, step ); #endif + move16(); } return; diff --git a/lib_dec/dec_ppp_fx.c b/lib_dec/dec_ppp_fx.c index d37efa4c7..189ecc2b7 100644 --- a/lib_dec/dec_ppp_fx.c +++ b/lib_dec/dec_ppp_fx.c @@ -70,7 +70,7 @@ ivas_error decod_ppp_fx( /* call voiced decoder at this point */ FOR( k = 0; k < M; k++ ) { - p_Aq_curr_fx[k] = Aq_fx[add( k, ( 3 * ( M + 1 ) ) + 1 )]; + p_Aq_curr_fx[k] = Aq_fx[( k + ( 3 * ( M + 1 ) ) + 1 )]; move16(); /*Q12 */ } diff --git a/lib_dec/dec_prm_fx.c b/lib_dec/dec_prm_fx.c index 7b923ab72..194e6bba6 100644 --- a/lib_dec/dec_prm_fx.c +++ b/lib_dec/dec_prm_fx.c @@ -20,10 +20,10 @@ void getLPCparam_fx( Decoder_State *st, /* i/o: decoder memory state */ - Word16 param_lpc[], /* o : LTP parameters */ + Word16 param_lpc[], /* o : LTP parameters Q0 */ Decoder_State *st0, /* i : bitstream */ - const Word16 ch, /* i : channel */ - const Word16 sns_low_br_mode /* i : SNS low-bitrate mode */ + const Word16 ch, /* i : channel Q0 */ + const Word16 sns_low_br_mode /* i : SNS low-bitrate mode Q0 */ ) { IF( st->use_partial_copy == 0 ) @@ -59,9 +59,9 @@ void getLPCparam_fx( { test(); test(); - IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && EQ_16( st->core, ACELP_CORE ) ) + IF( EQ_32( st->sr_core, INT_FS_16k ) && EQ_16( st->coder_type, VOICED ) && ( st->core == ACELP_CORE ) ) { - assert( EQ_16( st->element_mode, EVS_MONO ) ); + assert( st->element_mode == EVS_MONO ); lsf_bctcvq_decprm( st0, param_lpc ); } ELSE @@ -82,21 +82,21 @@ void getLPCparam_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st0, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st0, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st0, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } 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_fx( st0, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st0, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st0, 8 ); /* VQ 2 */ // Q0 move16(); } } @@ -106,7 +106,7 @@ void getLPCparam_fx( void dec_prm_hm_fx( Decoder_State *st, - Word16 *prm_hm, + Word16 *prm_hm, /* Q0 */ const Word16 L_frame ) { Word16 tmp; @@ -127,7 +127,7 @@ 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 ); // Q0 move16(); IF( prm_hm[0] != 0 ) @@ -161,13 +161,13 @@ 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 ) + Word16 param[], /* o : decoded parameters Q0 */ + const Word16 bits_common, /* i : number of common bits Q0 */ + const Word16 start_bit_pos, /* i : position of the start bit Q0 */ + const Word16 *no_param_tns, /* i : number of TNS parameters per subframe Q0 */ + Word16 p_param[2], /* o : pointer to parameters for next round of bs reading Q0 */ + Word16 nTnsBitsTCX10[2], /*Q0*/ + const Word16 pre_past_flag /*Q0*/ ) { Word16 ix, j, k, core, last_core, nSubframes; Word16 lg, lgFB, flag_ctx_hm, hm_size; @@ -243,7 +243,7 @@ void getTCXparam_fx( IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_SHORT, 1 - k ); IGFDecStoreTCX10SubFrameData( st->hIGFDec, k ); - nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); + nbits_igf = add( nbits_igf, sub( st0->next_bit_pos, ix ) ); // Q0 } } /* loop over subframes */ @@ -251,35 +251,35 @@ void getTCXparam_fx( { flag_ctx_hm = 0; move16(); - prm = param + imult1616( k, DEC_NPRM_DIV ); + prm = param + k * DEC_NPRM_DIV; j = 0; move16(); - nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st0->next_bit_pos, start_bit_pos ); // Q0 test(); test(); - IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, ( nSubframes - 1 ) ) ) + IF( pre_part && st->enablePlcWaveadjust && EQ_16( k, sub( nSubframes, 1 ) ) ) { - st->tonality_flag = get_next_indice_fx( st0, 1 ); + st->tonality_flag = get_next_indice_fx( st0, 1 ); // Q0 move16(); } IF( post_part ) { /* TCX Gain */ - prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_TCX_GAIN ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st0, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); } ELSE { - j = add( j, 1 + NOISE_FILL_RANGES ); + j = add( j, 1 + NOISE_FILL_RANGES ); // Q0 } /* LTP data */ @@ -289,24 +289,24 @@ void getTCXparam_fx( test(); IF( ( k == 0 ) && ( hTcxLtpDec->tcxltp || GT_32( st->sr_core, 25600 ) ) ) /* PLC pitch info for HB */ { - prm[j] = get_next_indice_fx( st0, 1 ); + prm[j] = get_next_indice_fx( st0, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); + prm[add( j, 1 )] = get_next_indice_fx( st0, 9 ); // Q0 move16(); - prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); + prm[add( j, 2 )] = get_next_indice_fx( st0, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 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 ); + st->BER_detect = s_or( 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 ) ); // Q0 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -316,45 +316,45 @@ void getTCXparam_fx( // To be done at the end 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 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } ELSE { - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } } /* TCX spectral data */ - lg = shr( st->L_frame, sub( nSubframes, 1 ) ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); + lg = shr( st->L_frame, sub( nSubframes, 1 ) ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, sub( nSubframes, 1 ) ); // Q0 test(); test(); IF( post_part && ( k == 0 ) && EQ_16( st->last_core_from_bs, ACELP_CORE ) ) { /* ACE->TCX transition */ - lg = add( lg, st->hTcxCfg->tcx_offset ); - lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 + lgFB = add( lgFB, shr( lgFB, sub( 3, nSubframes ) ) ); // Q0 - if ( st->hTcxCfg->lfacNext < 0 ) + IF( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } } @@ -384,33 +384,41 @@ void getTCXparam_fx( move16(); IF( no_param_tns ) { - ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ + ix = get_next_indice_fx( st0, 1 ); /* common_tns_data[] for subframe k */ // Q0 } IF( ix ) { - prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ + prm[j] = imult1616( no_param_tns[k], -1 ); /* - signals common TNS and its size */ // Q0 move16(); - nTnsParams = no_param_tns[k]; + nTnsParams = no_param_tns[k]; // Q0 move16(); } ELSE { ReadTnsData_ivas_fx( st->hTcxCfg->pCurrentTnsConfig, st0, &nTnsBits, prm + j, &nTnsParams ); } - hTcxDec->tnsActive[k] = 0; + hTcxDec->tnsActive[k] = 0; // Q0 move16(); if ( prm[j] != 0 ) { - hTcxDec->tnsActive[k] = nTnsParams; + hTcxDec->tnsActive[k] = nTnsParams; // Q0 move16(); } - if ( nTnsBitsTCX10 != NULL ) + IF( nTnsBitsTCX10 != NULL ) { - nTnsBitsTCX10[k] = add( nTnsBits, ( no_param_tns ? 1 : 0 ) ); - move16(); + IF( no_param_tns ) + { + nTnsBitsTCX10[k] = add( nTnsBits, 1 ); // Q0 + move16(); + } + ELSE + { + nTnsBitsTCX10[k] = add( nTnsBits, 0 ); // Q0 + move16(); + } } - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } IF( post_part ) @@ -418,46 +426,46 @@ void getTCXparam_fx( IF( EQ_16( core, TCX_20_CORE ) ) { // Q-factor of TcxBandwidth is 15 : derived from getTcxBandwidth function - hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); + hm_size = mult( st->TcxBandwidth, shl( lg, 1 ) ); // Q0 test(); - IF( hTcxDec->tcx_lpc_shaped_ari && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( hTcxDec->tcx_lpc_shaped_ari && ( st->last_core_from_bs != ACELP_CORE ) ) { dec_prm_hm_fx( st0, &prm[j], hm_size ); } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE { - hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); - nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); + hm_size = mult( st->TcxBandwidth, shl( lgFB, 1 ) ); // Q0 + nbits_tcx = sub( shr( sub( add( sub( sub( st->bits_frame_core, bits_common ), nbits_igf ), 1 ), k ), 1 ), sub( sub( st0->next_bit_pos, start_bit_pos ), nbits_tcx ) ); // Q0 } /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( st->last_core_from_bs, ACELP_CORE ) && ( k == 0 ) ) ) + IF( st->hTcxCfg->ctx_hm && !( ( st->last_core_from_bs == ACELP_CORE ) && ( k == 0 ) ) ) { - useHarmonicModel = get_next_indice_fx( st0, 1 ); - prm[j] = useHarmonicModel; + useHarmonicModel = get_next_indice_fx( st0, 1 ); // Q0 + prm[j] = useHarmonicModel; // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( useHarmonicModel ) { ix = DecodeIndex_fx( st0, (Word16) GE_16( hm_size, 256 ), prm + add( j, 1 ) ); - flag_ctx_hm = 1; + flag_ctx_hm = 1; // Q0 move16(); PeriodicityIndex = *( prm + add( j, 1 ) ); - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - nbits_tcx = sub( nbits_tcx, ix ); + nbits_tcx = sub( nbits_tcx, ix ); // Q0 } } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ test(); @@ -465,31 +473,39 @@ void getTCXparam_fx( { IF( st->igf ) { - ix = st->next_bit_pos; + ix = st->next_bit_pos; // Q0 move16(); - IGFDecReadLevel( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); - IGFDecReadData( st->hIGFDec, st0, ( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM, 1 ); + IF( st->last_core_from_bs == ACELP_CORE ) + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_TRAN, 1 ); + } + ELSE + { + IGFDecReadLevel( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + IGFDecReadData( st->hIGFDec, st0, IGF_GRID_LB_NORM, 1 ); + } - nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); + nbits_tcx = sub( nbits_tcx, sub( st0->next_bit_pos, ix ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st0->next_bit_pos, start_bit_pos ) ); // Q0 } ELSE IF( p_param != NULL ) { - p_param[k] = j; + p_param[k] = j; // Q0 move16(); } } ELSE { - j = p_param[k]; + j = p_param[k]; // Q0 move16(); - nbits_tcx = st->bits_frame_channel; + nbits_tcx = st->bits_frame_channel; // Q0 move16(); if ( EQ_16( st->core, TCX_10_CORE ) ) { - nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + nbits_tcx = sub( nTnsBitsTCX10[k], NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); // Q0 } } @@ -498,36 +514,52 @@ void getTCXparam_fx( test(); IF( hTcxDec->tcx_lpc_shaped_ari && EQ_16( core, TCX_20_CORE ) ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st0 ); + prms[ix] = get_next_indice_1_fx( st0 ); // Q0 } FOR( ix = 0; ix < 32; ix++ ) { - prms[add( ix, nbits_tcx )] = 1; + prms[ix + nbits_tcx] = 1; // Q0 + move16(); } - move16(); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { - IF( GT_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode > EVS_MONO ) { IF( useHarmonicModel ) { ConfigureContextHm( lgFB, nbits_tcx, PeriodicityIndex, hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); } - hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = RCcontextMapping_decode2_no_mem_s17_LCS_fx( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } ELSE { - hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), flag_ctx_hm ? &hm_cfg : NULL ); - move16(); + IF( flag_ctx_hm ) + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), &hm_cfg ); // Q0 + move16(); + } + ELSE + { + hTcxDec->resQBits[k] = ACcontextMapping_decode2_no_mem_s17_LC( st0, prm + j, lgFB, nbits_tcx, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), NULL ); // Q0 + move16(); + } } } } @@ -545,9 +577,9 @@ void getTCXparam_fx( *-----------------------------------------------------------------*/ 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 */ + Word16 param[], /* (o) : decoded parameters Q0 */ + Word16 param_lpc[], /* (o) : LPC parameters Q0 */ + Word16 *total_nbbits, /* i/o : number of bits / decoded bits Q0 */ Decoder_State *st, Word16 L_frame, Word16 *bitsRead ) @@ -613,17 +645,17 @@ void dec_prm_fx( 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 ); // Q0 } ELSE { - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; // Q0 move16(); } } /* Framing parameters */ - nb_subfr = st->nb_subfr; + nb_subfr = st->nb_subfr; // Q0 move16(); /* Initialize pointers */ @@ -646,12 +678,12 @@ void dec_prm_fx( /* Modes (ACE_GC, ACE_UC, TCX20, TCX10...) */ IF( st->tcxonly ) { - st->core = add( get_next_indice_fx( st, 1 ), 1 ); + st->core = add( get_next_indice_fx( st, 1 ), 1 ); // Q0 move16(); - ind = get_next_indice_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); - if ( ind == 0 ) + IF( ind == 0 ) { st->clas_dec = UNVOICED_CLAS; move16(); @@ -683,7 +715,7 @@ void dec_prm_fx( /* 2 bits instead of 3 as TCX is already signaled */ st->core = TCX_20_CORE; move16(); - st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); + st->hTcxCfg->coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); *coder_type = st->hTcxCfg->coder_type; move16(); @@ -694,7 +726,7 @@ void dec_prm_fx( { IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ { - tmp = get_next_indice_fx( st, 3 ); + tmp = get_next_indice_fx( st, 3 ); // Q0 assert( !( tmp & 4 ) || !"HQ_CORE encountered in dec_prm_fx" ); st->core = TCX_20_CORE; move16(); @@ -707,7 +739,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 2 ); + *coder_type = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -736,7 +768,7 @@ void dec_prm_fx( { st->core = ACELP_CORE; move16(); - *coder_type = get_next_indice_fx( st, 3 ); + *coder_type = get_next_indice_fx( st, 3 ); // Q0 move16(); IF( GE_16( *coder_type, ACELP_MODE_MAX ) ) { @@ -752,22 +784,22 @@ void dec_prm_fx( } test(); - if ( ( st->igf != 0 ) && EQ_16( st->core, ACELP_CORE ) ) + IF( ( st->igf != 0 ) && ( 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 ) ); // Q0 move16(); } - 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 */ // Q0 move16(); } /* Inactive frame detection on non-DTX mode */ st->VAD = 1; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->VAD = 0; move16(); @@ -778,7 +810,7 @@ void dec_prm_fx( st->core_ext_mode = *coder_type; move16(); - if ( EQ_16( *coder_type, INACTIVE ) ) + if ( *coder_type == INACTIVE ) { st->core_ext_mode = UNVOICED; move16(); @@ -789,7 +821,7 @@ void dec_prm_fx( move16(); test(); test(); - IF( ( NE_16( st->core, ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) + IF( ( ( st->core != ACELP_CORE ) || st->hTcxCfg->lfacNext > 0 ) && st->use_partial_copy == 0 ) { st->last_core_from_bs = get_next_indice_fx( st, 1 ); move16(); @@ -812,8 +844,8 @@ void dec_prm_fx( IF( EQ_16( st->core, TCX_10_CORE ) ) { st->last_core = TCX_20_CORE; - st->last_core_from_bs = TCX_20_CORE; move16(); + st->last_core_from_bs = TCX_20_CORE; move16(); } } @@ -828,14 +860,14 @@ void dec_prm_fx( 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, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); + get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), st->next_bit_pos ) ); // Q0 } 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( ( st->last_core == ACELP_CORE ) || ( EQ_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; move16(); @@ -853,7 +885,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 ) ) && ( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); @@ -864,12 +896,12 @@ void dec_prm_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); - IF( NE_16( st->core, ACELP_CORE ) ) + IF( st->core != ACELP_CORE ) { tmp = 0; move16(); /* if current TCX mode is not 0 (full overlap), read another bit */ - if ( get_next_indice_fx( st, 1 ) ) + IF( get_next_indice_fx( st, 1 ) ) { tmp = add( 2, get_next_indice_fx( st, 1 ) ); } @@ -880,7 +912,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 ) && ( st->last_core != ACELP_CORE ) && ( NE_16( st->last_core, AMR_WB_CORE ) ) ) { st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -897,28 +929,28 @@ void dec_prm_fx( search_range = 8; move16(); - st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); + st->flagGuidedAcelp = get_next_indice_fx( st, 1 ); // Q0 move16(); pitchDiff = 0; move16(); IF( st->flagGuidedAcelp ) { - pitchDiff = get_next_indice_fx( st, bits_per_subfr ); + pitchDiff = get_next_indice_fx( st, bits_per_subfr ); // Q0 move16(); - st->guidedT0 = sub( pitchDiff, search_range ); + st->guidedT0 = sub( pitchDiff, search_range ); // Q0 move16(); } test(); if ( ( pitchDiff == 0 ) && st->flagGuidedAcelp ) { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } } ELSE { - st->flagGuidedAcelp = 0; + st->flagGuidedAcelp = 0; // Q0 move16(); } @@ -926,9 +958,9 @@ void dec_prm_fx( { move16(); st->dec_glr_idx = -1; - if ( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { - st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); + st->dec_glr_idx = get_next_indice_fx( st, G_LPC_RECOVERY_BITS ); // Q0 move16(); } } @@ -962,7 +994,7 @@ void dec_prm_fx( /* Decode LPC parameters */ test(); - IF( hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + IF( hTcxDec->enableTcxLpc && ( st->core != ACELP_CORE ) ) { Word16 tcx_lpc_cdk; tcx_lpc_cdk = tcxlpc_get_cdk( *coder_type ); @@ -984,7 +1016,7 @@ void dec_prm_fx( { 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 ) && ( st->core == ACELP_CORE ) ) { lsf_bctcvq_decprm( st, param_lpc ); } @@ -1007,26 +1039,26 @@ void dec_prm_fx( test(); IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { - param_lpc[0] = 0; + param_lpc[0] = 0; // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ + param_lpc[1] = get_next_indice_fx( st, lsf_numbits[0] ); /* VQ 1 */ // Q0 move16(); - param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ + param_lpc[2] = get_next_indice_fx( st, lsf_numbits[1] ); /* VQ 2 */ // Q0 move16(); - param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ + param_lpc[3] = get_next_indice_fx( st, lsf_numbits[2] ); /* VQ 3 */ // Q0 move16(); } 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_fx( st, 8 ); /* VQ 1 */ + param_lpc[0] = get_next_indice_fx( st, 8 ); /* VQ 1 */ // Q0 move16(); - param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ + param_lpc[1] = get_next_indice_fx( st, 8 ); /* VQ 2 */ // Q0 move16(); } } - st->bits_common = sub( st->next_bit_pos, start_bit_pos ); + st->bits_common = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); @@ -1035,7 +1067,7 @@ void dec_prm_fx( *--------------------------------------------------------------------------------*/ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) + IF( ( st->core == ACELP_CORE ) && ( st->use_partial_copy == 0 ) ) { /* Target Bits */ acelp_target_bits = sub( st->bits_frame_core, st->bits_common ); @@ -1053,23 +1085,23 @@ 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]; // Q0 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 ); // Q0 + IF( n != 0 ) { - st->bpf_gain_param = get_next_indice_fx( st, n ); + st->bpf_gain_param = get_next_indice_fx( st, n ); // Q0 move16(); } /* Mean energy (2 or 3 bits) */ - n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; + n = ACELP_NRG_BITS[st->acelp_cfg.nrg_mode]; // Q0 move16(); - if ( n != 0 ) + IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1077,63 +1109,63 @@ void dec_prm_fx( FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (4, 5, 6, 8 or 9 bits) */ - n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[st->acelp_cfg.ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Adaptive codebook filtering (1 bit) */ IF( EQ_16( st->acelp_cfg.ltf_mode, 2 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /* Innovative codebook */ { /* Decode pulse positions. */ - j_old = j; + j_old = j; // Q0 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 ); // Q0 + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st->acelp_cfg.fixed_cdk_index[sfr] ), 0xF ); // Q0 /* 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 ) ) { - st->acelp_cfg.fixed_cdk_index[sfr] = 0; + st->acelp_cfg.fixed_cdk_index[sfr] = 0; // Q0 move16(); - st->BER_detect = 1; + st->BER_detect = 1; // Q0 move16(); } FOR( ix = 0; ix < wordcnt; ix++ ) { - prm[j] = (Word16) get_next_indice_fx( st, 16 ); - j = add( j, 1 ); + prm[j] = (Word16) get_next_indice_fx( st, 16 ); // Q0 + j = add( j, 1 ); // Q0 move16(); } - if ( bitcnt ) + IF( bitcnt ) { - prm[j] = get_next_indice_fx( st, bitcnt ); + prm[j] = get_next_indice_fx( st, bitcnt ); // Q0 move16(); } - j = add( j_old, 8 ); + j = add( j_old, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ - n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; + n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } /*end of subfr loop*/ } @@ -1157,43 +1189,44 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_NELP ) ) { /* NELP gain indices */ - st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); - st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG1 = get_next_indice_fx( st, 5 ); // Q0 move16(); - st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); + st->rf_indx_nelp_iG2[0] = get_next_indice_fx( st, 6 ); // Q0 + move16(); + st->rf_indx_nelp_iG2[1] = get_next_indice_fx( st, 6 ); // Q0 move16(); /* NELP filter selection index */ - st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); + st->rf_indx_nelp_fid = get_next_indice_fx( st, 2 ); // Q0 move16(); /* tbe gainFr */ - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 5 ); // Q0 move16(); } ELSE { /* rf_frame_type ALL_PRED: 4, NO_PRED: 5, GEN_PRED: 6*/ /* ES pred */ - prm[j] = get_next_indice_fx( st, 3 ); + prm[j] = get_next_indice_fx( st, 3 ); // Q0 move16(); - j = add( j, 1 ); + j = add( j, 1 ); // Q0 - ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; + ltp_mode = ACELP_LTP_MODE[1][1][st->rf_frame_type]; // Q0 move16(); - gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; + gains_mode = ACELP_GAINS_MODE[1][1][st->rf_frame_type]; // Q0 move16(); /* Subframe parameters */ FOR( sfr = 0; sfr < nb_subfr; sfr++ ) { /* Pitch lag (5, or 8 bits) */ - n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; + n = ACELP_LTP_BITS_SFR[ltp_mode][sfr]; // Q0 move16(); IF( n != 0 ) { - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } @@ -1205,24 +1238,24 @@ void dec_prm_fx( { /* 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_fx( st, 7 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 move16(); - j = add( j, 8 ); + j = add( j, 8 ); // Q0 } /* Gains (5b, 6b or 7b / subfr) */ test(); IF( sfr == 0 || EQ_16( sfr, 2 ) ) { - n = ACELP_GAINS_BITS[gains_mode]; + n = ACELP_GAINS_BITS[gains_mode]; // Q0 move16(); - prm[j] = get_next_indice_fx( st, n ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, n ); // Q0 + j = add( j, 1 ); // Q0 move16(); } } - st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); + st->rf_indx_tbeGainFr = get_next_indice_fx( st, 2 ); // Q0 move16(); } } @@ -1238,18 +1271,18 @@ void dec_prm_fx( if ( st->enablePlcWaveadjust ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1258,31 +1291,31 @@ void dec_prm_fx( IF( hTcxLtpDec->tcxltp != 0 || GT_32( st->sr_core, 25600 ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 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 ); + st->BER_detect = s_or( 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 ) ); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); test(); @@ -1290,12 +1323,12 @@ void dec_prm_fx( { 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 ); + hTcxDec->tcx_hm_LtpPitchLag = div_l( tmp32, tmp1 ); // Q15 move16(); } } - j = add( j, 3 ); + j = add( j, 3 ); // Q0 /* TCX spectral data */ lg = L_frame; @@ -1303,16 +1336,16 @@ void dec_prm_fx( lgFB = st->hTcxCfg->tcx_coded_lines; move16(); - IF( EQ_16( 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 ); + lg = add( lg, st->hTcxCfg->tcx_offset ); // Q0 if ( st->hTcxCfg->lfacNext < 0 ) { - lg = sub( lg, st->hTcxCfg->lfacNext ); + lg = sub( lg, st->hTcxCfg->lfacNext ); // Q0 } - lgFB = add( lgFB, shr( lgFB, 2 ) ); + lgFB = add( lgFB, shr( lgFB, 2 ) ); // Q0 } /* TNS data */ @@ -1326,7 +1359,7 @@ void dec_prm_fx( SetTnsConfig( st->hTcxCfg, 1, (Word16) EQ_16( st->last_core_from_bs, ACELP_CORE ) ); ReadTnsData( st->hTcxCfg->pCurrentTnsConfig, st, &nTnsBits, prm + j, &nTnsParams ); - j = add( j, nTnsParams ); + j = add( j, nTnsParams ); // Q0 } hm_size = shl( mult( st->TcxBandwidth, lg ), 1 ); @@ -1337,18 +1370,18 @@ void dec_prm_fx( } nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); - if ( st->enableGplc != 0 ) + IF( st->enableGplc != 0 ) { - nbits_tcx = sub( nbits_tcx, 7 ); + nbits_tcx = sub( nbits_tcx, 7 ); // Q0 } /*Context HM flag*/ test(); - IF( st->hTcxCfg->ctx_hm && NE_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( st->hTcxCfg->ctx_hm && ( st->last_core_from_bs != ACELP_CORE ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 IF( prm[j] ) { @@ -1375,10 +1408,10 @@ void dec_prm_fx( hTcxDec->tcx_hm_LtpPitchLag, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 /* read IGF payload */ IF( st->igf ) @@ -1386,7 +1419,7 @@ void dec_prm_fx( n = st->next_bit_pos; move16(); - IF( EQ_16( st->last_core_from_bs, ACELP_CORE ) ) + IF( 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 ); @@ -1397,22 +1430,22 @@ 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 ) ); // Q0 } - nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); + nbits_tcx = sub( st->bits_frame_core, sub( st->next_bit_pos, start_bit_pos ) ); // Q0 IF( hTcxDec->tcx_lpc_shaped_ari != 0 ) { - prm[j] = nbits_tcx; /* store length of buffer */ - j = add( j, 1 ); + prm[j] = nbits_tcx; /* store length of buffer */ // Q0 + j = add( j, 1 ); // Q0 move16(); prms = &prm[j]; FOR( ix = 0; ix < nbits_tcx; ix++ ) { - prms[ix] = get_next_indice_1_fx( st ); + prms[ix] = get_next_indice_1_fx( st ); // Q0 move16(); } set16_fx( prms + nbits_tcx, 1, 32 ); - j = add( j, nbits_tcx ); + j = add( j, nbits_tcx ); // Q0 } ELSE { @@ -1423,9 +1456,9 @@ void dec_prm_fx( 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, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lg ); + j = add( j, lg ); // Q0 } } @@ -1434,7 +1467,7 @@ void dec_prm_fx( 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_fx( st, 2 ); + ind = get_next_indice_fx( st, 2 ); // Q0 st->clas_dec = ONSET; move16(); @@ -1465,7 +1498,7 @@ void dec_prm_fx( IF( EQ_16( st->rf_frame_type, RF_TCXFD ) ) { /* TCX Gain = 7 bits */ - hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); + hTcxDec->old_gaintcx_bfi = get_next_indice_fx( st, 7 ); // Q0 move16(); } ELSE @@ -1476,19 +1509,19 @@ void dec_prm_fx( test(); 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_fx( st, 9 ); - prm_ltp[2] = 3; - move16(); /* max ampl. quantizer output (2bits), anyway not used later*/ + prm_ltp[0] = 1; // Q0 + move16(); /* LTP active*/ + prm_ltp[1] = get_next_indice_fx( st, 9 ); // Q0 + prm_ltp[2] = 3; // Q0 + 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 ); + st->BER_detect = s_or( 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 ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); } } @@ -1536,22 +1569,22 @@ void dec_prm_fx( j = 0; move16(); - nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); + nbits_tcx = sub( st->next_bit_pos, start_bit_pos ); // Q0 test(); - if ( st->enablePlcWaveadjust && k ) + IF( st->enablePlcWaveadjust && k ) { - st->tonality_flag = get_next_indice_fx( st, 1 ); + st->tonality_flag = get_next_indice_fx( st, 1 ); // Q0 move16(); } /* TCX Gain = 7 bits */ - prm[j] = get_next_indice_fx( st, 7 ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, 7 ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* TCX Noise Filling = NBITS_NOISE_FILL_LEVEL bits */ - prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); - j = add( j, 1 ); + prm[j] = get_next_indice_fx( st, NBITS_NOISE_FILL_LEVEL ); // Q0 + j = add( j, 1 ); // Q0 move16(); /* LTP data */ @@ -1559,22 +1592,22 @@ void dec_prm_fx( test(); IF( ( k == 0 ) && ( ( hTcxLtpDec->tcxltp != 0 ) || ( GT_32( st->sr_core, 25600 ) ) ) ) { - prm[j] = get_next_indice_fx( st, 1 ); + prm[j] = get_next_indice_fx( st, 1 ); // Q0 move16(); IF( prm[j] ) { - prm[j + 1] = get_next_indice_fx( st, 9 ); + prm[j + 1] = get_next_indice_fx( st, 9 ); // Q0 move16(); - prm[j + 2] = get_next_indice_fx( st, 2 ); + prm[j + 2] = get_next_indice_fx( st, 2 ); // Q0 move16(); - tcxltp_prm_0 = prm[j]; + tcxltp_prm_0 = prm[j]; // Q0 move16(); - tcxltp_prm_1 = prm[j + 1]; + tcxltp_prm_1 = prm[j + 1]; // Q0 move16(); - tcxltp_prm_2 = prm[j + 2]; + tcxltp_prm_2 = prm[j + 2]; // Q0 move16(); } @@ -1590,32 +1623,32 @@ void dec_prm_fx( st->pit_res_max ) ); move16(); - hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; + hTcxDec->tcxltp_last_gain_unmodified = hTcxLtpDec->tcxltp_gain; // Q15 move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; // Q15 move16(); - j = add( j, 3 ); + j = add( j, 3 ); // Q0 } ELSE { - prm[j] = tcxltp_prm_0; - j = add( j, 1 ); + prm[j] = tcxltp_prm_0; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_1; - j = add( j, 1 ); + prm[j] = tcxltp_prm_1; // Q0 + j = add( j, 1 ); // Q0 move16(); - prm[j] = tcxltp_prm_2; - j = add( j, 1 ); + prm[j] = tcxltp_prm_2; // Q0 + j = add( j, 1 ); // Q0 move16(); } /* TCX spectral data */ - lg = shr( L_frame, 1 ); - lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); + lg = shr( L_frame, 1 ); // Q0 + lgFB = shr( st->hTcxCfg->tcx_coded_lines, 1 ); // Q0 test(); - IF( k == 0 && EQ_16( 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 ); @@ -1656,31 +1689,31 @@ void dec_prm_fx( 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 ) ); // Q0 /*Context HM flag*/ test(); test(); - IF( st->hTcxCfg->ctx_hm && !( EQ_16( 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 ); // Q0 move16(); - nbits_tcx = sub( nbits_tcx, 1 ); + nbits_tcx = sub( nbits_tcx, 1 ); // Q0 move16(); 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 ); // Q0 flag_ctx_hm = 1; move16(); ConfigureContextHm( lgFB, nbits_tcx, *( prm + j + 1 ), -1, &hm_cfg ); - nbits_tcx = sub( nbits_tcx, NumIndexBits ); + nbits_tcx = sub( nbits_tcx, NumIndexBits ); // Q0 } } - j = add( j, NPRM_CTX_HM ); + j = add( j, NPRM_CTX_HM ); // Q0 phm_cfg = NULL; move16(); if ( flag_ctx_hm ) @@ -1688,9 +1721,9 @@ void dec_prm_fx( 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, imult1616( NPRM_RESQ, st->hTcxCfg->resq ), phm_cfg ); // Q0 move16(); - j = add( j, lgFB ); + j = add( j, lgFB ); // Q0 } /* k, window index */ } @@ -1701,10 +1734,10 @@ void dec_prm_fx( { 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] ) ); // Q0 move16(); } - bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); + bitsRead[0] = sub( st->next_bit_pos, start_bit_pos ); // Q0 move16(); } diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 53b688e72..35a417a6c 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1613,9 +1613,9 @@ void decoder_tcx_post_fx( Decoder_State *st_fx, #ifdef IVAS_FLOAT_FIXED void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, - Word16 *synth, - Word16 *synthFB, - Word16 *A, + Word16 *synth, // Qx + Word16 *synthFB, // Qx + Word16 *A, // Q: 14 - norm_s(A[0]) Word16 bfi, Word16 MCT_flag ) { @@ -1684,7 +1684,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, { 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 ) ); // Qx #else synthFB[i] = round_fx( L_shl( Mpy_32_16_1( tmp32, synthFB[i] ), 16 ) ); #endif @@ -1696,8 +1696,8 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, 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] ) ); // Qx move16(); tmp32_1 = L_sub( tmp32_1, tmp32_2 ); } @@ -1843,7 +1843,7 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, } } - if ( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) + IF( ( EQ_16( st_fx->nbLostCmpt, 1 ) ) ) { hTcxDec->conceal_eof_gain32 = ONE_IN_Q30 /*1.0f Q30*/; move32(); @@ -1878,14 +1878,14 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, FOR( i = 0; i < hTcxDec->L_frameTCX; i++ ) { tmp_shift = conceal_eof_gainFB_e; - synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); + synthFB[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( conceal_eof_gainFB, synthFB[i] ), tmp_shift ) ); // Qx move16(); - conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); + conceal_eof_gainFB = BASOP_Util_Add_Mant32Exp( conceal_eof_gainFB, conceal_eof_gainFB_e, L_negate( stepFB ), stepFB_e, &conceal_eof_gainFB_e ); // Q: 31 - conceal_eof_gainFB_e } } FOR( i = 0; i < st_fx->L_frame; i++ ) { - xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); + xn_buf[i] = round_fx_sat( L_shl_sat( Mpy_32_16_1( hTcxDec->conceal_eof_gain32, xn_buf[i] ), hTcxDec->conceal_eof_gain_e ) ); // Qx move16(); hTcxDec->conceal_eof_gain32 = BASOP_Util_Add_Mant32Exp( hTcxDec->conceal_eof_gain32, hTcxDec->conceal_eof_gain_e, L_negate( step ), step_e, &hTcxDec->conceal_eof_gain_e ); move32(); @@ -1956,16 +1956,16 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); - st_fx->mem_pitch_gain[add( shl( st_fx->nb_subfr, 1 ), 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2 + 1] = st_fx->mem_pitch_gain[st_fx->nb_subfr + 1]; // Q14 move16(); - st_fx->mem_pitch_gain[shl( st_fx->nb_subfr, 1 )] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; + st_fx->mem_pitch_gain[st_fx->nb_subfr * 2] = st_fx->mem_pitch_gain[st_fx->nb_subfr]; // Q14 move16(); FOR( i = 0; i < st_fx->nb_subfr; i++ ) { - st_fx->mem_pitch_gain[sub( sub( shl( st_fx->nb_subfr, 1 ), 1 ), i )] = st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )]; + st_fx->mem_pitch_gain[( st_fx->nb_subfr * 2 - 1 ) - i] = st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i]; // Q14 move16(); - st_fx->mem_pitch_gain[sub( sub( st_fx->nb_subfr, 1 ), i )] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ + st_fx->mem_pitch_gain[st_fx->nb_subfr - 1 - i] = shr( hTcxDec->tcxltp_last_gain_unmodified, 1 ); /* Q14 */ move16(); } } @@ -2049,7 +2049,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T /* number of zero for ALDO windows*/ tmp32 = L_add( st->sr_core, 0 ); - if ( fullbandScale != 0 ) + IF( fullbandScale != 0 ) { tmp32 = L_add( st->output_Fs, 0 ); } @@ -2057,7 +2057,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp_offset = 0; move16(); - if ( tcx_offset < 0 ) + IF( tcx_offset < 0 ) { tmp_offset = negate( tcx_offset ); } @@ -2258,9 +2258,9 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T L_win ); /* extra folding-out on left side of win, for perfect reconstruction */ - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = ( overlap / 2 ); w < overlap; w++ ) { - xn_buf[sub( sub( overlap, 1 ), w )] = negate( xn_buf[w] ); + xn_buf[( ( overlap - 1 ) - w )] = negate( xn_buf[w] ); move16(); } @@ -2745,8 +2745,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T 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[sub( sub( 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[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + 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 ) ) ); #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 ) ) ); @@ -2774,8 +2774,8 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T 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[sub( sub( 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[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im, tcx_mdct_window_half[sub( sub( tcx_mdct_window_half_length, 1 ), i )].v.im ) ) ); + 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 ) ) ); @@ -2836,7 +2836,7 @@ void IMDCT_ivas_fx( exp = 0; move16(); nz = BASOP_Util_Divide3216_Scale( c, L_frameTCX, &exp ); - exp = exp + ( 31 - 15 ); + exp = add( exp, ( 31 - 15 ) ); nz = shr( nz, sub( 15, exp ) ); // Q0 test(); @@ -2852,7 +2852,7 @@ void IMDCT_ivas_fx( fac = Mpy_32_16_1( hTcxDec->conceal_eof_gain32, st->last_concealed_gain_syn_deemph ); // q = 31 - hTcxDec->conceal_eof_gain_e FOR( Word16 ind = 0; ind < overlap; ind++ ) { - old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); + old_syn_overl_fx[ind] = extract_l( L_shl_sat( Mpy_32_32( old_syn_overl_fx[ind], fac ), hTcxDec->conceal_eof_gain_e ) ); // Q(-2) move16(); } } @@ -2998,17 +2998,17 @@ void IMDCT_ivas_fx( /* extra folding-out on left side of win, for perfect reconstruction */ IF( GE_16( kernel_type, MDCT_II ) ) { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = xn_buf_fx[w]; + xn_buf_fx[overlap - 1 - w] = xn_buf_fx[w]; move16(); } } ELSE { - FOR( w = shr( overlap, 1 ); w < overlap; w++ ) + FOR( w = overlap / 2; w < overlap; w++ ) { - xn_buf_fx[sub( sub( overlap, 1 ), w )] = negate( xn_buf_fx[w] ); + xn_buf_fx[overlap - 1 - w] = negate( xn_buf_fx[w] ); move16(); } } @@ -3068,7 +3068,7 @@ void IMDCT_ivas_fx( 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 ); + tmp_fx_32[ind] = L_shl( Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ), res_e ); move32(); } q_tmp_fx_32 = q_xn_buf_fx_32; @@ -3103,7 +3103,7 @@ void IMDCT_ivas_fx( 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 ); + tmp_fx_32[ind] = Mpy_32_16_1( xn_buf_fx_32[( overlap / 2 ) + nz + ind], res_m ); move32(); } q_tmp_fx_32 = sub( q_xn_buf_fx_32, res_e ); @@ -3111,7 +3111,7 @@ void IMDCT_ivas_fx( 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 ) ); + xn_buf_fx[( ind + ( overlap / 2 ) ) + nz] = (Word16) L_shr( xn_buf_fx_32[( ind + ( overlap / 2 ) ) + nz], sub( q_xn_buf_fx_32, q_win ) ); move16(); } @@ -3135,13 +3135,13 @@ void IMDCT_ivas_fx( IF( tcx_offset < 0 ) { - acelp_mem_len = -tcx_offset; + acelp_mem_len = negate( tcx_offset ); } ELSE { acelp_mem_len = 0; + move16(); } - move16(); IF( EQ_16( kernel_type, MDST_IV ) ) { @@ -3183,7 +3183,7 @@ void IMDCT_ivas_fx( 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 ); + st->old_Aq_12_8_fx[ind] = (Word16) L_shr( st->old_Aq_12_8_fx_32[ind], 16 ); // Q28 -> Q12 move16(); } } @@ -3215,9 +3215,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < sub( overlap, tcx_mdct_window_min_length ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); // Q(-2) #else - 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[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( i + ( ( overlap / 2 ) - tcx_offset ) )], old_out_fx[( i + nz )] ); #endif move16(); } @@ -3232,49 +3232,49 @@ void IMDCT_ivas_fx( FOR( ; i < overlap; i++ ) /* perfectly reconstructing ALDO shortening */ { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], old_out_fx[add( i, nz )] ); + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], old_out_fx[( i + nz )] ); // Q(-2) #endif move16(); } - FOR( i = 0; i < shr( tcx_mdct_window_min_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_min_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( 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[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); // Q(-2) #else - 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[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[i].v.re ) ); #endif move16(); } FOR( ; i < tcx_mdct_window_min_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( sub( add( i, shr( overlap, 1 ) ), tcx_offset ), overlap )] = add_sat( 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[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add_sat( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - 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[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )] = add( xn_buf_fx[( ( ( i + ( overlap / 2 ) ) - tcx_offset ) + overlap )], mult_r( old_out_fx[( ( i + nz ) + overlap )], tcx_mdct_window_minimum_fx[( tcx_mdct_window_min_length - ( 1 + i ) )].v.im ) ); #endif move16(); } } ELSE { - FOR( ; i < sub( overlap, shr( tcx_mdct_window_min_length, 1 ) ); i++ ) + FOR( ; i < ( overlap - ( tcx_mdct_window_min_length / 2 ) ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( ( tcx_mdct_window_min_length - overlap ) + i )].v.re ) ); #endif move16(); } FOR( ; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, sub( shr( overlap, 1 ), tcx_offset ) )] = add_sat( 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[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); // Q(-2) #else - 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[( i + ( ( overlap / 2 ) - tcx_offset ) )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_out_fx[( i + nz )], tcx_mdct_window_minimum_fx[( overlap - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3286,12 +3286,12 @@ void IMDCT_ivas_fx( IF( bfi != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[i].v.re ) ); #endif move16(); @@ -3299,9 +3299,9 @@ void IMDCT_ivas_fx( FOR( ; i < tcx_mdct_window_half_length; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( old_syn_overl_fx[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); #endif move16(); } @@ -3310,7 +3310,7 @@ void IMDCT_ivas_fx( { FOR( i = 0; i < overlap; i++ ) { - xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); + xn_buf_fx[i] = add_sat( xn_buf_fx[i], old_syn_overl_fx[i] ); // Q(-2) move16(); } } @@ -3319,9 +3319,9 @@ void IMDCT_ivas_fx( FOR( i = 0; i < overlap; i++ ) { #ifdef BASOP_NOGLOB - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add_sat( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add_sat( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); // Q(-2) #else - xn_buf_fx[add( i, shr( overlap, 1 ) )] = add( xn_buf_fx[add( i, shr( overlap, 1 ) )], old_syn_overl_fx[i] ); + xn_buf_fx[( i + ( overlap / 2 ) )] = add( xn_buf_fx[( i + ( overlap / 2 ) )], old_syn_overl_fx[i] ); #endif move16(); } @@ -3347,7 +3347,7 @@ void IMDCT_ivas_fx( { 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[( ( nz + overlap ) + i )] = negate( mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ) ); // Q(-2) move16(); } } @@ -3355,7 +3355,7 @@ void IMDCT_ivas_fx( { 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[( ( nz + overlap ) + i )] = mult_r( xn_buf_fx[( L_frame - ( 1 + i ) )], tcx_aldo_window_1_fx[( nz - ( 1 + i ) )] ); // Q(-2) move16(); } } @@ -3378,41 +3378,41 @@ void IMDCT_ivas_fx( { IF( FB_flag != 0 ) { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); 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_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - 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 ) ); // Q(-2) move16(); move16(); } 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_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); // Q(-2) + xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) move16(); move16(); } } ELSE { - FOR( i = 0; i < shr( tcx_mdct_window_half_length, 1 ); i++ ) + FOR( i = 0; i < ( tcx_mdct_window_half_length / 2 ); 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[i].v.im ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - 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 ) ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - 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 ) ); #endif move16(); move16(); } 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = mult_r( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.re ); #ifdef BASOP_NOGLOB - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add_sat( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); // Q(-2) #else - 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[( ( i + ( overlap / 2 ) ) - tcx_offset )] = add( xn_buf_fx[( ( i + ( overlap / 2 ) ) - tcx_offset )], mult_r( mult_r( hTcxDec->syn_Overl[i], tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ), tcx_mdct_window_half_fx[( tcx_mdct_window_half_length - ( 1 + i ) )].v.im ) ); #endif move16(); move16(); @@ -3536,7 +3536,16 @@ void init_tcx_info_fx( } ELSE { - IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, ( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) ? IGF_GRID_LB_TRAN : IGF_GRID_LB_NORM ); + test(); + test(); + IF( st->last_core == ACELP_CORE || ( *left_rect && st->bfi ) ) + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_TRAN ); + } + ELSE + { + IGFDecUpdateInfo_ivas_fx( st->hIGFDec, frame_cnt, IGF_GRID_LB_NORM ); + } } } } @@ -3593,6 +3602,7 @@ void decoder_tcx_IGF_mono_fx( test(); IF( NE_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { + test(); test(); IF( EQ_16( st->last_core, ACELP_CORE ) || ( left_rect && bfi ) ) { @@ -3664,7 +3674,7 @@ void decoder_tcx_IGF_stereo_fx( FOR( sfb = 0; sfb < sfbConf->sfbCnt; sfb++ ) { - set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sfbConf->sfbOffset[sfb + 1] - sfbConf->sfbOffset[sfb] ); + set16_fx( &coreMsMask[sfbConf->sfbOffset[sfb]], ms_mask[k][sfb], sub( sfbConf->sfbOffset[sfb + 1], sfbConf->sfbOffset[sfb] ) ); } test(); @@ -3756,10 +3766,10 @@ void decoder_tcx_IGF_stereo_fx( void decoder_tcx_ivas_fx( Decoder_State *st, Word16 prm[], - Word16 A_fx[], - Word16 Aind[], - Word16 synth_fx[], - Word16 synthFB_fx[], + Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) + Word16 Aind[], // Q: 14 - norm_s(Aind[0]) + Word16 synth_fx[], // Q_syn + Word16 synthFB_fx[], // Q_syn const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) @@ -4038,9 +4048,16 @@ void decoder_tcx_invQ_fx( prm_sqQ = prm_target + 1; move16(); - tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, ( st->bwidth > WB ) ? 1 : 0 ); + IF( GT_32( st->bwidth, WB ) ) + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 ); + } + ELSE + { + tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 ); + } - hTcxDec->resQBits[frame_cnt] = *prm_target - arith_bits; + hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits ); move16(); /* Noise filling seed */ @@ -4098,7 +4115,7 @@ void decoder_tcx_invQ_fx( move16(); } - FOR( i = start_zeroing; i < max( L_frame, L_frameTCX ); i++ ) + FOR( i = start_zeroing; i < s_max( L_frame, L_frameTCX ); i++ ) { x[i] = 0; move32(); @@ -4171,7 +4188,7 @@ void decoder_tcx_invQ_fx( hTcxDec->old_gaintcx_bfi_e = *gain_tcx_e; move16(); - hTcxDec->cummulative_damping_tcx = MAX16B; + hTcxDec->cummulative_damping_tcx = MAX16B; // 1 in Q15 move16(); } ELSE /* bfi = 1 */ @@ -4211,7 +4228,7 @@ void decoder_tcx_invQ_fx( move16(); } - hTcxDec->damping = ONE_IN_Q14; + hTcxDec->damping = ONE_IN_Q14; // Q14 move16(); } ELSE @@ -4257,7 +4274,7 @@ void decoder_tcx_invQ_fx( gamma = add( mult_r( hTcxDec->cummulative_damping_tcx, sub( gamma1, MAX16B ) ), MAX16B ); } - IF( st->element_mode != IVAS_CPE_MDCT ) + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { weight_a_fx( A, Ap, gamma, M ); lpc2mdct_2( Ap, M, NULL, NULL, gainlpc2, gainlpc2_e, FDNS_NPTS ); @@ -4295,7 +4312,7 @@ void decoder_tcx_invQ_fx( move16(); 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 ); // Q15 #else last_gain_syn_deemph_fx = round_fx( tmp32 ); #endif @@ -4689,7 +4706,7 @@ void decoder_tcx_noisefilling_fx( } /* 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->hPlcInfo->subframe = extract_l( L_mult0( frame_cnt, L_frameTCX_glob ) ); move16(); @@ -4904,7 +4921,7 @@ void decoder_tcx_noisefilling_fx( } } - if ( st->igf ) + IF( st->igf ) { *st->hIGFDec->igfData.igfInfo.nfSeed = extract_l( L_add( L_mult0( nf_seed, 31821 ), 13849 ) ); move16(); diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index 66c7440b1..5d9beccff 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -20,9 +20,9 @@ #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 */ + Word16 *sharpFlag, /* o : formant sharpening flag Q0 */ + Word16 *hq_core_type, /* o : HQ core type Q0 */ + Word16 *core_switching_flag /* o : ACELP->HQ switching frame flag Q0 */ ) { Word16 start_idx; @@ -60,24 +60,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( ( 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( st->total_brate != FRAME_NO_DATA ) { - st->cng_type = get_next_indice_fx( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); // Q0 - IF( EQ_16( st->cng_type, LP_CNG ) ) + IF( st->cng_type == LP_CNG ) { st->L_frame = L_FRAME; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( EQ_16( tmp16, 1 ) ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -85,14 +85,14 @@ void decision_matrix_dec_fx( } ELSE { - st->bwidth = get_next_indice_fx( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); // Q0 - tmp16 = get_next_indice_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 move16(); st->L_frame = L_FRAME16k; move16(); - IF( tmp16 == 0 ) + if ( tmp16 == 0 ) { st->L_frame = L_FRAME; move16(); @@ -101,7 +101,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(); @@ -110,7 +110,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( 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(); @@ -128,23 +128,27 @@ 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 ); // Q0 move16(); IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; + move16(); st->last_core = st->core; + move16(); st->last_core_brate = st->core_brate; + move32(); st->last_extl = st->extl; + move16(); } st->vbr_hw_BWE_disable_dec = 1; move16(); - get_next_indice_fx( st, 1 ); + get_next_indice_fx( st, 1 ); // Q0 - ppp_nelp_mode = get_next_indice_fx( st, 2 ); + ppp_nelp_mode = get_next_indice_fx( st, 2 ); // Q0 /* 0 - PPP_NB, 1 - PPP_WB, 2 - NELP_NB, 3 - NELP_WB */ IF( ppp_nelp_mode == 0 ) @@ -201,11 +205,11 @@ void decision_matrix_dec_fx( 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_fx( st, 1 ); + temp_core = get_next_indice_fx( st, 1 ); // Q0 st->core = HQ_CORE; move16(); - IF( temp_core == 0 ) + if ( temp_core == 0 ) { st->core = ACELP_CORE; move16(); @@ -217,7 +221,7 @@ void decision_matrix_dec_fx( * Read ACELP signaling bits from the bitstream *-----------------------------------------------------------------*/ - IF( EQ_16( st->core, ACELP_CORE ) ) + IF( st->core == ACELP_CORE ) { /* find the section in the ACELP signaling table corresponding to bitrate */ start_idx = 0; @@ -231,7 +235,7 @@ void decision_matrix_dec_fx( move16(); start_idx = 0; move16(); - break; + BREAK; } } @@ -242,7 +246,7 @@ void decision_matrix_dec_fx( nBits = extract_l( acelp_sig_tbl[start_idx] ); start_idx = add( start_idx, 1 ); - start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); + start_idx = add( start_idx, get_next_indice_fx( st, nBits ) ); // Q0 IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { ind = 0; @@ -257,17 +261,19 @@ void decision_matrix_dec_fx( move32(); /* convert signaling indice into signaling information */ - st->coder_type = extract_l( L_and( ind, 0x7L ) ); + st->coder_type = extract_l( L_and( ind, 0x7L ) ); // Q0 IF( EQ_16( st->coder_type, LR_MDCT ) ) { st->core = HQ_CORE; move16(); - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); // Q0 + move16(); } 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 ) ); // Q0 + move16(); + *sharpFlag = extract_l( L_and( L_shr( ind, 6 ), 0x1L ) ); // Q0 move16(); } } @@ -292,11 +298,11 @@ void decision_matrix_dec_fx( 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_32k ) && ( st->bwidth == NB ) ) || + ( GE_32( st->total_brate, ACELP_32k ) && !( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) || ( st->coder_type == INACTIVE ) ) ) || + ( LT_32( st->total_brate, ACELP_13k20 ) && ( 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( st->total_brate, ACELP_13k20 ) && EQ_16( st->coder_type, AUDIO ) && ( st->bwidth == NB ) ) ) { st->BER_detect = 0; move16(); @@ -413,7 +419,7 @@ void decision_matrix_dec_fx( test(); 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(); @@ -422,7 +428,7 @@ void decision_matrix_dec_fx( 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_fx( st, 1 ); + tmp16 = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp16, 1 ) ) { st->extl = WB_BWE; @@ -444,7 +450,7 @@ void decision_matrix_dec_fx( { st->extl = SWB_BWE_HIGHRATE; move16(); - IF( EQ_16( st->bwidth, FB ) ) + if ( EQ_16( st->bwidth, FB ) ) { st->extl = FB_BWE_HIGHRATE; move16(); @@ -471,7 +477,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(); @@ -504,6 +510,7 @@ void decision_matrix_dec_fx( /* set core bitrate */ st->core_brate = L_sub( st->total_brate, st->extl_brate ); + move32(); /*-----------------------------------------------------------------* * Read HQ signaling bits from the bitstream @@ -516,11 +523,11 @@ void decision_matrix_dec_fx( IF( NE_16( st->mdct_sw, MODE2 ) ) { /* skip the HQ/TCX core switching flag */ - get_next_indice_tmp_fx( st, 1 ); + get_next_indice_tmp_fx( st, 1 ); // Q0 } /* read ACELP->HQ core switching flag */ - *core_switching_flag = get_next_indice_fx( st, 1 ); + *core_switching_flag = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( *core_switching_flag, 1 ) ) { @@ -530,8 +537,8 @@ void decision_matrix_dec_fx( /* read ACELP L_frame info */ st->last_L_frame = L_FRAME16k; move16(); - tmp16 = get_next_indice_fx( st, 1 ); - IF( tmp16 == 0 ) + tmp16 = get_next_indice_fx( st, 1 ); // Q0 + if ( tmp16 == 0 ) { st->last_L_frame = L_FRAME; move16(); @@ -544,7 +551,7 @@ void decision_matrix_dec_fx( /* read/set band-width (needed for different I/O sampling rate support) */ IF( GT_32( st->total_brate, ACELP_16k40 ) ) { - tmp16 = get_next_indice_fx( st, 2 ); + tmp16 = get_next_indice_fx( st, 2 ); // Q0 IF( tmp16 == 0 ) { @@ -574,7 +581,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( ( GE_32( st->total_brate, ACELP_24k40 ) && EQ_16( st->bwidth, NB ) ) || + IF( ( GE_32( st->total_brate, ACELP_24k40 ) && ( 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; @@ -644,7 +651,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - IF( EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( st->core_brate == FRAME_NO_DATA ) { /* prevent "L_frame" changes in CNG segments */ st->L_frame = st->last_L_frame; @@ -670,14 +677,16 @@ 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 st->extl_orig = st->extl; + move16(); st->extl_brate_orig = st->extl_brate; + move32(); #endif test(); IF( EQ_32( st->output_Fs, 8000 ) ) diff --git a/lib_dec/gs_dec_amr_wb_fx.c b/lib_dec/gs_dec_amr_wb_fx.c index d57411ff4..9778acec0 100644 --- a/lib_dec/gs_dec_amr_wb_fx.c +++ b/lib_dec/gs_dec_amr_wb_fx.c @@ -49,9 +49,9 @@ static void gs_dec_amr_wb_fx( const long core_brate, Word16 *seed_tcx, const Wor *-------------------------------------------------------------------*/ 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 */ + Word16 *exc_diffQ_fx, /* i/o: Noise per band Q_out*/ + Word16 *seed_tcx, /* i : Seed for noise Q0*/ + const Word16 Mbands_gn, /* i : number of bands Q0*/ const Word16 Q_out /* i : Q of exc_diffQ_fx[] */ ) { @@ -60,16 +60,16 @@ static void NoiseFill_fx( Word16 fact; CurBin = 0; move16(); - fact = shr( 24576 /*0.75f*/, sub( 15, Q_out ) ); + fact = shr( 24576 /*0.75f in Q15*/, sub( 15, Q_out ) ); /* Q_out */ FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { EndBin = add( CurBin, crit_bins[i_band] ); FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( Random( seed_tcx ), fact ); - L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( Random( seed_tcx ), fact ); /* Q15 + Q_out + 1 */ + L_temp = L_msu( L_temp, exc_diffQ_fx[CurBin], -32768 ); /* Q15 + Q_out + 1*/ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -84,9 +84,9 @@ static void NoiseFill_fx( *-------------------------------------------------------------------*/ static void Ener_per_band_fx( - const Word16 exc_diff_fx[], /* i : target signal */ - const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ - Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16 */ + const Word16 exc_diff_fx[], /* i : target signal exp(exc_diff_exp)*/ + const Word16 exc_diff_exp, /* i : Exponent of exc_diff_fx */ + Word32 y_gain4_fx[] /* o : Energy per band to quantize Q16*/ ) { const Word16 *ptr16; @@ -96,29 +96,29 @@ static void Ener_per_band_fx( exp = shl( exc_diff_exp, 1 ); /* To Get 0.01f in Q of (exc_diff_exp-1)^2 */ - L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); + L_epsilon = L_shr( 42949673L, sub( 32 + ENER_FX_Q_GUARD * 2, exp ) ); /* Q16 */ ptr16 = exc_diff_fx; FOR( j = 0; j < CRIT_NOIS_BAND; j++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_epsilon, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_epsilon, temp, temp ); /* Q16 */ FOR( i = 1; i < crit_bins[j]; i++ ) { - temp = shr( *ptr16++, ENER_FX_Q_GUARD ); - L_temp = L_mac0( L_temp, temp, temp ); + temp = shr( *ptr16++, ENER_FX_Q_GUARD ); /* Q15 - exc_diff_exp + Q1 */ + L_temp = L_mac0( L_temp, temp, temp ); /* Q16 */ } L_temp2 = L_mult0( 1, 6554 ); /* sqrt of 0.01f in Q16*/ IF( L_temp != 0 ) /* avoid executing sqrt of 0 (because a div_s is used to invert and then call inv_sqrt) */ { L_temp2 = Sqrt_Ratio32( L_temp, exp, 1, 0, &i ); #ifdef BASOP_NOGLOB - L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); + L_temp2 = L_shr_sat( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); /* Q16 */ #else L_temp2 = L_shr( L_temp2, sub( 15 - ENER_FX_Q_GUARD, i ) ); #endif } - y_gain4_fx[j] = L_temp2; + y_gain4_fx[j] = L_temp2; /* Q16 */ move32(); } @@ -133,9 +133,9 @@ static void Ener_per_band_fx( *-------------------------------------------------------------------*/ static void Apply_gain_fx( - Word16 exc_diffQ_fx[], /* i/o: Quantized excitation */ - Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band */ - Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector */ + Word16 exc_diffQ_fx[], /* i/o: Quantized excitation Qx*/ + Word32 L_Ener_per_bd_iQ[], /* i : Target ener per band Q16*/ + Word32 L_Ener_per_bd_yQ[] /* i : Ener per band for norm vector Qx*/ , const Word16 Q_out ) { @@ -154,11 +154,11 @@ static void Apply_gain_fx( move16(); FOR( i_band = 0; i_band < CRIT_NOIS_BAND; i_band++ ) { - EndBin = add( CurBin, crit_bins[i_band] ); + EndBin = add( CurBin, crit_bins[i_band] ); /* Q0 */ y_gain_exp = norm_l( L_Ener_per_bd_yQ[i_band] ); exp3 = norm_l( L_Ener_per_bd_iQ[i_band] ); /* use 'exp3' as temporary exponent of 'L_Ener_per_bd_iQ[]' */ #ifdef BASOP_NOGLOB - y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); + y_gain_fx = round_fx_sat( Div_flt32_flt32( L_shl_sat( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl_sat( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); /* y_gain_exp - 31 + Q_out */ #else y_gain_fx = round_fx( Div_flt32_flt32( L_shl( L_Ener_per_bd_iQ[i_band], exp3 ), exp3, L_shl( L_Ener_per_bd_yQ[i_band], y_gain_exp ), y_gain_exp, &y_gain_exp ) ); #endif @@ -172,9 +172,9 @@ static void Apply_gain_fx( { FOR( ; CurBin < EndBin; CurBin++ ) { - L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); - L_temp = L_shr( L_temp, y_gain_exp ); - exc_diffQ_fx[CurBin] = round_fx( L_temp ); + L_temp = L_mult( exc_diffQ_fx[CurBin], y_gain_fx ); /* Q16 + Q_out + y_gain_exp */ + L_temp = L_shr( L_temp, y_gain_exp ); /* Q_out + 16 */ + exc_diffQ_fx[CurBin] = round_fx( L_temp ); /* Q_out */ move16(); } } @@ -190,29 +190,29 @@ static void Apply_gain_fx( *-------------------------------------------------------------------*/ static void normalize_spec_fx( - Word16 fac_up_fx, /* i : Core bitrate (Q8) */ - Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8) */ - const Word16 L_frame, /* i : Section lenght */ - const Word16 Q_out /* i : Q of fy_norm_fx[] */ + Word16 fac_up_fx, /* i : Core bitrate (Q8)*/ + Word16 fy_norm_fx[], /* i/o: Frequency quantized parameter (Q8)*/ + const Word16 L_frame, /* i : Section lenght Q0*/ + const Word16 Q_out /* i : Q of fy_norm_fx[] */ ) { Word16 idx, j; Word32 L_temp; Word16 temp, exp; - idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); + idx = emaximum_fx( 0 /* Exponent is not Important */, fy_norm_fx, L_frame, &L_temp ); /* Q0 */ exp = sub( Q_out, 8 /*Q8 of Fac Up/down*/ ); - temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); - L_temp = L_mult( temp, fac_up_fx ); + temp = Invert16( abs_s( fy_norm_fx[idx] ), &exp ); /* Q15 + exp */ + L_temp = L_mult( temp, fac_up_fx ); /* Q15 + exp + Q8 + 1 */ exp = sub( 15, exp ); #ifdef BASOP_NOGLOB - L_temp = L_shl_sat( L_temp, exp ); + L_temp = L_shl_sat( L_temp, exp ); /* Q24 + Q_out */ #else L_temp = L_shl( L_temp, exp ); #endif FOR( j = 0; j < L_frame; j++ ) { - fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); + fy_norm_fx[j] = round_fx( Mult_32_16( L_temp, fy_norm_fx[j] ) ); /* Q_out */ move16(); } @@ -226,16 +226,16 @@ static void normalize_spec_fx( *-------------------------------------------------------------------*/ static void gs_dec_amr_wb_fx( - const long core_brate, /* i : bitrate allocated to the core */ - Word16 *seed_tcx, /* i/o: seed used for noise generation */ - const Word16 dct_in_fx[], /* i : cdt of residual signal */ + const long core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: seed used for noise generation Q0*/ + const Word16 dct_in_fx[], /* i : cdt of residual signal Q_dct_in*/ const Word16 Q_dct_in, /* i : Exponent of dct_in_fx */ - Word16 dct_out_fx[], /* o : dct of pitch only excitation */ + Word16 dct_out_fx[], /* o : dct of pitch only excitation Q_dct_out*/ Word16 Q_dct_out, /* o : Exponent of dct_out_fx */ - const Word16 pitch_fx[], /* i : pitch buffer */ - const Word16 voice_fac, /* i : gain pitch Q15 */ - const Word16 clas, /* i : signal frame class */ - const Word16 coder_type /* i : coder type */ + const Word16 pitch_fx[], /* i : pitch buffer Q6*/ + const Word16 voice_fac, /* i : gain pitch Q15*/ + const Word16 clas, /* i : signal frame class Q0*/ + const Word16 coder_type /* i : coder type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -266,7 +266,7 @@ static void gs_dec_amr_wb_fx( FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { #ifdef BASOP_NOGLOB - temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); + temp = s_max( round_fx_sat( Ener_per_bd_iQ_fx[i] ), temp ); /* Q0 */ #else temp = s_max( round_fx( Ener_per_bd_iQ_fx[i] ), temp ); #endif @@ -278,7 +278,7 @@ static void gs_dec_amr_wb_fx( { FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); + Ener_per_bd_iQ_fx[i] = Mult_32_16( Ener_per_bd_iQ_fx[i], crit_bins_corr_fx[i] ); /* Q16 */ move32(); } } @@ -287,16 +287,16 @@ static void gs_dec_amr_wb_fx( /*--------------------------------------------------------------------------------------* * Find the lenght of the temporal contribution, with a minimum contribution of 1.2kHz *--------------------------------------------------------------------------------------*/ - temp = s_min( pitch_fx[0], pitch_fx[1] ); - temp = s_min( temp, pitch_fx[2] ); - temp = s_min( temp, pitch_fx[3] ); + temp = s_min( pitch_fx[0], pitch_fx[1] ); /* Q6 */ + temp = s_min( temp, pitch_fx[2] ); /* Q6 */ + temp = s_min( temp, pitch_fx[3] ); /* Q6 */ /* etmp14 = 12800.0f/(temp/16.0f)*8.0f */ exp = 6; /* Pitch in Q6*/ move16(); - temp = Invert16( temp, &exp ); - L_temp = L_mult( temp, 12800 ); - L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ + temp = Invert16( temp, &exp ); /* Q15 */ + L_temp = L_mult( temp, 12800 ); /* Q15 */ + L_temp = L_shl( L_temp, sub( 3, exp ) ); /* *8.0f */ /* Q15 */ #ifdef ADD_IVAS_GS_DEC_IMPR test(); test(); @@ -305,27 +305,27 @@ static void gs_dec_amr_wb_fx( if ( GE_32( core_brate, ACELP_12k65 ) ) #endif { - L_temp = L_shl( L_temp, 1 ); + L_temp = L_shl( L_temp, 1 ); /* Q16 */ } /* (Word16)(etmp14+0.5f) */ - mDiff_len = round_fx( L_temp ); + mDiff_len = round_fx( L_temp ); /* Q0 */ temp = 32767; move16(); L_temp = L_deposit_l( 0 ); FOR( i = 0; i < CRIT_NOIS_BAND; i++ ) { - temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); - temp2 = abs_s( temp2 ); + temp2 = sub( crit_bands_loc_fx[i], mDiff_len ); /* Q0 */ + temp2 = abs_s( temp2 ); /* Q0 */ if ( GT_16( temp, temp2 ) ) { - L_temp = L_msu( L_temp, crit_bins[i], -32768 ); + L_temp = L_msu( L_temp, crit_bins[i], -32768 ); /* Q16 */ } - temp = s_min( temp, temp2 ); + temp = s_min( temp, temp2 ); /* Q0 */ } - mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); + mDiff_len = s_max( round_fx( L_temp ), BIN_1k2 ); /* Q0 */ #ifdef ADD_IVAS_GS_DEC_IMPR @@ -334,12 +334,12 @@ static void gs_dec_amr_wb_fx( Copy( dct_in_fx, exc_diffQ, L_FRAME ); /* normalization of the spectrum and noise fill */ - normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, L_FRAME - mDiff_len, NORMALIZE_SPECS_Q_OUT ); + normalize_spec_fx( 1 * 256, exc_diffQ + mDiff_len, sub( L_FRAME, mDiff_len ), NORMALIZE_SPECS_Q_OUT ); } ELSE #endif { - Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); + Copy( dct_in_fx, exc_diffQ_fx, mDiff_len ); /* Q_dct_in */ set16_fx( exc_diffQ_fx + mDiff_len, 0, sub( L_FRAME, mDiff_len ) ); /* normalization of the spectrum and noise fill*/ @@ -356,7 +356,7 @@ static void gs_dec_amr_wb_fx( * Compute tilt factor and amplify HF accordingly *--------------------------------------------------------------------------------------*/ - temp = mult_r( sub( 32767, voice_fac ), 16384 ); /* Q15 */ + temp = mult_r( sub( 32767 /* 1.0 in Q15 */, voice_fac ), 16384 /* 0.5 in Q15 */ ); /* Q15 */ FOR( i = 240; i < L_FRAME; i++ ) { temp2 = msu_r( -7680 * 65536, -17564, shl( i, 6 ) ); /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */ @@ -374,7 +374,7 @@ static void gs_dec_amr_wb_fx( * Copy to the output vector *--------------------------------------------------------------------------------------*/ - Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); + Copy( exc_diffQ_fx, dct_out_fx, L_FRAME ); /* Q_dct_out */ return; } @@ -386,24 +386,24 @@ 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 Q0*/ + const Word16 coder_type, /* i : coder type Q0*/ + const Word32 core_brate, /* i : bitrate allocated to the core Q0*/ + Word16 *seed_tcx, /* i/o: Seed used for noise generation Q0*/ + Word16 *old_Aq_fx, /* i/o: old LPC filter coefficient q_old_Aq*/ + Word16 *mem_syn2_fx, /* i/o: synthesis memory Q_syn*/ + const Word16 lt_voice_fac_fx, /* i/o: long term voice factor Q14*/ + const Word16 locattack, /* i : Flag for a detected attack Q0*/ + Word16 *Aq_fx, /* i/o: Decoded LP filter coefficient q_Aq*/ + Word16 *exc2_fx, /* i/o: Decoded complete excitation Q_exc2*/ + const Word16 Q_exc2, /* i : Exponent of Exc2 */ + Word16 *mem_tmp_fx, /* i/o: synthesis temporary memory Q_syn*/ + Word16 *syn_fx, /* o: Decoded synthesis to be updated Q_syn*/ + const Word16 Q_syn, /* i : Synthesis scaling */ + const Word16 *pitch_buf_fx, /* i : Decoded pitch buffer Q6*/ + const Word16 Last_ener_fx, /* i : Last energy (Q8) Q0*/ + const Word16 rate_switching_reset, /* i : rate switching reset flag Q0*/ + const Word16 last_coder_type /* i : Last coder_type Q0*/ #ifdef ADD_IVAS_GS_DEC_IMPR , const Word16 VeryLowRateSTflag /* i : Enable the noise enhancement for very low rate stereo generic mode */ @@ -449,7 +449,7 @@ 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] ) ); /* Q0 */ move16(); /* last_coder_type == UNVOICED should be understand as INACTIVE, but it is forced to UNVOICED in update_dec */ test(); @@ -460,36 +460,36 @@ void improv_amr_wb_gs_fx( 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 ) ); /* q_Aq */ - exp_a = norm_s( Aq_fx[imult1616( i, ( M + 1 ) )] ); - exp_b = norm_s( old_Aq_fx[imult1616( i, ( 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 ) { - Scale_sig( &old_Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), negate( exp_diff ) ); + Scale_sig( &old_Aq_fx[i * ( M + 1 )], ( M + 1 ), negate( exp_diff ) ); /* exp_b */ } ELSE { - Scale_sig( &Aq_fx[imult1616( i, ( M + 1 ) )], ( M + 1 ), exp_diff ); + Scale_sig( &Aq_fx[i * ( M + 1 )], ( M + 1 ), exp_diff ); /* exp_a */ } - FOR( j = imult1616( i, ( M + 1 ) ); j < imult1616( add( 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] ) ); /* q_Aq */ move16(); } } /* check the smoothed LP filter stability */ - enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); + enr_LP_old = Enr_1_Az_fx( old_Aq_fx, L_SUBFR ); /* Q3 */ Overflow = 0; move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); + enr_LP_new = Enr_1_Az_fx_o( Aq_fx + imult1616( i, ( M + 1 ) ), L_SUBFR, &Overflow ); /* Q3 */ #else enr_LP_new = Enr_1_Az_fx( Aq_fx + i * ( M + 1 ), L_SUBFR ); #endif @@ -497,14 +497,14 @@ void improv_amr_wb_gs_fx( IF( GT_16( 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 ) ); /* q_Aq */ Overflow = 0; move16(); return; } - enr_LP_old = enr_LP_new; + enr_LP_old = enr_LP_new; /* Q3 */ move16(); } } @@ -527,7 +527,7 @@ void improv_amr_wb_gs_fx( * Redo core synthesis at 12k8 Hz with the modified excitation *------------------------------------------------------------*/ - Copy( mem_tmp_fx, mem_syn2_fx, M ); + Copy( mem_tmp_fx, mem_syn2_fx, M ); /* Q_syn */ syn_12k8_fx( L_FRAME, Aq_fx, exc2_fx, syn_fx, mem_syn2_fx, 1, Q_exc2, Q_syn ); } diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 9a10f0862..7af4b5c40 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -34,14 +34,14 @@ /*==========================================================================*/ 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 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + 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*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , Word16 *gain_buf /*Q14*/ ) @@ -71,7 +71,7 @@ void decod_audio_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -83,7 +83,7 @@ void decod_audio_fx( ( 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_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -92,9 +92,9 @@ void decod_audio_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); - st_fx->GSC_noisy_speech = 0; + st_fx->GSC_noisy_speech = 0; /* Q0 */ move16(); } /* set bit-allocation */ @@ -114,11 +114,11 @@ void decod_audio_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #ifdef ADD_LRTD if ( st_fx->GSC_IVAS_mode >= 1 ) @@ -144,12 +144,12 @@ void decod_audio_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -165,7 +165,7 @@ void decod_audio_fx( else #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); nb_subfr = SWNB_SUBFR; move16(); @@ -180,12 +180,12 @@ void decod_audio_fx( nbits = 2; } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); IF( s_and( nb_frame_flg, 0x1 ) == 0 ) { - nb_subfr = 2 * SWNB_SUBFR; + nb_subfr = 2 * SWNB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); @@ -216,29 +216,29 @@ void decod_audio_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type == INACTIVE ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -246,26 +246,26 @@ void decod_audio_fx( { 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; /* Q0 */ + 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 ); /* Q0 */ } /* 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; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -288,7 +288,7 @@ void decod_audio_fx( #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 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { @@ -296,7 +296,7 @@ void decod_audio_fx( move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -312,28 +312,28 @@ void decod_audio_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -346,18 +346,18 @@ void decod_audio_fx( * 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 ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -366,7 +366,7 @@ void decod_audio_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -374,47 +374,47 @@ void decod_audio_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + 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 ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } ELSE { /* No adaptive (pitch) excitation contribution */ - st_fx->bpf_off = 1; + st_fx->bpf_off = 1; /* Q0 */ move16(); set16_fx( dct_epit, 0, st_fx->L_frame ); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, L_SUBFR16k * 64, NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -434,7 +434,7 @@ void decod_audio_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #ifdef IVAS_CODE if ( st_fx->extl_brate_fx_orig > 0 ) @@ -443,7 +443,7 @@ void decod_audio_fx( #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 ); /* Q0 */ } @@ -456,7 +456,7 @@ void decod_audio_fx( if ( 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 ); /* Q0 */ } #ifdef ADD_LRTD @@ -502,8 +502,8 @@ void decod_audio_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -537,21 +537,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 : Word16 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 */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 dct_epit[], /* o : GSC excitation in DCT domain Qx*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *lsf_new /* i : ISFs at the end of the frame Qx*/ , 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_lp_reuse_flag, /* i : LPC reuse flag Q0*/ + const Word16 tdm_low_rate_mode, /* i : secondary channel low rate mode flag Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6*/ ) { Word16 tmp_nb_bits_tot, pit_band_idx; @@ -579,7 +579,7 @@ void decod_audio_ivas_fx( move16(); /* decode GSC attack flag (used to reduce possible pre-echo) */ - gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); + gsc_attack_flag = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); /* decode GSC SWB speech flag */ @@ -597,7 +597,7 @@ void decod_audio_ivas_fx( ( 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 ) ) ) ) #endif { - st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); + st_fx->GSC_noisy_speech = (Word16) get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } @@ -606,7 +606,7 @@ void decod_audio_ivas_fx( test(); IF( st_fx->GSC_noisy_speech && LT_16( st_fx->bwidth, SWB ) && st_fx->GSC_IVAS_mode == 0 ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); st_fx->GSC_noisy_speech = 0; move16(); @@ -628,11 +628,11 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->GSC_noisy_speech, 1 ) ) #endif { - nb_subfr = NB_SUBFR; + nb_subfr = NB_SUBFR; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); #if 1 // def ADD_LRTD IF( GE_16( st_fx->GSC_IVAS_mode, 1 ) ) @@ -640,20 +640,20 @@ void decod_audio_ivas_fx( test(); if ( LT_32( st_fx->core_brate, GSC_L_RATE_STG ) && LT_32( st_fx->GSC_IVAS_mode, 3 ) ) { - nb_subfr = 2; + nb_subfr = 2; /* Q0 */ move16(); } - hGSCDec->noise_lev = NOISE_LEVEL_SP2; + hGSCDec->noise_lev = NOISE_LEVEL_SP2; /* Q0 */ move16(); IF( EQ_16( st_fx->GSC_IVAS_mode, 3 ) ) /* Music like */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ move16(); } ELSE IF( st_fx->GSC_noisy_speech == 0 ) /* speech like but not noisy */ { - hGSCDec->noise_lev = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; /* Q0 */ move16(); } } @@ -663,12 +663,12 @@ void decod_audio_ivas_fx( { IF( LE_32( st_fx->core_brate, ACELP_8k00 ) ) { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 2 ), NOISE_LEVEL_SP2 ); /* Q0 */ move16(); } ELSE { - hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); + hGSCDec->noise_lev = add( (Word16) get_next_indice_fx( st_fx, 3 ), NOISE_LEVEL_SP0 ); /* Q0 */ move16(); } @@ -682,30 +682,30 @@ void decod_audio_ivas_fx( { hGSCDec->cor_strong_limit = 0; move16(); - nb_subfr = 1; + nb_subfr = 1; /* Q0 */ move16(); } ELSE #endif { - hGSCDec->cor_strong_limit = 1; + hGSCDec->cor_strong_limit = 1; /* Q0 */ move16(); - nb_subfr = SWNB_SUBFR; + nb_subfr = SWNB_SUBFR; /* Q0 */ move16(); IF( GE_32( st_fx->core_brate, ACELP_9k60 ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); #if 1 // def ADD_LRTD test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && GE_32( st_fx->core_brate, MIN_RATE_4SBFR ) ) { - nbits = 2; + nbits = 2; /* Q0 */ move16(); } #endif - nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); + nb_frame_flg = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); test(); @@ -725,7 +725,7 @@ void decod_audio_ivas_fx( if ( EQ_16( shr( nb_frame_flg, 1 ), 1 ) ) { - nb_subfr = shl( nb_subfr, 1 ); + nb_subfr = shl( nb_subfr, 1 ); /* Q0 */ } #endif } @@ -735,7 +735,7 @@ void decod_audio_ivas_fx( test(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) && EQ_16( nb_subfr, NB_SUBFR ) ) { - nb_subfr = NB_SUBFR16k; + nb_subfr = NB_SUBFR16k; /* Q0 */ move16(); } #endif @@ -745,29 +745,29 @@ void decod_audio_ivas_fx( IF( LT_32( st_fx->core_brate, CFREQ_BITRATE ) ) { - nbits = 3; + nbits = 3; /* Q0 */ move16(); test(); if ( LT_32( st_fx->core_brate, ACELP_9k60 ) && ( st_fx->coder_type == INACTIVE ) ) { - nbits = 1; + nbits = 1; /* Q0 */ move16(); } } ELSE { - nbits = 4; + nbits = 4; /* Q0 */ move16(); } test(); IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && st_fx->coder_type != INACTIVE ) { - pit_band_idx = 1; + pit_band_idx = 1; /* Q0 */ move16(); } ELSE { - pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); + pit_band_idx = (Word16) get_next_indice_fx( st_fx, nbits ); /* Q0 */ move16(); } @@ -775,26 +775,26 @@ void decod_audio_ivas_fx( { 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; /* Q0 */ + 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 ); /* Q0 */ } /* 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; + pit_band_idx = 13; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); } - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); @@ -824,15 +824,15 @@ void decod_audio_ivas_fx( #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 )]; /* Q0 */ move16(); if ( st_fx->element_mode > EVS_MONO ) { - nbits = 5; + nbits = 5; /* Q0 */ move16(); } - indice = get_next_indice_fx( st_fx, nbits ); + indice = get_next_indice_fx( st_fx, nbits ); /* Q0 */ Es_pred_dec_fx( &Es_pred, indice, nbits, 0 ); } @@ -848,28 +848,28 @@ void decod_audio_ivas_fx( IF( LT_16( low_pit, 64 ) ) { - pit_band_idx = 9 + BAND1k2; + pit_band_idx = 9 + BAND1k2; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - pit_band_idx = 7 + BAND1k2; + pit_band_idx = 7 + BAND1k2; /* Q0 */ move16(); } } ELSE IF( LT_16( low_pit, 128 ) ) { - pit_band_idx = 5 + BAND1k2; + pit_band_idx = 5 + BAND1k2; /* Q0 */ move16(); } ELSE { - pit_band_idx = 3 + BAND1k2; + pit_band_idx = 3 + BAND1k2; /* Q0 */ move16(); } - Diff_len = mfreq_loc_div_25[pit_band_idx]; + Diff_len = mfreq_loc_div_25[pit_band_idx]; /* Q0 */ move16(); - hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; /* Q0 */ move16(); } @@ -882,18 +882,18 @@ void decod_audio_ivas_fx( * 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 ); /* Q0 */ if ( st_fx->bwidth == NB ) { - max_len = sub( 160, Diff_len ); + max_len = sub( 160, Diff_len ); /* Q0 */ } Len = 80; move16(); if ( LT_16( max_len, 80 ) ) { - Len = max_len; + Len = max_len; /* Q0 */ move16(); } @@ -902,7 +902,7 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + dct_epit[i + Diff_len] = 0; move16(); } } @@ -910,23 +910,23 @@ void decod_audio_ivas_fx( { FOR( i = 0; i < Len; i++ ) { - dct_epit[add( i, Diff_len )] = mult_r( dct_epit[add( i, Diff_len )], sm_table_fx[i] ); + dct_epit[i + Diff_len] = mult_r( dct_epit[i + Diff_len], sm_table_fx[i] ); /* Qx */ move16(); } FOR( ; i < max_len; i++ ) { - dct_epit[add( i, Diff_len )] = 0; + 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 ); + st_fx->bfi_pitch_fx = mean_fx( pitch_buf, nb_subfr ); /* Q6 */ move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); - Diff_len = add( Diff_len, 1 ); + Diff_len = add( Diff_len, 1 ); /* Q0 */ st_fx->bpf_off = 0; move16(); } @@ -939,18 +939,18 @@ void decod_audio_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - set16_fx( pitch_buf, shl( L_SUBFR16k, 6 ), NB_SUBFR16k ); + set16_fx( pitch_buf, ( L_SUBFR16k * 64 ), NB_SUBFR16k ); } ELSE { - set16_fx( pitch_buf, shl( L_SUBFR, 6 ), NB_SUBFR ); + set16_fx( pitch_buf, L_SUBFR * 64, NB_SUBFR ); } set16_fx( gain_buf, 0, NB_SUBFR16k ); - st_fx->bfi_pitch_fx = shl( L_SUBFR, 6 ); + st_fx->bfi_pitch_fx = L_SUBFR * 64; move16(); - st_fx->bfi_pitch_frame = st_fx->L_frame; + st_fx->bfi_pitch_frame = st_fx->L_frame; /* Q0 */ move16(); st_fx->lp_gainp_fx = 0; move16(); @@ -970,7 +970,7 @@ void decod_audio_ivas_fx( /* find the current total number of bits used */ - tmp_nb_bits_tot = st_fx->next_bit_pos; + tmp_nb_bits_tot = st_fx->next_bit_pos; /* Q0 */ move16(); #if 1 // def IVAS_CODE if ( st_fx->extl_brate_orig > 0 ) @@ -979,7 +979,7 @@ void decod_audio_ivas_fx( #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 ); /* Q0 */ } @@ -991,16 +991,16 @@ void decod_audio_ivas_fx( 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 ); /* Q0 */ } #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 ); + tmp_nb_bits_tot = add( tmp_nb_bits_tot, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); /* Q0 */ 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 ); /* Q0 */ } } #endif @@ -1012,11 +1012,11 @@ void decod_audio_ivas_fx( Q_exc_old = sub( Q_exc_old, st_fx->Q_exc ); IF( st_fx->hGSCDec ) { - Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); + Scale_sig( st_fx->hGSCDec->last_exc_dct_in_fx, L_FRAME16k, Q_exc_old ); /* Q_exc_old */ } IF( bwe_exc ) { - Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); + Scale_sig( bwe_exc - PIT16k_MAX * 2, ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2, Q_exc_old ); /* Q_exc_old */ } } /*--------------------------------------------------------------------------------------* @@ -1051,8 +1051,8 @@ void decod_audio_ivas_fx( * Updates *--------------------------------------------------------------------------------------*/ - Copy( exc, exc2, st_fx->L_frame ); - Copy( exc_wo_nf, exc, st_fx->L_frame ); + Copy( exc, exc2, st_fx->L_frame ); /* Q_exc */ + Copy( exc_wo_nf, exc, st_fx->L_frame ); /* Q_exc */ /*--------------------------------------------------------------------------------------* * Channel aware mode parameters @@ -1088,15 +1088,15 @@ void decod_audio_ivas_fx( /*==========================================================================*/ 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 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1127,6 +1127,8 @@ void gsc_dec_fx( Word16 seed_init; GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; + move16(); + move16(); move16(); // for Mbands_gn move16(); // for Qexc_diffQ @@ -1164,8 +1166,8 @@ 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*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + 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*/ @@ -1202,7 +1204,7 @@ void gsc_dec_fx( 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 - 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 ); + 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 ); /* Q12 */ #endif st_fx->lp_gainc_fx = mult_r( 640, mean_gain ); /*10 in Q6 x Q12 -> lp_gainc in Q3 */ move16(); @@ -1239,13 +1241,13 @@ void gsc_dec_fx( 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_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1271,7 +1273,7 @@ void gsc_dec_fx( #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 ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1290,34 +1292,34 @@ void gsc_dec_fx( /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + j * 16, exc_diffQ + max_ener_band[j] * 16, 16 ); + Copy( concat_out + shl( j, 4 ), exc_diffQ + shl( max_ener_band[j], 4 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } 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 */ { - FOR( j = 0; j < shl( nb_subbands, 4 ); j++ ) + FOR( j = 0; j < nb_subbands * 16; j++ ) { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { - seed_init = add( seed_init, 3 ); + seed_init = add( seed_init, 3 ); /* Q0 */ move16(); } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1325,18 +1327,18 @@ void gsc_dec_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ 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 ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1413,15 +1415,15 @@ void gsc_dec_fx( /*==========================================================================*/ 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 exc_dct_in[], /* i/o: dct of pitch-only excitation / total excitation Q_exc*/ + const Word16 pit_band_idx, /* i : bin position of the cut-off frequency ` Q0*/ + const Word16 Diff_len, /* i : Lenght of the difference signal (before pure spectral) Q0*/ + const Word16 bits_used, /* i : Number of bit used before frequency Q Q0*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + const Word16 coder_type, /* i : coding type Q0*/ + Word16 *last_bin, /* i : last bin of bit allocation Q0*/ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx*/ + Word16 *exc_wo_nf, /* o : excitation (in f domain) without noisefill Q_exc*/ Word16 *Q_exc ) { Word16 i, j, bit, nb_subbands, pvq_len; @@ -1470,12 +1472,12 @@ void gsc_dec_ivas_fx( test(); if ( 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 ); /* Q0 */ } if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - Mbands_gn = MBANDS_GN16k; + Mbands_gn = MBANDS_GN16k; /* Q0 */ move16(); } #endif @@ -1489,8 +1491,8 @@ void gsc_dec_ivas_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*/ + Copy( hGSCDec->old_y_gain_fx, Ener_per_bd_iQ, Mbands_gn ); /* Q_old_gain */ + 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*/ @@ -1512,7 +1514,7 @@ void gsc_dec_ivas_fx( { break; } - i = add( i, 1 ); + i++; } test(); @@ -1521,9 +1523,9 @@ void gsc_dec_ivas_fx( if ( 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 = sub( i, 1 ); + 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 ); /* Q3 */ #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 ); @@ -1563,13 +1565,13 @@ void gsc_dec_ivas_fx( 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_mac( L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554 ); /* Q10 */ + hGSCDec->Last_GSC_spectrum_fx[i] = round_fx( L_tmp ); /*Q10*/ move16(); } } - Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); + Copy( hGSCDec->Last_GSC_spectrum_fx, exc_diffQ, st_fx->L_frame ); /* Q10 */ FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -1595,7 +1597,7 @@ void gsc_dec_ivas_fx( #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 ) ); + Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_PVQ_OUT, Q_tmp ) ); /* Q_PVQ_OUT */ } seed_init = 0; move16(); @@ -1603,7 +1605,7 @@ void gsc_dec_ivas_fx( #if 1 // def ADD_LRTD max_eq = 0; move16(); - max_eq_val = 32767; + max_eq_val = 32767; /* 1.0f in Q15 */ move16(); test(); @@ -1616,7 +1618,7 @@ void gsc_dec_ivas_fx( Word16 temp_max_eq = add( abs_s( concat_out[j] ), 10 ) /*0.01f in Q10*/; if ( LE_16( temp_max_eq, ONE_IN_Q10 ) ) { - max_eq = max_eq_val; + max_eq = max_eq_val; /* Q15 */ move16(); } ELSE @@ -1624,22 +1626,22 @@ void gsc_dec_ivas_fx( Word16 exp = 5; move16(); max_eq = Inv16( temp_max_eq, &exp ); - max_eq = shl( max_eq, exp ); + max_eq = shl( max_eq, exp ); /* Q15 */ } } #endif /* Reorder Q bands */ FOR( j = 0; j < nb_subbands; j++ ) { - Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); + Copy( concat_out + imult1616( j, 16 ), exc_diffQ + imult1616( max_ener_band[j], 16 ), 16 ); /* Q_PVQ_OUT */ - *last_bin = s_max( *last_bin, max_ener_band[j] ); + *last_bin = s_max( *last_bin, max_ener_band[j] ); /* Q0 */ move16(); - bitallocation_band[max_ener_band[j]] = 1; + bitallocation_band[max_ener_band[j]] = 1; /* Q0 */ move16(); - seed_init = add( seed_init, inpulses_fx[j] ); + seed_init = add( seed_init, inpulses_fx[j] ); /* Q0 */ } test(); IF( NE_16( st_fx->last_coder_type, AUDIO ) /* First audio frame */ @@ -1649,19 +1651,19 @@ void gsc_dec_ivas_fx( { IF( concat_out[j] > 0 ) { - seed_init = extract_l( L_shl( seed_init, 3 ) ); + seed_init = extract_l( L_shl( seed_init, 3 ) ); /* Q0 */ } if ( concat_out[j] < 0 ) { #ifdef BASOP_NOGLOB_TMP_715 - seed_init = add_sat( seed_init, 3 ); + seed_init = add_sat( seed_init, 3 ); /* Q0 */ #else seed_init = add( seed_init, 3 ); #endif } } - hGSCDec->seed_tcx = seed_init; + hGSCDec->seed_tcx = seed_init; /* Q0 */ move16(); } test(); @@ -1669,18 +1671,18 @@ void gsc_dec_ivas_fx( { if ( exc_diffQ[L_FRAME8k - 2] != 0 ) { - bitallocation_exc[0] = 1; + bitallocation_exc[0] = 1; /* Q0 */ move16(); } if ( exc_diffQ[L_FRAME8k - 1] != 0 ) { - bitallocation_exc[1] = 1; + bitallocation_exc[1] = 1; /* Q0 */ 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 ); /* Q_PVQ_OUT */ /*--------------------------------------------------------------------------------------* * Skip adaptive (pitch) contribution frequency band (no noise added over the time contribution) @@ -1698,7 +1700,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1708,7 +1710,7 @@ void gsc_dec_ivas_fx( { // PMT("GSC FIX point to be done here") // exc_diffQ[i] *= max_eq; - exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); + exc_diffQ[i] = mult_r( exc_diffQ[i], max_eq ); /* Q_PVQ_OUT */ move16(); } } @@ -1744,12 +1746,12 @@ void GSC_dec_init( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ hGSCDec->cor_strong_limit = 1; move16(); move16(); - hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; /* Q0 */ hGSCDec->Last_GSC_pit_band_idx = 0; move16(); move16(); @@ -1778,7 +1780,7 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx = 15687; + hGSCDec->seed_tcx = 15687; /* Q0 */ move16(); hGSCDec->cor_strong_limit = 1; move16(); diff --git a/lib_dec/hdecnrm_fx.c b/lib_dec/hdecnrm_fx.c index 9c8b6fa01..291aa87fb 100644 --- a/lib_dec/hdecnrm_fx.c +++ b/lib_dec/hdecnrm_fx.c @@ -13,18 +13,18 @@ /* 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 Q0*/ + Word16 *index ) /* o : indices of quantized norms Q0*/ { Word16 i, j, k, n, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( numNorms, 1 ); + m = sub( numNorms, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = (Word16) 0; @@ -34,51 +34,51 @@ void hdecnrm_fx( if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = (Word16) 1; + j = (Word16) 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = (Word16) 1; + k = (Word16) 1; /* Q0 */ move16(); } - n = add( shl( j, 1 ), k ); - j = shl( j, 2 ); - temp = sub( add( 16, n ), j ); + n = add( shl( j, 1 ), k ); /* Q0 */ + j = shl( j, 2 ); /* Q0 */ + temp = sub( add( 16, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( add( 12, n ), j ); + temp = add( add( 12, n ), j ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { j = (Word16) 0; move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } - temp = add( 8, n ); + temp = add( 8, n ); /* Q0 */ if ( j != 0 ) { - temp = add( temp, 12 ); + temp = add( temp, 12 ); /* Q0 */ } IF( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = n; + temp = n; /* Q0 */ move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( 4, n ); + temp = add( 4, n ); /* Q0 */ } if ( j != 0 ) { - temp = add( temp, 24 ); + temp = add( temp, 24 ); /* Q0 */ } } } } - *pidx++ = temp; + *pidx++ = temp; /* Q0 */ move16(); } @@ -96,9 +96,10 @@ void hdecnrm_fx( /*--------------------------------------------------------------------------*/ Word16 decode_huff_context_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *hufftab, - Word16 *rbits ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 tmp_l, tmp_h; Word32 hufftab_idx; @@ -106,11 +107,11 @@ Word16 decode_huff_context_fx( 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 ); + tmp_h = shr( hufftab[hufftab_idx], 4 ); /* Q0 */ + tmp_l = sub( hufftab[hufftab_idx], shl( tmp_h, 4 ) ); /* Q0 */ + *rbits = add( *rbits, tmp_l ); /* Q0 */ move16(); - hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); + hufftab_idx = L_add( hufftab_idx, L_add( L_deposit_l( tmp_h ), get_next_indice_fx( st_fx, tmp_l ) ) ); /* Q0 */ } return negate( hufftab[hufftab_idx] ); } @@ -129,20 +130,21 @@ Word16 decode_huff_context_fx( void hdecnrm_context_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 N, - Word16 *index, - Word16 *n_length ) + const Word16 N, /* Q0 */ + Word16 *index, /* Q0 */ + Word16 *n_length /* Q0 */ +) { Word16 i, prevj, tmp; - prevj = add( index[0], OFFSET_NORM ); + prevj = add( index[0], OFFSET_NORM ); /* Q0 */ FOR( i = 1; i < N; i++ ) { 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 ); /* Q0 */ + index[i] = sub( 31, tmp ); /* Q0 */ move16(); } ELSE @@ -150,17 +152,17 @@ void hdecnrm_context_fx( 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 ); /* Q0 */ 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 ); /* Q0 */ move16(); } } - prevj = index[i]; + prevj = index[i]; /* Q0 */ move16(); } return; @@ -168,17 +170,17 @@ 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 */ + const Word16 N, /* (i) number of SFMs Q0*/ + Word16 *index /* (o) norm quantization index vector Q0*/ ) { Word16 i, j, k, m; Word16 temp; Word16 *pidx; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ move16(); FOR( i = 0; i < m; i++ ) { @@ -191,7 +193,7 @@ void hdecnrm_resize_fx( { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k = add( k, 1 ); /* Q0 */ move16(); } ELSE @@ -202,31 +204,31 @@ void hdecnrm_resize_fx( IF( EQ_16( k, 11 ) ) { - temp = 25; + temp = 25; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 10 ) ) { - temp = 5; + temp = 5; /* Q0 */ move16(); } ELSE IF( EQ_16( k, 9 ) ) { - temp = 6; + temp = 6; /* Q0 */ move16(); } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = add( 16, k ); + temp = add( 16, k ); /* Q0 */ } ELSE { - temp = sub( 15, k ); + temp = sub( 15, k ); /* Q0 */ move16(); } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } @@ -241,20 +243,20 @@ return; 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 */ + const Word16 N, /* i : Number of codewords to decode Q0*/ + const Word16 buffer_len, /* i : Number of bits to read Q0*/ + const Word16 num_lengths, /* i : Number of different huffman codeword lengths Q0*/ + const Word16 *thres, /* i : Threshold of first codeword of each length Q0*/ + const Word16 *offset, /* i : Offset for first codeword Q0*/ + const Word16 *huff_tab, /* i : Huffman table order by codeword lengths Q0*/ + Word16 *index /* o : Decoded index Q0*/ ) { Word16 i, j, k; UWord16 val; Word16 last_bits; - last_bits = buffer_len; + last_bits = buffer_len; /* Q0 */ move16(); val = 0; @@ -263,24 +265,24 @@ void huff_dec_fx( move16(); FOR( i = 0; i < N; i++ ) { - last_bits = sub( buffer_len, j ); - val = (UWord16) L_shl( val, last_bits ); - val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); - val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); + last_bits = sub( buffer_len, j ); /* Q0 */ + val = (UWord16) L_shl( val, last_bits ); /* Q0 */ + val = (UWord16) L_and( val, sub( lshl( 1, buffer_len ), 1 ) ); /* Q0 */ + val = (UWord16) L_or( val, get_next_indice_fx( st_fx, last_bits ) ); /* Q0 */ /* Find codeword length */ - j = sub( num_lengths, 1 ); + j = sub( num_lengths, 1 ); /* Q0 */ WHILE( LT_16( val, thres[j] ) ) { - j = sub( j, 1 ); + j = sub( j, 1 ); /* Q0 */ } - k = lshr( sub( val, thres[j] ), j ); - *index++ = huff_tab[add( offset[j], k )]; + k = lshr( sub( val, thres[j] ), j ); /* Q0 */ + *index++ = huff_tab[offset[j] + k]; /* Q0 */ move16(); } /* Put back unused bits */ - st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); + st_fx->next_bit_pos = sub( st_fx->next_bit_pos, j ); /* Q0 */ move16(); return; @@ -293,9 +295,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 Q0*/ + Word16 *index /* o : indices of quantized norms Q0*/ ) { Word16 i, j, k, n, m; @@ -303,9 +305,9 @@ void hdecnrm_tran_fx( Word16 *pidx; Word16 l; - pidx = index; + pidx = index; /* Q0 */ - m = sub( N, 1 ); + m = sub( N, 1 ); /* Q0 */ FOR( i = 0; i < m; i++ ) { j = 0; @@ -314,20 +316,20 @@ void hdecnrm_tran_fx( move16(); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - j = 1; + j = 1; /* Q0 */ move16(); } if ( get_next_indice_1_fx( st_fx ) != 0 ) { - k = 1; + k = 1; /* Q0 */ move16(); } /*n = k * 2 + j; */ - n = add( shl( k, 1 ), j ); + n = add( shl( k, 1 ), j ); /* Q0 */ /*l = k * 4; */ - l = shl( k, 2 ); + l = shl( k, 2 ); /* Q0 */ test(); test(); test(); @@ -335,22 +337,22 @@ void hdecnrm_tran_fx( test(); IF( ( j == 0 && k == 0 ) || ( EQ_16( j, 1 ) && k == 0 ) || ( EQ_16( j, 1 ) && EQ_16( k, 1 ) ) ) { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ } ELSE{ IF( get_next_indice_1_fx( st_fx ) != 0 ){ - temp = sub( add( 15, n ), l ); + temp = sub( add( 15, n ), l ); /* Q0 */ } ELSE { - temp = sub( add( 15, l ), n ); + temp = sub( add( 15, l ), n ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { FOR( k = 0; k < 3; ) { IF( get_next_indice_1_fx( st_fx ) != 0 ) { - k = add( k, 1 ); + k++; /* Q0 */ } ELSE { @@ -364,22 +366,22 @@ void hdecnrm_tran_fx( temp = sub( temp, 5 ); if ( EQ_16( k, 3 ) ) { - temp = sub( temp, 1 ); + temp = sub( temp, 1 ); /* Q0 */ } } ELSE IF( EQ_16( k, 1 ) ) { - temp = add( temp, 1 ); + temp = add( temp, 1 ); /* Q0 */ } ELSE { - temp = add( temp, 2 ); + temp = add( temp, 2 ); /* Q0 */ IF( get_next_indice_1_fx( st_fx ) != 0 ) { temp = add( temp, 1 ); if ( get_next_indice_1_fx( st_fx ) != 0 ) { - temp = add( temp, 1 ); + temp = add( temp, 1 ); /* Q0 */ } } } @@ -387,7 +389,7 @@ void hdecnrm_tran_fx( } } -*pidx++ = temp; +*pidx++ = temp; /* Q0 */ move16(); } diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 1c5a15e28..71aaec7df 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -3127,14 +3127,14 @@ void stereo_dft_generate_res_pred_fx( move32(); 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] ) ); /* 2 * q_dft - 31 */ + dmx_nrg = L_add( dmx_nrg, L_shr( Madd_32_32( Mpy_32_32( pDFT_DMX[2 * i], pDFT_DMX[2 * i] ), pDFT_DMX[2 * i + 1], pDFT_DMX[2 * i + 1] ), 1 ) ); /* 2 * q_dft - 31 - 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 ) ); /* q_dft */ 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 ) ); /* q_dft */ 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] ) ); /* 2 * q_dft - 31 */ + past_dmx_nrg = L_add( past_dmx_nrg, L_shr( 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] ), 1 ) ); /* 2 * q_dft - 31 -1 */ } op1 = L_deposit_h( BASOP_Util_Divide3232_Scale( ( EPSILON_FIX + dmx_nrg ), ( EPSILON_FIX + past_dmx_nrg ), &q_div ) ); /* q_div + 16 */ q_norm_fac = q_div; diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 9304dc325..cc6f7c5be 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -778,7 +778,7 @@ typedef struct tcx_dec_structure #ifndef IVAS_FLOAT_FIXED float cummulative_damping_tcx_float; #endif - Word16 cummulative_damping_tcx; + Word16 cummulative_damping_tcx; // Q15 } TCX_DEC_DATA, *TCX_DEC_HANDLE; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index a3c6d0e1b..033086191 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1872,10 +1872,10 @@ ivas_error ivas_reverb_process( ); #ifdef IVAS_FLOAT_FIXED 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 */ + 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 Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ); #else void ivas_rev_delay_line_init( @@ -1887,13 +1887,13 @@ void ivas_rev_delay_line_init( #endif #ifdef IVAS_FLOAT_FIXED /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ); 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 */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ); void ivas_rev_delay_line_get_sample_blk_fx( @@ -1903,9 +1903,9 @@ void ivas_rev_delay_line_get_sample_blk_fx( ); 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 */ + 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 Q11 */ ); #else /*! r: sample gotten out of delay line, and amplified by set gain */ @@ -1987,20 +1987,20 @@ void ivas_reverb_t2f_f2t_ClearHistory( ivas_reverb_t2f_f2t_t *t2f_f2t ); #ifdef IVAS_FLOAT_FIXED -void ivas_reverb_t2f_f2t_in_fx( - ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R +void ivas_reverb_t2f_f2t_in_fx( + ivas_reverb_t2f_f2t_t *t2f_f2t, + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R // o: Qx + 1 ); void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R // i/o: Qx ); #else void ivas_reverb_t2f_f2t_in( @@ -2025,12 +2025,12 @@ Word16 ivas_reverb_fft_filter_init( ); void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ ); void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ); #else @@ -2057,9 +2057,9 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( ); #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, - const Word16 fft_size); + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx + const Word16 fft_size); void ivas_reverb_define_window_fft_fx( Word32 *pWindow, //output in Q31 const Word16 transitionStart, diff --git a/lib_rend/ivas_reverb_delay_line.c b/lib_rend/ivas_reverb_delay_line.c index 32599fd27..9025b1597 100644 --- a/lib_rend/ivas_reverb_delay_line.c +++ b/lib_rend/ivas_reverb_delay_line.c @@ -48,10 +48,10 @@ *-----------------------------------------------------------------------------------------*/ 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 */ + 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 Q11 */ + const UWord16 delay, /* i : the delay */ + const UWord16 maxdelay /* i : maximum delay to be supported */ ) { pDelay->MaxDelay = maxdelay; @@ -85,11 +85,11 @@ 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 */ + ivas_rev_delay_line_t *pDelay, /* i : the delay line */ + Word32 input /* i : the sample to feed Q11 */ ) { - pDelay->pBuffer_fx[pDelay->BufferPos] = input; + pDelay->pBuffer_fx[pDelay->BufferPos] = input; // Q11 pDelay->BufferPos = u_extract_l( UL_addNsD( pDelay->BufferPos, 1 ) ); move16(); @@ -223,9 +223,9 @@ 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 */ + 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 Q11 */ ) { Word32 *pDst, *pSrc; @@ -246,14 +246,14 @@ void ivas_rev_delay_line_feed_sample_blk_fx( pDst = &pDelay->pBuffer_fx[pos]; FOR( i = 0; i < blk_size_1; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } - pDst = &pDelay->pBuffer_fx[0]; - pSrc = &input[blk_size_1]; + pDst = &pDelay->pBuffer_fx[0]; // Q11 + pSrc = &input[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { - pDst[i] = pSrc[i]; + pDst[i] = pSrc[i]; // Q11 move32(); } pos = blk_size_2; @@ -261,10 +261,10 @@ 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]; + pDst = &pDelay->pBuffer_fx[pos]; // Q11 FOR( i = 0; i < blk_size; i++ ) { - pDst[i] = input[i]; + pDst[i] = input[i]; // Q11 move32(); } pos = (UWord16) L_add( pos, blk_size ); @@ -289,8 +289,8 @@ void ivas_rev_delay_line_feed_sample_blk_fx( *-----------------------------------------------------------------------------------------*/ /*! r: sample gotten out of delay line, and amplified by set gain */ -Word32 ivas_rev_delay_line_get_sample_fx( - ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ +Word32 ivas_rev_delay_line_get_sample_fx( /* Q11 */ + ivas_rev_delay_line_t *pDelay /* i/o: the delay line */ ) { IF( EQ_16( pDelay->Gain_fx, ONE_IN_Q14 ) ) @@ -301,7 +301,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 ) ); // Q11 + Q14 - 15 + 1 = Q11 } } /*-----------------------------------------------------------------------------------------* @@ -311,9 +311,9 @@ 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 */ + 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 Q11 */ ) { Word32 *pDst, *pSrc; @@ -334,16 +334,16 @@ void ivas_rev_delay_line_get_sample_blk_fx( move16(); blk_size_2 = (UWord16) L_sub( blk_size, blk_size_1 ); move16(); - pSrc = &pDelay->pBuffer_fx[pos]; + pSrc = &pDelay->pBuffer_fx[pos]; // Q11 IF( EQ_16( gain, ONE_IN_Q14 ) ) { FOR( i = 0; i < blk_size_1; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } - pSrc = &pDelay->pBuffer_fx[0]; - pDst = &output[blk_size_1]; + pSrc = &pDelay->pBuffer_fx[0]; // Q11 + pDst = &output[blk_size_1]; // Q11 FOR( i = 0; i < blk_size_2; i++ ) { pDst[i] = pSrc[i]; @@ -354,14 +354,14 @@ void ivas_rev_delay_line_get_sample_blk_fx( { 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 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } pSrc = &pDelay->pBuffer_fx[0]; pDst = &output[blk_size_1]; 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 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } @@ -374,7 +374,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { FOR( i = 0; i < blk_size; i++ ) { - output[i] = pSrc[i]; + output[i] = pSrc[i]; // Q11 move32(); } } @@ -382,7 +382,7 @@ void ivas_rev_delay_line_get_sample_blk_fx( { 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 ); // Q11 + Q14 - 15 + 1 = Q11 move32(); } } diff --git a/lib_rend/ivas_reverb_fft_filter.c b/lib_rend/ivas_reverb_fft_filter.c index 2e9ce6cda..bae4d3f36 100644 --- a/lib_rend/ivas_reverb_fft_filter.c +++ b/lib_rend/ivas_reverb_fft_filter.c @@ -139,8 +139,8 @@ uint16_t int_log2( *-----------------------------------------------------------------------------------------*/ static void fft_wrapper_2ch_fx( - Word32 *buffer_L_fx, - Word32 *buffer_R_fx, + Word32 *buffer_L_fx, // input Q: Qx -> output Q: (Qx + 1) + Word32 *buffer_R_fx, // input Q: Qx -> output Q: (Qx + 1) const Word16 fft_size ) { const Word16 half_sz = shr( fft_size, 1 ); @@ -149,27 +149,27 @@ static void fft_wrapper_2ch_fx( DoRTFTn_fx_ivas( buffer_L_fx, buffer_R_fx, fft_size ); /* separating left and right channel spectra */ - buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); + buffer_L_fx[0] = L_shl( buffer_L_fx[0], 1 ); // Qx + 1 move32(); - buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); + buffer_R_fx[0] = L_shl( buffer_R_fx[0], 1 ); // Qx + 1 move32(); FOR( k = 1; k < half_sz; k++ ) { mirror_k = sub( fft_size, k ); - left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); - left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); + left_re_fx = ( L_add( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ); // Qx + 1 + left_im_fx = ( L_sub( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 - right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); - right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); + right_re_fx = ( L_add( buffer_R_fx[k], buffer_R_fx[mirror_k] ) ); // Qx + 1 + right_im_fx = L_negate( ( L_sub( buffer_L_fx[k], buffer_L_fx[mirror_k] ) ) ); // Qx + 1 - buffer_L_fx[k] = left_re_fx; + buffer_L_fx[k] = left_re_fx; // Qx + 1 move32(); - buffer_R_fx[k] = right_re_fx; + buffer_R_fx[k] = right_re_fx; // Qx + 1 move32(); - buffer_L_fx[mirror_k] = left_im_fx; + buffer_L_fx[mirror_k] = left_im_fx; // Qx + 1 move32(); - buffer_R_fx[mirror_k] = right_im_fx; + buffer_R_fx[mirror_k] = right_im_fx; // Qx + 1 move32(); } @@ -221,8 +221,8 @@ static void fft_wrapper_2ch( *-----------------------------------------------------------------------------------------*/ static void ifft_wrapper_2ch_fx( - Word32 *buffer_L, - Word32 *buffer_R, + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx const Word16 fft_size ) { Word32 buffer_L_re, buffer_L_im, buffer_R_re, buffer_R_im; @@ -234,22 +234,22 @@ static void ifft_wrapper_2ch_fx( { mirror_k = sub( fft_size, k ); - buffer_L_re = buffer_L[k]; + buffer_L_re = buffer_L[k]; // Qx move32(); - buffer_L_im = buffer_L[mirror_k]; + buffer_L_im = buffer_L[mirror_k]; // Qx move32(); - buffer_R_re = buffer_R[k]; + buffer_R_re = buffer_R[k]; // Qx move32(); - buffer_R_im = buffer_R[mirror_k]; + buffer_R_im = buffer_R[mirror_k]; // Qx move32(); - buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); + buffer_L[k] = L_add( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); + buffer_L[mirror_k] = L_sub( buffer_L_re, buffer_R_im ); // Qx move32(); - buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); + buffer_R[k] = L_sub( buffer_R_re, buffer_L_im ); // Qx move32(); - buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); + buffer_R[mirror_k] = L_add( buffer_R_re, buffer_L_im ); // Qx move32(); } @@ -441,26 +441,26 @@ void ivas_reverb_t2f_f2t_ClearHistory( void ivas_reverb_t2f_f2t_in_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *input_L, - Word32 *input_R, - Word32 *buffer_L, - Word32 *buffer_R ) + Word32 *input_L, // i: Qx + Word32 *input_R, // i: Qx + Word32 *buffer_L, // o: Qx + 1 + Word32 *buffer_R ) // o: Qx + 1 { Word16 i; Word16 hlen = t2f_f2t->hist_size; move16(); Word16 bsiz = t2f_f2t->block_size; move16(); - Word32 *hist_L = t2f_f2t->fft_history_L_fx; - Word32 *hist_R = t2f_f2t->fft_history_R_fx; + Word32 *hist_L = t2f_f2t->fft_history_L_fx; // Qx + Word32 *hist_R = t2f_f2t->fft_history_R_fx; // Qx Word32 *pL, *pR; /* copy history to buffer */ FOR( i = 0; i < hlen; i++ ) { - buffer_L[i] = hist_L[i]; + buffer_L[i] = hist_L[i]; // Qx move16(); - buffer_R[i] = hist_R[i]; + buffer_R[i] = hist_R[i]; // Qx move16(); } @@ -469,9 +469,9 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[hlen]; FOR( i = 0; i < bsiz; i++ ) { - pL[i] = input_L[i]; + pL[i] = input_L[i]; // Qx move32(); - pR[i] = input_R[i]; + pR[i] = input_R[i]; // Qx move32(); } @@ -480,14 +480,14 @@ void ivas_reverb_t2f_f2t_in_fx( pR = &buffer_R[bsiz]; FOR( i = 0; i < hlen; i++ ) { - hist_L[i] = pL[i]; + hist_L[i] = pL[i]; // Qx move32(); - hist_R[i] = pR[i]; + hist_R[i] = pR[i]; // Qx move32(); } /* do FFT */ - fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); + fft_wrapper_2ch_fx( buffer_L, buffer_R, t2f_f2t->fft_size ); // Qx -> Qx + 1 return; } @@ -552,10 +552,10 @@ void ivas_reverb_t2f_f2t_in( void ivas_reverb_t2f_f2t_out_fx( ivas_reverb_t2f_f2t_t *t2f_f2t, - Word32 *buffer_L, - Word32 *buffer_R, - Word32 *output_L, - Word32 *output_R ) + Word32 *buffer_L, // i/o: Qx + Word32 *buffer_R, // i/o: Qx + Word32 *output_L, // i/o: Qx + Word32 *output_R ) // i/o: Qx { Word16 i; Word32 *pL = &buffer_L[t2f_f2t->hist_size]; @@ -565,9 +565,9 @@ void ivas_reverb_t2f_f2t_out_fx( FOR( i = 0; i < t2f_f2t->block_size; i++ ) { - output_L[i] = pL[i]; + output_L[i] = pL[i]; // Qx move32(); - output_R[i] = pR[i]; + output_R[i] = pR[i]; // Qx move32(); } @@ -654,8 +654,9 @@ int16_t ivas_reverb_fft_filter_init( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_ComplexMul_fx( - ivas_reverb_fft_filter_t *fft_filter, - Word32 *buffer ) + ivas_reverb_fft_filter_t *fft_filter, /* i */ + Word32 *buffer /* i/o: Qx */ +) { Word16 f_spec, h, i, j; Word32 *spec; @@ -665,18 +666,18 @@ void ivas_reverb_fft_filter_ComplexMul_fx( h = shr( f_spec, 1 ); spec = fft_filter->fft_spectrum_fx; - buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ + buffer[0] = Mpy_32_32( spec[0], buffer[0] ); /* real multiply f0 DC */ // Q31 + Qx - 31 = Qx move32(); - buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ + buffer[h] = Mpy_32_32( spec[h], buffer[h] ); /* real multiply f_spec Nyquist */ // Q31 + Qx - 31 = Qx move32(); j = sub( f_spec, 1 ); FOR( i = 1; i < h; i++ ) /*actual complex multiply in loop */ { t = buffer[i]; move32(); - buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); + buffer[i] = L_sub( Mpy_32_32( t, spec[i] ), Mpy_32_32( buffer[j], spec[j] ) ); // Qx + Q31 - 31 = Qx move32(); - buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); + buffer[j] = L_add( Mpy_32_32( t, spec[j] ), Mpy_32_32( buffer[j], spec[i] ) ); // Qx + Q31 - 31 = Qx move32(); j = sub( j, 1 ); } @@ -723,22 +724,22 @@ void ivas_reverb_fft_filter_ComplexMul( *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR_fx( - rv_fftwf_type_complex_fx *spectrum, - Word32 *fft_real, + rv_fftwf_type_complex_fx *spectrum, // i: Qx + Word32 *fft_real, // o: Qx const Word16 fft_size ) { Word16 i, h; h = shr( fft_size, 1 ); - fft_real[0] = spectrum[0][0]; + fft_real[0] = spectrum[0][0]; // Qx move32(); - fft_real[h] = spectrum[h][0]; + fft_real[h] = spectrum[h][0]; // Qx move32(); FOR( i = 1; i < h; i++ ) { - fft_real[i] = spectrum[i][0]; + fft_real[i] = spectrum[i][0]; // Qx move32(); - fft_real[sub( fft_size, i )] = spectrum[i][1]; + fft_real[fft_size - i] = spectrum[i][1]; // Qx move32(); } @@ -775,8 +776,8 @@ void ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( *-----------------------------------------------------------------------------------------*/ void ivas_reverb_fft_filter_CrossMix_fx( - Word32 *buffer0, - Word32 *buffer1, + Word32 *buffer0, // i/o: Qx + Word32 *buffer1, // i/o: Qx const Word16 fft_size ) { Word32 t; @@ -784,11 +785,11 @@ void ivas_reverb_fft_filter_CrossMix_fx( FOR( i = 0; i < fft_size; i++ ) { - t = buffer0[i]; + t = buffer0[i]; // Qx move32(); - buffer0[i] = L_add( t, buffer1[i] ); + buffer0[i] = L_add( t, buffer1[i] ); // Qx move32(); - buffer1[i] = L_sub( t, buffer1[i] ); + buffer1[i] = L_sub( t, buffer1[i] ); // Qx move32(); } diff --git a/lib_rend/ivas_rom_binaural_crend_head.c b/lib_rend/ivas_rom_binaural_crend_head.c index a34162e49..d688ccded 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.c +++ b/lib_rend/ivas_rom_binaural_crend_head.c @@ -678,7 +678,7 @@ const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS #ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ @@ -904,7 +904,7 @@ const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NU #ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_latency_s = 0.000020834f; #else -const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; +const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; // Q31 #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 3012dad11..ae3482a4f 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -204,9 +204,9 @@ const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = }; #else -const Word16 ap_lattice_coeffs_1_fx[330] = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; -const Word16 ap_lattice_coeffs_2_fx[132] = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; -const Word16 ap_lattice_coeffs_3_fx[66] = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; +const Word16 ap_lattice_coeffs_1_fx[330] /* Q15 */ = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; +const Word16 ap_lattice_coeffs_2_fx[132] /* Q15 */ = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; +const Word16 ap_lattice_coeffs_3_fx[66] /* Q15 */ = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; const Word16 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = { @@ -269,7 +269,7 @@ const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = 3.0903f, 2.0053f, 1.0860f, 0.8072f, 0.7079f }; #else -const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = +const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] /* Q13 */ = { 25315, 16427, 8896, 6612, 5799 }; @@ -302,7 +302,7 @@ const float lowBitRateBinauralEQ[LOW_BIT_RATE_BINAURAL_EQ_BINS] = 0.979f, 0.893f, 0.762f, 0.615f, 0.52f, 0.48f, 0.477f, 0.477f, 0.48f, 0.501f, 0.546f, 0.602f, 0.652f, 0.664f, 0.652f, 0.639f, 0.635f }; #else -const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] = +const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] /* Q31 */ = { 2102386432, 1917702912, 1636382592, 1320702464, 1116691456, 1030792128, 1024349696, 1024349696, 1030792128, 1075889280, 1172526080, 1292785152, 1400159360, 1425929088, 1400159360, 1372242048, 1363652096 -- GitLab From 7b6cf17a7e0165faa2f8c5d9db9d9f9fa2217416 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 13:29:47 +0530 Subject: [PATCH 03/39] Q information for decoder and renderer files - 2 --- lib_dec/dlpc_stoch_fx.c | 30 +- lib_dec/er_dec_acelp_fx.c | 234 ++--- lib_dec/er_dec_tcx_fx.c | 372 ++++---- lib_dec/ivas_decision_matrix_dec.c | 13 +- lib_dec/ivas_dirac_dec.c | 405 +++++---- lib_dec/ivas_dirac_output_synthesis_cov.c | 206 ++--- lib_dec/tonalMDCTconcealment.c | 58 +- lib_dec/tonalMDCTconcealment_fx.c | 506 +++++------ lib_dec/transition_dec_fx.c | 52 +- lib_dec/updt_dec_fx.c | 87 +- lib_dec/vlpc_1st_dec_fx.c | 6 +- lib_dec/vlpc_2st_dec_fx.c | 2 +- lib_dec/voiced_dec_fx.c | 12 +- lib_dec/waveadjust_fec_dec_fx.c | 130 +-- lib_rend/ivas_dirac_output_synthesis_dec.c | 965 +++++++++++---------- 15 files changed, 1578 insertions(+), 1500 deletions(-) diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index e06a2d515..6583c91de 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -15,14 +15,14 @@ void lpc_unquantize_fx( Decoder_State *st, - Word16 *lsf, - Word16 *lsp, + Word16 *lsf, /*x2.56*/ + Word16 *lsp, /*Q15*/ const Word16 m, - Word16 *param_lpc, - Word16 *lspmid, - Word16 *lsfmid, + Word16 *param_lpc, /*Q0*/ + Word16 *lspmid, /*Q15*/ + Word16 *lsfmid, /*x2.56*/ Word16 coder_type, - Word16 *LSF_Q_prediction /* o : LSF prediction mode */ + Word16 *LSF_Q_prediction /* o : LSF prediction mode Q0*/ ) { Word16 nb_indices, k; @@ -31,15 +31,15 @@ void lpc_unquantize_fx( nb_indices = 0; /* to avoid compilation warnings */ move16(); - Copy( st->lsf_old_fx, &lsf[0], m ); - Copy( st->lsp_old_fx, &lsp[0], m ); + Copy( st->lsf_old_fx, &lsf[0], m ); /*x2.56*/ + Copy( st->lsp_old_fx, &lsp[0], m ); /*x2.56*/ IF( st->lpcQuantization == 0 ) { - nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); + nb_indices = dlpc_avq_fx( param_lpc, &lsf[m], st->numlpc, st->sr_core ); /*Q0*/ FOR( k = 0; k < st->numlpc; k++ ) { - E_LPC_lsf_lsp_conversion( &lsf[imult1616( add( k, 1 ), m )], &lsp[imult1616( add( k, 1 ), m )], m ); + E_LPC_lsf_lsp_conversion( &lsf[( ( k + 1 ) * m )], &lsp[( ( k + 1 ) * m )], m ); /*Q15*/ } } ELSE IF( EQ_16( st->lpcQuantization, 1 ) ) @@ -76,7 +76,7 @@ void lpc_unquantize_fx( } } - lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); + lsf2lsp_fx( &lsf[m], &lsp[m], M, st->sr_core ); /*Q15*/ } ELSE { @@ -87,7 +87,7 @@ void lpc_unquantize_fx( move16(); 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 /*Q0*/, shr( st->seed_acelp, 1 ), 31821 /*Q0*/ ), param_lpc[i], 31821 /*Q0*/ ) ); /*Q0*/ } /* Decoded mid-frame isf */ @@ -96,9 +96,9 @@ void lpc_unquantize_fx( test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc && EQ_16( 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 ); - reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); - lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); + midlsf_dec( &lsf[0], &lsf[m], param_lpc[nb_indices], lsfmid, coder_type, &( st->mid_lsf_int ), st->prev_bfi, st->safety_net ); /*3Q12*/ + reorder_lsf_fx( lsfmid, LSF_GAP_MID_FX, M, st->sr_core ); /*x2.56*/ + lsf2lsp_fx( lsfmid, lspmid, M, st->sr_core ); /*Q15*/ } diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index b093fb129..3d2fdee1c 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -37,11 +37,11 @@ void con_acelp_fx( Word16 *pgainT, /*mem_syn >rescaling done */ - Word16 *pitch_buffer, - Word16 *voice_factors, - Word16 *bwe_exc ) + const Word16 *Qf_exc, /*mem_syn >rescaling done */ + Word16 *pitch_buffer, /* Q0 */ + Word16 *voice_factors, /* Q6 */ + Word16 *bwe_exc /* Qx */ ) { Word16 i_subfr, i, T0; /*Q0*/ @@ -115,12 +115,12 @@ void con_acelp_fx( *------------------------------------------------------------------------*/ /* set ACELP synthesis memory */ - Copy( st->mem_syn2_fx, mem_syn, M ); + Copy( st->mem_syn2_fx, mem_syn, M ); /* Q_syn */ /* 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; /*Qf_exc*/ + exc = harmonic_exc_buf + L_EXC_MEM_DEC; /*Qf_exc*/ + Copy( st->old_exc_fx, harmonic_exc_buf, L_EXC_MEM_DEC ); /*Q_exc*/ exc[st->L_frame] = 0; move16(); @@ -139,7 +139,7 @@ void con_acelp_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 ); + T0 = round_fx( predPitchLag ); /*Q0*/ IF( extrapolationFailed != 0 ) { @@ -160,7 +160,7 @@ void con_acelp_fx( l = shl( L_SUBFR, 1 ); FOR( i = 0; i < l; i++ ) { - exc[i] = exc[sub( i, st->guidedT0 )]; + exc[i] = exc[( i - st->guidedT0 )]; /*Qf_exc*/ move16(); } } @@ -171,11 +171,11 @@ void con_acelp_fx( move16(); } - tmp_tc = st->old_fpitch; - move32(); /* take the previous frame last pitch*/ + tmp_tc = st->old_fpitch; /*15Q16*/ + move32(); /* 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*/ /* Q16 */ } /* PLC: [ACELP: Fade-out] @@ -201,7 +201,7 @@ void con_acelp_fx( * Last pitch cycle of the previous frame is repeatedly copied. * *---------------------------------------------------------------*/ - Tc = round_fx( tmp_tc ); + Tc = round_fx( tmp_tc ); /* Q0 */ 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*/ ); @@ -221,16 +221,16 @@ void con_acelp_fx( pt_exc = exc; if ( st->enableGplc != 0 ) { - pt_exc = &exc[imult1616( nSubframes, L_SUBFR )]; + pt_exc = &exc[( nSubframes * L_SUBFR )]; /*Qf_exc*/ } - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Qf_exc*/ 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; + pt_exc = harmonic_exc_buf; /*Qf_exc*/ assert( pt_exc < pt1_exc - 1 ); } @@ -249,10 +249,10 @@ void con_acelp_fx( { /* *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] ); - *pt_exc = tmp_16; + tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); /*Q16 + Qf_exc*/ + tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); /*Q16 + Qf_exc*/ + tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); /*Qf_exc*/ + *pt_exc = tmp_16; /*Qf_exc*/ move16(); pt_exc++; pt1_exc++; @@ -263,20 +263,20 @@ void con_acelp_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = harmonic_exc_buf; + pt1_exc = harmonic_exc_buf; /*Qf_exc*/ } l = add( st->L_frame, sub( imult1616( L_SUBFR, sub( 1, nSubframes ) ), Tc ) ); FOR( i = 0; i < l; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Qf_exc*/ move16(); } @@ -287,9 +287,9 @@ void con_acelp_fx( IF( nSubframes > 0 ) { - pitch_buf[0] = L_deposit_h( st->guidedT0 ); + pitch_buf[0] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - pitch_buf[1] = L_deposit_h( st->guidedT0 ); + pitch_buf[1] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); } @@ -301,7 +301,7 @@ void con_acelp_fx( 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]; + pitch_buf[4] = pitch_buf[3]; /*Q16*/ move32(); } } @@ -315,7 +315,7 @@ void con_acelp_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*15Q16*/ } } @@ -323,8 +323,8 @@ void con_acelp_fx( * PLC: [ACELP: adaptive codebook] * PLC: Create the harmonic part needed for the overlap-add. *------------------------------------------------------------*/ - pt_exc = exc + st->L_frame; - pt1_exc = pt_exc - T0; + pt_exc = exc + st->L_frame; /*Qf_exc*/ + pt1_exc = pt_exc - T0; /*Qf_exc*/ if ( T0 == 0 ) { pt1_exc = pt_exc - Tc; @@ -343,11 +343,11 @@ void con_acelp_fx( IF( fUseExtrapolatedPitch != 0 ) { - st->old_fpitch = predPitchLag; + st->old_fpitch = predPitchLag; /*Q16*/ move32(); if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_fpitch = L_deposit_h( T0 ); + st->old_fpitch = L_deposit_h( T0 ); /*Q16*/ move32(); } } @@ -371,8 +371,8 @@ void con_acelp_fx( /* 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 )] ); /*Q16*/ test(); test(); /*test();*/ @@ -421,9 +421,9 @@ void con_acelp_fx( { 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*/ /*Qf_exc*/ #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*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -436,9 +436,9 @@ void con_acelp_fx( { 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*/ /*Qf_exc*/ #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*/ /*Qf_exc*/ #endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -449,12 +449,12 @@ void con_acelp_fx( { pT[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); - pitch_buffer[i] = round_fx( pitch_buf[i] ); + pitch_buffer[i] = round_fx( pitch_buf[i] ); /*Q0*/ move16(); } /* 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 ); /*Qf_exc*/ } ELSE { @@ -468,9 +468,9 @@ void con_acelp_fx( move32(); pgainT[i] = 0; move16(); - pT[i] = L_SUBFR; + pT[i] = L_SUBFR; /*Q0*/ move16(); - pitch_buffer[i] = L_SUBFR; + pitch_buffer[i] = L_SUBFR; /*Q0*/ move16(); } @@ -486,7 +486,7 @@ void con_acelp_fx( * * search for "Scale from randomized buffer to excitation buffer" *-----------------------------------------------------------------*/ - noise_buf = buf; + noise_buf = buf; /*Qf_exc*/ tmpSeed = st->seed_acelp; move16(); l = add( st->L_frame, sub( l_fir_fer, 1 ) ); @@ -516,7 +516,7 @@ void con_acelp_fx( /* 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 ); /*Q0*/ tmp = 32767 /*1.0f Q15*/; @@ -545,11 +545,11 @@ void con_acelp_fx( #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 ); /*Q0*/ #else tmp_16 = sub( shl( gainCNG, sub( gainCNG_e, 5 /*Q5*/ ) ), ftmp ); #endif @@ -594,7 +594,7 @@ void con_acelp_fx( 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 ) ); + st->Mode2_lp_gainc = L_shl( L_deposit_l( tmp_16 ), add( s_16, 1 ) ); /*Q16*/ move32(); test(); IF( ( EQ_16( st->last_good, UNVOICED_TRANSITION ) ) && ( EQ_16( coder_type, GENERIC ) ) ) @@ -607,13 +607,13 @@ void con_acelp_fx( 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 + shr( l_fir_fer, 1 ); + pt_exc = noise_buf + shr( l_fir_fer, 1 ); /*Qf_exc*/ /*** 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*/ - 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 ); + 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 ); /*Q31*/ BASOP_SATURATE_WARNING_ON_EVS 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)*/ @@ -629,7 +629,7 @@ void con_acelp_fx( { s_gain_inov = s_32; move16(); - tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); + tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); /* Q31 - s_gain_inov */ } ELSE { @@ -640,7 +640,7 @@ 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 */ /* Q15 - s_gain_inov */ /* PLC: [ACELP: Fade-out] * PLC: Linearly attenuate the gain through the frame */ @@ -661,12 +661,12 @@ void con_acelp_fx( 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 ); /*Q15*/ gain_inov = mult_r( gain_inov, sub( 32767 /*1.0f Q15*/, tilt_code ) ); /* Q15 * 2^s_gain_inov */ } - pt_exc = noise_buf; + pt_exc = noise_buf; /*Qf_exc*/ /* non-causal ringing of the FIR filter */ @@ -690,9 +690,9 @@ void con_acelp_fx( 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 ); + gain_16 = shl( gain_16, g_e ); /*Q15 + g_e*/ + gain_32 = L_shl( gain_32, g_e ); /*Q31 + g_e*/ + step_32 = L_shl( step_32, g_e ); /*Q31 + g_e*/ l = shr( l_fir_fer, 1 ); FOR( i = 0; i < l; i++ ) { @@ -711,7 +711,7 @@ void con_acelp_fx( pt_exc++; gain_32 = L_sub( gain_32, step_32 ); - gain_16 = round_fx( gain_32 ); + gain_16 = round_fx( gain_32 ); /*Q15*/ } l = add( shr( st->L_frame, 1 ), shr( l_fir_fer, 1 ) ); @@ -735,36 +735,36 @@ void con_acelp_fx( IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), 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 + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ + Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); /*Qf_exc*/ + Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ /*Qf_exc*/ } ELSE { /* Update exc_unv */ - bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), 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 + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ /*Qf_exc*/ } /* Compute total excitation in noisebuffer to save memories */ 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 ) ); /*Qf_exc*/ } ELSE { - noise_buf = exc_unv; + noise_buf = exc_unv; /*Qf_exc*/ } IF( st->hBWE_TD != NULL ) { 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 ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR ); /* Q6 */ } ELSE { interp_code_4over2_fx( noise_buf, bwe_exc, st->L_frame ); - set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); + set16_fx( voice_factors, st->last_voice_factor_fx, NB_SUBFR16k ); /* Q6 */ } } /*----------------------------------------------------------* @@ -773,13 +773,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 ); /*Q_syn*/ IF( EQ_16( st->nbLostCmpt, 1 ) ) { IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( st->mem_syn2_fx, mem_syn_unv, M ); + Copy( st->mem_syn2_fx, mem_syn_unv, M ); /*Q_syn*/ } ELSE { @@ -788,7 +788,7 @@ void con_acelp_fx( } ELSE { - Copy( st->mem_syn_unv_back, mem_syn_unv, M ); + Copy( st->mem_syn_unv_back, mem_syn_unv, M ); /*Q_syn*/ } /* voiced synth */ @@ -810,11 +810,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* 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[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -826,10 +826,10 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ #ifdef BASOP_NOGLOB g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /* Q15 */ #else g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); g = shl( g, g_e ); @@ -838,14 +838,14 @@ void con_acelp_fx( 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[add( i_subfr, i )], g ); + exc[i_subfr + i] = mult_r( exc[( i_subfr + i )], g ); /*Qf_exc*/ move16(); } } 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 ); /*Qf_exc*/ move16(); } @@ -866,7 +866,7 @@ void con_acelp_fx( 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 ); + Copy( mem_syn, mem_syn2, M ); /*Qf_syn + s_16*/ /* synthesize ola*/ E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); } @@ -875,8 +875,8 @@ void con_acelp_fx( 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 ) ); /* Qf_syn */ + Scale_sig( syn, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /* Qf_syn */ /*Scale_sig(exc, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -900,11 +900,11 @@ void con_acelp_fx( /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); /* 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[tmp_16] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); /*Q31*/ tmp_32 = L_max( tmp_32, 1 ); gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); move16(); - gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); /* Q15 - gain_lpc_e[tmp_16] */ move16(); p_A += ( M + 1 ); /* Pointer move */ @@ -916,24 +916,24 @@ void con_acelp_fx( { /* i_subfr / L_SUBFR */ tmp_16 = shr( i_subfr, Q6 ); - g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); /* Q15 - gain_lpc_e[tmp_16] */ g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); #ifdef BASOP_NOGLOB - g = shl_sat( g, g_e ); + g = shl_sat( g, g_e ); /*Q15*/ #else g = shl( g, g_e ); #endif FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[add( i_subfr, i )] = mult_r( exc_unv[add( i_subfr, i )], g ); + exc_unv[( i_subfr + i )] = mult_r( exc_unv[add( i_subfr, i )], g ); /*Qf_exc*/ move16(); } } 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 ); /*Qf_exc*/ move16(); } @@ -950,18 +950,18 @@ void con_acelp_fx( 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 ); /*Qf_syn + s_16*/ 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 ); } - Copy( mem_syn_unv, st->mem_syn_unv_back, M ); + Copy( mem_syn_unv, st->mem_syn_unv_back, M ); /*Qf_syn + s_16*/ IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - Copy( mem_syn_unv, mem_syn, M ); + Copy( mem_syn_unv, mem_syn, M ); /*Qf_syn + s_16*/ /* 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 ); } @@ -970,18 +970,18 @@ void con_acelp_fx( 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 ) ); + Scale_sig( mem_syn_unv, M, negate( s_16 ) ); /*Qf_syn*/ 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 ) ); /*Qf_syn*/ + Scale_sig( syn_unv, add( shr( st->L_frame, 1 ), st->L_frame ), negate( s_16 ) ); /*Qf_syn*/ } ELSE { - Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); + Scale_sig( syn_unv, st->L_frame, negate( s_16 ) ); /*Qf_syn*/ } - Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); + Scale_sig( st->mem_syn_unv_back, M, negate( s_16 ) ); /*Qf_syn*/ /*Scale_sig(exc_unv, add(shr(st->L_frame,1),st->L_frame) ,negate(s_16));*/ } @@ -992,7 +992,7 @@ void con_acelp_fx( FOR( i = 0; i < st->L_frame; i++ ) { #ifdef BASOP_NOGLOB - syn[i] = add_sat( syn[i], syn_unv[i] ); + syn[i] = add_sat( syn[i], syn_unv[i] ); /*Qf_syn*/ #else syn[i] = add( syn[i], syn_unv[i] ); #endif @@ -1001,7 +1001,7 @@ void con_acelp_fx( } 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 ) ) ); /*Qf_syn*/ } @@ -1072,21 +1072,21 @@ void con_acelp_fx( } /* 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 ); /*15Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*15Q16*/ /*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 ); #ifdef BASOP_NOGLOB - st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); + st->enr_old_fx = L_shl_sat( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); /*Q0*/ #else st->enr_old_fx = L_shl( st->enr_old_fx, shl( negate( Qf_syn ), 1 ) ); #endif move32(); /* 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 ); /*Qf_syn*/ + Copy( syn + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); /*Qf_syn*/ /*Q_mem_syn_new = Q_mem_syn;*/ /*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ @@ -1103,13 +1103,13 @@ void con_acelp_fx( 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*/ ); hTcxDec->Q_syn_Overl_TDAC = add( st->Q_syn, -1 ); move16(); - Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); + Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Qf_syn*/ /* update old_Aq */ - 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 ); /*Q12*/ - 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 ) ); /*Qf_syn*/ /* create aliasing and windowing */ @@ -1119,7 +1119,7 @@ void con_acelp_fx( 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*/ ) ); /*Q0*/ hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + sub( st->L_frame, n ), sub( st->L_frame, n ) ); @@ -1128,15 +1128,15 @@ void con_acelp_fx( bufferCopyFx( syn + sub( 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[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[add( 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 )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( 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 )] ) ); /* hHQ_core->q_old_outLB_fx */ move16(); } - set16_fx( &hHQ_core->old_out_LB_fx[add( 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; move16(); @@ -1144,38 +1144,38 @@ void con_acelp_fx( FOR( i = 0; i < W2; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); /* A-D */ + hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[( ( W1 - 1 ) - i )] ); /* A-D */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } /*-2*/ FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDAC[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); /* B-C */ + hTcxDec->syn_Overl_TDAC[( W2 + i )] = add( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /* B-C */ /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_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 ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[( ( W1 - 1 ) - i )].v.im ); /*hTcxDec->Q_syn_Overl_TDAC*/ move16(); } @@ -1192,7 +1192,7 @@ void con_acelp_fx( 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[sub( st->nb_subfr, 1 )] ), 6 ); + st->bfi_pitch_fx = shl( round_fx( pitch_buf[( st->nb_subfr - 1 )] ), 6 ); /*Q6*/ st->bfi_pitch_frame = st->L_frame; move16(); move16(); @@ -1200,7 +1200,7 @@ 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 /*Qx*/, Word16 *exc /*Qx*/, Word16 len, Word16 *s_16 ) { IF( GT_16( nbLostCmpt, 5 ) ) { @@ -1242,8 +1242,8 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc } *s_16 = s_max( sub( s_min( sf_exc, sf_mem_syn ), 5 ), 0 ) /*5 bits of headroom, scaling not smaller than 0*/; move16(); - Scale_sig( mem_syn, M, *s_16 ); - Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); + Scale_sig( mem_syn, M, *s_16 ); /*Qx + s_16*/ + Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); /*Qx + s_16*/ } } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 4158368c6..1a1dbce92 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -14,7 +14,7 @@ /***************************************************** 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 /*Q16*/, Word16 L_subfr /*Q0*/, Word32 lp_gainp /*Q16*/, Word32 *lp_gainc /*Q16*/ ) { Word32 L_c; Word16 tmp16, tmp16_2, tmp16_3, tmp_e, tmp2_e, tmp_loop, i; @@ -49,7 +49,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L /*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[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); + tmp16_3 = sub_o( exc[( i - ( L_subfr * 2 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[( ( i - ( L_subfr * 2 ) ) - tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); #else tmp16_3 = sub( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/ ); #endif @@ -61,7 +61,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L Overflow = 0; move16(); #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 Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ #endif @@ -81,7 +81,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L move32(); } -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 /*Q0*/, Word32 *lp_gainc /*Q16*/ ) { Word16 i, cnt, tmp16, tmp_e, tmp2_e; Word32 L_c, L_acc, L_tmp; @@ -106,15 +106,15 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp 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[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_acc = L_macNs_co( L_acc, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, exc[( i - ( L_subfr * 2 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ #else L_acc = L_macNs( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/ ); /*Q3*/ #endif Overflow = 0; move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - 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 Q-1*/ #else L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ #endif @@ -144,16 +144,16 @@ 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 Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left /* i : TD-PLC only in left channel Q0*/ #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 Q14*/ #endif #endif @@ -211,20 +211,20 @@ void con_tcx_fx( move16(); /* Framing parameters */ - L_frame = hTcxDec->L_frameTCX; + L_frame = hTcxDec->L_frameTCX; /*Q0*/ move16(); /* L_subfr = st->L_frameTCX/st->nb_subfr */ - L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); move32(); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); 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 ); /*Q0*/ 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 */ @@ -237,37 +237,37 @@ void con_tcx_fx( 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 ); /*Q16*/ move32(); } /* set excitation memory*/ - exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + exc = buf + OLD_EXC_SIZE_DEC; /*Q_exc*/ + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -( add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ) ), 1 )]; + mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( 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 ); + Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + 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 - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); + st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ - 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 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -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 ); @@ -276,7 +276,7 @@ void con_tcx_fx( 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 ); /*Q12*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -284,8 +284,8 @@ void con_tcx_fx( BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ Residu3_fx( A_local, - &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ - &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ + &( synth[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx = Q0*/ + &( exc[-( ( add( ( L_subfr * 2 ), Tc ) + 1 ) + M )] ), /*Qx+1 = Q1*/ add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); BASOP_SATURATE_WARNING_ON_EVS @@ -293,20 +293,20 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); 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 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( sub( Tc, shr( L_frame, 1 ) ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -344,9 +344,9 @@ void con_tcx_fx( 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*/ scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ 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 ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -372,7 +372,7 @@ void con_tcx_fx( &extrapolationFailed, st->nb_subfr ); - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); test(); @@ -386,12 +386,12 @@ void con_tcx_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -414,7 +414,7 @@ void con_tcx_fx( 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] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #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] ), @@ -449,7 +449,7 @@ void con_tcx_fx( 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] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ #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] ), @@ -477,7 +477,7 @@ void con_tcx_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -486,12 +486,12 @@ void con_tcx_fx( if ( fUseExtrapolatedPitch != 0 ) { - pt1_exc = buf; + pt1_exc = buf; /*Q_exc*/ } tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -512,7 +512,7 @@ void con_tcx_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -530,14 +530,14 @@ void con_tcx_fx( tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -599,7 +599,7 @@ void con_tcx_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -608,8 +608,8 @@ void con_tcx_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -617,7 +617,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -631,8 +631,8 @@ void con_tcx_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* 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 ) @@ -699,7 +699,7 @@ void con_tcx_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -709,7 +709,7 @@ void con_tcx_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -733,7 +733,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -741,7 +741,7 @@ void con_tcx_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -762,7 +762,7 @@ void con_tcx_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + sub( 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*/ @@ -784,7 +784,7 @@ void con_tcx_fx( #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 ); /*Q5*/ #endif IF( st->tcxonly != 0 ) { @@ -820,10 +820,10 @@ void con_tcx_fx( test(); 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*/ ); /*Q16*/ } -#ifdef BASOP_NOGLOB /* Critical Overflow */ - L_tmp = L_shl_sat( gain32, 1 ); +#ifdef BASOP_NOGLOB /* Critical Overflow */ + L_tmp = L_shl_sat( gain32, 1 ); /*Q16*/ #else L_tmp = L_shl( gain32, 1 ); #endif @@ -838,8 +838,8 @@ void con_tcx_fx( 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*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -864,7 +864,7 @@ void con_tcx_fx( test(); 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*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -901,7 +901,7 @@ void con_tcx_fx( 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 ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -910,7 +910,7 @@ void con_tcx_fx( 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 ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -938,7 +938,7 @@ void con_tcx_fx( 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 + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -946,7 +946,7 @@ void con_tcx_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -956,15 +956,15 @@ void con_tcx_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* 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 ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -977,10 +977,10 @@ void con_tcx_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ #ifdef BASOP_NOGLOB - tmp_deemph = shl_sat( tmp_deemph, Q_syn ); + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ #else tmp_deemph = shl( tmp_deemph, Q_syn ); #endif @@ -1031,37 +1031,37 @@ void con_tcx_fx( /*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*/ ) ); /*q0*/ /* update ACELP synthesis memory */ 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) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( 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( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( 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 )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( 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 )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -1069,10 +1069,10 @@ 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 ); /*Q_syn*/ 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 ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -1082,7 +1082,7 @@ void con_tcx_fx( } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( 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[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #endif @@ -1097,12 +1097,12 @@ void con_tcx_fx( 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 ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } @@ -1110,7 +1110,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); #endif @@ -1120,7 +1120,7 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ #else hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); #endif @@ -1129,23 +1129,23 @@ void con_tcx_fx( 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 ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*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 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; @@ -1163,10 +1163,10 @@ 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 */ + const Word16 coh, /* i : coherence of stereo signal Q14*/ + Word16 *noise_seed, /* i/o: noise seed for stereo Q0*/ + const Word16 only_left, /* i : TD-PLC only in left channel Q0*/ + const Word16 *A_cng /* i : CNG LP filter coefficients Q14*/ ) { Word16 i, s, c, L_frame, L_subfr, fLowPassFilter, T0; @@ -1224,16 +1224,16 @@ 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 ) ); + L_subfr = mult_r( hTcxDec->L_frameTCX, div_s( 1, st->nb_subfr ) ); /*Q0*/ assert( L_subfr == hTcxDec->L_frameTCX / st->nb_subfr ); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument Q15*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); 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 ); /*Q0*/ 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 */ @@ -1246,22 +1246,22 @@ void con_tcx_ivas_fx( 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 ); /*Q16*/ move32(); } /* set excitation memory*/ exc = buf + OLD_EXC_SIZE_DEC; - tmp_deemph = synth[-1]; + tmp_deemph = synth[-1]; /*Q0*/ move16(); - pre_emph_buf = synth[-1]; + pre_emph_buf = synth[-1]; /*Q0*/ move16(); test(); IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - mem = synth[sub( -add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ), 1 )]; + mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/ move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( 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 ); @@ -1269,18 +1269,18 @@ void con_tcx_ivas_fx( st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), 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 ); /*Q16*/ + st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); /*Q16*/ + st->Mode2_lp_gainp = L_shl( st->Mode2_lp_gainp, 13 ); /*Q29*/ move32(); move32(); move32(); - ana_window = buf; + ana_window = buf; /*Q15*/ ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[sub( -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 ); @@ -1289,7 +1289,7 @@ void con_tcx_ivas_fx( 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 ); /*Q14*/ /* Residu */ assert( ( 2 * L_subfr + Tc + 1 + M ) <= hTcxDec->old_synth_lenFB ); @@ -1306,20 +1306,20 @@ void con_tcx_ivas_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[sub( -L_frame, 1 )]; + mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); 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 ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ 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] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } @@ -1358,9 +1358,9 @@ void con_tcx_ivas_fx( scale_tmp = mult_r( hTcxDec->L_frameTCX, getInvFrameLen( st->L_frame ) ); /*getInvFrameLen()->9Q6*/ 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 ) ); + predPitchLag = L_shl( Mpy_32_16_1( tcxltp_pitch_tmp, shl( scale_tmp, tmp_shift ) ), sub( 9, tmp_shift ) ); /*Q16*/ - T0 = round_fx( predPitchLag ); + T0 = round_fx( predPitchLag ); /*Q0*/ test(); test(); @@ -1401,12 +1401,12 @@ void con_tcx_ivas_fx( fLowPassFilter = 0; move16(); - pt_exc = exc + offset; - pt1_exc = pt_exc - Tc; + pt_exc = exc + offset; /*Q_exc*/ + pt1_exc = pt_exc - Tc; /*Q_exc*/ if ( fUseExtrapolatedPitch != 0 ) { - pt_exc = buf; + pt_exc = buf; /*Q_exc*/ } test(); IF( LT_16( st->stab_fac_fx, 32767 /*1.f Q15*/ ) && EQ_16( st->nbLostCmpt, 1 ) ) @@ -1428,7 +1428,7 @@ void con_tcx_ivas_fx( 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] ); + 174 /* 0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1448,7 +1448,7 @@ void con_tcx_ivas_fx( 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] ); + -174 /*-0.0053f Q15*/, pt1_exc[5] ); /*Q_exc*/ move16(); pt1_exc++; } @@ -1462,7 +1462,7 @@ void con_tcx_ivas_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } fLowPassFilter = 1; @@ -1476,7 +1476,7 @@ void con_tcx_ivas_fx( tmp16 = add( sub( L_frame, imult1616( fLowPassFilter, Tc ) ), L_subfr ); FOR( i = 0; i < tmp16; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } @@ -1497,7 +1497,7 @@ void con_tcx_ivas_fx( } ELSE { - set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); + set32_fx( pitch_buf, st->old_fpitch, st->nb_subfr ); /*Q16*/ } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -1505,24 +1505,24 @@ void con_tcx_ivas_fx( pt_exc = exc + L_frame; IF( T0 == 0 ) { - pt1_exc = pt_exc - Tc; + pt1_exc = pt_exc - Tc; /*Q_exc*/ } ELSE { - pt1_exc = pt_exc - T0; + pt1_exc = pt_exc - T0; /*Q_exc*/ } tmp_loop = shr( L_frame, 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - *pt_exc++ = *pt1_exc++; + *pt_exc++ = *pt1_exc++; /*Q_exc*/ move16(); } } if ( fUseExtrapolatedPitch != 0 ) { - st->old_fpitchFB = predPitchLag; + st->old_fpitchFB = predPitchLag; /*Q16*/ move32(); } st->bpf_gain_param = 0; @@ -1584,7 +1584,7 @@ void con_tcx_ivas_fx( #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], round_fx_sat( gain32 ) ) /*Q1*/; move16(); - gain32 = L_sub_sat( gain32, step32 ); + gain32 = L_sub_sat( gain32, step32 ); /*Q31*/ #else exc[i] = mult_r( exc[i], round_fx( gain32 ) ) /*Q1*/; move16(); @@ -1593,8 +1593,8 @@ void con_tcx_ivas_fx( } /* update old exc without random part */ - offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); - Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); /*Q0*/ + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1602,7 +1602,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1616,8 +1616,8 @@ void con_tcx_ivas_fx( { calcGainc2_fx( &exc[0], Q_exc, L_subfr, &( st->Mode2_lp_gainc ) ); } - set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); - /* PLC: calculate damping factor */ + set32_fx( pitch_buf, L_deposit_h( L_SUBFR ), st->nb_subfr ); /*Q16*/ + /* 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 ) @@ -1645,7 +1645,7 @@ void con_tcx_ivas_fx( Word16 e; tmpSeed1 = *noise_seed; - noise = buf; + noise = buf; /*Q15*/ noise_e = 2; move16(); e = 0; @@ -1653,9 +1653,9 @@ void con_tcx_ivas_fx( alpha_coh = 0; move16(); - IF( NE_16( coh, 16384 ) ) + IF( NE_16( coh, 16384 /*1.0f in Q14*/ ) ) { - alpha_coh = Sqrt16( div_s( sub( 16384, coh ), add( 16384, coh ) ), &e ); + alpha_coh = Sqrt16( div_s( sub( 16384 /*1.0f in Q14*/, coh ), add( 16384 /*1.0f in Q14*/, coh ) ), &e ); /* Q15 - e */ } if ( EQ_16( st->idchan, 1 ) ) { @@ -1688,7 +1688,7 @@ void con_tcx_ivas_fx( ELSE #endif /*IVAS_CODE_CON_TCX*/ { - tmpSeed = st->seed_acelp; + tmpSeed = st->seed_acelp; /*Q0*/ move16(); noise = buf; noise_e = 1; /*set exponent of noise to 1*/ @@ -1698,7 +1698,7 @@ void con_tcx_ivas_fx( FOR( i = 0; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } st->seed_acelp = tmpSeed; @@ -1708,7 +1708,7 @@ void con_tcx_ivas_fx( FOR( ; i < tmp_loop; i++ ) { Random( &tmpSeed ); - noise[i] = shr( tmpSeed, noise_e ); + noise[i] = shr( tmpSeed, noise_e ); /*Q: -noise_e*/ move16(); } } @@ -1732,7 +1732,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_16[i]; + hp_filt[i] = h_high3_16[i]; /*Q15*/ move16(); } } @@ -1740,7 +1740,7 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < L_FIR_FER2; i++ ) { - hp_filt[i] = h_high3_32[i]; + hp_filt[i] = h_high3_32[i]; /*Q15*/ move16(); } } @@ -1761,7 +1761,7 @@ void con_tcx_ivas_fx( move32(); FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); + L_tmp2 = L_mac( L_tmp2, noise[( i + ( L_FIR_FER2 - j ) )], hp_filt[sub( 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*/ @@ -1776,11 +1776,11 @@ void con_tcx_ivas_fx( move16(); 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 ); /*Q13*/ } 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 ); /*Q13*/ } #else tmp16 = 32767; @@ -1807,7 +1807,7 @@ void con_tcx_ivas_fx( { // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; L_tmp = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */ - gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); + gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); /*Q15-gainCNG_e*/ } } #endif @@ -1824,9 +1824,9 @@ void con_tcx_ivas_fx( 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*/ ); /*Q16*/ } - L_tmp = L_shl( gain32, 1 ); + L_tmp = L_shl( gain32, 1 ); /*Q16*/ IF( GT_32( L_shl( L_deposit_h( gainCNG ), sub( gainCNG_e, 31 - 16 ) /*Q16*/ ), L_tmp ) ) { @@ -1839,8 +1839,8 @@ void con_tcx_ivas_fx( 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*/ - st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); + st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31-tmp_e*/ + st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); /*Q16*/ move32(); move32(); @@ -1873,7 +1873,7 @@ void con_tcx_ivas_fx( test(); 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*/ ); /*Q30*/ } ELSE IF( !( EQ_16( st->last_good, UNVOICED_CLAS ) || EQ_16( st->last_good, UNVOICED_TRANSITION ) ) ) { @@ -1907,7 +1907,7 @@ void con_tcx_ivas_fx( 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 ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; gain32 = L_sub( gain32 /*Q16,-tmp_e*/, step32_tmp ); /*Q16,-tmp_e*/ @@ -1916,7 +1916,7 @@ void con_tcx_ivas_fx( 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 ); /*Q-15,noise_e+gain_inov_e-tmp_e*/ move16(); pt_exc++; } @@ -1944,7 +1944,7 @@ void con_tcx_ivas_fx( 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 + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /*Q_exc*/ /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1952,7 +1952,7 @@ void con_tcx_ivas_fx( } ELSE { - Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); + Copy( st->old_exc_fx + L_FRAME16k, st->old_exc_fx, L_FRAME16k / 2 ); /*Q_exc*/ lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; @@ -1962,15 +1962,15 @@ void con_tcx_ivas_fx( /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ /* 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 ); /*Q16*/ + Copy32( pitch_buf, &st->old_pitch_buf_fx[st->nb_subfr], st->nb_subfr ); /*Q16*/ /*----------------------------------------------------------* * - compute the synthesis speech * *----------------------------------------------------------*/ - syn = buf + M; - Copy( synth - M, buf, M ); + syn = buf + M; /*Q_syn*/ + Copy( synth - M, buf, M ); /*Q_syn*/ new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -1984,7 +1984,7 @@ void con_tcx_ivas_fx( Q_syn = tmp16; move16(); - Copy_Scale_sig( buf, mem_syn, M, exp_scale ); + Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /* Q: tmp16 */ #ifdef BASOP_NOGLOB tmp_deemph = shl_sat( tmp_deemph, Q_syn ); @@ -2001,11 +2001,11 @@ void con_tcx_ivas_fx( { Word16 alpha_delayed; - alpha_delayed = 16384; + alpha_delayed = 16384; /*1.0f in Q14*/ move16(); IF( GT_16( 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 ); /*Q14*/ } test(); @@ -2013,13 +2013,13 @@ void con_tcx_ivas_fx( { Word16 lsp_local[M], lsp_fade[M], alpha_inv; - alpha_inv = sub( 16384, alpha_delayed ); + alpha_inv = sub( 16384 /*Q.0f in Q14*/, alpha_delayed ); /*Q14*/ E_LPC_a_lsp_conversion( A_local, lsp_local, lsp_local, M ); 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] ) ); /*Q14*/ move16(); } @@ -2043,37 +2043,37 @@ void con_tcx_ivas_fx( /*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*/ ) ); /*Q0*/ /* update ACELP synthesis memory */ 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) */ - Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); /*Q_syn*/ lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( 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( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /*Q_syn*/ /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); /*Q_syn*/ lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); /*Q_syn*/ FOR( i = 0; i < W12; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( 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 )] ) ); /*Q_syn*/ move16(); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( 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 )] ) ); /*Q_syn*/ move16(); } - set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); + set16_fx( &hHQ_core->old_out_fx[( W1 + n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -2081,10 +2081,10 @@ 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 ); /*Q_syn*/ 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 ) ); /*Q0*/ /* copy total excitation exc2 as 16kHz for acelp mode1 decoding */ IF( st->hWIDec != NULL ) @@ -2109,49 +2109,49 @@ void con_tcx_ivas_fx( 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 ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[( ( W1 - 1 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); + hTcxDec->syn_Overl_TDACFB[( W2 + i )] = add_sat( buf[( W2 + i )], buf[( ( ( W1 - 1 ) - W2 ) - i )] ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } 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 ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[( ( W12 - 1 ) - ( i - W12 ) )].v.im ); /*hTcxDec->Q_syn_Overl_TDACFB*/ move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; move16(); - synth[-1] = pre_emph_buf; + synth[-1] = pre_emph_buf; /*Q0*/ move16(); /* update memory for low band */ st->Q_syn = 0; move16(); - Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); + Scale_sig( hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, Q_syn ) ); /*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 ) ); hTcxDec->Q_syn_Overl_TDAC = hTcxDec->Q_syn_Overl_TDACFB; diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 0a4e950f6..ec8de4900 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -514,7 +514,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - IF( ( 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 ) ) ) + IF( ( st->idchan == 0 && ( ( 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(); @@ -578,7 +578,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - if ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + if ( ( 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(); @@ -654,6 +654,7 @@ void ivas_decision_matrix_dec_fx( { *sharpFlag = 0; move16(); + test(); if ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) { *sharpFlag = 1; @@ -678,6 +679,7 @@ void ivas_decision_matrix_dec_fx( IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) { st->coder_type = get_next_indice_fx( st, 3 ); + move16(); *sharpFlag = 0; move16(); @@ -694,9 +696,10 @@ void ivas_decision_matrix_dec_fx( { /* get coder_type info */ st->coder_type = get_next_indice_fx( st, 3 ); - + move16(); /* get sharpening flag */ *sharpFlag = get_next_indice_fx( st, 1 ); + move16(); } } } @@ -785,7 +788,7 @@ void ivas_decision_matrix_dec_fx( ELSE { st->extl = SWB_TBE; - move32(); + move16(); st->extl_brate = SWB_TBE_1k6; move32(); test(); @@ -878,7 +881,7 @@ void ivas_decision_matrix_dec_fx( 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 ) ) + if ( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( 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 ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a127cd1a4..155e03a17 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -278,6 +278,7 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + move16(); } nchan_transport = st_ivas->nchan_transport; @@ -312,7 +313,7 @@ static ivas_error ivas_dirac_rend_config_fx( Copy32( hDirACRend->hOutSetup.ls_elevation_fx, ls_elevation_fx, nchan_out_woLFE ); } - IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) + IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, -1 ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); @@ -340,6 +341,7 @@ static ivas_error ivas_dirac_rend_config_fx( { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); + move16(); nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; move16(); Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); @@ -470,7 +472,9 @@ static ivas_error ivas_dirac_rend_config_fx( /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ hDirACRend->num_outputs_diff = mult0( ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + move16(); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { @@ -893,7 +897,7 @@ static ivas_error ivas_dirac_rend_config_fx( } test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + 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; move16(); @@ -934,6 +938,7 @@ static ivas_error ivas_dirac_rend_config_fx( } } hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) ); + move16(); } if ( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -975,12 +980,13 @@ static ivas_error ivas_dirac_rend_config_fx( 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 ) && EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) + 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 ) && EQ_16( dec_param_estim_old, TRUE ) ) ) ) { FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) { free( hDirACRend->buffer_intensity_real_fx[i][j] ); @@ -1702,7 +1708,7 @@ ivas_error ivas_dirac_dec_config_fx( move16(); test(); test(); - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) + if ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && !hodirac_flag ) { sparfoa_flag = 1; move16(); @@ -1829,7 +1835,7 @@ ivas_error ivas_dirac_dec_config_fx( /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ test(); test(); - 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 && !( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->nSCE > 0 ) ) { ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } @@ -2029,7 +2035,7 @@ ivas_error ivas_dirac_dec_config( * * Close DirAC memories *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_close( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2055,7 +2061,7 @@ void ivas_dirac_dec_close( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_close_fx( DIRAC_DEC_HANDLE *hDirAC_out ) { @@ -2112,6 +2118,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + move16(); if ( last_bit_pos > 0 ) { st->next_bit_pos = last_bit_pos; @@ -2155,7 +2162,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2239,7 +2246,7 @@ void ivas_dirac_dec_read_BS_fx( } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) + FOR( j = ( orig_dirac_bands - 2 ); j >= 0; j-- ) { hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; move32(); @@ -2421,7 +2428,7 @@ void ivas_qmetadata_to_dirac_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands Q0*/ ) { Word16 block, band; @@ -2435,16 +2442,20 @@ void ivas_qmetadata_to_dirac_fx( Word16 *band_grouping; Word16 start_band; Word16 nbands = 0; + move16(); Word16 nblocks = 0; + move16(); Word16 qBand_idx; Word16 idx_sec = 0; + move16(); Word16 no_secs = 1; + move16(); q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; move16(); hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections ); - + move16(); test(); IF( hMasa != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { @@ -2642,7 +2653,6 @@ void ivas_qmetadata_to_dirac_fx( move16(); tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); } } } @@ -2668,7 +2678,6 @@ void ivas_qmetadata_to_dirac_fx( IF( EQ_32( ivas_format, SBA_FORMAT ) ) { qBand_idx = sub( dirac_to_spar_md_bands[band], start_band ); - move16(); } ELSE { @@ -2740,14 +2749,13 @@ void ivas_qmetadata_to_dirac_fx( Word16 exp_factor = 0; move16(); a = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + tmp1 = mult( a, dirac_dithering_azi_scale_fx[diff_idx] ); // exp_factor + 5 Word32 tmp1_32 = L_deposit_h( tmp1 ); Word16 final_1_exp; Word32 final_1_32 = BASOP_Util_Add_Mant32Exp( azimuth_fx, 9, tmp1_32, exp_factor + 5, &final_1_exp ); - b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor - move16(); + b_tmp = rand_triangular_signed_fx( seed_ptr, &exp_factor ); // q = exp_factor tmp4 = mult( b_tmp, dirac_dithering_ele_scale_fx[diff_idx] ); // exp_factor + 4 Word32 tmp4_32 = L_deposit_h( tmp4 ); @@ -2758,8 +2766,8 @@ void ivas_qmetadata_to_dirac_fx( final_1_32 = BASOP_Util_Add_Mant32Exp( final_1_32, final_1_exp, ONE_IN_Q30, 0, &final_1_exp ); /*0.5 in q31*/ final_2_32 = BASOP_Util_Add_Mant32Exp( final_2_32, final_2_exp, ONE_IN_Q30, 0, &final_2_exp ); - azi = extract_h( L_shr( final_1_32, 31 - final_1_exp - 16 ) ); - ele = extract_h( L_shr( final_2_32, 31 - final_2_exp - 16 ) ); + azi = extract_h( L_shr( final_1_32, sub( sub( 31, final_1_exp ), 16 ) ) ); + ele = extract_h( L_shr( final_2_32, sub( sub( 31, final_2_exp ), 16 ) ) ); /*addition of one to compensate precision loss*/ if ( azi < 0 ) @@ -2836,7 +2844,7 @@ void ivas_qmetadata_to_dirac_fx( } } tmp_write_idx_param_band = add( tmp_write_idx_param_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - move16(); + } /* for ( block =...) */ } /* for ( band = ...) */ @@ -2875,7 +2883,7 @@ void ivas_qmetadata_to_dirac_fx( } /* update buffer write index */ hSpatParamRendCom->dirac_bs_md_write_idx = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; - + move16(); return; } #else @@ -3296,6 +3304,7 @@ void ivas_dirac_dec_set_md_map( } iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 ); hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3458,15 +3467,12 @@ void ivas_dirac_dec_set_md_map_fx( norm_num = norm_l( tmp_fx ); num = L_shl( tmp_fx, norm_num ); exp_num = sub( exp_num, norm_num ); - move16(); norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); exp_denom = sub( exp_denom, norm_denom ); - move16(); exp = sub( exp_num, exp_denom ); - move16(); IF( GT_32( num, L_deposit_l( denom ) ) ) { @@ -3478,7 +3484,7 @@ void ivas_dirac_dec_set_md_map_fx( 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, sub( sub( Q31, exp_final ), Q16 ) ) ); - hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; // Q0 move16(); } set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); @@ -3500,7 +3506,7 @@ void ivas_dirac_dec_render_fx( 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 */ + Word32 *output_fx[] /* o : rendered time signal Q(6-1)*/ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -3520,7 +3526,7 @@ void ivas_dirac_dec_render_fx( set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL - move16(); + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); @@ -3537,7 +3543,6 @@ void ivas_dirac_dec_render_fx( { slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); last_sf = add( last_sf, 1 ); - move16(); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -3563,7 +3568,7 @@ void ivas_dirac_dec_render_fx( { test(); test(); - IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) + IF( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( ( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ) || EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) { Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); } @@ -3572,16 +3577,16 @@ 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 ) ){ 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 ) ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); // Q0 } 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 ) ); // Q0 } } -*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); +*nSamplesAvailableNext = i_mult( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); // Q0 move16(); return; @@ -3677,11 +3682,12 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ - 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] ) + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output Q(6-1)*/ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], /*Q6*/ + Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] /*Q6*/ +) { Word16 i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; @@ -3785,15 +3791,16 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_or( 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 ) ) ) { IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len ); - scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); + scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); // Q(proto_power_diff_smooth_q + tmp1) state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 ); + move16(); } } @@ -3813,7 +3820,7 @@ void ivas_dirac_dec_render_sf_fx( IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); // tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; move16(); } @@ -3823,18 +3830,20 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift ); - + move16(); shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + shift h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift ); - + move16(); tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth + tmp1 h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 ); + move16(); } + test(); test(); IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) @@ -3845,7 +3854,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } } - ELSE IF( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( !( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { Word16 outchannels; idx_lfe = 0; @@ -3877,7 +3886,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -3890,10 +3899,12 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx; @@ -3925,7 +3936,7 @@ void ivas_dirac_dec_render_sf_fx( size_ho = size; move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); @@ -3933,49 +3944,51 @@ void ivas_dirac_dec_render_sf_fx( { Word16 shift; shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); + move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 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_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); } ELSE { Word16 shift; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); // Q( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev+ shift) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); - + move16(); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev+ tmp1) hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 ); - + move16(); tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q tmp1) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 ); - + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q+ tmp1) 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, tmp1 ); + move16(); } } @@ -4001,7 +4014,7 @@ void ivas_dirac_dec_render_sf_fx( subframe_idx = hSpatParamRendCom->subframes_rendered; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); @@ -4013,7 +4026,7 @@ void ivas_dirac_dec_render_sf_fx( } /* copy parameters into local buffers*/ - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); q_diffuseness_vector = Q30; @@ -4028,7 +4041,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); } @@ -4046,7 +4059,7 @@ void ivas_dirac_dec_render_sf_fx( { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); } @@ -4055,13 +4068,14 @@ void ivas_dirac_dec_render_sf_fx( ELSE { p_Rmat_fx = 0; + move32(); } - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + IF( ( hDirAC->hConfig->dec_param_estim == FALSE ) ) { Word16 *masa_band_mapping; /* compute response */ - IF( 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, @@ -4089,7 +4103,7 @@ void ivas_dirac_dec_render_sf_fx( surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); move32(); - surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); // Q31 move32(); } } @@ -4114,13 +4128,16 @@ void ivas_dirac_dec_render_sf_fx( &max_exp_direct, &max_exp_diffusion ); hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub( Q31, max_exp_direct ); + move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); + move16(); IF( coherence_flag ) { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + move32(); } } ELSE @@ -4176,7 +4193,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { @@ -4198,7 +4215,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); - IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( ( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); } @@ -4219,7 +4236,7 @@ void ivas_dirac_dec_render_sf_fx( } test(); test(); - IF( L_or( 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 ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4229,7 +4246,7 @@ void ivas_dirac_dec_render_sf_fx( q_cldfb = Q6; move16(); } - ELSE IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( nchan_transport, 2 ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) { @@ -4260,13 +4277,16 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); test(); - IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + IF( 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->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; Word16 Q_input = Q11; move16(); q_temp_cldfb = Q11; move16(); + test(); + test(); + test(); generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], st_ivas->hTcBuffer->tc_fx[1], @@ -4274,9 +4294,9 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_ImagBuffer_fx[1][0], index_slot, st->cna_dirac_flag && st->flag_cna, - ( L_or( EQ_32( st->core_brate, FRAME_NO_DATA ), EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); - Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); - Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); + ( ( ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &q_temp_cldfb ); + Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, q_temp_cldfb ) ); // Q6 } /* LFE synthesis */ @@ -4450,6 +4470,7 @@ void ivas_dirac_dec_render_sf_fx( ELSE { hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( idiv1616( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ + move16(); } index = hDirACRend->index_buffer_intensity; @@ -4494,7 +4515,7 @@ void ivas_dirac_dec_render_sf_fx( 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[add( imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff ), imult1616( imult1616( 2, hSpatParamRendCom->num_freq_bands ), s_min( 4, nchan_transport ) ) )], + &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 ) * s_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, @@ -4508,8 +4529,9 @@ void ivas_dirac_dec_render_sf_fx( ELSE { scale = L_norm_arr( hDirACRend->proto_frame_f_fx, proto_length ); - Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); + Scale_sig32( hDirACRend->proto_frame_f_fx, proto_length, scale ); // Q(proto_frame_f_q+scale) hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, scale ); + move16(); ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, @@ -4556,7 +4578,7 @@ void ivas_dirac_dec_render_sf_fx( * output synthesis *-----------------------------------------------------------------*/ test(); - IF( L_or( 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 ) ) ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state; Word16 diffuse_start; @@ -4564,13 +4586,13 @@ void ivas_dirac_dec_render_sf_fx( diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len ); - scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); + scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); // hDirACRend->proto_frame_dec_f_q + exp hDirACRend->proto_frame_dec_f_q = add( hDirACRend->proto_frame_dec_f_q, exp ); - + move16(); exp = getScaleFactor32( state->proto_diffuse_buffer_f_fx, diffuse_start ); - scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); + scale_sig32( state->proto_diffuse_buffer_f_fx, diffuse_start, exp ); // state->proto_diffuse_buffer_f_q + exp state->proto_diffuse_buffer_f_q = add( state->proto_diffuse_buffer_f_q, exp ); - + move16(); /*Compute diffuse prototypes*/ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } @@ -4589,47 +4611,49 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) + IF( ( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { - Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); - IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) + IF( ( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->direct_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); + scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); // Q31 h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); - scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); // Q31 h_dirac_output_synthesis_state->direct_responses_square_q = Q31; move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth+ exp h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, exp ); - + move16(); exp = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_channels_dir, hSpatParamRendCom->num_freq_bands ), exp ); // h_dirac_output_synthesis_state->q_cy_auto_diff_smooth+ exp h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); + move16(); } test(); @@ -4685,13 +4709,13 @@ void ivas_dirac_dec_render_sf_fx( IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ) { - scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); + scale_sig32( hSpatParamRendCom->diffuseness_vector_fx[md_idx], hSpatParamRendCom->num_freq_bands, sub( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ); // q_diffuseness_vector hSpatParamRendCom->q_diffuseness_vector = q_diffuseness_vector; move16(); } ELSE { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( hSpatParamRendCom->q_diffuseness_vector, q_diffuseness_vector ) ); // q_diffuseness_vector q_diffuseness_vector = hSpatParamRendCom->q_diffuseness_vector; move16(); } @@ -4702,13 +4726,13 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( q_reference_power_smooth, DirAC_mem.reference_power_q ) ) { - scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); + scale_sig32( reference_power_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, DirAC_mem.reference_power_q ) ); // q_reference_power_smooth DirAC_mem.reference_power_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( DirAC_mem.reference_power_q, q_reference_power_smooth ) ); // reference_power_q q_reference_power_smooth = DirAC_mem.reference_power_q; move16(); } @@ -4728,17 +4752,17 @@ void ivas_dirac_dec_render_sf_fx( { offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ); buff_len = i_mult( 2, i_mult( nchan_transport, hSpatParamRendCom->num_freq_bands ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - buff_len = 2 * hDirACRend->num_outputs_diff * hSpatParamRendCom->num_freq_bands; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); + buff_len = i_mult( 2, i_mult( hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, q_proto_diffuse_buffer[slot_idx] ) ); // proto_diffuse_buffer_f_q } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { offset = i_mult( slot_idx, i_mult( 4, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q } ELSE { @@ -4750,7 +4774,7 @@ void ivas_dirac_dec_render_sf_fx( case 4: offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); buff_len = i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 2: IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -4763,16 +4787,17 @@ void ivas_dirac_dec_render_sf_fx( offset = i_mult( i_mult( i_mult( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), 2 ); buff_len = i_mult( 4, hSpatParamRendCom->num_freq_bands ); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; case 1: offset = i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); buff_len = i_mult( 2, hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx + offset, buff_len, sub( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, q_proto_direct_buffer[slot_idx] ) ); // proto_direct_buffer_f_q BREAK; } } q_proto_direct_buffer[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + move16(); } ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); @@ -4792,44 +4817,45 @@ void ivas_dirac_dec_render_sf_fx( { IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, Q26 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth ) ); // Q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; + move16(); } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size_ho, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); // Q26 } IF( NE_16( q_diffuseness_vector, Q30 ) ) { - scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); + scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q30, q_diffuseness_vector ) ); // Q30 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, @@ -4852,8 +4878,8 @@ void ivas_dirac_dec_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( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4863,8 +4889,8 @@ void ivas_dirac_dec_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( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, add( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, sub( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, 33 ) ) ) ); // Q6 } } } @@ -4884,37 +4910,37 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, size, sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, h_dirac_output_synthesis_state->diff_dir_power_factor_len, sub( Q31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ) ); // Q31 } IF( NE_16( q_diffuseness_vector, Q31 ) ) { - Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); + Scale_sig32( diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, q_diffuseness_vector ) ); // Q31 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, Q31 ) ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, i_mult( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ), sub( Q31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q ) ); // Q31 } exp = L_norm_arr( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, exp ); // q_reference_power_smooth + exp q_reference_power_smooth = add( q_reference_power_smooth, exp ); IF( LT_16( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub( q_reference_power_smooth, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q ) ); // q_reference_power_smooth hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = q_reference_power_smooth; move16(); } ELSE { - scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, sub( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, q_reference_power_smooth ) ); // reference_power_smooth_prev_q q_reference_power_smooth = hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q; move16(); } @@ -4923,49 +4949,52 @@ void ivas_dirac_dec_render_sf_fx( { IF( LT_16( 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_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = hDirACRend->masa_stereo_type_detect->q_subtract_power_y; move16(); } ELSE { - hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( 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_shr( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub( hDirACRend->masa_stereo_type_detect->q_subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ) ); // q_subtract_power_y + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth; move16(); } } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, proto_power_smooth_len, exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, exp ); - + move16(); IF( LT_16( 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, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( 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, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ) ); // 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; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, i_mult( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q ) ); // 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; move16(); } exp = getScaleFactor32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), exp ); // Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + exp) hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, exp ); + move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { IF( LT_16( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_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_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_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_prev_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q ) ); // 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; move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( 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_fx, i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q ) ); // 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; move16(); } @@ -4973,15 +5002,15 @@ void ivas_dirac_dec_render_sf_fx( IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); // Q26 } IF( NE_16( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, Q26 ) ) { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); // Q26 } IF( hDirACRend->proto_signal_decorr_on ) { - 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( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.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( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) ); // 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; move16(); } @@ -5015,8 +5044,8 @@ void ivas_dirac_dec_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( Q6, q_Cldfb ) ); - scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); + scale_sig32( Cldfb_RealBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 + scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], hSpatParamRendCom->num_freq_bands, sub( Q6, q_Cldfb ) ); // Q6 } } } @@ -5030,12 +5059,12 @@ void ivas_dirac_dec_render_sf_fx( test(); test(); - IF( L_or( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */ test(); test(); - IF( L_and( L_and( 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 ) ) ) { Word16 in_ch; FOR( in_ch = 0; in_ch < st_ivas->nchan_ism; in_ch++ ) @@ -5092,7 +5121,7 @@ void ivas_dirac_dec_render_sf_fx( for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ ) { test(); - IF( L_and( st_ivas->hIntSetup.num_lfe > 0, ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) + IF( ( st_ivas->hIntSetup.num_lfe > 0 && ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) { IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) { @@ -5109,28 +5138,30 @@ void ivas_dirac_dec_render_sf_fx( prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); test(); - IF( L_or( L_abs( gain_fx ) > 0, L_abs( prev_gain_fx ) > 0 ) ) + IF( ( L_abs( gain_fx ) > 0 || L_abs( prev_gain_fx ) > 0 ) ) { Word32 *tc_re_fx, *tc_im_fx; Word16 *w1_fx, w2_fx; w1_fx = &st_ivas->hIsmRendererData->interpolator_fx[interp_offset]; - tc_re_fx = pppQMfFrame_ts_re_fx[add( nchan_transport, i )][0]; + tc_re_fx = pppQMfFrame_ts_re_fx[nchan_transport + i][0]; move32(); - tc_im_fx = pppQMfFrame_ts_im_fx[add( nchan_transport, i )][0]; + tc_im_fx = pppQMfFrame_ts_im_fx[nchan_transport + i][0]; move32(); FOR( k = 0; k < n_slots_to_render; k++ ) { Word32 g_fx; w2_fx = sub( MAX16B, *w1_fx ); - g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); + g_fx = L_add( Mpy_32_16_1( gain_fx, *w1_fx ), Mpy_32_16_1( prev_gain_fx, w2_fx ) ); // Q15 FOR( l = 0; l < hSpatParamRendCom->num_freq_bands; l++ ) { Word32 tmp; tmp = Mpy_32_32( g_fx, *tc_re_fx ); - Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_RealBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_RealBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; tmp = Mpy_32_32( g_fx, *tc_im_fx ); - Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )] = L_add( Cldfb_ImagBuffer_fx[j2][0][add( i_mult( k, hSpatParamRendCom->num_freq_bands ), l )], tmp ); + Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l] = L_add( Cldfb_ImagBuffer_fx[j2][0][k * hSpatParamRendCom->num_freq_bands + l], tmp ); + move32(); tc_re_fx++; } w1_fx += hSpatParamRendCom->num_freq_bands; @@ -5159,14 +5190,14 @@ void ivas_dirac_dec_render_sf_fx( Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, &input_q ); - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[0][0], i_mult( BINAURAL_CHANNELS, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, CLDFB_NO_CHANNELS_MAX ) ), sub( Q6, input_q ) ); // Q6 /* Inverse CLDFB*/ FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - Word32 *synth_fx = &output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )]; + Word32 *synth_fx = &output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands]; Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) @@ -5177,8 +5208,8 @@ void ivas_dirac_dec_render_sf_fx( move32(); } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, synth_fx, i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); @@ -5191,14 +5222,17 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[ch]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[ch]->no_channels, 1 ) ), st_ivas->cldfbSynDec[ch]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( synth_fx, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( synth_fx, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } } - ELSE IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) { @@ -5252,9 +5286,10 @@ void ivas_dirac_dec_render_sf_fx( Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe ); FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { /* Move the LFE channel to the correct place */ Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe ); @@ -5297,9 +5332,10 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); test(); @@ -5307,18 +5343,18 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - RealBuffer_fx[i] = Cldfb_RealBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); - ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[sub( MAX_OUTPUT_CHANNELS, 1 )][i]; + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][i]; move32(); } Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); Word16 samplesToProcess = i_mult( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - Word32 *p_out = &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ); - - scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = sub( Q6, 1 ); + Word32 *p_out = &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ); + scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); // Q6-1 + st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = ( Q6 - 1 ); + move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[cldfbSynIdx] ); // Calculating length of output @@ -5328,11 +5364,14 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, 1 ) ), st_ivas->cldfbSynDec[cldfbSynIdx]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } Word16 synth_len = imult1616( no_col, no_channels ); - scale_sig32( p_out, synth_len, sub( Q11, sub( Q6, 1 ) ) ); + scale_sig32( p_out, synth_len, ( Q11 - ( Q6 - 1 ) ) ); // Q11 } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && hDirACRend->hOutSetup.separateChannelEnabled ) { @@ -5340,7 +5379,7 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - set32_fx( &( output_buf_fx[ch][i_mult( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); + set32_fx( &( output_buf_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); } IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5373,13 +5412,16 @@ void ivas_dirac_dec_render_sf_fx( move16(); IF( GT_16( samplesToProcess, -1 ) ) { - no_col = s_min( no_col, ( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ) ) / st_ivas->cldfbSynDec[idx_in]->no_channels ); + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide1616_Scale( add( samplesToProcess, sub( st_ivas->cldfbSynDec[idx_in]->no_channels, 1 ) ), st_ivas->cldfbSynDec[idx_in]->no_channels, &tmp_e ); + tmp = shr( tmp, 15 - tmp_e ); + no_col = s_min( no_col, tmp ); } out_len = imult1616( no_col, no_channels ); // Scaling cldfb_state to Q6-1 - scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( sub( Q6, 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); - st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = sub( Q6, 1 ); + scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->p_filter_length, sub( ( Q6 - 1 ), st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); + st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = ( Q6 - 1 ); move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[idx_in] ); @@ -5394,7 +5436,9 @@ void ivas_dirac_dec_render_sf_fx( } hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + move16(); hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -5411,7 +5455,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 ) ); // Q11 st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; move16(); } @@ -5451,7 +5495,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( ch = 0; ch < outchannels; ch++ ) { test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5464,22 +5508,23 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { + test(); test(); - IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + IF( ( hDirACRend->hOutSetup.num_lfe > 0 && ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { test(); 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 ) ); // Q11 st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; move16(); } } 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 ) ); // Q11 st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; move16(); idx_in = add( idx_in, 1 ); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 4af727672..4bcfdc3e6 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -70,7 +70,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( 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 Word32 *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) Q(15-proto_matrix_e) */ ) { Word16 idx; @@ -89,7 +89,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } h_dirac_output_synthesis_params->proto_matrix_len = imult1616( nchan_out, nchan_in ); - + move16(); /* cov buffers */ FOR( idx = 0; idx < num_param_bands; idx++ ) { @@ -116,6 +116,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); h_dirac_output_synthesis_state->mixing_matrix_len = i_mult( nchan_out, nchan_in ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -139,6 +140,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], imult1616( nchan_out, nchan_out ) ); h_dirac_output_synthesis_state->mixing_matrix_res_len = i_mult( nchan_out, nchan_out ); + move16(); } FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { @@ -194,6 +196,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( FOR( idx = 1; idx <= interp_length; ++idx ) { h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); + move16(); } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, imult1616( nchan_in, nchan_out ) ); h_dirac_output_synthesis_params->proto_matrix_e = 5; @@ -734,13 +737,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( *-------------------------------------------------------------------*/ #ifdef FIX_835_PARAMMC_BUFFER_VALUES void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( - Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) Q(31- RealBuffer_e)*/ Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part Q(ImagBuffer_e)*/ Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ - Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) Q(31- cx_e)*/ Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ - Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) Q(31- cx_imag_e)*/ Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ const Word16 param_band, /* i : parameter band */ @@ -777,9 +780,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( band = add( brange[0], band_idx ); FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) { - real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + real_in_buffer_fx[band_idx + num_bands * ch_idx] = RealBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); - imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + imag_in_buffer_fx[band_idx + num_bands * ch_idx] = ImagBuffer_fx[band + hParamMC->num_freq_bands * ch_idx]; move32(); } } @@ -788,8 +791,8 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( move16(); imag_in_e = ImagBuffer_e; move16(); - shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); - shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); + shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); + shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( add( num_bands, 1 ) ) ); real_in_e = sub( real_in_e, shift_real ); imag_in_e = sub( imag_in_e, shift_imag ); @@ -799,9 +802,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( i = 0; i < num_bands * nchan_in; ++i ) { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); // Q(31-output_e) move32(); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); // Q(31-output_e) move32(); } @@ -831,10 +834,10 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) { L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[j], cx_init_e, 0, 0, &tmp1_e ); - cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); + cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); // Q(31-tmp1) move32(); L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[j], cx_init_imag_e, 0, 0, &tmp2_e ); - cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); + cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); // Q(31-tmp2) move32(); } @@ -1095,13 +1098,13 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( } #else void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - Word32 *Cldfb_RealBuffer_in_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) */ + Word32 *Cldfb_RealBuffer_in_fx, /*Q6*/ + Word32 *Cldfb_ImagBuffer_in_fx, /*Q6*/ + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (real part) Q6*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : output channel filter bank samples (imaginary part) Q6*/ + Word32 *mixing_matrix_fx[], /* i : parameter band wise mixing matrices (direct part) Q(31-mixing_matrix_e)*/ 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) */ + Word32 *mixing_matrix_res_fx[], /* i : parameter band wise mixing matrices (residual part) Q(31-mixing_matrix_res_e)*/ 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 */ @@ -1118,6 +1121,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word16 mixing_matrix_smooth_e; Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_res_smooth_e = 0; + move16(); Word32 mixing_matrix_buffer_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; Word16 mixing_matrix_buffer_e; Word32 input_f_real_fx[PARAM_MC_MAX_TRANSPORT_CHANS]; @@ -1145,7 +1149,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move16(); brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + brange[1] = hParamMC->band_grouping[( param_band_idx + 1 )]; move16(); if ( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) @@ -1191,7 +1195,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( assert( LT_16( band, hParamMC->h_output_synthesis_params.max_band_decorr ) ); 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 + diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); diff_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band]; move32(); @@ -1200,17 +1204,17 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); + scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); + scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); // Q6 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(); - Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; + Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = output_f_imag_fx[ch_idx]; // Q6 move32(); } } @@ -1229,20 +1233,20 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { - input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; // Q6 + 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[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 move32(); } /* apply mixing matrix */ matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_real_fx, 25, nX, 1, 0, output_f_real_fx, &output_f_real_e ); - 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 ) ) ); // Q6 matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_imag_fx, 25, nX, 1, 0, output_f_imag_fx, &output_f_imag_e ); - 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 ) ) ); // Q6 /* collect output */ FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) @@ -1529,20 +1533,20 @@ int16_t computeMixingMatrices( 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 Word32 *Cx, /* i : input channel covariance matrix Q(31-Cx_e) */ Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ + const Word32 *Cy, /* i : target covariance matrix Q(31-Cy_e) */ Word16 Cy_e, - const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) */ + const Word32 *Q, /* i : prototype matrix (usually a upmix matrix) Q_fx_e */ 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 */ 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 Q(31-reg_ghat_e) */ Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix Q(31-mixing_matrix_out_e) */ Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ + Word32 *Cr_fx, /* o : residual covariance matrix Q(31-Cr_e) */ Word16 *Cr_e ) { Word16 i, j; @@ -1650,9 +1654,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[add( i, imult1616( j, lengthCy ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Ky_fx[i + ( j * lengthCy )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Ky_fx_e[add( i, imult1616( j, lengthCy ) )] = tmp_e; + Ky_fx_e[i + ( j * lengthCy )] = tmp_e; move16(); } } @@ -1674,9 +1678,9 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_e[j]; move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Kx_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + Kx_fx[( i + ( j * lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); - Kx_fx_e[add( i, imult1616( j, lengthCx ) )] = tmp_e; + Kx_fx_e[( i + ( j * lengthCx ) )] = tmp_e; move16(); } } @@ -1686,7 +1690,7 @@ Word16 computeMixingMatrices_fx( { tmp_e = svd_s_buffer_e[i]; 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 ); // Q(31-tmp_e) move32(); svd_s_buffer_e[i] = tmp_e; move16(); @@ -1744,9 +1748,9 @@ Word16 computeMixingMatrices_fx( scale = add( scale, sub( Q31, svd_s_buffer_e[i] ) ); FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[add( i, imult1616( 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 ); // Q(31-scale) move32(); - Kx_reg_inv_e[add( i, imult1616( j, lengthCx ) )] = scale; + Kx_reg_inv_e[i + j * lengthCx] = scale; move16(); } } @@ -1780,7 +1784,7 @@ Word16 computeMixingMatrices_fx( #endif } #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // limit_e+ reg_ghat_e limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); #endif @@ -1798,7 +1802,7 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( 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 = add( exp, sub( Cy_fx_e, Cy_hat_diag_buff_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; @@ -1839,7 +1843,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1919,7 +1923,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -1943,11 +1947,11 @@ Word16 computeMixingMatrices_fx( } /* Avoid Meaningless negative main diagonal elements */ - IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[add( i, imult1616( i, lengthCy ) )], exp, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + ( i * lengthCy )], exp, 0, 0 ) < 0 ) { - Cr_fx[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_fx[i + ( i * lengthCy )] = 0; move32(); - Cr_e_arr[add( i, imult1616( i, lengthCy ) )] = 0; + Cr_e_arr[i + ( i * lengthCy )] = 0; move16(); } } @@ -1965,7 +1969,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); + Cr_fx[i] = L_shr( Cr_fx[i], sub( exp, Cr_e_arr[i] ) ); // Q(31-exp) move32(); } @@ -1985,7 +1989,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); + mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], sub( exp, mat_mult_buffer2_fx_e[i] ) ); // Q(31-exp) move32(); } @@ -2005,16 +2009,16 @@ Word16 computeMixingMatrices_fx( { /* 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[add( i, imult1616( 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; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 1; move16(); } ELSE { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], L_add( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], EPSILON_FX ), &exp ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + ( i * lengthCy )], L_add( Cy_tilde_p_fx[i + ( i * lengthCy )], EPSILON_FX ), &exp ); exp = add( exp, sub( Cy_fx_e, mat_mult_buffer2_e ) ); L_tmp = L_deposit_h( tmp ); L_tmp = Sqrt32( L_tmp, &exp ); @@ -2026,7 +2030,7 @@ Word16 computeMixingMatrices_fx( IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], adj_e[i], 1073741824, 3 ) > 0 ) { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_e[i] = 3; move16(); @@ -2046,7 +2050,7 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); // Q(31-exp) move32(); } adj_fx_e = exp; @@ -2054,7 +2058,7 @@ Word16 computeMixingMatrices_fx( 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, imult1616( lengthCx, lengthCy ) ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); // Q(31-mat_mult_buffer3_e) mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2271,15 +2275,15 @@ 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 Q(31-Cx_e) */ 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()) Q(31-Cy_fx_e) */ 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 Q(31-reg_Sx_e) */ 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 Q(31-reg_ghat_e) */ const Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix */ + Word32 *mixing_matrix_fx, /* o : resulting residual mixing matrix Q(31-mixing_matrix_ret_e) */ Word16 *mixing_matrix_ret_e ) { Word16 i, j; @@ -2359,7 +2363,7 @@ Word16 computeMixingMatricesResidual_fx( tmp_e = svd_s_buffer_e[j]; move16(); 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[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); // Q(31-tmp_e) move32(); Ky_fx_e[i + j * lengthCy] = tmp_e; move16(); @@ -2382,6 +2386,7 @@ Word16 computeMixingMatricesResidual_fx( exp = Cx_e; move16(); Kx_fx[i] = Sqrt32( Cx_fx[i], &exp ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -2405,7 +2410,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); // limit_e + reg_Sx_e L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); @@ -2427,10 +2432,11 @@ 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 ); // 1073741824 -> 1.0f in Q30 scale = add( scale, sub( Q1, exp ) ); Kx_reg_inv_fx[i] = L_deposit_h( tmp ); + move32(); Kx_reg_inv_e[i] = scale; move16(); } @@ -2449,7 +2455,7 @@ 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 ) ); // Q(31-Cx_e) Cy_hat_diag_e = Cx_e; move16(); @@ -2464,7 +2470,7 @@ Word16 computeMixingMatricesResidual_fx( } } - L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); + L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); // Q(limit_e+reg_ghat_e) limit_fx = L_add( L_tmp, EPSILON_FX ); limit_e = add( limit_e, reg_ghat_e ); @@ -2496,7 +2502,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs; i++ ) { - L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); + L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); // Q(31-(Kx_fx_e+G_hag_e)) Kx_fx[i] = L_tmp; move32(); Kx_fx_e[i] = add( Kx_fx_e[i], G_hat_e[i] ); @@ -2511,10 +2517,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( Ky_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mat_mult_buffer1_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); // Q(31-(Ky_fx_e+Kx_fx_e)) + mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; move32(); - mat_mult_buffer1_buff_e[add( i, imult1616( j, extract_l( num_outputs ) ) )] = extract_l( L_add( Ky_fx_e[add( i, imult1616( j, extract_l( 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] ) ); + move16(); } } @@ -2531,7 +2538,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); // Q(31-mat_mult_buffer1_e) move32(); } @@ -2572,11 +2579,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < num_outputs; j++ ) { #ifdef FIX_827_HIGH_MLD - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( i, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); // Q(31-mat_mult_buffer1_e+Kx_reg_inv_e) + mixing_matrix_fx[j + i * num_outputs] = L_tmp; #else - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); - mixing_matrix_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + j * num_outputs], fac_fx ); // mat_mult_buffer1_e+Kx_reg_inv_e + mixing_matrix_fx[j + j * num_outputs] = L_tmp; #endif move32(); mixing_matrix_fx_e[j + i * num_outputs] = add( mat_mult_buffer1_buff_e[j + i * num_outputs], Kx_reg_inv_e[i] ); @@ -2608,7 +2615,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); + mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], sub( exp, mixing_matrix_fx_e[i] ) ); // Q(31-exp) move32(); } mixing_matrix_e = exp; @@ -2627,7 +2634,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( exp, mat_mult_buffer1_buff_e[i] ) ); // Q(31-exp) move32(); } mat_mult_buffer1_e = exp; @@ -2643,14 +2650,15 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( 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 = add( scale, sub( Cy_fx_e, Cy_tilde_e ) ); adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); + move32(); adj_buff_e[i] = scale; move16(); - 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 ) // 1073741824 -> 1.0f in Q30 { - adj_fx_p[i] = 1073741824; + adj_fx_p[i] = 1073741824; // 1.0f in Q30 move32(); adj_buff_e[i] = 3; move16(); @@ -2672,7 +2680,7 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); // Q(31-adj_e) move32(); } @@ -2698,19 +2706,19 @@ Word16 computeMixingMatricesISM_fx( const Word16 num_inputs, const Word16 num_responses, const Word16 num_outputs, - const Word32 *responses_fx, + const Word32 *responses_fx, /*Q(31-responses_e) */ const Word16 responses_e, - const Word32 *ener_fx, + const Word32 *ener_fx, /*Q(31-ener_e) */ const Word16 ener_e, - const Word32 *Cx_diag_fx, + const Word32 *Cx_diag_fx, /*Q(31-diag_e) */ const Word16 Cx_diag_e, - const Word32 *Cy_diag_fx, + const Word32 *Cy_diag_fx, /*Q(31-diag_e) */ const Word16 Cy_diag_e, const Word16 *Q_16fx, // Q15 const Word16 energy_compensation_flag, - const Word32 reg_Sx_fx, - const Word32 reg_ghat_fx, - Word32 *mixing_matrix_fx, + const Word32 reg_Sx_fx, /*Q0*/ + const Word32 reg_ghat_fx, /*Q0*/ + Word32 *mixing_matrix_fx, /*Q(31-mixing_matrix_e) */ Word16 *mixing_matrix_e ) { Word16 i, out; @@ -2743,7 +2751,7 @@ Word16 computeMixingMatricesISM_fx( push_wmops( "dirac_cov_mix_mat" ); out = EXIT_SUCCESS; - move32(); + move16(); lengthCx = num_inputs; move16(); lengthCy = num_outputs; @@ -2787,13 +2795,13 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); + Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); // Q(31-Kx_e) move32(); } /* Regularization of Sx */ maximum_32_fx( Kx_fx, lengthCx, &limit_fx ); - limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_Sx_fx ); // Cy_hat_diag_e + reg_ghat_e FOR( i = 0; i < lengthCx; ++i ) { @@ -2845,7 +2853,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); + Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); // Q(31- Kx_reg_inv_e) move32(); } @@ -2893,7 +2901,7 @@ Word16 computeMixingMatricesISM_fx( } } - limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); + limit_fx = Mpy_32_32( limit_fx, reg_ghat_fx ); // Cy_hat_diag_e + reg_ghat_e /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) @@ -2940,7 +2948,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); + G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); // Q(31-G_hat_e) move32(); } @@ -3006,7 +3014,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] < 0 ) + IF( Cy_tilde_p_fx[( i + ( i * lengthCy ) )] < 0 ) { adj_fx[i] = MAX_32; move32(); @@ -3017,9 +3025,9 @@ Word16 computeMixingMatricesISM_fx( { IF( Cy_diag_fx[i] ) { - IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] ) + IF( Cy_tilde_p_fx[i + ( i * lengthCy )] ) { - adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], &temp_e[i] ); + adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[i + ( i * lengthCy )], &temp_e[i] ); move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, mat_mult_buffer2_e ) ); move16(); @@ -3061,7 +3069,7 @@ Word16 computeMixingMatricesISM_fx( } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); + adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); // Q(31-adj_e) move32(); } diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index f27836c0e..9bb027025 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -960,15 +960,15 @@ void TonalMDCTConceal_SaveTimeSignal_ivas( #ifdef IVAS_FLOAT_FIXED void TonalMdctConceal_create_concealment_noise_ivas_fx( - Word32 concealment_noise[L_FRAME48k], + Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_exp Word16 *concealment_noise_exp, CPE_DEC_HANDLE hCPE, - const Word16 L_frameTCX, - const Word16 L_frame, - const Word16 idchan, - const Word16 subframe_idx, - const Word16 core, - const Word16 crossfade_gain, + const Word16 L_frameTCX, // Q0 + const Word16 L_frame, // Q0 + const Word16 idchan, // Q0 + const Word16 subframe_idx, // Q0 + const Word16 core, // Q0 + const Word16 crossfade_gain, // Q15 const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ) { STEREO_MDCT_DEC_DATA_HANDLE hStereoMdct; @@ -1027,10 +1027,10 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* first lost frame is handled separately */ IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - *rnd = add( 1977, idchan ); + *rnd = add( 1977, idchan ); // Q0 move16(); /* will be set twice when looping over two channels, but does not matter */ - *rnd_c = 1979; + *rnd_c = 1979; // Q0 move16(); } @@ -1042,7 +1042,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { *rnd = own_random( rnd ); move16(); - concealment_noise[i] = *rnd; + concealment_noise[i] = *rnd; // Q31-concealment_noise_exp move32(); } *concealment_noise_exp = 31; @@ -1052,7 +1052,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( return; } - save_rnd_c = *rnd_c; + save_rnd_c = *rnd_c; // Q0 move16(); c_e = 1; @@ -1067,13 +1067,13 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { IF( LT_16( c_e, c_inv_e ) ) { - c = shr( c, sub( c_inv_e, c_e ) ); + c = shr( c, sub( c_inv_e, c_e ) ); // Q0 c_e = c_inv_e; move16(); } ELSE { - c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); + c_inv = shr( c_inv, sub( c_e, c_inv_e ) ); // Q0 } } @@ -1105,7 +1105,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( { noise_shape_buffer_e[i] = hFdCngCom->cngNoiseLevelExp; move16(); - noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); + noise_shape_buffer[i] = Sqrt32( *( cngNoiseLevelPtr ), &noise_shape_buffer_e[i] ); // Q31-noise_shape_buffer_e[i] move32(); noise_shape_buffer_common_exp = s_max( noise_shape_buffer_e[i], noise_shape_buffer_common_exp ); } @@ -1115,33 +1115,33 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( IF( NE_16( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ) { - noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); + noise_shape_buffer[i] = L_shr( noise_shape_buffer[i], sub( noise_shape_buffer_common_exp, noise_shape_buffer_e[i] ) ); // Q31- (noise_shape_buffer_common_exp-noise_shape_buffer_e[i]) move32(); } } - last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); + last_scf = Sqrt32( *( cngNoiseLevelPtr - inc ), &last_scf_e ); // Q31-last_scf_e IF( LT_16( noise_shape_buffer_common_exp, last_scf_e ) ) { - Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); + Scale_sig32( noise_shape_buffer, stop_idx, sub( noise_shape_buffer_common_exp, last_scf_e ) ); // Q31- (noise_shape_buffer_common_exp-last_scf_e) noise_shape_buffer_common_exp = last_scf_e; move16(); } ELSE { - last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); + last_scf = L_shl( last_scf, sub( last_scf_e, noise_shape_buffer_common_exp ) ); // Q31-(last_scf_e-noise_shape_buffer_common_exp) } FOR( ; i < max_noise_line; i++ ) { - noise_shape_buffer[i] = last_scf; + noise_shape_buffer[i] = last_scf; // Q31 - noise_shape_buffer_common_exp move32(); } /* fill the noise vector */ - hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; + hTonalMDCTConc->curr_noise_nrg = MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31; // Q31 move32(); hTonalMDCTConc->curr_noise_nrg_exp = 0; move16(); @@ -1160,17 +1160,17 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( FOR( i = 0; i < max_noise_line; i++ ) { - *rnd = own_random( rnd ); + *rnd = own_random( rnd ); // Q0 *rnd_c = own_random( rnd_c ); move16(); move16(); - concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); + concealment_noise[i] = Mpy_32_32( L_add( L_shr( L_mult( c_inv, *rnd ), 1 ), L_shr( L_mult( c, *rnd_c ), 1 ) ), noise_shape_buffer[i] ); // Q31 - *concealment_noise_exp move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1181,8 +1181,8 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( /* 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++ ) { - *rnd = own_random( rnd ); - *rnd_c = own_random( rnd_c ); + *rnd = own_random( rnd ); // Q0 + *rnd_c = own_random( rnd_c ); // Q0 move16(); move16(); @@ -1190,7 +1190,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move32(); IF( concealment_noise[i] != 0 ) { - hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); + hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, Mpy_32_32( concealment_noise[i], concealment_noise[i] ), shl( *concealment_noise_exp, 1 ), &temp_e ); // Q31-temp_e } hTonalMDCTConc->curr_noise_nrg_exp = temp_e; move16(); @@ -1521,11 +1521,11 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( sns_interpolate_scalefactors_fx( scfs_int, scf, ENC ); sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC ); - scfs_for_shaping = &scfs_int[0]; + scfs_for_shaping = &scfs_int[0]; // Q16 } ELSE /* whitening_mode == ON_FIRST_GOOD_FRAME */ { - scfs_for_shaping = &scfs_bg[0]; + scfs_for_shaping = &scfs_bg[0]; // Q16 } IF( sum32_sat( scfs_for_shaping, FDNS_NPTS ) > 0 ) @@ -1537,7 +1537,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( { FOR( i = 0; i < sub( stop_idx, start_idx ); i++ ) { - hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); + hFdCngCom->cngNoiseLevel[i] = L_shr( whitenend_noise_shape[start_idx + i], sub( add( q_wns, hFdCngCom->cngNoiseLevelExp ), 30 ) ); //(q_wns + 1) move32(); } } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index fa49a85f3..b46d0abd5 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -118,8 +118,8 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, shr( imult1616( 3, ( s_min( L_FRAME_MAX, nSamples ) ) ), 1 ) )]; - hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * ( min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - 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] ) ); @@ -231,8 +231,8 @@ 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->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, s_min( L_FRAME_MAX, nSamples ) )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - ( 3 * min( L_FRAME_MAX, nSamples ) / 2 )]; + hTonalMDCTConc->lastPcmOut = &hTonalMDCTConc->timeDataBuffer[( 3 * L_FRAME_MAX ) / 2 - 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] ) ); @@ -240,11 +240,11 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( } void TonalMDCTConceal_SaveFreqSignal( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp const Word16 mdctSpectrum_exp, - Word16 nNewSamples, - Word16 nNewSamplesCore, - const Word16 *scaleFactors, + Word16 nNewSamples, // Q0 + Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q31-scaleFactors_exp const Word16 *scaleFactors_exp, const Word16 gain_tcx_exp #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -375,7 +375,7 @@ void TonalMDCTConceal_SaveFreqSignal( 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 ) ); // Q31-(mdctSpectrum_exp-s) move16(); } hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); @@ -390,14 +390,14 @@ void TonalMDCTConceal_SaveFreqSignal( void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 *mdctSpectrum, - const Word16 mdctSpectrum_exp, - const Word16 nNewSamples, - const Word16 nNewSamplesCore, - const Word16 *scaleFactors, - const Word16 *scaleFactors_exp, - const Word16 gain_tcx_exp, - const Word16 infoIGFStartLine ) + const Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp + const Word16 mdctSpectrum_exp, // Q0 + const Word16 nNewSamples, // Q0 + const Word16 nNewSamplesCore, // Q0 + const Word16 *scaleFactors, // Q15 - *scaleFactors_exp + const Word16 *scaleFactors_exp, // Q0 + const Word16 gain_tcx_exp, // Q0 + const Word16 infoIGFStartLine ) // Q0 { Word16 *temp; Word16 nOldSamples, temp_exp, s, i, max_exp; @@ -496,7 +496,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 ) ); // Q31-last_block_nrg_exp move32(); } hTonalMDCTConc->last_block_nrg_exp = sub( 31, sub( shl( sub( 15, mdctSpectrum_exp ), 1 ), 16 ) ); @@ -526,7 +526,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( tmp = 1; move16(); } - hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); + hTonalMDCTConc->lastBlockData.spectralData[i] = extract_h( L_shl( mdctSpectrum[i], s ) ); // 31 - mdctSpectrum_exp +s -16 = 15-(mdctSpectrum_exp -s) move16(); test(); @@ -549,9 +549,9 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 nNewSamples, - Word32 pitchLag, - Word16 badBlock, + Word16 nNewSamples, // Q0 + Word32 pitchLag, // Qx + Word16 badBlock, // Q0 Word8 tonalConcealmentActive ) { Word8 newBlockIsValid; @@ -596,8 +596,8 @@ TONALMDCTCONCEAL_ERROR TonalMDCTConceal_UpdateState( TonalMDCTConcealPtr hTonalM } 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 */ + Word32 secondLastMDCT[], /* i: MDST spectrum data Qx +31 -diff_exp */ + Word32 secondLastMDST[], /* i: MDCT spectrum data Qx */ Word16 diff_exp ) /* i: exp_MDST - exp_MDCT */ { Word16 i; @@ -614,7 +614,7 @@ static void FindPhases( /* o: currenc /* 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 ); // Q13 move16(); } } @@ -630,7 +630,7 @@ static void FindPhases( /* o: currenc static void FindPhaseDifferences( /* o: Phase difference [-pi;pi] 2Q13*/ TonalMDCTConcealPtr const hTonalMDCTConc, /* i: Pointer to internal structure */ - Word32 powerSpectrum[] ) /* i: Power spectrum data */ + Word32 powerSpectrum[] ) /* i: Power spectrum data Qx */ { Word16 i, k; Word16 *phaseDiff; @@ -684,7 +684,7 @@ static void FindPhaseDifferences( /* o 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 ); + Q = BASOP_Util_fPow( L_deposit_h( divi ), sf, G, 0, &sf ); // Q31-sf L_tmp = Mpy_32_16_1( Q, s ); sfn = sub( sf, 2 ); @@ -743,11 +743,11 @@ static void FindPhaseDifferences( /* o #ifdef IVAS_FLOAT_FIXED static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31 - secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31 - secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) { @@ -823,14 +823,14 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; move16(); - powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ + 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; move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); move32(); - powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31-(powerSpectrum_exp-tmp_exp) move32(); } @@ -838,7 +838,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( { invScaleFactors_exp[i] = hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]; move16(); - invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); + invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); // Q31-invScaleFactors_exp[i] move16(); } @@ -868,19 +868,19 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( } IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) { - Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); + Scale_sig32( powerSpectrum, length, sub( old_power_spectrum_q, power_spectrum_q ) ); // Q(old_power_spectrum_q-power_spectrum_q) } ELSE { - Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); + Scale_sig32( powerSpectrum + length, sub( nSamples, length ), sub( power_spectrum_q, old_power_spectrum_q ) ); // Q(power_spectrum_q - old_power_spectrum_q) powerSpectrum_exp = sub( 31, power_spectrum_q ); } - Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ + Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ // Q(31 - powerSpectrum_exp )-3 powerSpectrum_exp = add( powerSpectrum_exp, 3 ); FOR( i = hTonalMDCTConc->nSamplesCore; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); // Q(31 - powerSpectrum_exp) #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[nBands - 1] ), invScaleFactors_exp[nBands - 1] ); #endif @@ -895,7 +895,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( 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 ); // Q31 - powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -910,11 +910,11 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( static void CalcPowerSpecAndDetectTonalComponents( TonalMDCTConcealPtr const hTonalMDCTConc, - Word32 secondLastMDST[], + Word32 secondLastMDST[], // Q31-secondLastMDST_exp Word16 secondLastMDST_exp, - Word32 secondLastMDCT[], + Word32 secondLastMDCT[], // Q31-secondLastMDCT_exp Word16 secondLastMDCT_exp, - Word32 const pitchLag, + Word32 const pitchLag, /*15Q16*/ Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -995,8 +995,8 @@ static void CalcPowerSpecAndDetectTonalComponents( { tmp_exp = old_exp; move16(); - 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 ); // Q31- tmp_exp + powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); // Q31- tmp_exp move32(); } @@ -1005,7 +1005,7 @@ static void CalcPowerSpecAndDetectTonalComponents( 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] ); // Q31 - invScaleFactors_exp[i] } @@ -1027,7 +1027,7 @@ static void CalcPowerSpecAndDetectTonalComponents( 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] ); + powerSpectrum[i] = L_shl_sat( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); // powerSpectrum_exp+ 2*invScaleFactors_exp -15 #else powerSpectrum[i] = L_shl( Mpy_32_16_1( powerSpectrum[i], invScaleFactors[FDNS_NPTS - 1] ), invScaleFactors_exp[FDNS_NPTS - 1] ); #endif @@ -1038,7 +1038,7 @@ static void CalcPowerSpecAndDetectTonalComponents( 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 ); // Q31-powerSpectrum_exp #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif @@ -1055,8 +1055,8 @@ static void CalcPowerSpecAndDetectTonalComponents( static void CalcMDXT( const TonalMDCTConcealPtr hTonalMDCTConc, const Word16 type, - const Word16 *timeSignal, - Word32 *mdxtOutput, + const Word16 *timeSignal, // Qx + Word32 *mdxtOutput, // Q31-mdxtOutput_e Word16 *mdxtOutput_e ) { Word16 windowedTimeSignal[L_FRAME_PLUS + 2 * L_MDCT_OVLP_MAX]; @@ -1082,7 +1082,7 @@ static void CalcMDXT( void TonalMDCTConceal_Detect( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, Word16 element_mode #ifdef IVAS_CODE_MDCT_GSHAPE @@ -1184,8 +1184,8 @@ void TonalMDCTConceal_Detect( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ 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 ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q2*(31-secondLastMDST_exp+powerSpectrum_exp) -31 move32(); } @@ -1225,7 +1225,7 @@ void TonalMDCTConceal_Detect( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Detect_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, - const Word32 pitchLag, + const Word32 pitchLag, /*15Q16*/ Word16 *numIndices, const PsychoacousticParameters *psychParamsCurrent, Word16 element_mode ) @@ -1328,8 +1328,8 @@ void TonalMDCTConceal_Detect_ivas_fx( /* multFLOAT(powerSpectrum, powerSpectrum, powerSpectrum, nSamples); */ 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 ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) + powerSpectrum[i] = Mpy_32_32( t, t ); // Q(31-secondLastMDST_exp+powerSpectrum_exp) move32(); } } @@ -1345,8 +1345,8 @@ void TonalMDCTConceal_Detect_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - Word32 const t = L_shl( powerSpectrum[i], -3 ); - powerSpectrum[i] = Mpy_32_32( t, t ); + Word32 const t = L_shl( powerSpectrum[i], -3 ); // Q31 - powerSpectrum_exp -3 + powerSpectrum[i] = Mpy_32_32( t, t ); // 2*(Q31 - powerSpectrum_exp -3)-31 move32(); } } @@ -1387,17 +1387,17 @@ void TonalMDCTConceal_Detect_ivas_fx( void TonalMDCTConceal_InsertNoise_ivas_fx( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, + Word32 *mdctSpectrum, // Q31-mdctSpectrum_exp Word16 *mdctSpectrum_exp, const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - const Word16 crossfadeGain_const, - const Word32 concealment_noise[L_FRAME48k], + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + const Word16 crossfadeGain_const, // Q15 + const Word32 concealment_noise[L_FRAME48k], // Q31-concealment_noise_e const Word16 concealment_noise_e, - const Word32 cngLevelBackgroundTrace_bfi, + const Word32 cngLevelBackgroundTrace_bfi, // Q31-cngLevelBackgroundTrace_bfi_e const Word16 cngLevelBackgroundTrace_bfi_e, - const Word16 crossOverFreq ) + const Word16 crossOverFreq ) // Q0 { Word16 i, l, ld, fac; Word16 rnd; @@ -1438,11 +1438,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move32(); 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 ) ); - BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ + inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); // Q31-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 ) ); // Q15 - 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 ); // Q15 #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -1474,19 +1474,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[i] > 0 ) { - mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); // Q31-spectralData_exp move32(); } ELSE { - mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); + mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); // Q31-spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // Q31-spectralData_exp move32(); } @@ -1508,14 +1508,14 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( num = L_shl( cngLevelBackgroundTrace_bfi, ld ); exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q31- curr_noise_nrg_exp + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } #ifdef BASOP_NOGLOB @@ -1533,13 +1533,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15-exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain + exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = sub( hTonalMDCTConc->lastBlockData.spectralData_exp, exp ); move16(); @@ -1568,25 +1568,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[i]; + Word32 y = concealment_noise[i]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[i], mdctSpectrum[i] ) ); // Q31- faded_signal_nrg_exp move32(); } FOR( i = crossOverFreq; i < hTonalMDCTConc->lastBlockData.nSamples; i++ ) @@ -1621,11 +1621,11 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l];//concealment_noise_e move32(); 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 ); + y = L_negate( Mpy_32_32( y, y ) );//Q31-2* concealment_noise_e + 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 ); // Q31- hTonalMDCTConc->curr_noise_nrg_exp move32(); } } @@ -1639,12 +1639,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_32( concealment_noise[l], 0 ) ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1654,12 +1654,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } @@ -1669,19 +1669,19 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( concealment_noise[l] > 0 ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } ELSE { - mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { - mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); // hTonalMDCTConc->lastBlockData.spectralData_exp move32(); } @@ -1700,17 +1700,17 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( move16(); ld = norm_l( cngLevelBackgroundTrace_bfi ); - num = L_shl( cngLevelBackgroundTrace_bfi, ld ); + num = L_shl( cngLevelBackgroundTrace_bfi, ld ); // Q15 - exp_num + ld exp_num = sub( exp_num, ld ); ld = norm_l( hTonalMDCTConc->curr_noise_nrg ); - den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); + den = L_shl( hTonalMDCTConc->curr_noise_nrg, ld ); // Q15 - exp_den + ld exp_den = sub( exp_den, ld ); exp = sub( exp_num, exp_den ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1725,13 +1725,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { IF( GT_16( exp, 0 ) ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15- exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15 - e_crossfadeGain e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1760,25 +1760,25 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31 - 2*mdctSpectrum_exp move32(); } @@ -1786,41 +1786,41 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp } } FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 y = concealment_noise[l]; + Word32 y = concealment_noise[l]; // Q31-concealment_noise_e move32(); - L_tmp = Mpy_32_16_1( y, g ); - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-concealment_noise_e- spectralData_exp + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); - hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); + hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); // Q31- 2*mdctSpectrum_exp move32(); } @@ -1845,26 +1845,26 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 num_exp, den_exp; Word32 num, den; - num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); + num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); // Q31-num_exp - den = hTonalMDCTConc->faded_signal_nrg; + den = hTonalMDCTConc->faded_signal_nrg; // Q31 - hTonalMDCTConc->faded_signal_nrg_exp move32(); den_exp = hTonalMDCTConc->faded_signal_nrg_exp; move16(); ld = norm_l( num ); - num = L_shl( num, ld ); + num = L_shl( num, ld ); // Q31-num_exp + ld num_exp = sub( num_exp, ld ); ld = norm_l( den ); - den = L_shl( den, ld ); + den = L_shl( den, ld ); // Q31-den_exp + ld den_exp = sub( den_exp, ld ); exp = sub( num_exp, den_exp ); IF( GT_32( num, den ) ) { - num = L_shr( num, 1 ); + num = L_shr( num, 1 ); // Q31- exp -1 exp = add( exp, 1 ); } tmp = div_l( num, round_fx( den ) ); @@ -1872,7 +1872,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { - mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); + mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); // Q31-(*mdctSpectrum_exp+exp) move32(); } *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); @@ -1914,20 +1914,20 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31- exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31-exp -1 exp = add( exp, 1 ); } - tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); + tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); // Q15 tmp = Sqrt16( tmp, &exp ); g = mult_r( g, tmp ); // exponent of g = exp @@ -1937,13 +1937,13 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } ELSE { - crossfadeGain = shl( crossfadeGain, exp ); + crossfadeGain = shl( crossfadeGain, exp ); // Q15-e_crossfadeGain+ exp e_crossfadeGain = sub( e_crossfadeGain, exp ); *mdctSpectrum_exp = add( e_crossfadeGain, hTonalMDCTConc->lastBlockData.spectralData_exp ); move16(); @@ -1964,29 +1964,29 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( } FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( GT_32( y, 0 ) ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + 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 ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2002,12 +2002,12 @@ ELSE fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); // 15Q16 + 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 -> Q15 @@ -2036,12 +2036,12 @@ ELSE } FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 - hTonalMDCTConc->lastBlockData.spectralData_exp * 2 - ld) x = round_fx( y ); // Q15 @@ -2067,20 +2067,20 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 ) ); - 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 ) ); // 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( EQ_32( nrgNoiseInLastFrame, 0 ) ) @@ -2095,17 +2095,17 @@ ELSE exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last+ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - Qexp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, extract_h( nrgWhiteNoise ) ); @@ -2117,7 +2117,7 @@ ELSE exp = sub( ld, exp ); IF( exp > 0 ) { - g = shr( g, exp ); + g = shr( g, exp ); // Q15 - exp *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; move16(); } @@ -2144,22 +2144,22 @@ ELSE FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2167,22 +2167,22 @@ ELSE { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); - IF( GT_32( y, 0 ) ) + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + IF( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2202,29 +2202,29 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); IF( GT_16( g, 0 ) ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp IF( GT_32( y, 0 ) ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + 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 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp move32(); } } @@ -2241,12 +2241,12 @@ return; void TonalMDCTConceal_InsertNoise( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*OUT*/ + Word32 *mdctSpectrum, // Q31- *mdctSpectrum_exp /*OUT*/ Word16 *mdctSpectrum_exp, /*OUT*/ const Word16 tonalConcealmentActive, - Word16 *pSeed, /*IN/OUT*/ - const Word16 tiltCompFactor, - Word16 crossfadeGain, + Word16 *pSeed, /*IN/OUT*/ + const Word16 tiltCompFactor, // Q15 + Word16 crossfadeGain, // Q15 #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT const Word16concealment_noise[L_FRAME48k], const float cngLevelBackgroundTrace_bfi, @@ -2488,7 +2488,7 @@ void TonalMDCTConceal_InsertNoise( 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 ); // Q15- 2*exp #else tiltFactor = shl( tiltFactor, exp ); #endif @@ -2510,20 +2510,20 @@ void TonalMDCTConceal_InsertNoise( FOR( i = 0; i < crossOverFreq; i++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 ) ); - 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 ) ); // 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) mdctSpectrum[i] = y; /* 15Q16 */ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2540,17 +2540,17 @@ void TonalMDCTConceal_InsertNoise( IF( nrgWhiteNoise > 0 ) { ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31-exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31-exp_noise + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31- exp - 1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2591,27 +2591,27 @@ void TonalMDCTConceal_InsertNoise( { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; move16(); - Word32 const y = mdctSpectrum[i]; + Word32 const y = mdctSpectrum[i]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[i] = L_shl( L_tmp2, exp ); + mdctSpectrum[i] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + 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 ); + mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2630,20 +2630,20 @@ void TonalMDCTConceal_InsertNoise( fac = shr( -32768, ld ); FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 ) ); - 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 ) ); // 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) @@ -2661,27 +2661,27 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 ) ); - 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 ) ); // 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } } tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( 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 ); // Q15 - 2*exp #else tmp = shl( tmp, exp ); #endif @@ -2690,20 +2690,20 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); Word32 y; - rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); - y = L_mult( tilt, rnd ); + 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 ) ); - 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 ) ); // 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) mdctSpectrum[l] = y; /* 15Q16 L_deposit_l(y);*/ move32(); - tilt = mult_r( tilt, tiltFactor ); + tilt = mult_r( tilt, tiltFactor ); // Q15 } IF( nrgNoiseInLastFrame == 0 ) @@ -2718,17 +2718,17 @@ void TonalMDCTConceal_InsertNoise( exp_noise = add( ld, shl( 15, 1 ) ); ld = norm_l( nrgNoiseInLastFrame ); - nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); + nrgNoiseInLastFrame = L_shl( nrgNoiseInLastFrame, ld ); // Q31 - exp_last + ld exp_last = sub( exp_last, ld ); ld = norm_l( nrgWhiteNoise ); - nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); + nrgWhiteNoise = L_shl( nrgWhiteNoise, ld ); // Q31 - exp_last + ld exp_noise = sub( exp_noise, ld ); exp = sub( exp_last, exp_noise ); IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { - nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); + nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); // Q31 - exp -1 exp = add( exp, 1 ); } tmp = div_l( nrgNoiseInLastFrame, round_fx( nrgWhiteNoise ) ); @@ -2766,22 +2766,22 @@ void TonalMDCTConceal_InsertNoise( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } @@ -2789,22 +2789,22 @@ void TonalMDCTConceal_InsertNoise( { FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + exp move32(); } } @@ -2824,29 +2824,29 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { - Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; // Q15 - spectralData_exp move16(); - Word32 const y = mdctSpectrum[l]; + Word32 const y = mdctSpectrum[l]; // Q31-mdctSpectrum_exp move32(); if ( g > 0 ) { - L_tmp = Mpy_32_16_1( y, g ); + L_tmp = Mpy_32_16_1( y, g ); // Q31-mdctSpectrum_exp- spectralData_exp } - L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); + L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp if ( y > 0 ) { - L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); + L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp } - mdctSpectrum[l] = L_shl( L_tmp2, exp ); + mdctSpectrum[l] = L_shl( L_tmp2, exp ); // Q15 - e_crossfadeGain + Q15 - spectralData_exp + 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 ); + mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), exp ); // Q15 - spectralData_exp + exp move32(); } } @@ -2860,7 +2860,7 @@ void TonalMDCTConceal_InsertNoise( void TonalMDCTConceal_Apply( const TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 *mdctSpectrum_exp /*IN */ #ifdef IVAS_CODE_MDCT_GSHAPE , @@ -2964,7 +2964,7 @@ void TonalMDCTConceal_Apply( #ifdef IVAS_FLOAT_FIXED void TonalMDCTConceal_Apply_ivas_fx( TonalMDCTConcealPtr hTonalMDCTConc, /*IN */ - Word32 *mdctSpectrum, /*IN/OUT*/ + Word32 *mdctSpectrum, // Q31-*mdctSpectrum_exp /*IN/OUT*/ Word16 mdctSpectrum_exp[L_FRAME_MAX], /*IN */ const PsychoacousticParameters *psychParamsCurrent ) @@ -2990,7 +2990,7 @@ void TonalMDCTConceal_Apply_ivas_fx( /* Creating 32-bit scaleFactors with common exponent. */ 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] ) ); // Q31- scaleFactors_max_e+scaleFactors_exp[i] move32(); } @@ -3004,7 +3004,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( i = 0; i < nSamples; i++ ) { - powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); + powerSpectrum[i] = L_deposit_h( tmp_secondLastPowerSpectrum[i] ); // Q31 - secondLastPowerSpectrum_exp move16(); } powerSpectrum_exp = tmp_secondLastPowerSpectrum_exp; @@ -3030,7 +3030,7 @@ void TonalMDCTConceal_Apply_ivas_fx( 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 ); // q_ps -1 move32(); } @@ -3038,7 +3038,7 @@ void TonalMDCTConceal_Apply_ivas_fx( 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 ); // q_sf - 1 move32(); } @@ -3057,7 +3057,7 @@ void TonalMDCTConceal_Apply_ivas_fx( 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] ); // Q31 -(exp_right + scaleFactors_exp[]) move32(); } exp_right = add( exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1] ); @@ -3071,12 +3071,12 @@ void TonalMDCTConceal_Apply_ivas_fx( 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 ) ); // Q31-max_e move32(); } 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 ) ); // Q31-max_e move32(); } } @@ -3146,7 +3146,7 @@ void TonalMDCTConceal_Apply_ivas_fx( void TonalMDCTConceal_SaveTimeSignal( TonalMDCTConcealPtr hTonalMDCTConc, - Word16 *timeSignal, + Word16 *timeSignal, // Qx Word16 nNewSamples ) @@ -3164,13 +3164,13 @@ void TonalMDCTConceal_SaveTimeSignal( return; } static void CalcPowerSpec( - const Word32 *mdctSpec, /* i: MDCT spectrum Q31,mdctSpec_exp */ + 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 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 */ + Word32 *powerSpec, /* o: power spectrum Q31- powerSpec_exp */ Word16 *powerSpec_exp ) /* o: exponent of power spectrum */ { Word16 k, s1, s2, tmp; diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 73342e64c..ab6a76cac 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -37,19 +37,19 @@ 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 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *Jopt_flag, /* i : joint optimization flag Q0*/ + Word16 *exc, /* o : excitation signal Q0 */ + Word16 *T0, /* o : close loop integer pitch Q0 */ + Word16 *T0_frac, /* o : close loop fractional part of the pitch Q0*/ + Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 Q0 */ + Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 Q0 */ + Word16 **pt_pitch, /* o : floating pitch values Q6 */ + Word16 *position, /* i/o: first glottal impulse position in frame Q0*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -110,8 +110,8 @@ void transition_dec_fx( /* 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 ); - move16(); /* save subframe pitch values Q6 */ + **pt_pitch = shl( add( shl( *T0, 2 ), *T0_frac ), 4 ); // Q6 + move16(); /* save subframe pitch values Q6 */ *Jopt_flag = 1; move16(); @@ -620,14 +620,14 @@ void transition_dec_fx( static void tc_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame, /* i : length of the frame */ - Word16 exc[], /* o : glottal codebook contribution */ - Word16 *T0, /* o : close-loop pitch period */ - Word16 *T0_frac, /* o : close-loop pitch period - fractional part */ - const Word16 i_subfr, /* i : subframe index */ - const Word16 tc_subfr, /* i : TC subframe index */ - Word16 *position, /* o : first glottal impulse position in frame */ - Word16 bwe_exc[], /* o : excitation for SWB TBE */ + const Word16 L_frame, /* i : length of the frame Q0*/ + Word16 exc[], /* o : glottal codebook contribution Q0*/ + Word16 *T0, /* o : close-loop pitch period Q0 */ + Word16 *T0_frac, /* o : close-loop pitch period - fractional part Q0 */ + const Word16 i_subfr, /* i : subframe index Q0*/ + const Word16 tc_subfr, /* i : TC subframe index Q0 */ + Word16 *position, /* o : first glottal impulse position in frame Q0*/ + Word16 bwe_exc[], /* o : excitation for SWB TBE Q_exc */ Word16 *Q_exc /*i/o : scaling of excitation */ ) { @@ -829,9 +829,9 @@ return; * TC subframe classification decoding *-------------------------------------------------------------------*/ -Word16 tc_classif_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 L_frame /* i : length of the frame */ +Word16 tc_classif_fx( /*o: Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 L_frame /* i : length of the frame Q0 */ ) { Word16 tc_subfr, indice; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 4c8df0899..d21bde643 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -17,14 +17,14 @@ *-------------------------------------------------------------------*/ 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 : fixed point 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 *old_exc_fx, /* i : buffer of excitation Q_exc */ + const Word16 *pitch_buf_fx, /* i : fixed point pitch values for each subframe Q6*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + const Word16 *Aq, /* i : A(z) quantized for all subframes Q12 */ + const Word16 *lsf_new_fx, /* i : current frame LSF vector Qlog2(2.56)*/ + const Word16 *lsp_new_fx, /* i : current frame LSP vector Q15*/ + const Word16 voice_factors[], /* i : voicing factors Q15*/ + const Word16 *old_bwe_exc_fx, /* i : buffer of excitation Q_syn*/ const Word16 *gain_buf /* i : fixed point pitch gain for each subframe Q14*/ ) { @@ -85,7 +85,7 @@ void updt_dec_fx( /* 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]; // Q15 move16(); } @@ -131,32 +131,32 @@ void updt_dec_fx( Copy32( &st_fx->old_pitch_buf_fx[len], st_fx->old_pitch_buf_fx, len ); 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 ); /* 15Q16 */ move32(); } Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[add( 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]; + st_fx->mem_pitch_gain[2] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[2]; + st_fx->mem_pitch_gain[3] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[1]; + st_fx->mem_pitch_gain[4] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[0]; + st_fx->mem_pitch_gain[5] = gain_buf[0]; // Q14 move16(); } ELSE { - st_fx->mem_pitch_gain[2] = gain_buf[4]; + st_fx->mem_pitch_gain[2] = gain_buf[4]; // Q14 move16(); - st_fx->mem_pitch_gain[3] = gain_buf[3]; + st_fx->mem_pitch_gain[3] = gain_buf[3]; // Q14 move16(); - st_fx->mem_pitch_gain[4] = gain_buf[2]; + st_fx->mem_pitch_gain[4] = gain_buf[2]; // Q14 move16(); - st_fx->mem_pitch_gain[5] = gain_buf[1]; + st_fx->mem_pitch_gain[5] = gain_buf[1]; // Q14 move16(); - st_fx->mem_pitch_gain[6] = gain_buf[0]; + st_fx->mem_pitch_gain[6] = gain_buf[0]; // Q14 move16(); } @@ -268,7 +268,7 @@ void updt_IO_switch_dec_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_weight_fx = 6554; + hBWE_FD->prev_weight_fx = 6554; /*0.2 in Q15*/ move16(); } @@ -294,7 +294,7 @@ void updt_IO_switch_dec_fx( /* reset the unvoiced/audio signal improvement memories */ if ( st_fx->hGSCDec != NULL ) { - st_fx->hGSCDec->seed_tcx = 15687; + st_fx->hGSCDec->seed_tcx = 15687; // Q0 move16(); } st_fx->hAmrwb_IO->UV_cnt_fx = 30; @@ -396,22 +396,22 @@ void updt_IO_switch_dec_fx( void updt_bw_switching_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *synth, /* i : fixed point synthesis signal */ + const Word16 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( 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 ) ); // Q27 - 16 = Q11 #else st_fx->tilt_swb_fx = round_fx( L_shl( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -453,7 +453,7 @@ 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 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -771,7 +771,7 @@ 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 : fixed point synthesis signal */ + const Word32 *synth, /* i : fixed point synthesis signal Qpost */ const Word16 Qpost ) { test(); @@ -784,9 +784,9 @@ static void ivas_updt_bw_switching_fx( #endif } - st_fx->prev_enerLH_fx = st_fx->enerLH_fx; + st_fx->prev_enerLH_fx = st_fx->enerLH_fx; // enerLH_fx_Q move32(); - st_fx->prev_enerLL_fx = st_fx->enerLL_fx; + st_fx->prev_enerLL_fx = st_fx->enerLL_fx; // enerLL_fx_Q move32(); st_fx->last_bwidth = st_fx->bwidth; move32(); @@ -818,13 +818,13 @@ 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 ) // Qx { Word64 sum = 0; Word16 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] ) ); // 2*Qx -1 } return W_round64_L( sum ); } @@ -833,7 +833,7 @@ 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 Q(Qpostd) */ + const Word32 *synth, /* i : decoded synthesis Qpostd */ const Word16 Qpostd /* i : Synthesis Q value */ ) @@ -996,22 +996,22 @@ void ivas_updt_dec_common_fx( Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); Word16 output_frame = NS2SA_FX2( st_fx->output_Fs, FRAME_SIZE_NS ); move16(); - Word32 sum_val = sum_32_32_fx( synth, output_frame ); + Word32 sum_val = sum_32_32_fx( synth, output_frame ); // 2*Q_syn -1 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; + L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); // Q15 + Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); // Q15 + st_fx->log_energy_old_fx = log_energy; // Q15 move32(); - 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 ) ); // Q15 IF( EQ_16( 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( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), 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( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); // Q15 + st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); // Q15 } 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 ) ) ); + L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); // Q15 } #endif @@ -1209,9 +1209,10 @@ 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 ) + Word16 *timeDomainBuffer, /*QtimeDomainBuffer*/ + Word16 *A, /*Q12*/ + Word16 *bpf_noise_buf /*Qbpf_noise_buf*/ +) { Word16 i; Word16 lsp[M], lsf[M]; diff --git a/lib_dec/vlpc_1st_dec_fx.c b/lib_dec/vlpc_1st_dec_fx.c index ad2c3fc2c..cd79792c2 100644 --- a/lib_dec/vlpc_1st_dec_fx.c +++ b/lib_dec/vlpc_1st_dec_fx.c @@ -11,17 +11,17 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_1st_dec( Word16 index, /* input: codebook index */ - Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf */ + Word16 *lsfq ) /* i/o: i:prediction o:quantized lsf 14Q1*1.28 */ { Word16 i; const Word16 *p_dico; assert( index < 256 ); - p_dico = &dico_lsf_abs_8b[index * M]; + p_dico = &dico_lsf_abs_8b[index * M]; /*14Q1*1.28*/ FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( lsfq[i], *p_dico ); + lsfq[i] = add( lsfq[i], *p_dico ); /*14Q1*1.28*/ move16(); p_dico++; } diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 6aacd0974..74b53369c 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -12,7 +12,7 @@ #ifdef IVAS_FLOAT_FIXED void vlpc_2st_dec( - Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ + Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage 14Q1*1.28*/ Word16 *indx, /* i : index[] (4 bits per words) */ Word16 mode, /* i : 0=abs, >0=rel */ Word32 sr_core /* i : internal sampling rate */ diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index 761f904ea..c9ef8b473 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -43,11 +43,11 @@ /*===================================================================*/ 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 : fixed point pitch values for each subframe */ - Word16 bfi /* i : Frame error rate */ + Word16 *out_fx, /* o : residual signal Q0*/ + const Word16 *lpc2_fx, /* i : current frame LPC Q12*/ + Word16 *exc_fx, /* i : previous frame excitation Q0*/ + Word16 *pitch, /* o : fixed point pitch values for each subframe Q6*/ + Word16 bfi /* i : Frame error rate Q0*/ ) { Word16 k, delta_lag_D = 0, temp, Ql, Qh, diff; @@ -258,7 +258,7 @@ ivas_error ppp_voiced_decoder_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 ); // Q23 #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 */ diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index b090b22e5..070447cd4 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -19,12 +19,12 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ 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 ) /*i/o: Qx */ { return s_min( a, b ); } -void set_state( Word16 *state, Word16 num, Word16 N ) +void set_state( Word16 *state, Word16 num, Word16 N ) /*i/o: Qx */ { Word16 i, tmp; @@ -38,7 +38,7 @@ void set_state( Word16 *state, Word16 num, Word16 N ) 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 /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word32 *data_reci2 = plcInfo->data_reci2_fx; @@ -99,46 +99,46 @@ 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 ) /* i: Qx*/ /* o: 2*Qx-31*/ { Word16 i; Word32 temp, zp = L_deposit_l( 0 ); 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] ); // 2*Qx + zp = L_sub( zp, L_shr( temp, 31 ) ); // 2*Qx-31 } return extract_l( zp ); } -Word16 Sqrt_x_fast( Word32 value ) +Word16 Sqrt_x_fast( Word32 value /*Qvalue*/ ) /*o : Q11-(2*norm+1)*/ { 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 ) ) ); + result = shr( sqrt_table_pitch_search[index], sub( 11, shr( add( norm, 1 ), 1 ) ) ); // Q11-(2*norm+1) return result; } -Word32 dot_w32_accuracy_x( Word16 *s1, Word16 *s2, Word16 nbits, Word16 N ) +Word32 dot_w32_accuracy_x( Word16 *s1 /*Qs1*/, Word16 *s2 /*Qs2*/, Word16 nbits, Word16 N ) { Word16 i; Word32 eng = L_deposit_l( 0 ), temp; 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] ); /*Qs1+ Qs2*/ + eng = L_add( eng, L_shr( temp, nbits ) ); /*Qs1+ Qs2-nbits*/ } return eng; } -Word16 int_div_s_x( Word16 a, Word16 b ) +Word16 int_div_s_x( Word16 a, Word16 b ) /*i/o : Q0*/ { Word16 result = 0; Word16 norm, left = 0, i; @@ -170,7 +170,7 @@ 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 ) /*i : Qx, o: Q0*/ { Word32 smax = L_deposit_l( 0 ); Word16 smax_norm, i; @@ -185,7 +185,7 @@ Word16 GetW32Norm_x( Word32 *s, Word16 N ) return smax_norm; } -Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) +Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) /*i : Qx, o: Q15*/ { Word16 h, k, result = 0; Word32 ener = L_deposit_l( 0 ), ener_harmo = L_deposit_l( 0 ); @@ -229,7 +229,7 @@ Word16 harmo_x( Word32 *X, Word16 Framesize, Word16 pitch ) return result; } -static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, +static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, /*i: Qx*/ /*o: Q0*/ Word16 curr_mode, Word16 N ) { @@ -276,7 +276,7 @@ static Word16 get_low_freq_eng_rate_x( Word32 *mdct_data, 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 ) /*i/o : Qx*/ { Word16 i; Word16 smax, norm; @@ -305,7 +305,7 @@ 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 /*Qx*/, Word16 FrameSize, Word32 *enr1 /*2*Qx-nbits*/, Word32 *enr2 /*2*Qx-nbits*/ ) { Word16 subFrameSize, shIFt; Word16 *p1, *p2; @@ -323,7 +323,7 @@ void sig_tilt_x( Word16 *s, Word16 FrameSize, Word32 *enr1, Word32 *enr2 ) 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 /*Qx*/, Word16 s /*Q0*/, Word16 e /*Q0*/, Word16 N, Word32 *maxConv /*2*Qx-nbits*/, Word16 *maxConv_bits, Word16 *pitch /*Q0*/ ) { Word16 t, cov_size, size = N; Word32 tmp_sigma = L_deposit_l( 0 ), cov_max_sigma = L_deposit_l( 0 ); @@ -399,7 +399,7 @@ void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 move16(); } -Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_bits, Word16 Framesize ) +Word16 get_voicing_x( Word16 *s_LP /*Qx*/, Word16 pitch /*Q0*/, Word32 covMax /*2*Qx-nbits*/, Word16 maxConv_bits, Word16 Framesize ) /*o : Q15*/ { Word32 eng1 = L_deposit_l( 0 ), eng2 = L_deposit_l( 0 ); Word16 voicing, norm; @@ -447,7 +447,7 @@ Word16 get_voicing_x( Word16 *s_LP, Word16 pitch, Word32 covMax, Word16 maxConv_ } } -void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameSize ) +void pitch_modify_x( Word16 *s_LP /*Qx*/, Word16 *voicing /*Q15*/, Word16 *pitch /*Q0*/, Word16 FrameSize ) { Word32 eng1, eng2, eng3; Word16 shIFt = shr( *pitch, 1 ); @@ -513,7 +513,7 @@ void pitch_modify_x( Word16 *s_LP, Word16 *voicing, Word16 *pitch, Word16 FrameS } } -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 /*Qx*/, Word16 cov_max /*Q15*/, Word16 zp, Word32 ener /*Q8*/, Word32 ener_mean /*Q8*/, Word16 pitch /*Q0*/, Word16 Framesize ) /*o: Q0*/ { Word16 flag = 0; Word16 harm; @@ -561,7 +561,7 @@ 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 /*Qx*/, Word16 shIFt, Word16 N ) /*o :Q0*/ { Word32 eng1, eng2, eng3; Word16 eng1_w, eng2_w; @@ -607,14 +607,14 @@ Word16 get_conv_relation_x( Word16 *s_LP, Word16 shIFt, Word16 N ) return tmp; } -static Word16 pitch_search_fx( Word16 *s, /* lastPcmOut */ - Word16 *outx_new, +static Word16 pitch_search_fx( Word16 *s /*Qs*/, /* lastPcmOut */ + Word16 *outx_new /*Qoutx_new*/, Word16 Framesize, - Word16 *voicing, - Word16 zp, - Word32 ener, - Word32 ener_mean, - Word32 *mdct_data, + Word16 *voicing /*Q15*/, + Word16 zp, /*Q0*/ + Word32 ener /*Q8*/, + Word32 ener_mean /*Q8*/, + Word32 *mdct_data /*Qmdct*/, Word16 curr_mode ) { Word16 pitch = 0; @@ -901,14 +901,14 @@ void concealment_init_ivas_fx( #endif // IVAS_FLOAT_FIXED static Word16 own_random_fix( /* o : output random value */ - Word16 *seed /* i/o: random seed */ + Word16 *seed /* i/o: random seed Q0 */ ) { *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 /*Qinvkoef_scale*/, Word16 *invkoef_scale, void *_plcInfo ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 i; @@ -940,7 +940,7 @@ void concealment_decode_fix( Word16 curr_mode, Word32 *invkoef, Word16 *invkoef_ } -Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_length, Word16 times ) +Word16 Spl_GetScalingSquare_x( const Word16 *in_vector /*Qin_vector*/, const Word16 in_vector_length, Word16 times ) /*o : Q0*/ { Word16 nbits = sub( 15, norm_s( times ) ) /*Spl_GetSizeInBits_x(times)*/; Word16 i; @@ -973,7 +973,7 @@ Word16 Spl_GetScalingSquare_x( const Word16 *in_vector, const Word16 in_vector_l } -Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *scale_factor ) +Word32 Spl_Energy_x( const Word16 *vector /*Qvector*/, const Word16 vector_length, Word16 *scale_factor ) { Word32 en = L_deposit_l( 0 ); Word32 i; @@ -990,7 +990,7 @@ Word32 Spl_Energy_x( const Word16 *vector, const Word16 vector_length, Word16 *s return en; } -void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) +void Log10OfEnergy_x( const Word16 *s /* Qs */, Word32 *enerlogval /* Q8 */, const Word16 len ) { Word32 energy = L_deposit_l( 0 ), tmp2 = L_deposit_l( 0 ); Word16 shfts = 0; @@ -1013,7 +1013,7 @@ void Log10OfEnergy_x( const Word16 *s, Word32 *enerlogval, const Word16 len ) } } -static Word32 fnLog2( Word32 L_Input ) +static Word32 fnLog2( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; @@ -1067,7 +1067,7 @@ static Word32 fnLog2( Word32 L_Input ) return ( LwIn ); } -static Word32 fnLog10( Word32 L_Input ) +static Word32 fnLog10( Word32 L_Input /*QL_Input*/ ) /*o :Q26*/ { Word16 Scale = 9864; /* 0.30103 = log10(2) */ @@ -1088,7 +1088,7 @@ static Word32 fnLog10( Word32 L_Input ) return ( LwIn ); } -Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) +Word32 con_Log10( Word32 i_s32Val /*Qi_s32Val*/, Word16 i_s16Q /*Q0*/ ) /*o; Q26*/ { Word32 s32Out; Word32 s32Correct; /* corrected (31-q)*log10(2) */ @@ -1111,7 +1111,7 @@ Word32 con_Log10( Word32 i_s32Val, Word16 i_s16Q ) return s32Out; } -void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 FrameSize ) +void concealment_update2_x( const Word16 *outx_new /*Qoutx_new*/, void *_plcInfo, const Word16 FrameSize ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; @@ -1129,7 +1129,7 @@ void concealment_update2_x( const Word16 *outx_new, void *_plcInfo, const Word16 return; } -static Word16 array_max_indx_fx( Word16 *s, Word16 N ) +static Word16 array_max_indx_fx( Word16 *s /*Qs*/, Word16 N ) { Word16 i, indx = 0; move16(); @@ -1145,7 +1145,7 @@ static Word16 array_max_indx_fx( Word16 *s, Word16 N ) } 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 *x, /* i: array containing 16-bit data Qx*/ Word16 len_x ) /* i: length of the array to scan */ { Word16 i, i_min, i_max; @@ -1189,7 +1189,7 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], return i; } -static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word16 pitch, Word16 Framesize ) +static Word16 OverlapAdd_fx( Word16 *pitch125_data /*Qx*/, Word16 *sbuf /*Qx*/, Word16 n, Word16 pitch /*Q0*/, Word16 Framesize ) { Word16 n1, n2, s, s16MaxCoefNorm, s16MaxCoefNorm2, tmp16; Word16 i; @@ -1236,12 +1236,12 @@ static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word return pitch; } -static void add_noise( Word16 *const sbuf, - Word16 *const outx_new_n1, - Word16 const *const noise_seg, +static void add_noise( Word16 *const sbuf, /*Qsbuf*/ + Word16 *const outx_new_n1, /*Q0*/ + Word16 const *const noise_seg, /*Q0*/ Word16 const Len, - Word16 *const gain, - Word16 const *const gain_n, + Word16 *const gain, /*Q15*/ + Word16 const *const gain_n, /*Q15*/ Word8 const firstFrame ) { Word16 i; @@ -1283,18 +1283,18 @@ static void add_noise( Word16 *const sbuf, 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, +static Word16 waveform_adj_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outdata2, /*Qoutdata2*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ Word16 Framesize, Word8 T_bfi, - Word16 voicing, + Word16 voicing, /*Q15*/ Word16 curr_mode, - Word16 pitch ) + Word16 pitch /*Q0*/ ) { Word16 i, zp1, zp2, Framesizediv2, s16MaxCoefNorm; Word16 sbuf[L_FRAME_MAX]; @@ -1429,15 +1429,15 @@ static 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, +void waveform_adj2_fix( Word16 *overlapbuf, /*Qoverlapbuf*/ + Word16 *outx_new, /*Qoutx_new*/ + Word16 *data_noise, /*Qoutx_new*/ + Word16 *outx_new_n1, /*Q0*/ + Word16 *nsapp_gain, /*Q15*/ + Word16 *nsapp_gain_n, /*Q15*/ + Word16 *recovery_gain, /*Q14*/ + Word16 step_concealgain, /*Q15*/ + Word16 pitch, /*Q0*/ Word16 Framesize, Word16 delay, Word16 bfi_cnt, @@ -1612,7 +1612,7 @@ 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 /*Qoutx_new_fx*/, void *_plcInfo, Word16 nbLostCmpt, Word16 pre_bfi, Word16 *OverlapBuf_fx /*QOverlapBuf_fx*/, Word16 past_core_mode, Word16 *outdata2_fx /*Qoutdata2_fx*/, Decoder_State *st ) { T_PLCInfo *plcInfo = (T_PLCInfo *) _plcInfo; Word16 FrameSize = plcInfo->FrameSize; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 4c93bcdc1..ef7f34e82 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -54,18 +54,24 @@ * Local constants *------------------------------------------------------------------------*/ -#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ -#define DIRAC_ALPHA_MAX 0.1f -#define DIRAC_ALPHA_MAX_Q15 3276 +#define DIRAC_AVG_LENGTH_SYNTH_MS 20 /*averaging length in ms for DirAC synthesis*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX 0.1f +#endif +#define DIRAC_ALPHA_MAX_Q15 3276 /*0.1f q15*/ #define DIRAC_AVG_LENGTH_SYNTH_MS_FAST 10 -#define DIRAC_ALPHA_MAX_FAST 0.12f -#define DIRAC_ALPHA_MAX_FAST_Q15 3932 -#define DIRECTION_SMOOTHNESS_ALPHA 0.01f -#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) +#ifndef IVAS_FLOAT_FIXED +#define DIRAC_ALPHA_MAX_FAST 0.12f +#endif +#define DIRAC_ALPHA_MAX_FAST_Q15 3932 /*0.12f q15*/ +#ifndef IVAS_FLOAT_FIXED +#define DIRECTION_SMOOTHNESS_ALPHA 0.01f +#endif +#define DIRECTION_SMOOTHNESS_ALPHA_Q31 ( 21474836 ) /*0.01f q31*/ #ifdef IVAS_FLOAT_FIXED -#define POINT_3679_Q31 790059234 -#define POINT_1175_Q31 252329329 +#define POINT_3679_Q31 790059234 /*.3679 q31*/ +#define POINT_1175_Q31 252329329 /*.1175 q31*/ #endif /*------------------------------------------------------------------------- @@ -83,7 +89,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, co static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, const Word32 *onset_filter, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); -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 /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ); static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); @@ -321,7 +327,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" ) ); } - 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 ); /*q15*/ 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 ); @@ -329,7 +335,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" ) ); } - 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 ); /*q15*/ IF( ( dirac_output_synthesis_state->reference_power_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -377,10 +383,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( 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]; + tmp_fx = hDirACRend->diffuse_response_function_fx[ch_idx]; /*q15*/ move16(); - dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 -> Q31 */ + dirac_output_synthesis_state->diffuse_responses_square_fx[ch_idx] = L_mult( tmp_fx, tmp_fx ); /* Q15 + Q15 + 1 -> Q31 */ move32(); } } @@ -418,28 +424,28 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { 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 ); // Q30 - gaurd_bits /* is it a transport channel?*/ test(); 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 ); // Q30 - gaurd_bits } /* is it a decorrelated or transport channel?*/ if ( LT_16( 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 ); // Q30 - gaurd_bits } } Word16 exp_1 = 0, exp_2 = 0, tmp; move16(); move16(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_trans_fx, &exp_1 ); // Q(15 - exp_1) dirac_output_synthesis_params->diffuse_compensation_factor_fx = L_shl( L_deposit_l( tmp ), add( Q12, exp_1 ) ); // Q27 move32(); - tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_diff) + tmp = BASOP_Util_Divide3232_Scale( diff_nrg_total_fx, diff_nrg_decorr_fx, &exp_2 ); // (Q15 - exp_2) dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx = L_shl( L_deposit_l( tmp ), add( Q14, exp_2 ) ); // Q29 move32(); } @@ -1319,17 +1325,17 @@ 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 Word16 q_reference_power, /* i : Estimated power */ - const Word32 *onset, /* i : onset filter */ + const Word32 *reference_power, /* i : Estimated power Q(q_reference_power)*/ + const Word16 q_reference_power, /* i : Estimated power Q */ + const Word32 *onset, /* i : onset filter Q31*/ const Word16 *azimuth, const Word16 *elevation, - const Word32 *diffuseness, + const Word32 *diffuseness, /* Q(q_diffuseness)*/ Word16 q_diffuseness, 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 Q30*/ 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*/ @@ -1348,7 +1354,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( 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_state->onset_filter_fx = onset; + h_dirac_output_synthesis_state->onset_filter_fx = onset; /*Q31*/ /*-----------------------------------------------------------------* * processing @@ -1390,14 +1396,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( 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->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - 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 ) ); + 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 ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ 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 ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[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->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1409,23 +1415,23 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio1_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /* 30 + 31 - 31 -> 30 */ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio1_fx[md_idx], h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*Q30*/ - v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32, aux_buf, num_freq_bands ); - v_addc_fixed( aux_buf, ONE_IN_Q30, aux_buf, num_freq_bands ); + v_multc_fixed( hSpatParamRendCom->energy_ratio2_fx[md_idx], -MAX_32 /*-1 Q31*/, aux_buf, num_freq_bands ); /*30+31-31->30*/ + v_addc_fixed( aux_buf, ONE_IN_Q30 /*1 Q30*/, aux_buf, num_freq_bands ); /*30*/ Copy32( hSpatParamRendCom->energy_ratio2_fx[md_idx], &h_dirac_output_synthesis_state->direct_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ Copy32( aux_buf, &h_dirac_output_synthesis_state->diffuse_power_factor_fx[hSpatParamRendCom->num_freq_bands], - num_freq_bands ); + num_freq_bands ); /*Q30*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 30; move16(); @@ -1462,14 +1468,14 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( h_dirac_output_synthesis_state->direct_responses_square_fx ) { - Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( num_channels_dir, num_freq_bands ), sub( 31, h_dirac_output_synthesis_state->direct_responses_square_q ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_square_fx, imult1616( 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->Q31*/ h_dirac_output_synthesis_state->direct_responses_square_q = 31; move16(); } - 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 ) ); + 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 ) ); /*h_dirac_output_synthesis_state->direct_responses_q->Q31*/ 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 ) ); + Scale_sig32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[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->Q31*/ } h_dirac_output_synthesis_state->direct_responses_q = 31; move16(); @@ -1487,13 +1493,13 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( 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, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->direct_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->direct_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->direct_power_factor_q*/ v_multc_fixed( h_dirac_output_synthesis_state->diffuse_power_factor_fx, - ONE_IN_Q29, + ONE_IN_Q29 /*0.25f Q31*/, h_dirac_output_synthesis_state->diffuse_power_factor_fx, - num_freq_bands ); + num_freq_bands ); /*h_dirac_output_synthesis_state->diffuse_power_factor_q+Q31-Q31->h_dirac_output_synthesis_state->diffuse_power_factor_q*/ /*Direct gain*/ @@ -1519,9 +1525,9 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Directonal sound gain nrg compensation*/ 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 + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); - IF( reference_power[add( k, num_freq_bands )] == 0 ) + IF( reference_power[k + num_freq_bands] == 0 ) { b = 0; move16(); @@ -1530,68 +1536,68 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[add( k, num_freq_bands )], L_add( reference_power[add( k, imult1616( add( 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 ); /*Q(15-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 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 /*1.0 / 6.0 Q15*/ ) ); /*Diffuseness modellling nrg compensation*/ /*Q29*/ - 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 + (15 - b_exp) - 15) + (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(q_diff_aab) = 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_diff_c) = q_diffuseness - 2 - q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 31, b_exp ) ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( sub( add( h_dirac_output_synthesis_state->direct_responses_q, sub( 15, b_exp ) ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && 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 ); /*Q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*Q(q_diff_aab)*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } ELSE { - sqr_inp = mpy_diff_c; + sqr_inp = mpy_diff_c; /*Q(q_diff_c)*/ move32(); sqr_exp = sub( 31, q_diff_c ); } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( 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 ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { 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 ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth-> (31-sqr_exp) */ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } 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 ) ); /*( 31- sqr_exp )-> h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - 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[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx*/ move32(); } 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 ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*31-sqr_exp*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } 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 + a = h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands + k]; // Q = h_dirac_output_synthesis_state->q_direct_responses move32(); IF( reference_power[k + num_freq_bands] == 0 ) { @@ -1602,37 +1608,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } ELSE { - IF( reference_power[add( k, imult1616( add( ch_idx, 1 ), num_freq_bands ) )] == 0 ) + IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) { - b = MAXVAL_WORD16; + b = MAXVAL_WORD16; /*Q(-9)*/ move16(); b_exp = 40; move16(); } ELSE { - b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[add( k, imult1616( add( 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 ); /*q(15-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 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 ) ); /*Diffuseness modellling nrg compensation*/ /* 1.0 / 6.0 = 5461 in Q15*/ /*Q29*/ - 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_a_a_b = Mpy_32_32( a, Mpy_32_16_1( a, b ) ); // Q = (h_dirac_output_synthesis_state->q_direct_responses + (15 - b_exp) - 15) + (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 = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 31, b_exp ), 31 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); + q_diff_aab = add( h_dirac_output_synthesis_state->direct_responses_q + sub( sub( 15, b_exp ), 15 ), add( sub( h_dirac_output_synthesis_state->direct_responses_q, 31 ), sub( q_diffuseness, 31 ) ) ); q_diff_c = sub( q_diffuseness, 2 ); test(); IF( mpy_diff_c != 0 && 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 ); /*q(31-sqr_exp)*/ } ELSE { IF( mpy_diff_c == 0 ) { - sqr_inp = mpy_diff_aab; + sqr_inp = mpy_diff_aab; /*q_diff_aab*/ move32(); sqr_exp = sub( 31, q_diff_aab ); } @@ -1640,34 +1646,34 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { sqr_inp = mpy_diff_c; move32(); - sqr_exp = sub( 31, q_diff_c ); + sqr_exp = sub( 31, q_diff_c ); /*q_diff_c*/ } } - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( 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 ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { 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 ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } 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(31- sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - 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[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } 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 ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } @@ -1679,73 +1685,74 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( /*Diffuseness modellling nrg compensation*/ 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 ); + /*diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) )*/ + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx /*q29=0.5 * q30*/, ONE_IN_Q29 /*0.5 Q30*/ ) /*q30*/ ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( 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 ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { 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 ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth->Q(31- sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } 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(31-sqr_exp)->h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - 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[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } 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 ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } 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 ); + mpy_diff = Mpy_32_32( diffuseness[k], L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ) ); // Q = q_diffuseness - 1 + sqr_inp = L_add( L_shl( 1, sub( q_diffuseness, 1 ) ), mpy_diff ); // Q = q_diffuseness - 1 sqr_exp = sub( 31, sub( q_diffuseness, 1 ) ); - sqr = Sqrt32( sqr_inp, &sqr_exp ); - sqr = L_shr( sqr, 2 ); - IF( 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 ); /*Q(31-sqr_exp)*/ + sqr = L_shr( sqr, 2 ); /*Q(31-sqr_exp)*/ + IF( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] != 0 ) { 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 ) ) ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_shr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sub( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, sub( 31, sqr_exp ) ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, Q( 31- sqr_exp )*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } 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( 31- sqr_exp ), h_dirac_output_synthesis_state->q_cy_cross_dir_smooth*/ + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth; move16(); } - 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[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k]*/ move32(); } 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 ); + h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = L_add( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k], sqr ); /*Q(31-sqr_exp)*/ move32(); - Q_temp_cy_cross_dir_smooth_fx[L_add( i_mult( ch_idx, num_freq_bands ), k )] = sub( 31, sqr_exp ); + Q_temp_cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + k] = sub( 31, sqr_exp ); move16(); } } } } - Word16 temp = MAX_16; + Word16 temp = MAX_16; /*q0*/ move16(); tmp16 = imult1616( num_freq_bands, num_channels_dir ); FOR( Word16 kk = 0; kk < tmp16; kk++ ) @@ -1756,7 +1763,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( move16(); FOR( Word16 kk = 0; kk < tmp16; 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] ) ); /*Q_temp_cy_cross_dir_smooth_fx[kk]->temp*/ move32(); } free( Q_temp_cy_cross_dir_smooth_fx ); @@ -1766,7 +1773,7 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { FOR( Word16 kk = 0; kk < tmp16; 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*/ move32(); } h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = temp_q; @@ -1775,33 +1782,37 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( 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 )], + &h_dirac_output_synthesis_state->direct_responses_fx[ch_idx * num_freq_bands], aux_buf, - num_freq_bands ); + num_freq_bands ); /*temp_q*/ 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 ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx[imult1616( 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 ); /*Q(h_dirac_output_synthesis_state->q_cy_cross_dir_smooth)*/ } /*Diffuse gain*/ 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 ); - + v_multc_fixed_16( h_dirac_output_synthesis_state->diffuse_power_factor_fx, + hDirACRend->diffuse_response_function_fx[ch_idx], + aux_buf, + num_freq_bands_diff ); /* h_dirac_output_synthesis_state->diffuse_power_factor_q+15-15*/ + temp_q = h_dirac_output_synthesis_state->diffuse_power_factor_q; + IF( NE_16( temp_q, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ) + { + Scale_sig32( aux_buf, num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, temp_q ) ); /*temp_q->(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth)*/ + } v_add_fixed( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx[imult1616( 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 ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth*/ } return; @@ -1815,8 +1826,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( 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 ); + Scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ + Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, num_freq_bands, 2 ); /*q29->q31*/ h_dirac_output_synthesis_state->diffuse_power_factor_q = 31; move16(); h_dirac_output_synthesis_state->direct_power_factor_q = 31; @@ -1928,32 +1939,32 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_multc_fixed( diffuseness, // Q30 - ONE_IN_Q31, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 + v_multc_fixed( diffuseness, // Q30 + ONE_IN_Q31, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q30 - L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q30 + L_sub( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, ONE_IN_Q27 ), // Q27 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26 /*1 in Q26*/, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*Q( Q31- exp)->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ @@ -1963,38 +1974,38 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { aux_buf[l] = L_sub( ONE_IN_Q30, diffuseness[l] ); // Q30 move32(); - ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[add( num_freq_bands, l )] ); // Q31 + ratio_float[l] = L_sub( ONE_IN_Q31, h_dirac_output_synthesis_state.direct_power_factor_fx[num_freq_bands + l] ); // Q31 move32(); - ratio_float[add( l, num_freq_bands )] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 + ratio_float[l + num_freq_bands] = L_sub( ONE_IN_Q31, ratio_float[l] ); // Q31 move32(); } v_mult_fixed( aux_buf, ratio_float, ratio_float, num_freq_bands ); //(Q30, Q31) -> Q30 v_mult_fixed( aux_buf, &ratio_float[num_freq_bands], &ratio_float[num_freq_bands], num_freq_bands ); //(Q30, Q31) -> Q30 - v_mult_fixed( ratio_float, // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], //(Q30, Q31) -> Q30 + v_mult_fixed( ratio_float, // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], //(Q30, Q31) -> Q30 num_freq_bands ); - v_mult_fixed( &ratio_float[num_freq_bands], // Q30 - &h_dirac_output_synthesis_state.direct_responses_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], //(Q30, Q31) -> Q30 + v_mult_fixed( &ratio_float[num_freq_bands], // Q30 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], //(Q30, Q31) -> Q30 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q30 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, Q30 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q30 ) ); /*Q30->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[add( imult1616( ch_idx, num_freq_bands ), imult1616( num_freq_bands, num_channels_dir ) )], + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands + num_freq_bands * num_channels_dir], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2005,19 +2016,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2030,54 +2041,54 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Direct gain*/ FOR( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_decorr_fx, Q3 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q26 num_freq_bands_diff ); - v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q31 - L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), num_freq_bands_diff )], // Q26 + v_multc_fixed( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q31 + L_sub( L_shr( h_dirac_output_synthesis_params.diffuse_compensation_factor_fx, Q1 ), ONE_IN_Q26 ), // Q26 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + num_freq_bands_diff], // Q26 num_freq_bands - num_freq_bands_diff ); FOR( l = 0; l < num_freq_bands; l++ ) { exp = Q31 - Q26; - h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] = - Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[add( imult1616( ch_idx, num_freq_bands ), l )] ), + h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] = + Sqrt32( L_add( ONE_IN_Q26, h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands + l] ), &exp ); // (Q31 - exp) move32(); } // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, sub( Q31, exp ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, sub( Q31, exp ) ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, sub( Q31, exp ) ) ); /*( Q31- exp )->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } /*Directional gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_dir; ch_idx++ ) { - v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 - &h_dirac_output_synthesis_state.direct_responses_fx[imult1616( ch_idx, num_freq_bands )], // Q31 - &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], // Q31 + v_mult_fixed( h_dirac_output_synthesis_state.direct_power_factor_fx, // Q31 + &h_dirac_output_synthesis_state.direct_responses_fx[ch_idx * num_freq_bands], // Q31 + &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], // Q31 num_freq_bands ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[imult1616( ch_idx, num_freq_bands )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_cross_dir_smooth = q_com; @@ -2088,19 +2099,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /*Diffuse gain*/ FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 - hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 - &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], // Q31 + v_multc_fixed_16( h_dirac_output_synthesis_state.diffuse_power_factor_fx, // Q31 + hDirACRend->diffuse_response_function_fx[ch_idx], // Q15 + &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], // Q31 num_freq_bands_diff ); // Scale to bring in common Q-factor q_com = s_min( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, Q31 ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, Q31 ) ); - Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + sub( q_com, Q31 ) ); /*q31->q_com*/ + Scale_sig32( &h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); + sub( q_com, h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev->q_com*/ } h_dirac_output_synthesis_state.q_cy_auto_diff_smooth = q_com; @@ -2228,9 +2239,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev = h_dirac_output_synthesis_state.gains_dir_prev_fx; FOR( ch_idx = 0; ch_idx < num_channels_dir; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[imult1616( ch_idx, num_freq_bands )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_dir_prev_fx[ch_idx * num_freq_bands], num_freq_bands, - sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, h_dirac_output_synthesis_state.gains_dir_prev_q ) ); /*h_dirac_output_synthesis_state.gains_dir_prev_q->h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } h_dirac_output_synthesis_state.gains_dir_prev_q = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); @@ -2239,14 +2250,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { p_proto_diff = h_dirac_output_synthesis_state.proto_diffuse_buffer_f_fx + shl( i_mult( buf_idx, i_mult( num_freq_bands, num_channels_diff ) ), Q1 ) + - shl( i_mult( ch_idx, num_freq_bands ), Q1 ); + shl( ch_idx * num_freq_bands, Q1 ); FOR( l = 0; l < num_freq_bands; l++ ) { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto_diff++ ) ) ); // (p_gains_dir_q, p_proto_diff_q) -> (p_gains_dir_q + p_proto_diff_q - 31) move32(); } } @@ -2274,7 +2285,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir_prev++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_real[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), /* s1 */ gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); /* s2 */ @@ -2283,7 +2294,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_proto2++; // ((p_gains_dir_q, p_proto_dir_q) >> 1) -> (p_gains_dir_q + p_proto_dir_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = + output_imag[l * num_channels_dir + ch_idx] = Madd_32_32( Mpy_32_32( gs1, ( L_add( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ) ), gs2, L_sub( Mpy_32_32( 1903158016 /* 1.772454e+00f / 2 in Q31 */, ( *p_proto ) ), Mpy_32_32( 1098788992 /* 1.023327e+00f / 2 in Q31 */, ( *p_proto2 ) ) ) ); @@ -2302,9 +2313,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2320,9 +2331,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_dir++ ) ) ), g2, ( *( p_gains_dir_prev++ ) ) ); // (Q31, p_gains_dir_q) -> (p_gains_dir_q) - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = Mpy_32_32( g, ( *( p_proto++ ) ) ); // (p_gains_dir_q, p_proto_dir_q) -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2333,9 +2344,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_dir++; p_gains_dir_prev++; - output_real[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_real[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); - output_imag[add( imult1616( l, num_channels_dir ), ch_idx )] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) + output_imag[l * num_channels_dir + ch_idx] = L_shl( *( p_proto++ ), sub( h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev, 31 ) ); // p_proto_dir_q -> (p_gains_dir_q + p_proto_dir_q - 31) move32(); } } @@ -2347,9 +2358,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( p_gains_diff_prev = h_dirac_output_synthesis_state.gains_diff_prev_fx + i_mult( nchan_transport_foa, num_freq_bands_diff ); FOR( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[imult1616( ch_idx, num_freq_bands_diff )], + Scale_sig32( &h_dirac_output_synthesis_state.gains_diff_prev_fx[ch_idx * num_freq_bands_diff], num_freq_bands_diff, - sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); + sub( h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev, h_dirac_output_synthesis_state.gains_diff_prev_q ) ); /*h_dirac_output_synthesis_state.gains_diff_prev_q->h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ } h_dirac_output_synthesis_state.gains_diff_prev_q = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2369,14 +2380,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( g = Madd_32_32( Mpy_32_32( g1, ( *( p_gains_diff++ ) ) ), g2, ( *( p_gains_diff_prev++ ) ) ); // (Q31, p_gains_diff_q) -> p_gains_diff_q // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_real[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); // ((p_gains_diff_q, p_proto_diff_q) >> Q1) -> (p_gains_diff_q + p_proto_diff_q - 31) - output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )] = - Madd_32_32( output_imag[add( imult1616( l, num_channels_dir ), hDirACRend->sba_map_tc[ch_idx] )], + output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] = + Madd_32_32( output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]], g, ( *( p_proto++ ) ) ); move32(); } @@ -2396,6 +2407,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( *-----------------------------------------------------------------*/ test(); + /*q=(p_gains_dir_q + p_proto_dir_q - 31)*/ IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { Word32 *p_real, *p_imag; @@ -2405,8 +2417,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( FOR( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ ) { - p_real = RealBuffer[ch_idx][buf_idx]; - p_imag = ImagBuffer[ch_idx][buf_idx]; + p_real = RealBuffer[ch_idx][buf_idx]; /*q - Q2*/ + p_imag = ImagBuffer[ch_idx][buf_idx]; /*q - Q2*/ FOR( l = 0; l < num_freq_bands; l++ ) { @@ -2433,9 +2445,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + RealBuffer[ch_idx][buf_idx][l] = L_shr( output_real[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); - ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[add( imult1616( l, num_channels_dir ), ch_idx )], Q2 ); + ImagBuffer[ch_idx][buf_idx][l] = L_shr( output_imag[l * num_channels_dir + ch_idx], Q2 ); /* q - Q2*/ move32(); } } @@ -2449,16 +2461,16 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( /* store estimates for next synthesis block */ IF( hodirac_flag ) { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) * DIRAC_HO_NUMSECTORS ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } ELSE { - Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); + Copy32( h_dirac_output_synthesis_state.cy_cross_dir_smooth_prev_fx, h_dirac_output_synthesis_state.gains_dir_prev_fx, imult1616( num_freq_bands, num_channels_dir ) ); /*h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev*/ } *q_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state.q_cy_cross_dir_smooth_prev; move16(); - Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); + Copy32( h_dirac_output_synthesis_state.cy_auto_diff_smooth_prev_fx, h_dirac_output_synthesis_state.gains_diff_prev_fx, imult1616( num_freq_bands_diff, num_channels_diff ) ); /* h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev*/ *q_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state.q_cy_auto_diff_smooth_prev; move16(); @@ -2925,15 +2937,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( - Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals Q(q_Cldfb)*/ 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 nbslots, /* i : number of slots to process */ - Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/ - Word32 *reference_power_smooth, + Word32 *diffuseness_vector, /* i : diffuseness (needed for direction smoothing) Q(31)*/ + Word32 *reference_power_smooth, /*Q(q_reference_power_smooth)*/ Word16 *q_reference_power_smooth, - Word32 qualityBasedSmFactor, + Word32 qualityBasedSmFactor, /*Q(31)*/ const Word16 enc_param_start_band, Word16 *q_Cldfb ) { @@ -3036,11 +3048,11 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( diff_start_band != 0 ) { q_com = s_min( *q_reference_power_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); - scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); - scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); + scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ + scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); /**q_reference_power_smooth->q_com*/ scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_freq_bands, nchan_target_psds ), - sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); + sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ *q_reference_power_smooth = q_com; move16(); h_dirac_output_synthesis_state->reference_power_smooth_prev_q = q_com; @@ -3095,7 +3107,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( q_target_power_y1 = add( sub( Q31, exp1 ), sub( q_com, sub( Q31, exp ) ) ); 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 ) ) ); + 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 ) ) ); /*min(q_target_power_y1, q_target_power_y )*/ exp = s_min( q_target_power_y1, q_target_power_y ); } ELSE @@ -3190,8 +3202,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( exp = 0; move16(); - tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); - smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 + tmp = BASOP_Util_Divide3232_Scale( weightedDirectionSmoothness, L_add( sumWeight, EPSILON_FX ), &exp ); /*Q(15-exp)*/ + smoothedDirectionSmoothness = L_shl_sat( L_deposit_l( tmp ), add( sub( Q31, Q15 ), exp ) ); // Q31 h_dirac_output_synthesis_state->direction_smoothness_prev_fx[l] = smoothedDirectionSmoothness; // Q31 move32(); @@ -3235,20 +3247,20 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( IF( EQ_32( *( p_power_smooth_prev ), EPSILON_FX ) ) { p_power_smooth_prev++; - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, EPSILON_FX, &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } ELSE { - L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); - exp_arr[add( i_mult( k, num_freq_bands ), l )] = exp; + L_tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q31, *( p_power_smooth_prev++ ), &exp ); /*Q=31-(exp-(31-q_proto_power_smooth))*/ + exp_arr[k * num_freq_bands + l] = exp; move16(); - *( p_power_smooth++ ) = L_tmp; + *( p_power_smooth++ ) = L_tmp; /*Q=31-(exp-(31-q_proto_power_smooth))*/ move32(); } } @@ -3264,9 +3276,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - IF( GT_16( exp_arr[add( i_mult( k, num_freq_bands ), l )], min_exp ) ) + IF( GT_16( exp_arr[k * num_freq_bands + l], min_exp ) ) { - min_exp = exp_arr[add( i_mult( k, num_freq_bands ), l )]; + min_exp = exp_arr[k * num_freq_bands + l]; move16(); } } @@ -3279,7 +3291,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[add( i_mult( k, num_freq_bands ), l )] ) ); + *p_power_smooth = L_shr( *p_power_smooth, sub( min_exp, exp_arr[k * num_freq_bands + l] ) ); /*(31-(exp-(31-q_proto_power_smooth)))->(31-(min_exp-(31-q_proto_power_smooth)))*/ move32(); p_power_smooth++; q_tmp = add( sub( Q31, min_exp ), sub( Q31, h_dirac_output_synthesis_state->proto_power_smooth_q ) ); @@ -3305,12 +3317,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { q_cy_auto_dir_smooth_prev_local[k] = getScaleFactor32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands ); move16(); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, q_cy_auto_dir_smooth_prev_local[k] ); /*q_cy_auto_dir_smooth_prev_local[k]+h_dirac_output_synthesis_state -> q_cy_auto_dir_smooth_prev*/ q_cy_auto_dir_smooth_prev_local[k] = add( q_cy_auto_dir_smooth_prev_local[k], h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); move16(); q_com = s_min( q_cy_auto_dir_smooth_local[k], q_cy_auto_dir_smooth_prev_local[k] ); - scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); - scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( p_cy_auto_dir_smooth + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_local[k] ) ); /*q_cy_auto_dir_smooth_local -> q_com*/ + scale_sig32( p_cy_auto_dir_smooth_prev + imult1616( k, num_freq_bands ), num_freq_bands, sub( q_com, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local -> q_com*/ q_cy_auto_dir_smooth_local[k] = q_cy_auto_dir_smooth_prev_local[k] = q_com; move16(); move16(); @@ -3320,8 +3332,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_cross_dir_smooth = h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx; p_cy_cross_dir_smooth_prev = h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ); - scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); - scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); + scale_sig32( p_cy_cross_dir_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth -> q_com*/ + scale_sig32( p_cy_cross_dir_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = h_dirac_output_synthesis_state->q_cy_cross_dir_smooth_prev = q_com; move16(); move16(); @@ -3329,8 +3341,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx; p_cy_auto_diff_smooth_prev = h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx; q_com = s_min( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ); - scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); - scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); + scale_sig32( p_cy_auto_diff_smooth, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth -> q_com*/ + scale_sig32( p_cy_auto_diff_smooth_prev, imult1616( nchan_out_woLFE, num_freq_bands ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ) ); /*h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev -> q_com*/ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev = q_com; move16(); move16(); @@ -3352,7 +3364,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_cross_dir_smooth_prev ) ) ) ); // (Q31, q_cy_cross_dir_smooth_prev) -> q_cy_cross_dir_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_dir_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_dir_smooth_prev_local - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), q_cy_auto_dir_smooth_prev_local[k] ), @@ -3371,13 +3383,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*26 + h_dirac_output_synthesis_state->gains_dir_prev_q + 1 + 5 - 32 -> h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*h_dirac_output_synthesis_state->gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3406,9 +3418,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); /*h_dirac_output_synthesis_state->gains_diff_prev_q*/ move32(); } p_gains_diff++; @@ -3422,10 +3434,10 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( move32(); g2 = L_sub( ONE_IN_Q31, g1 ); // Q31 W_temp = W_add( W_mult_32_32( g1, ( *( p_cy_auto_dir_smooth++ ) ) ), - W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); + W_mult_32_32( g2, ( *( p_cy_auto_dir_smooth_prev ) ) ) ); /*32+q_cy_auto_dir_smooth_prev_local*/ q_tmp = W_norm( W_temp ); - L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp - *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); + L_tmp = W_extract_h( W_shl( W_temp, q_tmp ) ); // q_cy_auto_dir_smooth_prev_local + q_tmp + *( p_cy_auto_dir_smooth_prev++ ) = L_shr_r( L_tmp, q_tmp ); // q_cy_auto_dir_smooth_prev_local move32(); *( p_cy_cross_dir_smooth_prev ) = L_add( Mpy_32_32( g1, ( *( p_cy_cross_dir_smooth++ ) ) ), @@ -3448,15 +3460,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_dir ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_dir ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ) ) ) /*gains_dir_prev_q*/ { - *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); + *( p_gains_dir ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_dir_prev_q ) ), Q5 ) ); /*gains_dir_prev_q*/ move32(); } IF( *( p_cy_cross_dir_smooth_prev++ ) < 0 ) { - *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); + *( p_gains_dir ) = L_negate( *( p_gains_dir ) ); /*gains_dir_prev_q*/ move32(); } p_gains_dir++; @@ -3466,14 +3478,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Mpy_32_32( g2, ( *( p_cy_auto_diff_smooth_prev ) ) ) ); // (Q31, q_cy_auto_diff_smooth_prev) -> q_cy_auto_diff_smooth_prev move32(); - power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); + power_smooth_temp = L_shl( *p_power_smooth, norm_l( *p_power_smooth ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) L_tmp = Mpy_32_32( power_smooth_temp, ( *( p_cy_auto_diff_smooth_prev++ ) ) ); // proto_power_smooth_q + norm_l( *p_power_smooth ) ) + q_cy_auto_diff_smooth_prev - 31 exp = sub( Q31, sub( add( add( h_dirac_output_synthesis_state->proto_power_smooth_q, norm_l( *p_power_smooth ) ), h_dirac_output_synthesis_state->q_cy_auto_diff_smooth_prev ), Q31 ) ); p_power_smooth++; - *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); + *( p_gains_diff ) = Sqrt32( L_tmp, &exp ); /*31-exp*/ move32(); *( p_gains_diff ) = L_shl_sat( *( p_gains_diff ), sub( h_dirac_output_synthesis_state->gains_diff_prev_q, sub( Q31, exp ) ) ); // gains_diff_prev_q move32(); @@ -3483,9 +3495,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *( p_gains_diff ) = 0; move32(); } - ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) + ELSE IF( GT_32( *( p_gains_diff ), W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ) ) ) // gains_diff_prev_q { - *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); + *( p_gains_diff ) = W_extract_h( W_shl( W_mult_32_32( DIRAC_GAIN_LIMIT_Q26, L_shl( 1, h_dirac_output_synthesis_state->gains_diff_prev_q ) ), Q5 ) ); // gains_diff_prev_q move32(); } p_gains_diff++; @@ -3567,7 +3579,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { g = L_add( Mpy_32_32( g1, *( p_gain_1++ ) ), Mpy_32_32( g2, *( p_gain_2++ ) ) ); // (Q31, gains_diff_prev_q) -> gains_diff_prev_q Cldfb_RealBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_RealBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_RealBuffer64_fx[k][buf_idx][l] ) ) ) @@ -3576,12 +3588,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( } Cldfb_ImagBuffer64_fx[k][buf_idx][l] = W_add( Cldfb_ImagBuffer64_fx[k][buf_idx][l], - W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) >> Q1 -> gains_diff_prev_q + q_proto_direct_buffer - 32 + W_mult0_32_32( g, ( *( p_power_smooth++ ) ) ) ); // (gains_diff_prev_q, q_proto_direct_buffer) -> gains_diff_prev_q + q_proto_direct_buffer move64(); if ( LT_64( W_temp, W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ) ) ) { - W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); + W_temp = W_abs( Cldfb_ImagBuffer64_fx[k][buf_idx][l] ); // gains_diff_prev_q + q_proto_direct_buffer } } } @@ -3593,9 +3605,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); + RealBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_RealBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); - ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); + ImagBuffer[k][buf_idx][l] = W_extract_h( W_shl( Cldfb_ImagBuffer64_fx[k][buf_idx][l], q_align ) ); /*( ( ( h_dirac_output_synthesis_state->proto_direct_buffer_f_q+h_dirac_output_synthesis_state->gains_dir_prev_q )+ q_align )- 32 )*/ move32(); } } @@ -3609,8 +3621,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( *-----------------------------------------------------------------*/ /* store estimates for next synthesis block */ - Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); - Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); + Copy32( gains_dir, h_dirac_output_synthesis_state->gains_dir_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_dir_prev_q*/ + Copy32( gains_diff, h_dirac_output_synthesis_state->gains_diff_prev_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); /*gains_diff_prev_q*/ /* reset values */ set_zero_fx( h_dirac_output_synthesis_state->proto_power_smooth_fx, imult1616( num_freq_bands, num_protos_dir ) ); @@ -3622,7 +3634,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( minimum_fx( q_cy_auto_dir_smooth_prev_local, nchan_out_woLFE, &h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev ); FOR( k = 0; k < nchan_out_woLFE; k++ ) { - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx + ( k * num_freq_bands ), num_freq_bands, sub( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev, q_cy_auto_dir_smooth_prev_local[k] ) ); /*q_cy_auto_dir_smooth_prev_local[k] -> h_dirac_output_synthesis_state->q_cy_auto_dir_smooth_prev*/ } set_zero_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_freq_bands, nchan_out_woLFE ) ); @@ -4003,9 +4015,9 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( #ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_get_response_split_order_fx( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, + const Word16 azimuth, /*q0*/ + const Word16 elevation, /*q0*/ + Word32 *response, /*q_response*/ const Word16 shd_rot_max_order, const Word32 *p_Rmat /* Q30 */, Word16 *q_response ) @@ -4040,13 +4052,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 in Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 in Q14*/ move16(); el = index_elevation; move16(); @@ -4055,21 +4067,21 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } // dirac_gains_trg_term_int Q30 cos_1 = L_shr( dirac_gains_trg_term_int[az][0], 1 ); // Q29 cos_2 = L_shl( Mpy_32_32( cos_1, cos_1 ), 2 ); // Q29 - sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29] + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29 cos_az[0] = cos_1; // Q29 move32(); @@ -4173,13 +4185,13 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_elevation, 90 ) ) { - e = -ONE_IN_Q14; + e = -ONE_IN_Q14; /*-1 Q14*/ move16(); el = sub( 180, index_elevation ); } ELSE { - e = ONE_IN_Q14; + e = ONE_IN_Q14; /*1 Q14*/ move16(); el = index_elevation; move16(); @@ -4188,14 +4200,14 @@ static void ivas_dirac_dec_get_response_split_order_fx( IF( GT_16( index_azimuth, 180 ) ) { az = sub( 360, index_azimuth ); - f = -ONE_IN_Q30; + f = -ONE_IN_Q30; /*-1 Q30*/ move32(); } ELSE { az = index_azimuth; move16(); - f = ONE_IN_Q30; + f = ONE_IN_Q30; /*1 Q30*/ move32(); } @@ -4452,10 +4464,10 @@ void ivas_dirac_dec_compute_directional_responses_fx( const Word16 *azimuth, const Word16 *elevation, const Word16 md_idx, - const Word32 *surCohRatio_fx, + const Word32 *surCohRatio_fx, /*i:Q_surCohRatio*/ Word16 Q_surCohRatio, const Word16 shd_rot_max_order, /* i : split-order rotation method */ - const Word32 *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix Q30*/ const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { @@ -4515,9 +4527,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; + azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; /*q0*/ move16(); - elevation2 = hSpatParamRendCom->elevation2[md_idx]; + elevation2 = hSpatParamRendCom->elevation2[md_idx]; /*q0*/ move16(); } @@ -4527,11 +4539,15 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { + test(); if ( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) { codingBand = add( codingBand, 1 ); } + test(); + test(); + test(); IF( masa_band_mapping != NULL && GT_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand]] ) && LT_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) && NE_16( k, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) ) @@ -4541,20 +4557,20 @@ void ivas_dirac_dec_compute_directional_responses_fx( { mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ } mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k - 1], hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { /* HOA3 PANNING */ IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) { - set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); - set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); + set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ + set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); /*q29*/ Q_direct_response_hoa = Q29; move16(); @@ -4590,11 +4606,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( test(); 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 ); + 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 ); /*Q_direct_response_hoa*/ IF( hodirac_flag ) { - mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[add( k, i_mult( hSpatParamRendCom->num_freq_bands, num_channels_dir ) )], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*Q_direct_response_dir2*/ } } ELSE IF( ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) && ( masa_band_mapping != NULL ) ) || @@ -4603,7 +4619,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( /* Synthesize the first direction */ IF( GT_16( Q_direct_response_hoa, Q29 ) ) { - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); /*Q_direct_response_hoa->q29*/ Q_direct_response_hoa = Q29; move16(); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); @@ -4617,7 +4633,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( { IF( GT_16( Q_direct_response_dir2, Q29 ) ) { - Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); + Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); /*Q_direct_response_dir2->q29*/ Q_direct_response_dir2 = Q29; move16(); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); @@ -4627,7 +4643,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); /* Combine gains from the two directions */ - totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( totalDirect_fx == 0 ) { totalDirect_fx = EPSILON_FIX; @@ -4635,12 +4651,12 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 var_a, var_b, exp_1, exp_2; - var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_a = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); /*15-exp_1*/ + var_b = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); /*15-exp_2*/ - directRatio_fx[0] = L_deposit_h( var_a ); + directRatio_fx[0] = L_deposit_h( var_a ); /*15-exp_1+16*/ move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); /*15-exp_2+16*/ move32(); Word32 temp_a; @@ -4650,13 +4666,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*Q(Q_direct_response_hoa+31-exp_1-31)*/ move32(); exp_arr[l] = add( exp_1, sub( 31, Q_direct_response_hoa ) ); move16(); - temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); + temp_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); /*Q(Q_direct_response_dir2+31-exp_2-31)*/ exp_temp_a = add( exp_2, sub( 31, Q_direct_response_dir2 ) ); - direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); + direct_response_hoa_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_a, exp_temp_a, &final_exp ); /*Q(31-final_exp)*/ move32(); exp_arr[l] = final_exp; move16(); @@ -4667,7 +4683,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_hoa = max_exp; @@ -4707,8 +4723,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, exp_direct_response_temp + 1, &exp_temp ); + temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], exp_direct_response_ism, temp_1, add( exp_direct_response_temp, 1 ), &exp_temp ); //(31-exp_temp) move32(); exp_arr[l] = exp_temp; move16(); @@ -4718,38 +4734,38 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], max_exp - exp_arr[l] ); + direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31- exp_arr[l])->Q(31-max_exp)*/ move32(); } exp_direct_response_ism = max_exp; move16(); } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; /*q30*/ move32(); if ( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); /*q30*/ } if ( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; /*q30*/ move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); /*q30*/ } - 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 ); /*q30*/ // 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 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); /*Q(15-exp_1)*/ + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); /*q(15-exp_2)*/ + directRatio_fx[0] = L_deposit_h( var_a ); // Q(31-exp_1) move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // Q(31-exp_2) move32(); Word32 temp_2, temp_3; @@ -4757,14 +4773,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_hoa, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], directRatio_fx[0] ); /*31-exp_direct_response_hoa+31-exp_1-31*/ move32(); exp_arr[l] = add( exp_direct_response_hoa, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, exp_2 + exp_direct_response_ism, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); /*31-exp_direct_response_ism+31-exp_2-31*/ + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_hoa_fx[l], exp_arr[l], temp_2, add( exp_2, exp_direct_response_ism ), &exp_temp_3 ); /*31-exp_temp_3*/ - direct_response_hoa_fx[l] = temp_3; + direct_response_hoa_fx[l] = temp_3; /*31-exp_temp_3*/ move32(); exp_arr[l] = exp_temp_3; move16(); @@ -4775,7 +4791,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4794,9 +4810,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp = 0; move16(); - var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); - var_b = Sqrt32( var_a, &exp ); - direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); + var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); /*q(31-exp)*/ + var_b = Sqrt32( var_a, &exp ); /*31-exp*/ + direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); /*Q_direct_response_hoa+31-exp-31*/ move32(); exp_arr[l] = add( sub( 31, Q_direct_response_hoa ), exp ); move16(); @@ -4806,7 +4822,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move32(); } Q_direct_response_hoa = sub( 31, max_exp ); @@ -4816,36 +4832,36 @@ void ivas_dirac_dec_compute_directional_responses_fx( Q_direct_response_hoa = sub( Q31, exp_direct_response_hoa ); - Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); /*Q_direct_response_hoa->q29*/ direct_response_q = Q29; move16(); direct_response_fx = direct_response_hoa_fx; IF( NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*Q(2*direct_response_q-31)*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ IF( EQ_16( transport_signal_type, MASA_STEREO_SPACED_MICS ) ) { - direct_response_fx[0] = ONE_IN_Q29; + direct_response_fx[0] = ONE_IN_Q29; /*q29*/ move32(); test(); IF( GE_16( k, dipole_freq_range[0] ) && LT_16( k, dipole_freq_range[1] ) ) { - direct_response_fx[1] = ONE_IN_Q29; + direct_response_fx[1] = ONE_IN_Q29; /*q29*/ move32(); } } ELSE { - set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); + set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); /*q29*/ } } - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*q29*/ } ELSE { @@ -4867,7 +4883,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ - Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); /*q30*/ IF( test == 0 ) { @@ -4875,16 +4891,16 @@ void ivas_dirac_dec_compute_directional_responses_fx( } ELSE { - totalDirect_fx = test; + totalDirect_fx = test; // q30 move32(); } Word16 var_1, var_2, exp_1, exp_2; - var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); - var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); + var_1 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], totalDirect_fx, &exp_1 ); // 15-exp_1 + var_2 = BASOP_Util_Divide3232_Scale( hSpatParamRendCom->energy_ratio2_fx[md_idx][k], totalDirect_fx, &exp_2 ); // 15-exp_2 - directRatio_fx[0] = L_deposit_h( var_1 ); + directRatio_fx[0] = L_deposit_h( var_1 ); // 31-exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_2 ); + directRatio_fx[1] = L_deposit_h( var_2 ); // 31-exp_2 move32(); Word32 var_a; @@ -4904,7 +4920,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( var_a = Mpy_32_32( directRatio_fx[1], direct_response_dir2_fx[l] ); // exp_direct_response_dir2 + exp_2 exp_tmp = 0; move16(); - direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); + direct_response_ls_fx[l] = BASOP_Util_Add_Mant32Exp( temp, add( exp_direct_response_ls, exp_1 ), var_a, add( exp_direct_response_dir2, exp_2 ), &exp_tmp ); // q(31-exp_tmp) move32(); exp_table[l] = exp_tmp; move16(); @@ -4914,7 +4930,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); + direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], sub( exp_max, exp_table[i] ) ); /*(q(31-exp_table[i])->q(31-exp_max))*/ move32(); } Q_direct_response_ls = sub( 31, exp_max ); @@ -4953,8 +4969,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 Q_arr[MAX_OUTPUT_CHANNELS], exp_tmp; FOR( l = 0; l < num_channels_dir; l++ ) { - tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); + tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); // q(31-exp_tmp) move32(); Q_arr[l] = sub( 31, exp_tmp ); move16(); @@ -4964,7 +4980,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( minimum_fx( Q_arr, num_channels_dir, &Q_min ); FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); + direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); // Q_arr[i]->Q_min move32(); } Q_direct_response_temp = Q_min; @@ -4973,31 +4989,31 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 exp_1, exp_2; - masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; + masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; // q30 move32(); IF( masaDirect_fx == 0 ) { - masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); + masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); // q30 } IF( EQ_32( hSpatParamRendCom->numParametricDirections, 2 ) ) { - masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); + masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); // q30 } - ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; + ismDirect_fx = hMasaIsm->energy_ratio_ism_fx[0][md_idx][k]; // q30 move32(); FOR( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); + ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // q30 } - 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 ); // q30 // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a, var_b; - var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); - var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); - directRatio_fx[0] = L_deposit_h( var_a ); + var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); // 15-exp_1 + var_b = BASOP_Util_Divide3232_Scale( ismDirect_fx, totalDirect_fx, &exp_2 ); // 15- exp_2 + directRatio_fx[0] = L_deposit_h( var_a ); // 31- exp_1 move32(); - directRatio_fx[1] = L_deposit_h( var_b ); + directRatio_fx[1] = L_deposit_h( var_b ); // 31 - exp_2 move32(); Word32 temp_2, temp_3; @@ -5005,14 +5021,14 @@ void ivas_dirac_dec_compute_directional_responses_fx( set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); // q(31-exp_direct_response_ls+31-exp_1-31) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_1 ); move16(); - temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); - temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, exp_2 + 31 - Q_direct_response_temp, &exp_temp_3 ); + temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); // q(Q_direct_response_temp+31-exp_2-31) + temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, add( exp_2, sub( 31, Q_direct_response_temp ) ), &exp_temp_3 ); // 31-exp_temp_3 - direct_response_ls_fx[l] = temp_3; + direct_response_ls_fx[l] = temp_3; // 31-exp_temp_3 move32(); exp_arr[l] = exp_temp_3; move16(); @@ -5023,7 +5039,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*q(31-exp_arr[l])->q(31-max_exp)*/ move16(); } Q_direct_response_ls = sub( 31, max_exp ); @@ -5035,6 +5051,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } /* Synthesize surrounding coherence */ + test(); IF( surCohRatio_fx != NULL && surCohRatio_fx[k] > 0 ) { Word16 num_channels_surrCoh; @@ -5052,9 +5069,9 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp = 0; move16(); - temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); - temp = Sqrt32( temp, &exp_temp ); - direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // exp_direct_response_ls + exp_temp + temp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30 /*1 Q30*/, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp_temp ); // q(31-exp_temp) + temp = Sqrt32( temp, &exp_temp ); // q(31-exp_temp) + direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // Q31-(exp_direct_response_ls + exp_temp) move32(); exp_arr[l] = add( exp_direct_response_ls, exp_temp ); @@ -5063,25 +5080,25 @@ void ivas_dirac_dec_compute_directional_responses_fx( { exp_temp_a = 0; move16(); - temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); + temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); /*15-(exp_temp_a+exp_surCohRatio-15)*/ exp_temp_a = add( exp_temp_a, sub( exp_surCohRatio, 15 ) ); - temp_a = Sqrt16( temp_a, &exp_temp_a ); + temp_a = Sqrt16( temp_a, &exp_temp_a ); /*15-temp_a*/ final_exp = 0; move16(); - final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); - direct_response_ls_fx[l] = final; + final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); /*31-final_exp*/ + direct_response_ls_fx[l] = final; /*31-final_exp*/ move32(); exp_arr[l] = final_exp; move16(); } } - max_exp = MIN16B; + max_exp = MIN16B; /*Q0*/ move16(); maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { - direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); + direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], sub( max_exp, exp_arr[l] ) ); /*Q(31-exp_arr[l])->Q(31-max_exp)*/ move32(); } @@ -5093,17 +5110,17 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); - Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); + Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); /*Q_direct_response_ls->Q29*/ direct_response_q = Q29; move16(); /* Set computed gains */ direct_response_fx = direct_response_ls_fx; - v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); /*2*direct_response_q-31*/ direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_square_q*/ + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); /*direct_response_q*/ } ELSE { @@ -5459,9 +5476,9 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_compute_gain_factors_fx( const Word16 num_freq_bands, - const Word32 *diffuseness_fx, - Word32 *direct_gain_factor, - Word32 *diffuse_gain_factor, + const Word32 *diffuseness_fx, /*i:q30*/ + Word32 *direct_gain_factor, /*o:exponent is max_exp_direct*/ + Word32 *diffuse_gain_factor, /*o:exponent is max_exp_diffusion*/ Word16 *max_exp_direct_fx, Word16 *max_exp_diffusion ) { @@ -5475,9 +5492,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( move16(); exp2 = 1; move16(); - direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30, diffuseness_fx[i] ), &exp1 ); + direct_gain_factor[i] = Sqrt32( L_sub( ONE_IN_Q30 /*1 Q30*/, diffuseness_fx[i] ), &exp1 ); /*31-exp1*/ move32(); - diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); + diffuse_gain_factor[i] = Sqrt32( diffuseness_fx[i], &exp2 ); /*31-exp2*/ move32(); exp_direct_gain_factor[i] = exp1; move16(); @@ -5486,9 +5503,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( } /*make common exp for both buffers*/ - Word16 max_exp_direct = MIN16B; + Word16 max_exp_direct = MIN16B; /*Q0*/ move16(); - Word16 max_exp_diffuse = MIN16B; + Word16 max_exp_diffuse = MIN16B; /*Q0*/ move16(); FOR( i = 0; i < num_freq_bands; i++ ) { @@ -5503,9 +5520,9 @@ void ivas_dirac_dec_compute_gain_factors_fx( FOR( i = 0; i < num_freq_bands; i++ ) { - direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); + direct_gain_factor[i] = L_shr( direct_gain_factor[i], sub( max_exp_direct, exp_direct_gain_factor[i] ) ); /*Q(31-max_exp_direct)*/ move32(); - diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); + diffuse_gain_factor[i] = L_shr( diffuse_gain_factor[i], sub( max_exp_diffuse, exp_diffuse_gain_factor[i] ) ); /*Q(31-max_exp_diffuse)*/ move32(); } @@ -5569,8 +5586,8 @@ void ivas_dirac_dec_compute_power_factors_fx( const Word16 num_freq_bands, const Word32 *diffuseness_fx, // Q3O const Word16 max_band_decorr, - Word32 *direct_power_factor, - Word32 *diffuse_power_factor ) + Word32 *direct_power_factor, /*input is q30 and ouput is q29*/ + Word32 *diffuse_power_factor /*input is q30 and ouput is q29*/ ) { Word16 i; @@ -5630,12 +5647,12 @@ void ivas_lfe_synth_with_filters_fx( /* Delay the separated channel to sync the LFE synthesis with the DirAC rendering */ delay = hMasaLfeSynth->delayBuffer_syncDirAC_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncDirAC_fx, delay ); /*q11*/ /* Filterbank for dividing the separated channel to LFE frequencies and higher frequencies */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize, &lowpassCoef_fx_exp ); /*15-lowpassCoef_fx_exp*/ FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum_fx = L_add( hMasaLfeSynth->lowpassSum_fx, L_shl( Mpy_32_16_1( L_sub( data_fx[separateChannelIndex][i], hMasaLfeSynth->lfeSynthRingBuffer_fx[hMasaLfeSynth->ringBufferLoPointer] ), lowpassCoef_fx ), lowpassCoef_fx_exp ) ); // Q11 @@ -5685,7 +5702,7 @@ void ivas_lfe_synth_with_filters_fx( Word16 tmp_shift = W_norm( W_tmp ); - W_tmp = W_shl( W_tmp, tmp_shift ); + W_tmp = W_shl( W_tmp, tmp_shift ); /*Q22+tmp_shift*/ Word16 tmp_q = sub( add( Q22, tmp_shift ), 32 ); Word16 tmp_exp; @@ -5716,62 +5733,62 @@ void ivas_lfe_synth_with_filters_fx( IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneLfeSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - lfeGain_fx = MAX_16; + lfeGain_fx = MAX_16; /* 1.0 in q15*/ move16(); } ELSE { - lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); + lfeGain_fx = extract_h( BASOP_Util_Divide3232_Scale_cadence( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &lfeGain_fx_exp ) ); /*Q(31-(lfeGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneLfeSmooth_q))-16*/ lfeGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneLfeSmooth_q ), lfeGain_fx_exp ); - lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); - lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 + lfeGain_fx = Sqrt16( lfeGain_fx, &lfeGain_fx_exp ); // Q15-lfeGain_fx_exp + lfeGain_fx = shl_r( lfeGain_fx, lfeGain_fx_exp ); // Q15 } IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( Q31, hMasaLfeSynth->targetEneTransSmooth_q ), /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, sub( Q31, hMasaLfeSynth->transportEneSmooth_q ) ), 1 ) ) { - transportGain_fx = MAX_16; + transportGain_fx = MAX_16; // q15 move16(); } ELSE { Flag overFlow; - transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); + transportGain_fx = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, /*EPSILON + */ hMasaLfeSynth->transportEneSmooth_fx, &transportGain_fx_exp ); /*Q=15-(transportGain_fx_exp+hMasaLfeSynth->transportEneSmooth_q-hMasaLfeSynth->targetEneTransSmooth_q)*/ transportGain_fx_exp = add( sub( hMasaLfeSynth->transportEneSmooth_q, hMasaLfeSynth->targetEneTransSmooth_q ), transportGain_fx_exp ); - transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); + transportGain_fx = Sqrt16( transportGain_fx, &transportGain_fx_exp ); // q15-transportGain_fx_exp transportGain_fx = shl_ro( transportGain_fx, transportGain_fx_exp, &overFlow ); // Q15 } j = 0; move16(); FOR( i = mrange[0]; i < mrange[1]; i++ ) { - Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 - data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); + Word32 L_tmp1 = L_mult( transportGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp2 = L_mult( hMasaLfeSynth->transportGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); // Q31 + data_fx[separateChannelIndex][i] = L_add( Mpy_32_32( L_add( L_tmp1, L_tmp2 ), lowPassSignal_fx[i] ), highPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); - Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 - Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); - data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); + Word32 L_tmp3 = L_mult( lfeGain_fx, hMasaLfeSynth->interpolator_fx[j] ); // Q31 + Word32 L_tmp4 = L_mult( hMasaLfeSynth->lfeGainPrev_fx, sub( MAX_16, hMasaLfeSynth->interpolator_fx[j] ) ); /*q31*/ + data_fx[lfeChannelIndex][i] = Mpy_32_32( L_add( L_tmp3, L_tmp4 ), lowPassSignal_fx[i] ); /*q31+q11-q31->q11*/ move32(); j = add( j, 1 ); } - hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; + hMasaLfeSynth->lfeGainPrev_fx = lfeGain_fx; /*q15*/ move16(); - hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; + hMasaLfeSynth->transportGainPrev_fx = transportGain_fx; /*q15*/ move16(); } /* Lowpass filter for removing remaining mid and high frequencies from the LFE signal */ lowpassCoef_fx_exp = 15; move16(); - lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); + lowpassCoef_fx = Inv16( hMasaLfeSynth->ringBufferSize2, &lowpassCoef_fx_exp ); // q15-lowpassCoef_fx_exp FOR( i = 0; i < output_frame; i++ ) { hMasaLfeSynth->lowpassSum2_fx = L_add( hMasaLfeSynth->lowpassSum2_fx, L_shl_r( L_sub( Mpy_32_16_1( data_fx[lfeChannelIndex][i], lowpassCoef_fx ), Mpy_32_16_1( hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2], lowpassCoef_fx ) ), - lowpassCoef_fx_exp ) ); + lowpassCoef_fx_exp ) ); /*q11+15-lowpassCoef_fx_exp-15+lowpassCoef_fx_exp->q11*/ move32(); - hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; + hMasaLfeSynth->lfeSynthRingBuffer2_fx[hMasaLfeSynth->ringBufferLoPointer2] = data_fx[lfeChannelIndex][i]; /*q11*/ move32(); hMasaLfeSynth->ringBufferLoPointer2 = sub( hMasaLfeSynth->ringBufferLoPointer2, 1 ); @@ -5782,14 +5799,14 @@ void ivas_lfe_synth_with_filters_fx( move16(); } - data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; + data_fx[lfeChannelIndex][i] = hMasaLfeSynth->lowpassSum2_fx; /*q11*/ move32(); } /* Delay the separated channel to match the delay of the lowpass filter */ delay = hMasaLfeSynth->delayBuffer_syncLp_size; move16(); - delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); + delay_signal_fx( data_fx[separateChannelIndex], output_frame, hMasaLfeSynth->delayBuffer_syncLp_fx, delay ); /*q11*/ return; } @@ -5912,14 +5929,14 @@ void ivas_lfe_synth_with_filters( static void computeTargetPSDs_direct_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx; @@ -5999,14 +6016,14 @@ static void computeTargetPSDs_direct( static void computeTargetPSDs_direct_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, - const Word32 *direct_power_factor, - const Word32 *reference_power, + const Word32 *direct_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *direct_responses, - const Word32 *direct_responses_square, - Word32 *cy_auto_dir_smooth, + const Word32 *direct_responses, /*q31*/ + const Word32 *direct_responses_square, /*q31*/ + Word32 *cy_auto_dir_smooth, /*q_cy_auto_dir_smooth*/ Word16 *q_cy_auto_dir_smooth, - Word32 *cy_cross_dir_smooth, + Word32 *cy_cross_dir_smooth, /*q_cy_cross_dir_smooth*/ Word16 *q_cy_cross_dir_smooth ) { Word16 ch_idx, cur_idx, i, q_tmp; @@ -6028,14 +6045,17 @@ static void computeTargetPSDs_direct_subframe_fx( move64(); FOR( i = 0; i < num_freq_bands; i++ ) { - W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // (q_reference_power, Q31) + 1 + W_tmp[i] = W_mult_32_32( direct_power[i], direct_responses_square[cur_idx + i] ); // q_reference_power + Q31 + 1 move64(); - W_max = W_max < W_abs( W_tmp[i] ) ? W_abs( W_tmp[i] ) : W_max; + IF( LT_64( W_max, W_abs( W_tmp[i] ) ) ) + { + W_max = W_abs( W_tmp[i] ); + } } q_tmp = W_norm( W_max ); FOR( i = 0; i < num_freq_bands; i++ ) { - cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); + cy_auto_dir_smooth[cur_idx + i] = W_extract_h( W_shl( W_tmp[i], q_tmp ) ); /*q_reference_power+q_tmp*/ move32(); } q_cy_auto_dir_smooth[ch_idx] = add( *q_reference_power, q_tmp ); @@ -6086,11 +6106,11 @@ static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*Q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6109,10 +6129,10 @@ static void computeTargetPSDs_diffuse_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ - scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ - scale_sig32( &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ - v_add_fixed( &cy_auto_diff_smooth[add( cur_idx, start_band )], aux_buffer_res, &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], aux_buffer_res, sub( num_freq_bands, start_band ) ); /* Q31 + Q(q_reference_power) - Q31 = Q(q_reference_power) */ + scale_sig32( aux_buffer_res, sub( num_freq_bands, start_band ), sub( common_q, *q_reference_power ) ); /* Q(common_q) */ + scale_sig32( &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), sub( common_q, *q_cy_auto_diff_smooth ) ); /* Q(common_q) */ + v_add_fixed( &cy_auto_diff_smooth[cur_idx + start_band], aux_buffer_res, &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ), Q1 ); /* Q(common_q) - Q1 */ } /* Q adjustment */ @@ -6158,11 +6178,11 @@ static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /*q_reference_power*/ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx; @@ -6176,7 +6196,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( { cur_idx = imult1616( ch_idx, num_freq_bands ); - v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[add( cur_idx, start_band )], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power + v_multc_fixed( &diffuse_power[start_band], diffuse_responses_square[ch_idx], &cy_auto_diff_smooth[cur_idx + start_band], sub( num_freq_bands, start_band ) ); // (q_reference_power, Q31) -> q_reference_power } *q_cy_auto_diff_smooth = *q_reference_power; @@ -6219,12 +6239,12 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, - const Word32 *diffuse_power_factor, - const Word32 *reference_power, + const Word32 *diffuse_power_factor, /*q31*/ + const Word32 *reference_power, /* q_reference_power */ const Word16 *q_reference_power, - const Word32 *diffuse_responses_square, - const Word32 *onset_filter, - Word32 *cy_auto_diff_smooth, + const Word32 *diffuse_responses_square, /*q31*/ + const Word32 *onset_filter, /*q31*/ + Word32 *cy_auto_diff_smooth, /*q_cy_auto_diff_smooth*/ Word16 *q_cy_auto_diff_smooth ) { Word16 ch_idx, cur_idx, diff_idx; @@ -6328,7 +6348,7 @@ static void computeTargetPSDs_diffuse_with_onsets( #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 /*q15*/, const Word16 averaging_length_ms, const Word16 maxAlpha_fx /*q15*/, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx /*q0*/, const Word32 output_Fs ) { Word16 k; Word16 avg_length_f_ms_fx; @@ -6341,28 +6361,29 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a IF( averaging_length_ms == 0 ) { - set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); + set16_fx( alpha_synthesis_fx, MAX16B, num_freq_bands ); /*q15*/ } ELSE { 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 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) - avg_length_f_ms_fx = tmp_2; + Word16 tmp_1 = BASOP_Util_Divide1616_Scale( averaging_length_ms, frequency_axis_fx[faxis_idx], &tmp_exp ); /*Q(15-(tmp_exp+15-15))*/ + Word16 tmp_2 = mult( tmp_1, 1000 ); // 15 - tmp_exp + 0 -15 = -tmp_exp (Q-fac) + avg_length_f_ms_fx = tmp_2; // Q(-tmp_exp) move16(); move16(); - + /* alpha_synthesis[k] = min( (float) slot_size / ( avg_length_f_ms * (float) output_Fs / 1000.f ), 1.0f );*/ Word32 tmp_3 = Mpy_32_16_1( output_Fs, avg_length_f_ms_fx ); // 0 - tmp_exp - 15 (Q-fac) Word16 tmp_exp_3; - Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); + Word16 tmp_4 = BASOP_Util_Divide3232_Scale( tmp_3, 1000, &tmp_exp_3 ); /*tmp_exp_4 stores resultant exponent*/ Word16 tmp_exp_4 = sub( add( tmp_exp_3, add( add( 31, tmp_exp ), 15 ) ), 31 ); Word16 tmp_exp_5; - 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 ); /*res_exp stores resultant exponent*/ Word16 res_exp = sub( add( tmp_exp_5, 15 ), tmp_exp_4 ); Word16 flag = BASOP_Util_Cmp_Mant32Exp( L_deposit_h( tmp_5 ), res_exp, 1, 31 ); @@ -6373,7 +6394,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a } ELSE { - alpha_synthesis_fx[k] = MAX16B; + alpha_synthesis_fx[k] = MAX16B; /*q15*/ move16(); } @@ -6381,7 +6402,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const Word16 a test(); IF( flag2 == 0 || EQ_16( flag2, 1 ) ) { - alpha_synthesis_fx[k] = maxAlpha_fx; + alpha_synthesis_fx[k] = maxAlpha_fx; /*q15*/ move16(); *numAlphas = add( k, 1 ); move16(); @@ -6441,9 +6462,9 @@ static void computeAlphaSynthesis( static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, - const Word16 spreadCoh_fx, /*Q15*/ - Word32 *direct_response_fx, /*Q29*/ - Word16 *Q_direct_response, /*Q29*/ + const Word16 spreadCoh_fx, /*i:Q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*i/o:stores q for direct_response_fx*/ const Word16 num_channels_dir, const Word16 ambisonics_order ) { @@ -6454,18 +6475,18 @@ static void spreadCoherencePanningHoa_fx( Word32 gainCenter_fx; Word32 gainSide_fx; - ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 exp_Gain_side, exp_Gain_center; IF( spreadCoh_fx > 0 ) { - ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); - ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 30 ), elevation, direct_response_left_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( add( azimuth, 330 ), elevation, direct_response_right_fx /*Q_direct_response*/, ambisonics_order, *Q_direct_response ); Word16 var_a, var_b, exp_a; - IF( LT_16( spreadCoh_fx, ONE_IN_Q14 ) ) + IF( LT_16( spreadCoh_fx, ONE_IN_Q14 /*0.5 q15*/ ) ) { /*gainCenter = (3 - 4*spreadCoh )/3*/ var_a = sub( 24576 /*3 in Q13*/, spreadCoh_fx ); // Q13 @@ -6480,16 +6501,16 @@ static void spreadCoherencePanningHoa_fx( } ELSE { - var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); + var_a = shl( sub( 16384 /*2 in Q13*/, shr( spreadCoh_fx, 2 ) ), 1 ); // q13 exp_a = 15 - Q13; move16(); - var_a = Inv16( var_a, &exp_a ); - gainSide_fx = L_deposit_h( var_a ); // Q14 + 16 = Q30 //exp_a + var_a = Inv16( var_a, &exp_a ); // 15-exp_a + gainSide_fx = L_deposit_h( var_a ); // 15-exp_a + 16 = Q31 -exp_a exp_Gain_side = exp_a; move16(); var_b = sub( 8192 /*2 in Q12*/, shr( spreadCoh_fx, 2 ) /*Q14*/ ); // exp => 3 - gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // Q13 + 16 = Q29 // 3 + exp_a + gainCenter_fx = L_deposit_h( mult( var_b, var_a ) ); // 15-exp_a + 12-15+16=>28-exp_a = // 3 + exp_a exp_Gain_center = add( 3, exp_a ); } @@ -6503,7 +6524,7 @@ static void spreadCoherencePanningHoa_fx( mpy2 = Mpy_32_32( direct_response_fx[i], gainCenter_fx ); // 31 - Q_direct_response + exp_Gain_Center exp = 0; move16(); - direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, 31 - *Q_direct_response + exp_Gain_side, mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); + direct_response_fx[i] = BASOP_Util_Add_Mant32Exp( mpy1, add( sub( 31, *Q_direct_response ), exp_Gain_side ), mpy2, add( sub( 31, *Q_direct_response ), exp_Gain_center ), &exp ); // 31-exp move32(); exp_arr[i] = exp; move16(); @@ -6516,7 +6537,7 @@ static void spreadCoherencePanningHoa_fx( } FOR( i = 0; i < 16; i++ ) { - direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); + direct_response_fx[i] = L_shr( direct_response_fx[i], sub( max_val, exp_arr[i] ) ); // Q(31-exp_arr[i])->q(31-max_val) move32(); } *Q_direct_response = sub( 31, max_val ); @@ -6572,11 +6593,11 @@ static void spreadCoherencePanningHoa( #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( - const Word16 azimuth, - const Word16 elevation, - const Word16 spreadCoh_fx, - Word32 *direct_response_fx, - Word16 *Q_direct_response, + const Word16 azimuth, /*i:q0*/ + const Word16 elevation, /*i:q0*/ + const Word16 spreadCoh_fx, /*i:q15*/ + Word32 *direct_response_fx, /*i/o:Q_direct_response*/ + Word16 *Q_direct_response, /*o: stores q for direct_response_fx*/ const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata ) { @@ -6602,14 +6623,14 @@ static void spreadCoherencePanningVbap_fx( } set32_fx( direct_response_fx, 0, MAX_OUTPUT_CHANNELS ); - vbap_determine_gains_fx( hVBAPdata, direct_response_fx, azimuth, elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_fx /*q29*/, azimuth, elevation, 0 ); *Q_direct_response = Q29; move16(); IF( spreadCoh_fx > 0 ) { - vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, add( azimuth, 30 ), elevation, 0 ); - vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, sub( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx /*q29*/, add( azimuth, 30 ), elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx /*q29*/, sub( azimuth, 30 ), elevation, 0 ); Word32 var1 = 0; move32(); @@ -6703,8 +6724,8 @@ static void spreadCoherencePanningVbap( #ifdef IVAS_FLOAT_FIXED static void normalizePanningGains_fx( - Word32 *direct_response_fx, - Word16 *q_direct_res, + Word32 *direct_response_fx, /*i/o:resultant q is q_direct_res*/ + Word16 *q_direct_res, /*i/o: stores q for direct_response_fx*/ const Word16 num_channels_dir ) { Word32 energySum_fx; @@ -6714,7 +6735,7 @@ static void normalizePanningGains_fx( move16(); Word16 gb = find_guarded_bits_fx( num_channels_dir ); - energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); + energySum_fx = sum2_f_32_fx( direct_response_fx, num_channels_dir, gb ); // exp_energySum stores resultant exponent IF( GT_16( *q_direct_res, Q31 ) ) { exp_energySum = add( shl( sub( Q31, *q_direct_res ), 1 ), gb ); @@ -6723,17 +6744,17 @@ static void normalizePanningGains_fx( IF( energySum_fx > 0 ) { - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } ELSE { - energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); - normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, exp_energySum, ONE_IN_Q30, 1, &exp_energySum ); // 31-exp_energySum + normVal_fx = ISqrt32( energySum_fx, &exp_energySum ); // 31-exp_energySum } FOR( i = 0; i < num_channels_dir; i++ ) { - direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); + direct_response_fx[i] = Mpy_32_32( direct_response_fx[i], normVal_fx ); // q_direct_res stores resultant q for the same move32(); } Word16 exp = add( sub( Q31, *q_direct_res ), exp_energySum ); -- GitLab From 8a552db21379224392a5451afbd1ba62c6997cf3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 14:05:53 +0530 Subject: [PATCH 04/39] Clang formatting changes --- lib_dec/tonalMDCTconcealment_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index b46d0abd5..adb73de03 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -1621,10 +1621,10 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; move16(); - Word32 y = concealment_noise[l];//concealment_noise_e + Word32 y = concealment_noise[l]; // concealment_noise_e move32(); - 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 ) );//Q31-2* concealment_noise_e + 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 ) ); // Q31-2* concealment_noise_e 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 ); // Q31- hTonalMDCTConc->curr_noise_nrg_exp move32(); } -- GitLab From 342430c51e3a9d5cd060ba9cfc04d73eeec1ead2 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Tue, 17 Sep 2024 01:20:00 +0300 Subject: [PATCH 05/39] fix 853 fixed point --- lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 87f712150..424110028 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -191,7 +191,7 @@ #define FIX_924_IGF_ROUNDFX_SAT #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ - +#define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6903773ed..eb805a80c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5585,6 +5585,10 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + delta_phi = L_shr( delta_phi, 22 ); + delta_phi = L_shl( delta_phi, 22 ); +#endif IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) { azimuth = L_sub( azimuth, delta_phi ); -- GitLab From a7542956e41d112aa34c37569572f974d21661e9 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sat, 28 Sep 2024 16:48:44 +0300 Subject: [PATCH 06/39] fix 853 basop --- lib_dec/ivas_masa_dec.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index eb805a80c..f49c5556c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5522,7 +5522,12 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 nb_bits_read; Word32 delta_phi; // Q22 Word16 meta_write_index; +#if 1 + static FILE *pF = NULL; + if ( pF == NULL ) + pF = fopen( "./direction.txt", "w" ); +#endif nb_bits_read = *next_bit_pos; move16(); nbands = hQMetaData->q_direction->cfg.nbands; @@ -5585,19 +5590,46 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ + #if 0 #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - delta_phi = L_shr( delta_phi, 22 ); - delta_phi = L_shl( delta_phi, 22 ); + delta_phi = L_shr( delta_phi, 20 ); + delta_phi = L_shl( delta_phi, 20 ); +#endif + #endif +#if 1 + fprintf( pF, "azimuth = %4.2f delta_phi = %4.2f obj = %d \n", (float) azimuth / (float) 4194304, (float) delta_phi / (float) 4194304, obj ); #endif +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + Word32 tmp_32; + Word64 tmp_64; + tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); + tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); + + + IF( GT_64( tmp_64, (DEGREE_360_Q_22 + 83886) ) ) /* >= 360 in Q22 + 0.02 in Q22, because there is an additional shift left in W_mult_32_16*/ +#else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) +#endif { azimuth = L_sub( azimuth, delta_phi ); +#if 1 + fprintf( pF, "azimuth = %3.1f obj = %d 1 \n", (float) azimuth / (float) 4194304, obj ); +#endif } ELSE { +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC + + IF( GT_64( -DEGREE_360_Q_22 - 83886, tmp_64 ) ) +#else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) +#endif { azimuth = L_add( azimuth, delta_phi ); +#if 1 + fprintf( pF, "azimuth = %3.1f obj = %d -1 \n", (float) azimuth / (float) 4194304, obj ); +#endif + } } } -- GitLab From e2801e12b3a46564a28f5996a1162eacb01be4ee Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sat, 28 Sep 2024 17:53:05 +0300 Subject: [PATCH 07/39] fix 853 basop --- lib_com/ivas_cnst.h | 5 ++++- lib_dec/ivas_masa_dec.c | 24 ++++-------------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 5fef65816..1356d695e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1353,7 +1353,10 @@ enum #define MASA_JBM_RINGBUFFER_FRAMES 3 - +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC +#define TOLERANCE_360_Q22 1510033326 /* 360 in Q22 + 0.02 in Q22*/ +#define MINUS_TOLERANCE_360_Q22 -1510033326 /* - (360 in Q22 + 0.02 in Q22) */ +#endif typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f49c5556c..a1a7c5728 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5590,46 +5590,30 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ - #if 0 -#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - delta_phi = L_shr( delta_phi, 20 ); - delta_phi = L_shl( delta_phi, 20 ); -#endif - #endif -#if 1 - fprintf( pF, "azimuth = %4.2f delta_phi = %4.2f obj = %d \n", (float) azimuth / (float) 4194304, (float) delta_phi / (float) 4194304, obj ); -#endif + #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC Word32 tmp_32; Word64 tmp_64; tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); - - IF( GT_64( tmp_64, (DEGREE_360_Q_22 + 83886) ) ) /* >= 360 in Q22 + 0.02 in Q22, because there is an additional shift left in W_mult_32_16*/ + IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ #else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) #endif { azimuth = L_sub( azimuth, delta_phi ); -#if 1 - fprintf( pF, "azimuth = %3.1f obj = %d 1 \n", (float) azimuth / (float) 4194304, obj ); -#endif } ELSE { #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - IF( GT_64( -DEGREE_360_Q_22 - 83886, tmp_64 ) ) + IF( GT_64( MINUS_TOLERANCE_360_Q22, tmp_64 ) ) #else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) #endif { - azimuth = L_add( azimuth, delta_phi ); -#if 1 - fprintf( pF, "azimuth = %3.1f obj = %d -1 \n", (float) azimuth / (float) 4194304, obj ); -#endif - + azimuth = L_add( azimuth, delta_phi ); } } } -- GitLab From f2c82000e89a82af976397b321c482382720f51f Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Sun, 29 Sep 2024 09:36:29 +0300 Subject: [PATCH 08/39] fix clang --- lib_dec/ivas_masa_dec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a1a7c5728..eea31e559 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5584,20 +5584,20 @@ static Word16 ivas_decode_masaism_metadata_fx( test(); test(); test(); - // if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) + /* if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) */ IF( ( ( azimuth > 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] > 0 ) ) || ( ( azimuth < 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] < 0 ) ) ) { Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ -#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC +#ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC Word32 tmp_32; Word64 tmp_64; tmp_32 = L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ); tmp_64 = W_mult_32_16( tmp_32, no_phi_masa[bits_ism[obj] - 1][idx_el] ); - IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ + IF( GT_64( tmp_64, TOLERANCE_360_Q22 ) ) /* >= 360 in Q22 (because there is an additional shift left in W_mult_32_16) + 0.02 in Q22 to counteract for precision loss, */ #else IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) #endif @@ -5607,13 +5607,12 @@ static Word16 ivas_decode_masaism_metadata_fx( ELSE { #ifdef FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC - IF( GT_64( MINUS_TOLERANCE_360_Q22, tmp_64 ) ) #else if ( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) #endif { - azimuth = L_add( azimuth, delta_phi ); + azimuth = L_add( azimuth, delta_phi ); } } } -- GitLab From 0bbf2c7cd5140d12728312054c52bd515cdbb391 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Tue, 8 Oct 2024 14:21:57 +0300 Subject: [PATCH 09/39] remove debug code from issue 853 --- lib_dec/ivas_masa_dec.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index eea31e559..13e970f85 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -5522,12 +5522,7 @@ static Word16 ivas_decode_masaism_metadata_fx( Word16 nb_bits_read; Word32 delta_phi; // Q22 Word16 meta_write_index; -#if 1 - static FILE *pF = NULL; - if ( pF == NULL ) - pF = fopen( "./direction.txt", "w" ); -#endif nb_bits_read = *next_bit_pos; move16(); nbands = hQMetaData->q_direction->cfg.nbands; -- GitLab From ce60a2351b70dcfc9ccc264e5cca341d960732a9 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 23 Oct 2024 17:22:46 +0530 Subject: [PATCH 10/39] Fix for 3GPP issue 885: Crashes in stereo BASOP decoder with error pattern from complexity measurement --- lib_dec/swb_tbe_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c519d51b1..c5c1bed29 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1862,8 +1862,8 @@ void ivas_swb_tbe_dec_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } IF( exp < 0 ) @@ -1883,8 +1883,8 @@ void ivas_swb_tbe_dec_fx( #endif temp_fx = sub( 32767 /*1.0f Q15*/, temp_fx ); Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } } -- GitLab From e8a625a2c6d4b32e1551335707107972f49dd0c4 Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Wed, 23 Oct 2024 14:56:41 +0200 Subject: [PATCH 11/39] add missing pop_wmops(); in ivas_vbap.c --- lib_rend/ivas_vbap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d62f5952..91587f46d 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -467,6 +467,8 @@ ivas_error vbap_init_data_fx( } } + pop_wmops(); + IF( is_success ) { *hVBAPdata = vbap; -- GitLab From 26f383a19d482046934efc5e6d21a8c5bb31798a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 09:19:14 +0530 Subject: [PATCH 12/39] Q-information update for lib_dec and lib_rend files --- lib_com/common_api_types.h | 14 +- lib_com/ivas_prot.h | 10 +- lib_com/ivas_tools.c | 21 +- lib_com/tools.c | 6 +- lib_dec/lead_deindexing_fx.c | 4 +- lib_dec/lib_dec.h | 22 +- lib_dec/lib_dec_fx.c | 164 +++++----- lib_dec/lp_exc_d_fx.c | 8 +- lib_rend/ivas_efap.c | 2 +- lib_rend/ivas_prot_rend.h | 22 +- lib_rend/ivas_stat_rend.h | 16 +- lib_rend/ivas_vbap.c | 537 +++++++++++++++--------------- lib_rend/lib_rend.c | 617 +++++++++++++++++++---------------- lib_rend/lib_rend.h | 194 +++++------ 14 files changed, 862 insertions(+), 775 deletions(-) diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 3e8a963cd..ed75c249b 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -119,13 +119,13 @@ typedef struct _IVAS_ENC_CHANNEL_AWARE_CONFIG typedef struct _IVAS_ISM_METADATA { #ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx; - Word32 elevation_fx; - Word16 radius_fx; - Word32 spread_fx; - Word32 gainFactor_fx; - Word32 yaw_fx; - Word32 pitch_fx; + Word32 azimuth_fx; /* Q22 */ + Word32 elevation_fx; /* Q22 */ + Word16 radius_fx; /* Q9 */ + Word32 spread_fx; /* Q22 */ + Word32 gainFactor_fx; /* Q31 */ + Word32 yaw_fx; /* Q22 */ + Word32 pitch_fx; /* Q22 */ #endif float azimuth; float elevation; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 876313d1b..db7ec4ee2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -7570,11 +7570,11 @@ void panning_wrap_angles( float *ele_wrapped /* o : wrapped elevation component */ ); #ifdef IVAS_FLOAT_FIXED -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ); #endif void v_sort_ind( diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 76e84cc9a..20cce673c 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -2938,8 +2938,8 @@ static float wrap_azi( } #ifdef IVAS_FLOAT_FIXED /* helper function for panning_wrap_angles */ -static Word32 wrap_azi_fixed( - const Word32 azi_deg ) +static Word32 wrap_azi_fx( + const Word32 azi_deg /* Q22 */ ) { Word32 azi = azi_deg; move32(); @@ -3027,19 +3027,18 @@ void panning_wrap_angles( } #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* - * panning_wrap_angles_fixed() + * panning_wrap_angles_fx() * * Wrap angles for amplitude panning to the range: * azimuth = (-180, 180] * elevation = [-90, 90] * Considers direction changes from large elevation values *-------------------------------------------------------------------*/ -void panning_wrap_angles_fixed( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - Word32 *azi_wrapped, /* o : wrapped azimuth component */ - Word32 *ele_wrapped /* o : wrapped elevation component */ - +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ ) { Word32 azi, ele; @@ -3053,7 +3052,7 @@ void panning_wrap_angles_fixed( { *ele_wrapped = ele; move32(); - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); return; } @@ -3093,7 +3092,7 @@ void panning_wrap_angles_fixed( ele = L_sub( -ANGLE_180_DEG_Q22, ele ); } } - *azi_wrapped = wrap_azi_fixed( azi ); + *azi_wrapped = wrap_azi_fx( azi ); move32(); *ele_wrapped = ele; move32(); diff --git a/lib_com/tools.c b/lib_com/tools.c index 0222d6cc4..072cfa767 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1101,9 +1101,9 @@ float dotp( /*! r: dot product of x[] and y[] */ Word32 dotp_fixed( - const Word32 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ + const Word32 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ ) { Word16 i; diff --git a/lib_dec/lead_deindexing_fx.c b/lib_dec/lead_deindexing_fx.c index 068d60bb1..4c13ee392 100644 --- a/lib_dec/lead_deindexing_fx.c +++ b/lib_dec/lead_deindexing_fx.c @@ -277,7 +277,7 @@ static void fcb_decode_pos_fx( FOR( i = 0; i < tmp_loop; i++ ) { select_table23 = select_table22[temp1]; - select_table24 = &select_table23[sub( pulse_num, l )]; + select_table24 = &select_table23[pulse_num - l]; k = sub( *select_table24, k ); WHILE( LE_16( k, *select_table24 ) ) @@ -286,7 +286,7 @@ static void fcb_decode_pos_fx( select_table24--; } - k = sub( select_table23[sub( temp2, l )], k ); + k = sub( select_table23[temp2 - l], k ); pos_vector[i] = sub( l, 1 ); move16(); temp1 = sub( temp1, 1 ); diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 93604547b..e44092fb6 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -430,7 +430,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -455,7 +455,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *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 */ + Word16 *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 Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o : indication that the decoder needs a new frame */ ); @@ -527,14 +527,14 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ); /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *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 */ + Word16 *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 Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , JbmTraceFileWriterFn jbmWriterFn, @@ -545,7 +545,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *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 */ + Word16 *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 Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ); @@ -571,12 +571,12 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ); ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ); ivas_error IVAS_DEC_GetNumOrientationSubframes( @@ -586,7 +586,7 @@ ivas_error IVAS_DEC_GetNumOrientationSubframes( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ); @@ -678,7 +678,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( /*! r: error code */ ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ); /*! r: true if decoder has no data in VoIP jitter buffer */ @@ -689,8 +689,8 @@ bool IVAS_DEC_VoIP_IsEmpty( ivas_error IVAS_DEC_VoIP_Get_CA_offset( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *optimum_offset, - Word16 *FEC_hi + Word16 *optimum_offset, //Q0 + Word16 *FEC_hi //Q0 ); #ifdef SUPPORT_JBM_TRACEFILE diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index d3e26547e..05fd52bfb 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -295,7 +295,7 @@ static void init_decoder_config( hDecoderConfig->Opt_RendConfigCustom = 0; hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; hDecoderConfig->Opt_non_diegetic_pan = 0; - hDecoderConfig->non_diegetic_pan_gain_fx = 0; + hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15 hDecoderConfig->Opt_tsm = 0; hDecoderConfig->Opt_delay_comp = 0; hDecoderConfig->Opt_ExternalOrientation = 0; @@ -418,7 +418,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -489,7 +489,7 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled; hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan; - hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; + hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15 hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = Opt_dpid_on; @@ -571,11 +571,11 @@ Word16 get_render_frame_size_ms( } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 1 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 ); } ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) ) { - return shl( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ), 2 ); + return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 ); } return 0; } @@ -637,7 +637,7 @@ ivas_error IVAS_DEC_GetRenderFramesize( ivas_error IVAS_DEC_GetRenderFramesizeSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *render_framesize /* o : render framesize in samples */ + Word16 *render_framesize /* o : render framesize in samples Q0 */ ) { Word16 tmp; @@ -679,7 +679,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeSamples( ivas_error IVAS_DEC_GetRenderFramesizeMs( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - UWord32 *render_framesize /* o : render framesize in samples */ + UWord32 *render_framesize /* o : render framesize in samples Q0 */ ) { test(); @@ -703,7 +703,7 @@ ivas_error IVAS_DEC_GetRenderFramesizeMs( ivas_error IVAS_DEC_GetReferencesUpdateFrequency( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word16 *update_frequency /* o : update frequency */ + Word16 *update_frequency /* o : update frequency Q0 */ ) { test(); @@ -937,7 +937,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL && - NE_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 0 ) ) + ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) ) { DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0]; st->codec_mode = MODE2; @@ -969,7 +969,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( ivas_error IVAS_DEC_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */ - Word16 *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 */ + Word16 *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 Q0 */ Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */ bool *needNewFrame /* o :indication that the decoder needs a new frame */ ) @@ -1090,33 +1090,33 @@ ivas_error IVAS_DEC_GetSamples( Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 } IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 } } ELSE { - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); + tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) } IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } - for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { - hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); + hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 } } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); @@ -1189,7 +1189,7 @@ static ivas_error IVAS_DEC_Setup( UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */ UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */ - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Q0 */ ) { ivas_error error; @@ -1258,7 +1258,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( 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 ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) 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 ) ) && st_ivas->ini_active_frame == 0 ) { IF( st_ivas->hSpar ) { @@ -1317,7 +1317,7 @@ static ivas_error IVAS_DEC_Setup( test(); test(); test(); - IF( is_DTXrate( ivas_total_brate ) == 0 && st_ivas->ivas_format == MASA_ISM_FORMAT && 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 ) ) && st_ivas->ini_active_frame == 0 ) + IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && 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 ) ) && st_ivas->ini_active_frame == 0 ) { IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { @@ -1363,7 +1363,7 @@ static ivas_error IVAS_DEC_Setup( static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - 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 Q11 */ Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ) { @@ -1403,7 +1403,7 @@ static ivas_error IVAS_DEC_GetTcSamples( 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++ ) { set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k ); - st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; + st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; // Q11 } } @@ -1463,13 +1463,13 @@ static ivas_error IVAS_DEC_GetTcSamples( /*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 ) { - 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 ) ); // Q11 sts[n]->cldfbAna->Q_cldfb_state = Q11; move16(); } 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 ) ); // Q11 sts[n]->cldfbSyn->Q_cldfb_state = Q11; move16(); } @@ -1498,7 +1498,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */ - Word32 *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 /* 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 Q11*/ ) { Decoder_Struct *st_ivas; @@ -1529,7 +1529,8 @@ static ivas_error IVAS_DEC_GetRenderedSamples( const UWord16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the renerer pipeline */ - Word16 *pcmBuf ) + Word16 *pcmBuf // Q0 +) { Decoder_Struct *st_ivas; ivas_error error; @@ -1768,23 +1769,23 @@ ivas_error IVAS_DEC_GetObjectMetadata( IF( hIsmMeta == NULL || zero_flag ) { - metadata->azimuth_fx = 0; - metadata->elevation_fx = 0; - metadata->radius_fx = 512; - metadata->yaw_fx = 0; - metadata->pitch_fx = 0; - metadata->spread_fx = 0; - metadata->gainFactor_fx = ONE_IN_Q31; + metadata->azimuth_fx = 0; // Q22 + metadata->elevation_fx = 0; // Q22 + metadata->radius_fx = 512; // Q9 + metadata->yaw_fx = 0; // Q22 + metadata->pitch_fx = 0; // Q22 + metadata->spread_fx = 0; // Q22 + metadata->gainFactor_fx = ONE_IN_Q31; // Q31 metadata->non_diegetic_flag = 0; } ELSE { - metadata->azimuth_fx = hIsmMeta->azimuth_fx; - metadata->elevation_fx = hIsmMeta->elevation_fx; - metadata->radius_fx = hIsmMeta->radius_fx; - metadata->yaw_fx = hIsmMeta->yaw_fx; - metadata->pitch_fx = hIsmMeta->pitch_fx; - metadata->spread_fx = 0; + metadata->azimuth_fx = hIsmMeta->azimuth_fx; // Q22 + metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22 + metadata->radius_fx = hIsmMeta->radius_fx; // Q9 + metadata->yaw_fx = hIsmMeta->yaw_fx; // Q22 + metadata->pitch_fx = hIsmMeta->pitch_fx; // Q22 + metadata->spread_fx = 0; // Q22 metadata->gainFactor_fx = ONE_IN_Q31; metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag; } @@ -1940,18 +1941,18 @@ ivas_error IVAS_DEC_FeedHeadTrackData( Word32 updateRate_fx = 1677721600; // value is 200 in Q23 move32(); - orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); - orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); - orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); - orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); - hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); + orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); // Q29 + orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 + hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29 orientation.q_fact = Q29; hHeadTrackData->OrientationTracker->refRot.q_fact = Q29; @@ -2004,10 +2005,10 @@ ivas_error IVAS_DEC_FeedRefRotData( pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker; - pOtr->refRot.w_fx = rotation.w_fx; - pOtr->refRot.x_fx = rotation.x_fx; - pOtr->refRot.z_fx = rotation.z_fx; - pOtr->refRot.y_fx = rotation.y_fx; + pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact + pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact + pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact + pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact pOtr->refRot.q_fact = rotation.q_fact; move32(); @@ -2140,15 +2141,16 @@ ivas_error IVAS_DEC_FeedCustomLsData( hLsSetupCustom->num_spk = hLsCustomData.num_spk; move16(); - Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); - Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); + Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); // Q22 + Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22 /* Set planar flag */ is_planar = 1; move16(); FOR( i = 0; i < hLsCustomData.num_spk; i++ ) { - IF( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) + test(); + if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 ) { is_planar = 0; move16(); @@ -2282,9 +2284,9 @@ 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 ); + Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 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; @@ -2382,9 +2384,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( move32(); } - Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); - Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); + Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16 + Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26 + Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30 Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS ); @@ -2444,7 +2446,7 @@ ivas_error IVAS_DEC_GetDelay( nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); move16(); - nSamples[2] = (Word16) W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ); + nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) ); move16(); nSamples[0] = add( nSamples[1], nSamples[2] ); move16(); @@ -2496,7 +2498,7 @@ ivas_error IVAS_DEC_HasDecodedFirstGoodFrame( ivas_error IVAS_DEC_GetPcmFrameSize( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels */ + Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */ ) { test(); @@ -2572,7 +2574,7 @@ static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 n /* Add 4 padding bytes required by core coder */ FOR( i = 0; i < 4 * 8; ++i ) { - serial[L_add( num_bits, (Word32) i )] = 0; + serial[( num_bits + i )] = 0; move16(); } #undef WMC_TOOL_SKIP @@ -2696,7 +2698,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } @@ -2719,7 +2721,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const Word16 quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality Q14 */ ) { ivas_error error; @@ -2727,13 +2729,14 @@ ivas_error IVAS_DEC_TSM_SetQuality( error = IVAS_ERR_OK; move32(); - IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm, false ) ) + IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false ) { return IVAS_ERR_TSM_NOT_ENABLED; } ELSE { - hIvasDec->tsm_quality = quality; + hIvasDec->tsm_quality = quality; // Q14 + move16(); } return error; @@ -2749,7 +2752,7 @@ ivas_error IVAS_DEC_TSM_SetQuality( ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *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 */ + Word16 *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 Q0 */ const UWord32 systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE , @@ -2804,7 +2807,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( extBufferedSamples = add( nSamplesRendered, nSamplesBuffered ); Word16 exp; extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp ); - extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, 15 - exp ); + extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0 dataUnit = NULL; /* pop one access unit from the jitter buffer */ @@ -2959,7 +2962,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( ivas_error IVAS_DEC_Flush( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ - Word16 *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 */ + Word16 *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 Q0 */ Word16 *nSamplesFlushed /* o : number of samples flushed */ ) { @@ -3462,8 +3465,9 @@ void IVAS_DEC_PrintDisclaimer( void ) static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, - Word32 *Buf_fx, - Word16 *pcmBuf ) + Word32 *Buf_fx, // Q11 + Word16 *pcmBuf // Q0 +) { DEC_CORE_HANDLE *hCoreCoder; Word16 mixer_left_fx, mixer_right_fx; @@ -3477,13 +3481,13 @@ static ivas_error evs_dec_main_fx( hCoreCoder[0]->total_num_bits = st_ivas->num_bits; move16(); move32(); - 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 /*Q0*/ ) ); // Q0 move16(); mdct_switching_dec( hCoreCoder[0] ); FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) { - p_output_fx[ch] = st_ivas->p_output_fx[ch]; + p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0 } /* run the main EVS decoding routine */ @@ -3538,7 +3542,7 @@ static ivas_error evs_dec_main_fx( move16(); IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); + mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14 mixer_right_fx = sub( MAX16B, mixer_left_fx ); v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */ diff --git a/lib_dec/lp_exc_d_fx.c b/lib_dec/lp_exc_d_fx.c index e0bcb2c60..cb94c47f7 100644 --- a/lib_dec/lp_exc_d_fx.c +++ b/lib_dec/lp_exc_d_fx.c @@ -57,7 +57,7 @@ void lp_filt_exc_dec_fx( lp_flag = (Word16) get_next_indice_fx( st_fx, 1 ); } } - IF( EQ_16( lp_flag, LOW_PASS ) ) + IF( lp_flag == LOW_PASS ) { /* pointer positioning to avoid doing it inside the loop */ test(); @@ -76,9 +76,9 @@ void lp_filt_exc_dec_fx( FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_mult( fac_n, exc[add( sub( i, 1 ), i_subfr )] ); - L_tmp = L_mac( L_tmp, fac_m, exc[add( i /*+ 0 */, i_subfr )] ); - code[i] = mac_r( L_tmp, fac_n, exc[add( add( i, 1 ), i_subfr )] ); + L_tmp = L_mult( fac_n, exc[( ( i - 1 ) + i_subfr )] ); + L_tmp = L_mac( L_tmp, fac_m, exc[( i /*+ 0 */ + i_subfr )] ); + code[i] = mac_r( L_tmp, fac_n, exc[( ( i + 1 ) + i_subfr )] ); move16(); } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index ddaf6a41a..e9f7d3d33 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -384,7 +384,7 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fixed( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); /* Panning */ efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 033086191..8a9e8185d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -254,19 +254,21 @@ void efap_determine_gains( #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ); + void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ); + void vbap_free_data_fx( VBAP_HANDLE *hVBAPdata /* i/o: VBAP handle to be freed */ ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 03b8fd46e..49808bdd1 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -780,12 +780,12 @@ typedef struct vbap_data_structure Word16 bottom_virtual_speaker_node_index; Word16 back_virtual_speaker_node_index; #ifdef IVAS_FLOAT_FIXED - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; - Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *object_mode_back_virtual_speaker_node_division_gains_fx; /* Q16 */ #else float *bottom_virtual_speaker_node_division_gains; float *top_virtual_speaker_node_division_gains; @@ -2350,8 +2350,8 @@ 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 */ - Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths */ - Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations */ + Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker azimuths Q22 */ + Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; /* custom loudspeaker elevations Q22 */ 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 */ diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d62f5952..9f4612947 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -94,8 +94,8 @@ typedef struct connection_option Word16 chA; Word16 chB; #ifdef IVAS_FLOAT_FIXED - Word32 arc_weighted_fx; - Word32 arc_fx; + Word32 arc_weighted_fx; /* Q29 */ + Word32 arc_fx; /* Q29 */ #else float arc; float arc_weighted; @@ -115,9 +115,9 @@ enum SpeakerNodeGroup typedef struct vbap_speaker_node_structure { #ifdef IVAS_FLOAT_FIXED - Word32 azi_deg_fx; - Word32 ele_deg_fx; - Word32 unit_vec_fx[3]; + Word32 azi_deg_fx; /* Q22 */ + Word32 ele_deg_fx; /* Q22 */ + Word32 unit_vec_fx[3]; /* Q30 */ #else float azi_deg; float ele_deg; @@ -137,13 +137,13 @@ static UWord8 vector_matrix_multiply_3x3_fx( const Word16 *src_vector, Word32 ma static UWord8 vector_matrix_multiply_3x3_32_fx( const Word32 *src_vector, Word32 matrix[3][3], Word32 *result, Word16 q_matrix ); -static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const int16_t num_speaker_nodes ); +static void init_speaker_node_direction_data_fx( VBAP_SPEAKER_NODE *speaker_node_data, const Word32 *speaker_node_azi_deg_fx, const Word32 *speaker_node_ele_deg_fx, const Word16 num_speaker_nodes ); static Word16 determine_virtual_surface_triplets_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, VBAP_VS_TRIPLET *triplets, Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS], enum SpeakerNodeGroup allowed_group ); -static void determine_initial_search_indices_fx( const int16_t num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); +static void determine_initial_search_indices_fx( const Word16 num_triplets, const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] ); -static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, int16_t *group2_count ); +static ivas_error determine_connections_fx( const Word16 num_speaker_nodes, const VBAP_SPEAKER_NODE *speaker_node_data, Word16 connections[][2], const Word16 max_num_connections, Word16 *group1_count, Word16 *group2_start, Word16 *group2_count ); static void formulate_horizontal_connections_fx( const VBAP_SPEAKER_NODE *speaker_node_data, const Word16 num_speaker_nodes, Word16 connections[][2], Word16 *connection_write_index ); @@ -157,7 +157,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_H static Word16 determine_best_triplet_and_gains_fx( VBAP_SEARCH_STRUCT *search_struct, const Word16 panning_unit_vec_fx[3], const Word16 azi_deg, Word32 gains_fx[3] ); -static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 *max_exp, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); +static void determine_virtual_speaker_node_division_gains_fx( const Word16 virtual_speaker_node_index, Word16 *virtual_node_division_gains_fx, Word16 connections[][2], const enum VirtualSpeakerNodeType type, const Word16 max_num_connections, const Word16 num_speaker_nodes, const Word16 use_object_mode ); static void reorder_triplets_fx( VBAP_VS_TRIPLET *triplets, const Word16 *target_order, const Word16 num_triplets ); #else @@ -193,13 +193,14 @@ static void reorder_triplets( VBAP_VS_TRIPLET *triplets, const int16_t *target_o * * Initialize VBAP data structure for the speaker node set *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED ivas_error vbap_init_data_fx( - VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ - const IVAS_FORMAT ivas_format /* i : IVAS format */ + VBAP_HANDLE *hVBAPdata, /* i/o: handle for VBAP data structure that will be initialized */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths (positive left) Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations (positive up) Q22 */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes in the set */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { /* Variables */ @@ -213,8 +214,8 @@ ivas_error vbap_init_data_fx( enum VirtualSpeakerNodeType virtual_bottom_type; enum VirtualSpeakerNodeType virtual_back_type; - Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; + Word32 speaker_node_azi_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ + Word32 speaker_node_ele_deg_internal_fx[VBAP_MAX_NUM_SPEAKER_NODES]; /* Q22 */ VBAP_SPEAKER_NODE speaker_node_data[VBAP_MAX_NUM_SPEAKER_NODES]; VBAP_DATA *vbap; @@ -299,7 +300,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /*-90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->bottom_virtual_speaker_node_index] = -377487360; /* -90.0f in Q22 */ move32(); move32(); } @@ -323,7 +324,7 @@ ivas_error vbap_init_data_fx( is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains_fx != NULL; } speaker_node_azi_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 0; - speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /*90.0f in Q22*/ + speaker_node_ele_deg_internal_fx[vbap->top_virtual_speaker_node_index] = 377487360; /* 90.0f in Q22 */ move32(); move16(); } @@ -346,24 +347,14 @@ ivas_error vbap_init_data_fx( set16_fx( vbap->object_mode_back_virtual_speaker_node_division_gains_fx, 0, num_speaker_nodes ); is_success &= vbap->object_mode_back_virtual_speaker_node_division_gains_fx != NULL; } - speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; + speaker_node_azi_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 754974720; /* 180.0f in Q22 */ speaker_node_ele_deg_internal_fx[vbap->back_virtual_speaker_node_index] = 0; move32(); move16(); } + init_speaker_node_direction_data_fx( speaker_node_data, speaker_node_azi_deg_internal_fx, speaker_node_ele_deg_internal_fx, vbap->num_speaker_nodes_internal ); -#ifdef TRUE0 - /*TODO: Clean up of update float buffers*/ - for ( int ch = 0; ch < vbap->num_speaker_nodes_internal; ch++ ) - { - speaker_node_data[ch].unit_vec[0] = fix_to_float( speaker_node_data[ch].unit_vec_fx[0], Q30 ); - speaker_node_data[ch].unit_vec[1] = fix_to_float( speaker_node_data[ch].unit_vec_fx[1], Q30 ); - speaker_node_data[ch].unit_vec[2] = fix_to_float( speaker_node_data[ch].unit_vec_fx[2], Q30 ); - speaker_node_data[ch].ele_deg = fix_to_float( speaker_node_data[ch].ele_deg_fx, Q22 ); - speaker_node_data[ch].azi_deg = fix_to_float( speaker_node_data[ch].azi_deg_fx, Q22 ); - } -#endif /* Allocate and determine node-node connections */ max_num_connections = mult0( ( sub( vbap->num_speaker_nodes_internal, 2 ) ), 3 ); /* Theoretical maximum */ @@ -382,10 +373,12 @@ ivas_error vbap_init_data_fx( Word16 speaker_nodes_horiz_internal = 0; move16(); UWord8 loop_done = 0; + move16(); /* Count nodes in different groups to reserve correct memory */ FOR( ch = 0; ch < vbap->num_speaker_nodes_internal && !loop_done; ch++ ) { + test(); SWITCH( speaker_node_data[ch].group ) { case SPEAKER_NODE_ALL: @@ -411,21 +404,21 @@ ivas_error vbap_init_data_fx( } } - 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 - ( s_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" ) ); } - is_success &= vbap->search_struct[0].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[0].triplets != NULL ); IF( speaker_nodes_group2_internal > 0 ) { vbap->num_search_structs = 2; move16(); - 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 - ( s_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" ) ); } - is_success &= vbap->search_struct[1].triplets != NULL; + is_success = s_and( is_success, vbap->search_struct[1].triplets != NULL ); } ELSE { @@ -441,29 +434,29 @@ ivas_error vbap_init_data_fx( { /* 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_fx( 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 ); + move16(); } 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_fx( 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 ); + move16(); vbap->search_struct[1].num_triplets = determine_virtual_surface_triplets_fx( 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 ); + move16(); } } /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ IF( is_success ) { - Word16 max_exp = 31; - move16(); - - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); - determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, &max_exp, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains_fx, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains_fx, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains_fx( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - determine_virtual_speaker_node_division_gains_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, &max_exp, 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_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, &max_exp, 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_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, &max_exp, 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_fx( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains_fx, 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_fx( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains_fx, 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_fx( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains_fx, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); } } @@ -730,6 +723,8 @@ ivas_error vbap_init_data( return IVAS_ERR_OK; } #endif + + /*-------------------------------------------------------------------------* * vbap_free_data() * @@ -843,33 +838,33 @@ void vbap_free_data( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void vbap_determine_gains_fx( - const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ - Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction */ - const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ - const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) */ - const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ + const VBAP_HANDLE hVBAPdata, /* i : prepared VBAP structure */ + Word32 *gains_fx, /* o : gain vector for loudspeakers for given direction Q29 */ + const Word16 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q0 */ + const Word16 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q0 */ + const Word16 use_object_mode /* i : select between object mode panning and spatial mode panning */ ) { /* This function formulates gains for the given angle. The triplet-selection has been pre-formulated. */ Word16 ch, ch2; Word16 triplet_ch; Word16 triplet_index; - Word16 panning_unit_vec_fx[3]; - Word32 gain_triplet_fx[3]; + Word16 panning_unit_vec_fx[3]; /* Q15 */ + Word32 gain_triplet_fx[3]; /* Q16 */ Word32 norm_value_fx; Word32 gain_ene_fx; - Word32 azi_norm; - Word32 ele_norm; - Word32 azi_temp_fx; - Word32 ele_temp_fx; + Word16 azi_norm; /* Q15 */ + Word16 ele_norm; /* Q15 */ + Word32 azi_temp_fx; /* Q22 */ + Word32 ele_temp_fx; /* Q22 */ Word16 num_speaker_nodes; Word16 bottom_virtual_speaker_node_index; Word16 top_virtual_speaker_node_index; Word16 back_virtual_speaker_node_index; VBAP_VS_TRIPLET *selected_triplet; - Word16 *bottom_virtual_speaker_node_division_gains_fx; - Word16 *top_virtual_speaker_node_division_gains_fx; - Word16 *back_virtual_speaker_node_division_gains_fx; + Word16 *bottom_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *top_virtual_speaker_node_division_gains_fx; /* Q16 */ + Word16 *back_virtual_speaker_node_division_gains_fx; /* Q16 */ push_wmops( "vbap_gains" ); @@ -895,13 +890,14 @@ void vbap_determine_gains_fx( back_virtual_speaker_node_division_gains_fx = hVBAPdata->back_virtual_speaker_node_division_gains_fx; } - panning_wrap_angles_fixed( L_shl( azi_deg, 22 ), L_shl( ele_deg, 22 ), &azi_temp_fx, &ele_temp_fx ); - azi_norm = L_shr( Mpy_32_32( azi_temp_fx, 5965232 ), 7 ); - ele_norm = L_shr( Mpy_32_32( ele_temp_fx, 5965232 ), 7 ); + panning_wrap_angles_fx( L_shl( azi_deg, Q22 ), L_shl( ele_deg, Q22 ), &azi_temp_fx, &ele_temp_fx ); + azi_norm = extract_l( L_shr( Mpy_32_32( azi_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + ele_norm = extract_l( L_shr( Mpy_32_32( ele_temp_fx, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ - panning_unit_vec_fx[0] = mult( getCosWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[1] = mult( getSineWord16R2( (Word16) azi_norm ), getCosWord16R2( (Word16) ele_norm ) ); - panning_unit_vec_fx[2] = getSineWord16R2( (Word16) ele_norm ); + panning_unit_vec_fx[0] = mult( getCosWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[1] = mult( getSineWord16R2( azi_norm ), getCosWord16R2( ele_norm ) ); /* Q15 */ + panning_unit_vec_fx[2] = getSineWord16R2( ele_norm ); /* Q15 */ + move16(); move16(); move16(); @@ -911,13 +907,11 @@ void vbap_determine_gains_fx( IF( EQ_16( hVBAPdata->num_search_structs, 2 ) && ele_deg > 0 ) { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[1] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[1].triplets[triplet_index]; } ELSE { triplet_index = determine_best_triplet_and_gains_fx( &( hVBAPdata->search_struct[0] ), panning_unit_vec_fx, azi_deg, gain_triplet_fx ); - move16(); selected_triplet = &hVBAPdata->search_struct[0].triplets[triplet_index]; } @@ -926,14 +920,14 @@ void vbap_determine_gains_fx( move32(); FOR( ch = 0; ch < 3; ch++ ) { - gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); // 2q -31 = 27 + gain_ene_fx = L_add( gain_ene_fx, Mpy_32_32( gain_triplet_fx[ch], gain_triplet_fx[ch] ) ); /* Q(2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31) */ } - norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); // q = 47 - hVBAPdata->search_struct[0].triplets->q_inverse_matrix = 18 + norm_value_fx = Isqrt( L_shr( gain_ene_fx, 1 ) ); /* Q(31 - (2 * VBAP_VS_TRIPLET.q_inverse_matrix - 31 - 1) / 2 ) = Q(47 - VBAP_VS_TRIPLET.q_inverse_matrix) */ FOR( ch = 0; ch < 3; ch++ ) { - gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); // Q16 + gain_triplet_fx[ch] = Mpy_32_32( gain_triplet_fx[ch], norm_value_fx ); /* 47 - VBAP_VS_TRIPLET.q_inverse_matrix + VBAP_VS_TRIPLET.q_inverse_matrix - 31 = Q16 */ move32(); /* Sanity check for rounding issues */ @@ -956,7 +950,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], bottom_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -964,7 +958,7 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], top_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } @@ -972,13 +966,13 @@ void vbap_determine_gains_fx( { FOR( ch2 = 0; ch2 < num_speaker_nodes; ch2++ ) { - gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), 12 ) ); // Q29 + gains_fx[ch2] = L_add( gains_fx[ch2], L_shl( Mpy_32_16_1( gain_triplet_fx[ch], back_virtual_speaker_node_division_gains_fx[ch2] ), Q12 ) ); /* Q16 + Q16 - Q15 + Q12 = Q29 */ move32(); } } ELSE { - gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], 13 ) ); // Q29 + gains_fx[triplet_ch] = L_add( gains_fx[triplet_ch], L_shl( gain_triplet_fx[ch], Q13 ) ); /* Q16 + Q13 = Q29 */ move32(); } } @@ -1126,11 +1120,12 @@ void vbap_determine_gains( * * 3-by-3 vector cross product *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void vbap_crossp_fx( - const Word32 *vec1_fx, /* i : input vector 1 */ - const Word32 *vec2_fx, /* i : input vector 2 */ - Word32 *crossProduct_fx /* o : cross product output */ + const Word32 *vec1_fx, /* i : input vector 1 Qx */ + const Word32 *vec2_fx, /* i : input vector 2 Qy */ + Word32 *crossProduct_fx /* o : cross product output Qx + Qy - 31 */ ) { @@ -1168,43 +1163,43 @@ static void vbap_crossp( #ifdef IVAS_FLOAT_FIXED /*! r: Status result if triplet is usable for panning. Allows early exit. */ static UWord8 vector_matrix_multiply_3x3_fx( - const Word16 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word16 *src_vector, /* i : input vector Q15 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix) */ Word16 q_matrix ) { - result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); // q = q_matrix - result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_16_1( matrix[0][0], src_vector[0] ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix) */ + result[0] = L_add( result[0], Mpy_32_16_1( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 ) ) ) // 327 = 0.01 in Q = 15 + IF( LT_32( result[0], Mpy_32_16_1( L_lshl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_16_1( matrix[0][1], src_vector[0] ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix) */ + result[1] = L_add( result[1], Mpy_32_16_1( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[1], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } - result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_16_1( matrix[0][2], src_vector[0] ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix) */ + result[2] = L_add( result[2], Mpy_32_16_1( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 ) ) ) + IF( LT_32( result[2], Mpy_32_16_1( L_shl( 1, q_matrix ), -327 /* -0.01 in Q15 */ ) ) ) { return 0; } @@ -1213,42 +1208,42 @@ static UWord8 vector_matrix_multiply_3x3_fx( } static UWord8 vector_matrix_multiply_3x3_32_fx( - const Word32 *src_vector, /* i : input vector */ - Word32 matrix[3][3], /* i : input matrix */ - Word32 *result, /* o : output vector */ + const Word32 *src_vector, /* i : input vector Q30 */ + Word32 matrix[3][3], /* i : input matrix Q(q_matrix) */ + Word32 *result, /* o : output vector Q(q_matrix - 1) */ Word16 q_matrix ) { - result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); // q = ( q_matrix + 30 ) - 31 - result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); - result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); + result[0] = Mpy_32_32( matrix[0][0], src_vector[0] ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[1][0], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[0] = L_add( result[0], Mpy_32_32( matrix[2][0], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[0], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); - result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); - result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); + result[1] = Mpy_32_32( matrix[0][1], src_vector[0] ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[1][1], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[1] = L_add( result[1], Mpy_32_32( matrix[2][1], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[1], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } - result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); - result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); - result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); + result[2] = Mpy_32_32( matrix[0][2], src_vector[0] ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[1][2], src_vector[1] ) ); /* Q(q_matrix - 1) */ + result[2] = L_add( result[2], Mpy_32_32( matrix[2][2], src_vector[2] ) ); /* Q(q_matrix - 1) */ move32(); move32(); move32(); - IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 ) ) ) // 21474836 = 0.01 in Q = 31 + IF( LT_32( result[2], Mpy_32_32( L_shl( 1, ( sub( q_matrix, 1 ) ) ), -21474836 /* -0.01 in Q31 */ ) ) ) { return 0; } @@ -1292,8 +1287,8 @@ static uint8_t vector_matrix_multiply_3x3( return 1; } - #endif + /*----------------------------------------------------------------------------------------------* * determine_best_triplet_and_gains() * @@ -1301,14 +1296,12 @@ static uint8_t vector_matrix_multiply_3x3( *----------------------------------------------------------------------------------------------*/ /*! r: triplet id */ - - #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 Q15 */ + const Word16 azi_deg, /* i : panning azimuth */ + Word32 gains_fx[3] /* o : panning gains Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ ) { Word16 i, tr, k; @@ -1334,13 +1327,23 @@ static Word16 determine_best_triplet_and_gains_fx( * the chosen four sectors. */ IF( GT_16( abs_s( azi_deg ), 90 ) ) { - sector = azi_deg < 0 ? 2 : 1; + sector = 1; move16(); + if ( azi_deg < 0 ) + { + sector = 2; + move16(); + } } ELSE { - sector = azi_deg < 0 ? 3 : 0; + sector = 0; move16(); + if ( azi_deg < 0 ) + { + sector = 3; + move16(); + } } first_triplet = search_struct->initial_search_indices[sector]; move16(); @@ -1355,7 +1358,6 @@ static Word16 determine_best_triplet_and_gains_fx( 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 ) ) { @@ -1365,7 +1367,7 @@ static Word16 determine_best_triplet_and_gains_fx( move16(); FOR( k = 0; k < 3; k++ ) { - gains_fx[k] = unnormalized_gains_fx[k]; + gains_fx[k] = unnormalized_gains_fx[k]; /* Q(VBAP_VS_TRIPLET.q_inverse_matrix) */ move32(); } IF( best_min_gain_fx >= 0 ) @@ -1472,21 +1474,22 @@ static int16_t determine_best_triplet_and_gains( return best_triplet; } #endif + /*-------------------------------------------------------------------------* * determine_virtual_speaker_node_division_gains() * * Determines how the virtual node gains are distributed to real nodes *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static void determine_virtual_speaker_node_division_gains_fx( - const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ - Word16 *virtual_node_division_gains_fx, - Word16 *max_exp, - Word16 connections[][2], /* i : vector of all connections */ - const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ - const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ + const Word16 virtual_speaker_node_index, /* i : virtual speaker node index */ + Word16 *virtual_node_division_gains_fx, /* o : virtual speaker node division gains Q16 */ + Word16 connections[][2], /* i : vector of all connections */ + const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_speaker_nodes, /* i : max number of speaker nodes */ + const Word16 use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ ) { /* When node type is VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, the gains of the virtual node @@ -1536,7 +1539,7 @@ static void determine_virtual_speaker_node_division_gains_fx( Word16 guard_bits = find_guarded_bits_fx( num_speaker_nodes ); FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { - sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); // Q10 + sum_val_fx = add( sum_val_fx, shr( virtual_node_division_gains_fx[ch], guard_bits ) ); } Word16 final_exp = 0, res_exp; Word32 tmp_1, tmp_2, tmp_3; @@ -1545,7 +1548,7 @@ static void determine_virtual_speaker_node_division_gains_fx( { IF( virtual_node_division_gains_fx[ch] != 0 ) { - BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); // Q15 + BASOP_Util_Divide_MantExp( virtual_node_division_gains_fx[ch], 1, sum_val_fx, add( guard_bits, 1 ), &virtual_node_division_gains_fx[ch], &final_exp ); } ELSE { @@ -1565,9 +1568,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } ELSE { - Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); // q is 15-final_exp// ldep -> 31-final_exp (q) + Word32 tmp32 = L_deposit_h( virtual_node_division_gains_fx[ch] ); tmp_1 = L_add( BASOP_Util_Log2( tmp32 ), L_shl( ( sub( 31, sub( 31, final_exp ) ) ), 25 ) ); // Q25 - tmp_2 = Mpy_32_32( 26843546 /*0.8f in Q25*/, tmp_1 ); + tmp_2 = Mpy_32_32( 26843546 /* 0.8f in Q25 */, tmp_1 ); tmp_3 = BASOP_util_Pow2( tmp_2, Q31 - Q19, &res_exp ); exp_virtual_node_division_gains[ch] = res_exp; move16(); @@ -1577,10 +1580,9 @@ static void determine_virtual_speaker_node_division_gains_fx( } } /*make a common exp*/ - *max_exp = -1; /*Q16*/ FOR( i = 0; i < num_speaker_nodes; i++ ) { - virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( *max_exp, exp_virtual_node_division_gains[i] ) ); + virtual_node_division_gains_fx[i] = shr( virtual_node_division_gains_fx[i], sub( -1, exp_virtual_node_division_gains[i] ) ); /* Q16 */ move16(); } } @@ -1662,13 +1664,13 @@ static void determine_virtual_speaker_node_division_gains( #ifdef IVAS_FLOAT_FIXED static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( VBAP_HANDLE hVBAPdata, /* i/o: VBAP structure */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ enum SpeakerNodeGroup group /* i : group of speaker nodes where this belongs */ ) { Word16 ch; - Word32 max_elevation_fx = 0; + Word32 max_elevation_fx = 0; /* Q22 */ Word16 Flag1, Flag2, Flag3; move32(); @@ -1677,17 +1679,17 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( { Word16 virtual_back_needed = 1; move16(); - const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f Q15*/ + const Word16 virtual_back_epsilon_fx = -573; /* -0.0175f in Q15 */ move16(); FOR( ch = 0; ch < hVBAPdata->num_speaker_nodes; ch++ ) { Flag1 = BASOP_Util_Cmp_Mant32Exp( speaker_node_ele_deg_fx[ch], Q31 - Q22, 23040 /*45.0f Q9*/, Q31 - Q9 ); - IF( EQ_16( Flag1, (Word16) -1 ) ) + IF( EQ_16( Flag1, -1 ) ) { Word16 azi_temp; - azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); /* Q15 */ - Word16 cos_res = getCosWord16R2( azi_temp ); // Q15 + azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + Word16 cos_res = getCosWord16R2( azi_temp ); /* Q15 */ IF( LT_16( cos_res, virtual_back_epsilon_fx ) ) { @@ -1729,7 +1731,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( } } } - Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /*44.9990005 Q9*/, Q31 - Q9 ); + Flag2 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 23039 /* 44.9990005 in Q9 */, Q31 - Q9 ); IF( EQ_16( Flag2, 1 ) ) { return NO_VIRTUAL_SPEAKER_NODE; @@ -1749,7 +1751,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( hVBAPdata->num_speaker_nodes_internal = add( hVBAPdata->num_speaker_nodes_internal, 1 ); move16(); - Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /*19.9990005 Q10*/, Q31 - Q10 ); + Flag3 = BASOP_Util_Cmp_Mant32Exp( max_elevation_fx, Q31 - Q22, 20478 /* 19.9990005 in Q10 */, Q31 - Q10 ); IF( EQ_16( Flag3, 1 ) ) { @@ -1849,31 +1851,28 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( #ifdef IVAS_FLOAT_FIXED static void init_speaker_node_direction_data_fx( - VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ - const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths */ - const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations */ - const Word16 num_speaker_nodes /* i : number of speaker nodes */ + VBAP_SPEAKER_NODE *speaker_node_data, /* o : storage for speaker node data */ + const Word32 *speaker_node_azi_deg_fx, /* i : vector of speaker node azimuths Q22 */ + const Word32 *speaker_node_ele_deg_fx, /* i : vector of speaker node elevations Q22 */ + const Word16 num_speaker_nodes /* i : number of speaker nodes */ ) { Word16 ch; - - Word16 azi_rad_fx = 0; - Word16 ele_rad_fx = 0; - + Word16 azi_rad_fx; + Word16 ele_rad_fx; Word16 num_horiz = 0; UWord8 in_all_mode = TRUE; - move32(); - move32(); - move32(); move16(); + move16(); + FOR( ch = 0; ch < num_speaker_nodes; ch++ ) { speaker_node_data[ch].azi_deg_fx = speaker_node_azi_deg_fx[ch]; move32(); - azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ test(); - IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), 5 ) ) + IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], Q22 ), 5 ) ) { speaker_node_data[ch].ele_deg_fx = 0; move32(); @@ -1887,7 +1886,7 @@ static void init_speaker_node_direction_data_fx( { speaker_node_data[ch].ele_deg_fx = speaker_node_ele_deg_fx[ch]; move32(); - ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); + ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ IF( ele_rad_fx < 0 ) { @@ -1901,11 +1900,11 @@ static void init_speaker_node_direction_data_fx( } } - speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 (add one gaurd bit , buffer being used in Q30) + speaker_node_data[ch].unit_vec_fx[0] = L_shr( L_mult( getCosWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[1] = L_shr( L_mult( getSineWord16R2( azi_rad_fx ), getCosWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q15 + Q1 - Q1 = Q30 */ move32(); - speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); // Q30 + speaker_node_data[ch].unit_vec_fx[2] = L_shr( L_deposit_h( getSineWord16R2( ele_rad_fx ) ), 1 ); /* Q15 + Q16 - Q1 = Q30 */ move32(); } /* Check for largest horizontal gap if there are at least 3 horizontal speaker nodes */ @@ -1921,18 +1920,19 @@ static void init_speaker_node_direction_data_fx( move16(); FOR( ch = 0; ch < num_speaker_nodes && i < num_horiz; ch++ ) { + test(); IF( EQ_16( speaker_node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) ) { Word16 exp1; - Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], 31 - 22, 23040, 31 - 6, &exp1 ); + Word32 Mant2 = BASOP_Util_Add_Mant32Exp( speaker_node_azi_deg_fx[ch], Q31 - Q22, 23040 /* 360.0f in Q6 */, Q31 - Q6, &exp1 ); IF( L_shr( speaker_node_azi_deg_fx[ch], 22 ) < 0 ) { - horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); + horiz_azi[i] = (UWord16) L_shr( Mant2, sub( 31, exp1 ) ); /* Q0 */ } ELSE { - horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], 22 ); + horiz_azi[i] = (UWord16) L_shr( speaker_node_azi_deg_fx[ch], Q22 ); /* Q0 */ } i = add( i, 1 ); } @@ -1944,7 +1944,7 @@ static void init_speaker_node_direction_data_fx( /* Find largest gap. Initialize with the wrap over gap. */ largest_gap = add( sub( horiz_azi[0], horiz_azi[num_horiz - 1] ), 360 ); - FOR( ch = 0; ch < sub( num_horiz, 1 ); ch++ ) + FOR( ch = 0; ch < num_horiz - 1; ch++ ) { temp = sub( horiz_azi[ch + 1], horiz_azi[ch] ); if ( GT_16( temp, largest_gap ) ) @@ -2082,26 +2082,25 @@ static void init_speaker_node_direction_data( #ifdef IVAS_FLOAT_FIXED static void matrix_inverse_3x3_32_fx( - const Word32 **input_matrix_fx, /* i : input matrix */ - Word32 inverse_matrix_fx[3][3], /* o : output matrix */ + const Word32 **input_matrix_fx, /* i : input matrix Q30 */ + Word32 inverse_matrix_fx[3][3], /* o : output matrix Q(31 - exp_inv_mat) */ Word16 *exp_inv_mat ) { Word16 k; - Word32 determinant_fx; - Word32 cross_vec_fx[3]; + Word32 determinant_fx; /* Q28 */ + Word32 cross_vec_fx[3]; /* Q29 */ Word16 exp_inverse_matrix_fx[3][3]; vbap_crossp_fx( input_matrix_fx[1], input_matrix_fx[2], cross_vec_fx ); - determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); // Q30 + Q29 - Q31 = Q28 + determinant_fx = dotp_fixed( input_matrix_fx[0], cross_vec_fx, 3 ); Word16 inv_mat_exp = 0; move16(); FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][0] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][0] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][0] = inv_mat_exp; move16(); } @@ -2110,10 +2109,9 @@ static void matrix_inverse_3x3_32_fx( FOR( k = 0; k < 3; k++ ) { inverse_matrix_fx[k][1] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); - exp_inverse_matrix_fx[k][1] = inv_mat_exp; - move32(); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); + exp_inverse_matrix_fx[k][1] = inv_mat_exp; move16(); } @@ -2123,7 +2121,7 @@ static void matrix_inverse_3x3_32_fx( { inverse_matrix_fx[k][2] = L_deposit_h( BASOP_Util_Divide3232_Scale( cross_vec_fx[k], determinant_fx, &inv_mat_exp ) ); move32(); - inv_mat_exp = add( inv_mat_exp, ( ( 31 - 29 ) - ( 31 - 28 ) ) ); + inv_mat_exp = add( inv_mat_exp, ( ( Q31 - Q29 ) - ( Q31 - Q28 ) ) ); exp_inverse_matrix_fx[k][2] = inv_mat_exp; move16(); } @@ -2149,13 +2147,13 @@ static void matrix_inverse_3x3_32_fx( IF( LT_16( exp_inverse_matrix_fx[i][j], -15 ) && inverse_matrix_fx[i][j] != 0 ) { inverse_matrix_fx[i][j] = 1; - exp_inverse_matrix_fx[i][j] = 0; move32(); + exp_inverse_matrix_fx[i][j] = 0; move16(); } ELSE { - inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], *exp_inv_mat - exp_inverse_matrix_fx[i][j] ); + inverse_matrix_fx[i][j] = L_shr( inverse_matrix_fx[i][j], sub( *exp_inv_mat, exp_inverse_matrix_fx[i][j] ) ); /* Q(31 - *exp_inv_mat) */ move32(); } } @@ -2205,37 +2203,41 @@ static void matrix_inverse_3x3( * Check if the given loudspeaker triplet is a valid one and store data when * valid triplet is found. *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static Word16 check_and_store_triplet_fx( - const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ - const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ - const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ - VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ - Word16 *triplet_index, /* i/o: index for the next free triplet slot */ - Word32 *triplet_azidegs_fx, - Word16 *triplet_order /* o : initial order of triplet indices */ + const Word16 chA, /* i : first channel index that forms the loudspeaker triplet */ + const Word16 chB, /* i : second channel index that forms the loudspeaker triplet */ + const Word16 chC, /* i : third channel index that forms the loudspeaker triplet */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data structure */ + VBAP_VS_TRIPLET *triplets, /* o : vector of virtual surface triplets */ + Word16 *triplet_index, /* i/o: index for the next free triplet slot */ + Word32 *triplet_azidegs_fx, /* o : center azimuths of the found triplets Q19 */ + Word16 *triplet_order /* o : initial order of triplet indices */ ) { Word16 ch_check; Word16 k; Word16 speaker_node_found_inside_triplet; UWord8 triplet_ok; + Word16 exp_inv_mat; - Word32 inverse_matrix_fx[3][3], unnormalized_gains_fx[3]; + Word32 inverse_matrix_fx[3][3] /* Q(31 - exp_inv_mat) */, unnormalized_gains_fx[3] /* Q(31 - exp_inv_mat - 1) */; set32_fx( unnormalized_gains_fx, 0, 3 ); - const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; + const Word32 *speaker_node_triplet_unit_vec_matrix_fx[3]; /* Q30 */ /* Triplet found, determine inverse matrix for VBAP formulation */ speaker_node_triplet_unit_vec_matrix_fx[0] = speaker_node_data[chA].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[1] = speaker_node_data[chB].unit_vec_fx; + move32(); speaker_node_triplet_unit_vec_matrix_fx[2] = speaker_node_data[chC].unit_vec_fx; - Word16 exp_inv_mat = 31; - move16(); + move32(); matrix_inverse_3x3_32_fx( speaker_node_triplet_unit_vec_matrix_fx, inverse_matrix_fx, &exp_inv_mat ); triplets[*triplet_index].q_inverse_matrix = sub( 31, exp_inv_mat ); + move16(); /* 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. @@ -2248,7 +2250,7 @@ static Word16 check_and_store_triplet_fx( test(); IF( ( NE_16( ch_check, chA ) ) && NE_16( ch_check, chB ) && NE_16( ch_check, chC ) ) { - triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( 31, exp_inv_mat ) ); + triplet_ok = vector_matrix_multiply_3x3_32_fx( speaker_node_data[ch_check].unit_vec_fx, inverse_matrix_fx, unnormalized_gains_fx, sub( Q31, exp_inv_mat ) ); test(); test(); test(); @@ -2275,16 +2277,16 @@ static Word16 check_and_store_triplet_fx( Copy32( inverse_matrix_fx[k], triplets[*triplet_index].inverse_matrix_fx[k], 3 ); } /* 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 + 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] ), Q2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], Q2 ) ); /* Q28 */ /*Condition to make tmp_a 0 to adress precision loss seen*/ - if ( EQ_32( tmp_a, -8193 ) ) + if ( EQ_32( tmp_a, -8193 /* -0.0000305 in Q28 */ ) ) { tmp_a = 0; move32(); } - 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 - Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); - triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); // Q3 + 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 */ + Word16 tmp_tan = shr( BASOP_util_atan2( tmp_a, tmp_b, 0 ), Q13 - Q9 ); /* Q9 */ + triplet_azidegs_fx[*triplet_index] = L_mult( tmp_tan, 29335 /*_180_OVER_PI in Q9*/ ); /* Q19 */ move32(); /* Store increasing order indices for the later sorting step. */ triplet_order[*triplet_index] = *triplet_index; @@ -2300,7 +2302,6 @@ static Word16 check_and_store_triplet_fx( return 0; } #else - static int16_t check_and_store_triplet( const int16_t chA, /* i : first channel index that forms the loudspeaker triplet */ const int16_t chB, /* i : second channel index that forms the loudspeaker triplet */ @@ -2399,7 +2400,7 @@ static Word16 determine_virtual_surface_triplets_fx( Word16 num_connected_to_chA; Word16 connected_to_chA[VBAP_MAX_NUM_SPEAKER_NODES]; Word16 connection_uses_left[VBAP_MAX_NUM_SPEAKER_NODES]; - Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; + Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS]; /* Q19 */ Word16 triplet_order[VBAP_MAX_NUM_TRIPLETS]; /* Each connection can be used exactly by two different virtual surface triplets. */ @@ -2441,12 +2442,24 @@ static Word16 determine_virtual_surface_triplets_fx( { Word16 connect_index_k = connected_to_chA[k]; move16(); - chB = EQ_16( connections[connect_index_k][0], chA ) ? connections[connect_index_k][1] : connections[connect_index_k][0]; + chB = connections[connect_index_k][0]; + move16(); + if ( EQ_16( connections[connect_index_k][0], chA ) ) + { + chB = connections[connect_index_k][1]; + move16(); + } FOR( l = k + 1; l < num_connected_to_chA; l++ ) { Word16 connect_index_l = connected_to_chA[l]; move16(); - chC = EQ_16( connections[connect_index_l][0], chA ) ? connections[connect_index_l][1] : connections[connect_index_l][0]; + chC = connections[connect_index_l][0]; + move16(); + if ( EQ_16( connections[connect_index_l][0], chA ) ) + { + chC = connections[connect_index_l][1]; + move16(); + } /* 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++ ) @@ -2485,7 +2498,7 @@ static Word16 determine_virtual_surface_triplets_fx( * each search sector for this search struct. */ v_sort_ind_fixed( triplet_azidegs_fx, triplet_order, num_triplets ); reorder_triplets_fx( triplets, triplet_order, num_triplets ); - determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx /*Q19*/, initial_search_indices ); + determine_initial_search_indices_fx( num_triplets, triplet_azidegs_fx, initial_search_indices ); return num_triplets; } @@ -2593,18 +2606,18 @@ static int16_t determine_virtual_surface_triplets( #ifdef IVAS_FLOAT_FIXED static void determine_initial_search_indices_fx( - const Word16 num_triplets, /* i : number of triplets */ - const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], - Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ + const Word16 num_triplets, /* i : number of triplets */ + const Word32 triplet_azidegs_fx[VBAP_MAX_NUM_TRIPLETS], /* i : azimuths of triplets (in degrees) Q19 */ + Word16 initial_search_indices[VBAP_NUM_SEARCH_SECTORS] /* o : initial search indices */ ) { Word16 i, j; - Word32 sector_reference_azideg_fx; - Word32 sector_border_start_azideg_fx; - Word32 sector_border_end_azideg_fx; + Word32 sector_reference_azideg_fx; /* Q0 */ + Word32 sector_border_start_azideg_fx; /* Q0 */ + Word32 sector_border_end_azideg_fx; /* Q0 */ Word16 best_index; Word32 min_azideg_diff_fx; - Word32 azideg_diff_fx; + Word32 azideg_diff_fx; /* Q19 */ FOR( i = 0; i < VBAP_NUM_SEARCH_SECTORS; i++ ) { @@ -2622,13 +2635,13 @@ static void determine_initial_search_indices_fx( { azideg_diff_fx = L_sub( L_shl( sector_reference_azideg_fx, Q19 ), triplet_azidegs_fx[j] ); - IF( GT_32( azideg_diff_fx, 94371840 ) ) + IF( GT_32( azideg_diff_fx, 94371840 /* 180.0f in Q19 */ ) ) { - azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_sub( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } - ELSE IF( LT_32( azideg_diff_fx, -94371840 ) ) + ELSE IF( LT_32( azideg_diff_fx, -94371840 /* -180.0f in Q19 */ ) ) { - azideg_diff_fx = L_add( azideg_diff_fx, 188743680 ); + azideg_diff_fx = L_add( azideg_diff_fx, 188743680 /* 360.0f in Q19 */ ); } azideg_diff_fx = L_abs( azideg_diff_fx ); @@ -2718,7 +2731,7 @@ static ivas_error determine_connections_fx( Word16 c; Word16 connection_write_index = 0; move16(); - Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; + Word32 non_crossing_plane_elevation_deg_fx[VBAP_MAX_PLANES]; /* Q14 */ ivas_error error; @@ -2844,15 +2857,15 @@ static enum ConnectionClass determine_connection_class_fx( Word16 ch, k; const Word32 *p1_fx, *v2_fx; - Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; - Word32 determinant_fx; + Word32 v1v1_fx, v1v2_fx, v2v2_fx, v1p1_fx, v2p1_fx; /* Q25, Q27, Q29, Q27, Q29 */ + Word32 determinant_fx; /* Q23 */ Word32 norm_distance_on_v1_fx; Word32 vec_diff_fx[3]; - Word32 v1_fx[3]; + Word32 v1_fx[3]; /* Q28 */ Word32 vTarget_fx[3]; Word32 energy_sum_fx; Word32 eq_value_fx; - Word32 uvecdot_fx; + Word32 uvecdot_fx; /* Q30 */ /* Check if connection passes through origin. This is not desired. * When this happens, unit vectors point in opposite directions. */ @@ -2885,9 +2898,10 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { - v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); // q28 (Add two guard bit) + v1_fx[k] = L_sub( L_shr( node_data[chB].unit_vec_fx[k], 2 ), L_shr( node_data[chA].unit_vec_fx[k], 2 ) ); /* Q28 (Add two guard bit) */ + move32(); } - v2_fx = node_data[ch].unit_vec_fx; // q30 + v2_fx = node_data[ch].unit_vec_fx; // Q30 move32(); v1v1_fx = dotp_fixed( v1_fx, v1_fx, 3 ); // Q25 @@ -2939,13 +2953,13 @@ static enum ConnectionClass determine_connection_class_fx( FOR( k = 0; k < 3; k++ ) { var1 = Mpy_32_32( norm_distance_on_v1_fx, v1_fx[k] ); // Q(25 - exp) + Q28 - 31 - vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, Q31 - ( Q25 - exp + Q28 - Q31 ), &exp_vTarget ); + vTarget_fx[k] = BASOP_Util_Add_Mant32Exp( p1_fx[k], 1, var1, sub( Q31, add( sub( Q25, exp ), Q28 - Q31 ) ), &exp_vTarget ); move16(); vTarget_fx_e[k] = exp_vTarget; move16(); var2 = Mpy_32_32( vTarget_fx[k], vTarget_fx[k] ); // 2*exp_vTarget - energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, 2 * exp_vTarget, &exp_energy_sum ); + energy_sum_fx = BASOP_Util_Add_Mant32Exp( energy_sum_fx, exp_energy_sum, var2, shl( exp_vTarget, 1 ), &exp_energy_sum ); vec_diff_fx[k] = BASOP_Util_Add_Mant32Exp( vTarget_fx[k], exp_vTarget, L_negate( v2_fx[k] ), 1, &exp_vec_diff ); move16(); vec_diff_e[k] = exp_vec_diff; @@ -2990,7 +3004,7 @@ static enum ConnectionClass determine_connection_class_fx( Word32 res = dotp_fixed( vTarget_fx, v2_fx, 3 ); // 31 - (max_vTarget_e + 2) + 30 - 31 = 28 - max_vTarget_e move32(); - IF( GT_32( res, L_shr( 2147054208, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) + IF( GT_32( res, L_shr( 2147054208 /* 0.9998f in Q31 */, sub( 31, sub( 28, max_vTarget_e ) ) ) ) ) { return CONNECTION_WITH_SPEAKER_NODE_BEHIND; } @@ -3001,10 +3015,10 @@ static enum ConnectionClass determine_connection_class_fx( Word32 vec_diff_dotp = dotp_fixed( vec_diff_fx, vec_diff_fx, 3 ); // exp : 2 * max_vec_diff_e + 4 move32(); Word32 var = Mpy_32_32( vec_diff_dotp, 51200 /*25.0f in Q11*/ ); // exp : 2 * max_vec_diff_e + 4 + 20 - Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, 2 * max_vec_diff_e + 4 + 20 ); + Word16 Flag1 = BASOP_Util_Cmp_Mant32Exp( v1v1_fx, Q31 - Q25, var, add( shl( max_vec_diff_e, 1 ), 4 + 20 ) ); IF( EQ_16( Flag1, 1 ) ) { - IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 2147483 ) ) + IF( LT_32( L_abs( L_sub( node_data[chB].unit_vec_fx[2], node_data[chA].unit_vec_fx[2] ) ), 1073742 /* 0.001f in Q30 */ ) ) { return ELEVATED_PLANE_THIN_TRIANGLE_CONNECTION; } @@ -3240,10 +3254,10 @@ static void formulate_horizontal_connections( /*! r: truth value for crossing */ #ifdef IVAS_FLOAT_FIXED static Word16 check_plane_crossing_fx( - const Word32 ele1_deg_fx, /* i : speaker node 1 elevation */ - const Word32 ele2_deg_fx, /* i : speaker node 2 elevation */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations*/ + const Word32 ele1_deg_fx, /* i : speaker node 1 elevation Q22 */ + const Word32 ele2_deg_fx, /* i : speaker node 2 elevation Q22 */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector non-crossing plane elevations Q14 */ ) { /* Find if the connection crosses a non-crossing plane, with 1-degree threshold. */ @@ -3300,13 +3314,13 @@ static int16_t check_plane_crossing( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error get_half_sphere_connection_options_fx( - const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ - const enum SpeakerNodeGroup group, /* i : speaker node group */ - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations */ - ConnectionOption **connection_options_pr, /* o : list of connection options */ - Word16 *num_connection_options /* o : number of connection options */ + const VBAP_SPEAKER_NODE *speaker_node_data, /* i : speaker node data */ + const enum SpeakerNodeGroup group, /* i : speaker node group */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx, /* i : vector of non-crossing plane elevations Q14 */ + ConnectionOption **connection_options_pr, /* o : list of connection options */ + Word16 *num_connection_options /* o : number of connection options */ ) { Word16 max_num_connection_options = 0; @@ -3380,8 +3394,8 @@ static ivas_error get_half_sphere_connection_options_fx( Word16 exp_uv = Q31 - Q27; move16(); one_minus_unit_vec_dotp_sq_root = Sqrt32( one_minus_unit_vec_dotp_sq, &exp_uv ); - acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, exp_uv - 2 ); // Q13 - c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 + acos_val = BASOP_util_atan2( one_minus_unit_vec_dotp_sq_root, unit_vec_dotp, sub( exp_uv, 2 ) ); // Q13 + c_options[index].arc_fx = L_deposit_h( acos_val ); // Q29 move32(); c_options[index].arc_weighted_fx = c_options[index].arc_fx; // Q29 move32(); @@ -3397,7 +3411,7 @@ static ivas_error get_half_sphere_connection_options_fx( /* If the connection passes a pre-determined plane of speaker nodes, then add further penalty */ - IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx /*q22*/, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) + IF( check_plane_crossing_fx( speaker_node_data[chA].ele_deg_fx, speaker_node_data[chB].ele_deg_fx, num_non_crossing_planes, non_crossing_plane_elevation_deg_fx ) ) { c_options[index].arc_weighted_fx = L_shl( c_options[index].arc_weighted_fx, 1 ); move32(); @@ -3595,9 +3609,9 @@ static ivas_error formulate_half_sphere_connections_fx( const enum SpeakerNodeGroup group, /* i : speaker node group */ Word16 connections[][2], /* o : vector of connections */ Word16 *connection_write_index, - const Word16 max_num_connections, /* i : max number of connections */ - const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ - const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations */ + const Word16 max_num_connections, /* i : max number of connections */ + const Word16 num_non_crossing_planes, /* i : number of non-crossing planes */ + const Word32 *non_crossing_plane_elevation_deg_fx /* i : vector of non-crossing plane elevations Q14*/ ) { /* Variable initializations */ @@ -3607,11 +3621,11 @@ static ivas_error formulate_half_sphere_connections_fx( Word32 new_cross_fx[3]; Word32 planeCrossingVec_fx[3]; Word16 Q_planeCrossingVec; - Word32 new_arc_fx; - Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; - Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; + Word32 new_arc_fx; /* Q29 */ + Word32 connection_arc_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3]; /* Q29 */ + Word32 connection_cross_fx[( VBAP_MAX_NUM_SPEAKER_NODES - 2 ) * 3][3]; /* Q29 */ Word32 tmpFloat_fx; - Word32 cmp_arc_fx; + Word32 cmp_arc_fx; /* Q29 */ Word32 normVal_fx; Word16 angleCmp_fx; ConnectionOption *connection_options; @@ -3648,6 +3662,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); WHILE( c_opt < num_connection_options && *connection_write_index < max_num_connections ) { + test(); chA = connection_options[c_opt].chA; move16(); chB = connection_options[c_opt].chB; @@ -3747,10 +3762,10 @@ static ivas_error formulate_half_sphere_connections_fx( sub_exp = 0, sub_exp_2 = 0, sub_final_exp = 0; var_a = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); var_b = BASOP_Util_Add_Mant32Exp( 25735, Q31 - Q12, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp_2 ); var_c = BASOP_Util_Add_Mant32Exp( new_arc_fx, Q31 - Q29, L_negate( var_b ), sub_exp_2, &sub_final_exp ); - comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836, 0 ); + comp2 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_c ), sub_final_exp, 21474836 /* 0.01f in Q31 */, 0 ); within_first_arc = 0; move16(); @@ -3771,7 +3786,7 @@ static ivas_error formulate_half_sphere_connections_fx( move32(); } /*update Q for planeCrossingVec */ - Q_planeCrossingVec = sub( sub( add( Q27, Q27 ), tmp_exp ), Q31 ); + Q_planeCrossingVec = sub( sub( Q27 + Q27, tmp_exp ), Q31 ); } /* Study if the crossing is also between arc cmp_chA-cmp_chB */ @@ -3803,13 +3818,13 @@ static ivas_error formulate_half_sphere_connections_fx( } one_minus_var1_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var1_sq ), exp_var1_sq, &final_exp_A ); var1_sqrt = Sqrt32( one_minus_var1_sq, &final_exp_A ); - var1_cos = BASOP_util_atan2( var1_sqrt, var1, final_exp_A - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var1_cos = BASOP_util_atan2( var1_sqrt, var1, sub( final_exp_A, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 angleCmp_fx = var1_cos; move16(); one_minus_var2_sq = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( var2_sq ), exp_var2_sq, &final_exp_B ); var2_sqrt = Sqrt32( one_minus_var2_sq, &final_exp_B ); - var2_cos = BASOP_util_atan2( var2_sqrt, var2, final_exp_B - ( Q31 - ( Q_planeCrossingVec + Q30 - Q31 ) ) ); // Q13 + var2_cos = BASOP_util_atan2( var2_sqrt, var2, sub( final_exp_B, sub( Q31, add( Q_planeCrossingVec, Q30 - Q31 ) ) ) ); // Q13 final_exp = BASOP_Util_Add_MantExp( angleCmp_fx, Q15 - Q13, var2_cos, Q15 - Q13, &angleCmp_fx ); @@ -3818,7 +3833,7 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); move16(); var_a = BASOP_Util_Add_Mant32Exp( cmp_arc_fx, Q31 - Q29, L_negate( L_deposit_h( angleCmp_fx ) ), final_exp, &sub_exp ); - comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836, 0 ); + comp1 = BASOP_Util_Cmp_Mant32Exp( L_abs( var_a ), sub_exp, 21474836 /* 0.01f in Q31 */, 0 ); if ( EQ_16( comp1, -1 ) ) { @@ -3839,13 +3854,13 @@ static ivas_error formulate_half_sphere_connections_fx( move16(); connections[*connection_write_index][1] = chB; move16(); - connection_arc_fx[*connection_write_index] = new_arc_fx; // Q29 + connection_arc_fx[*connection_write_index] = new_arc_fx; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; + connection_cross_fx[*connection_write_index][0] = new_cross_fx[0]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; + connection_cross_fx[*connection_write_index][1] = new_cross_fx[1]; /* Q29 */ move16(); - connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; + connection_cross_fx[*connection_write_index][2] = new_cross_fx[2]; /* Q29 */ move16(); *connection_write_index = add( *connection_write_index, 1 ); } @@ -4013,15 +4028,15 @@ static ivas_error formulate_half_sphere_connections( #ifdef IVAS_FLOAT_FIXED static Word16 determine_non_crossing_planes_fx( - const Word16 num_speaker_nodes, /* i : number of speaker nodes */ - const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ - Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations */ + const Word16 num_speaker_nodes, /* i : number of speaker nodes */ + const VBAP_SPEAKER_NODE *node_data, /* i : speaker node data */ + Word32 *non_crossing_plane_elevation_deg_fx /* o : vector of non-crossing plane elevations Q14 */ ) { - Word32 next_ele_check_fx; - Word32 ele_check_fx; - Word32 max_gap_fx; - Word32 gap_to_next_ls_fx; + Word32 next_ele_check_fx; /* Q14 */ + Word32 ele_check_fx; /* Q14 */ + Word32 max_gap_fx; /* Q14 */ + Word32 gap_to_next_ls_fx; /* Q14 */ Word16 ch, ch_cmp; Word16 num_planes; @@ -4046,7 +4061,7 @@ static Word16 determine_non_crossing_planes_fx( tmp2 = L_sub( next_ele_check_fx, 16 /*VBAP_EPSILON in Q14*/ ); test(); test(); - IF( ( node_data[ch].group != SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) + IF( NE_32( node_data[ch].group, SPEAKER_NODE_HORIZONTAL ) && GT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp1 ) && LT_32( L_shr( node_data[ch].ele_deg_fx, 8 ), tmp2 ) ) { next_ele_check_fx = L_shr( node_data[ch].ele_deg_fx, 8 ); // shift due to comparision with 90.0f } @@ -4098,7 +4113,7 @@ static Word16 determine_non_crossing_planes_fx( test(); IF( LT_32( max_gap_fx, 2293776 /*Q14*/ ) && max_gap_fx > 0 ) { - non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; // q14 + non_crossing_plane_elevation_deg_fx[num_planes] = ele_check_fx; /* Q14 */ move32(); num_planes = add( num_planes, 1 ); IF( EQ_16( num_planes, VBAP_MAX_PLANES ) ) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a178953ba..90ac02ce1 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -133,7 +133,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float gain; /* Linear, not in dB */ #else - Word32 gain_fx; /* Linear, not in dB */ + Word32 gain_fx; /* Linear, not in dB Q30 */ #endif rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ @@ -164,7 +164,7 @@ typedef struct rotation_matrix_fx rot_mat_prev_fx; #endif pan_vector prev_pan_gains; - int8_t firstFrameRendered; + Word8 firstFrameRendered; #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif @@ -174,10 +174,10 @@ typedef struct float nonDiegeticPanGain; #endif #ifdef IVAS_FLOAT_FIXED - Word32 nonDiegeticPanGain_fx; + Word32 nonDiegeticPanGain_fx; /* Q31 */ #endif OMASA_ANA_HANDLE hOMasa; - uint16_t total_num_objects; + UWord16 total_num_objects; #ifdef IVAS_FLOAT_FIXED Word32 ism_metadata_delay_ms_fx; /* Q0 */ #else @@ -210,13 +210,13 @@ typedef struct Word16 numLfeChannels; bool pan_lfe; // float lfeInputGain; - Word32 lfeInputGain_fx; + Word32 lfeInputGain_fx; /* Q31 */ // float lfeOutputAzimuth; Word16 lfeOutputAzimuth_fx; // float lfeOutputElevation; Word16 lfeOutputElevation_fx; // IVAS_REND_LfePanMtx lfePanMtx; - IVAS_REND_LfePanMtx_fx lfePanMtx_fx; + IVAS_REND_LfePanMtx_fx lfePanMtx_fx; /* Q31 */ } lfe_routing; #else typedef struct @@ -236,16 +236,22 @@ typedef struct /* Full panning matrix. 1st index is input channel, 2nd index is output channel. All LFE channels should be included, both for inputs and outputs */ +#ifndef IVAS_FLOAT_FIXED pan_matrix panGains; - pan_matrix_fx panGains_fx; +#else + pan_matrix_fx panGains_fx; /* Q31 */ +#endif LSSETUP_CUSTOM_STRUCT customLsInput; EFAP_WRAPPER efapInWrapper; TDREND_WRAPPER tdRendWrapper; CREND_WRAPPER_HANDLE crendWrapper; REVERB_HANDLE hReverb; +#ifndef IVAS_FLOAT_FIXED rotation_gains rot_gains_prev; +#else rotation_gains_Word32 rot_gains_prev_fx; +#endif Word16 nonDiegeticPan; Word32 nonDiegeticPanGain_fx; lfe_routing lfeRouting; @@ -253,7 +259,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float *bufferData; #endif - int16_t binauralDelaySmp; + Word16 binauralDelaySmp; #ifndef IVAS_FLOAT_FIXED float nonDiegeticPanGain; float *lfeDelayBuffer; @@ -292,12 +298,13 @@ typedef struct // pan_matrix hoaDecMtx; pan_matrix_fx hoaDecMtx_fx; CREND_WRAPPER_HANDLE crendWrapper; - rotation_gains rot_gains_prev; - rotation_gains_fx rot_gains_prev_fx; #ifndef IVAS_FLOAT_FIXED + rotation_gains rot_gains_prev; float *bufferData; -#endif +#else + rotation_gains_fx rot_gains_prev_fx; Word32 *bufferData_fx; +#endif DIRAC_ANA_HANDLE hDirAC; } input_sba; #else @@ -397,7 +404,7 @@ static void intermidiate_ext_dirac_render( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static ivas_error allocateInputBaseBufferData_fx( - Word32 **data, + Word32 **data, /* Qx */ const Word16 data_size ) { *data = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -424,7 +431,7 @@ static ivas_error allocateInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static void freeInputBaseBufferData_fx( - Word32 **data ) + Word32 **data /* Qx */ ) { IF( *data != NULL ) { @@ -449,7 +456,7 @@ static void freeInputBaseBufferData( #endif #ifdef IVAS_FLOAT_FIXED static ivas_error allocateMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer, + Word32 **lfeDelayBuffer, /* Qx */ const Word16 data_size ) { *lfeDelayBuffer = (Word32 *) malloc( data_size * sizeof( Word32 ) ); @@ -477,7 +484,7 @@ static ivas_error allocateMcLfeDelayBuffer( #endif #ifdef IVAS_FLOAT_FIXED static void freeMcLfeDelayBuffer_fx( - Word32 **lfeDelayBuffer ) + Word32 **lfeDelayBuffer /* Qx */ ) { IF( *lfeDelayBuffer != NULL ) { @@ -521,11 +528,6 @@ static IVAS_QUATERNION quaternionInit_fx( move16(); move16(); -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - q.w = 1.0f; - q.x = q.y = q.z = 0.0f; -#endif - return q; } #else @@ -651,7 +653,7 @@ static void accumulate2dArrayToBuffer( /*! r: number of clipped output samples */ static Word32 limitRendererOutput_fx( IVAS_LIMITER_HANDLE hLimiter, /* i/o: limiter struct handle */ - Word32 *output, /* i/o: I/O buffer */ + Word32 *output, /* i/o: I/O buffer Q(q_factor) */ const Word16 output_frame, /* i : number of samples per channel in the buffer */ const Word32 threshold, /* i : signal amplitude above which limiting starts to be applied */ Word16 q_factor ) /* i : q factor of output samples */ @@ -1208,7 +1210,7 @@ static LSSETUP_CUSTOM_STRUCT defaultCustomLs( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerAzimuths_fx( AUDIO_CONFIG config, - const Word32 **azimuths ) + const Word32 **azimuths /* Q22 */ ) { SWITCH( config ) { @@ -1279,7 +1281,7 @@ static ivas_error getSpeakerAzimuths( #ifdef IVAS_FLOAT_FIXED static ivas_error getSpeakerElevations_fx( AUDIO_CONFIG config, - const Word32 **elevations ) + const Word32 **elevations /* Q22 */ ) { SWITCH( config ) { @@ -1514,8 +1516,8 @@ static ivas_error getNumNonLfeChannelsInSpeakerLayout( static ivas_error getMcConfigValues_fx( AUDIO_CONFIG inConfig, const LSSETUP_CUSTOM_STRUCT *pInCustomLs, - const Word32 **azimuth, - const Word32 **elevation, + const Word32 **azimuth, /* Q22 */ + const Word32 **elevation, /* Q22 */ Word16 *lfe_idx, Word16 *is_planar ) { @@ -1666,8 +1668,8 @@ static ivas_error initEfap( const LSSETUP_CUSTOM_STRUCT *pCustomLsOut ) { ivas_error error; - const Word32 *azimuths; - const Word32 *elevations; + const Word32 *azimuths; /* Q22 */ + const Word32 *elevations; /* Q22 */ Word16 numNonLfeChannels; test(); @@ -1798,11 +1800,11 @@ static ivas_error initEfap( #ifdef IVAS_FLOAT_FIXED static ivas_error getEfapGains_fx( EFAP_WRAPPER efapWrapper, - const Word32 azi, - const Word32 ele, - pan_vector_fx panGains ) + const Word32 azi, /* Q22 */ + const Word32 ele, /* Q22 */ + pan_vector_fx panGains /* Q31 */ ) { - pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ + pan_vector_fx tmpPanGains; /* tmp pan gain buffer without LFE channels */ /* Q30 */ Word32 *readPtr; Word16 i; Word16 lfeCount; @@ -1826,7 +1828,7 @@ static ivas_error getEfapGains_fx( { panGains[i] = 0; move32(); - ++lfeCount; + lfeCount = add( lfeCount, 1 ); } ELSE { @@ -1947,7 +1949,7 @@ static ivas_error initHeadRotation_fx( IVAS_REND_HANDLE hIvasRend ) { Word16 i, crossfade_len; - Word32 tmp_fx; + Word32 tmp_fx; /* Q31 */ ivas_error error; /* Head rotation is enabled by default */ @@ -2117,7 +2119,7 @@ static void initRotGainsWord32_fx( return; } -#endif +#else static void initRotGains( rotation_gains rot_gains ) { @@ -2132,6 +2134,7 @@ static void initRotGains( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void initRendInputBase_fx( input_base *inputBase, @@ -2232,6 +2235,7 @@ static IVAS_ISM_METADATA defaultObjectPosition( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED static int8_t checkObjectPositionChanged( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2239,8 +2243,7 @@ static int8_t checkObjectPositionChanged( return !( fabs( currentPos->azimuth - previousPos->azimuth ) < EPSILON && fabs( currentPos->elevation - previousPos->elevation ) < EPSILON ); } - -#ifdef IVAS_FLOAT_FIXED +#else static Word8 checkObjectPositionChanged_fx( IVAS_ISM_METADATA *currentPos, IVAS_ISM_METADATA *previousPos ) @@ -2409,6 +2412,7 @@ static ivas_error setRendInputActiveIsm( initRendInputBase_fx( &inputIsm->base, inConfig, id, rendCtx, inputIsm->bufferData_fx, MAX_BUFFER_LENGTH ); inputIsm->firstFrameRendered = FALSE; + move16(); inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); @@ -2662,7 +2666,7 @@ static void copyLsConversionMatrixToPanMatrix_fx( } ELSE { - panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); + panMatrix[inCh][outCh] = L_shl( lsConvMatrix[i].value, 1 ); /* Q30 + Q1 = Q31 */ } move32(); } @@ -2670,7 +2674,6 @@ static void copyLsConversionMatrixToPanMatrix_fx( return; } #else - static void copyLsConversionMatrixToPanMatrix( const LS_CONVERSION_MATRIX *lsConvMatrix, pan_matrix panMatrix ) @@ -2695,6 +2698,8 @@ static void copyLsConversionMatrixToPanMatrix( return; } #endif + +#ifndef IVAS_FLOAT_FIXED static void setZeroPanMatrix( pan_matrix panMatrix ) { @@ -2707,7 +2712,7 @@ static void setZeroPanMatrix( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void setZeroPanMatrix_fx( pan_matrix_fx panMatrix ) { @@ -2721,6 +2726,7 @@ static void setZeroPanMatrix_fx( return; } #endif + #ifdef IVAS_FLOAT_FIXED /* Note: this only sets non-zero elements, call setZeroPanMatrix() to init first. */ static void fillIdentityPanMatrix_fx( @@ -2850,7 +2856,7 @@ static ivas_error initMcPanGainsWithEfap_fx( Word16 i; Word16 numNonLfeInChannels; Word16 inLfeChIdx, outChIdx; - const Word32 *spkAzi, *spkEle; + const Word32 *spkAzi, *spkEle; /* Q22 */ ivas_error error; IF( NE_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -2895,14 +2901,14 @@ static ivas_error initMcPanGainsWithEfap_fx( { IF( EQ_16( i, inLfeChIdx ) ) { - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } IF( NE_32( ( error = getEfapGains_fx( *inputMc->base.ctx.pEfapOutWrapper, spkAzi[i], spkEle[i], inputMc->panGains_fx[outChIdx] ) ), IVAS_ERR_OK ) ) { return error; } - ++outChIdx; + outChIdx = add( outChIdx, 1 ); } test(); @@ -3085,6 +3091,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( /* ls_conversion_cicpX_stereo contains gains for side speakers. * These should be skipped with 5.1+X inputs. */ skipSideSpeakers = false; + move16(); test(); if ( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) ) { @@ -3121,7 +3128,7 @@ static ivas_error initMcPanGainsWithMonoOut_fx( inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_mono_fx[readIdx][0], 1 ); // Q31 } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } } @@ -3198,9 +3205,9 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( * Use gains for center CICP speaker and return early. */ IF( EQ_32( inputMc->base.inConfig, IVAS_AUDIO_CONFIG_MONO ) ) { - inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); // Q31 + inputMc->panGains_fx[0][0] = L_shl( ls_conversion_cicpX_stereo_fx[2][0], 1 ); /* Q30 + Q1 = Q31 */ move32(); - inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); // Q31 + inputMc->panGains_fx[0][1] = L_shl( ls_conversion_cicpX_stereo_fx[2][1], 1 ); /* Q30 + Q1 = Q31 */ move32(); return IVAS_ERR_OK; } @@ -3237,7 +3244,7 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); + inputMc->panGains_fx[writeIdx][0] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][0], 1 ); /* Q30 + Q1 = Q31 */ } move32(); @@ -3247,10 +3254,10 @@ static ivas_error initMcPanGainsWithStereoLookup_fx( } ELSE { - inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); + inputMc->panGains_fx[writeIdx][1] = L_shl( ls_conversion_cicpX_stereo_fx[readIdx][1], 1 ); /* Q30 + Q1 = Q31 */ } move32(); - ++readIdx; + readIdx = add( readIdx, 1 ); } return IVAS_ERR_OK; @@ -3449,7 +3456,7 @@ static ivas_error updateLfePanGainsForMcOut( } /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], numOutChannels ); /* Q31 */ } return error; @@ -3528,7 +3535,7 @@ static ivas_error updateLfePanGainsForAmbiOut( ivas_dirac_dec_get_response_fx( inputMc->lfeRouting.lfeOutputAzimuth_fx, inputMc->lfeRouting.lfeOutputElevation_fx, inputMc->lfeRouting.lfePanMtx_fx[i], outAmbiOrder, Q29 ); /* linear input gain */ - v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); + v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); /* Q31 */ } return error; @@ -3606,7 +3613,7 @@ static ivas_error updateMcPanGainsForMcOut( } ELSE { - inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); + inputMc->panGains_fx[0][0] = L_add( L_shr( inputMc->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 /* 0.5f in Q31 */ ); /* Q31 */ } move32(); inputMc->panGains_fx[0][1] = L_sub( ONE_IN_Q31, inputMc->panGains_fx[0][0] ); @@ -3713,7 +3720,7 @@ static ivas_error updateMcPanGainsForAmbiOut( { Word16 ch_in, ch_out, lfeIdx, i; Word16 numNonLfeInChannels, outAmbiOrder; - const Word32 *spkAzi_fx, *spkEle_fx; + const Word32 *spkAzi_fx, *spkEle_fx; /* Q22 */ ivas_error error; IF( NE_32( ( error = getAmbisonicsOrder_fx( outConfig, &outAmbiOrder ) ), IVAS_ERR_OK ) ) @@ -3768,11 +3775,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } ELSE @@ -3816,11 +3823,11 @@ static ivas_error updateMcPanGainsForAmbiOut( } ELSE { - inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); + inputMc->panGains_fx[ch_out][i] = L_shl( temp, 2 ); /* Q29 + Q2 = Q31 */ move32(); } } - ++ch_in; + ch_in = add( ch_in, 1 ); } } @@ -4053,11 +4060,13 @@ static ivas_error initMcBinauralRendering( IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { useTDRend = TRUE; + move16(); } 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; + move16(); } } @@ -4177,8 +4186,8 @@ static ivas_error initMcBinauralRendering( Word16 exp = 0; move16(); 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 ) ), negate( exp ) ); // 31 + exp - inputMc->binauralDelaySmp = (Word16) var2; + Word32 var2 = L_shr_r( Mpy_32_32( binauralDelayNs, L_deposit_h( var1 ) ), negate( exp ) ); /* Q0 */ + inputMc->binauralDelaySmp = extract_l( var2 ); move16(); // inputMc->binauralDelaySmp = (int16_t) roundf( (float) binauralDelayNs * *inputMc->base.ctx.pOutSampleRate / 1000000000.f ); @@ -4406,6 +4415,7 @@ static lfe_routing defaultLfeRouting( case IVAS_AUDIO_CONFIG_LS_CUSTOM: FOR( i = 0; i < routing.numLfeChannels && i < customLsOut.num_lfe; ++i ) { + test(); routing.lfePanMtx_fx[i][customLsOut.lfe_idx[i]] = ONE_IN_Q31; move32(); } @@ -4507,7 +4517,6 @@ static ivas_error setRendInputActiveMc( } initRendInputBase_fx( &inputMc->base, inConfig, id, rendCtx, inputMc->bufferData_fx, MAX_BUFFER_LENGTH ); - setZeroPanMatrix( inputMc->panGains ); setZeroPanMatrix_fx( inputMc->panGains_fx ); inputMc->customLsInput = defaultCustomLs(); @@ -4516,7 +4525,6 @@ static ivas_error setRendInputActiveMc( inputMc->hReverb = NULL; inputMc->hMcMasa = NULL; - initRotGains( inputMc->rot_gains_prev ); initRotGainsWord32_fx( inputMc->rot_gains_prev_fx ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); set32_fx( inputMc->lfeDelayBuffer_fx, 0, MAX_BIN_DELAY_SAMPLES ); @@ -4747,7 +4755,7 @@ static ivas_error initSbaPanGainsForMcOut( { CONTINUE; /* nothing to be rendered to LFE */ } - inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, 2 ); + inputSba->hoaDecMtx_fx[chInIdx][chOutIdx] = L_shl_sat( *readPtr++, Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -4876,7 +4884,6 @@ static ivas_error updateSbaPanGains( rendering_context rendCtx; /* Reset to all zeros - some functions below only write non-zero elements. */ - // setZeroPanMatrix( inputSba->hoaDecMtx ); setZeroPanMatrix_fx( inputSba->hoaDecMtx_fx ); inConfig = inputSba->base.inConfig; @@ -5269,7 +5276,7 @@ static ivas_error setRendInputActiveMasa( } initRendInputBase_fx( &inputMasa->base, inConfig, id, rendCtx, inputMasa->bufferData_fx, MAX_BUFFER_LENGTH ); - IF( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &numInChannels ) ), IVAS_ERR_OK ) ) { return error; } @@ -5288,7 +5295,7 @@ static ivas_error setRendInputActiveMasa( temp = 2; } move16(); - IF( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = masaPrerendOpen_fx( &inputMasa->hMasaPrerend, temp, *( inputMasa->base.ctx.pOutSampleRate ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -5358,7 +5365,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; @@ -5635,11 +5642,6 @@ static LSSETUP_CUSTOM_STRUCT makeCustomLsSetup( /* Copy layout description */ customLs.num_spk = rendCustomLsLayout.num_spk; move16(); - FOR( i = 0; i < rendCustomLsLayout.num_spk; i++ ) - { - customLs.ls_azimuth_fx[i] = (Word32) ( rendCustomLsLayout.azimuth[i] * ONE_IN_Q22 ); - customLs.ls_elevation_fx[i] = (Word32) ( rendCustomLsLayout.elevation[i] * ONE_IN_Q22 ); - } Copy32( rendCustomLsLayout.azimuth_fx, customLs.ls_azimuth_fx, rendCustomLsLayout.num_spk ); Copy32( rendCustomLsLayout.elevation_fx, customLs.ls_elevation_fx, rendCustomLsLayout.num_spk ); customLs.is_planar_setup = 1; @@ -6696,9 +6698,9 @@ ivas_error IVAS_REND_SetInputGain( } #else ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ) { input_base *inputBase; @@ -6823,11 +6825,11 @@ ivas_error IVAS_REND_SetInputLfeMtx_fx( *-------------------------------------------------------------------*/ ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ ) { input_base *pInputBase; @@ -6854,11 +6856,11 @@ ivas_error IVAS_REND_SetInputLfePos_fx( pInputMc->lfeRouting.pan_lfe = true; move16(); - pInputMc->lfeRouting.lfeInputGain_fx = inputGain; // Q31 + pInputMc->lfeRouting.lfeInputGain_fx = inputGain; /* Q31 */ move32(); - pInputMc->lfeRouting.lfeOutputAzimuth_fx = (Word16) ( outputAzimuth ); // Q0 + pInputMc->lfeRouting.lfeOutputAzimuth_fx = outputAzimuth; /* Q0 */ move16(); - pInputMc->lfeRouting.lfeOutputElevation_fx = (Word16) ( outputElevation ); // Q0 + pInputMc->lfeRouting.lfeOutputElevation_fx = outputElevation; /* Q0 */ move16(); IF( NE_32( ( error = updateMcPanGains( pInputMc, hIvasRend->outputConfig ) ), IVAS_ERR_OK ) ) @@ -7160,6 +7162,13 @@ ivas_error IVAS_REND_GetDelay_fx( Word32 max_latency_ns; Word32 timescale_by_ns[7] = { 0, 17180, 34360, 0, 68719, 0, 103079 }; + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); + move32(); /* Validate function arguments */ test(); @@ -7242,6 +7251,7 @@ ivas_error IVAS_REND_GetDelay_fx( IF( NE_32( hIvasRend->inputsMasa[i].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) { latency_ns = (Word32) ( IVAS_FB_DEC_DELAY_NS ); + move32(); max_latency_ns = L_max( max_latency_ns, latency_ns ); } } @@ -7508,7 +7518,9 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( /* Set position to OMasa struct */ hIvasRend->inputsIsm->hOMasa->ism_azimuth_fx[inputIndex] = objectPosition.azimuth_fx; + move32(); hIvasRend->inputsIsm->hOMasa->ism_elevation_fx[inputIndex] = objectPosition.elevation_fx; + move32(); return IVAS_ERR_OK; } @@ -7933,25 +7945,25 @@ ivas_error IVAS_REND_SetHeadRotation( rotQuat = headRot; } - Word32 updateRate_fx = 1677721600; // value is 200 in Q23 - rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); - rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); + Word32 updateRate_fx = 1677721600; // value is 200 in Q23 + rotQuat.w_fx = L_shl( rotQuat.w_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.x_fx = L_shl( rotQuat.x_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.y_fx = L_shl( rotQuat.y_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ + rotQuat.z_fx = L_shl( rotQuat.z_fx, sub( Q29, rotQuat.q_fact ) ); /* Q29 */ move32(); move32(); move32(); move32(); - hIvasRend->headRotData.hOrientationTracker->refRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( 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.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->refRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->refRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->refRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.w_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.x_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.y_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ + hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx = L_shl( hIvasRend->headRotData.hOrientationTracker->absAvgRot.z_fx, sub( Q29, hIvasRend->headRotData.hOrientationTracker->absAvgRot.q_fact ) ); /* Q29 */ move32(); move32(); @@ -8504,8 +8516,8 @@ static void renderBufferChannelLerp( static void renderBufferChannelLerp_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const gainsCurrent, - const Word32 *const gainsPrev, + const Word32 *const gainsCurrent, /* Q31 */ + const Word32 *const gainsPrev, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { const Word32 *inSmpl; @@ -8515,8 +8527,8 @@ static void renderBufferChannelLerp_fx( Word32 i; const Word32 *lastInSmpl; Word16 outChnlIdx; - Word32 currentGain; - Word32 previousGain; + Word32 currentGain; /* Q31 */ + Word32 previousGain; /* Q31 */ /* Pointer to behind last input sample */ lastInSmpl = getSmplPtr_fx( inAudio, inChannelIdx, inAudio.config.numSamplesPerChannel ); @@ -8524,9 +8536,17 @@ static void renderBufferChannelLerp_fx( FOR( outChnlIdx = 0; outChnlIdx < outAudio.config.numChannels; ++outChnlIdx ) { currentGain = gainsCurrent[outChnlIdx]; - previousGain = gainsPrev == NULL ? 0 : gainsPrev[outChnlIdx]; - move32(); move32(); + if ( gainsPrev == NULL ) + { + previousGain = 0; + move32(); + } + else + { + previousGain = gainsPrev[outChnlIdx]; + move32(); + } /* Process current output channel only if applying non-zero gains */ test(); @@ -8621,7 +8641,7 @@ static void renderBufferChannelLerp_fx( static void renderBufferChannel_fx( const IVAS_REND_AudioBuffer inAudio, const Word32 inChannelIdx, - const Word32 *const outputGains, + const Word32 *const outputGains, /* Q31 */ IVAS_REND_AudioBuffer outAudio ) { renderBufferChannelLerp_fx( inAudio, inChannelIdx, outputGains, NULL, outAudio ); @@ -8656,7 +8676,7 @@ static ivas_error chooseCrossfade( #else static ivas_error chooseCrossfade_fx( const IVAS_REND_HeadRotData *headRotData, - const Word32 **pCrossfade ) + const Word32 **pCrossfade /* Q31 */ ) { *pCrossfade = headRotData->crossfade_fx; @@ -8679,10 +8699,10 @@ static ivas_error rotateFrameMc_fx( { Word16 i; Word16 j; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; - Word32 azimuth_fx, elevation_fx; + Word32 azimuth_fx, elevation_fx; /* Q22 */ Word16 is_planar_setup, lfe_idx; Word16 nchan; Word16 ch_in, ch_out; @@ -8691,10 +8711,10 @@ static ivas_error rotateFrameMc_fx( const Word32 *ls_azimuth, *ls_elevation; rotation_matrix_fx Rmat_fx; rotation_gains_Word32 gains; - Word32 tmp_gains[MAX_INPUT_CHANNELS]; + Word32 tmp_gains[MAX_INPUT_CHANNELS]; /* Q30 */ ivas_error error; push_wmops( "rotateFrameMc_fx" ); - IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) // Q31 + IF( NE_32( ( error = chooseCrossfade_fx( headRotData, &crossfade ) ), IVAS_ERR_OK ) ) { return error; } @@ -8770,10 +8790,8 @@ static ivas_error rotateFrameMc_fx( } /* input channel index without LFE */ - ch_in_woLFE = ( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) ? sub( ch_in, 1 ) : ch_in; - test(); - IF( ( GT_16( lfe_idx, 0 ) ) && ( GE_16( ch_in, lfe_idx ) ) ) + IF( ( lfe_idx > 0 ) && ( GE_16( ch_in, lfe_idx ) ) ) { ch_in_woLFE = sub( ch_in, 1 ); } @@ -8824,14 +8842,14 @@ static ivas_error rotateFrameMc_fx( { FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { - writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); - readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); + writePtr = getSmplPtr_fx( outAudio, ch_out, imult1616( subframe_idx, subframe_len ) ); /* Qx */ + readPtr = getSmplPtr_fx( inAudio, ch_in, imult1616( subframe_idx, subframe_len ) ); /* Qx */ /* crossfade with previous rotation gains */ FOR( i = 0; i < subframe_len; i++ ) { *writePtr = - L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( ( ONE_IN_Q31 - crossfade[i] ), gains_prev[ch_in][ch_out] ) ), - Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); // Qinp -1 + L_add( *writePtr, L_add( Mpy_32_32( ( *readPtr ), Mpy_32_32( L_sub( ONE_IN_Q31, crossfade[i] ), gains_prev[ch_in][ch_out] ) ), + Mpy_32_32( ( *readPtr ), Mpy_32_32( crossfade[i], gains[ch_in][ch_out] ) ) ) ); /* Qx - 1 */ move32(); readPtr++; writePtr++; @@ -8997,28 +9015,28 @@ static ivas_error rotateFrameMc( #ifdef IVAS_FLOAT_FIXED static ivas_error rotateFrameSba_fx( - IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ - const AUDIO_CONFIG inConfig, /* i : Input Audio config */ - const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ + IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ + const AUDIO_CONFIG inConfig, /* i : Input Audio config */ + const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ - Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains */ - IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ + Word16 gains_prev[MAX_INPUT_CHANNELS][MAX_INPUT_CHANNELS], /* i/o: Previous frame rotation gains Q14 */ + IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ ) { Word16 i, l, n, m; Word16 m1, m2; Word16 shd_rot_max_order; - const Word32 *crossfade; + const Word32 *crossfade; /* Q31 */ Word16 num_subframes; Word16 subframe_idx, subframe_len; Word32 *writePtr; Word32 tmpRot[2 * HEADROT_ORDER + 1]; - Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; + Word16 gains[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; /* Q14 */ Word32 temp; - Word32 Rmat[3][3]; + Word32 Rmat[3][3]; /* Q30 */ ivas_error error; Word16 idx, exp; - Word32 cf, oneminuscf; + Word32 cf, oneminuscf; /* Q31 */ Word32 val; push_wmops( "rotateFrameSba" ); @@ -9052,7 +9070,7 @@ static ivas_error rotateFrameSba_fx( { FOR( l = 0; l < 3; l++ ) { - Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; // Q30 + Rmat[i][l] = ( *hCombinedOrientationData )->Rmat_fx[subframe_idx][i][l]; /* Q30 */ move32(); } } @@ -9091,14 +9109,14 @@ static ivas_error rotateFrameSba_fx( /* compute mtx-vector product for this l */ FOR( n = m1; n < m2; n++ ) { - tmpRot[sub( n, m1 )] = 0; + tmpRot[n - m1] = 0; move32(); FOR( m = m1; m < m2; m++ ) { - val = inAudio.data_fx[add( imult1616( m, inAudio.config.numSamplesPerChannel ), idx )]; + val = inAudio.data_fx[m * inAudio.config.numSamplesPerChannel + idx]; /* crossfade with previous rotation gains */ temp = Mpy_32_32( L_add( Mpy_32_16_r( cf, gains[n][m] ), ( Mpy_32_16_r( oneminuscf, gains_prev[n][m] ) ) ), val ); - tmpRot[sub( n, m1 )] = L_add( L_shl( temp, 1 ), tmpRot[sub( n, m1 )] ); // Qexp + tmpRot[n - m1] = L_add( L_shl( temp, 1 ), tmpRot[n - m1] ); move32(); move32(); } @@ -9107,19 +9125,19 @@ static ivas_error rotateFrameSba_fx( FOR( n = m1; n < m2; n++ ) { writePtr = getSmplPtr_fx( outAudio, n, idx ); - ( *writePtr ) = tmpRot[sub( n, m1 )]; + ( *writePtr ) = tmpRot[n - m1]; move32(); } m1 = m2; move16(); - m2 = add( m2, 2 * ( l + 1 ) + 1 ); + m2 = add( m2, add( shl( add( l, 1 ), 1 ), 1 ) ); } } /* move SHrotmat to SHrotmat_prev */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) { - Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); // Q14 + Copy( gains[i], gains_prev[i], HEADROT_SHMAT_DIM ); } } pop_wmops(); @@ -9261,7 +9279,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( 11, exp ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( 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, @@ -9273,7 +9291,7 @@ static ivas_error renderIsmToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpTDRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9282,7 +9300,7 @@ static ivas_error renderIsmToBinaural( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], 2 ); + tmpTDRendBuffer[i][j] = L_shl( tmpTDRendBuffer[i][j], Q2 ); /* Q(exp + 2) */ move32(); } } @@ -9333,9 +9351,9 @@ static Word16 getNumSubframesInBuffer( const IVAS_REND_AudioBuffer *buffer, const Word32 sampleRate ) { - Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 ) ); // Q0 + Q31 - Q31 -> Q0 + Word16 scale, temp = extract_l( Mpy_32_32( sampleRate, 10737418 /* 1 / FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); temp = BASOP_Util_Divide1616_Scale( buffer->config.numSamplesPerChannel, temp, &scale ); - temp = shr( temp, sub( 15, scale ) ); + temp = shr( temp, sub( 15, scale ) ); /* Q0 */ return temp; } #else @@ -9358,7 +9376,7 @@ static ivas_error renderIsmToBinauralRoom( { Word16 position_changed; Word16 i, j; - Word32 azi_rot, ele_rot; + Word32 azi_rot, ele_rot; /* Q22 */ Word16 subframe_idx; Word16 tmp; rotation_matrix_fx Rmat; @@ -9389,7 +9407,6 @@ static ivas_error renderIsmToBinauralRoom( { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) { - IF( ( *hCombinedOrientationData )->enableCombinedOrientation[subframe_idx] != 0 ) { combinedOrientationEnabled = 1; @@ -9459,7 +9476,9 @@ static ivas_error renderIsmToBinauralRoom( move32(); } + test(); position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &rotatedPos, &rotatedPosPrev ); + move16(); /* set previous gains if this is the first frame */ IF( NE_32( ( error = getEfapGains_fx( *ismInput->base.ctx.pEfapOutWrapper, rotatedPosPrev.azimuth_fx, rotatedPosPrev.elevation_fx, ismInput->prev_pan_gains_fx ) ), IVAS_ERR_OK ) ) @@ -9493,11 +9512,20 @@ static ivas_error renderIsmToBinauralRoom( tmpMcBuffer.data_fx = malloc( imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) * sizeof( Word32 ) ); set_zero_fx( tmpMcBuffer.data_fx, imult1616( tmpMcBuffer.config.numSamplesPerChannel, tmpMcBuffer.config.numChannels ) ); - - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - tmpMcBuffer ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains, + ismInput->prev_pan_gains_fx, + tmpMcBuffer ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + tmpMcBuffer ); + } copyBufferTo2dArray_fx( tmpMcBuffer, tmpRendBuffer ); @@ -9512,11 +9540,8 @@ static ivas_error renderIsmToBinauralRoom( Copy32( currentPanGains, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); } // Crend_process porting - move16(); CREND_HANDLE hCrend; hCrend = ismInput->crendWrapper->hCrend; - move16(); - move16(); IF( hCrend->reflections != NULL ) { test(); @@ -9524,7 +9549,7 @@ static ivas_error renderIsmToBinauralRoom( { FOR( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], 9 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], Q9 ); move32(); } } @@ -9735,7 +9760,7 @@ static ivas_error renderIsmToBinauralReverb( 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( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( 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, tmpRendBuffer_fx, &exp ) ), IVAS_ERR_OK ) ) @@ -9745,7 +9770,7 @@ static ivas_error renderIsmToBinauralReverb( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( 11, exp ) ) ); /* Q(exp) */ } IF( ismInput->hReverb != NULL ) @@ -9754,7 +9779,7 @@ static ivas_error renderIsmToBinauralReverb( { FOR( Word16 j = 0; j < outAudio.config.numSamplesPerChannel; j++ ) { - tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); + tmpRendBuffer_fx[i][j] = L_shl( tmpRendBuffer_fx[i][j], 2 ); /* Q(exp + 2) */ move16(); } } @@ -9799,26 +9824,31 @@ static ivas_error renderIsmToMc( const IVAS_REND_AudioBuffer outAudio ) { Word8 position_changed; - pan_vector_fx currentPanGains_fx; + pan_vector_fx currentPanGains_fx; /* Q31 */ ivas_error error; push_wmops( "renderIsmToMc" ); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->previousPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); ismInput->previousPos.elevation_fx = L_shl( L_shr( L_add( ismInput->previousPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); IF( EQ_32( *ismInput->base.ctx.pOutConfig, IVAS_AUDIO_CONFIG_STEREO ) ) { IF( ismInput->nonDiegeticPan ) { - currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); - currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); - ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; // Q31 - ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; // Q31 + currentPanGains_fx[0] = L_add( L_shr( ismInput->nonDiegeticPanGain_fx, 1 ), ONE_IN_Q30 ); /* Q31 */ + currentPanGains_fx[1] = L_sub( ONE_IN_Q31, currentPanGains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[0] = currentPanGains_fx[0]; /* Q31 */ + ismInput->prev_pan_gains_fx[1] = currentPanGains_fx[1]; /* Q31 */ move32(); move32(); move32(); @@ -9835,8 +9865,8 @@ static ivas_error renderIsmToMc( elevation_tmp = extract_l( L_shr( ismInput->currentPos.elevation_fx, Q22 ) ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + currentPanGains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + currentPanGains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); @@ -9845,8 +9875,8 @@ static ivas_error renderIsmToMc( set32_fx( ismInput->prev_pan_gains_fx, 0, MAX_OUTPUT_CHANNELS ); ivas_ism_get_stereo_gains_fx( azimuth_tmp, elevation_tmp, &gains_fx[0], &gains_fx[1] ); - ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); // Q31 - ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); // Q31 + ismInput->prev_pan_gains_fx[0] = L_deposit_h( gains_fx[0] ); /* Q31 */ + ismInput->prev_pan_gains_fx[1] = L_deposit_h( gains_fx[1] ); /* Q31 */ move32(); move32(); } @@ -9885,10 +9915,20 @@ static ivas_error renderIsmToMc( /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { @@ -9989,6 +10029,7 @@ static ivas_error renderIsmToSba( pan_vector_fx currentPanGains_fx; ivas_error error; error = IVAS_ERR_OK; + move32(); ismInput->currentPos.azimuth_fx = L_shl( L_shr( L_add( ismInput->currentPos.azimuth_fx, ONE_IN_Q21 ), Q22 ), Q22 ); ismInput->currentPos.elevation_fx = L_shl( L_shr( L_add( ismInput->currentPos.elevation_fx, ONE_IN_Q21 ), Q22 ), Q22 ); @@ -10011,8 +10052,9 @@ static ivas_error renderIsmToSba( return error; } - position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged( &ismInput->currentPos, &ismInput->previousPos ); test(); + position_changed = !ismInput->firstFrameRendered || checkObjectPositionChanged_fx( &ismInput->currentPos, &ismInput->previousPos ); + move16(); /* set previous gains if this is the first frame */ Word16 azimuth_tmp, elevation_tmp; @@ -10028,7 +10070,7 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); + ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } @@ -10046,22 +10088,31 @@ static ivas_error renderIsmToSba( Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { - currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); + currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); /* Q29 + Q2 = Q31 */ move32(); } } /* Assume num channels in audio buffer to be 1. * This should have been validated in IVAS_REND_FeedInputAudio() */ - renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, - position_changed ? currentPanGains_fx : ismInput->prev_pan_gains_fx, - position_changed ? ismInput->prev_pan_gains_fx : NULL, - outAudio ); + IF( position_changed ) + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + currentPanGains_fx, + ismInput->prev_pan_gains_fx, + outAudio ); + } + ELSE + { + renderBufferChannelLerp_fx( ismInput->base.inputBuffer, 0, + ismInput->prev_pan_gains_fx, + NULL, + outAudio ); + } IF( position_changed ) { Copy32( currentPanGains_fx, ismInput->prev_pan_gains_fx, MAX_OUTPUT_CHANNELS ); - // mvr2r( currentPanGains, ismInput->prev_pan_gains, MAX_OUTPUT_CHANNELS ); } pop_wmops(); @@ -10158,16 +10209,18 @@ static void renderIsmToMasa( FOR( i = 1; i < MAX_NUM_OBJECTS; i++ ) { - IF( LT_16( max_e, input_e[0] ) ) - max_e = input_e[i]; - move16(); + if ( LT_16( max_e, input_e[0] ) ) + { + max_e = input_e[i]; + move16(); + } } FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { FOR( j = 0; j < L_FRAME48k; j++ ) { - tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); + tmpRendBuffer_fx[i][j] = L_shr( tmpRendBuffer_fx[i][j], add( sub( max_e, sub( 31, *outAudio.pq_fact ) ), guard_bits ) ); /* Q(31 - (max_e + guard_bits)) */ move32(); } } @@ -10232,10 +10285,10 @@ 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 ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); - exp = *outAudio.pq_fact; - move16(); + exp = *outAudio.pq_fact; move16(); + /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *ismInput->base.ctx.pCombinedOrientationData ); @@ -10283,11 +10336,11 @@ static ivas_error renderInputIsm( } ismInput->firstFrameRendered = TRUE; + move16(); *outAudio.pq_fact = exp; - - move16(); move16(); + return error; } #else @@ -10382,7 +10435,7 @@ static ivas_error renderActiveInputsIsm( } 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 ) ) ); /* Q(input_q - 1) */ move32(); } *outAudio.pq_fact = sub( input_q, 1 ); @@ -10434,7 +10487,7 @@ static ivas_error renderLfeToBinaural_fx( assert( ( outAudio.config.numChannels == 2 ) && "Must be binaural output" ); push_wmops( "renderLfeToBinaural" ); - gain_fx = GAIN_LFE_WORD32; + gain_fx = GAIN_LFE_WORD32; /* 1.88364911f in Q30 */ move32(); IF( NE_32( mcInput->base.inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -10455,7 +10508,6 @@ static ivas_error renderLfeToBinaural_fx( /* --- Prepare LFE signal to be added to binaural output --- */ lfeInput = getSmplPtr_fx( mcInput->base.inputBuffer, lfe_idx, 0 ); - move32(); frame_size = mcInput->base.inputBuffer.config.numSamplesPerChannel; move16(); num_cpy_smpl_prev_frame = mcInput->binauralDelaySmp; @@ -10466,10 +10518,10 @@ static ivas_error renderLfeToBinaural_fx( assert( mcInput->binauralDelaySmp < frame_size ); /* Get delayed LFE signal from previous frame, apply gain and save in tmp buffer */ - v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); // Qinp-1 + v_multc_fixed( mcInput->lfeDelayBuffer_fx, gain_fx, tmpLfeBuffer, num_cpy_smpl_prev_frame ); /* Qx - 1 */ /* Continue filling tmp buffer, now with LFE signal from current frame */ - v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); // Qinp-1 + v_multc_fixed( lfeInput, gain_fx, tmpLfeBuffer + num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); /* Qx - 1 */ /* Save remaining LFE samples of current frame for next frame */ MVR2R_WORD32( lfeInput + num_cpy_smpl_cur_frame, mcInput->lfeDelayBuffer_fx, num_cpy_smpl_prev_frame ); @@ -10479,8 +10531,7 @@ static ivas_error renderLfeToBinaural_fx( { FOR( i = 0; i < add( num_cpy_smpl_prev_frame, num_cpy_smpl_cur_frame ); i++ ) { - tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); // out_q - + tmpLfeBuffer[i] = L_shr( tmpLfeBuffer[i], r_shift ); /* Q(out_q) */ move32(); } } @@ -10489,7 +10540,7 @@ static ivas_error renderLfeToBinaural_fx( { writePtr = getSmplPtr_fx( outAudio, ear_idx, 0 ); move32(); - v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); // out_q + v_add_fixed( writePtr, tmpLfeBuffer, writePtr, frame_size, 0 ); /* Q(out_q) */ } pop_wmops(); @@ -10608,7 +10659,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( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( 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 ) ), @@ -10619,7 +10670,7 @@ static ivas_error renderMcToBinaural( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer_fx[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } } ELSE @@ -10791,9 +10842,8 @@ static ivas_error renderMcToBinauralRoom( inConfig = mcInput->base.inConfig; move32(); hCombinedOrientationData = mcInput->base.ctx.pCombinedOrientationData; - move32(); combinedOrientationEnabled = 0; - move32(); + move16(); IF( hCombinedOrientationData != NULL ) { FOR( subframe_idx = 0; subframe_idx < ( *hCombinedOrientationData )->num_subframes; subframe_idx++ ) @@ -10818,7 +10868,7 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, sub( Q11, exp ) ); /* Q11 */ } IF( NE_32( ( error = ivas_td_binaural_renderer_ext_fx( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pCombinedOrientationData, NULL, mcInput->hReverb, @@ -10830,9 +10880,8 @@ static ivas_error renderMcToBinauralRoom( FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) { - Scale_sig32( tmpRendBuffer[i], L_FRAME48k, -sub( Q11, exp ) ); + Scale_sig32( tmpRendBuffer[i], L_FRAME48k, negate( sub( Q11, exp ) ) ); /* Q(exp) */ } - //*outAudio.pq_fact = exp; } ELSE { @@ -11273,28 +11322,35 @@ static void renderMcToSba( } #endif +#ifdef IVAS_FLOAT_FIXED static void renderMcToMasa( input_mc *mcInput, IVAS_REND_AudioBuffer outAudio ) { -#ifdef IVAS_FLOAT_FIXED push_wmops( "renderMcToMasa" ); Word32 tmpRendBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray_fx( mcInput->base.inputBuffer, tmpRendBuffer_fx ); ivas_mcmasa_ana_fx( mcInput->hMcMasa, tmpRendBuffer_fx, *( outAudio.pq_fact ), mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer_fx( tmpRendBuffer_fx, &outAudio ); + pop_wmops(); + return; +} #else +static void renderMcToMasa( + input_mc *mcInput, + IVAS_REND_AudioBuffer outAudio ) +{ push_wmops( "renderMcToMasa" ); float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); ivas_mcmasa_ana( mcInput->hMcMasa, tmpRendBuffer, mcInput->base.inputBuffer.config.numSamplesPerChannel, outAudio.config.numChannels, mcInput->base.inputBuffer.config.numChannels ); accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); -#endif // IVAS_FLOAT_FIXED pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error renderInputMc( @@ -11317,6 +11373,7 @@ static ivas_error renderInputMc( move32(); v_multc_fixed( inAudio.data_fx, mcInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); *outAudio.pq_fact = sub( *outAudio.pq_fact, Q1 ); // reducing the Q by 1 compensating for the v_mult_fixed done + move16(); /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( mcInput->base.ctx.pCombinedOrientationData ) ); @@ -11595,7 +11652,7 @@ static ivas_error renderSbaToBinaural( tmpRotBuffer.data_fx = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_16( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, sbaInput->rot_gains_prev_fx, tmpRotBuffer ) ), @@ -11765,7 +11822,7 @@ static ivas_error renderSbaToBinauralRoom( tmpRotBuffer.data_fx = malloc( imult1616( tmpRotBuffer.config.numSamplesPerChannel, tmpRotBuffer.config.numChannels ) * sizeof( Word32 ) ); /* copy input for in-place rotation */ - MVR2R_WORD32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, tmpRotBuffer.config.numChannels * tmpRotBuffer.config.numSamplesPerChannel ); + Copy32( sbaInput->base.inputBuffer.data_fx, tmpRotBuffer.data_fx, i_mult( tmpRotBuffer.config.numChannels, tmpRotBuffer.config.numSamplesPerChannel ) ); IF( NE_32( ( error = rotateFrameSba_fx( sbaInput->base.inputBuffer, sbaInput->base.inConfig, sbaInput->base.ctx.pHeadRotData, sbaInput->base.ctx.pCombinedOrientationData, @@ -11788,7 +11845,7 @@ static ivas_error renderSbaToBinauralRoom( tmpMcBuffer.config.numChannels = tmp; move16(); tmpMcBuffer.data_fx = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( Word32 ) ); - set32_fx( tmpMcBuffer.data_fx, 0, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); + set32_fx( tmpMcBuffer.data_fx, 0, i_mult( tmpMcBuffer.config.numChannels, tmpMcBuffer.config.numSamplesPerChannel ) ); IF( combinedOrientationEnabled ) { @@ -11980,7 +12037,7 @@ static ivas_error renderInputSba( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, sbaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); @@ -12149,9 +12206,9 @@ static void copyMasaMetadataToDiracRenderer_fx( { FOR( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1] && bin < maxBin; bin++ ) { - hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->azimuth[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->elevation[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[0].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio1_fx[meta_write_index][bin] = meta->directional_meta[0].energy_ratio_fx[sf][band]; move32(); @@ -12164,9 +12221,9 @@ static void copyMasaMetadataToDiracRenderer_fx( IF( EQ_16( hSpatParamRendCom->numSimultaneousDirections, 2 ) ) { - hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->azimuth2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].azimuth_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); - hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); // Q22 -> Q0 + hSpatParamRendCom->elevation2[meta_write_index][bin] = extract_l( L_shr( meta->directional_meta[1].elevation_fx[sf][band], Q22 ) ); /* Q22 - Q22 = Q0 */ move16(); hSpatParamRendCom->energy_ratio2_fx[meta_write_index][bin] = meta->directional_meta[1].energy_ratio_fx[sf][band]; move32(); @@ -12179,7 +12236,7 @@ static void copyMasaMetadataToDiracRenderer_fx( } } - 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 = add( hSpatParamRendCom->dirac_bs_md_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; move16(); return; @@ -12236,7 +12293,7 @@ static void renderMasaToMasa( IVAS_REND_AudioBuffer outAudio ) { Word16 sf, band, dir, numDirs; - Word32 ratioSum_fx; + Word32 ratioSum_fx; /* Q30 */ MASA_DECODER_EXT_OUT_META_HANDLE outMeta; MASA_METADATA_FRAME *inMeta; Word32 tmpBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -12256,7 +12313,8 @@ static void renderMasaToMasa( move16(); move16(); /* Calculate energy */ - l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + // l_ts = masaInput->base.inputBuffer.config.numSamplesPerChannel / CLDFB_NO_COL_MAX; + l_ts = shr( masaInput->base.inputBuffer.config.numSamplesPerChannel, 4 ); numAnalysisChannels = masaInput->hMasaPrerend->num_Cldfb_instances; move16(); /* do processing over all CLDFB time slots */ @@ -12282,8 +12340,8 @@ static void renderMasaToMasa( cldfbAnalysis_ts_fx_fixed_q( &( tmpBuffer_fx[i][l_ts * ts] ), Chan_RealBuffer_fx[i], Chan_ImagBuffer_fx[i], l_ts, masaInput->hMasaPrerend->cldfbAnaEnc[i], &q_cldfb_out ); scale_factor = s_min( scale_factor, s_min( getScaleFactor32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ), getScaleFactor32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX ) ) ); scale_factor = sub( scale_factor, 1 ); - scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 - scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); // Q17 + scale_sig32( Chan_RealBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ + scale_sig32( Chan_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, scale_factor ); /* Q(q_cldfb_out + scale_factor) */ } Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); @@ -12298,8 +12356,8 @@ static void renderMasaToMasa( { FOR( i = 0; i < numAnalysisChannels; i++ ) { - Word32 temp = L_add( Mult_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mult_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); - masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, ( 2 * q_add ), &tmp_energy_e[block_m_idx][band_m_idx] ); + Word32 temp = L_add( Mpy_32_32( Chan_RealBuffer_fx[0][j], Chan_RealBuffer_fx[0][j] ), Mpy_32_32( Chan_ImagBuffer_fx[0][j], Chan_ImagBuffer_fx[0][j] ) ); /* 2 * Q(q_cldfb_out + scale_factor) - 31 */ + masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx] = BASOP_Util_Add_Mant32Exp( masaInput->hMasaPrerend->energy_fx[block_m_idx][band_m_idx], tmp_energy_e[block_m_idx][band_m_idx], temp, shl( q_add, 1 ), &tmp_energy_e[block_m_idx][band_m_idx] ); move32(); } } @@ -12312,7 +12370,6 @@ static void renderMasaToMasa( move16(); FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - max_e = s_max( max_e, tmp_energy_e[i][j] ); } masaInput->hMasaPrerend->energy_e[i] = max_e; @@ -12320,7 +12377,7 @@ static void renderMasaToMasa( FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); + masaInput->hMasaPrerend->energy_fx[i][j] = L_shr( masaInput->hMasaPrerend->energy_fx[i][j], sub( max_e, tmp_energy_e[i][j] ) ); /* Q(31 - max_e) */ move32(); } } @@ -12329,7 +12386,7 @@ static void renderMasaToMasa( test(); IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 1 ) && EQ_16( outAudio.config.numChannels, 2 ) ) { - MVR2R_WORD32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); + Copy32( tmpBuffer_fx[0], tmpBuffer_fx[1], masaInput->base.inputBuffer.config.numSamplesPerChannel ); } ELSE IF( EQ_16( masaInput->base.inputBuffer.config.numChannels, 2 ) && EQ_16( outAudio.config.numChannels, 1 ) ) { @@ -12378,14 +12435,16 @@ static void renderMasaToMasa( FOR( dir = 0; dir < numDirs; dir++ ) { tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } tmp_e = 0; move16(); tmp = 0; move32(); tmp = BASOP_Util_Divide3232_Scale_cadence( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); - inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); // Q30 + inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ + move32(); } } } @@ -12400,7 +12459,7 @@ static void renderMasaToMasa( { outMeta->directionIndex[dir][sf][band] = index_theta_phi_16_fx( &inMeta->directional_meta[dir].elevation_fx[sf][band], &inMeta->directional_meta[dir].azimuth_fx[sf][band], masaInput->hMasaPrerend->sph_grid16 ); outMeta->directToTotalRatio[dir][sf][band] = (UWord8) L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], Q22 ); - outMeta->diffuseToTotalRatio[sf][band] -= outMeta->directToTotalRatio[dir][sf][band]; + outMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( outMeta->diffuseToTotalRatio[sf][band], outMeta->directToTotalRatio[dir][sf][band] ); outMeta->spreadCoherence[dir][sf][band] = (UWord8) shr( inMeta->directional_meta[dir].spread_coherence_fx[sf][band], Q7 ); move16(); @@ -12575,11 +12634,11 @@ static ivas_error renderInputMasa( *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ - v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); + v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, i_mult( inAudio.config.numSamplesPerChannel, inAudio.config.numChannels ) ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. move16(); - maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); + maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); /* Q0 */ /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( masaInput->base.ctx.pCombinedOrientationData ) ); @@ -12600,7 +12659,7 @@ static ivas_error renderInputMasa( copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); - num_subframes = shr( num_subframes, sub( 15, exp ) ); + num_subframes = shr( num_subframes, sub( 15, exp ) ); /* Q0 */ SWITCH( masaInput->hMasaExtRend->renderer_type ) { @@ -12611,10 +12670,11 @@ static ivas_error renderInputMasa( 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; + move16(); } FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { - Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); @@ -12623,8 +12683,9 @@ static ivas_error renderInputMasa( 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->cldfbSynRend[ch]->Q_cldfb_state ) ); + scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); /* Q11 */ masaInput->hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; + move16(); } intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 0 ); @@ -12635,8 +12696,8 @@ static ivas_error renderInputMasa( copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); - Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); - Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ + Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); /* Q11 */ ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); *outAudio.pq_fact = Q11; @@ -13157,7 +13218,7 @@ static ivas_error getSamplesInternal( test(); IF( EQ_32( getAudioConfigType( hIvasRend->outputConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_BINAURAL ) && - NE_32( outAudio.config.numSamplesPerChannel * 1000, ( hIvasRend->num_subframes * BINAURAL_RENDERING_FRAME_SIZE_MS ) * hIvasRend->sampleRateOut ) ) + NE_32( L_mult0( outAudio.config.numSamplesPerChannel, 1000 ), imult3216( hIvasRend->sampleRateOut, i_mult( hIvasRend->num_subframes, BINAURAL_RENDERING_FRAME_SIZE_MS ) ) ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BUFFER_SIZE, "Binaural rendering requires specific frame size" ); } @@ -13581,13 +13642,13 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( hDirACRend->hOutSetup.ls_elevation_fx = inputMasa->base.ctx.pCustomLsOut->ls_elevation_fx; hDirACRend->hOutSetup.num_lfe = inputMasa->base.ctx.pCustomLsOut->num_lfe; + move16(); hDirACRend->hOutSetup.index_lfe[0] = inputMasa->base.ctx.pCustomLsOut->lfe_idx[0]; + move16(); hDirACRend->hOutSetup.is_loudspeaker_setup = TRUE; - hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; - move16(); - move16(); move16(); + hDirACRend->hOutSetup.is_planar_setup = (Word8) inputMasa->base.ctx.pCustomLsOut->is_planar_setup; move16(); } @@ -13605,7 +13666,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ move16(); - IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + test(); + if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; move16(); @@ -13625,10 +13687,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; - nchan_out_woLFE = 1; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + nchan_out_woLFE = 1; move16(); } ELSE IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -13641,15 +13703,15 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE IF( !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_16( nchan_transport, 1 ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } ELSE { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; - hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); + hDirACRend->panningConf = DIRAC_PANNING_HOA3; move32(); } @@ -13688,39 +13750,35 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirACRend->num_outputs_diff = imult1616( ( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); + hDirACRend->num_outputs_diff = imult1616( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ), ( add( s_min( hDirACRend->hOutSetup.ambisonics_order, 1 ), 1 ) ) ); hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); - move16(); - move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; - hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); + hDirACRend->num_outputs_dir = nchan_out_woLFE; move16(); } ELSE IF( EQ_16( 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 */ move16(); + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ move16(); } ELSE { assert( 0 && "DirAC: not existing synthesis methods!" ); } - move16(); - move16(); IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) { @@ -13740,10 +13798,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( nchan_transport, 1 ) ) { hDirACRend->num_protos_ambi = 1; - hDirACRend->num_protos_dir = 1; - hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 1; move16(); + hDirACRend->num_protos_diff = 1; move16(); } ELSE IF( EQ_16( nchan_transport, 2 ) ) @@ -13751,33 +13809,33 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( 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; move16(); + hDirACRend->num_protos_diff = 1; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_dir = 2; - hDirACRend->num_protos_diff = 3; - hDirACRend->proto_index_dir[0] = 0; - hDirACRend->proto_index_diff[0] = 0; move16(); + hDirACRend->num_protos_dir = 2; move16(); + hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->proto_index_dir[0] = 0; move16(); + hDirACRend->proto_index_diff[0] = 0; move16(); } ELSE { hDirACRend->num_protos_ambi = 2; - hDirACRend->num_protos_diff = 3; move16(); + hDirACRend->num_protos_diff = 3; move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) @@ -13806,8 +13864,8 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( ELSE { hDirACRend->num_protos_dir = 2; - hDirACRend->proto_index_dir[1] = 1; move16(); + hDirACRend->proto_index_dir[1] = 1; move16(); } } @@ -13841,7 +13899,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->hoa_encoder_fx, 0, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + set32_fx( hDirACRend->hoa_encoder_fx, 0, imult1616( nchan_out_woLFE, hDirACRend->num_outputs_diff ) ); compute_hoa_encoder_mtx_fx( ls_azimuth_fx, ls_elevation_fx, hDirACRend->hoa_encoder_fx, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); } @@ -13874,7 +13932,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( /* decorrelation */ hDirACRend->proto_signal_decorr_on = 1; move16(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->proto_signal_decorr_on = 0; move16(); @@ -13906,7 +13964,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( move16(); test(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + 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; move16(); @@ -14466,8 +14524,8 @@ static ivas_error ivas_masa_ext_rend_parambin_init( /* Set common variables and defaults */ output_Fs = *( inputMasa->base.ctx.pOutSampleRate ); - nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move32(); + nBins = inputMasa->hMasaExtRend->hSpatParamRendCom->num_freq_bands; move16(); renderer_type = inputMasa->hMasaExtRend->renderer_type; move32(); @@ -14543,7 +14601,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( tmpFloat_fx = s_max( 0, sub( shl_sat( 1, sub( 15, tmp_e ) ), tmp ) ) /*max( 0.0f, 1.0f - binCenterFreq / 2700.0f )*/; /*Q30*/ tmp2 = extract_l( Mult_32_32( binCenterFreq_fx, 1952258 /*=2^31*180/(550)/360*/ ) % 32767 ); //*binCenterFreq_fx * EVS_PI / 550.0f*/ hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( L_mult0( divide3232( tmpFloat_fx, Mult_32_16( binCenterFreq_fx, 187 /*2^15*pi/550*/ ) ), getSineWord16R2( tmp2 ) ), tmp_e ); /*tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );*/ - hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); // Q31 + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); /* Q31 */ move32(); move32(); } @@ -14606,7 +14664,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( return error; } /* External renderer uses constant regularization factor */ - hDiracDecBin->reqularizationFactor_fx = 6554; + hDiracDecBin->reqularizationFactor_fx = 6554; /* 0.4f in Q14 */ move16(); inputMasa->hMasaExtRend->hDiracDecBin = hDiracDecBin; @@ -15118,7 +15176,7 @@ static void intermidiate_ext_dirac_render( move16(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); /* Q30 */ hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; move16(); } @@ -15126,22 +15184,22 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - 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, shift ); + 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, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); move16(); } IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); move16(); } @@ -15157,8 +15215,8 @@ static void intermidiate_ext_dirac_render( IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { - tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); + tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); /* Q(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth + tmp) */ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); move16(); } @@ -15166,21 +15224,21 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); - 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, tmp ); + 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, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev + tmp) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp ); move16(); } - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); /* Q26 */ hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; move16(); IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); /* Q(hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev + shift) */ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); move16(); } @@ -15188,7 +15246,7 @@ static void intermidiate_ext_dirac_render( IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); /* Q(hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer + tmp) */ hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); move16(); } @@ -15224,8 +15282,9 @@ static void intermidiate_ext_dirac_render( Word16 hr_exp = sub( 31, shift ); - 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( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); + 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( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); /* Q(31 - hr_exp) */ hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = sub( 31, hr_exp ); + move16(); } FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -15242,25 +15301,25 @@ static void intermidiate_ext_dirac_render( IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, tmp ); move16(); - tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); } tmp = L_norm_arr( 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, tmp ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q + tmp) */ hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, tmp ); move16(); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp = L_norm_arr( 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, tmp ); + 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, tmp ); /* Q(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q + tmp) */ 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, tmp ); move16(); } @@ -15272,7 +15331,7 @@ static void intermidiate_ext_dirac_render( /* CLDFB Analysis*/ 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 ) ); /* Q11 */ hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; move16(); } @@ -15280,7 +15339,7 @@ static void intermidiate_ext_dirac_render( 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 ) ); /* Q11 */ hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; move16(); } diff --git a/lib_rend/lib_rend.h b/lib_rend/lib_rend.h index beb2af289..1d8c36cf5 100644 --- a/lib_rend/lib_rend.h +++ b/lib_rend/lib_rend.h @@ -133,12 +133,12 @@ typedef enum _IVAS_REND_COMPLEXITY_LEVEL #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_Open( - IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ - const Word32 outputSampleRate, /* i : output sampling rate */ - const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ - const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ - const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain */ - const Word16 num_subframes /* i : number of subframes */ + IVAS_REND_HANDLE *phIvasRend, /* i/o: Pointer to renderer handle */ + const Word32 outputSampleRate, /* i : output sampling rate */ + const IVAS_AUDIO_CONFIG outConfig, /* i : output audio config */ + const Word16 nonDiegeticPan, /* i : non-diegetic object flag */ + const Word32 nonDiegeticPanGain, /* i : non-diegetic panning gain Q31 */ + const Word16 num_subframes /* i : number of subframes */ ); #else ivas_error IVAS_REND_Open( @@ -149,7 +149,7 @@ ivas_error IVAS_REND_Open( const float nonDiegeticPanGain, /* i : non-diegetic panning gain */ const int16_t num_subframes /* i : number of subframes */ ); -#endif // IVAS_FLOAT_FIXED +#endif /* Note: this will reset custom LFE routings set for any MC input */ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( @@ -160,30 +160,30 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( /* Functions to be called before/during rendering */ -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - int16_t *numOutChannels /* o : number of output channels */ + Word16 *numOutChannels /* o : number of output channels */ +); + +ivas_error IVAS_REND_AddInput_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ + IVAS_REND_InputId *inputId /* o : ID of the new input */ ); #else ivas_error IVAS_REND_NumOutChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *numOutChannels /* o : number of output channels */ + int16_t *numOutChannels /* o : number of output channels */ ); -#endif ivas_error IVAS_REND_AddInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ IVAS_REND_InputId *inputId /* o : ID of the new input */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_AddInput_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_AUDIO_CONFIG inConfig, /* i : audio config for a new input */ - IVAS_REND_InputId *inputId /* o : ID of the new input */ -); #endif + /* Note: this will reset any custom LFE routing set for the input */ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ @@ -191,24 +191,33 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( const IVAS_CUSTOM_LS_DATA layout /* i : custom loudspeaker layout for input */ ); -ivas_error IVAS_REND_SetInputGain( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const float gain /* i : linear gain (not in dB) */ -); #ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetInputGain_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 gain /* i : linear gain (not in dB) */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 gain /* i : linear gain (not in dB) Q30 */ ); ivas_error IVAS_REND_SetInputLfeMtx_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_REND_LfePanMtx_fx *lfePanMtx /* i : LFE panning matrix */ +); + +ivas_error IVAS_REND_SetInputLfePos_fx( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) Q31 */ + const Word16 outputAzimuth, /* i : Output azimuth position Q0 */ + const Word16 outputElevation /* i : Output elevation position Q0 */ +); +#else +ivas_error IVAS_REND_SetInputGain( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const float gain /* i : linear gain (not in dB) */ ); -#endif // IVAS_FLOAT_FIXED + ivas_error IVAS_REND_SetInputLfeMtx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -222,15 +231,8 @@ ivas_error IVAS_REND_SetInputLfePos( const float outputAzimuth, /* i : Output azimuth position */ const float outputElevation /* i : Output elevation position */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_SetInputLfePos_fx( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_REND_InputId inputId, /* i : ID of the input */ - const Word32 inputGain, /* i : Input gain to be applied to the LFE channel(s) */ - const Word16 outputAzimuth, /* i : Output azimuth position */ - const Word16 outputElevation /* i : Output elevation position */ -); -#endif // IVAS_FLOAT_FIXED +#endif + ivas_error IVAS_REND_RemoveInput( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId /* i : ID of the input */ @@ -240,7 +242,13 @@ ivas_error IVAS_REND_RemoveInput( ivas_error IVAS_REND_GetInputNumChannels( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ - Word16 *numChannels /* o : number of channels of the input */ + Word16 *numChannels /* o : number of channels of the input */ +); + +ivas_error IVAS_REND_GetDelay_fx( + IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ + Word16 *nSamples, /* o : Renderer delay in samples */ + Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); #else ivas_error IVAS_REND_GetInputNumChannels( @@ -248,46 +256,47 @@ ivas_error IVAS_REND_GetInputNumChannels( const IVAS_REND_InputId inputId, /* i : ID of the input */ int16_t *numChannels /* o : number of channels of the input */ ); -#endif -#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetDelay( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *nSamples, /* o : Renderer delay in samples */ int32_t *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ ); -#else -ivas_error IVAS_REND_GetDelay( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_GetDelay_fx( - IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer state */ - Word16 *nSamples, /* o : Renderer delay in samples */ - Word32 *timeScale /* o : Time scale of the delay, equal to renderer output sampling rate */ -); -#endif // IVAS_FLOAT_FIXED - /* Functions to be called during rendering */ -ivas_error IVAS_REND_FeedInputAudio( +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_REND_FeedInputAudio_fx( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error IVAS_REND_FeedInputAudio_fx( +ivas_error IVAS_REND_FeedInputObjectMetadata( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_REND_InputId inputId, /* i : ID of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); + +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const Word16 inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#else +ivas_error IVAS_REND_FeedInputAudio( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ const IVAS_REND_ReadOnlyAudioBuffer inputAudio /* i : buffer with input audio */ ); -#endif ivas_error IVAS_REND_FeedInputObjectMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -300,6 +309,14 @@ ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( const IVAS_ISM_METADATA objectPosition /* i : object position struct */ ); +ivas_error IVAS_REND_FeedInputObjectMetadataToOMasa( + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const int16_t inputIndex, /* i : Index of the input */ + const IVAS_ISM_METADATA objectPosition /* i : object position struct */ +); +#endif + + ivas_error IVAS_REND_FeedInputMasaMetadata( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ const IVAS_REND_InputId inputId, /* i : ID of the input */ @@ -311,45 +328,40 @@ ivas_error IVAS_REND_InitConfig( const IVAS_AUDIO_CONFIG outAudioConfig /* i : output audioConfig */ ); -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_GetRenderConfig( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ -); -#else +#ifdef IVAS_FLOAT_FIXED Word16 IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif -#ifndef IVAS_FLOAT_FIXED -int16_t IVAS_REND_FeedRenderConfig( +Word16 IVAS_REND_FeedRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ ); + +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 */ +); #else -Word16 IVAS_REND_FeedRenderConfig( +int16_t IVAS_REND_GetRenderConfig( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ - const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ + const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */ ); -#endif +int16_t IVAS_REND_FeedRenderConfig( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS decoder handle */ + const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */ +); -#ifndef IVAS_FLOAT_FIXED 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 int16_t sf_idx /* i : subframe index */ ); -#else -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 */ -); #endif /* Head rotation becomes enabled by calling IVAS_REND_SetHeadRotation. Use this to disable. */ @@ -433,31 +445,27 @@ ivas_error IVAS_REND_SetTotalNumberOfObjects( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const UWord16 total_num_objects /* i : total number of objects */ ); -#else -ivas_error IVAS_REND_SetTotalNumberOfObjects( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const uint16_t total_num_objects /* i : total number of objects */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_SetIsmMetadataDelay( IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ const Word32 sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ ); -#else -ivas_error IVAS_REND_SetIsmMetadataDelay( - IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ - const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ -); -#endif -#ifdef IVAS_FLOAT_FIXED ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ Word16 *numChannels /* o : number of all objects */ ); #else +ivas_error IVAS_REND_SetTotalNumberOfObjects( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const uint16_t total_num_objects /* i : total number of objects */ +); + +ivas_error IVAS_REND_SetIsmMetadataDelay( + IVAS_REND_HANDLE hIvasRend, /* i/o: IVAS renderer handle */ + const float sync_md_delay /* i : Metadata Delay in ms to sync with audio delay */ +); + ivas_error IVAS_REND_GetNumAllObjects( IVAS_REND_CONST_HANDLE hIvasRend, /* i : Renderer handle */ int16_t *numChannels /* o : number of all objects */ -- GitLab From a6cce468a79921dc5ab775740a98668aad82fdc4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 12:32:27 +0530 Subject: [PATCH 13/39] Fix for 3gpp issue 903 --- lib_com/options.h | 1 + lib_dec/ivas_mdct_core_dec.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 424110028..819f2a42f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -135,6 +135,7 @@ #define NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES /* FhG: issue 1133: skip de-whitening of bg noise shape after frameloss period if the first good frame is an SID */ #define NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID /* FhG: issue 1133: in TCX PLC, don't scale hHQ_core->old_out after applying fade to noise in burst frame error */ #define NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL +#define FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE /* FhG: zero out all relevant imdct buffers in MCT decoding of channels with mct_chan_mode == MCT_CHAN_MODE_IGNORE */ /* ##################### End NON-BE switches ########################### */ #define FIX_740_HQ_CORE_OVA // Proposed fix to solve overlap and add issue for HQ_CORE diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 90cb85cc3..7201bad8c 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -1862,6 +1862,15 @@ void ivas_mdct_core_reconstruct( { set_f( &synth[k * L_frame[ch]], 0.f, L_frame[ch] ); set_f( &synthFB[k * L_frame[ch]], 0.f, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set_f( &st->hHQ_core->old_outLB[0], 0.f, L_frame[ch] ); + set_f( &st->hHQ_core->old_out[0], 0.f, L_frameTCX[ch] ); + set_f( &st->hTcxDec->syn_Overl[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_OverlFB[0], 0.f, L_frameTCX[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDAC[0], 0.f, L_frame[ch] / 2 ); + set_f( &st->hTcxDec->syn_Overl_TDACFB[0], 0.f, L_frameTCX[ch] / 2 ); +#endif } } @@ -2093,6 +2102,15 @@ void ivas_mdct_core_reconstruct_fx( { set16_fx( &synth_fx[k * L_frame[ch]], 0, L_frame[ch] ); set16_fx( &synthFB_fx[k * L_frame[ch]], 0, L_frameTCX[ch] ); +#ifdef FIX_903_ZERO_OUT_IMDCT_BUFFERS_FOR_MCT_IGNORE + /* Note: these buffers are not subframe-based, hence no indexing with k */ + set16_fx( &st->hHQ_core->old_out_LB_fx[0], 0, L_frame[ch] ); + set16_fx( &st->hHQ_core->old_out_fx[0], 0, L_frameTCX[ch] ); + set16_fx( &st->hTcxDec->syn_Overl[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_OverlFB[0], 0, shr( L_frameTCX[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDAC[0], 0, shr( L_frame[ch], 1 ) ); + set16_fx( &st->hTcxDec->syn_Overl_TDACFB[0], 0, shr( L_frameTCX[ch], 1 ) ); +#endif } } -- GitLab From d1458004d0e3822f33cd677d92c89e2d02c62afd Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 13:51:44 +0530 Subject: [PATCH 14/39] Fix for 3GPP issue 948: High MLD value due to high energy in transients for MC 5.1 in MCT --- lib_dec/ivas_mct_dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 197c9f2a9..ae5057bc1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -579,15 +579,15 @@ ivas_error ivas_mct_dec_fx( hdrm = getScaleFactor16( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[0], 15 ), hdrm ); + sh = s_min( sub( e_sig[0], 16 ), hdrm ); Scale_sig( synth_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sh ); e_sig[0] = sub( e_sig[0], sh ); move16(); } - + hdrm = getScaleFactor16( synth_fx[1], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX ); IF( hdrm != 0 ) { - sh = s_min( sub( e_sig[1], 15 ), hdrm ); + sh = s_min( sub( e_sig[1], 16 ), hdrm ); Scale_sig( synth_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sh ); e_sig[1] = sub( e_sig[1], sh ); move16(); @@ -616,11 +616,11 @@ ivas_error ivas_mct_dec_fx( IF( ( 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, Q11 - 0 ); // Q11 + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, ( sub( 15, e_sig[n] ) ) ) ); // Q11 Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, sub( Q11, hCPE->hCoreCoder[n]->hHQ_core->Q_old_wtda ) ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1, Q11 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); // Q0 + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( sub( 15, e_sig[n] ), Q11 ) ); // Q0 #else Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif @@ -630,7 +630,7 @@ ivas_error ivas_mct_dec_fx( 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 ), 0 - Q11 ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), -Q11 ); } ELSE { -- GitLab From 76142da0269cc7a87a04285afb132bc83ac6f8b8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 24 Oct 2024 14:07:12 +0530 Subject: [PATCH 15/39] SBA path functions conversion, ASAN and MSAN fixes, cleanup [x] spar process functions/ sub-functions conversion and integration [x] Cleanup of ivas_dirac_param_est_enc function [x] Few ASAN and MSAN fixes [x] Q-info updates for lib_dec and lib_rend files --- lib_com/ivas_fb_mixer.c | 220 ++++++- lib_com/ivas_prot.h | 35 +- lib_com/ivas_prot_fx.h | 20 +- lib_com/ivas_rom_com_fx.c | 106 ++-- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_stat_com.h | 1 + lib_com/prot.h | 24 +- lib_com/prot_fx.h | 311 +++++----- lib_com/rom_com.c | 26 +- lib_com/rom_com_fx.c | 53 ++ lib_dec/er_scale_syn_fx.c | 16 +- lib_dec/er_sync_exc_fx.c | 140 ++--- lib_dec/er_util_fx.c | 102 ++-- lib_dec/hf_synth_fx.c | 591 +++++++++--------- lib_dec/hq_classifier_dec_fx.c | 32 +- lib_dec/hq_conf_fec_fx.c | 24 +- lib_dec/hq_core_dec_fx.c | 236 +++---- lib_dec/hq_env_dec_fx.c | 110 ++-- lib_dec/hq_hr_dec_fx.c | 112 ++-- lib_dec/swb_bwe_dec.c | 67 +- lib_dec/swb_bwe_dec_fx.c | 139 ++--- lib_dec/swb_bwe_dec_hr_fx.c | 105 ++-- lib_dec/swb_bwe_dec_lr_fx.c | 125 ++-- lib_dec/swb_tbe_dec.c | 153 +++-- lib_dec/swb_tbe_dec_fx.c | 153 +++-- lib_dec/syn_outp.c | 3 +- lib_dec/syn_outp_fx.c | 18 +- lib_dec/tcq_core_dec_fx.c | 47 +- lib_dec/tcx_utils_dec_fx.c | 87 ++- lib_dec/tns_base_dec_fx.c | 24 +- lib_enc/ivas_core_enc.c | 19 +- lib_enc/ivas_core_pre_proc_front.c | 3 + lib_enc/ivas_dirac_enc.c | 949 ++++++++++++----------------- lib_enc/ivas_mdct_core_enc.c | 5 + lib_enc/ivas_spar_encoder.c | 119 +++- lib_enc/ivas_spar_md_enc.c | 69 +++ lib_enc/ivas_stat_enc.h | 7 +- lib_enc/swb_pre_proc.c | 2 +- 38 files changed, 2270 insertions(+), 1987 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 9d54f3f0a..5da92e987 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -48,7 +48,7 @@ /*------------------------------------------------------------------------------------------* * Static functions declarations *------------------------------------------------------------------------------------------*/ - +static void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ); static void ivas_get_active_bins( const int16_t **pActive_bins, const int16_t **pActive_bins_abs, const int16_t **pStart_offset, const int16_t **pStart_offset_ab, const int32_t sampling_rate ); static void ivas_get_ld_fb_resp( float **ppIdeal_FRs_re, float **ppIdeal_FRs_im, float **ppNew_FRs_re, float **ppNew_FRs_im, const int16_t *pActive_bins, const int16_t *pStart_offset, const int16_t num_bands, const int16_t delay, const int32_t sampling_rate ); #ifdef IVAS_FLOAT_FIXED @@ -426,6 +426,21 @@ ivas_error ivas_FB_mixer_open( set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + + 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 ) + { + 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 ( 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; + set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); + } + } } if ( !spar_reconfig_flag ) @@ -506,6 +521,12 @@ ivas_error ivas_FB_mixer_open( { return error; } + Word16 index[IVAS_MAX_NUM_FB_BANDS]; + set16_fx( index, 0, IVAS_MAX_NUM_FB_BANDS ); + if ( ( error = ivas_filterbank_setup_fx( hFbMixer, sampling_rate, index ) ) != IVAS_ERR_OK ) + { + return error; + } } *hFbMixer_out = hFbMixer; @@ -1400,7 +1421,162 @@ void ivas_fb_mixer_cross_fading_fx( * * Filter bank process *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_cmult_fix( Word32 in1_re, Word32 in1_im, Word32 in2_re, Word32 in2_im, Word32 *out1_re, Word32 *out1_im ) +{ + *out1_re = L_sub_sat( Mpy_32_32( in1_re, in2_re ), Mpy_32_32( in1_im, in2_im ) ); + *out1_im = L_add_sat( Mpy_32_32( in1_re, in2_im ), Mpy_32_32( in2_re, in1_im ) ); +} +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +) +{ + ivas_filterbank_t *pFb = hFbMixer->pFb; + Word16 num_bands = pFb->filterbank_num_bands; + move16(); + Word16 i, j, k, ch, hist; + + const Word32 *pFilterbank_bin_to_band_re_fx; + const Word32 *pFilterbank_bin_to_band_im_fx; + Word32 *pMdft_out_fx[2]; + Word32 *pOut_fr_re_fx, *pOut_fr_im_fx; + Word16 q_pOut_fr_fx = 31; + move16(); + Word32 Out_fr_re_fx[L_FRAME48k], Out_fr_im_fx[L_FRAME48k]; + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; + + pOut_fr_re_fx = Out_fr_re_fx; + pOut_fr_im_fx = Out_fr_im_fx; + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; + + FOR( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + /* Run a loop of 2 to calculate current frame's filterbank output and prev frame's output */ + FOR( hist = 0; hist < 2; hist++ ) + { + set_zero_fx( pOut_fr_re_fx, frame_len ); + set_zero_fx( pOut_fr_im_fx, frame_len ); + q_pOut_fr_fx = 31; + move16(); + FOR( j = 0; j < hFbMixer->fb_cfg->num_in_chans; j++ ) + { + IF( in_out_mixer_map[ch][j] != 0 ) + { + + Word32 filterbank_mixer_bins_re_fx[L_FRAME48k]; + Word32 filterbank_mixer_bins_im_fx[L_FRAME48k]; + Word32 *pFb_inFR_re_fx = hFbMixer->ppFilterbank_inFR_re_fx[j]; + Word32 *pFb_inFR_im_fx = hFbMixer->ppFilterbank_inFR_im_fx[j]; + + set_zero_fx( filterbank_mixer_bins_re_fx, frame_len ); + set_zero_fx( filterbank_mixer_bins_im_fx, frame_len ); + + Word16 total_guard = find_guarded_bits_fx( num_bands ); + move16(); + FOR( i = 0; i < num_bands; i++ ) + { + Word16 start_offset = pFb->fb_consts.pFilterbank_bins_start_offset[i]; + move16(); + Word16 num_bins = pFb->fb_consts.pFilterbank_bins_per_band[i]; + move16(); + Word32 mixer_const_fx = hFbMixer->prior_mixer_fx[ch][j][i]; + move32(); + pFilterbank_bin_to_band_re_fx = pFb->fb_consts.ppFilterbank_FRs_fx[0][i]; + pFilterbank_bin_to_band_im_fx = pFb->fb_consts.ppFilterbank_FRs_fx[1][i]; + + FOR( k = start_offset; k < num_bins + start_offset; k++ ) + { + filterbank_mixer_bins_re_fx[k] = L_add_sat( filterbank_mixer_bins_re_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_re_fx, mixer_const_fx ), total_guard ) ); + move32(); + filterbank_mixer_bins_im_fx[k] = L_add_sat( filterbank_mixer_bins_im_fx[k], L_shr( Mpy_32_32( *pFilterbank_bin_to_band_im_fx, mixer_const_fx ), total_guard ) ); + move32(); + /*filterbank_mixer_bins_im_fx q 30 */ + /*mixer_const_fx q q_ppOut_pcm_fx */ + pFilterbank_bin_to_band_re_fx++; + pFilterbank_bin_to_band_im_fx++; + } + hFbMixer->prior_mixer_fx[ch][j][i] = mixer_mat_fx[ch][j][i]; + move32(); + } + Word16 res_q = 0; + move16(); + FOR( k = 0; k < frame_len; k++ ) + { + Word32 temp_out_re_fx, temp_out_im_fx; + + Word16 Fb_inFR_com_q = s_min( hFbMixer->q_ppFilterbank_inFR_re_fx[j], hFbMixer->q_ppFilterbank_inFR_im_fx[j] ); + Word32 inp_Fb_inFR_re, inp_Fb_inFR_im; + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_re = L_shr( pFb_inFR_re_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_re_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_re = pFb_inFR_re_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + move32(); + } + IF( NE_16( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ) + { + inp_Fb_inFR_im = L_shr( pFb_inFR_im_fx[k], sub( hFbMixer->q_ppFilterbank_inFR_im_fx[j], Fb_inFR_com_q ) ); + /*common q for real and imag hFbMixer->q_ppFilterbank_inFR_re_fx[j]*/ + } + ELSE + { + inp_Fb_inFR_im = pFb_inFR_im_fx[k]; + /*q hFbMixer->q_ppFilterbank_inFR_im_fx[j]*/ + move32(); + } + ivas_cmult_fix( filterbank_mixer_bins_re_fx[k], filterbank_mixer_bins_im_fx[k], inp_Fb_inFR_re, + inp_Fb_inFR_im, &temp_out_re_fx, &temp_out_im_fx ); + res_q = sub( add( sub( sub( add( 30, *q_mixer_mat_fx ), 31 ), total_guard ), Fb_inFR_com_q ), 31 ); + move16(); + Word16 q_check = s_min( q_pOut_fr_fx, res_q ); + move16(); + IF( NE_16( q_check, q_pOut_fr_fx ) ) + { + pOut_fr_re_fx[k] = L_shr( pOut_fr_re_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + pOut_fr_im_fx[k] = L_shr( pOut_fr_im_fx[k], sub( q_pOut_fr_fx, q_check ) ); + move32(); + } + IF( q_check != res_q ) + { + temp_out_re_fx = L_shr( temp_out_re_fx, sub( res_q, q_check ) ); + temp_out_im_fx = L_shr( temp_out_im_fx, sub( res_q, q_check ) ); + } + res_q = q_check; + move16(); + pOut_fr_re_fx[k] = L_add_sat( pOut_fr_re_fx[k], temp_out_re_fx ); + move32(); + pOut_fr_im_fx[k] = L_add_sat( pOut_fr_im_fx[k], temp_out_im_fx ); + move32(); + } + q_pOut_fr_fx = res_q; + move16(); + } + } + ivas_imdft_fx( pOut_fr_re_fx, pOut_fr_im_fx, pMdft_out_fx[hist], frame_len ); + } + + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); + q_ppOut_pcm_fx[ch] = q_pOut_fr_fx; + move16(); + } + + return; +} + +#else void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -1415,13 +1591,27 @@ void ivas_fb_mixer_process( const float *pFilterbank_bin_to_band_re; const float *pFilterbank_bin_to_band_im; float *pMdft_out[2], *pOut_fr_re, *pOut_fr_im; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 *pMdft_out_fx[2]; + Word32 **ppOut_pcm_fx = (Word32 **) malloc( hFbMixer->fb_cfg->num_out_chans * sizeof( Word32 * ) ); + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + ppOut_pcm_fx[ch] = (Word32 *) malloc( frame_len * sizeof( Word32 ) ); + } +#endif float Out_fr_re[L_FRAME48k], Out_fr_im[L_FRAME48k]; float Mdft_out_0[L_FRAME48k * 2], Mdft_out_1[L_FRAME48k * 2]; - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word32 Mdft_out_0_fx[L_FRAME48k * 2], Mdft_out_1_fx[L_FRAME48k * 2]; +#endif pOut_fr_re = Out_fr_re; pOut_fr_im = Out_fr_im; pMdft_out[0] = Mdft_out_0; pMdft_out[1] = Mdft_out_1; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + pMdft_out_fx[0] = Mdft_out_0_fx; + pMdft_out_fx[1] = Mdft_out_1_fx; +#endif for ( ch = ( hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) { @@ -1476,14 +1666,32 @@ void ivas_fb_mixer_process( ivas_imdft( pOut_fr_re, pOut_fr_im, pMdft_out[hist], frame_len ); } - +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hFbMixer, ppOut_pcm, pMdft_out[0], pMdft_out[1], ch, frame_len, frame_len ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q1 = Q_factor_arrL( pMdft_out[0], frame_len * 2 ); + Word16 q2 = Q_factor_arrL( pMdft_out[1], frame_len * 2 ); + Word16 q = s_min( q1, q2 ); + floatToFixed_arrL( pMdft_out[0], pMdft_out_fx[0], q, frame_len * 2 ); + floatToFixed_arrL( pMdft_out[1], pMdft_out_fx[1], q, frame_len * 2 ); +#endif + ivas_fb_mixer_cross_fading_fx( hFbMixer, ppOut_pcm_fx, pMdft_out_fx[0], pMdft_out_fx[1], ch, frame_len, frame_len ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + fixedToFloat_arrL( ppOut_pcm_fx[ch], ppOut_pcm[ch], q, frame_len ); +#endif +#endif } - +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( ch = 0; ch < hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + free( ppOut_pcm_fx[ch] ); + } + free( ppOut_pcm_fx ); +#endif return; } - - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_get_in_out_mapping() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index db7ec4ee2..5e1214c42 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4706,6 +4706,23 @@ int16_t ivas_chan_project_elevation_index( ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag +); +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4720,6 +4737,7 @@ void ivas_dirac_param_est_enc( int16_t *mono_frame_count, int16_t *dirac_mono_flag ); +#endif void ivas_sba_config( @@ -8409,14 +8427,25 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); +#ifdef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ const int16_t frame_len, /* i : frame length in samples */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ ); - +#else +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + float ***mixer_mat, /* i : mixer matrix */ + float **ppOut_pcm, /* o : output audio channels */ + const int16_t frame_len, /* i : frame length in samples */ + int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); +#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 07f548f32..121570bc3 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1911,16 +1911,16 @@ void ivas_GenShapedWBExcitation_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ); +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb*/ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ); void ivas_param_ism_config_fx( PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure */ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..200c376cb 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,46 +1634,76 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[90] = { - 0, 1509949440, 754974720, 503316480, 377487360, 301989888, - 251658240, 215707056, 188743680, 167772160, 150994944, - 137268128, 125829120, 116149960, 107853528, 100663296, - 94371840, 88820552, 83886080, 79471024, 75497472, - 71902352, 68634064, 65649976, 62914560, 60397976, - 58074980, 55924052, 53926764, 52067224, 50331648, - 48708048, 47185920, 45756044, 44410276, 43141412, - 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, - 32824988, 32126584, 31457280, 30815294, 30198988, - 29606852, 29037490, 28489612, 27962026, 27453626, - 26963382, 26490342, 26033612, 25592364, 25165824, - 24753270, 24354024, 23967452, 23592960, 23229992, - 22878022, 22536558, 22205138, 21883326, 21570706, - 21266894, 20971520, 20684238, 20404722, 20132660, - 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, - 17557552, 17355740, 17158516, 16965724 +const Word32 delta_phi_val[257] = { + 0, + 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, + 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, + 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, + 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, + 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, + 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, + 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, + 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, + 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, + 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, + 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, + 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, + 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, + 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, + 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, + 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, + 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, + 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, + 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, + 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, + 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, + 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, + 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, + 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, + 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, + 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, + 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, + 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, + 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, + 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 }; -const Word32 inv_delta_phi_val[90] = { - 0, 5965232, 11930464, 17895697, 23860929, 29826161, - 35791394, 41756626, 47721858, 53687091, 59652323, - 65617555, 71582788, 77548020, 83513252, 89478485, - 95443717, 101408950, 107374182, 113339414, 119304647, - 125269879, 131235111, 137200344, 143165576, 149130808, - 155096041, 161061273, 167026505, 172991738, 178956970, - 184922203, 190887435, 196852667, 202817900, 208783132, - 214748364, 220713597, 226678829, 232644061, 238609294, - 244574526, 250539758, 256504991, 262470223, 268435456, - 274400688, 280365920, 286331153, 292296385, 298261617, - 304226850, 310192082, 316157314, 322122547, 328087779, - 334053011, 340018244, 345983476, 351948708, 357913941, - 363879173, 369844406, 375809638, 381774870, 387740103, - 393705335, 399670567, 405635800, 411601032, 417566264, - 423531497, 429496729, 435461961, 441427194, 447392426, - 453357659, 459322891, 465288123, 471253356, 477218588, - 483183820, 489149053, 495114285, 501079517, 507044750, - 513009982, 518975214, 524940447, 530905679 +const Word32 inv_delta_phi_val[257] = { + 0, + 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, + 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, + 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, + 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, + 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, + 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, + 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, + 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, + 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, + 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, + 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, + 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, + 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, + 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, + 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, + 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, + 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, + 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, + 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, + 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, + 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, + 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, + 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, + 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, + 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, + 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, + 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, + 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, + 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, + 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, + 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, + 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..6d4f50fa8 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[90]; -extern const Word32 inv_delta_phi_val[90]; +extern const Word32 delta_phi_val[257]; +extern const Word32 inv_delta_phi_val[257]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5fdcf2bc1..a4d1065f4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -871,6 +871,7 @@ typedef struct ivas_fb_mixer_state_structure Word16 q_ppFilterbank_inFR_im_fx[IVAS_MAX_FB_MIXER_IN_CH]; Word16 q_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]; + Word16 q_prior_mixer_fx; #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) */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d0fc8d2ff..d286851e0 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -240,11 +240,13 @@ void mvl2l( const int16_t n /* i : vector size */ ); +#ifndef IVAS_FLOAT_FIXED void AGC_dec( float x[], /* i/o: input/output vector */ float mem[], /* i/o: mem[2] should be init to [0,0] */ const int16_t n /* i : vector size */ ); +#endif /*! r: index of the maximum value in the input vector */ int16_t maximum( @@ -2792,13 +2794,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 : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ); void GenTransition_WB( @@ -2808,9 +2810,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 : Q11 */ + const Word32 output_Fs /* i : output sampling rate */ ); void td_bwe_dec_init( @@ -4923,11 +4925,13 @@ void dec_acelp_4t64( const int16_t Opt_AMR_WB /* i : flag indicating AMR-WB IO mode */ ); +#ifndef IVAS_FLOAT_FIXED uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ const int16_t output_frame, /* i : output frame length */ int16_t *synth_out /* o : integer 16 bits synthesis signal */ ); +#endif void FEC_exc_estim( Decoder_State *st, /* i/o: Decoder static memory */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1a1b8a81a..da45e5743 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6372,20 +6372,20 @@ 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 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ 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 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ); void hf_synth_amr_wb_init_fx( @@ -6400,21 +6400,21 @@ 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 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + 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) Q0*/ + 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 Q0*/ + 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 @@ -6518,19 +6518,20 @@ void init_tcx_cfg_fx( // 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 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ); void unscale_AGC( - const Word16 x[], - const Word16 Qx, - Word16 y[], - Word16 mem[], - const Word16 n ); + 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] Q0 */ + const Word16 n /* i: vector size */ +); // bass_psfilter_fx.c void bass_psfilter_init_fx( @@ -7514,21 +7515,21 @@ void destroy_cldfb_decoder_fx( // 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_fenv /*Q15*/ +); Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE 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 Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #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 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ); @@ -7542,19 +7543,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class const Word16 hqswb_clas /* i : HQ BWE class */ ); -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #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/o: ACELP core synthesis/final synthesis (might be rescaled inside wtda() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #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 ); + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ); void fd_bwe_dec_init( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -7573,11 +7574,11 @@ void hq_core_enc_ivas_fx( // 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 synth[], /* o : output synthesis Q_synth*/ 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 */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ); void HQ_core_dec_init_fx( HQ_DEC_HANDLE hHQ_core /* i/o: HQ core data handle */ @@ -7623,24 +7624,24 @@ void hq_lr_dec_fx( ); // gq_env_dec_fx.c -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ 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 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ); 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 Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ); #ifdef IVAS_FLOAT_FIXED @@ -7690,20 +7691,21 @@ void hdecnrm_tran_fx( // 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 ); + Word16 *inp_vector_fx, /*x5 */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +); // FEC_HQ_core_fx.c void HQ_FEC_processing_fx( @@ -7745,11 +7747,11 @@ void time_domain_FEC_HQ_fx( // 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ); void hq_hr_dec_fx( @@ -7761,7 +7763,7 @@ void hq_hr_dec_fx( 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 */ + const Word16 core_switching_flag /* i : Core switching flag Q1 */ ); // hq_classifier_dec_fx.c @@ -7804,12 +7806,12 @@ Word16 hvq_pvq_bitalloc_fx( // 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 */ + 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 Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ); // core_switching_dec_fx.c @@ -8255,14 +8257,14 @@ void tcxltp_dec_init_fx( const Word32 sr_core ); /* Q0 */ // 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 */ +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 : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ); void hr_bwe_dec_init( @@ -8517,26 +8519,26 @@ ivas_error decod_ppp_fx( // 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + 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 : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ); #ifdef IVAS_FLOAT_FIXED @@ -9291,39 +9293,40 @@ void tcx_arith_decode_envelope_fx( // tcx_utils_dec_fx.c void tcx_decoder_memory_update( - Word16 *xn_buf, /* i: mdct output buffer */ - Word16 *synthout, /* i/o: synth */ - Word16 *A, /* i: Quantized LPC coefficients */ - Decoder_State *st, - Word8 fb /* i: fullband flag */ + Word16 *xn_buf, /* i/o: mdct output buffer used also as temporary buffer : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ); 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: 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 */ + Word32 x_Q[], /* i/o: quantized spectrum Q(31-x_Q_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 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, + Word16 *prm, /*i*/ Word16 resQBits ); Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ +); // er_dec_acelp_fx.c void con_acelp_fx( @@ -10461,24 +10464,24 @@ void v_sub32_fx( ); void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ); 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_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 : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ); ivas_error acelp_core_dec_ivas_fx( diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 450c166cb..9047d8338 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -26312,23 +26312,7 @@ const float lsf_q_cb_3b[8] = 0.05307309f, 0.06137543f, 0.07216742f, 0.09013262f }; -const Word16 lsf_q_cb_4b_fx[16] = -{ - 589, 773, 914, 1043, - 1173, 1302, 1430, 1558, - 1698, 1843, 1973, 2103, - 2258, 2470, 2787, 3282 - -}; - -const Word16 lsf_q_cb_3b_fx[8] = -{ - 679, 976, 1245, 1491, - 1739, 2011, 2365, 2953 -}; - const float * const lsf_q_cb[NUM_Q_LSF] = { lsf_q_cb_4b, lsf_q_cb_4b, lsf_q_cb_3b, lsf_q_cb_3b, lsf_q_cb_3b }; -const Word16 * const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; const int16_t lsf_q_cb_size[NUM_Q_LSF] = {16, 16, 8, 8, 8}; const int16_t lsf_q_num_bits[NUM_Q_LSF] = { 4, 4, 3, 3, 3 }; @@ -26344,16 +26328,8 @@ const float lsf_grid[4][5] = { 0.14185823f, 0.26648724f, 0.39740108f, 0.55685745f, 0.74688616f }, { 0.15416561f, 0.27238427f, 0.39376780f, 0.59287916f, 0.86613986f } }; -const Word16 lsf_grid_fx[4][5] = -{ - { 5242, 10229, 15516, 21804, 27540, }, - { 5117, 10059, 14949, 20478, 25493, }, - { 4648, 8732, 13022, 18247, 24474, }, - { 5052, 8925, 12903, 19427, 28382, } -}; -const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; -const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; +const float grid_smoothing[5] = { 0.2f, 0.35f, 0.5f, 0.75f, 0.8f }; const float allpass_poles_3_ov_2_flt[9] = { diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index a1465dc53..39b94b308 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -6631,3 +6631,56 @@ const Word16 LP_assym_window_16k_fx[L_LP_16k] = { 0x0a40, 0x0a3d, }; + +/* 4-bit/3-bit TD SWB BWE differential LSF scalar quantizer tables */ +/*Q15*/ +const Word16 lsf_q_cb_4b_fx[16] = { + 589, 773, 914, 1043, + 1173, 1302, 1430, 1558, + 1698, 1843, 1973, 2103, + 2258, 2470, 2787, 3282 + +}; + +/*Q15*/ +const Word16 lsf_q_cb_3b_fx[8] = { + 679, 976, 1245, 1491, + 1739, 2011, 2365, 2953 +}; + +const Word16 *const lsf_q_cb_fx[NUM_Q_LSF] = { lsf_q_cb_4b_fx, lsf_q_cb_4b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx, lsf_q_cb_3b_fx }; + +/*Q15*/ +const Word16 lsf_grid_fx[4][5] = { + { + 5242, + 10229, + 15516, + 21804, + 27540, + }, + { + 5117, + 10059, + 14949, + 20478, + 25493, + }, + { + 4648, + 8732, + 13022, + 18247, + 24474, + }, + { + 5052, + 8925, + 12903, + 19427, + 28382, + } +}; + +/*Q15*/ +const Word16 grid_smoothing_fx[5] = { 6554, 11469, 16384, 24576, 26214 }; diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index 2e5746ccf..509fd071b 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -57,8 +57,8 @@ Word16 Damping_fact_fx( /* o : damping factor 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 ); + /* * (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 ); /*Q14*/ } ELSE IF( EQ_16( nbLostCmpt, 2 ) ) { @@ -67,7 +67,7 @@ Word16 Damping_fact_fx( /* o : damping factor } 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 Q14*/ } } ELSE IF( EQ_16( last_good, UNVOICED_TRANSITION ) ) @@ -80,12 +80,12 @@ Word16 Damping_fact_fx( /* o : damping factor } 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 Q14*/ } IF( GE_16( last_good, VOICED_CLAS ) ) { - lp_tmp = *lp_gainp; + lp_tmp = *lp_gainp; /*Q29*/ move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ @@ -96,7 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; move16(); - gain32 = Sqrt32( lp_tmp, &s_gainp ); + gain32 = Sqrt32( lp_tmp, &s_gainp ); /*Q31-s_gainp*/ #ifdef BASOP_NOGLOB gain = round_fx_o( L_shl_o( gain32, s_gainp, &Overflow ), &Overflow ); /* Q15*/ @@ -110,7 +110,7 @@ Word16 Damping_fact_fx( /* o : damping factor 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 ) ) ); /*Q14*/ } ELSE { @@ -118,7 +118,7 @@ Word16 Damping_fact_fx( /* o : damping factor 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*/ } - *lp_gainp = lp_tmp; /*store*/ + *lp_gainp = lp_tmp; /*store Q29*/ move32(); } } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 268476821..ac04d048c 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -36,9 +36,9 @@ static Word16 GetMinimumPosition_fx( move16(); #endif - filterLength = s_min( filterLength, length ); - center = shr( filterLength, 1 ); - iMinEnergyPos = center; + filterLength = s_min( filterLength, length ); /*Q0*/ + center = shr( filterLength, 1 ); /*Q0*/ + iMinEnergyPos = center; /*Q0*/ move16(); IF( filterLength > 0 ) @@ -47,22 +47,22 @@ static Word16 GetMinimumPosition_fx( energy = L_deposit_l( 0 ); energy_old = L_deposit_l( 0 ); - cnt = sub( length, filterLength ); + cnt = sub( length, filterLength ); /*Q0*/ tmp_e = 0; move16(); FOR( i = 0; i < cnt; i++ ) { - tmp16 = shr( x[i], tmp_e ); + tmp16 = shr( x[i], tmp_e ); /*Qx*/ #ifdef BASOP_NOGLOB - energy = L_msu_sat( energy_old, tmp16, tmp16 ); + energy = L_msu_sat( energy_old, tmp16, tmp16 ); /*2Qx+1*/ #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[add( i, filterLength )], tmp_e ); - BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ + tmp16 = shr( x[( i + filterLength )], tmp_e ); /*Qx*/ + 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 ); /*2Qx+1*/ #else energy = L_mac( energy, tmp16, tmp16 ); #endif @@ -71,7 +71,7 @@ static Word16 GetMinimumPosition_fx( /*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 ); /*Q31*/ #else tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif @@ -80,15 +80,15 @@ static Word16 GetMinimumPosition_fx( { 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[add( i, filterLength )], tmp_e ); - energy = L_mac( energy, tmp16, tmp16 ); + tmp16 = shr( x[i], tmp_e ); /*Qx-1*/ + energy = L_msu( energy, tmp16, tmp16 ); /*2Qx-1*/ + tmp16 = shr( x[( i - filterLength )], tmp_e ); + energy = L_mac( energy, tmp16, tmp16 ); /*2Qx-1*/ } IF( energy < 0 ) { - iMinEnergyPos = add( i, center ); + iMinEnergyPos = add( i, center ); /*Q0*/ tmp_e = 0; move16(); energy = 0; @@ -98,7 +98,7 @@ static Word16 GetMinimumPosition_fx( } } - return iMinEnergyPos; + return iMinEnergyPos; /*Q0*/ } /*! @@ -108,7 +108,7 @@ static Word16 GetMinimumPosition_fx( */ static Word16 FindMaxPeak_fx( - Word16 /*float*/ const *x, /* 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } /* Add some samples */ - ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); + ftmp = negate( mult( *pt_src, 1638 /*.05f Q15*/ ) ); /*Qx*/ FOR( j = 0; j < points_by_pos[i]; j++ ) { - *pt_dest++ = ftmp; + *pt_dest++ = ftmp; /*Qx*/ move16(); - ftmp = negate( ftmp ); + ftmp = negate( ftmp ); /*Qx*/ } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ FOR( j = sub( L_frame, add( n_samples_to_add, last_min_pos ) ); j > 0; j-- ) { - *pt_dest++ = *pt_src++; + *pt_dest++ = *pt_src++; /*Qx*/ move16(); } } @@ -192,30 +192,30 @@ static void RemoveSamples_fx( 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; /*Qx*/ + last_min_pos = sub( L_frame, n_samples_to_add ); /*Q0*/ 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; /*Qx*/ FOR( j = sub( last_min_pos, add( min_pos[i], points_by_pos[i] ) ); j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } /* Prepare for the next loop iteration */ - last_min_pos = min_pos[i]; + last_min_pos = min_pos[i]; /*Q0*/ move16(); } /* Copy remaining length */ - pt_src = old_exc + last_min_pos; + pt_src = old_exc + last_min_pos; /*Qx*/ FOR( j = last_min_pos; j > 0; j-- ) { - *--pt_dest = *--pt_src; + *--pt_dest = *--pt_src; /*Qx*/ move16(); } } @@ -258,7 +258,7 @@ void PulseResynchronization_fx( test(); IF( src_exc != dst_exc && LE_16( nFrameLength, 1200 ) ) { - Copy( src_exc, dst_exc, nFrameLength ); + Copy( src_exc, dst_exc, nFrameLength ); /*Q15*/ } return; } @@ -282,7 +282,7 @@ void PulseResynchronization_fx( 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 ); + tmp32 = L_sub( pitchEnd, pitchStart ); /*Q16*/ 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*/ @@ -290,7 +290,7 @@ void PulseResynchronization_fx( tmp16 = imult1616( nFrameLength, add( nSubframes, 1 ) ); /*Q0*/ /*tmp16=nFrameLength*(nSubframes+1)*/ tmp2_e = norm_s( tmp16 ); - tmp16 = shl( tmp16, tmp2_e ); + tmp16 = shl( tmp16, tmp2_e ); /*Q0+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 */ @@ -298,7 +298,7 @@ void PulseResynchronization_fx( /*samplesDelta -= nFrameLength*(1.0f-pitchStart*freqStart);*/ tmp2_e = norm_l( pitchStart ); - tmp32_a = L_shl( pitchStart, tmp2_e ); + tmp32_a = L_shl( pitchStart, tmp2_e ); /*Q16+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 ); @@ -314,7 +314,7 @@ void PulseResynchronization_fx( 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 ); + tmp16_a = shl( nFrameLength, tmp2_e ); /*Q0+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*/ @@ -346,7 +346,7 @@ void PulseResynchronization_fx( 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 ); + tmp32_b = L_shl( absPitchDiff, tmp2_e ); /*Q16+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*/ @@ -412,33 +412,33 @@ void PulseResynchronization_fx( /* Make sure that the number of samples increases */ IF( GT_32( L_deposit_h( roundedCycleDelta ), cycleDelta32 ) ) { - iDeltaSamples[i] = roundedCycleDelta; + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ 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 Q0*/ + iDeltaSamples[i - 1] = roundedCycleDelta; /*Q0*/ move16(); } ELSE { - roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i] = roundedCycleDelta; + roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here Q0*/ + iDeltaSamples[i] = roundedCycleDelta; /*Q0*/ move16(); } /*fractionalLeft = cycleDelta-roundedCycleDelta = cycleDelta-(int)cycleDelta;*/ fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[( k + 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( 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 = round_fx( L_shl( tmp32, tmp_e ) ); /*Q0*/ + tmp16 = sub( tmp16, T0 ); /*Q0*/ tmp16 = s_min( roundedPitchStart, tmp16 ); iMinPos1 = GetMinimumPosition_fx( @@ -455,26 +455,26 @@ void PulseResynchronization_fx( 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 ) ) ); /*Q0*/ move16(); } ELSE { - 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 ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - 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 ) ) ); /*Q0*/ move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( 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 ) ) ) { - iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); + iMinPos[( k + 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[( k + 1 )], 1 ) ) ); /*Q0*/ move16(); } ELSE @@ -482,18 +482,18 @@ void PulseResynchronization_fx( /*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 + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); - iMinPos[add( k, 1 )] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[( k + 1 )], 1 ) ); + iMinPos[( k + 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + iDeltaSamples[( k + 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[( k + 1 )] ) ); /*Q0*/ move16(); } @@ -505,43 +505,43 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy before the first pulse */ IF( GT_16( iMinPos1, roundedPitchStart ) ) { - iMinPos[0] = sub( iMinPos1, roundedPitchStart ); + iMinPos[0] = sub( iMinPos1, roundedPitchStart ); /*Q0*/ move16(); } ELSE { - iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); + iMinPos[0] = GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ); /*Q0*/ move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - iMinPos[i] = iMinPos1; + iMinPos[i] = iMinPos1; /*Q0*/ move16(); - iMinPos1 = add( iMinPos1, roundedPitchStart ); + iMinPos1 = add( iMinPos1, roundedPitchStart ); /*Q0*/ } /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[add( k, 1 )] = iMinPos1; + iMinPos[( k + 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[( k + 1 )] ); /*Q0*/ tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[add( k, 1 )] = tmp16; + iMinPos[( k + 1 )] = tmp16; /*Q0*/ move16(); } - IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[( k + 1 )], iDeltaSamples[( k + 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[( k + 1 )], sub( iDeltaSamples[( k + 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); /*Q0*/ move16(); - iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); + iDeltaSamples[( k + 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[( k + 1 )] ); /*Q0*/ move16(); } /* Add samples at the given positions */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index cc6a53cd2..c2c766d9e 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -61,7 +61,7 @@ void minimumStatistics_fx( #endif { BASOP_SATURATE_WARNING_ON_EVS - currentFrameLevel = PLC_MIN_CNG_LEV; + currentFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/ move16(); currentFrameLevel_e = 0; move16(); @@ -73,13 +73,13 @@ void minimumStatistics_fx( IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ - aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); + aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); /*Q16-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 = BASOP_Util_Divide1616_Scale( *lastFrameLevel, *noiseEstimate, &aOpt_e ); /*Q16-aOpt_e*/ aOpt_e = add( aOpt_e, sub( *lastFrameLevel_e, noiseEstimate_e ) ); } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ @@ -90,7 +90,7 @@ void minimumStatistics_fx( move16(); } - *lastFrameLevel = currentFrameLevel; + *lastFrameLevel = currentFrameLevel; /*Qx*/ move16(); *lastFrameLevel_e = currentFrameLevel_e; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( move16(); if ( tmp == 0 ) { - tmp = PLC_MIN_STAT_BUFF_SIZE; + tmp = PLC_MIN_STAT_BUFF_SIZE; /*Q0*/ move16(); } /*f = msu_r(L_mult(aOpt, noiseLevelMemory[sub(tmp, 1)]), add(aOpt, 0x8000), currentFrameLevel);*/ @@ -128,7 +128,7 @@ void minimumStatistics_fx( assert( f >= 0 ); /* if current frame min is a new local min, set index to current index */ - p = *noiseLevelIndex; + p = *noiseLevelIndex; /*Q0*/ move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); IF( tmp >= 0 ) @@ -137,7 +137,7 @@ void minimumStatistics_fx( /*rescale noiseLevelMemory*/ setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); - p = *currLevelIndex; + p = *currLevelIndex; /*Q0*/ move16(); } ELSE @@ -147,7 +147,7 @@ void minimumStatistics_fx( /* current min is not a new min, so check if min must be re-searched */ 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 Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -164,7 +164,7 @@ void minimumStatistics_fx( move16(); } } - f = noiseLevelMemory[p]; + f = noiseLevelMemory[p]; /*Qx*/ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; move16(); @@ -172,10 +172,10 @@ void minimumStatistics_fx( } /* update local-minimum-value index and current circular-buffer index */ - *noiseLevelIndex = p; + *noiseLevelIndex = p; /*Q0*/ move16(); p = add( *currLevelIndex, 1 ); - *currLevelIndex = add( *currLevelIndex, 1 ); + *currLevelIndex = add( *currLevelIndex, 1 ); /*Q0*/ move16(); if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { @@ -183,7 +183,7 @@ void minimumStatistics_fx( move16(); } - *noiseEstimate = f; + *noiseEstimate = f; /*Qx*/ move16(); } @@ -226,15 +226,15 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ move16(); /*calculate headroom for dotproduct*/ - Hr16 = sub( 15, norm_s( lenLpcExc ) ); + Hr16 = sub( 15, norm_s( lenLpcExc ) ); /*Q0*/ 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 ) ); /*Q15*/ /*moved from inside loop, before synthesis*/ - h1Init[0] = mult_r( h1Init[0], tmp16 ); + h1Init[0] = mult_r( h1Init[0], tmp16 ); /*Q15*/ move16(); FOR( loop = 0; loop < numLoops; loop++ ) @@ -242,7 +242,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ set16_fx( h1, 0, lenLpcExc ); set16_fx( mem, 0, lpcorder ); - Copy( h1Init, h1, 1 ); + Copy( h1Init, h1, 1 ); /*Q15*/ /*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 ); @@ -250,10 +250,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* gain introduced by synthesis+deemphasis */ /*levelSynDeemphSub = (float)sqrt(dot_product( h1, h1, lenLpcExc));*/ - levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); + levelSynDeemphSub = Dot_product12_offs( h1, h1, lenLpcExc, &s16, 0 ); /*Q31 - s16*/ s16 = sub( shl( add( Q_h1, Hr16 ), 1 ), sub( 30, s16 ) ); - levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31*/ + levelSynDeemphSub = Sqrt32( levelSynDeemphSub, &s16 ); /*Q31 - s16*/ /* mean of the above across all subframes -- moved outta loop*/ /*levelSynDeemph += (1.0/(float)numLoops) * levelSynDeemphSub;*/ @@ -262,14 +262,14 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ if ( GT_16( numLoops, 1 ) ) { - tmp16 = div_s( 1, numLoops ); + tmp16 = div_s( 1, numLoops ); /*Q15*/ } 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 ); - *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + levelSynDeemph = L_shl( levelSynDeemph, s16 ); /*Q31*/ + *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ move16(); #ifdef BASOP_NOGLOB @@ -281,10 +281,10 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ /* 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 Q0*/ + Word16 *lpFiltAdapt, /* o : filter coefficients for filtering codebooks in case of flc Q15*/ + const Word16 type, /* i : type of filter, either 0 : lowpass or 1 : highpass Q0*/ + const Word16 alpha /* i : fade out factor [0 1) used decrease filter tilt Q15*/ ) { Word16 a, b, exp; @@ -305,17 +305,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 13107 /*0.4000f Q15*/, alpha ); + a = mult_r( 13107 /*0.4000f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -332,17 +332,17 @@ void genPlcFiltBWAdap_fx( } ELSE { - a = mult_r( 9218 /*0.2813f Q15*/, alpha ); + a = mult_r( 9218 /*0.2813f Q15*/, alpha ); /*Q15*/ exp = 0; move16(); - b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); - b = shr( b, sub( 1, exp ) ); - a = negate( mult_r( a, b ) ); - *lpFiltAdapt++ = a; + b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); /*Q15 - exp*/ + b = shr( b, sub( 1, exp ) ); /*Q15*/ + a = negate( mult_r( a, b ) ); /*Q15*/ + *lpFiltAdapt++ = a; /*Q15*/ move16(); - *lpFiltAdapt++ = b; + *lpFiltAdapt++ = b; /*Q15*/ move16(); - *lpFiltAdapt = a; + *lpFiltAdapt = a; /*Q15*/ move16(); } } @@ -355,11 +355,11 @@ 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 */ + const Word16 last_good, /* i: short last classification type Q0*/ + const Word16 L_buffer, /* i: int buffer length Q0*/ 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 l_fir_fer ) /* i: high pass filter length Q0*/ { Word16 i; /*int*/ @@ -368,7 +368,7 @@ void highPassFiltering_fx( { 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 ) ); /*Qx*/ move16(); } } @@ -391,9 +391,9 @@ Word16 GetPLCModeDecision_ivas_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -430,7 +430,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); if ( GT_16( st->nbLostCmpt, 1 ) ) { - core = st->last_core_bfi; + core = st->last_core_bfi; /*Q0*/ move16(); } IF( EQ_16( st->nbLostCmpt, 1 ) ) @@ -462,7 +462,7 @@ Word16 GetPLCModeDecision_ivas_fx( 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 ); /*Q16*/ } // TonalMDCTConceal_Detect_ivas_fx(&st->tonalMDCTconceal, pitch, &numIndices // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) @@ -503,7 +503,7 @@ Word16 GetPLCModeDecision_ivas_fx( } } } - return core; + return core; /*Q0*/ } #endif @@ -523,9 +523,9 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( st->nb_subfr * 2 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); - st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[( ( st->nb_subfr * 2 ) + 1 )] = L_deposit_h( st->guidedT0 ); /*Q16*/ move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ move16(); @@ -594,7 +594,7 @@ Word16 GetPLCModeDecision_fx( 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 ); /*Q16*/ } IF( st->element_mode == EVS_MONO ) { diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 21989d052..9af04d1f2 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -90,20 +90,20 @@ 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 Q12 */ - const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc */ - Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2 */ - Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2 */ + ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 *Aq, /* i : quantized Az Q12*/ + const Word16 *exc, /* i : excitation at 12.8 kHz Q_exc*/ + Word16 *synth, /* i : 12.8kHz synthesis signal Q_syn2*/ + Word16 *synth16k, /* o : 16kHz synthesis signal Q_syn2*/ const Word16 Q_exc, /* i : excitation scaling */ const Word16 Q_syn2, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /*i/o: HF synthesis memory */ + Word16 *delay_syn_hf, /*i/o: HF synthesis memory Q_syn2*/ 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 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { const Word16 *p_Aq; @@ -112,13 +112,13 @@ void hf_synth_fx( output_subfr = output_frame / NB_SUBFR; move16(); - p_Aq = Aq; + p_Aq = Aq; /* Q12 */ FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { hf_synthesis_fx( hBWE_zero, core_brate, output_subfr, p_Aq, &exc[i_subfr], Q_exc, &synth[i_subfr], &synth16k[imult3216( (Word32) i_subfr, output_subfr ) / L_SUBFR], Q_syn2, delay_syn_hf, memExp1, mem_hp_interp, extl, CNG_mode ); - p_Aq += ( M + 1 ); + p_Aq += ( M + 1 ); /* Q12 */ } return; @@ -176,19 +176,19 @@ void hf_synth_ivas_fx( static void hf_synthesis_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, - const Word32 core_brate, /* i : core bitrate */ - const Word16 output_subfr, /* i : output sub-frame length */ - const Word16 Aq[], /* i : quantized Az Q12 */ - const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc */ - const Word16 Q_exc, /* i : excitation scaling */ - Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn */ - Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn */ - const Word16 Q_syn, /* i : synthesis scaling */ - Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_subfr, /* i : output sub-frame length Q0*/ + const Word16 Aq[], /* i : quantized Az Q12*/ + const Word16 exc[], /* i : excitation at 12.8 kHz Q_exc*/ + const Word16 Q_exc, /* i : excitation scaling */ + Word16 synth[], /* i : 12.8kHz synthesis signal Q_syn*/ + Word16 synth16k[], /* i/o: 16kHz synthesis signal Q_syn*/ + const Word16 Q_syn, /* i : synthesis scaling */ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory Q_syn*/ Word16 *memExp1, /* o : HF excitation scaling exponent */ - Word16 *mem_hp_interp, /* i/o: interpol. memory */ - const Word16 extl, /* i : flag indicating BWE */ - const Word16 CNG_mode /* i : CNG_mode */ + Word16 *mem_hp_interp, /* i/o: interpol. memory Qx*/ + const Word16 extl, /* i : flag indicating BWE Q0*/ + const Word16 CNG_mode /* i : CNG_mode Q0*/ ) { Word16 i; @@ -219,22 +219,22 @@ static void hf_synthesis_fx( *-----------------------------------------------------------------*/ /*ener = sum2_f( exc, L_SUBFR ) + 0.01f*/ - ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); + ener = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp2 ) ); /* Q15 */ 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 ); + tmp = round_fx( L_tmp ); /* Q15 */ /* tmp = (float)(sqrt(ener/tmp)) */ /* scale is -1 if tmp > ener */ - scale = shr( sub( ener, tmp ), 15 ); - tmp = shl( tmp, scale ); + scale = shr( sub( ener, tmp ), 15 ); /* Q0 */ + tmp = shl( tmp, scale ); /* Q15 + scale*/ exp1 = sub( exp1, scale ); - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ exp1 = sub( exp1, exp2 ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp1 ); scale = round_fx( L_tmp ); /* Q18 when Q_exc=-1, HF_exc in Q-3 */ @@ -256,11 +256,11 @@ static void hf_synthesis_fx( /* i: synth in Q_syn */ /* o: synth in Q_syn-3 */ - L_tmp = L_mac( 1L, synth[0], synth[0] ); + L_tmp = L_mac( 1L, synth[0], synth[0] ); /* 2*(Q_syn-3)+1 */ 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] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i] ); #endif @@ -269,11 +269,11 @@ static void hf_synthesis_fx( 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] ); + L_tmp = L_mac( 1L, synth[1], synth[0] ); /* 2*(Q_syn-3)+1 */ 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] ); /* 2*(Q_syn-3)+1 */ #else L_tmp = L_mac( L_tmp, synth[i], synth[i - 1] ); #endif @@ -287,7 +287,7 @@ static void hf_synthesis_fx( tmp = s_max( 0, tmp ); if ( tmp > 0 ) { - tmp = div_s( tmp, ener ); + tmp = div_s( tmp, ener ); /* Q15 */ } /*-----------------------------------------------------------------* @@ -296,7 +296,7 @@ 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 /* 1 in Q15 */, tmp ), &Overflow ); #else tmp = add( 1, sub( 32767, tmp ) ); #endif @@ -306,7 +306,7 @@ static void hf_synthesis_fx( /* emphasize HF noise in CNG */ /*fac *= 2.0f;*/ #ifdef BASOP_NOGLOB - tmp = add_o( tmp, tmp, &Overflow ); + tmp = add_o( tmp, tmp, &Overflow ); /* Q15 */ #else tmp = add( tmp, tmp ); #endif @@ -347,10 +347,10 @@ static void hf_synthesis_fx( /* delay by 5 samples @16kHz to compensate CLDFB resampling delay (20samples) and HP filtering delay (roughly 15 samples) */ delay = NS2SA_FX2( 16000, DELAY_CLDFB_NS ) - 15; - Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); - Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); - Copy( delay_syn_hf, HF_syn, delay ); - Copy( temp_buffer, delay_syn_hf, delay ); + Copy( HF_syn + sub( L_SUBFR16k, delay ), temp_buffer, delay ); /* Q_syn+exp1 */ + Copy( HF_syn, HF_syn + delay, sub( L_SUBFR16k, delay ) ); /* Q_syn+exp1 */ + Copy( delay_syn_hf, HF_syn, delay ); /* Q_syn */ + Copy( temp_buffer, delay_syn_hf, delay ); /* Q_syn */ /* interpolate the HF synthesis */ IF( EQ_16( output_subfr, L_SUBFR48k ) ) /* 48kHz sampled output */ @@ -360,12 +360,12 @@ static void hf_synthesis_fx( 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 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qx + 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, 3 * L_SUBFR16k, -s ); /* Q_syn + exp1 + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } Scale_sig( upsampled_HF_syn, L_SUBFR48k, -1 ); } @@ -374,17 +374,17 @@ static void hf_synthesis_fx( { 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 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Q_syn+exp1+s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qx + 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 ); /* Q_syn + exp1 */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qx */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Q_syn+exp1 */ } } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Q_syn */ } Vr_add( synth16k, upsampled_HF_syn, synth16k, output_subfr ); @@ -630,11 +630,11 @@ 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 Qx*/ + Word16 lg, /* i : length of input Q0*/ + Word16 mem[], /* i/o: memory (size=30) exp*/ + Word16 fact, /* i : multiply factor Q0*/ + Word16 exp /* i : Mem Exponent */ ) { Word16 i, x[L_FRAME48k / NB_SUBFR + ( L_FIR - 1 )]; @@ -647,8 +647,8 @@ static void filt_6k_7k_scale_fx( 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 ); /* Qx - 2 */ + move16(); /* gain of filter = 4 */ } FOR( i = 0; i < lg; i++ ) { @@ -659,20 +659,20 @@ static void filt_6k_7k_scale_fx( 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 ); /* Q16 */ #else 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 ); /* Q0 */ move16(); #else signal[i] = round_fx( L_tmp ); #endif } - Copy( x + lg, mem, L_FIR - 1 ); + Copy( x + lg, mem, L_FIR - 1 ); /* Qx - 2 */ } /*-------------------------------------------------------------------* @@ -694,7 +694,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -702,7 +702,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -710,7 +710,7 @@ void hf_synth_amr_wb_init_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ ; return; } @@ -746,7 +746,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->frame_count_fx = 0; move16(); hAmrwb_IO->ne_min_fx = -7680; - move16(); /*Q8*/ + move16(); /*-30.0f in Q8*/ hAmrwb_IO->fmerit_m_sm_fx = 0; move16(); hAmrwb_IO->voice_fac_amr_wb_hf = 0; @@ -754,7 +754,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->unvoicing_fx = 0; move16(); hAmrwb_IO->unvoicing_sm_fx = 32767; - move16(); /*Q15*/ + move16(); /*1.0f in Q15*/ hAmrwb_IO->unvoicing_flag_fx = 0; move16(); hAmrwb_IO->voicing_flag_fx = 0; @@ -762,7 +762,7 @@ void hf_synth_amr_wb_reset_fx( hAmrwb_IO->start_band_old_fx = 160; move16(); hAmrwb_IO->OptCrit_old_fx = 32768; - move32(); /*Q15*/ + move32(); /*1.0f in Q15*/ return; } @@ -776,21 +776,21 @@ 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 */ + const Word32 core_brate, /* i : core bitrate Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + 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) Q0*/ + 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 Q0*/ + 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; @@ -824,11 +824,12 @@ void hf_synth_amr_wb_fx( Word32 exc32[L_FRAME], dct_exc32[L_FRAME], dct_hb32[L_FRAME16k], exc16k32[L_FRAME16k]; Word16 q_tmp; Word16 gamma; + move16(); - Scale_sig( synth, L_FRAME, -3 ); + Scale_sig( synth, L_FRAME, -3 ); /* Q_syn - 3 */ - pt1 = synth + 1; - pt2 = synth; + pt1 = synth + 1; /* Q_syn - 3 */ + pt2 = synth; /* Q_syn - 3 */ pt3 = til; pt4 = til0; FOR( i = 0; i < NB_SUBFR; i++ ) @@ -836,9 +837,9 @@ void hf_synth_amr_wb_fx( enr1 = Dot_product( pt2, pt2, L_SUBFR ); /*2*(Q_syn-3)+1 */ enr2 = Dot_product( pt1, pt2, L_SUBFR - 1 ); /*2*(Q_syn-3)+1 */ - tmp1 = extract_h( enr1 ); + tmp1 = extract_h( enr1 ); /*2*(Q_syn-3) - 15 */ tmp1 = s_max( 1, tmp1 ); - tmp2 = extract_h( enr2 ); + tmp2 = extract_h( enr2 ); /*2*(Q_syn-3) - 15 */ exp = norm_s( tmp1 ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(29-exp-2*(Q_syn-3)-1) */ @@ -852,7 +853,7 @@ void hf_synth_amr_wb_fx( pt2 += L_SUBFR; } - output_subfr = shr( output_frame, 2 ); + output_subfr = shr( output_frame, 2 ); /* Q0 */ if ( NE_16( *amr_io_class, 7 ) ) { @@ -863,8 +864,8 @@ void hf_synth_amr_wb_fx( /* modify LF parameters for excitation weighting or sub-frame gains calculating */ pitch_var_cur = 0; move16(); - pt6 = pitch_buf; - pt7 = pitch_buf + 1; + pt6 = pitch_buf; /* Q5 */ + pt7 = pitch_buf + 1; /* Q5 */ FOR( i = 0; i < 3; i++ ) { tmp1 = abs_s( sub( *pt6++, *pt7++ ) ); /*Q5 */ @@ -874,41 +875,41 @@ void hf_synth_amr_wb_fx( 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; + hAmrwb_IO->ne_min_fx = -7680; /* -30.0f in Q8 */ move16(); move16(); /*Q8; */ } ELSE { - hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); + hAmrwb_IO->frame_count_fx = s_min( hAmrwb_IO->frame_count_fx, 2 * FRAME_COUNT_HF_SYNTH - 1 ); /* Q0 */ move16(); - hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); + hAmrwb_IO->frame_count_fx = add( hAmrwb_IO->frame_count_fx, 1 ); /* Q0 */ move16(); - hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); + hAmrwb_IO->ne_min_fx = s_min( hAmrwb_IO->ne_min_fx, ng_ener_ST ); /* Q8 */ move16(); } pt6 = voice_factors; - L_tmp = L_mult( *pt6++, 4096 ); + L_tmp = L_mult( *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ FOR( i = 1; i < 4; i++ ) { - L_tmp = L_mac( L_tmp, *pt6++, 4096 ); + L_tmp = L_mac( L_tmp, *pt6++, 4096 /* 0.25 IN Q14 */ ); /* Q30 */ } - voice_fac = round_fx( L_tmp ); + voice_fac = round_fx( L_tmp ); /* Q14 */ /*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 /* 0.35 IN Q14 */ ); /* Q14 */ + fmerit_w = s_max( fmerit_w, 2458 /* 0.15 IN Q14 */ ); /* Q14 */ 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 ) ); /* Q14 */ #else L_tmp = L_mult( fmerit_w, add( 16384, voice_fac ) ); #endif @@ -920,17 +921,17 @@ void hf_synth_amr_wb_fx( move16(); - tmp1 = fmerit; + tmp1 = fmerit; /* Q14 */ move16(); - if ( LT_16( fmerit, 8192 ) ) + if ( LT_16( fmerit, 8192 /* 0.5 in Q14 */ ) ) { - tmp1 = 16384; + tmp1 = 16384; /* 1.0f in Q14 */ 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 */ move16(); - fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; + fmerit_m = hAmrwb_IO->fmerit_m_sm_fx; /* Q14 */ move16(); pt1 = til; @@ -940,15 +941,15 @@ void hf_synth_amr_wb_fx( tmp = s_and( tmp, *pt1 ); if ( tmp < 0 ) { - *pt1 = 1638; + *pt1 = 1638; /* 0.2 in Q13 */ move16(); } - tmp1 = sub( 8192, *pt1 ); - *pt1 = s_max( 6554, tmp1 ); + tmp1 = sub( 8192 /* 1.0 in Q13 */, *pt1 ); /* Q13 */ + *pt1 = s_max( 6554 /* 0.8 in Q13 */, tmp1 ); /* Q13 */ move16(); - tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 ); /*Q8 */ - tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ + tmp1 = add( hAmrwb_IO->ne_min_fx, 7680 /* 30.0 in Q30 */ ); /*Q8 */ + tmp1 = mult_r( tmp1, 7340 ); /*Q20 - > 0.007 //Q13 */ *pt1 = add( *pt1, tmp1 ); move16(); /*Q13 */ @@ -979,19 +980,19 @@ void hf_synth_amr_wb_fx( q_tmp = Exp16Array( L_FRAME, exc ); qdct = sub( q_tmp, 1 ); - Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); + Copy_Scale_sig_16_32( exc, exc32, L_FRAME, qdct ); /* Qexc + qdct */ 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 ); + Copy_Scale_sig_32_16( dct_exc32, dct_exc, L_FRAME, q_tmp ); /* qdct + qtmp */ qdct = add( qdct, q_tmp ); set16_fx( dct_hb, 0, L_FRAME16k ); - pt1 = &dct_hb[200]; - pt2 = &dct_exc[200]; + pt1 = &dct_hb[200]; /* qdct */ + pt2 = &dct_exc[200]; /* qdct */ FOR( i = 200; i < 240; i++ ) { *pt1++ = *pt2++; @@ -1014,10 +1015,10 @@ void hf_synth_amr_wb_fx( } 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 /* 0.00625f in Q15 */ ), 14 ); /*Q30 */ + tmp = round_fx( L_tmp ); /*Q14 */ + tmp = sub( 18022 /* 1.1f in Q14 */, 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 */ @@ -1027,15 +1028,15 @@ void hf_synth_amr_wb_fx( 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 /* 1.0f in Q14 */, 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 /* 0.95f in Q15 */ ); /*Q30 */ + gamma = round_fx( L_tmp ); /*Q14 */ + gamma = sub( 17203 /* 1.05f in Q14 */, gamma ); /*Q14 */ + gamma = s_min( 16384 /* 1.0f in Q14 */, gamma ); /* Q14 */ + gamma = s_max( 4915 /* 0.3f in Q14 */, gamma ); /* Q14 */ - IF( LT_16( beta, 16384 ) ) + IF( LT_16( beta, 16384 /* 1 in Q14 */ ) ) { L_tmp = 1; /*variable for tonal energy*/ move32(); @@ -1045,7 +1046,7 @@ void hf_synth_amr_wb_fx( pt3 = &dct_hb[240]; FOR( i = 0; i < 8; i++ ) { - fn = add( i, 8 ); + fn = add( i, 8 ); /* Q0 */ tmp1 = div_s( 1, fn ); /*Q15 */ tmp = 0; move16(); @@ -1060,11 +1061,11 @@ void hf_synth_amr_wb_fx( } *pt1 = round_fx( L_shl( L_mult( tmp, tmp1 ), 2 ) ); /*qdct */ move16(); - *pt2 = sub( *pt3, *pt1 ); + *pt2 = sub( *pt3, *pt1 ); /* qdct */ move16(); 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 ) ); /*2*qdct-2 */ } pt1++; pt2++; @@ -1072,8 +1073,8 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k - 8; i++ ) { - fb = sub( i, 7 ); - fn = add( fb, 15 ); + fb = sub( i, 7 ); /* Q0 */ + fn = add( fb, 15 ); /* Q0 */ tmp = 0; move16(); pt4 = &dct_hb[fb + 240]; @@ -1092,7 +1093,7 @@ void hf_synth_amr_wb_fx( 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 ) ); /*2*qdct-2 */ #else L_tmp = L_mac0( L_tmp, shr( *pt2, 1 ), shr( *pt2, 1 ) ); #endif @@ -1103,11 +1104,11 @@ void hf_synth_amr_wb_fx( } FOR( ; i < L_SUBFR16k; i++ ) { - fb = sub( i, 7 ); + fb = sub( i, 7 ); /* Q0 */ tmp = 0; move16(); - fn = sub( L_SUBFR16k, fb ); - tmp1 = div_s( 1, fn ); /*Q15 */ + fn = sub( L_SUBFR16k, fb ); /* Q0 */ + tmp1 = div_s( 1, fn ); /*Q15 */ pt4 = &dct_hb[fb + 240]; FOR( j = fb; j < L_SUBFR16k; j++ ) { @@ -1172,11 +1173,11 @@ void hf_synth_amr_wb_fx( 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 ); /* q2 */ + 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 */ #else @@ -1191,23 +1192,23 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_6k60 ) ) { - filt_weight_coeff = 60; + filt_weight_coeff = 60; /* Q0 */ move16(); rev_filt_weight_coeff = 555; move16(); /* 1/(filt_weight_coeff-1) Q15 */ } ELSE IF( EQ_32( core_brate, ACELP_8k85 ) ) { - filt_weight_coeff = 40; + filt_weight_coeff = 40; /* Q0 */ move16(); - rev_filt_weight_coeff = 840; + rev_filt_weight_coeff = 840; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } ELSE { - filt_weight_coeff = 20; + filt_weight_coeff = 20; /* Q0 */ move16(); - rev_filt_weight_coeff = 1725; + rev_filt_weight_coeff = 1725; /* 1/(filt_weight_coeff-1) Q15 */ move16(); } @@ -1223,7 +1224,7 @@ void hf_synth_amr_wb_fx( IF( EQ_32( core_brate, ACELP_23k85 ) ) { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ pt3 = filt_weight + tmp; FOR( i = 240; i < L_FRAME16k; i++ ) { @@ -1252,21 +1253,21 @@ void hf_synth_amr_wb_fx( { tmp = *pt6++; move16(); - *pt1++ = HP_gain_fx[tmp]; + *pt1++ = HP_gain_fx[tmp]; /* Q15 */ move16(); } } ELSE { pt1 = dct_hb + 240; - tmp = sub( filt_weight_coeff, 80 ); + tmp = sub( filt_weight_coeff, 80 ); /* Q0 */ 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( 19505, *pt1 ); + *pt1 = mult_r( 19505 /* 0.6 in Q15 */, *pt1 ); move16(); } @@ -1281,25 +1282,25 @@ void hf_synth_amr_wb_fx( pt1 = dct_hb + 200; pt6 = filt_hp_fx; - pt7 = deem_tab_fx; + pt7 = deem_tab_fx; /* Q15 */ FOR( i = 200; i < 256; i++ ) { *pt1 = mult_r( *pt6++, *pt1 ); move16(); /*qdct */ *pt1 = mult_r( *pt7++, *pt1 ); - move16(); + move16(); /* qdct */ 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 ); + Copy_Scale_sig_16_32( dct_hb, dct_hb32, L_FRAME16k, qhf ); /* qhf + qdct */ 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 ); + Copy_Scale_sig_32_16( exc16k32, exc16k, L_FRAME16k, q_tmp ); /* qhf + qtmp */ qhf = add( qhf, q_tmp ); ener = dot_prod_satcontr( exc, exc, Q_exc, Q_exc, &q1, L_FRAME ); @@ -1383,19 +1384,19 @@ 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 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 : Q_out*/ + Word16 *mem_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *delay_syn_hf, /* i/o: HF synthesis memory : Q_out*/ + Word16 *mem_hp_interp, /* i/o: interpol. memory : Q_out*/ + 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 : Qexc*/ const Word16 Q_exc, /*exc scaling*/ const Word16 Q_out, /*synth_out scaling*/ Word16 qhf /*exc16k scaling*/ @@ -1412,7 +1413,7 @@ static void hf_synthesis_amr_wb_fx( 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) */ + L_tmp = L_mult( ener, 6554 /* 0.2 in Q15 */ ); /*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); */ @@ -1463,14 +1464,14 @@ static void hf_synthesis_amr_wb_fx( scale = round_fx( Isqrt( L_shl( L_tmp, sub( q2, 24 ) ) ) ); /*Q12 */ #endif flag = negate( s_and( til, -0x8000 ) ); - if ( GT_16( scale, 4096 ) ) + if ( GT_16( scale, 4096 /* 1.0f in Q12 */ ) ) { flag = 1; move16(); } IF( flag ) { - Copy( exc2385, exc16k, L_SUBFR16k ); + Copy( exc2385, exc16k, L_SUBFR16k ); /* qhf */ } ELSE { @@ -1478,10 +1479,10 @@ static void hf_synthesis_amr_wb_fx( pt2 = exc2385; 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 = sub( 16348 /* 1 in Q14 */, shl( til, 1 ) ); /*Q14 */ + L_tmp = L_mult( tmp, sub( 26214 /* 1.6f in Q14 */, shr( voice_factors, 1 ) ) ); /*Q29*/ + tmp = round_fx( L_shr( L_tmp, 1 ) ); /*Q12*/ + tmp = s_min( tmp, 4096 /* 1 in Q12 */ ); tmp = s_max( tmp, scale ); *pt1++ = round_fx( L_shl( L_mult( *pt2++, tmp ), 3 ) ) /*qhf*/; move16(); @@ -1517,31 +1518,31 @@ static void hf_synthesis_amr_wb_fx( 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 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, s ); /* Qout + s */ 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( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); - Scale_sig( HF_syn, L_SUBFR16k, -s ); + Scale_sig( upsampled_HF_syn, L_SUBFR48k, add( -s, -1 ) ); /* Qout - 1 */ + Scale_sig( mem_hp_interp, INTERP_3_1_MEM_LEN, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } 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 ); + Scale_sig( HF_syn, L_SUBFR16k, s ); /* Qout + s */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, s ); /* Qout + 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 ); /* Qout */ + Scale_sig( mem_hp_interp, 2 * ALLPASSSECTIONS_STEEP, -s ); /* Qout */ + Scale_sig( HF_syn, L_SUBFR16k, -s ); /* Qout */ } ELSE /* 16kHz sampled output */ { - Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); + Copy( HF_syn, upsampled_HF_syn, L_SUBFR16k ); /* Qout */ } Vr_add( synth_out, upsampled_HF_syn, synth_out, output_subfr ); @@ -1550,15 +1551,15 @@ 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 qq_fx, /* Qx */ + const Word16 pp_fx, /* Qx */ + const Word16 tilt0_fx, /* i : spectrum tilt Q13*/ + const Word16 tilt_fx, /* i : spectrum tilt Q13*/ + const Word16 voice_factor_fx, /* i : voice factor Q15*/ + Word16 *voice_fac_fx, /* i/o: smoothed voiced parameter Q15*/ + Word16 *unvoicing_fx, /* i/o: unvoiced parameter Q15*/ + Word16 *unvoicing_sm_fx, /* i/o: smoothed unvoiced parameter Q15*/ + Word16 *unvoicing_flag /* i/o: unvoiced flag Q0*/ ) { Word16 unvoicing_tmp_fx; @@ -1571,41 +1572,41 @@ 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 /* 0.75 in Q15 */ ), voice_factor_fx, 8192 /* 0.25 in Q15 */ ) ); /*Q15 */ move16(); - tmp = mult_r( sub( 8192, tilt0_fx ), 16384 ); /*Q13 */ + tmp = mult_r( sub( 8192 /* 1.0f in Q13 */, tilt0_fx ), 16384 /* 1.0f in Q15 */ ); /*Q13 */ - L_tmp = L_sub( 32768, *voice_fac_fx ); /*Q15 */ + L_tmp = L_sub( 32768 /* 1.0 in Q15 */, *voice_fac_fx ); /*Q15 */ 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 = s_min( tmp1, 8192 /* 1.0f in Q13 */ ); 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 /* 0.5 in Q15 */, *unvoicing_fx ), 16384 /* 0.5 in Q15 */, unvoicing_tmp_fx ) ); /*Q15 */ move16(); 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 /* 0.9 in Q15 */, *unvoicing_sm_fx ), 3277 /* 0.1 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } 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 /* 0.99 in Q15 */, *unvoicing_sm_fx ), 328 /* 0.01 in Q15 */, *unvoicing_fx ) ); /*Q15 */ move16(); } #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 /* 0.1 in Q15 */ ) ) #else if ( GT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 3277 ) ) #endif @@ -1615,7 +1616,7 @@ static Word16 EnhanceClass_fx( } #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 /* 0.05 in Q15 */ ) ) #else if ( LT_16( sub( *unvoicing_fx, *unvoicing_sm_fx ), 1638 ) ) #endif @@ -1629,13 +1630,13 @@ static Word16 EnhanceClass_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 Q0*/ + const Word16 Aq_dyn_scal[], /* i : de-quant. LPC coefficents, dynamic scaling Q12*/ + 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*/ ) { @@ -1654,7 +1655,7 @@ static void envelope_fx( /* 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 ); + Copy_Scale_sig( Aq_dyn_scal, Aq, M + 1, shift ); /* Q12 + shift */ /* LPC envelope weighting */ IF( EQ_32( core_brate, ACELP_6k60 ) ) @@ -1670,17 +1671,17 @@ static void envelope_fx( shift = sub( norm_s( Ap[0] ), 2 ); IF( shift != 0 ) { - Scale_sig( Ap, M + 1, shift ); + Scale_sig( Ap, M + 1, shift ); /* Q12 + shift */ } /* LPC envelope level estimate */ L_tmp = 0; move32(); - pt1 = Ap; - pt2 = exp_tab_p_fx; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1688,11 +1689,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = Ap; - pt2 = exp_tab_p_fx + 33; + pt1 = Ap; /* Q12 */ + pt2 = exp_tab_p_fx + 33; /* Q14 */ FOR( i = 0; i <= M; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1710,12 +1711,12 @@ static void envelope_fx( py = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q1)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx; /* Q14 */ 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++ ); /* Q27 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3++ ); #endif @@ -1725,12 +1726,12 @@ static void envelope_fx( rx = round_fx( L_shr( L_tmp, 1 ) ); /*Q(10+q2)*/ L_tmp = L_deposit_l( 0 ); - pt2 = Aq; - pt3 = exp_tab_q_fx + 33; + pt2 = Aq; /* Q12 */ + pt3 = exp_tab_q_fx + 33; /* Q14 */ 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-- ); /* Q14 */ #else L_tmp = L_mac( L_tmp, *pt2++, *pt3-- ); #endif @@ -1765,21 +1766,21 @@ static void envelope_fx( 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 ) ) + IF( EQ_16( shr( As[2], 1 ), -2048 /* -1.0f in Q11 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); if ( As[1] < 0 ) { - k1 = -k1; + k1 = -k1; /* Q12 */ move16(); } } ELSE { - k1 = add( 2048, shr( As[2], 1 ) ); /*Q11 */ + k1 = add( 2048 /* 1 in Q11 */, shr( As[2], 1 ) ); /*Q11 */ q1 = 11; move16(); q2 = norm_s( k1 ); @@ -1801,28 +1802,28 @@ static void envelope_fx( #endif k2 = As[2]; move16(); /*Q12 */ - if ( GT_16( k2, 2458 ) ) + if ( GT_16( k2, 2458 /* 0.6f in Q12 */ ) ) { - k2 = 2458; + k2 = 2458; /* 0.6f in Q12 */ move16(); } - if ( LT_16( k2, -2458 ) ) + if ( LT_16( k2, -2458 /* -0.6f in Q12 */ ) ) { - k2 = -2458; + k2 = -2458; /* -0.6f in Q12 */ move16(); } - if ( GT_16( k1, 4055 ) ) + if ( GT_16( k1, 4055 /* 0.99f in Q12 */ ) ) { - k1 = 4055; + k1 = 4055; /* 0.99f in Q12 */ move16(); } - if ( LT_16( k1, -4055 ) ) + if ( LT_16( k1, -4055 /* -0.99f in Q12 */ ) ) { - k1 = -4055; + k1 = -4055; /* -0.99f in Q12 */ move16(); } } - As[1] = add( 4096, k2 ); + As[1] = add( 4096 /* 1 in Q12 */, k2 ); move16(); L_tmp = L_mult( As[1], k1 ); /*Q25 */ As[1] = round_fx( L_shl( L_tmp, 3 ) ); /*Q12 */ @@ -1831,11 +1832,11 @@ static void envelope_fx( move16(); /*Q12 */ L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2++ ); /* Q27 */ } q1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q1 ); /*Q(27+q1)*/ @@ -1843,11 +1844,11 @@ static void envelope_fx( L_tmp = L_deposit_l( 0 ); - pt1 = As; - pt2 = exp_tab_q_fx + 33; + pt1 = As; /* Q12 */ + pt2 = exp_tab_q_fx + 33; /* Q14 */ FOR( i = 0; i < 3; i++ ) { - L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); + L_tmp = L_mac( L_tmp, *pt1++, *pt2-- ); /* Q27 */ } q2 = norm_l( L_tmp ); shift = sub( q1, q2 ); @@ -1865,11 +1866,11 @@ static void envelope_fx( 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 ); + L_tmp = L_mult( qx, qx ); /* Q21 + 2q1 */ + L_tmp = L_mac( L_tmp, qy, qy ); /* Q21 + 2q1 */ 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 ); + 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 ); /* Q0 */ alpha = 0; move16(); IF( Unvoicing_flag ) @@ -1886,31 +1887,31 @@ static void envelope_fx( 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 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); - 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, rr ); /*Q23*/ + rr = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ + L_tmp = L_mult( tilt, sub( 26214 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_max( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ #ifdef BASOP_NOGLOB qq = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); /*Q10*/ #else 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 ); /* Q10 */ + rr = s_max( rr, pp ); /* Q10 */ } ELSE { test(); - IF( LT_16( rr, 1024 ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 ) ) + IF( LT_16( rr, 1024 /* 1 in Q10 */ ) && LT_16( ( hAmrwb_IO->prev_r_fx ), 1024 /* 1 in Q10 */ ) ) { L_tmp = L_mult( rr, rr ); /*Q21*/ tmp = round_fx( L_shl( L_tmp, 9 ) ); /*Q14*/ - L_tmp = L_sub( 2097152, L_tmp ); /*Q21*/ + L_tmp = L_sub( 2097152 /* 1 in Q21 */, 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*/ @@ -1924,9 +1925,9 @@ static void envelope_fx( 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 /* 1.6f in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ - L_tmp = L_min( L_tmp, 268435456 ); + L_tmp = L_min( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, qq ); /*Q23*/ est_level1 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1935,8 +1936,8 @@ static void envelope_fx( 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 = L_mult( abs_s( sub( tilt, 8192 /* 1 in Q13 */ ) ), sub( 26214 /* 1.6 in Q14 */, shr( voice_factor, 1 ) ) ); /*Q28*/ + L_tmp = L_add( L_tmp, 268435456 /* 1 in Q28 */ ); L_tmp = Mult_32_16( L_tmp, rr ); /*Q23*/ est_level2 = round_fx( L_shl( L_tmp, 3 ) ); /*Q10*/ @@ -1949,7 +1950,7 @@ static void envelope_fx( 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 /* 5.0f in Q12 */, round_fx_sat( L_shl_sat( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ move16(); #else *sub_gain = s_min( 20480, round_fx( L_shl( L_tmp, sub( q1, 2 ) ) ) ); /*Q12 */ @@ -1963,15 +1964,15 @@ static void envelope_fx( * adaptively select the start band of bandwidth extension *---------------------------------------------------------------------*/ -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 *voicing_flag, - Word16 *start_band_old, - Word32 *OptCrit_old_fx /*i/o : Q15 */ +static void AdaptiveStartBand_fx( + Word16 *start_band, /* o : start point of copied band Q0*/ + const Word32 core_rate, /* i : core bitrate Q0*/ + const Word16 *lsf_fx, /* i : lsf frequency Q2*/ + const Word16 voicing_fac_fx, /* i : voicing factors Q14*/ + const Word16 clas, /* i : signal class (determined by FEC algorithm) Q0*/ + Word16 *voicing_flag, /* Q0 */ + Word16 *start_band_old, /* Q0 */ + Word32 *OptCrit_old_fx /*i/o : Q15 */ ) { Word16 i, pos, M2, voicing_flag_old; @@ -1985,19 +1986,19 @@ void AdaptiveStartBand_fx( move32(); // corresponding to initialization of OptCrit_fx /*voicing switching flag : to avoid switching start band frequently in VOICED or AUDIO area*/ - voicing_flag_old = *voicing_flag; + voicing_flag_old = *voicing_flag; /* Q0 */ move16(); 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 /* 0.4 in Q14 */ ) || ( GT_16( voicing_fac_fx, 4915 /* 0.3 in Q14 */ ) && GE_16( clas, VOICED_CLAS ) ) || EQ_16( clas, AUDIO_CLAS ) ) { - *voicing_flag = 1; + *voicing_flag = 1; /* Q0 */ move16(); } test(); - if ( LT_16( voicing_fac_fx, 3277 ) && LT_16( clas, VOICED_CLAS ) ) + if ( LT_16( voicing_fac_fx, 3277 /* 0.2 in Q14 */ ) && LT_16( clas, VOICED_CLAS ) ) { *voicing_flag = 0; move16(); @@ -2016,14 +2017,14 @@ void AdaptiveStartBand_fx( *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 /* 0.00005 in Q29 */ ) ); /*Q14 */ + L_tmp = L_shr( L_mult0( tmp1, 22370 /* 1/6000 in Q27 */ ), 15 ); /*Q27->1/6000 ->Q26 */ + tmp2 = extract_l( L_tmp ); /*Q26 */ + W_fx = mult_r( tmp1, tmp2 ); /*Q25 */ IF( EQ_16( clas, AUDIO_CLAS ) ) { - W_fx = mult_r( W_fx, 24576 ); /*Q25 */ + W_fx = mult_r( W_fx, 24576 /* 0.75 in Q15 */ ); /*Q25 */ } pos = 2; @@ -2050,8 +2051,8 @@ void AdaptiveStartBand_fx( } /*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 /* 1 in Q2.56+25+1 */, lsf_fx[2], W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* 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 ); pos = 2; @@ -2062,37 +2063,37 @@ void AdaptiveStartBand_fx( pt1 = &lsf_diff_fx[3]; FOR( i = 3; i < M2; i++ ) { - L_tmp = L_max( L_msu( 171798692, *pt2++, W_fx ), 171799 ); /* Q2.56+25+1 */ + L_tmp = L_max( L_msu( 171798692 /* 1 in Q2.56+25+1 */, *pt2++, W_fx ), 171799 /* 0.001 in Q2.56+25+1 */ ); /* Q2.56+25+1 */ Crit_fx = Mult_32_16( L_tmp, *pt1++ ); /* Q2.56+25+1+2.56-15 = Q11+2.56+2.56 */ IF( LE_32( Crit_fx, OptCrit_fx ) ) { OptCrit_fx = L_add( Crit_fx, 0 ); /* Q11+2.56+2.56 */ - pos = i; + pos = i; /* Q0 */ move16(); } } - tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); - *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); + tmp1 = add( mult_r( lsf_fx[pos - 1], 256 ), mult_r( lsf_fx[pos], 256 ) ); /* Q0 */ + *start_band = s_min( s_max( sub( tmp1, 40 ), 40 ), 160 ); /* Q0 */ move16(); - L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 ); /* Q11+2.56+2.56 */ + L_tmp = Mult_32_16( *OptCrit_old_fx, 22938 /* 0.7 in Q15 */ ); /* Q11+2.56+2.56 */ test(); test(); test(); test(); 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 ) ) ) + ( LT_32( OptCrit_fx, L_tmp ) && GT_32( *OptCrit_old_fx, 858993 /* 64 in Q11+2.56+2.56 */ ) ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ 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 ) ) { - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } } @@ -2101,29 +2102,29 @@ void AdaptiveStartBand_fx( test(); if ( LT_32( OptCrit_fx, ( *OptCrit_old_fx ) ) && EQ_16( ( *voicing_flag ), 1 ) ) { - *OptCrit_old_fx = OptCrit_fx; + *OptCrit_old_fx = OptCrit_fx; /* Q15 */ move16(); } - *start_band = *start_band_old; + *start_band = *start_band_old; /* Q0 */ move16(); } IF( EQ_16( clas, AUDIO_CLAS ) ) { - *start_band = s_min( *start_band, 120 ); + *start_band = s_min( *start_band, 120 ); /* Q0 */ move16(); } flag = sub( s_and( *start_band, 0x0001 ), 1 ); IF( flag == 0 ) { - *start_band = sub( *start_band, 1 ); + *start_band = sub( *start_band, 1 ); /* Q0 */ move16(); } } - *start_band_old = *start_band; + *start_band_old = *start_band; /* Q0 */ move16(); return; diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index ace2e535c..e67d5f663 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -26,11 +26,11 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } test(); @@ -38,21 +38,21 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_SPEC48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); + *hqswb_clas = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -62,7 +62,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -71,12 +71,12 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } ELSE IF( EQ_16( length, L_SPEC48k ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } @@ -97,11 +97,11 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits Word16 bits; Word32 max_brate; - max_brate = HQ_32k; + max_brate = HQ_32k; /* Q0 */ move32(); if ( st_fx->element_mode > EVS_MONO ) { - max_brate = HQ_48k; + max_brate = HQ_48k; /* Q0 */ move32(); } #ifndef SOLVED_COMP_ENC_DEC @@ -116,21 +116,21 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits 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 ); + *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); } ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 0; move16(); move16(); } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); + *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); @@ -140,7 +140,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits move16(); if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) { - *is_transient = 1; + *is_transient = 1; /* Q0 */ move16(); } @@ -149,7 +149,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits { IF( EQ_16( length, L_SPEC32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #ifndef SOLVED_COMP_ENC_DEC @@ -158,7 +158,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits ELSE IF( EQ_16( length, L_SPEC48k ) ) #endif { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_conf_fec_fx.c b/lib_dec/hq_conf_fec_fx.c index dfc19c542..adcd83076 100644 --- a/lib_dec/hq_conf_fec_fx.c +++ b/lib_dec/hq_conf_fec_fx.c @@ -16,22 +16,22 @@ * 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 Q0*/ + const Word16 **sfm_start, /* o : Subband start coefficients Q0*/ + const Word16 **sfm_end /* o : Subband end coefficients Q0*/ ) { - *num_Sb = MAX_SB_NB; + *num_Sb = MAX_SB_NB; /* Q0 */ move16(); - *nb_sfm = SFM_N_NB; + *nb_sfm = SFM_N_NB; /* Q0 */ move16(); - Copy( Num_bands_NB, num_bands_p, *num_Sb ); - *sfmsize = band_len_wb; - *sfm_start = band_start_wb; - *sfm_end = band_end_wb; + Copy( Num_bands_NB, num_bands_p, *num_Sb ); /* Q0 */ + *sfmsize = band_len_wb; /* Q0 */ + *sfm_start = band_start_wb; /* Q0 */ + *sfm_end = band_end_wb; /* Q0 */ move16(); move16(); move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 9ff889997..de8d19e32 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -19,11 +19,11 @@ void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ 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 */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -62,15 +62,17 @@ void hq_core_dec_fx( move16(); sfm_start = sfm_end = NULL; num_Sb = nb_sfm = 0; + move16(); + move16(); - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); 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; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding @@ -114,18 +116,18 @@ void hq_core_dec_fx( } #endif /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* 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 ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -133,7 +135,7 @@ void hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -145,10 +147,10 @@ void hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifndef ADD_IVAS_HQ_CODE_L_SPEC - L_spec = inner_frame; + L_spec = inner_frame; /* Q0 */ #endif move16(); @@ -174,7 +176,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -189,22 +191,22 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); 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 ); /* Q0 */ - 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 ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ 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 Q0*/ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -222,7 +224,7 @@ void hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -251,8 +253,8 @@ void hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -280,7 +282,7 @@ void hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15 */ } ELSE { @@ -291,11 +293,11 @@ void hq_core_dec_fx( { 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 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -304,7 +306,7 @@ void hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -315,11 +317,11 @@ void hq_core_dec_fx( /* WB/SWB bandwidth switching */ 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 ); /* -1Q */ } 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 ); /* -1Q */ } @@ -421,7 +423,7 @@ void hq_core_dec_fx( test(); 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 ) ); /* 15 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -499,7 +501,7 @@ void hq_core_dec_fx( 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 ); /* Q14 + Q_synth */ move16(); #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); @@ -526,7 +528,7 @@ void hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -548,9 +550,9 @@ void hq_core_dec_fx( 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 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -558,11 +560,11 @@ void hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ move16(); if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -572,9 +574,9 @@ void hq_core_dec_fx( { 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 ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ 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 ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } #ifdef ADD_IVAS_HQ_CODE @@ -590,12 +592,12 @@ void hq_core_dec_fx( void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ + Word16 synth[], /* o : output synthesis Q_synth*/ 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 output[], + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag Q0*/ + Word16 output[], /* Q_ouput */ Word16 *Q_output ) { Word16 num_bits, is_transient, hqswb_clas, inner_frame; @@ -656,14 +658,14 @@ void ivas_hq_core_dec_fx( hTcxDec = st_fx->hTcxDec; - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; + st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ move16(); 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; /* Q0 */ move16(); } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); test(); test(); @@ -678,7 +680,7 @@ void ivas_hq_core_dec_fx( num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ /* Set default spectrum length */ - L_spec = l_spec_tbl[st_fx->bwidth]; + L_spec = l_spec_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( !st_fx->bfi ) { @@ -686,7 +688,7 @@ void ivas_hq_core_dec_fx( { IF( NE_16( st_fx->element_mode, EVS_MONO ) ) { - L_spec = l_spec_ext_tbl[st_fx->bwidth]; + L_spec = l_spec_ext_tbl[st_fx->bwidth]; /* Q0 */ move16(); } ELSE @@ -706,18 +708,18 @@ void ivas_hq_core_dec_fx( acelp_plc_mdct_transition_fx( st_fx ); } /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); + num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ /* 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 ) ) { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } ELSE { @@ -725,7 +727,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = 1; + hHQ_core->HqVoicing = 1; /* Q0 */ move16(); } } @@ -737,7 +739,7 @@ void ivas_hq_core_dec_fx( } /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); IF( EQ_16( st_fx->bfi, 0 ) ) @@ -746,7 +748,7 @@ void ivas_hq_core_dec_fx( move16(); if ( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; /* Q0 */ move16(); } } @@ -762,7 +764,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient[0]; + is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { @@ -777,22 +779,22 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ move16(); 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 ); /* Q0 */ - 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 ); + Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* q_previoussynth */ + Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* q_delay_buff */ 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 Q0*/ move16(); set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } @@ -811,7 +813,7 @@ void ivas_hq_core_dec_fx( /* HQ low rate decoder */ hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; + hqswb_clas = is_transient; /* Q0 */ move16(); Q_audio = 12; move16(); @@ -843,8 +845,8 @@ void ivas_hq_core_dec_fx( } ELSE { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; + tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ + ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ move16(); FOR( i = 0; i < inner_frame; i++ ) { @@ -872,7 +874,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { ener_match = 32767; - move16(); /*Q15*/ + move16(); /* 1.0f in Q15*/ } ELSE { @@ -883,11 +885,11 @@ void ivas_hq_core_dec_fx( { 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 ); j < tmp_loop; j++ ) + tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); /* Q0 */ + FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 ); /*Q0*/ + tmp = i_mult( i, inner_frame ); /*Q0*/ + tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ tmp = add( tmp, j ); t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); move32(); /*Q12*/ @@ -896,7 +898,7 @@ void ivas_hq_core_dec_fx( } ELSE { - FOR( i = inner_frame_tbl[sub( st_fx->bwidth, 1 )]; i < inner_frame; i++ ) + FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) { t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ move32(); @@ -907,11 +909,11 @@ void ivas_hq_core_dec_fx( /* WB/SWB bandwidth switching */ 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 ); /* -1Q */ } 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 ); /* -1Q */ } @@ -926,34 +928,34 @@ void ivas_hq_core_dec_fx( { /* Initializations for TCX MDCT framework, to be used for switching frame */ tcx_cfg = st_fx->hTcxCfg; - L_frameTCX_glob = hTcxDec->L_frameTCX; + L_frameTCX_glob = hTcxDec->L_frameTCX; /* Q0 */ move16(); - L_frame_glob = st_fx->L_frame; + L_frame_glob = st_fx->L_frame; /* Q0 */ move16(); - L_spec = hTcxDec->L_frameTCX; + L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ // 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 ); + mdctWindowLength = getMdctWindowLength( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); - mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); + mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ IF( core_switching_flag ) { - tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; + tcx_cfg->tcx_last_overlap_mode = TRANSITION_OVERLAP; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; + tcx_cfg->tcx_curr_overlap_mode = FULL_OVERLAP; /* Q0 */ move16(); } ELSE { - tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; + tcx_cfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ move16(); - st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame */ + st_fx->last_core = HQ_CORE; /* Needed to decode non-transition frame Q0*/ move16(); } @@ -961,11 +963,11 @@ void ivas_hq_core_dec_fx( init_tcx_info_fx( st_fx, L_frame_glob, L_frameTCX_glob, 0, st_fx->bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); - overlap = tcx_cfg->tcx_mdct_window_length; + overlap = tcx_cfg->tcx_mdct_window_length; /* Q0 */ move16(); - overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; + overlapFB = tcx_cfg->tcx_mdct_window_lengthFB; /* Q0 */ move16(); - index = tcx_cfg->tcx_last_overlap_mode; + index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); #ifndef MSAN_FIX @@ -978,9 +980,9 @@ void ivas_hq_core_dec_fx( left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_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 ); + Scale_sig( wtda_audio_16 + L_frame, overlap, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); + Copy( wtda_audio_16 + sub( shr( overlap, 1 ), tcx_offset ), output, L_frame_glob ); /* q_wtda + 1 */ /* FB synthesis */ temp = BASOP_Util_Divide3232_Scale( L_mult0( FSCALE_DENOM, L_frameTCX_glob ), L_frame_glob, &temp_e ); @@ -988,14 +990,14 @@ void ivas_hq_core_dec_fx( 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, shr( s_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, temp, acelp_zir ); - Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); + Scale_sig( wtda_audio_16 + L_frameTCX, overlapFB, Q1 ); /* q_wtda + 1 */ - Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); + Copy( wtda_audio_16 + sub( shr( overlapFB, 1 ), tcx_offsetFB ), synth, L_frameTCX_glob ); /* q_wtda */ - Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); + Copy_Scale_sig_16_32( wtda_audio_16, wtda_audio, 2 * L_FRAME48k, 12 ); /* q_wtda + 12 */ IF( !core_switching_flag ) { - st_fx->last_core = ACELP_CORE; /* Restore last core */ + st_fx->last_core = ACELP_CORE; /* Restore last core Q0*/ move16(); } } @@ -1036,9 +1038,9 @@ void ivas_hq_core_dec_fx( tmp = Sqrt16( tmp, &tmp_e ); ener_match = shr( tmp, sub( 2, tmp_e ) ); // Q13 - v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q + v_multc_fixed_16( t_audio_q, ener_match, t_audio_q, inner_frame ); // Q10 - Scale_sig32( t_audio_q, inner_frame, Q2 ); + Scale_sig32( t_audio_q, inner_frame, Q2 ); // Q10 + Q2 Q_audio = Q_G_audio; move16(); Inverse_Transform( t_audio_q, &Q_audio, wtda_audio_LB, is_transient, st_fx->L_frame, inner_frame, st_fx->element_mode ); @@ -1052,7 +1054,7 @@ void ivas_hq_core_dec_fx( test(); IF( EQ_16( 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 ) ); /* 31 - exp_old_out - Q_old_wtda */ } ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { @@ -1129,7 +1131,7 @@ void ivas_hq_core_dec_fx( 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 ) ) && EQ_16( 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 ); /* Q15 */ #else st_fx->plcInfo.recovery_gain = shl( st_fx->plcInfo.recovery_gain, *Q_synth ); #endif @@ -1155,7 +1157,7 @@ void ivas_hq_core_dec_fx( { hHQ_core->oldHqVoicing = 1; move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); + Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ } ELSE { @@ -1177,9 +1179,9 @@ void ivas_hq_core_dec_fx( 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 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* Q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ @@ -1187,10 +1189,10 @@ void ivas_hq_core_dec_fx( { Word16 nbsubfr; /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; + nbsubfr = 4; /* Q0 */ if ( EQ_16( st_fx->L_frame, 320 ) ) { - nbsubfr = 5; + nbsubfr = 5; /* Q0 */ move16(); } @@ -1200,16 +1202,16 @@ void ivas_hq_core_dec_fx( { 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 ); + Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ 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 ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ IF( st_fx->element_mode > EVS_MONO ) { - Copy_Scale_sig( output, tmp_out, st_fx->L_frame, -( *Q_output ) ); - Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); + Copy_Scale_sig( output, tmp_out, st_fx->L_frame, negate( *Q_output ) ); /* Q0 */ + Copy( tmp_out, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame ); /* Q0 */ } return; } @@ -1238,7 +1240,7 @@ void HQ_core_dec_init_fx( move16(); move16(); - hHQ_core->last_hq_core_type = -1; + hHQ_core->last_hq_core_type = -1; /* Q0 */ move16(); set16_fx( hHQ_core->old_is_transient, 0, 3 ); @@ -1251,7 +1253,7 @@ void HQ_core_dec_init_fx( move16(); move16(); move16(); - hHQ_core->energy_lt_fx = 2457600; /*Q13*/ + hHQ_core->energy_lt_fx = 2457600; /*300.0f in 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; @@ -1281,7 +1283,7 @@ void HQ_core_dec_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ + hHQ_core->prev_ni_ratio_fx = 16384; /*0.5 in Q15*/ move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); @@ -1309,9 +1311,9 @@ void HQ_core_dec_init_fx( 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; move16(); - set16_fx( hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX ); + set16_fx( hHQ_core->mag_chg_1st_fx, 32767 /* 1.0f in Q15 */, LGW_MAX ); set16_fx( hHQ_core->Xavg_fx, 0, LGW_MAX ); - hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; + hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; /* Q15 */ hHQ_core->last_fec = 0; hHQ_core->ph_ecu_HqVoicing = 0; hHQ_core->oldHqVoicing = 0; @@ -1343,7 +1345,7 @@ void HQ_nbfec_init_fx( { Word16 i, j; - hHQ_nbfec->prev_last_core = -1; + hHQ_nbfec->prev_last_core = -1; /* Q0 */ hHQ_nbfec->diff_energy_fx = 0; hHQ_nbfec->stat_mode_out = 0; hHQ_nbfec->stat_mode_old = 0; diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index 81385aaaa..677221f31 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -14,15 +14,15 @@ * Decode envelope indices *------------------------------------------------------------------------*/ -Word16 decode_envelope_indices_fx( /* o : Number of bits */ +Word16 decode_envelope_indices_fx( /* o : Number of bits Q0*/ 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 start_norm, /* i : starting band index Q0*/ + const Word16 num_sfm, /* i : Number of subbands Q0*/ + const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0*/ + Word16 *difidx, /* o : Diff indices/encoded diff indices Q0*/ + const Word16 flag_HQ2 /* i : indicator of HQ2 core Q0*/ , - const Word16 is_transient /* i : indicator of HQ_TRANSIENT */ + const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0*/ ) { Word16 hcode_l; @@ -34,14 +34,14 @@ Word16 decode_envelope_indices_fx( /* o : Number of b test(); IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) { - LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); + LCmode = (Word16) get_next_indice_fx( st_fx, BITS_DE_HMODE ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, BITS_DE_FCOMP ); /* Q0 */ move16(); } ELSE { - LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); - difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); + LCmode = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ + difidx[start_norm] = (Word16) get_next_indice_fx( st_fx, NORM0_BITS ); /* Q0 */ move16(); } @@ -53,10 +53,10 @@ Word16 decode_envelope_indices_fx( /* o : Number of b IF( EQ_16( LCmode, 1 ) ) { hdecnrm_tran_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - j = add( start_norm, num_sfm ); + j = add( start_norm, num_sfm ); /* Q0 */ 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]] ); /* Q0 */ } } ELSE @@ -74,68 +74,68 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } ELSE IF( EQ_16( LCmode, 1 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ 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] ); /* Q0 */ } - pDifidx1 = &difidx[startNormPlus1]; + pDifidx1 = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus2 = sub( num_sfm, 2 ); + numSfmMinus2 = sub( num_sfm, 2 ); /* Q0 */ FOR( i = 0; i < numSfmMinus2; i++ ) { - pDifidx = pDifidx1++; + pDifidx = pDifidx1++; /* Q0 */ move16(); IF( GT_16( *pDifidx, 17 ) ) { - offset = sub( *pDifidx, 17 ); - offset = s_min( offset, 3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 17 ); /* Q0 */ + offset = s_min( offset, 3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } ELSE IF( LT_16( *pDifidx, 13 ) ) { - offset = sub( *pDifidx, 13 ); - offset = s_max( offset, -3 ); - *pDifidx1 = sub( *pDifidx1, offset ); + offset = sub( *pDifidx, 13 ); /* Q0 */ + offset = s_max( offset, -3 ); /* Q0 */ + *pDifidx1 = sub( *pDifidx1, offset ); /* Q0 */ move16(); } } } ELSE IF( EQ_16( LCmode, 2 ) ) { - startNormPlus1 = add( start_norm, 1 ); + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); - pDifidx = &difidx[startNormPlus1]; + pDifidx = &difidx[startNormPlus1]; /* Q0 */ move16(); - numSfmMinus1 = sub( num_sfm, 1 ); + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - j = *pDifidx++; + j = *pDifidx++; /* Q0 */ move16(); - hcode_l = add( hcode_l, huffsizn[j] ); + hcode_l = add( hcode_l, huffsizn[j] ); /* Q0 */ } } ELSE { - startNormPlus1 = add( start_norm, 1 ); - numSfmMinus1 = sub( num_sfm, 1 ); - pDifidx = &difidx[startNormPlus1]; + startNormPlus1 = add( start_norm, 1 ); /* Q0 */ + numSfmMinus1 = sub( num_sfm, 1 ); /* Q0 */ + pDifidx = &difidx[startNormPlus1]; /* Q0 */ FOR( i = 0; i < numSfmMinus1; i++ ) { - *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); + *pDifidx++ = (Word16) get_next_indice_fx( st_fx, NORMI_BITS ); /* Q0 */ move16(); } - hcode_l = numnrmibits; + hcode_l = numnrmibits; /* Q0 */ move16(); } } @@ -152,12 +152,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b *------------------------------------------------------------------------*/ 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 Q0*/ + const Word16 num_sfm, /* i : Number of norms Q0*/ + const Word16 is_transient, /* i : Transient flag Q0*/ + Word16 *ynrm, /* o : Decoded norm indices Q0*/ + Word16 *normqlg2 /* o : Log2 of decoded norms Q0*/ ) { Word16 i, j; @@ -165,28 +165,28 @@ void dequantize_norms_fx( Word16 *pYnrm, *pNormqlg2; /* First sub-frame */ - i = ynrm[start_norm]; + i = ynrm[start_norm]; /* Q0 */ move16(); - normqlg2[start_norm] = dicnlg2[i]; + normqlg2[start_norm] = dicnlg2[i]; /* Q0 */ move16(); /* Other sub-frames */ IF( is_transient ) { /* Recover quantization indices and quantized norms */ - idxbuf[0] = ynrm[0]; + idxbuf[0] = ynrm[0]; /* Q0 */ move16(); 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 ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( idxbuf[i] < 0 || GT_16( idxbuf[i], 39 ) ) { - idxbuf[i] = 39; + idxbuf[i] = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } } @@ -195,26 +195,26 @@ void dequantize_norms_fx( } ELSE { - pYnrm = &ynrm[start_norm]; + pYnrm = &ynrm[start_norm]; /* Q0 */ move16(); - pNormqlg2 = &normqlg2[start_norm + 1]; + pNormqlg2 = &normqlg2[start_norm + 1]; /* Q0 */ move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = sub( *pYnrm++, 15 ); + j = sub( *pYnrm++, 15 ); /* Q0 */ move16(); - *pYnrm = add( *pYnrm, j ); + *pYnrm = add( *pYnrm, j ); /* Q0 */ move16(); /* safety check in case of bit errors */ test(); IF( *pYnrm < 0 || GT_16( *pYnrm, 39 ) ) { - *pYnrm = 39; + *pYnrm = 39; /* Q0 */ move16(); - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } - *pNormqlg2++ = dicnlg2[*pYnrm]; + *pNormqlg2++ = dicnlg2[*pYnrm]; /* Q0 */ move16(); } } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 93b94a5c8..556006121 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -18,10 +18,10 @@ #ifdef IVAS_FLOAT_FIXED 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 */ + const Word16 *ynrm, /* i : norm quantization index vector Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -41,7 +41,7 @@ void ivas_hq_pred_hb_bws_fx( { L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ 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*/ move16(); @@ -71,11 +71,11 @@ 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 Q0*/ + const Word16 length, /* i : frame length Q0*/ + const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ + const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ ) { Word16 i; @@ -99,7 +99,7 @@ void hq_pred_hb_bws_fx( L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ #endif } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); + L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ 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*/ move16(); @@ -153,7 +153,7 @@ void ivas_hq_hr_dec_fx( 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 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -211,8 +211,8 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters @@ -231,15 +231,15 @@ void ivas_hq_hr_dec_fx( test(); 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_fx( st_fx, 2 ); + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - 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 ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); @@ -249,7 +249,7 @@ void ivas_hq_hr_dec_fx( 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 Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -257,8 +257,8 @@ void ivas_hq_hr_dec_fx( 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) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -267,7 +267,7 @@ void ivas_hq_hr_dec_fx( } 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 ); /* Q15 */ } ELSE { @@ -286,16 +286,16 @@ void ivas_hq_hr_dec_fx( { IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } 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 ); /* Q15 */ move16(); } } - 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 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); /*------------------------------------------------------------------* @@ -309,20 +309,20 @@ void ivas_hq_hr_dec_fx( test(); 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 /* 1/20 in Q15 */ ); move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { 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 ); /* Q1 */ move16(); } } 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 ); /* Q1 */ move16(); } } @@ -330,8 +330,8 @@ void ivas_hq_hr_dec_fx( test(); 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 ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -350,10 +350,10 @@ void ivas_hq_hr_dec_fx( test(); 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; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -407,7 +407,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; @@ -422,7 +422,7 @@ void hq_hr_dec_fx( 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 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -500,25 +500,25 @@ void hq_hr_dec_fx( test(); 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 ); + nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* * Decode envelope *------------------------------------------------------------------*/ - 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 ) ); + hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ + bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ 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 ) ) { - 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 */ + 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 Q0*/ 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 Q0*/ } map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -526,8 +526,8 @@ void hq_hr_dec_fx( env_stab = 0; move16(); - csw_flag1 = s_and( core_switching_flag, (Word16) ( 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) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ + csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { @@ -536,7 +536,7 @@ void hq_hr_dec_fx( } 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 ); /* Q0 */ } ELSE { @@ -556,16 +556,16 @@ void hq_hr_dec_fx( test(); IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; + move16(); /* calculated stability */ + hHQ_core->env_stab_fx = env_stab; /* Q15 */ } 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 ); /* Q15 */ move16(); } } - 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 ); /* Q0 */ /*------------------------------------------------------------------* * Bit allocation @@ -578,20 +578,20 @@ void hq_hr_dec_fx( test(); 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 /* 1/20 in Q15 */ ); /* Q15 */ move16(); IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { 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 ); /* Q1 */ move16(); } } 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 ); /* Q1 */ move16(); } } @@ -599,8 +599,8 @@ void hq_hr_dec_fx( test(); 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 ); /* Q0 */ + sum = sub( sum, b_delta_env ); /* Q0 */ } /*------------------------------------------------------------------* @@ -619,10 +619,10 @@ void hq_hr_dec_fx( test(); 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; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) @@ -676,7 +676,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ move16(); return; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index a1f18d2da..34bb10fc8 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -218,9 +218,9 @@ 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn */ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -242,7 +242,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -251,9 +251,9 @@ static Word16 para_pred_bws_fx( move16(); FOR( j = 0; j < SHARP_WIDTH; j++ ) { - mag_fx = abs_s( *input_hi_fx ); - peak_fx = s_max( peak_fx, mag_fx ); - mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); + mag_fx = abs_s( *input_hi_fx ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ + mean_fx[i] = L_add( mean_fx[i], L_deposit_l( mag_fx ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -275,7 +275,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -287,11 +287,11 @@ static Word16 para_pred_bws_fx( 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] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - 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 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -303,7 +303,7 @@ static Word16 para_pred_bws_fx( 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_num = extract_l( L_shr( avrg2_fx, sub( 15, exp ) ) ); /*Qsyn - 16 + exp */ } ELSE { @@ -315,16 +315,16 @@ static Word16 para_pred_bws_fx( 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 ); /*Q_syn + Q15 - 15*/ move32(); } min_fx = L_min( min_fx, mean_fx[i] ); peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -410,21 +410,21 @@ static Word16 para_pred_bws_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] ) ) + IF( NE_16( st_fx->prev_coder_type, coder_type ) && GT_16( mult_r( SWB_fenv_fx[i], 16384 /*1/2.0f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { - 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 /*0.1f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 29491 /*0.9f in Q15*/ ) ); move16(); } ELSE { - 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 /*1.0f in Q15*/, st_fx->attenu_fx ) ) ); move16(); } } - IF( LT_16( st_fx->attenu_fx, 29491 ) ) + IF( LT_16( st_fx->attenu_fx, 29491 /*0.9f in Q15*/ ) ) { - st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 ); + st_fx->attenu_fx = add( st_fx->attenu_fx, 1638 /*0.05f in Q15*/ ); move16(); } } @@ -439,7 +439,7 @@ static Word16 para_pred_bws_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] ) ) + if ( GT_16( mult_r( SWB_fenv_fx[i], 16384 /*0.5f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i] ) ) { SWB_fenv_fx[i] = st_fx->prev_SWB_fenv_fx[i]; move16(); @@ -449,10 +449,10 @@ static Word16 para_pred_bws_fx( FOR( i = 0; i < SWB_FENV; i++ ) { - 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 /*0.9f in Q15*/ ), st_fx->prev_SWB_fenv_fx[i], 3277 /*0.1f in Q15*/ ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -1031,12 +1031,12 @@ 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 : Q_syn_hb */ + Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + Word16 output_frame /* i : frame length */ ) { Word16 L; @@ -1285,7 +1285,7 @@ Word16 swb_bwe_dec_fx32( { FOR( i = 0; i < SWB_TENV; i++ ) { - SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i], 26214 ); + SWB_tenv_tmp_fx[i] = L_mult0( SWB_tenv_fx[i] /*Q0*/, 26214 /*0.8f Q15*/ ); // Q15 move32(); } @@ -1351,7 +1351,7 @@ Word16 swb_bwe_dec_fx32( FOR( i = 0; i < output_frame; i++ ) { - hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); + hb_synth_fx[i] = L_deposit_l( hb_synth_fx16[i] ); // Q_syn_hb move32(); } @@ -1400,7 +1400,7 @@ void fd_bwe_dec_init_fx( ) { 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->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 16000, DELAY_FD_BWE_ENC_NS ) ); hBWE_FD->prev_mode = NORMAL; move16(); hBWE_FD->prev_Energy_fx = 0; @@ -1420,7 +1420,6 @@ void fd_bwe_dec_init_fx( move16(); hBWE_FD->prev_Energy_wb_fx = 0; move32(); - hBWE_FD->mem_deemph_old_syn_fx = 0; move16(); diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 765458a90..6e9fd80dc 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -21,9 +21,9 @@ * 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *signal_wb_fx, /* i : wideband frequency signal Q_syn*/ + Word16 *SWB_fenv_fx, /* o : frequency-domain BWE envelope Q1 */ Word16 Q_syn ) { Word16 i, j, k; @@ -45,7 +45,7 @@ static Word16 para_pred_bws_fx( k = 0; move16(); - input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; + input_hi_fx = &signal_wb_fx[SHARP_WIDTH]; /*Q_syn*/ FOR( i = 0; i < 7; i++ ) { peak_fx = 0; @@ -54,13 +54,13 @@ static Word16 para_pred_bws_fx( move16(); 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 ); /*Q_syn*/ + peak_fx = s_max( peak_fx, mag_fx ); /*Q_syn*/ /*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 ) ); /*Q_syn*/ move32(); input_hi_fx++; } @@ -82,7 +82,7 @@ static Word16 para_pred_bws_fx( } IF( tmp > 0 ) { - L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ), 18432 ), peak_fx, 4544 ); + L_tmp = L_msu0( Mult_32_16( L_shl( mean_fx[i], 10 ) /*Q_syn + 10*/, 18432 /*4.5f Q12*/ ), peak_fx /*Q_syn*/, 4544 /*35.5 (SHARP_WIDTH + 3.5f)Q7*/ ); if ( L_tmp < 0 ) { k = add( k, 1 ); @@ -94,11 +94,11 @@ static Word16 para_pred_bws_fx( 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] ); /*Q_syn*/ + avrg2_fx = L_add( avrg2_fx, mean_fx[i + 3] ); /*Q_syn*/ } - 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 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ + avrg2_fx = Mult_32_16( avrg2_fx, 10923 /* 1/3 -> Q15 -> 10923 */ ); /*Q_syn + Q15 - 15*/ min_fx = L_add( 2147483647, 0 ); /*2^31 */ peak_32_fx = L_deposit_l( 0 ); @@ -122,11 +122,11 @@ static Word16 para_pred_bws_fx( 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 ); // Q_syn + Q15 - 15 move32(); } min_fx = L_min( min_fx, mean_fx[i] ); - peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); + peak_32_fx = L_max( peak_32_fx, mean_fx[i] ); /*Q_syn*/ /*IF(L_sub(mean_fx[i], min_fx) < 0) */ /*{ */ /* min_fx = mean_fx[i]; */ @@ -137,9 +137,9 @@ static Word16 para_pred_bws_fx( /*} */ } - IF( GT_16( st_fx->tilt_wb_fx, 16384 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 16384 /*8 in Q11*/ ) ) { - IF( GT_16( st_fx->tilt_wb_fx, 30720 ) ) + IF( GT_16( st_fx->tilt_wb_fx, 30720 /*15.0f in Q11*/ ) ) { min_fx = peak_32_fx; move32(); @@ -147,7 +147,7 @@ static Word16 para_pred_bws_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 ); + min_fx = Mult_32_16( peak_32_fx, tmp ); /*Q_syn + Q15 - 15*/ } } @@ -272,7 +272,7 @@ static Word16 para_pred_bws_fx( SWB_fenv_fx[i] = round_fx( L_mac( L_mult( SWB_fenv_fx[i], 29491 ), st_fx->prev_SWB_fenv_fx[i], 3277 ) ); move16(); } - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; /*Q15*/ move16(); } @@ -309,7 +309,8 @@ static Word16 para_pred_bws_fx( *-------------------------------------------------------------------*/ Word16 WB_BWE_gain_deq_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *WB_fenv ) + Word16 *WB_fenv /* o : Q15 */ +) { Word16 mode; Word16 index, index2; @@ -320,25 +321,25 @@ Word16 WB_BWE_gain_deq_fx( mode = add( extract_l( get_next_indice_fx( st_fx, 1 ) ), 2 ); index2 = shl( index, 1 ); - L_tmp = L_shr( F_2_5_fx[index2], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[0] = shl( tmp, add( exp, 3 ) ); + WB_fenv[0] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); - L_tmp = L_shr( F_2_5_fx[index2 + 1], 1 ); - L_tmp = L_shl( L_tmp, 6 ); + L_tmp = L_shr( F_2_5_fx[index2 + 1] /*Q10*/, 1 ); + L_tmp = L_shl( L_tmp, 6 ); /*Q15*/ frac = L_Extract_lc( L_tmp, &exp ); tmp = extract_l( Pow2( 14, frac ) ); exp = sub( exp, 14 ); - WB_fenv[1] = shl( tmp, add( exp, 3 ) ); + WB_fenv[1] = shl( tmp, add( exp, 3 ) ); // Q15 move16(); return ( mode ); @@ -349,16 +350,16 @@ Word16 WB_BWE_gain_deq_fx( * * WB BWE decoder (only for 16kHz signals) *-------------------------------------------------------------------*/ -Word16 ivas_wb_bwe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 output[], /* i : suntehsis @ internal Fs */ - Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis */ - Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis */ - const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ - const Word16 output_frame, /* i : frame length */ - Word16 *voice_factors_fx, /* i : voicing factors */ - const Word16 pitch_buf_fx[], /* i : pitch buffer */ - Word16 *Qpost ) +Word16 ivas_wb_bwe_dec_fx( /* o : Q_syn_hb */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 output[], /* i : suntehsis @ internal Fs Q_input */ + Word16 *synth_fx, /* i/o: ACELP core synthesis/final synthesis Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ + const Word16 use_cldfb_for_dft, /* i : flag to use of CLDFB for DFT Stereo */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Word16 *Qpost ) { Word16 mode; Word16 WB_fenv_fx[SWB_FENV]; @@ -449,7 +450,7 @@ Word16 ivas_wb_bwe_dec_fx( { /* de-quantization */ mode = WB_BWE_gain_deq_fx( st_fx, WB_fenv_fx ); - st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 ) ); + st_fx->last_wb_bwe_ener_fx = extract_l( Mpy_32_16_r( L_add( WB_fenv_fx[0], WB_fenv_fx[1] ), 16384 /*0.5f in Q15*/ ) ); move16(); } ELSE @@ -536,15 +537,15 @@ Word16 wb_bwe_dec_fx( #ifdef ADD_IVAS_BWE 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 Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #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 */ + const Word16 output_frame, /* i : frame length */ + Word16 *voice_factors_fx, /* i : voicing factors Q15 */ + const Word16 pitch_buf_fx[], /* i : pitch buffer Q6 */ + Decoder_State *st_fx /* i/o: decoder state structure */ , Word16 *Qpost ) { @@ -706,12 +707,12 @@ 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 core, /* i : core : Q0 */ + Word16 *SWB_tenv, /* o : time-domain BWE envelope : Q0 */ + Word16 *SWB_fenv, /* o : frequency-domain BWE envelope : Q1 */ + const Word16 hr_flag, /* i : high rate flag : Q0 */ + const Word16 hqswb_clas /* i : HQ BWE class : Q0 */ ) { Word16 index, mode, n_band; @@ -759,7 +760,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class 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 */ + quant_tmp[2 * n_band] = Env_TR_Cdbk1_fx[tmp + n_band]; /*Q8 */ move16(); } @@ -848,8 +849,8 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class move16(); } - Copy( &EnvCdbk11_fx[i_mult2( indice[0], DIM11 )], quant_tmp, DIM11 ); - Copy( &EnvCdbk1st_fx[i_mult2( indice[1], DIM1ST )], quant_tmp2, DIM1ST ); + Copy( &EnvCdbk11_fx[indice[0] * DIM11], quant_tmp, DIM11 ); + Copy( &EnvCdbk1st_fx[indice[1] * DIM1ST], quant_tmp2, DIM1ST ); Copy( &EnvCdbk2nd_fx[indice[2] * DIM2ND], quant_tmp2 + DIM1ST, DIM2ND ); FOR( n_band = 0; n_band < ( DIM11 - 1 ); n_band++ ) @@ -867,13 +868,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class SWB_fenv[11] = quant_tmp[6]; move16(); - Copy( &EnvCdbk3rd_fx[i_mult( indice[3], DIM3RD )], quant_tmp2, DIM3RD ); - Copy( &EnvCdbk3rd_fx[i_mult( indice[4], DIM3RD )], quant_tmp2 + DIM3RD, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[3] * DIM3RD], quant_tmp2, DIM3RD ); + Copy( &EnvCdbk3rd_fx[indice[4] * DIM3RD], quant_tmp2 + DIM3RD, DIM3RD ); FOR( n_band = 0; n_band < 5; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band + 1] ); + SWB_fenv[n_band * 2 + 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] ); #endif @@ -896,7 +897,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { #ifdef BASOP_NOGLOB - SWB_fenv[add( n_band * 2, 1 )] = add_sat( shr( add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ), 1 ), quant_tmp2[n_band] ); + SWB_fenv[n_band * 2 + 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] ); #endif @@ -929,11 +930,11 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class 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[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] ); + tmp = add( SWB_fenv[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 */ @@ -942,7 +943,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 13 ); - SWB_fenv[add( n_band, nenv )] = shl( tmp, add( exp, 1 ) ); + SWB_fenv[n_band + nenv] = shl( tmp, add( exp, 1 ) ); move16(); } } @@ -958,19 +959,19 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class * * SWB BWE decoder *-------------------------------------------------------------------*/ -Word16 swb_bwe_dec_fx( +Word16 swb_bwe_dec_fx( /*o :Q_syn_hb*/ #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() ) Q0/Qpost */ + Word16 *hb_synth_fx, /* o : SHB synthesis/final synthesis Q_syn_hb */ #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 ) + const Word16 output_frame /* i : frame length */ + , + Word16 *Qpost ) { Word16 i, l_subfr; Word16 mode; @@ -1280,7 +1281,7 @@ void fd_bwe_dec_init( { 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->old_syn_12k8_16k_fx, 0, NS2SA_FX2( 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(); diff --git a/lib_dec/swb_bwe_dec_hr_fx.c b/lib_dec/swb_bwe_dec_hr_fx.c index 51880fe61..8b238e46c 100644 --- a/lib_dec/swb_bwe_dec_hr_fx.c +++ b/lib_dec/swb_bwe_dec_hr_fx.c @@ -26,6 +26,7 @@ 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. */ +#ifdef IVAS_FLOAT_FIXED static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) */ Word16 index, /* i: quantization index */ const Word16 min, /* i: value of lower limit (Q13) */ @@ -40,9 +41,9 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) 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 ) ) { L_mini = MAKE_PSEUDO_FLT( 26214, 15 ); /* 0.8 in Q15 */ @@ -83,7 +84,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) /* c_mult = (float) ((levels-1)/(log10(max)-c_min));*/ /* gain = (float)pow( 10.0, (((float)index)/c_mult) + c_min );*/ - L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); + L_temp = L_mult0( extract_h( L_fact ), inv_tbl_2n_minus1[bits] ); // Q12 + Qx exp1 = norm_s( index ); index = shl( index, exp1 ); /* inv_tbl has variable Q, with Q0 being at [2]*/ @@ -100,7 +101,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) exp1 = sub( 30 - 16 - 15, p2_int ); exp1 = add( exp1, extract_l( L_mini ) ); - gain = round_fx( L_temp ); + gain = round_fx( L_temp ); // exp1 L_temp = L_mult( gain, extract_h( L_mini ) ); exp2 = norm_l( L_temp ); @@ -109,7 +110,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) gain = round_fx( L_temp ); exp1 = add( exp1, exp2 ); - *exp = exp1; + *exp = exp1; // gain_e move16(); return gain; @@ -122,7 +123,7 @@ static Word16 Gain_Dequant_HR( /* o: decoded gain (Q13) *-------------------------------------------------------------------*/ static Word16 TD_Postprocess( /* o : gain in Q15 */ - Word16 hb_synth_fx[], /* i/o: high-band synthesis */ + Word16 hb_synth_fx[], /* i/o: high-band synthesis Q(15 - hb_synth_fx_exp) */ const Word16 hb_synth_fx_exp, /* i : Q of high-band synthesis */ const Word16 input_frame, /* i : frame length */ const Word16 last_extl /* i : last extension layer */ @@ -251,14 +252,14 @@ 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 : Q(15 - exp) */ + const Word16 exp, /* i : Exponent of core synthesis */ + Word16 *hb_synth_fx, /* o : SHB synthesis : Q(15 - hb_synth_fx_exp)*/ + const Word16 output_frame, /* i : frame length */ + const Word16 unbits, /* i : number of core unused bits */ + const Word16 pitch_buf[] /* i : pitch buffer : Q6 */ ) { Word16 i, j, k, nBits, nBits_total, nBits_block, Nsv, Nsv2, width_noncoded; @@ -413,9 +414,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp4 = add( temp4, t_audio_exp ); FOR( i = 0; i < tmpS; i++ ) { - L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[add( i, ind1 )] ); + L_temp = L_mult( alpha, hBWE_FD_HR->t_audio_prev_fx[i + ind1] ); L_temp = L_shr( L_temp, temp4 ); - t_audio32[add( pos, i )] = L_temp; + t_audio32[pos + i] = L_temp; move32(); } ind1 = add( ind1, tmpS ); @@ -590,17 +591,17 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB 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 ) ); // Q9 } 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 ) ); // Q9 } 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 ) ); // Q9 } } @@ -621,7 +622,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB move16(); FOR( i = 0; i < i_mult( Nsv, WIDTH_BAND ); i++ ) { - t_audio[add( temp, i )] = shl( x_norm[i], t_audio_exp ); + t_audio[temp + i] = shl( x_norm[i], t_audio_exp ); move16(); } @@ -656,7 +657,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* reconstruct 14-16(20) kHz spectrum */ FOR( j = 0; j < tmpS; j++ ) { - *ptr32++ = L_shr( t_audio32[add( pos, j )], 1 ); + *ptr32++ = L_shr( t_audio32[pos + j], 1 ); move32(); } @@ -678,8 +679,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB temp2 = add( NUM_TRANS_END_FREQ_COEF_EFF, temp ); j = sub( tmpS, width_noncoded ); - ptr16 = &t_audio[add( temp2, j )]; - ptr32 = &t_audio32[add( temp2, j )]; + ptr16 = &t_audio[temp2 + j]; + ptr32 = &t_audio32[temp2 + j]; /* envelope denormalization of 14.4-16(20) kHz spectrum */ FOR( ; j < tmpS; j++ ) { @@ -763,7 +764,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( i = 0; i < j; i++ ) { - t_audio[add( temp, i )] = mult_r( t_audio[add( temp, i )], temp2 ); + t_audio[temp + i] = mult_r( t_audio[temp + i], temp2 ); move16(); } } @@ -787,18 +788,18 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB ind2 = (Word16) get_next_indice_fx( st_fx, NBITS_ENVELOPE_BWE_HR2 ); temp = shl( ind1, 1 ); - en_band[0] = swb_hr_env_code1_fx[temp]; + en_band[0] = swb_hr_env_code1_fx[temp]; // Q9 move16(); - en_band[1] = swb_hr_env_code1_fx[temp + 1]; + en_band[1] = swb_hr_env_code1_fx[temp + 1]; // Q9 move16(); temp = shl( ind2, 1 ); - en_band[2] = swb_hr_env_code2_fx[temp]; + en_band[2] = swb_hr_env_code2_fx[temp]; // Q9 move16(); - en_band[3] = swb_hr_env_code2_fx[temp + 1]; + en_band[3] = swb_hr_env_code2_fx[temp + 1]; // Q9 move16(); /*env = add(add(shr(en_band[0], 2), shr(en_band[1], 2)), add(shr(en_band[2], 2), shr(en_band[3], 2)));*/ - env = mac_r( L_mac( L_mac( L_mult( en_band[0], 8192 ), en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); + env = mac_r( L_mac( L_mac( L_mult( en_band[0] /*Q9*/, 8192 /*0.25 in Q15*/ ) /*Q23*/, en_band[1], 8192 ), en_band[2], 8192 ), en_band[3], 8192 ); // Q23 /*---------------------------------------------------------------------* * choose sub-bands to be dequantized @@ -846,19 +847,19 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB 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 ); // Q9 } 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 ) ); // Q9 } 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 ); // Q9 } } @@ -954,7 +955,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { L_temp = L_mult( gain2_fx, *ptr16++ ); L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + t_audio_tmp[temp + j] = round_fx( L_temp ); } /* 'nq[i] = add(nq[i], nq2[incr])' replaced by 'nq[i] = nq2[incr]' because 'nq[i] == 0' */ nq[i] = nq2[incr]; @@ -978,9 +979,9 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB FOR( j = 0; j < WIDTH_BAND; j++ ) { L_temp = L_mult( gain2_fx, *ptr16++ ); - L_temp = L_msu( L_temp, t_audio_tmp[add( temp, j )], temp3 ); /* go to -Q't_audio' */ - L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ - t_audio_tmp[add( temp, j )] = round_fx( L_temp ); + L_temp = L_msu( L_temp, t_audio_tmp[temp + j], temp3 ); /* go to -Q't_audio' */ + L_temp = L_shr( L_temp, temp2 ); /* go to Q't_audio' */ + t_audio_tmp[temp + j] = round_fx( L_temp ); } nq[i] = add( nq[i], nq2[incr] ); move16(); @@ -1043,7 +1044,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB { nq[j] = nq[i]; move16(); - j = j - 1; + j = sub( j, 1 ); } Copy( nq + ind2, nq + ind1, add( WIDTH_BAND, pos ) ); @@ -1271,7 +1272,8 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB /* Apply global gain */ if ( LE_16( nBits_total, NBITS_THRESH_BWE_HR ) ) { - gain_fx = mult_r( 27853, gain_fx ); /* 0.85 */ + gain_fx = mult_r( 27853, gain_fx ); /* 0.85 in exp_0 */ + // gain_e } ptr32 = &t_audio32[NUM_NONTRANS_START_FREQ_COEF]; @@ -1336,12 +1338,12 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } 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 ) /*gain_e + (31 - Q23)*/, 7 ) ); /*gain_e + 15*/ move16(); } FOR( i = 0; i < SWB_FENV; i++ ) { - st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; + st_fx->prev_SWB_fenv_fx[i] = st_fx->prev_ener_shb_fx; /*gain_e + 15*/ move16(); } @@ -1512,7 +1514,7 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB } } - hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; + hBWE_FD_HR->L_mem_EnergyLT_fx = L_EnergyLT; // exp_temp4 move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = temp4; move16(); @@ -1558,7 +1560,6 @@ Word16 swb_bwe_dec_hr_fx( /* o : Exponent of SHB * * Initialize HR BWE state structure at the decoder *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED void hr_bwe_dec_init( HR_BWE_DEC_HANDLE hBWE_FD_HR /* i/o: HR BWE data handle */ ) @@ -1567,32 +1568,14 @@ void hr_bwe_dec_init( 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; + hBWE_FD_HR->bwe_highrate_seed_fx = 12345; /*0.75f in Q14*/ move16(); - hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); + hBWE_FD_HR->L_mem_EnergyLT_fx = L_deposit_h( 16384 ); /*1.0f in Q30*/ move32(); hBWE_FD_HR->mem_EnergyLT_fx_exp = 40; move16(); /* set to a high exponent */ return; } -#else -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 */ - 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->mem_EnergyLT_fx_exp = 40; - move16(); /* set to a high exponent */ - - return; -} #endif diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index f2aa60a59..b9bb17621 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -15,12 +15,12 @@ *-------------------------------------------------------------------*/ 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 :Q0 */ + const Word16 nBands_search_fx, /* i : number of subbnads for SSearch :Q0 */ + const Word16 BANDS_fx, /* i : total number of subbands per frame :Q0 */ + const Word16 *p2a_flags_fx, /* i : HF tonal flag :Q0 */ + const Word16 hq_swb_clas_fx /* i : mode of operation HQ_NORMAL or HQ_HARMONIC :Q0 */ ) { Word16 sb; @@ -35,16 +35,15 @@ static void DecodeSWBGenericParameters_fx( } ELSE { - IF( p2a_flags_fx[add( sub( BANDS_fx, NB_SWB_SUBBANDS ), sb )] == 0 ) + IF( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + sb] == 0 ) { lagIndices_fx[sb] = (Word16) get_next_indice_fx( st_fx, bits_lagIndices_modeNormal[sb] ); - move16(); } ELSE { lagIndices_fx[sb] = 0; - move16(); } + move16(); } } @@ -61,32 +60,32 @@ 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 */ - 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 */ + 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 : QsL */ + Word16 QsL, /* i : Q value of spectra */ + const Word16 fLenLow_fx, /* i : lowband length : Q0 */ + const Word16 fLenHigh_fx, /* i : highband length : Q0 */ + const Word16 nBands_fx, /* i : number of subbands : Q0 */ + const Word16 *sbWidth_fx, /* i : subband lengths : Q0 */ + const Word16 *subband_offsets_fx, /* i : subband offsets : Q0 */ + Word16 *lagIndices_fx, /* i : lowband index for each subband : Q0 */ + Word16 *lagGains_fx, /* i : first gain for each subband QlagGains*/ + Word16 *QlagGains, /* i : Q value of lagGains */ + Word16 BANDS_fx, /* i : number subbands per frame : Q0 */ + Word16 *band_start_fx, /* i : band start of each SB : Q0 */ + Word16 *band_end_fx, /* i : band end of each SB : Q0 */ + Word32 *L_band_energy, /* i : band energy of each SB : Q0 */ + Word16 Qbe, /* i : Q value of band energy */ + Word16 *p2a_flags_fx, /* i : HF tonal indicator : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + const Word16 har_bands_fx, /* i : number of LF harmonic bands : Q0 */ + const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband band widths : Q0 */ + const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled : QsL */ + Word16 *ni_seed_fx /* i/o: random seed for search buffer NI : Q0 */ ) { Word16 i, k; @@ -179,7 +178,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -192,7 +191,7 @@ static void DecodeSWBSubbands_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++ ) { - if ( EQ_16( p2a_flags_fx[add( 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(); @@ -200,12 +199,12 @@ static void DecodeSWBSubbands_fx( } GetlagGains_fx( sspectra_ni_fx, Qss, - &L_band_energy[sub( 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 < nBands_fx; k++ ) { - IF( EQ_16( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )], 1 ) ) + IF( EQ_16( p2a_flags_fx[BANDS_fx - NB_SWB_SUBBANDS + k], 1 ) ) { lagGains_fx[k] = 0; move16(); @@ -214,7 +213,7 @@ static void DecodeSWBSubbands_fx( } ELSE { - lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 ); /* lagGains[k]*0.9f; */ + lagGains_fx[k] = mult_r( lagGains_fx[k], 29491 /*0.9f in Q15*/ ); /* lagGains[k]*0.9f; */ move16(); } } @@ -223,7 +222,7 @@ static void DecodeSWBSubbands_fx( { L_th_g[k] = 0; move32(); - IF( p2a_flags_fx[add( BANDS_fx - NB_SWB_SUBBANDS, k )] == 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 -> Qs */ move32(); @@ -244,7 +243,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_xSynth_har[sub( i, fLenLow_fx )]; + L_spectra[i] = L_xSynth_har[i - fLenLow_fx]; move32(); /* QsL */ } } @@ -252,7 +251,7 @@ static void DecodeSWBSubbands_fx( { FOR( i = band_start_fx[k]; i <= band_end_fx[k]; i++ ) { - L_spectra[i] = L_spectra_ni[i]; + L_spectra[i] = L_spectra_ni[i]; /* QsL */ move32(); } } @@ -268,26 +267,26 @@ static void DecodeSWBSubbands_fx( * Main decoding routine of SWB BWE for the LR MDCT core *-------------------------------------------------------------------*/ 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 L_m_core[], /* i : lowband synthesis : QsL */ + const Word16 QsL, /* i : Q value of m_core */ + Word32 L_m[], /* o : highband synthesis with lowband zeroed : QsL */ + const Word32 L_total_brate, /* i : total bitrate for selecting subband pattern */ + Word16 BANDS_fx, /* i : Number subbands/Frame : Q0 */ + Word16 *band_start_fx, /* i : Band Start of each SB : Q0 */ + Word16 *band_end_fx, /* i : Band end of each SB :Q0 */ + 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 : Q0 */ + const Word16 hqswb_clas_fx, /* i : class information : Q0 */ + Word16 lowlength_fx, /* i : Lowband Length : Q0 */ + Word16 highlength_fx, /* i : Highband Length : Q0 */ + const Word16 har_bands_fx, /* i : Number of LF harmonic bands : Q0 */ + Word16 *prev_frm_hfe2, /* i/o: : Q0 */ + Word16 *prev_stab_hfe2, /* i/o: : Q0 */ + Word16 band_width_fx[], /* i : subband bandwidth : Q0 */ + const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ + Word16 *ni_seed_fx /* i/o: random seed : QsL */ ) { Word16 k; diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c5c1bed29..3c788e784 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -466,10 +466,10 @@ void wb_tbe_dec( } #else 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 */ + const Word32 *sp_fx, /* i : input signal : Q11 */ + Word32 *tilt_fx, /* o : signal tilt : tilt_fx_q */ + Word16 *tilt_fx_q, /* o : signal tilt */ + const Word16 N /* i : signal length : Q0 */ ) { Word16 i; @@ -479,14 +479,14 @@ static void calc_tilt_bwe_fx_loc( move64(); FOR( i = 0; i < N; i++ ) { - r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); + r0_fx = W_add( r0_fx, W_shr( W_mult_32_32( sp_fx[i], sp_fx[i] ), 1 ) ); /*Q11*2 - 1*/ } - r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); + r1_fx = W_deposit32_l( abs( L_sub( sp_fx[1], sp_fx[0] ) ) ); /*Q11*/ FOR( i = 2; i < N; i++ ) { - IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ), L_sub( sp_fx[i - 1], sp_fx[i - 2] ) ) < 0 ) + IF( W_mult_32_32( L_sub( sp_fx[i], sp_fx[i - 1] ) /*Q11*/, L_sub( sp_fx[i - 1], sp_fx[i - 2] ) /*Q11*/ ) /*Q11 * 2 - 1*/ < 0 ) { - r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); + r1_fx = W_add( r1_fx, W_deposit32_l( abs( L_sub( sp_fx[i], sp_fx[i - 1] ) ) ) ); /*Q11*/ } } Word16 headroom_left_r0 = W_norm( r0_fx ); @@ -494,7 +494,6 @@ static void calc_tilt_bwe_fx_loc( Word16 r0_q = 0, r1_q = 0; move16(); move16(); - // Word16 r0_bits_occ = 0, r1_bits_occ = 0; IF( LT_16( headroom_left_r0, 32 ) ) { r0_fx = W_shr( r0_fx, sub( 32, headroom_left_r0 ) ); @@ -553,7 +552,8 @@ static void calc_tilt_bwe_fx_loc( *-------------------------------------------------------------------*/ static void rescale_genSHB_mem_dec( Decoder_State *st_fx, - Word16 sf ) + Word16 sf /*Q0*/ +) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -598,8 +598,8 @@ static void rescale_genSHB_mem_dec( static void gradientGainShape( Decoder_State *st_fx, - Word16 *GainShape_fx, - Word32 *GainFrame_fx ) + Word16 *GainShape_fx, /*Q15*/ + Word32 *GainFrame_fx /* Q18 */ ) { Word16 i, j, tmp; Word16 GainShapeTemp[NUM_SHB_SUBFR / 4]; @@ -617,7 +617,7 @@ static void gradientGainShape( move16(); /* Q14 */ 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 /*0.4f in Q15*/ ), mult_r( GainGrad1[j], 19660 /*0.6f in Q15*/ ) ); move16(); /* Q14 */ } @@ -628,14 +628,14 @@ static void gradientGainShape( 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 /*0.1f in Q15*/ ), mult_r( GainGrad1[2], 29490 /*0.9f in Q15*/ ) ); move16(); /* Q14 */ } ELSE { - GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 ), mult_r( GainGrad1[1], 9830 ) ); + GainGradFEC[0] = add( mult_r( GainGrad1[0], 6553 /*0.2f in Q15*/ ), mult_r( GainGrad1[1], 9830 /*0.3f in Q15*/ ) ); move16(); - GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 ) ); + GainGradFEC[0] = add( GainGradFEC[0], mult_r( GainGrad1[2], 16384 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } @@ -649,7 +649,7 @@ static void gradientGainShape( } 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 /*0.5f in Q15*/ ) ); move16(); /* Q14 */ } ELSE @@ -668,7 +668,7 @@ static void gradientGainShape( { 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 /*0.8f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); @@ -681,7 +681,7 @@ static void gradientGainShape( { 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 /*0.2f in Q15*/ ) ); move16(); /* GainShapeTemp[i-1] + 0.8* GainShapeTemp[i] */ GainShapeTemp[i] = s_max( GainShapeTemp[i], 328 /*0.01f Q15*/ ); move16(); /* Q14 */ @@ -709,17 +709,17 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - tmp = mult_r( GainShapeTemp[i], 19660 ); /* GainShapeTemp[i]*0.6 */ + tmp = mult_r( GainShapeTemp[i], 19660 /*0.6f Q15*/ ); /* GainShapeTemp[i]*0.6 */ IF( GT_16( 8192, tmp ) ) { - GainShape_fx[add( i * 4, j )] = shl( tmp, 2 ); - move16(); /* (GainShapeTemp[i]*0.6)>>1 */ + GainShape_fx[i * 4 + j] = shl( tmp, 2 ); /*Q15*/ + move16(); /* (GainShapeTemp[i]*0.6)>>1 */ } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; - move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ + move16(); /* Clipping here to avoid the a huge change of the code due to gain shape change */ } } } @@ -734,17 +734,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; // 1.0f in Q15 move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 31129 /*0.95f in Q15*/ ); /*Q15*/ move16(); } ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) @@ -753,11 +753,11 @@ static void gradientGainShape( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = GainShapeTemp[i]; + GainShape_fx[i * 4 + j] = GainShapeTemp[i]; /*Q15*/ move16(); } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 16384 /*0.5f in Q15*/ ); /*Q15*/ move16(); } ELSE @@ -768,17 +768,17 @@ static void gradientGainShape( { IF( LT_16( GainShapeTemp[i], 16384 ) ) { - GainShape_fx[add( i * 4, j )] = shl( GainShapeTemp[i], 1 ); + GainShape_fx[i * 4 + j] = shl( GainShapeTemp[i], 1 ); /*Q15*/ move16(); } ELSE { - GainShape_fx[add( i * 4, j )] = 32767; + GainShape_fx[i * 4 + j] = 32767; /*Q15*/ move16(); } } } - hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 ); + hBWE_TD->GainAttn_fx = mult_r( hBWE_TD->GainAttn_fx, 27852 /*0.85f in Q15*/ ); /*Q15*/ move16(); } @@ -1012,15 +1012,15 @@ void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ void ivas_swb_tbe_dec_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors */ - const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis */ - Word16 *pitch_buf_fx, + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word32 old_syn_12k8_16k_fx[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word16 *pitch_buf_fx, /* i : Q6 */ Word16 *Q_white_exc ) { Word16 i, j, cnt, n; @@ -1136,7 +1136,7 @@ void ivas_swb_tbe_dec_fx( /* WB/SWB bandwidth switching */ test(); test(); - IF( ( GT_16( st->tilt_wb_fx, 10240 ) && ( st->clas_dec == UNVOICED_CLAS ) ) || GT_16( st->tilt_wb_fx, 20480 ) ) + IF( ( GT_16( st->tilt_wb_fx, 10240 /*5 in Q11*/ ) && ( EQ_16( st->clas_dec, UNVOICED_CLAS ) ) ) || GT_16( st->tilt_wb_fx, 20480 /*10 in Q11*/ ) ) { test(); test(); @@ -1155,21 +1155,20 @@ void ivas_swb_tbe_dec_fx( ) { is_fractive = 0; - move16(); } ELSE { is_fractive = 1; - move16(); } + move16(); } /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { - f_fx = 1489; /*Q15*/ + f_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); - inc_fx = 1489; /*Q15*/ + inc_fx = 1489; /*1.0f / 22.0f in Q15*/ move16(); IF( EQ_16( is_fractive, 1 ) ) @@ -1180,9 +1179,9 @@ void ivas_swb_tbe_dec_fx( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } test(); @@ -1194,13 +1193,13 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && !( ( L_sub( L_shr( st->prev_enerLH_fx, 1 ), st->enerLH_fx ) < 0 ) && L_sub( st->prev_enerLH_fx, ( L_shr( st->enerLH_fx, 1 ) > 0 ) ) ) ) || st->last_core != ACELP_CORE || ( ( st->last_core == ACELP_CORE ) && GT_32( abs( L_sub( st->last_core_brate, st->core_brate ) ), 3600 ) ) || EQ_16( s_xor( is_fractive, st->prev_fractive ), 1 ) ) { - set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); + set16_fx( GainShape_fx, 11587, NUM_SHB_SUBFR ); /*0.3536f in Q15*/ } ELSE { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) + if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) /*0.3536f in Q15*/ { - hBWE_TD->prev_GainShape_fx = 11587; + hBWE_TD->prev_GainShape_fx = 11587; /*0.3536f in Q15*/ move16(); } set16_fx( GainShape_fx, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); @@ -1220,7 +1219,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); f_fx = add( f_fx, inc_fx ); } @@ -1240,9 +1239,9 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; + hBWE_TD->lsp_prevfrm_fx[i] = f_fx; /*Q15*/ move16(); - f_fx = add( f_fx, inc_fx ); + f_fx = add( f_fx, inc_fx ); /*Q15*/ } } Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); @@ -1267,7 +1266,7 @@ void ivas_swb_tbe_dec_fx( test(); IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && !st->prev_use_partial_copy && EQ_16( st->prev_coder_type, UNVOICED ) && NE_32( GainFrame_fx, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st->next_coder_type, GENERIC ) && EQ_16( st->last_extl, SWB_TBE ) ) { - GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame_fx, 6553 ) ); + GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6553 /*0.2f in Q15*/ ) ); } } ELSE @@ -1323,13 +1322,14 @@ void ivas_swb_tbe_dec_fx( IF( EQ_16( st->last_extl, SWB_TBE ) ) { GainFrame_fx = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp_fx ), Mult_32_16( GainFrame_fx, sub( 32767, temp_fx ) ) ); + /*Q18*/ } IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) ) { - if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 ) && LT_32( GainFrame_fx, 3059606 ) ) + if ( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, VOICED ) && EQ_16( st->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame_fx, 2097152 /*8.0f in Q18*/ ) && LT_32( GainFrame_fx, 3059606 /*11.67f in Q18*/ ) ) { - GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 ); + GainFrame_fx = Mult_32_16( GainFrame_fx, 9830 /*0.3f in Q15*/ ); // Q18 } } } @@ -1360,7 +1360,7 @@ void ivas_swb_tbe_dec_fx( { FOR( j = 0; j < 4; j++ ) { - GainShape_fx[add( i * 4, j )] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); + GainShape_fx[i * 4 + j] = mult_r( st->cummulative_damping, st->GainShape_Delay[4 + i] ); move16(); } } @@ -1464,7 +1464,7 @@ void ivas_swb_tbe_dec_fx( Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; /*Q15*/ move16(); } @@ -2140,9 +2140,9 @@ void ivas_swb_tbe_dec_fx( IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( ( EQ_16( st->codec_mode, MODE1 ) && GT_32( st->enerLL_fx, st->prev_enerLL_fx ) && GT_32( st->enerLH_fx, st->prev_enerLH_fx ) ) || EQ_16( st->codec_mode, MODE2 ) ) ) { test(); - IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) + IF( GT_16( tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 /*10.0f in Q11*/ ) ) { - GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame_fx, 6554 ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 ), 3 ) ); /*Q18*/ + GainFrame_fx = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame_fx, 6554 /*0.2f in Q15*/ ) ), L_shl( Mult_32_16( GainFrame_fx, 16384 /*4.0f in Q12*/ ), 3 ) ); /*Q18*/ } ELSE { @@ -2154,11 +2154,11 @@ void ivas_swb_tbe_dec_fx( test(); IF( GT_16( tilt_swb_fec_fx, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame_fx, 16384 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 /*0.5f in Q15*/ ), Mult_32_16( GainFrame_fx, 16384 /*0.5f in Q15*/ ) ); /* Q18 */ } ELSE { - GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); + GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 /*0.2f in Q15*/ ), Mult_32_16( GainFrame_fx, 26214 /*0.8f in Q15*/ ) ); /* Q18 */ } } } @@ -2446,7 +2446,7 @@ void ivas_swb_tbe_dec_fx( { GainShape_fx[2 * j] = mult_r( GainShape_fx[2 * j], scale_fx ); move16(); - GainShape_fx[add( 2 * j, 1 )] = mult_r( GainShape_fx[add( 2 * j, 1 )], scale_fx ); + GainShape_fx[2 * j + 1] = mult_r( GainShape_fx[2 * j + 1], scale_fx ); move16(); FOR( i = 0; i < L_FRAME16k / 8; i++ ) { @@ -2573,7 +2573,7 @@ void ivas_swb_tbe_dec_fx( move16(); FOR( i = 0; i < 40; i++ ) { - shaped_shb_excitation_fx[add( i, j * 40 )] = shl( mult_r( shaped_shb_excitation_fx[add( i, j * 40 )], scale_fx ), 3 ); + shaped_shb_excitation_fx[i + j * L_FRAME16k / 8] = shl( mult_r( shaped_shb_excitation_fx[i + j * L_FRAME16k / 8], scale_fx ), 3 ); move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ } @@ -2772,7 +2772,7 @@ void ivas_swb_tbe_dec_fx( if ( !st->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -2784,7 +2784,7 @@ void ivas_swb_tbe_dec_fx( move32(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec_fx; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*1.0f in Q15*/ move16(); } } @@ -4565,12 +4565,12 @@ void GenTransition( #ifdef IVAS_FLOAT_FIXED void GenTransition_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 element_mode, /* i : element mode */ - const Word16 L_frame, /* i : ACELP frame length */ - const Word16 rf_flag, /* i : RF flag */ - const Word32 total_brate, /* i : total bitrate */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ + const Word32 output_Fs, /* i : output sampling rate : Q0 */ + const Word16 element_mode, /* i : element mode : Q0 */ + const Word16 L_frame, /* i : ACELP frame length : Q0 */ + const Word16 rf_flag, /* i : RF flag : Q0 */ + const Word32 total_brate, /* i : total bitrate : Q0 */ const Word16 prev_Qx ) { Word16 i, length; @@ -4578,7 +4578,7 @@ void GenTransition_fixed( Word32 syn_overlap_32k_fx[2 * SHB_OVERLAP_LEN]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, SHB_OVERLAP_LEN, syn_overlap_32k_fx ); @@ -4599,13 +4599,12 @@ void GenTransition_fixed( IF( i % 2 == 0 ) { syn_overlap_32k_fx[i] = L_negate( syn_overlap_32k_fx[i] ); - move32(); } ELSE { syn_overlap_32k_fx[i] = syn_overlap_32k_fx[i]; - move32(); } + move32(); } } @@ -4697,7 +4696,7 @@ void GenTransition_WB( #ifdef IVAS_FLOAT_FIXED void GenTransition_WB_fixed( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ - Word32 *outputHB_fx, /* o : synthesized HB transitions signal */ + Word32 *outputHB_fx, /* o : synthesized HB transitions signal : Q11 */ const Word32 output_Fs /* i : output sampling rate */ ) { @@ -4706,7 +4705,7 @@ void GenTransition_WB_fixed( Word32 upsampled_synth_fx[L_FRAME48k]; /* set targeted length of transition signal */ - length = i_mult( 2, NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ) ); + length = i_mult( 2, NS2SA_FX2( output_Fs, DELAY_BWE_TOTAL_NS ) ); /* upsample overlap snippet */ Interpolate_allpass_steep_32( hBWE_TD->syn_overlap_fx_32, hBWE_TD->state_lsyn_filt_shb_fx_32, SHB_OVERLAP_LEN / 2, speech_buf_16k1_fx ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 2e187546e..cb3ae52a8 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -633,11 +633,11 @@ void ResetSHBbuffer_Dec_fx( Decoder_State *st_fx /* i/o: SHB encoder structure * /*==========================================================================*/ void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ + const Word16 coder_type, /* i : coding type Q0 */ 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 */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -716,7 +716,7 @@ void ivas_wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( 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 /*Q18*/, 26214 /*0.8f in Q15*/ ), Mult_32_16( GainFrame /*Q18*/, 6553 /*0.2f in Q15*/ ) /*Q18+Q15 - 15*/ ); /*Q18*/ } } ELSE @@ -782,7 +782,7 @@ void ivas_wb_tbe_dec_fx( test(); 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 /*0.3f in Q15*/ ); /*Q18*/ } } } @@ -806,12 +806,12 @@ void ivas_wb_tbe_dec_fx( } 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 /*0.85f in Q15*/ ); /*Q15*/ move16(); 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 /*Q18*/, hBWE_TD->GainAttn_fx /*Q15*/ ); /*Q15+Q18-15*/ } ELSE { @@ -835,7 +835,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } ELSE @@ -852,7 +852,7 @@ void ivas_wb_tbe_dec_fx( lpc_wb[i] = negate( lpc_wb[i] ); move16(); } - lpc_wb[0] = 4096; + lpc_wb[0] = 4096; /*1.0f in Q12*/ move16(); } @@ -1187,7 +1187,7 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { - synth[i] = mult_r( error[i], 21299 ); + synth[i] = mult_r( error[i], 21299 /*0.65f in Q15*/ ); move16(); } @@ -1376,11 +1376,11 @@ void wb_tbe_dec_fx( move16(); FOR( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ ) { - hBWE_TD->lsp_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*/ ); /*Q15*/ move16(); } } - 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 ); /*Q15*/ set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) @@ -1397,7 +1397,7 @@ void wb_tbe_dec_fx( IF( ( st_fx->core == ACELP_CORE ) && ( 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 ) ); /*Q18*/ } } ELSE @@ -1463,7 +1463,7 @@ void wb_tbe_dec_fx( test(); 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 ); /*Q18*/ } } } @@ -1478,11 +1478,11 @@ void wb_tbe_dec_fx( { 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 ); /*Q15*/ } 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 ); /*Q15*/ } set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR / 2 ); @@ -1971,18 +1971,18 @@ void wb_tbe_dec_fx( /* Update previous frame parameters for FEC */ IF( EQ_32( st_fx->extl_brate, WB_TBE_0k35 ) ) { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_LBR_WB ); /*Q15*/ } ELSE { - Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); + Copy( lsf_wb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER_WB ); /*Q15*/ } hBWE_TD->GainFrame_prevfrm_fx = GainFrame; /* Q18 */ move32(); IF( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } @@ -3742,7 +3742,7 @@ void swb_tbe_dec_fx( if ( !st_fx->bfi ) { - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3754,7 +3754,7 @@ void swb_tbe_dec_fx( move16(); /*Q18*/ hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; move16(); - hBWE_TD->GainAttn_fx = 32767; + hBWE_TD->GainAttn_fx = 32767; /*Q15*/ move16(); } } @@ -3970,7 +3970,7 @@ static void gradientGainShape( static void Dequant_lower_LSF_fx( const Word16 lsf_idx[], /* i : LSF indices */ - Word16 lsf_q[] /* o : Quantized LSFs */ + Word16 lsf_q[] /* o : Quantized LSFs Q15*/ ) { Word16 i; @@ -3979,7 +3979,7 @@ static void Dequant_lower_LSF_fx( move16(); FOR( i = 1; i < NUM_Q_LSF; i++ ) { - lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); + lsf_q[i] = add( lsf_q_cb_fx[i][lsf_idx[i]], lsf_q[i - 1] ); /*Q15*/ move16(); } @@ -3993,9 +3993,10 @@ 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 Q15*/ + const Word16 m, /* i : Mirroring point Q15*/ + const Word16 grid_in[] /* i : Input LSF smoohthing grid Q15*/ +) { Word16 lsf_map[NUM_MAP_LSF]; Word16 grid[NUM_MAP_LSF]; @@ -4007,42 +4008,42 @@ static void Map_higher_LSF_fx( FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); + lsf_map[i] = sub( shl( m, 1 ), lsf_q[NUM_MAP_LSF - 1 - i] ); /*Q15*/ move16(); } IF( GT_16( m, MAX_LSF_FX_BY_2 ) ) { - offset = lsf_map[0]; + offset = lsf_map[0]; /*Q15*/ move16(); scale = div_s( sub( MAX_LSF_FX, m ), m ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); + lsf_map[i] = add( mult_r( sub( lsf_map[i], offset ), scale ), offset ); /*Q15*/ move16(); } } - last_q_lsf = lsf_q[NUM_Q_LSF - 1]; + last_q_lsf = lsf_q[NUM_Q_LSF - 1]; /*Q15*/ move16(); scale = sub( MAX_LSF_FX, last_q_lsf ); FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); + grid[i] = add( mult_r( grid_in[i], scale ), last_q_lsf ); /*Q15*/ move16(); } 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*/ ) ) ); + lsf_smooth[i] = sub( mult_r( grid_smoothing_fx[i], grid[i] ) /*Q15*/, + mult_r( lsf_map[i], add( grid_smoothing_fx[i], -32768 /*-1.0f Q15*/ /*Q15*/ ) ) ); /*Q15*/ move16(); } FOR( i = 0; i < NUM_MAP_LSF; i++ ) { - lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; + lsf_q[NUM_Q_LSF + i] = lsf_smooth[i]; /*Q15*/ move16(); } @@ -4051,40 +4052,41 @@ 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 Q15*/ + const Word16 m_idx, /* i : Mirror point index Q0 */ + Word16 *m /* i : Mirroring point Q15*/ +) { - *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); + *m = add( mirror_point_q_cb_fx[m_idx], lsf_q[NUM_Q_LSF - 1] ); /*Q15*/ move16(); return; } Word16 dotp_loc( - const Word16 x[], /* i : vector x[] */ - const Word32 y[], /* i : vector y[] */ + const Word16 x[], /* i : vector x[] Qx */ + const Word32 y[], /* i : vector y[] Qy */ const Word16 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 ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ 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 ) ); /*Qx + Qy - guarded_bits*/ } - suma = L_shl_sat( suma, guarded_bits ); + suma = L_shl_sat( suma, guarded_bits ); /*Qx + Qy*/ - return extract_h( suma ); + return extract_h( suma ); /*Qx + Qy - 16*/ } void ivas_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*/ + 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*/ @@ -4281,13 +4283,10 @@ void ivas_dequantizeSHBparams_fx_9_1( *Q_mixFactors = 0; move16(); } - //*Q_mixFactors = 0; set16_fx( Q_shb_res_gshape, 0, 5 ); } /* LSFs */ - - test(); test(); test(); @@ -4327,13 +4326,13 @@ void ivas_dequantizeSHBparams_fx_9_1( set16_fx( lsf_q, 0, LPC_SHB_ORDER ); /* VQ part */ - num_bits_lvq = config_LSF_BWE[i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 )]; + num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3]; Idx = get_next_indice_fx( st_fx, num_bits_lvq ); v_add_16( lsf_q, cb_stage + i_mult( Idx, 6 ), lsf_q, 6 ); /* MSLVQ part */ - num_bits_lvq = sub( sub( nbits, num_bits_lvq ), config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )] ); - predictor_bits = config_LSF_BWE[add( i_mult( sub( NUM_BITS_SHB_MSLVQ, nbits ), 3 ), 2 )]; + num_bits_lvq = sub( sub( 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; move16(); @@ -4364,9 +4363,9 @@ void ivas_dequantizeSHBparams_fx_9_1( ELSE { Idx_pred = (Word16) get_next_indice_fx( st_fx, 1 ); - lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred )], LATTICE_DIM ); + lsf_q[LATTICE_DIM] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM ); move16(); - lsf_q[LATTICE_DIM + 1] = dotp_loc( lsf_q, &LastCoefPred_1bit_fx[add( i_mult( 2 * ( LATTICE_DIM + 1 ), Idx_pred ), LATTICE_DIM + 1 )], 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 ); move16(); } @@ -4541,15 +4540,15 @@ 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*/ + 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 */ + 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; @@ -4841,10 +4840,10 @@ 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 */ + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word16 *hb_synth, /* o : high-band synthesis */ + Word16 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp ) { @@ -4903,11 +4902,11 @@ void fb_tbe_dec_fx( 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 */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, - Word32 *hb_synth, /* o : high-band synthesis */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, - Word16 *fb_synth_ref, + Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ Word16 Q_fb_synth_ref, Word16 output_frame ) @@ -4978,7 +4977,7 @@ void fb_tbe_dec_ivas_fx( 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_shl( fb_synth[i], Q11 ) ); // hb_synth_exp move16(); } return; @@ -5099,12 +5098,12 @@ void tbe_read_bitstream_fx( * 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 */ + const Word16 *input, /* i : gain shape overlap buffer Q11 */ + const Word16 *old_hb_synth, /* i : synthesized HB from previous frame Q(15 - hb_synth_fx_exp)*/ + Word16 length, /* i : targeted length of transition signal */ + Word16 *output, /* o : synthesized transitions signal st_fx->prev_Q_bwe_syn2 */ + Word32 Hilbert_Mem[], /* i/o: memory st_fx->prev_Q_bwe_syn2 */ + Word16 state_lsyn_filt_shb_local[], /* i/o: memory st_fx->prev_Q_bwe_syn2*/ Word16 mem_resamp_HB_32k[], /* i/o: memory */ Word16 *syn_dm_phase, Word32 target_fs, @@ -5446,7 +5445,7 @@ void td_bwe_dec_init_fx( const Word32 output_Fs /* i : output sampling rate */ ) { - int16_t i; + Word16 i; /* init. SHB buffers */; InitSWBdecBuffer_fx( st_fx ); @@ -5469,7 +5468,7 @@ void td_bwe_dec_init_fx( 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 /*0.5f in Q15*/, LPC_SHB_ORDER - 2 ); hBWE_TD->prev_tilt_para_fx = 0; move16(); set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); @@ -5503,10 +5502,8 @@ void td_bwe_dec_init_fx( hBWE_TD->fb_tbe_demph_fx = 0; move16(); - set16_fx( hBWE_TD->old_hb_synth_fx, 0, L_FRAME48k ); - hBWE_TD->prev_ener_fx = L_deposit_l( 0 ); move32(); diff --git a/lib_dec/syn_outp.c b/lib_dec/syn_outp.c index 65e36bc61..31cd8b109 100644 --- a/lib_dec/syn_outp.c +++ b/lib_dec/syn_outp.c @@ -47,7 +47,7 @@ * Output synthesis signal with compensation for saturation * returns number of clipped samples *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED /*! r: number of clipped samples */ uint32_t syn_output( float *synth, /* i/o: float synthesis signal */ @@ -133,3 +133,4 @@ void AGC_dec( return; } +#endif diff --git a/lib_dec/syn_outp_fx.c b/lib_dec/syn_outp_fx.c index 7d51c4341..0d84c0c88 100644 --- a/lib_dec/syn_outp_fx.c +++ b/lib_dec/syn_outp_fx.c @@ -15,11 +15,11 @@ *-------------------------------------------------------------------*/ void syn_output_fx( - const Word16 codec_mode, /* i : MODE1 or MODE2 */ - Word16 *synth, /* i/o: fixed point 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 */ + const Word16 codec_mode, /* i : MODE1 or MODE2 Q0 */ + Word16 *synth, /* i/o: fixed point synthesis signal Q_syn2 */ + const Word16 output_frame, /* i : output frame length Q0 */ + Word16 *synth_out, /* o : integer 16 bits synthesis signal Q_syn2 */ + const Word16 Q_syn2 /* i : Synthesis scaling factor */ ) { Word16 i, tmp; @@ -66,7 +66,7 @@ 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] */ + Word16 mem[], /* i/o: mem[2] should be init to [0,0] Q0 */ const Word16 n /* i: vector size */ ) { @@ -97,16 +97,16 @@ void unscale_AGC( move16(); 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 /*0.5f in Q15*/, 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 /*0.99f in Q15*/, mem[0] ) /*Q14*/, 328 /*0.01f in Q15*/, frame_fac /*Q15*/ ); - L_tmp = L_mult( x[0], 16384 ); + L_tmp = L_mult( x[0], 16384 /*1.0f in Q14*/ ); // Q13 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 */ diff --git a/lib_dec/tcq_core_dec_fx.c b/lib_dec/tcq_core_dec_fx.c index 41c83c71e..0432f02a5 100644 --- a/lib_dec/tcq_core_dec_fx.c +++ b/lib_dec/tcq_core_dec_fx.c @@ -16,20 +16,21 @@ #ifdef IVAS_FLOAT_FIXED void tcq_core_LR_dec_fx( Decoder_State *st_fx, - Word16 *inp_vector_fx, /* x5 */ - const Word16 bit_budget, - const Word16 BANDS, - const Word16 *band_start, - const Word16 *band_width, - Word32 *Rk_fx, /* Q16 */ - 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 ) + Word16 *inp_vector_fx, /*Qx */ + const Word16 bit_budget, /*Q0 */ + const Word16 BANDS, /*Q0 */ + const Word16 *band_start, /*Q0 */ + const Word16 *band_width, /*Q0 */ + Word32 *Rk_fx, /*Q16*/ + Word16 *npulses, /*Q0 */ + Word16 *k_sort, /*Q0 */ + const Word16 *p2a_flags, /*Q0 */ + const Word16 p2a_bands, /*Q0 */ + const Word16 *last_bitalloc, /*Q0 */ + const Word16 input_frame, /*Q0 */ + const Word16 adjustFlag, /*Q0 */ + const Word16 *is_transient /*Q0 */ +) { Word16 i, j, k; Word32 Rk_sort_fx[NB_SFM]; @@ -141,7 +142,7 @@ void tcq_core_LR_dec_fx( { IF( Rk_fx[j] > 0 ) { - Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); + Rk_fx[j] = L_sub( Rk_fx[j], ar_div( bsub_fx, nzb ) ); /*Q16*/ move32(); IF( Rk_fx[j] < 0 ) { @@ -201,7 +202,7 @@ void tcq_core_LR_dec_fx( IF( LE_16( input_frame, L_FRAME16k ) && ( adjustFlag == 0 ) && ( *is_transient == 0 ) ) { surplus_fx = -131072; - move32(); /*16 */ + move32(); /*2 in Q16 */ bit_allocation_second_fx( Rk_fx, Rk_sort_fx, BANDS, band_width, k_sort, k_num, p2a_flags, p2a_bands, last_bitalloc, input_frame ); @@ -244,7 +245,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -266,7 +267,7 @@ void tcq_core_LR_dec_fx( 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 ); decode_signs_fx( pardec_fx, band_width[k_sort[k]], &inp_vector_fx[band_start[k_sort[k]]] ); } - nzbands--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE IF( ( Rk_fx[k_sort[k]] > 0 ) && EQ_16( USQ_TCQ[k_sort[k]], 1 ) ) @@ -282,7 +283,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } IF( surplus_fx != 0 ) @@ -302,7 +303,7 @@ 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--; + nzbands = sub( nzbands, 1 ); move16(); } ELSE @@ -311,7 +312,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -403,7 +404,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } @@ -436,7 +437,7 @@ void tcq_core_LR_dec_fx( move16(); FOR( i = 0; i < band_width[k_sort[k]]; i++ ) { - inp_vector_fx[add( band_start[k_sort[k]], i )] = 0; + inp_vector_fx[band_start[k_sort[k]] + i] = 0; move16(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e4b56eca9..1c7bee57b 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -20,11 +20,11 @@ * *--------------------------------------------------------------*/ 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 : Q0 */ + Word16 *synthout, /* o: synth : Q0 */ + Word16 *A, /* i: Quantized LPC coefficients : Q12*/ + Decoder_State *st, /* i/o: decoder memory state */ + Word8 fb /* i: fullband flag */ ) { Word16 tmp; @@ -35,7 +35,7 @@ void tcx_decoder_memory_update( L_frame_glob = st->L_frame; move16(); - preemph = st->preemph_fac; + preemph = st->preemph_fac; // Q15 move16(); /* Output synth */ @@ -105,7 +105,7 @@ void tcx_decoder_memory_update( 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 /*Q12*/, M + 1 ); #ifdef FIX_778_STEREO_BRATE_SWITCHING } #endif @@ -116,27 +116,22 @@ 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 Q(31-x_Q_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; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; + Word16 i, j, num_zeros, zeros[L_FRAME_PLUS], fac_p, sign, s; Word32 L_tmp; - Word16 s; - /* Limit the number of residual bits */ target_bits = s_min( target_bits, NPRM_RESQ ); - /* Requantize the spectrum line-by-line */ /* fac_m = deadzone * 0.5f; */ num_zeros = 0; @@ -157,7 +152,7 @@ Word16 tcx_ari_res_invQ_spec( 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 ) ); // x_Q_e move32(); bits = add( bits, 1 ); } @@ -196,7 +191,6 @@ Word16 tcx_ari_res_invQ_spec( bits = add( bits, 1 ); } - return bits; } /*--------------------------------------------------------------- @@ -205,14 +199,13 @@ Word16 tcx_ari_res_invQ_spec( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_gain( - Word16 *gain_tcx, + Word16 *gain_tcx, /* i/o : gain_tcx_e*/ Word16 *gain_tcx_e, - Word16 *prm, - Word16 resQBits ) + Word16 *prm, /*i : Q0 */ + Word16 resQBits /*i : Q0 */ +) { - Word16 bits; - Word16 gain, tmp1, tmp2; - + Word16 bits, gain, tmp1, tmp2; gain = *gain_tcx; move16(); @@ -255,14 +248,14 @@ Word16 tcx_res_invQ_gain( * *--------------------------------------------------------------*/ Word16 tcx_res_invQ_spec( - Word32 *x, + Word32 *x, /*Q(31 - x_e)*/ Word16 x_e, Word16 L_frame, Word16 *prm, Word16 resQBits, Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ) + Word16 sq_round, /*i : sq deadzone Q15*/ + const Word16 lf_deemph_factors[] /*i : LF deemphasis factors Q14*/ ) { Word16 i; Word16 fac_m, fac_p; @@ -275,9 +268,9 @@ Word16 tcx_res_invQ_spec( /* Requantize the spectrum line-by-line */ fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); + fac_p = sub( 0x4000 /*0.5f Q15*/, fac_m ); // Q15 - lf_deemph_factor = 0x4000; + lf_deemph_factor = 0x4000; /*0.5f Q15*/ move16(); s = sub( x_e, 1 ); @@ -290,11 +283,11 @@ Word16 tcx_res_invQ_spec( 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 /*0.5f in Q14*/ ) ) ) ) { if ( lf_deemph_factors != NULL ) { - lf_deemph_factor = lf_deemph_factors[i]; + lf_deemph_factor = lf_deemph_factors[i]; // Q14 move16(); } @@ -306,13 +299,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_sub( x[i], L_shr( tmp, s ) ); + x[i] = L_sub( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } ELSE @@ -323,13 +316,13 @@ Word16 tcx_res_invQ_spec( move32(); if ( x[i] > 0 ) - tmp = L_mult( fac_p, lf_deemph_factor ); + tmp = L_mult( fac_p, lf_deemph_factor ); // Q14+Q15-1 = Q28 if ( x[i] < 0 ) - tmp = L_mult( fac_m, lf_deemph_factor ); + tmp = L_mult( fac_m, lf_deemph_factor ); // Q14+Q15-1 = Q28 assert( tmp != 0 ); - x[i] = L_add( x[i], L_shr( tmp, s ) ); + x[i] = L_add( x[i], L_shr( tmp, s ) ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -354,11 +347,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( 21627 /*1.32f Q14*/, fac_p ); + tmp = L_mult( 21627 /*1.32f Q14*/, fac_p /*Q15*/ ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); @@ -367,7 +360,7 @@ Word16 tcx_res_invQ_spec( } 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*/ ) ); // Q15 FOR( i = 0; i < L_frame; i++ ) { @@ -383,11 +376,11 @@ Word16 tcx_res_invQ_spec( { bits = add( bits, 1 ); - tmp = L_mult( c, lf_deemph_factors[i] ); + tmp = L_mult( c, lf_deemph_factors[i] ); // Q28 if ( prm[bits] == 0 ) tmp = L_negate( tmp ); - x[i] = L_shr( tmp, s ); + x[i] = L_shr( tmp, s ); // Q(31 - x_e) move32(); } bits = add( bits, 1 ); diff --git a/lib_dec/tns_base_dec_fx.c b/lib_dec/tns_base_dec_fx.c index 4f44dab85..4a68a49c2 100644 --- a/lib_dec/tns_base_dec_fx.c +++ b/lib_dec/tns_base_dec_fx.c @@ -35,9 +35,10 @@ Word16 ReadTnsData( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; @@ -97,13 +98,13 @@ Word16 ReadTnsData_ivas_fx( STnsConfig const *pTnsConfig, Decoder_State *st, - Word16 *pnBits, - Word16 *stream, - Word16 *pnSize ) + Word16 *pnBits, /*Q0*/ + Word16 *stream, /*Q0*/ + Word16 *pnSize /*Q0*/ +) { Word16 start_bit_pos; - move16(); start_bit_pos = st->next_bit_pos; @@ -143,7 +144,6 @@ ReadTnsData_ivas_fx( move16(); *pnBits = sub( st->next_bit_pos, start_bit_pos ); - #ifdef IVAS_CODE return; #else @@ -159,8 +159,8 @@ ReadTnsData_ivas_fx( Word16 DecodeTnsData( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; @@ -215,8 +215,8 @@ Word16 DecodeTnsData( Word16 DecodeTnsData_ivas_fx( STnsConfig const *pTnsConfig, - Word16 const *stream, - Word16 *pnSize, + Word16 const *stream, /*Q0*/ + Word16 *pnSize, /*Q0*/ STnsData *pTnsData ) { Word16 result; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index d601c6fa2..48e175a43 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -114,8 +114,8 @@ ivas_error ivas_core_enc( Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; /* 2 * Q_new */ Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ Word16 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; /* ACELP core synthesis at 12.8kHz or 16kHz to be used by the SWB BWE */ - Word16 *new_swb_speech_fx1; - Word16 new_swb_speech_buffer_fx1[L_FRAME48k + STEREO_DFT_OVL_MAX]; + Word16 *new_swb_speech_fx_16; + Word16 new_swb_speech_buffer_fx_16[L_FRAME48k + STEREO_DFT_OVL_MAX]; #endif int16_t Voicing_flag[CPE_CHANNELS]; #ifdef IVAS_FLOAT_FIXED_CONVERSIONS // required for float fixed conversions @@ -140,6 +140,9 @@ ivas_error ivas_core_enc( Word16 i; #endif + set32_fx( new_swb_speech_buffer_fx, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + set16_fx( new_swb_speech_buffer_fx_16, 0, L_FRAME48k + STEREO_DFT_OVL_MAX ); + #ifdef MSAN_FIX FOR( i = 0; i < CPE_CHANNELS; i++ ) { @@ -906,7 +909,7 @@ ivas_error ivas_core_enc( new_swb_speech = new_swb_speech_buffer + STEREO_DFT_OVL_MAX; #ifdef IVAS_FLOAT_FIXED new_swb_speech_fx = new_swb_speech_buffer_fx + STEREO_DFT_OVL_MAX; - new_swb_speech_fx1 = new_swb_speech_buffer_fx1 + STEREO_DFT_OVL_MAX; + new_swb_speech_fx_16 = new_swb_speech_buffer_fx_16 + STEREO_DFT_OVL_MAX; #endif if ( !st->Opt_SC_VBR && input_Fs >= 32000 && st->hBWE_TD != NULL ) @@ -916,7 +919,7 @@ ivas_error ivas_core_enc( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; + // Word16 new_swb_speech_16_fx[L_FRAME48k] = { 0 }; Word16 use_shb32 = 0; Word16 q_realImagBuffer = Q_factor_arrL( (float *) &realBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ); q_realImagBuffer = s_min( q_realImagBuffer, Q_factor_arrL( (float *) &imagBuffer[n][0][0], CLDFB_NO_COL_MAX * CLDFB_NO_CHANNELS_MAX ) ); @@ -963,7 +966,7 @@ ivas_error ivas_core_enc( } #endif #endif - swb_pre_proc_ivas_fx( st, new_swb_speech_16_fx, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); + swb_pre_proc_ivas_fx( st, new_swb_speech_fx_16, new_swb_speech_fx, shb_speech_fx, shb_speech_fx_32, &use_shb32, realBuffer_fx, imagBuffer_fx, q_realImagBuffer, hCPE ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS fixedToFloat_arr( (Word16 *) &st->hBWE_TD->old_speech_shb_fx[0], (float *) &st->hBWE_TD->old_speech_shb[0], 0, L_LOOK_16k + L_SUBFR16k ); fixedToFloat_arr( (Word16 *) &st->hBWE_FD->old_fdbwe_speech_fx[0], (float *) &st->hBWE_FD->old_fdbwe_speech[0], 0, L_FRAME48k ); @@ -973,7 +976,7 @@ ivas_error ivas_core_enc( st->hBWE_FD->old_input[ii] = (Word16) st->hBWE_FD->old_input_fx[ii]; } fixedToFloat_arrL32( (Word32 *) &st->cldfbSynTd->cldfb_state_fx[0], (float *) &st->cldfbSynTd->cldfb_state[0], q_realImagBuffer, st->cldfbSynTd->p_filter_length ); - fixedToFloat_arr( new_swb_speech_16_fx, new_swb_speech, 0, L_FRAME48k ); + fixedToFloat_arr( new_swb_speech_fx_16, new_swb_speech, 0, L_FRAME48k ); if ( use_shb32 == 0 ) { fixedToFloat_arr( shb_speech_fx, shb_speech, 0, L_FRAME16k ); @@ -1153,7 +1156,7 @@ ivas_error ivas_core_enc( for ( int ii = 0; ii < L_FRAME48k + STEREO_DFT_OVL_MAX; ii++ ) { - new_swb_speech_buffer_fx1[ii] = (Word16) new_swb_speech_buffer[ii]; + new_swb_speech_buffer_fx_16[ii] = (Word16) new_swb_speech_buffer[ii]; } for ( int ii = 0; ii < NS2SA( 48000, DELAY_FD_BWE_ENC_NS + DELAY_FIR_RESAMPL_NS ); ii++ ) { @@ -1161,7 +1164,7 @@ ivas_error ivas_core_enc( } #endif /* SWB(FB) BWE encoder */ - swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx1, shb_speech_fx, q_shb_speech_fx, q_val ); + swb_bwe_enc_ivas_fx( st, last_element_mode, old_inp_12k8_fx, old_inp_16k_fx, old_syn_12k8_16k_fx[n], new_swb_speech_fx_16, shb_speech_fx, q_shb_speech_fx, q_val ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( st->hBWE_FD != NULL ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 3cdbd36a0..b84e82262 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2128,6 +2128,9 @@ ivas_error pre_proc_front_ivas_fx( } stab_fac = (float) ( (float) stab_fac_fx / 32767.0f ); + + free( old_inp_12k8_loc_fx ); + #endif if ( element_mode == IVAS_CPE_TD && st->idchan == 1 ) { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 7891a753b..2a10d92d7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -138,6 +138,21 @@ ivas_error ivas_dirac_enc_open( } set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); } +#ifdef IVAS_FLOAT_FIXED + IF( ( hDirAC->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 DirAC\n" ) ); + } + + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); + } +#endif } hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); @@ -426,6 +441,10 @@ void ivas_dirac_enc_close( { free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; +#endif } for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) @@ -456,6 +475,10 @@ void ivas_dirac_enc_close( free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; +#endif } free( hDirAC->buffer_energy ); @@ -505,7 +528,159 @@ ivas_error ivas_dirac_enc( ivas_error error; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- float to fixed ----------------------------------------------*/ + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + Word16 block_m_idx; + Word16 band_m_idx; + Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; + Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Find Q-factor */ + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); + hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + Word16 tmp; + f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); + hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; + } + } + + for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) + { + hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); + hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); + } + for ( i = 0; i < NUM_ANA_SECTORS; i++ ) + { + for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) + { + f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); + f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); + } + } +#endif + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + /*---------------------------------------------- fixed to float ----------------------------------------------*/ + for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + if ( hodirac_flag ) + { + hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); + } + } + } + const int N_bands = hDirAC->hConfig->nbands; + for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) + { + for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) + { + hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); + hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); + hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); + hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); + } + for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) + { + hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); + } + } + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); + me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); + } + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + for ( int k = 0; k < N_bands; k++ ) + { + hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } + } + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); + } + } +#endif + if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -1400,9 +1575,10 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const UWord8 useLowerRes, - float *data_f[], - float **pp_fr_real, - float **pp_fr_imag, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, const Word16 input_frame, const IVAS_FORMAT ivas_format, const Word16 hodirac_flag, @@ -1410,116 +1586,31 @@ void ivas_dirac_param_est_enc( Word16 *mono_frame_count, Word16 *dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - Word32 **pp_fr_real_fx; - Word32 **pp_fr_imag_fx; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Assign memory */ - Word16 nblocks = useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->direction_vector_m_fx[0] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[1] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - hDirAC->direction_vector_m_fx[2] = (Word32 **) malloc( nblocks * sizeof( Word32 * ) ); - for ( int block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - hDirAC->direction_vector_m_fx[0][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[1][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - hDirAC->direction_vector_m_fx[2][block_m_idx] = (Word32 *) malloc( hDirAC->hConfig->nbands * sizeof( Word32 ) ); - } - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( int i = 0; i < nchan_fb_in; i++ ) - { - for ( int j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( pp_fr_real[i][j] ) ); - max_val = max( max_val, (float) fabs( pp_fr_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - /* Float to fixed */ - pp_fr_real_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - pp_fr_imag_fx = (Word32 **) calloc( nchan_fb_in, sizeof( Word32 * ) ); - for ( int i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_real_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - pp_fr_imag_fx[i] = (Word32 *) calloc( input_frame, sizeof( Word32 ) ); - for ( int j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( pp_fr_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( pp_fr_imag[i][j], pp_fr_q ); - } - } -#endif - - Word16 i, d, ts, index, l_ts, num_freq_bands; + Word16 i, j, k, d, ts, index, l_ts, num_freq_bands; Word16 band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; -#ifdef IVAS_FLOAT_FIXED Word32 dir_v_fx[DIRAC_NUM_DIMS]; -#endif - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_MAX_ANA_CHANS; i++ ) - { - set_zero( Cldfb_RealBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - set_zero( Cldfb_ImagBuffer[i], DIRAC_NO_FB_BANDS_MAX ); - } -#endif - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; Word32 *pcm_in_fx[DIRAC_MAX_ANA_CHANS]; Word32 Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; Word32 *p_Cldfb_RealBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word32 *p_Cldfb_ImagBuffer_fx[DIRAC_MAX_ANA_CHANS]; Word16 cldfb_q; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; -#ifdef IVAS_FLOAT_FIXED Word32 intensity_real_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 intensity_real_q = 0; + Word16 intensity_real_q; Word32 direction_vector_fx[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - Word16 direction_vector_q = 0; + Word16 direction_vector_q; Word32 diffuseness_vector_fx[DIRAC_MAX_NBANDS]; - Word16 diffuseness_vector_q = 0; - move16(); - move16(); - move16(); -#endif - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + Word16 diffuseness_vector_q; Word32 renormalization_factor_fx[DIRAC_MAX_NBANDS]; + Word16 renormalization_factor_exp; Word32 renormalization_factor_diff_fx[DIRAC_MAX_NBANDS]; - float norm_tmp; + Word16 renormalization_factor_diff_exp[DIRAC_MAX_NBANDS]; + Word32 norm_tmp_fx; + Word16 norm_tmp_exp; Word16 mrange[2]; Word16 num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word32 reference_power_fx[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; Word16 reference_power_exp; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 azi_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 ele_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; Word32 diff_secs_fx[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; @@ -1534,6 +1625,12 @@ void ivas_dirac_param_est_enc( /* Initialization */ cldfb_q = 0; move16(); + intensity_real_q = 0; + move16(); + direction_vector_q = 0; + move16(); + diffuseness_vector_q = 0; + move16(); l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); IF( useLowerRes ) @@ -1553,7 +1650,11 @@ void ivas_dirac_param_est_enc( /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ set_zero_fx( hDirAC->diffuseness_m_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( hDirAC->diffuseness_m_exp, hDirAC->hConfig->nbands ); set_zero_fx( renormalization_factor_diff_fx, hDirAC->hConfig->nbands ); + set16_zero_fx( renormalization_factor_diff_exp, hDirAC->hConfig->nbands ); + reference_power_exp = 0; + move16(); set_zero_fx( azi_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); set_zero_fx( ele_secs_fx, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); @@ -1563,168 +1664,45 @@ void ivas_dirac_param_est_enc( set16_zero_fx( ene_secs_exp, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); /* Copy current frame to memory for delay compensation */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* assign memory */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] = data_f_fx[i]; p_Cldfb_RealBuffer_fx[i] = &Cldfb_RealBuffer_fx[i][0]; p_Cldfb_ImagBuffer_fx[i] = &Cldfb_ImagBuffer_fx[i][0]; } -#if 1 - /* using void temporarily to avoid null */ - (void) p_Cldfb_RealBuffer_fx; - (void) p_Cldfb_ImagBuffer_fx; - (void) p_Cldfb_RealBuffer; - (void) p_Cldfb_ImagBuffer; - (void) pcm_in_fx; - (void) pcm_in; -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /* Fixed to float */ - fixedToFloat_arrL( azi_secs_fx, azi_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ele_secs_fx, ele_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( diff_secs_fx, diff_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - fixedToFloat_arrL( ene_secs_fx, ene_secs, 0, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - fixedToFloat_arrL( hDirAC->diffuseness_m_fx, hDirAC->diffuseness_m, 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( renormalization_factor_diff_fx, renormalization_factor_diff, 0, hDirAC->hConfig->nbands ); -#endif - -#else - int16_t i, d, ts, index, l_ts, num_freq_bands; - int16_t band_m_idx, block_m_idx; - float dir_v[DIRAC_NUM_DIMS]; - float *pcm_in[DIRAC_MAX_ANA_CHANS]; - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; - float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; - float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; - float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; - float diffuseness_vector[DIRAC_MAX_NBANDS]; - float renormalization_factor[DIRAC_MAX_NBANDS]; - float renormalization_factor_diff[DIRAC_MAX_NBANDS]; - float norm_tmp; - int16_t mrange[2]; - int16_t num_blocks; - float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; - float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; - - push_wmops( "dirac_enc_param_est" ); - num_freq_bands = hDirAC->hConfig->nbands; - - /* Initialization */ - l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - if ( useLowerRes ) - { - q_direction->cfg.nblocks = 1; - num_blocks = 1; - } - else - { - q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - renormalization_factor_diff[i] = 0; - hDirAC->diffuseness_m[i] = 0; - } - - set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); - - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] = data_f[i]; - p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; - p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; - } -#endif /* ifdef IVAS_FLOAT_FIXED */ /* do processing over all CLDFB time slots */ - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) { -#ifdef IVAS_FLOAT_FIXED mrange[0] = hDirAC->block_grouping[block_m_idx]; move16(); mrange[1] = hDirAC->block_grouping[add( block_m_idx, 1 )]; move16(); set32_fx( renormalization_factor_fx, EPSILON_FX, hDirAC->hConfig->nbands ); + renormalization_factor_exp = 0; + move16(); set_zero_fx( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->hConfig->nbands ); set_zero_fx( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->hConfig->nbands ); + hDirAC->direction_vector_m_exp[block_m_idx] = 0; + move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - set_f( renormalization_factor, EPSILON, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[0][block_m_idx], hDirAC->direction_vector_m[0][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[1][block_m_idx], hDirAC->direction_vector_m[1][block_m_idx], 0, hDirAC->hConfig->nbands ); - fixedToFloat_arrL( hDirAC->direction_vector_m_fx[2][block_m_idx], hDirAC->direction_vector_m[2][block_m_idx], 0, hDirAC->hConfig->nbands ); -#endif + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + IF( hDirAC->hFbMixer ) + { + ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); -#else - mrange[0] = hDirAC->block_grouping[block_m_idx]; - mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; - - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - renormalization_factor[band_m_idx] = EPSILON; - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; - } -#endif - - for ( ts = mrange[0]; ts < mrange[1]; ts++ ) - { - if ( hDirAC->hFbMixer ) - { -#ifdef IVAS_FLOAT_FIXED - ivas_fb_mixer_get_windowed_fr_fx( hDirAC->hFbMixer, pcm_in_fx, p_Cldfb_RealBuffer_fx, p_Cldfb_ImagBuffer_fx, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans, 0 ); - - ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + ivas_fb_mixer_update_prior_input_fx( hDirAC->hFbMixer, pcm_in_fx, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); FOR( i = 0; i < nchan_fb_in; i++ ) { pcm_in_fx[i] += l_ts; } -#else - ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); - - for ( i = 0; i < nchan_fb_in; i++ ) - { - pcm_in[i] += l_ts; - } -#endif } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } FOR( i = 0; i < nchan_fb_in; i++ ) { Copy32( &pp_fr_real_fx[i][imult1616( ts, l_ts )], Cldfb_RealBuffer_fx[i], l_ts ); @@ -1732,94 +1710,31 @@ void ivas_dirac_param_est_enc( } cldfb_q = pp_fr_q; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_fb_in; i++ ) - { - fixedToFloat_arrL( Cldfb_ImagBuffer_fx[i], Cldfb_ImagBuffer[i], cldfb_q, l_ts ); - fixedToFloat_arrL( Cldfb_RealBuffer_fx[i], Cldfb_RealBuffer[i], cldfb_q, l_ts ); - } -#endif -#else - for ( i = 0; i < nchan_fb_in; i++ ) - { - mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); - mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); - } -#endif - } - -#ifndef IVAS_FLOAT_FIXED - computeReferencePower_enc( - hDirAC->band_grouping, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - reference_power[ts], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - ivas_format, - hodirac_flag ? 0 : 1, - FOA_CHANNELS, - mono_frame_count, - dirac_mono_flag ); -#else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 Q_Cldfb = 31; - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Q_Cldfb = s_min( Q_Cldfb, Q_factor_L( Cldfb_RealBuffer[x][k] ) ); - } - } - Word16 guard = find_guarded_bits_fx( 16 ) / 2; // Guard bits to avoid the precision loss for the reference_power - Word16 e_reference; - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_RealBuffer[k], Cldfb_RealBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 k = 0; k < FOA_CHANNELS; k++ ) - { - floatToFixed_arrL( Cldfb_ImagBuffer[k], Cldfb_ImagBuffer_fx[k], Q_Cldfb, DIRAC_NO_FB_BANDS_MAX ); - } - - FOR( Word16 x = 0; x < FOA_CHANNELS; x++ ) - { - FOR( Word16 k = 0; k < DIRAC_NO_FB_BANDS_MAX; k++ ) - { - Cldfb_RealBuffer_fx[x][k] = L_shr( Cldfb_RealBuffer_fx[x][k], guard ); - Cldfb_ImagBuffer_fx[x][k] = L_shr( Cldfb_ImagBuffer_fx[x][k], guard ); - } } - Q_Cldfb = sub( Q_Cldfb, guard ); - Word16 hodirac_flag_temp = 1; + Word16 ref_power_w = 1; + move16(); IF( hodirac_flag ) { - hodirac_flag_temp = 0; + ref_power_w = 0; + move16(); } -#endif + computeReferencePower_enc_fx_dirac( hDirAC->band_grouping, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, - sub( 31, Q_Cldfb ), + sub( 31, cldfb_q ), reference_power_fx[ts], - &e_reference, + &reference_power_exp, hDirAC->hConfig->enc_param_start_band, num_freq_bands, ivas_format, - hodirac_flag_temp, + ref_power_w, FOA_CHANNELS, mono_frame_count, dirac_mono_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( reference_power_fx[ts], reference_power[ts], 31 - e_reference, DIRAC_NO_FB_BANDS_MAX ); -#endif -#endif -#ifdef IVAS_FLOAT_FIXED computeIntensityVector_enc_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -1828,29 +1743,10 @@ void ivas_dirac_param_est_enc( num_freq_bands, intensity_real_fx ); - // intensity_real_q = 2 * Q_Cldfb + 1 - 32; - intensity_real_q = sub( shl( Q_Cldfb, 1 ), 31 ); - move16(); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( intensity_real_fx[i], intensity_real[i], intensity_real_q, num_freq_bands ); - } -#endif -#else - computeIntensityVector_enc( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - intensity_real ); -#endif + intensity_real_q = sub( shl( cldfb_q, 1 ), 31 ); // 2 * Q_Cldfb + 1 - 32; - if ( !hodirac_flag ) + IF( !hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED computeDirectionVectors_fixed( intensity_real_fx[0], intensity_real_fx[1], @@ -1864,153 +1760,71 @@ void ivas_dirac_param_est_enc( direction_vector_q = Q30; move16(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - fixedToFloat_arrL( direction_vector_fx[i], direction_vector[i], direction_vector_q, num_freq_bands ); - } -#endif -#else - computeDirectionVectors( - intensity_real[0], - intensity_real[1], - intensity_real[2], - hDirAC->hConfig->enc_param_start_band, - num_freq_bands, - direction_vector[0], - direction_vector[1], - direction_vector[2] ); -#endif } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS -#define MAX_NUM_INDEX_INTENSITY ( 10 ) /* NOTE: arbitrary value. need to check exact max value of "index"*/ - Word32 buffer_intensity_real_fx[DIRAC_NUM_DIMS][MAX_NUM_INDEX_INTENSITY][DIRAC_MAX_NBANDS]; - Word32 buffer_energy_fx[MAX_NUM_INDEX_INTENSITY * DIRAC_MAX_NBANDS]; - max_val = 0; - Word32 tmp32; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - float tmpf; - maximumAbs( intensity_real[i], num_freq_bands, &tmpf ); - max_val = fmaxf( max_val, tmpf ); - } - Word16 intensity_real_exp; - f2me( max_val, &tmp32, &intensity_real_exp ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( int j = 0; j < num_freq_bands; j++ ) - { - intensity_real_fx[i][j] = (Word32) ( intensity_real[i][j] * powf( 2, 31.f - intensity_real_exp ) ); - } - } - f2me_buf( reference_power[ts], reference_power_fx[ts], &reference_power_exp, num_freq_bands ); -#endif /* fill buffers of length "averaging_length" time slots for intensity and energy */ hDirAC->index_buffer_intensity = add( ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hDirAC->index_buffer_intensity; move16(); - assert( index <= MAX_NUM_INDEX_INTENSITY ); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hDirAC->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_intensity_real_q[i][index - 1][0], intensity_real_q, num_freq_bands ); } - Copy32( reference_power_fx[ts], &( buffer_energy_fx[imult1616( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Copy32( reference_power_fx[ts], &( hDirAC->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + set16_fx( &hDirAC->buffer_energy_q[( index - 1 ) * num_freq_bands], sub( 31, reference_power_exp ), num_freq_bands ); + + Word16 buffer_intensity_real_single_q; + buffer_intensity_real_single_q = hDirAC->buffer_intensity_real_q[0][0][0]; + move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - me2f_buf( &buffer_intensity_real_fx[i][index - 1][0], intensity_real_exp, &hDirAC->buffer_intensity_real[i][index - 1][0], num_freq_bands ); - } - me2f_buf( &buffer_energy_fx[( index - 1 ) * num_freq_bands], reference_power_exp, &hDirAC->buffer_energy[( index - 1 ) * num_freq_bands], num_freq_bands ); -#endif -#else - /* fill buffers of length "averaging_length" time slots for intensity and energy */ - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ - index = hDirAC->index_buffer_intensity; - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - /* only real part needed */ - mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + buffer_intensity_real_single_q = s_min( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ); + } + } } - mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); -#endif - - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 buffer_intensity_real_q = 0; - float max_buffer_intensity_real_val = 0; - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { - for ( int k = 0; k < num_freq_bands; k++ ) + FOR( k = 0; k < num_freq_bands; k++ ) { - max_buffer_intensity_real_val = max( max_buffer_intensity_real_val, (float) fabs( hDirAC->buffer_intensity_real[j][i][k] ) ); + hDirAC->buffer_intensity_real_fx[i][j][k] = L_shl( hDirAC->buffer_intensity_real_fx[i][j][k], sub( buffer_intensity_real_single_q, hDirAC->buffer_intensity_real_q[i][j][k] ) ); + move32(); + hDirAC->buffer_intensity_real_q[i][j][k] = buffer_intensity_real_single_q; + move16(); } } } - Word32 tmp_var = 0; - Word16 buffer_intensity_real_buff_e = 0; - f2me( (float) fabs( max_buffer_intensity_real_val ), &tmp_var, &buffer_intensity_real_buff_e ); - buffer_intensity_real_q = sub( 31, buffer_intensity_real_buff_e ); - for ( i = 0; i < hDirAC->no_col_avg_diff; i++ ) + Word16 buffer_energy_single_q; + Word16 buffer_len; + buffer_len = imult1616( DIRAC_MAX_NBANDS, hDirAC->no_col_avg_diff ); + minimum_fx( hDirAC->buffer_energy_q, buffer_len, &buffer_energy_single_q ); + FOR( i = 0; i < buffer_len; i++ ) { - for ( int j = 0; j < DIRAC_NUM_DIMS; j++ ) - { - floatToFixed_arrL( hDirAC->buffer_intensity_real[j][i], hDirAC->buffer_intensity_real_fx[j][i], buffer_intensity_real_q, num_freq_bands ); - } + hDirAC->buffer_energy_fx[i] = L_shl( hDirAC->buffer_energy_fx[i], sub( buffer_energy_single_q, hDirAC->buffer_energy_q[i] ) ); + move32(); + hDirAC->buffer_energy_q[i] = buffer_energy_single_q; + move16(); } - Word16 buffer_energy_e = 0; - Word16 buffer_energy_q = 0; - move16(); - move16(); - f2me_buf( hDirAC->buffer_energy, hDirAC->buffer_energy_fx, &buffer_energy_e, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - buffer_energy_q = sub( 31, buffer_energy_e ); -#endif - Word16 *buffer_energy_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - Word16 *buffer_intensity_real_buff_q = (Word16 *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( Word16 ) ); - set16_fx( buffer_energy_buff_q, buffer_energy_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - set16_fx( buffer_intensity_real_buff_q, buffer_intensity_real_q, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); + Word16 tmp_q_buffer_for_intensity[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; + Word16 tmp_q_buffer_for_energy[DIRAC_MAX_NBANDS * DIRAC_NO_COL_AVG_DIFF]; - computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, buffer_intensity_real_buff_q, buffer_energy_buff_q, &diffuseness_vector_q ); + set16_fx( tmp_q_buffer_for_intensity, buffer_intensity_real_single_q, buffer_len ); + set16_fx( tmp_q_buffer_for_energy, buffer_energy_single_q, buffer_len ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - fixedToFloat_arrL( diffuseness_vector_fx, diffuseness_vector, diffuseness_vector_q, num_freq_bands ); -#endif - free( buffer_energy_buff_q ); - buffer_energy_buff_q = NULL; - free( buffer_intensity_real_buff_q ); - buffer_intensity_real_buff_q = NULL; -#else - computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); -#endif + computeDiffuseness_mdft_fx( hDirAC->buffer_intensity_real_fx, hDirAC->buffer_energy_fx, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector_fx, tmp_q_buffer_for_intensity, tmp_q_buffer_for_energy, &diffuseness_vector_q ); - if ( hodirac_flag ) + IF( hodirac_flag ) { -#ifdef IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( int j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } -#endif calculate_hodirac_sector_parameters_fx( hDirAC, Cldfb_RealBuffer_fx, @@ -2026,189 +1840,188 @@ void ivas_dirac_param_est_enc( diff_secs_exp, ene_secs_fx, ene_secs_exp ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - azi_secs[i_sec * N_bands + i_band] = fix_to_float( azi_secs_fx[i_sec * N_bands + i_band], Q23 ); - ele_secs[i_sec * N_bands + i_band] = fix_to_float( ele_secs_fx[i_sec * N_bands + i_band], Q23 ); - ene_secs[i_sec * N_bands + i_band] = me2f( ene_secs_fx[i_sec * N_bands + i_band], ene_secs_exp[i_sec * N_bands + i_band] ); - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - diff_secs[i_sec * N_bands + i_band] = me2f( diff_secs_fx[i_sec * N_bands + i_band], diff_secs_exp[i_sec * N_bands + i_band] ); - } - } -#endif - -#else - calculate_hodirac_sector_parameters( - hDirAC, - Cldfb_RealBuffer, - Cldfb_ImagBuffer, - 0.20f, - hDirAC->band_grouping, - hDirAC->hConfig->nbands, - hDirAC->hConfig->enc_param_start_band, - azi_secs, - ele_secs, - diff_secs, - ene_secs ); -#endif } - if ( hodirac_flag ) + const Word16 gbits = 4; // 4 guard bits + move16(); + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } } - else + ELSE { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); - - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; - renormalization_factor[band_m_idx] += norm_tmp; + Word32 tmp_diff = L_shr( diffuseness_vector_fx[band_m_idx], sub( diffuseness_vector_q, 30 ) ); // diffueseness_vector_q -> Q30 + norm_tmp_fx = Mpy_32_32( reference_power_fx[ts][band_m_idx], L_sub( ONE_IN_Q30, tmp_diff ) ); - hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; - renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ), gbits ) ); + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], L_shr( Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ), gbits ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], L_shr( norm_tmp_fx, gbits ) ); + move32(); + hDirAC->diffuseness_m_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx], + Mpy_32_32( reference_power_fx[ts][band_m_idx], tmp_diff ), add( reference_power_exp, 1 ), &hDirAC->diffuseness_m_exp[band_m_idx] ); + move32(); + renormalization_factor_diff_fx[band_m_idx] = BASOP_Util_Add_Mant32Exp( renormalization_factor_diff_fx[band_m_idx], renormalization_factor_diff_exp[band_m_idx], + reference_power_fx[ts][band_m_idx], reference_power_exp, &renormalization_factor_diff_exp[band_m_idx] ); + move32(); } + norm_tmp_exp = add( reference_power_exp, 1 ); + hDirAC->direction_vector_m_exp[block_m_idx] = add( norm_tmp_exp, add( sub( 31, direction_vector_q ), gbits ) ); + move32(); + renormalization_factor_exp = add( norm_tmp_exp, gbits ); } } - if ( !hodirac_flag ) + IF( !hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - renormalization_factor[band_m_idx] = EPSILON; - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) - { - renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); - } - renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + renormalization_factor_fx[band_m_idx] = EPSILON_FX; + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_fx[band_m_idx] = L_add( renormalization_factor_fx[band_m_idx], Mpy_32_32( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] ) ); + move32(); + renormalization_factor_exp = shl( hDirAC->direction_vector_m_exp[block_m_idx], 1 ); // 2 * direction_vector_m_exp + renormalization_factor_fx[band_m_idx] = Sqrt32( renormalization_factor_fx[band_m_idx], &renormalization_factor_exp ); + move32(); - if ( renormalization_factor[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + Word16 tmp_e; + Word32 tmp32; + + tmp32 = hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); + + tmp32 = hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx]; + move32(); + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( tmp32, renormalization_factor_fx[band_m_idx], &tmp_e ) ); + tmp_e = add( tmp_e, sub( hDirAC->direction_vector_m_exp[block_m_idx], renormalization_factor_exp ) ); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_shr( tmp32, sub( 1, tmp_e ) ); // Q30 + move32(); } - else + ELSE { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx] = ONE_IN_Q30; + move32(); + hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx] = 0; + move32(); + hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx] = 0; + move32(); } + hDirAC->direction_vector_m_exp[block_m_idx] = 1; + move16(); /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ - for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + FOR( d = 0; d < DIRAC_NUM_DIMS; d++ ) { - dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + dir_v_fx[d] = hDirAC->direction_vector_m_fx[d][block_m_idx][band_m_idx]; // Q30 + move32(); } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_dir_e = 0; - f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); Scale_sig32( dir_v_fx, 3, -1 ); -#endif - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, - Q31 - q_dir_e, + Q30, &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); -#endif -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( - dir_v, - &q_direction->band_data[band_m_idx].azimuth[block_m_idx], - &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); -#endif } } /* Sectors */ - if ( hodirac_flag ) + IF( hodirac_flag ) { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; - q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; - // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 + move32(); - q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; - q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); - } - } - } + q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 + move32(); + Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); + Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); -#ifdef IVAS_FLOAT_FIXED - for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) - { - free( hDirAC->direction_vector_m_fx[0][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[1][block_m_idx] ); - free( hDirAC->direction_vector_m_fx[2][block_m_idx] ); + Word16 tmp16 = extract_h( L_add( x, y ) ); + Word32 tmp32; + IF( tmp16 == 0 ) + { + tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + } + ELSE + { + tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + } + tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 + } + } } - free( hDirAC->direction_vector_m_fx[0] ); - free( hDirAC->direction_vector_m_fx[1] ); - free( hDirAC->direction_vector_m_fx[2] ); -#endif /* Diffuseness */ - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + IF( GT_32( renormalization_factor_diff_fx[band_m_idx], EPSILON_FX ) ) { - hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + Word16 tmp_e; + hDirAC->diffuseness_m_fx[band_m_idx] = L_deposit_h( BASOP_Util_Divide3232_Scale( hDirAC->diffuseness_m_fx[band_m_idx], renormalization_factor_diff_fx[band_m_idx], &tmp_e ) ); + move32(); + tmp_e = add( tmp_e, sub( hDirAC->diffuseness_m_exp[band_m_idx], renormalization_factor_diff_exp[band_m_idx] ) ); + hDirAC->diffuseness_m_fx[band_m_idx] = L_shr( hDirAC->diffuseness_m_fx[band_m_idx], sub( 1, tmp_e ) ); // to Q30 + move32(); } - else + ELSE { - hDirAC->diffuseness_m[band_m_idx] = 0.f; + hDirAC->diffuseness_m_fx[band_m_idx] = 0; + move32(); } + hDirAC->diffuseness_m_exp[band_m_idx] = 1; + move16(); /* set coherence to zero and convert diffuseness to energy ratio*/ - set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + set32_fx( q_direction->band_data[band_m_idx].energy_ratio_fx, L_sub( ONE_IN_Q30, hDirAC->diffuseness_m_fx[band_m_idx] ), q_direction->cfg.nblocks ); - for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + FOR( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) { - if ( q_direction->coherence_band_data != NULL ) + IF( q_direction->coherence_band_data != NULL ) { q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + move16(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_fb_in; i++ ) - { - free( data_f_fx[i] ); - free( pp_fr_real_fx[i] ); - free( pp_fr_imag_fx[i] ); - } - free( pp_fr_real_fx ); - free( pp_fr_imag_fx ); -#endif - pop_wmops(); return; } diff --git a/lib_enc/ivas_mdct_core_enc.c b/lib_enc/ivas_mdct_core_enc.c index aecf4c9a9..f8787ab7d 100644 --- a/lib_enc/ivas_mdct_core_enc.c +++ b/lib_enc/ivas_mdct_core_enc.c @@ -2128,9 +2128,14 @@ void ivas_mdct_core_whitening_enc( bw_detect( st, NULL, st->hTcxEnc->spectrum[n], NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifdef MSAN_FIX + q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], st->hTcxEnc->L_frameTCX / ( n + 1 ) ); + floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, st->hTcxEnc->L_frameTCX / ( n + 1 ) ); +#else Word16 l_frame = (int16_t) ( st->input_Fs / FRAMES_PER_SEC ); q_spectrum = Q_factor_arr( st->hTcxEnc->spectrum[n], l_frame ); floatToFixed_arr( st->hTcxEnc->spectrum[n], spect_fx[n], q_spectrum, l_frame ); +#endif #endif bw_detect_fx( st, NULL, spect_fx[n], NULL, NULL, MC_FORMAT /*just cannot be ISM_FORMAT*/, mct_on ); #endif diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 6777a8527..2ba611679 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -861,8 +861,15 @@ static ivas_error ivas_spar_cov_md_process( move32(); FOR( i = 1; i < nchan_inp; i++ ) { - Word32 tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); - tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + Word32 tmp = 0; + move32(); + tmp_e = 0; + move16(); + IF( cov_real_fx[0][0][b] != 0 ) + { + tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( cov_real_fx[i][i][b], cov_real_fx[0][0][b], &tmp_e ) ); + tmp_e = add( tmp_e, sub( sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][i][b] ), sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[0][0][b] ) ) ); + } Wscale_d_fx[b] = BASOP_Util_Add_Mant32Exp( tmp, tmp_e, Wscale_d_fx[b], Wscale_d_e, &Wscale_d_e ); move32(); } @@ -1125,9 +1132,9 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - FOR( Word16 m = 0; m < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; m++ ) + FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) { - IF( data_f[m] != NULL && ( m <= nchan_fb_in + nchan_transport ) ) + IF( data_f[m] != NULL ) { q_data_fix[m] = Q_factor_arrL( data_f[m], input_frame ); floatToFixed_arrL( data_f[m], data_fix[m], q_data_fix[m], input_frame ); @@ -1325,9 +1332,73 @@ static ivas_error ivas_spar_enc_process( fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } #endif +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 mixer_q = 31; + Word16 prior_mixer_q = 31; + Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); + } + } + + mixer_q = s_min( mixer_q, prior_mixer_q ); + // both should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + } + } + + hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; +#endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + // both mixer_mat_fx and prior mixer_mat_fx should have a common q as there are values being copied inside function + // or need to do loop for updating values for unused values + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, p_pcm_tmp_fx, q_p_pcm_tmp_loc_fx, input_frame, in_out_mixer_map ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( int ch = ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ); ch < hSpar->hFbMixer->fb_cfg->num_out_chans; ch++ ) + { + for ( int k = 0; k < input_frame; k++ ) + { + p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); + } + } + + // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; + // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; + // should be same + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + { + fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); + } + } +#endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { @@ -1337,7 +1408,7 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag != dyn_active_w_flag ) { float new_w[L_FRAME48k]; - + Word32 new_w_fx[L_FRAME48k]; /* delayed W */ mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); @@ -1347,11 +1418,47 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 0 && dyn_active_w_flag == 1 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, p_pcm_tmp[0], new_w, 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, p_pcm_tmp_fx[0], new_w_fx, 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } else if ( hSpar->hMdEnc->spar_md.prior_dyn_active_w_flag == 1 && dyn_active_w_flag == 0 ) { +#ifndef IVAS_FLOAT_FIXED ivas_fb_mixer_cross_fading( hSpar->hFbMixer, p_pcm_tmp, new_w, p_pcm_tmp[0], 0, input_frame, 0 ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arrL32( new_w, new_w_fx, Q11, input_frame ); + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + p_pcm_tmp_fx[i] = &pcm_tmp_fx[i][0]; + floatToFixed_arrL32( p_pcm_tmp[i], p_pcm_tmp_fx[i], Q11, input_frame ); + } +#endif + ivas_fb_mixer_cross_fading_fx( hSpar->hFbMixer, p_pcm_tmp_fx, new_w_fx, p_pcm_tmp_fx[0], 0, input_frame, 0 ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + fixedToFloat_arrL32( p_pcm_tmp_fx[i], p_pcm_tmp[i], Q11, input_frame ); + } +#endif +#endif } } else diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 13c9bdc0a..357e52230 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -299,6 +299,7 @@ ivas_error ivas_spar_md_enc_open_fx( * Deallocate SPAR MD encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) @@ -331,12 +332,80 @@ void ivas_spar_md_enc_close( } free( hMdEnc->mixer_mat ); } +#ifdef IVAS_FLOAT_FIXED + IF( hMdEnc->mixer_mat_fx != NULL ) + { + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_fx[i][j] ); + } + free( hMdEnc->mixer_mat_fx[i] ); + } + free( hMdEnc->mixer_mat_fx ); + } +#endif free( *hMdEnc_in ); *hMdEnc_in = NULL; return; } +#else +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +{ + int16_t num_channels, i, j; + ivas_spar_md_enc_state_t *hMdEnc; + + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + + hMdEnc = *hMdEnc_in; + num_channels = hMdEnc->num_umx_ch; + + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } + if ( hMdEnc->mixer_mat != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat[i][j] ); + } + free( hMdEnc->mixer_mat[i] ); + } + free( hMdEnc->mixer_mat ); + } + + if ( hMdEnc->mixer_mat_local != NULL ) + { + for ( i = 0; i < num_channels; i++ ) + { + + for ( j = 0; j < num_channels; j++ ) + { + free( hMdEnc->mixer_mat_local[i][j] ); + } + free( hMdEnc->mixer_mat_local[i] ); + } + free( hMdEnc->mixer_mat_local ); + } + + free( *hMdEnc_in ); + *hMdEnc_in = NULL; + + return; +} +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 746d5712a..4c3eca4d9 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -942,8 +942,10 @@ typedef struct ivas_dirac_enc_data_structure float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ float diffuseness_m[DIRAC_MAX_NBANDS]; #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_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; + Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; @@ -979,7 +981,9 @@ typedef struct ivas_dirac_enc_data_structure float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; + Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; + Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; #endif /* Frame count for detecting mono */ @@ -1061,7 +1065,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 HOA_md_ind[IVAS_SPAR_MAX_CH]; Word32 ***mixer_mat_fx; Word16 q_mixer_mat_fx; - Word32 ***mixer_mat_local_fx; } ivas_spar_md_enc_state_t; /* PCA structure */ diff --git a/lib_enc/swb_pre_proc.c b/lib_enc/swb_pre_proc.c index de6cafa55..b8c891d3c 100644 --- a/lib_enc/swb_pre_proc.c +++ b/lib_enc/swb_pre_proc.c @@ -567,7 +567,7 @@ void swb_pre_proc_ivas_fx( { Word16 out_start_ind, out_end_ind; stereo_dft_enc_synthesize_fx( hCPE->hStereoDft, new_swb_speech_fx, &out_start_ind, &out_end_ind, st->idchan, input_Fs, 32000, 0, NULL ); - Copy_Scale_sig32_16( new_swb_speech_fx, new_swb_speech, q_reImBuffer, L_FRAME48k ); + Copy_Scale_sig32_16( new_swb_speech_fx - STEREO_DFT_OVL_MAX, new_swb_speech - STEREO_DFT_OVL_MAX, q_reImBuffer, L_FRAME48k + STEREO_DFT_OVL_MAX ); Copy( new_swb_speech - Sample_Delay_SWB_BWE32k, hBWE_FD->old_input_fx, Sample_Delay_SWB_BWE32k ); } } -- GitLab From 3873dec200377f6bad939115c5be35ae601f1b14 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Wed, 23 Oct 2024 12:09:44 +0300 Subject: [PATCH 16/39] fix 953 --- lib_com/options.h | 2 ++ lib_dec/ivas_masa_dec.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 819f2a42f..f1023d3b6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -193,6 +193,8 @@ #define FIX_930_JBM_BUFSIZE_MULT /* FhG: Fix 930, Word16 too small for apa_buffer_size */ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ +#define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 13e970f85..f3962ced2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4438,6 +4438,13 @@ static void create_masa_ext_out_meta_fx( move16(); FOR( dir = 0; dir < numDirections; dir++ ) { +#ifdef FIX_953_WRONG_ENERGY_RATIO_MASA_EXT + /* todo: not optimal, but less invasive */ + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); extOutMeta->diffuseToTotalRatio[sf][b_new] = (UWord8) sub( extOutMeta->diffuseToTotalRatio[sf][b_new], tmp ); // Q8 -- GitLab From a40470201a978eb8397f16c103276b9f1cbc25f7 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 11:36:50 +0530 Subject: [PATCH 17/39] Encoder LTV crash fix, MSAN/ASAN error fix and Q-info updates --- lib_com/ivas_mdct_imdct_fx.c | 162 +++++----- lib_com/ivas_prot.h | 7 + lib_com/ivas_prot_fx.h | 8 + lib_com/ivas_qmetadata_com.c | 15 +- lib_com/ivas_qspherical_com.c | 78 +++++ lib_com/ivas_rom_com_fx.c | 106 +++---- lib_com/ivas_rom_com_fx.h | 4 +- lib_com/ivas_spar_com.c | 19 +- lib_com/ivas_stat_com.h | 14 +- lib_com/modif_fs_fx.c | 6 +- lib_com/prot_fx.h | 86 +++--- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/hq_lr_dec_fx.c | 357 +++++++++++----------- lib_dec/lsf_dec_fx.c | 270 ++++++++--------- lib_dec/lsf_msvq_ma_dec_fx.c | 100 ++++--- lib_dec/nelp_dec_fx.c | 48 +-- lib_enc/init_enc.c | 4 + lib_enc/ivas_core_enc.c | 4 +- lib_enc/ivas_core_pre_proc.c | 4 +- lib_enc/ivas_dirac_enc.c | 118 ++++---- lib_enc/ivas_enc.c | 88 +++--- lib_enc/ivas_init_enc.c | 26 -- lib_enc/ivas_masa_enc.c | 175 ++++++++--- lib_enc/ivas_mc_param_enc.c | 4 + lib_enc/ivas_mcmasa_enc.c | 28 +- lib_enc/ivas_mct_enc.c | 26 -- lib_enc/ivas_qmetadata_enc.c | 12 +- lib_enc/ivas_qspherical_enc.c | 8 +- lib_enc/ivas_spar_encoder.c | 9 +- lib_enc/ivas_stat_enc.h | 13 +- lib_enc/ivas_stereo_cng_enc.c | 33 +- lib_rend/ivas_efap.c | 514 +++++++++++++++++--------------- 32 files changed, 1254 insertions(+), 1094 deletions(-) diff --git a/lib_com/ivas_mdct_imdct_fx.c b/lib_com/ivas_mdct_imdct_fx.c index c25f4fab4..37c525109 100644 --- a/lib_com/ivas_mdct_imdct_fx.c +++ b/lib_com/ivas_mdct_imdct_fx.c @@ -63,9 +63,9 @@ *-----------------------------------------------------------------------------------------*/ 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 Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ) { Word16 i; @@ -74,9 +74,9 @@ void ivas_tda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); /* Q10*/ move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( i_mult( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); /* Q10*/ move32(); } @@ -91,32 +91,32 @@ void ivas_tda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, - Word32 *pTemp_lfe ) + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 + Word32 *pTemp_lfe ) // Q10 { Word16 i; Word16 rem_len; rem_len = 0; move16(); - Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); + Copy32( pBuffer_prev, pOut_buf + zero_pad_len, fade_len ); // Q10 - Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); + Copy32( pTemp_lfe, ( pOut_buf + add( fade_len, zero_pad_len ) ), dct_len ); // Q10 set32_fx( pOut_buf, 0, zero_pad_len ); - Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); + Copy32( ( pOut_buf + sub( full_len, fade_len ) ), pBuffer_prev, fade_len ); // Q10 FOR( i = 0; i < fade_len; i++ ) { - pOut_buf[add( zero_pad_len, i )] = Mult_32_32( pOut_buf[add( zero_pad_len, i )], pWindow_coeffs[i] ); + pOut_buf[zero_pad_len + i] = Mult_32_32( pOut_buf[zero_pad_len + i], pWindow_coeffs[i] ); // Q10 move32(); } @@ -124,7 +124,7 @@ void ivas_dct_windowing_fx( FOR( i = 0; i < rem_len; i++ ) { - pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )] = Mult_32_32( pOut_buf[add( add( i_mult( zero_pad_len, 3 ), fade_len ), i )], pWindow_coeffs[sub( sub( fade_len, i ), 1 )] ); + pOut_buf[zero_pad_len * 3 + fade_len + i] = Mult_32_32( pOut_buf[zero_pad_len * 3 + fade_len + i], pWindow_coeffs[fade_len - i - 1] ); // Q10 move32(); } @@ -141,9 +141,9 @@ void ivas_dct_windowing_fx( *-----------------------------------------------------------------------------------------*/ void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -152,23 +152,23 @@ void ivas_mdct_fx( Word32 ivas_mdct_scaling_gain; len_by_2 = shr( length, 1 ); - ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); + ivas_mdct_scaling_gain = ivas_get_mdct_scaling_gain_fx( len_by_2 ); // Q46 ivas_get_twid_factors_fx1( length, &pTwid_re, &pTwid_im ); FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_sub( pIn[add( len_by_2, i )], pIn[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_sub( pIn[len_by_2 + i], pIn[len_by_2 - i - 1] ); // q_out move32(); - pOut[add( len_by_2, i )] = L_add( pIn[sub( sub( imult1616( length, 2 ), i ), 1 )], pIn[add( length, i )] ); + pOut[len_by_2 + i] = L_add( pIn[length * 2 - i - 1], pIn[length + i] ); // q_out move32(); } 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[sub( sub( length, 1 ), imult1616( 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] ) ) ); // q_out move32(); - im[i] = L_sub( Mpy_32_16_1( pOut[sub( sub( length, 1 ), imult1616( 2, i ) )], pTwid_re[i] ), Mpy_32_16_1( pOut[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] ) ); // q_out move32(); } @@ -176,9 +176,9 @@ void ivas_mdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); + re[i] = Mult_32_32( re[i], ivas_mdct_scaling_gain ); // q_out+15 move32(); - im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); + im[i] = Mult_32_32( im[i], ivas_mdct_scaling_gain ); // q_out +15 move32(); } *q_out = add( *q_out, Q15 ); @@ -186,18 +186,18 @@ void ivas_mdct_fx( 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] ) ); // q_out + im[i] = L_add( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // q_out move32(); - re[i] = tmp; + re[i] = tmp; // q_out move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[sub( sub( length, imult1616( 2, i ) ), 1 )] = re[i]; + pOut[length - 2 * i - 1] = re[i]; // q_out move32(); - pOut[2 * i] = im[i]; + pOut[2 * i] = im[i]; // q_out move32(); } @@ -212,33 +212,33 @@ void ivas_mdct_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx( - Word32 *re, - Word32 *im, - const Word16 length ) + Word32 *re, /*Q24*/ + Word32 *im, /*Q24*/ + const Word16 length /*Q0*/ ) { Word16 i; Word32 ivas_imdct_one_by_powergain; - ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; + ivas_imdct_one_by_powergain = IVAS_ONE_BY_IMDCT_SCALING_GAIN_Q16; // Q16 move32(); /*re-arrange inputs to use fft as ifft */ - re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); + re[0] = Mult_32_32( re[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); + im[0] = Mult_32_32( im[0], ivas_imdct_one_by_powergain ); // Q9 move32(); - FOR( i = 1; i <= shr( length, 1 ); i++ ) + FOR( i = 1; i <= ( length / 2 ); i++ ) { Word32 tmp; - tmp = Mult_32_32( re[sub( length, i )], ivas_imdct_one_by_powergain ); - re[sub( length, i )] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( re[length - i], ivas_imdct_one_by_powergain ); // Q9 + re[length - i] = Mult_32_32( re[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; //-Q6 move32(); - tmp = Mult_32_32( im[sub( length, i )], ivas_imdct_one_by_powergain ); - im[sub( length, i )] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); + tmp = Mult_32_32( im[length - i], ivas_imdct_one_by_powergain ); // Q9 + im[length - i] = Mult_32_32( im[i], ivas_imdct_one_by_powergain ); // Q9 move32(); - im[i] = tmp; + im[i] = tmp; // Q9 move32(); } @@ -255,9 +255,9 @@ static void ivas_ifft_cplx( *-----------------------------------------------------------------------------------------*/ void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ) { Word16 i; @@ -266,13 +266,13 @@ void ivas_itda_fx( FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); /*Q24 */ move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[add( len_by_2, i )] = re[i]; /*Q24 */ move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[add( length, i )] = re[len_by_2 + i]; /*Q24 */ move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; /*Q24 */ move32(); } @@ -287,9 +287,9 @@ void ivas_itda_fx( *-----------------------------------------------------------------------------------------*/ void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ) { const Word16 *pTwid_re, *pTwid_im; @@ -303,9 +303,9 @@ void ivas_imdct_fx( FOR( i = 0; i < len_by_2; i++ ) { - re[i] = L_add( Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 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 Q24*/ move32(); - im[i] = L_sub( Mpy_32_16_1( pIn[2 * i], pTwid_re[i] ), Mpy_32_16_1( pIn[sub( sub( length, shl( i, 1 ) ), 1 )], 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 Q24*/ move32(); } @@ -319,30 +319,30 @@ void ivas_imdct_fx( 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] ) ); // Q9 + im[i] = L_sub( Mpy_32_16_1( im[i], pTwid_re[i] ), Mpy_32_16_1( re[i], pTwid_im[i] ) ); // Q9 move32(); - re[i] = tmp; + re[i] = tmp; // Q9 move32(); } FOR( i = ( len_by_2 - 1 ); i >= 0; i-- ) { - re[add( shl( i, 1 ), 1 )] = im[sub( sub( len_by_2, 1 ), i )]; + re[2 * i + 1] = im[( len_by_2 - 1 ) - i]; // Q9 move32(); - re[2 * i] = L_negate( re[i] ); + re[2 * i] = L_negate( re[i] ); // Q9 move32(); } FOR( i = 0; i < len_by_2; i++ ) { - pOut[i] = L_negate( re[sub( sub( len_by_2, i ), 1 )] ); + pOut[i] = L_negate( re[len_by_2 - i - 1] ); // Q9 move32(); - pOut[add( len_by_2, i )] = re[i]; + pOut[len_by_2 + i] = re[i]; // Q9 move32(); - pOut[add( length, i )] = re[add( len_by_2, i )]; + pOut[length + i] = re[len_by_2 + i]; // Q9 move32(); - pOut[add( imult1616( 3, len_by_2 ), i )] = re[sub( sub( length, i ), 1 )]; + pOut[3 * len_by_2 + i] = re[length - i - 1]; // Q9 move32(); } @@ -356,29 +356,29 @@ void ivas_imdct_fx( * Sets/Maps the fft twiddle tables based on fft length *-----------------------------------------------------------------------------------------*/ void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, - const Word16 **pTwid_im ) + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 + const Word16 **pTwid_im ) // Q15 { 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]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_480_fx[0]; // Q15 } 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]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_320_fx[0]; // Q15 } 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]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_160_fx[0]; // Q15 } 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]; // Q15 + *pTwid_im = (const Word16 *) &ivas_sin_twiddle_80_fx[0]; // Q15 } ELSE { @@ -405,19 +405,19 @@ Word32 ivas_get_mdct_scaling_gain_fx( { case L_FRAME48k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_48k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME32k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_32k_Q46; /*Q46*/ move32(); BREAK; } case L_FRAME16k >> 2: { - gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; + gain = IVAS_MDCT_SCALING_GAIN_16k_Q46; /*Q46*/ move32(); BREAK; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5e1214c42..a2aada6a9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4610,6 +4610,13 @@ Word16 quantize_phi_fx( Word32 *phi_hat, /* o : quantized azimuth */ const Word16 n /* i : azimuth codebook size */ ); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); #endif /*! r: decoded elevation value */ float deindex_elevation( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 121570bc3..a9ca1f48d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3516,4 +3516,12 @@ void ivas_omasa_enc_close_fx( ivas_error ivas_omasa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bcec831e..3bb90ec8d 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,13 +177,20 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { +#ifndef IVAS_FLOAT_FIXED 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 ); -#endif set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef IVAS_FLOAT_FIXED +#ifdef MSAN_FIX + set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif +#else + 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].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef MSAN_FIX + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif #endif set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index ab10cd57c..db931df0f 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -495,6 +495,84 @@ ELSE move32(); id_phi = add( id_phi, shr( n, 1 ) ); +return id_phi; +} + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value, Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth, Q22 */ + const Word16 n /* i : azimuth codebook size */ +) +{ + Word16 id_phi; + Word32 dd_fx; + Word32 delta_phi_fx; + Word32 inv_delta_phi_fx; + Word32 temp_res; + Word16 temp_e; + + delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( 360, n, &temp_e ); + delta_phi_fx = L_shl( delta_phi_fx, sub( temp_e, 9 ) ); + inv_delta_phi_fx = BASOP_Util_Divide3232_Scale_cadence( n, 360, &temp_e ); + + IF( EQ_16( n, 1 ) ) + { + *phi_hat = 0; + move32(); + + return 0; + } + + test(); + IF( EQ_16( flag_delta, 1 ) && GT_16( n, 2 ) ) + { + dd_fx = dd_val[n]; + move32(); + } + ELSE + { + dd_fx = 0; + move32(); + } + + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); + temp_res = L_shl( temp_res, temp_e ); + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + + assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); + + + IF( add( id_phi, shr( n, 1 ) ) < 0 ) + { + id_phi = add( id_phi, 1 ); + } + + IF( sub( id_phi, shr( n, 1 ) ) >= 0 ) + { + id_phi = negate( shr( n, 1 ) ); + } + + IF( EQ_16( id_phi, negate( add( shr( n, 1 ), ( n % 2 ) ) ) ) ) + { + id_phi = add( id_phi, ( 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 ); +} +} +} + +*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +move32(); +id_phi = add( id_phi, shr( n, 1 ) ); + return id_phi; } #endif diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 200c376cb..269c62d28 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -1634,76 +1634,46 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 -const Word32 delta_phi_val[257] = { - 0, - 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, - 167772160, 150994944, 137268128, 125829120, 116149960, 107853528, 100663296, 94371840, - 88820552, 83886080, 79471024, 75497472, 71902352, 68634064, 65649976, 62914560, - 60397976, 58074980, 55924052, 53926764, 52067224, 50331648, 48708048, 47185920, - 45756044, 44410276, 43141412, 41943040, 40809444, 39735512, 38716652, 37748736, - 36828036, 35951176, 35115104, 34317032, 33554432, 32824988, 32126584, 31457280, - 30815294, 30198988, 29606852, 29037490, 28489612, 27962026, 27453626, 26963382, - 26490342, 26033612, 25592364, 25165824, 24753270, 24354024, 23967452, 23592960, - 23229992, 22878022, 22536558, 22205138, 21883326, 21570706, 21266894, 20971520, - 20684238, 20404722, 20132660, 19867756, 19609732, 19358326, 19113284, 18874368, - 18641352, 18414018, 18192162, 17975588, 17764112, 17557552, 17355740, 17158516, - 16965724, 16777216, 16592851, 16412494, 16236015, 16063292, 15894205, 15728640, - 15566489, 15407647, 15252015, 15099494, 14949994, 14803426, 14659703, 14518745, - 14380471, 14244806, 14111677, 13981013, 13852747, 13726813, 13603148, 13481691, - 13362384, 13245171, 13129995, 13016806, 12905551, 12796182, 12688651, 12582912, - 12478921, 12376635, 12276012, 12177012, 12079596, 11983726, 11889366, 11796480, - 11705034, 11614996, 11526332, 11439011, 11353003, 11268279, 11184811, 11102569, - 11021529, 10941663, 10862946, 10785353, 10708861, 10633447, 10559087, 10485760, - 10413444, 10342119, 10271765, 10202361, 10133889, 10066330, 9999665, 9933878, - 9868951, 9804866, 9741609, 9679163, 9617512, 9556642, 9496537, 9437184, - 9378568, 9320676, 9263493, 9207009, 9151209, 9096081, 9041613, 8987794, - 8934612, 8882056, 8830114, 8778776, 8728031, 8677870, 8628283, 8579258, - 8530788, 8482862, 8435472, 8388608, 8342262, 8296425, 8251090, 8206247, - 8161889, 8118007, 8074596, 8031646, 7989150, 7947102, 7905494, 7864320, - 7823572, 7783244, 7743330, 7703823, 7664718, 7626007, 7587685, 7549747, - 7512186, 7474997, 7438174, 7401713, 7365607, 7329851, 7294441, 7259372, - 7224638, 7190235, 7156158, 7122403, 7088964, 7055838, 7023020, 6990506, - 6958292, 6926373, 6894746, 6863406, 6832350, 6801574, 6771073, 6740845, - 6710886, 6681192, 6651759, 6622585, 6593665, 6564997, 6536577, 6508403, - 6480469, 6452775, 6425317, 6398091, 6371094, 6344325, 6317780, 6291456, - 6265350, 6239460, 6213783, 6188317, 6163059, 6138006, 6113155, 6088506, - 6064054, 6039798, 6015735, 5991863, 5968179, 5944683, 5921370, 5898240 +const Word32 delta_phi_val[90] = { + 0, 1509949440, 754974720, 503316480, 377487360, 301989888, + 251658240, 215707056, 188743680, 167772160, 150994944, + 137268128, 125829120, 116149960, 107853528, 100663296, + 94371840, 88820552, 83886080, 79471024, 75497472, + 71902352, 68634064, 65649976, 62914560, 60397976, + 58074980, 55924052, 53926764, 52067224, 50331648, + 48708048, 47185920, 45756044, 44410276, 43141412, + 41943040, 40809444, 39735512, 38716652, 37748736, + 36828036, 35951176, 35115104, 34317032, 33554432, + 32824988, 32126584, 31457280, 30815294, 30198988, + 29606852, 29037490, 28489612, 27962026, 27453626, + 26963382, 26490342, 26033612, 25592364, 25165824, + 24753270, 24354024, 23967452, 23592960, 23229992, + 22878022, 22536558, 22205138, 21883326, 21570706, + 21266894, 20971520, 20684238, 20404722, 20132660, + 19867756, 19609732, 19358326, 19113284, 18874368, + 18641352, 18414018, 18192162, 17975588, 17764112, + 17557552, 17355740, 17158516, 16965724 }; -const Word32 inv_delta_phi_val[257] = { - 0, - 5965232, 11930465, 17895698, 23860930, 29826162, 35791396, 41756628, 47721860, - 53687092, 59652324, 65617556, 71582792, 77548024, 83513256, 89478488, 95443720, - 101408952, 107374184, 113339416, 119304648, 125269880, 131235112, 137200352, 143165584, - 149130816, 155096048, 161061280, 167026512, 172991744, 178956976, 184922208, 190887440, - 196852672, 202817904, 208783136, 214748368, 220713600, 226678832, 232644064, 238609296, - 244574528, 250539760, 256504992, 262470224, 268435456, 274400704, 280365920, 286331168, - 292296384, 298261632, 304226848, 310192096, 316157312, 322122560, 328087776, 334053024, - 340018240, 345983488, 351948704, 357913952, 363879168, 369844416, 375809632, 381774880, - 387740096, 393705344, 399670560, 405635808, 411601024, 417566272, 423531488, 429496736, - 435461952, 441427200, 447392416, 453357664, 459322880, 465288128, 471253344, 477218592, - 483183808, 489149056, 495114272, 501079520, 507044736, 513009984, 518975200, 524940448, - 530905664, 536870912, 542836160, 548801408, 554766592, 560731840, 566697088, 572662336, - 578627520, 584592768, 590558016, 596523264, 602488448, 608453696, 614418944, 620384192, - 626349376, 632314624, 638279872, 644245120, 650210304, 656175552, 662140800, 668106048, - 674071232, 680036480, 686001728, 691966976, 697932160, 703897408, 709862656, 715827904, - 721793088, 727758336, 733723584, 739688832, 745654016, 751619264, 757584512, 763549760, - 769514944, 775480192, 781445440, 787410688, 793375872, 799341120, 805306368, 811271616, - 817236864, 823202048, 829167296, 835132544, 841097792, 847062976, 853028224, 858993472, - 864958720, 870923904, 876889152, 882854400, 888819648, 894784832, 900750080, 906715328, - 912680576, 918645760, 924611008, 930576256, 936541504, 942506688, 948471936, 954437184, - 960402432, 966367616, 972332864, 978298112, 984263360, 990228544, 996193792, 1002159040, - 1008124288, 1014089472, 1020054720, 1026019968, 1031985216, 1037950400, 1043915648, 1049880896, - 1055846144, 1061811328, 1067776576, 1073741824, 1079707008, 1085672320, 1091637504, 1097602816, - 1103568000, 1109533184, 1115498496, 1121463680, 1127428864, 1133394176, 1139359360, 1145324672, - 1151289856, 1157255040, 1163220352, 1169185536, 1175150720, 1181116032, 1187081216, 1193046528, - 1199011712, 1204976896, 1210942208, 1216907392, 1222872576, 1228837888, 1234803072, 1240768384, - 1246733568, 1252698752, 1258664064, 1264629248, 1270594432, 1276559744, 1282524928, 1288490240, - 1294455424, 1300420608, 1306385920, 1312351104, 1318316288, 1324281600, 1330246784, 1336212096, - 1342177280, 1348142464, 1354107776, 1360072960, 1366038272, 1372003456, 1377968640, 1383933952, - 1389899136, 1395864320, 1401829632, 1407794816, 1413760128, 1419725312, 1425690496, 1431655808, - 1437620992, 1443586176, 1449551488, 1455516672, 1461481984, 1467447168, 1473412352, 1479377664, - 1485342848, 1491308032, 1497273344, 1503238528, 1509203840, 1515169024, 1521134208, 1527099520 +const Word32 inv_delta_phi_val[90] = { + 0, 5965232, 11930464, 17895697, 23860929, 29826161, + 35791394, 41756626, 47721858, 53687091, 59652323, + 65617555, 71582788, 77548020, 83513252, 89478485, + 95443717, 101408950, 107374182, 113339414, 119304647, + 125269879, 131235111, 137200344, 143165576, 149130808, + 155096041, 161061273, 167026505, 172991738, 178956970, + 184922203, 190887435, 196852667, 202817900, 208783132, + 214748364, 220713597, 226678829, 232644061, 238609294, + 244574526, 250539758, 256504991, 262470223, 268435456, + 274400688, 280365920, 286331153, 292296385, 298261617, + 304226850, 310192082, 316157314, 322122547, 328087779, + 334053011, 340018244, 345983476, 351948708, 357913941, + 363879173, 369844406, 375809638, 381774870, 387740103, + 393705335, 399670567, 405635800, 411601032, 417566264, + 423531497, 429496729, 435461961, 441427194, 447392426, + 453357659, 459322891, 465288123, 471253356, 477218588, + 483183820, 489149053, 495114285, 501079517, 507044750, + 513009982, 518975214, 524940447, 530905679 }; const Word32 dd_val[90] = { diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 6d4f50fa8..4cf61f9ae 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -188,8 +188,8 @@ extern const Word16 ls_elevation_CICP19_idx[11]; extern const Word32 shoebox_sin_cos_tbl_fx[11][2]; -extern const Word32 delta_phi_val[257]; -extern const Word32 inv_delta_phi_val[257]; +extern const Word32 delta_phi_val[90]; +extern const Word32 inv_delta_phi_val[90]; extern const Word32 dd_val[90]; extern const Word32 cb_azi_chan_fx[]; // Q22 extern const Word16 cb_azi_chan_16fx[]; // Q0 diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 1cea89b76..9d21cfbb4 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1341,24 +1341,23 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp64 = W_shl( tmp64, tmp_shift ); } - L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); - val_e = sub( 31, sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ) ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, shl( dm_beta_re_q, 1 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), sub( 31, sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( sub( 31, dm_beta_re_q ), 4 ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); @@ -1366,7 +1365,7 @@ static void ivas_get_pred_coeffs_enc_fx( move16(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); move32(); - DM_F_q[b] = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); + DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); } } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index a4d1065f4..4fde550bd 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -537,11 +537,12 @@ typedef struct typedef struct ivas_qdirection_band_data_struct { uint16_t spherical_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -557,11 +558,12 @@ typedef struct ivas_qdirection_band_data_struct uint16_t energy_ratio_index_mod[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t azimuth_index[MAX_PARAM_SPATIAL_SUBFRAMES]; uint16_t elevation_index[MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifndef IVAS_FLOAT_FIXED float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; -#ifdef IVAS_FLOAT_FIXED - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ +#else + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 9c490a012..3cf2b645d 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -1709,8 +1709,8 @@ void decimate_2_over_3_allpass_fx( Word16 out, tmp; Word16 mem_fx_11, mem_fx_7, mem_fx_3; Word16 sc, input_fx[960]; - sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 6 ), 2 ) ); - Scale_sig( lp_mem_fx, 6, sc ); + sc = s_min( s_min( sub( Find_Max_Norm16( input, len ), 2 ), sub( Find_Max_Norm16( mem_fx, 12 ), 2 ) ), sub( Find_Max_Norm16( lp_mem_fx, 3 ), 2 ) ); + Scale_sig( lp_mem_fx, 3, sc ); Copy_Scale_sig( input, input_fx, len, sc ); Scale_sig( mem_fx, 12, sc ); out1 = out1_buff; @@ -1843,7 +1843,7 @@ void decimate_2_over_3_allpass_fx( 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( lp_mem_fx, 3, negate( sc ) ); return; } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index da45e5743..70d2f94b0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5860,17 +5860,17 @@ void td_bwe_dec_init_fx( // 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 Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ); @@ -5998,26 +5998,26 @@ Word32 dotp_me_fx( #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, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #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 endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ); // cng_dec_fx.c @@ -7299,14 +7299,13 @@ void pvq_decode_fx( #ifdef IVAS_FLOAT_FIXED // 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 */ + Decoder_State *st_fx, /* i/o: decoder static memory */ + Word16 *exc_nelp, /* o : adapt. excitation/total exc Q0 */ + Word16 *exc, /* o : adapt. excitation exc Q_exc */ Word16 *Q_exc, - Word16 bfi, /* i : frame error rate */ - const Word16 coder_type /* i : coding type */ - , - Word16 *gain_buf /*Q14*/ + Word16 bfi, /* i : frame error rate Q0 */ + const Word16 coder_type, /* i : coding type Q0 */ + Word16 *gain_buf /* Q14 */ ); #endif @@ -8623,27 +8622,30 @@ void tcx_hm_decode( ); // lsf_msvq_ma_dec_fx.c -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ); +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +); Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc + Word16 *param_lpc /* Q0 */ ); 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 */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ); 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 */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ); // lsf_msvq_ma_fx.c diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f72017940..fdac07f56 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1739,7 +1739,7 @@ Word32 encode_position_ari_fx( /* Estimate TCQ bits */ bits_fx = L_sub( table_logcum_fx[size + 1], L_add( table_logcum_fx[nz + 1], table_logcum_fx[add( sub( 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[add( sub( size, nz ), 1 )] ) ) ) ); - bits_fx = L_sub( bits_fx, L_sub( table_logcum_fx[pulses], L_add( table_logcum_fx[nz], table_logcum_fx[add( pulses, sub( 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 ); move32(); diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 887f37d5c..c51a2fde5 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -36,7 +36,7 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); *exp = 0; move16(); @@ -51,16 +51,16 @@ static Word16 Calc_inv( Word32 L_tmp, Word16 *exp ) *--------------------------------------------------------------------------*/ 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 */ + Decoder_State *st_fx, /* i: encoder state structure */ + const Word16 p2a_flags[], /* i: p2a anlysis information Q0*/ + const Word16 new_band_start[], /* i: new band start position Q0*/ + const Word16 new_band_end[], /* i: new band end position Q0*/ + const Word16 new_band_width[], /* i: new subband band width Q0*/ + const Word16 bands, /* i: total number of subbands Q0*/ + Word16 band_start[], /* o: band start position Q0*/ + Word16 band_end[], /* o: band end position Q0*/ + Word16 band_width[], /* o: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 j, k; @@ -68,27 +68,28 @@ static void spt_shorten_domain_set_dec_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { spt_shorten_flag[j] = 0; move16(); IF( EQ_16( p2a_flags[k], 1 ) ) { - spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); - *bit_budget = sub( *bit_budget, 1 ); + spt_shorten_flag[j] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ + move16(); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ move16(); IF( EQ_16( spt_shorten_flag[j], 1 ) ) { - band_start[k] = new_band_start[j]; + band_start[k] = new_band_start[j]; /* Q0 */ move16(); - band_end[k] = new_band_end[j]; + band_end[k] = new_band_end[j]; /* Q0 */ move16(); - band_width[k] = new_band_width[j]; + band_width[k] = new_band_width[j]; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; @@ -131,12 +132,12 @@ void hq_lr_dec_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 */; Word32 L_Rk[BANDS_MAX]; Word16 bit_budget_fx; @@ -203,32 +204,32 @@ void hq_lr_dec_fx( test(); 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_fx( st_fx, 2 ); - num_bits = sub( num_bits, 2 ); + hqswb_clas_fx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ + num_bits = sub( num_bits, 2 ); /* Q0 */ *is_transient_fx = 0; move16(); if ( EQ_16( hqswb_clas_fx, HQ_TRANSIENT ) ) { - *is_transient_fx = 1; + *is_transient_fx = 1; /* Q0 */ move16(); } } ELSE { /* decode transient flag */ - *is_transient_fx = get_next_indice_fx( st_fx, 1 ); + *is_transient_fx = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - num_bits = sub( num_bits, 1 ); + num_bits = sub( num_bits, 1 ); /* Q0 */ } /* 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 ); - highlength_fx = band_end[bands_fx - 1]; + highlength_fx = band_end[bands_fx - 1]; /* Q0 */ move16(); - har_bands_fx = bands_fx; + har_bands_fx = bands_fx; /* Q0 */ move16(); test(); @@ -240,11 +241,11 @@ void hq_lr_dec_fx( test(); 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 ) ); /* Q0 */ } if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { - flag_spt_fx = 1; + flag_spt_fx = 1; /* Q0 */ move16(); } } @@ -257,26 +258,26 @@ void hq_lr_dec_fx( { j = 0; move16(); - FOR( k = sub( bands_fx, SPT_SHORTEN_SBNUM ); k < bands_fx; k++ ) + FOR( k = bands_fx - SPT_SHORTEN_SBNUM; k < bands_fx; k++ ) { hHQ_core->prev_SWB_peak_pos_fx[j] = 0; move16(); - j = add( j, 1 ); + j++; } } } /* Spectral energy calculation/quantization */ - ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); + ebits_fx = band_energy_dequant_fx( st_fx, L_band_energy, bands_fx, L_qint, eref_fx, *is_transient_fx ); /* Q0 */ /* simple check: band_energy is too large, Abnormal Situation of bit errors */ FOR( k = 0; k < bands_fx; k++ ) { /* Max: 45.0(737279,Q14) at 32kHz, highest band, Min: -6.600037(-108135,Q14) at 8kHz(NB),8kbps, is_transient (-6.7f(-109772,Q14) is safty-threshold) */ test(); - IF( GT_32( L_band_energy[k], 737279L ) || LT_32( L_band_energy[k], -109772L ) ) + IF( GT_32( L_band_energy[k], 737279L /* 45.0 in Q14 */ ) || LT_32( L_band_energy[k], -109772L /* -6.7 in Q14 */ ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0L, inner_frame ); return; @@ -285,9 +286,9 @@ 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 ); + gqbits_fx = sub( 14, exp_norm ); /* Q0 */ - 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; Q0*/ pbits_fx = 0; @@ -302,8 +303,8 @@ 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 ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { @@ -313,8 +314,8 @@ 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 ); + pbits_fx = p2a_threshold_dequant_fx( st_fx, p2a_flags_fx, bands_fx, p2a_bands_fx ); /* Q0 */ + bit_budget_fx = sub( bit_budget_fx, pbits_fx ); /* Q0 */ } IF( EQ_16( flag_spt_fx, 1 ) ) @@ -328,7 +329,7 @@ void hq_lr_dec_fx( /* safety check in case of bit errors */ IF( LT_16( bit_budget_fx, 2 ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); set32_fx( L_yout, 0x0, inner_frame ); return; @@ -347,13 +348,13 @@ void hq_lr_dec_fx( Ep_fx[i] = L_shl_sat( L_tmp, s_max( sub( exp, 6 ), -31 ) ); /* Q -6 */ move32(); #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_tmp2 = Ep_fx[i]; /* Q -6 */ move32(); L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); @@ -375,7 +376,7 @@ void hq_lr_dec_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ 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 */ @@ -395,20 +396,20 @@ void hq_lr_dec_fx( move16(); FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } - lowband = 6; + lowband = 6; /* Q0 */ move16(); - trans_bit_fx = 2; + trans_bit_fx = 2; /* Q0 */ move16(); - bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); + bit_budget_fx = sub( bit_budget_fx, trans_bit_fx ); /* Q0 */ 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[bands_fx - trans_bit_fx], 0, 2 ); IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { @@ -416,7 +417,7 @@ void hq_lr_dec_fx( 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 ); + Copy( &p2a_flags_fx[bands_fx - trans_bit_fx], &p2a_flags_tmp[bands_fx - trans_bit_fx], trans_bit_fx ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ @@ -429,11 +430,11 @@ void hq_lr_dec_fx( 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_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[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[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } ELSE @@ -441,7 +442,7 @@ 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 ) ) { @@ -479,7 +480,7 @@ void hq_lr_dec_fx( } ELSE { - FOR( i = sub( bands_fx, trans_bit_fx ); i < bands_fx; i++ ) + FOR( i = bands_fx - trans_bit_fx; i < bands_fx; i++ ) { alpha_fx = 16384; move16(); /*Q14 */ @@ -554,7 +555,7 @@ void hq_lr_dec_fx( move32(); } } - lowband = 3; + lowband = 3; /* Q0 */ move16(); Ep_avrg_fx = L_deposit_l( 0 ); Ep_avrgL_fx = L_deposit_l( 0 ); @@ -605,17 +606,17 @@ void hq_lr_dec_fx( } 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 Q0*/ FOR( i = 0; i < 2; i++ ) { - last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); + last_bitalloc_max_band[i] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); } 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 ); /* Q15 */ #else Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif @@ -623,21 +624,21 @@ void hq_lr_dec_fx( } IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 15; + highband = 15; /* Q0 */ 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] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } ELSE { - lowband = 8; + lowband = 8; /* Q0 */ move16(); - highband = 16; + highband = 16; /* Q0 */ 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] ); /* Q0 */ + bw_high = sub( add( band_end[bands_fx - 1], 1 ), band_start[highband] ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ enerL_fx = L_deposit_l( 0 ); @@ -650,11 +651,11 @@ void hq_lr_dec_fx( 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[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[i - 1] ) ) ); /*Q15 */ + Ep_avrg_fx = L_add( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif } @@ -663,7 +664,7 @@ void hq_lr_dec_fx( #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 ) ) @@ -671,7 +672,7 @@ void hq_lr_dec_fx( #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 } } @@ -685,7 +686,7 @@ void hq_lr_dec_fx( 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++ ) + FOR( i = bands_fx - p2a_bands_fx; i < bands_fx; i++ ) { test(); IF( EQ_16( p2a_flags_fx[i], 1 ) || L_tmp2 > 0 ) @@ -696,7 +697,7 @@ void hq_lr_dec_fx( #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 ) { @@ -734,7 +735,7 @@ void hq_lr_dec_fx( 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 ) ) + IF( EQ_16( last_bitalloc_max_band[i - ( tmp + 1 )], 1 ) ) { tmp = sub( tmp, lowband ); L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ @@ -887,11 +888,11 @@ void hq_lr_dec_fx( 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 ); + Copy32( L_y2, L_y2_org, L_FRAME32k ); /* Q12 */ /* 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 ); + Copy32( L_y2, L_y2_ni, band_end[bands_fx - 1] + 1 ); /* Q12 */ 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, @@ -924,16 +925,16 @@ void hq_lr_dec_fx( } } } - Copy32( L_y2_ni, L_y2, lowlength_fx ); + Copy32( L_y2_ni, L_y2, lowlength_fx ); /* Q12 */ } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB */ + Copy32( L_y2_ni, L_y2, add( band_end[bands_fx - 1], 1 ) ); /* NB, WB Q12*/ } test(); @@ -942,7 +943,7 @@ void hq_lr_dec_fx( 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 ); /* Q1 */ } L_tmp = L_deposit_l( 0 ); FOR( i = k1_fx; i < bands_fx; i++ ) @@ -950,7 +951,7 @@ void hq_lr_dec_fx( 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 ) ); /* Q1 */ move16(); } test(); @@ -972,26 +973,26 @@ 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 Q0*/ + Word16 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { 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 ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* converting to original values */ FOR( i = 0; i < bands; i++ ) { - qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); + qbidx[i] = sub( difidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -1005,41 +1006,41 @@ static Word16 small_symbol_dec_tran_fx( * Huffman decoding of differential energies (MSB and LSB) *--------------------------------------------------------------------------*/ -static Word16 small_symbol_dec_fx( /* o : bits */ +static Word16 small_symbol_dec_fx( /* o : bits Q0*/ 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 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands, /* i : number of bands Q0*/ const Word16 is_transient ) { Word16 i, LSB, bits; Word16 difidx[BANDS_MAX]; /* Decoding MSB bits */ - bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); + bits = decode_envelope_indices_fx( st_fx, 0, bands, 0, difidx, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* Q0 */ /* counting 1 bit for band_energy_huff_coding_mode */ - bits = add( bits, BITS_DE_HMODE ); + bits = add( bits, BITS_DE_HMODE ); /* Q0 */ /* Decoding LSB bit packing */ FOR( i = 0; i < bands; ++i ) { - LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); - difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); + LSB = get_next_indice_fx( st_fx, BITS_DE_LSB ); /* Q0 */ + difidx[i] = s_or( shl( difidx[i], 1 ), LSB ); /* Q0 */ move16(); } /* counting bits for LSB */ - bits = add( bits, bands ); + bits = add( bits, bands ); /* Q0 */ /* converting to original values */ FOR( i = 1; i < bands; ++i ) { - qbidx[i] = sub( difidx[i], DE_OFFSET1 ); + qbidx[i] = sub( difidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } - qbidx[0] = sub( difidx[0], DE_OFFSET0 ); + qbidx[0] = sub( difidx[0], DE_OFFSET0 ); /* Q0 */ move16(); return ( bits ); @@ -1048,18 +1049,19 @@ static Word16 small_symbol_dec_fx( /* o : bits static Word16 decode_huff_8s_fx( Decoder_State *st_fx, - const Word16 *hufftab, - Word16 *rbits ) + const Word16 *hufftab, /* Q0 */ + Word16 *rbits /* Q0 */ +) { Word16 bit; WHILE( *hufftab > 0 ) { - *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); + *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); + bit = get_next_indice_fx( st_fx, s_and( *hufftab, 0xf ) ); /* Q0 */ move16(); - hufftab += add( shr( *hufftab, 4 ), bit ); + hufftab += add( shr( *hufftab, 4 ), bit ); /* Q0 */ } return negate( *hufftab ); @@ -1067,8 +1069,8 @@ static Word16 decode_huff_8s_fx( 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 *qbidx, /* o : output of dequantized differential energy Q0*/ + const Word16 bands /* i : number of bands Q0*/ ) { Word16 i, bits; @@ -1077,29 +1079,29 @@ static Word16 large_symbol_dec_fx( /* o : bits Word16 pos_outlyer; Word16 ns2mode0, ns2mode1; - cntbits = BITS_DE_8SMODE; + cntbits = BITS_DE_8SMODE; /* Q0 */ move16(); - ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); + ns2mode = get_next_indice_fx( st_fx, BITS_DE_8SMODE ); /* Q0 */ IF( ns2mode == 0 ) { - ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); - ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); - cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); + ns2mode0 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N0 ); /* Q0 */ + ns2mode1 = get_next_indice_fx( st_fx, BITS_DE_8SMODE_N1 ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); /* Q0 */ IF( ns2mode0 == 0 ) { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { - pos_outlyer = -1; + pos_outlyer = -1; /* Q0 */ move16(); } @@ -1107,84 +1109,84 @@ static Word16 large_symbol_dec_fx( /* o : bits { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < bands; ++i ) + FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } ELSE { IF( EQ_16( ns2mode1, 1 ) ) { - pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); - cntbits = add( cntbits, BITS_DE_8SPOS ); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + pos_outlyer = get_next_indice_fx( st_fx, BITS_DE_8SPOS ); /* Q0 */ + cntbits = add( cntbits, BITS_DE_8SPOS ); /* Q0 */ + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); - qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ + qbidx[pos_outlyer] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } ELSE { pos_outlyer = 0; move16(); - qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); + qbidx[0] = sub( get_next_indice_fx( st_fx, BITS_ABS_ENG ), ABS_ENG_OFFSET ); /* Q0 */ move16(); - cntbits = add( cntbits, BITS_ABS_ENG ); + cntbits = add( cntbits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } } } ELSE { - basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); - cntbits = add( cntbits, BITS_MAX_DEPTH ); + basic_shift = get_next_indice_fx( st_fx, BITS_MAX_DEPTH ); /* Q0 */ + cntbits = add( cntbits, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < bands; ++i ) { bits = 0; move16(); - qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); + qbidx[i] = sub( decode_huff_8s_fx( st_fx, hestable, &bits ), 4 ); /* Q0 */ move16(); - qbidx[i] = shl( qbidx[i], basic_shift ); + qbidx[i] = shl( qbidx[i], basic_shift ); /* Q0 */ move16(); - cntbits = add( cntbits, bits ); + cntbits = add( cntbits, bits ); /* Q0 */ } FOR( i = 0; i < bands; ++i ) { - LSB[0] = get_next_indice_fx( st_fx, basic_shift ); + LSB[0] = get_next_indice_fx( st_fx, basic_shift ); /* Q0 */ move16(); - qbidx[i] = add( qbidx[i], LSB[0] ); + qbidx[i] = add( qbidx[i], LSB[0] ); /* Q0 */ move16(); - cntbits = add( cntbits, basic_shift ); + cntbits = add( cntbits, basic_shift ); /* Q0 */ } } @@ -1199,12 +1201,13 @@ static Word16 large_symbol_dec_fx( /* o : bits *--------------------------------------------------------------------------*/ static Word16 band_energy_dequant_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word32 L_band_energy[], /* o : Q14 band energy */ - const Word16 bands_fx, - const Word32 L_qint, - const Word16 eref_fx, - const Word16 is_transient_fx ) + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word32 L_band_energy[], /* o : band energy Q14*/ + const Word16 bands_fx, /* Q0 */ + const Word32 L_qint, /* Q0 */ + const Word16 eref_fx, /* Q0 */ + const Word16 is_transient_fx /* Q0 */ +) { Word16 k; Word16 deng_cmode; @@ -1221,28 +1224,28 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ - deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); + deng_cmode = get_next_indice_fx( st_fx, BITS_DE_CMODE ); /* Q0 */ IF( deng_cmode == 0 ) { - deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); + deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); /* Q0 */ /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } ELSE { IF( is_transient_fx ) { - deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_tran_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } ELSE { - deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); + deng_bits = small_symbol_dec_fx( st_fx, bq2_fx, bands_fx, is_transient_fx ); /* Q0 */ } /* counting 1 bit for deng coding mode */ - deng_bits = add( deng_bits, BITS_DE_CMODE ); + deng_bits = add( deng_bits, BITS_DE_CMODE ); /* Q0 */ } exp_normd = norm_l( L_qint ); @@ -1281,10 +1284,10 @@ 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 */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *p2a_flags, /* o : tonaly indicator Q0*/ + const Word16 bands, /* i : number of subbands Q0*/ + const Word16 p2a_bands /* i : number of subbnads for computing tonality Q0*/ ) { Word16 j, k; @@ -1292,17 +1295,17 @@ static Word16 p2a_threshold_dequant_fx( j = sub( bands, p2a_bands ); FOR( k = 0; k < j; k++ ) { - p2a_flags[k] = 1; + p2a_flags[k] = 1; /* Q0 */ move16(); } j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = bands - p2a_bands; k < bands; k++ ) { - p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); + p2a_flags[k] = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); - j = add( j, 1 ); + j++; } return ( j ); @@ -1348,11 +1351,11 @@ static void mdct_spectrum_fine_gain_dec_fx( 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 ) ); + delta_fx = div_l( L_shl( L_qint, exp_normn ), shl( gqlevs, exp_normd ) ); /* Q15 */ + 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 ) ); /* Q18 - Qdelta */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q -1*/ FOR( i = 0; i < gqlevs; i++ ) { @@ -1369,9 +1372,9 @@ static void mdct_spectrum_fine_gain_dec_fx( move16(); } - FOR( k = sub( bands, Ngq ); k < bands; k++ ) + FOR( k = bands - Ngq; k < bands; k++ ) { - imin_fx = get_next_indice_fx( st_fx, gqbits ); + imin_fx = get_next_indice_fx( st_fx, gqbits ); /* Q0 */ /*gamma = gain_table[imin]; */ gamma_fx = gain_table_fx[imin_fx]; @@ -1382,12 +1385,12 @@ static void mdct_spectrum_fine_gain_dec_fx( /* This IF statement for keeping same mantissa evenif y2 is plus or minus */ 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 ); /* Q12 */ move32(); } 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 ) ); /* Q12 */ move32(); } } diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 5d7313b21..a81e22f25 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -29,32 +29,32 @@ 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 Q9*/ ) { Word16 indice[4]; Word16 ber_flag; - indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); + indice[0] = (Word16) get_next_indice_fx( st_fx, 4 ); /* Q0 */ move16(); - indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); + indice[1] = (Word16) get_next_indice_fx( st_fx, LEN_INDICE ); /* Q0 */ move16(); - indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); + indice[2] = (Word16) get_next_indice_fx( st_fx, LSF_BITS_CNG - 4 - LEN_INDICE ); /* Q0 */ move16(); /* deindex_lvq_cng decoder does not need to know the sampling rate, the sampling rate data is embedded inside the LSF coefficients */ IF( 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] ); /* Q0 */ } 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 ); /* Q0 */ } - st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); + st_fx->BER_detect = s_or( ber_flag, st_fx->BER_detect ); /* Q0 */ move16(); /* The sampling frequency of the LP-CNG frame can be determined by checking the value of the highest order LSF coefficient (last coefficient). @@ -67,7 +67,7 @@ static void dqlsf_CNG_fx( 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 ) ) ) ) { - st_fx->BER_detect = 1; + st_fx->BER_detect = 1; /* Q0 */ move16(); } @@ -102,17 +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 */ - 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 Q0*/ + Word16 *Aq, /* o : quantized A(z) for 4 subframes Q12*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *lsf_new, /* o : de-quantized LSF vector Q(x2.56)*/ + Word16 *lsp_new, /* o : de-quantized LSP vector Q15*/ + Word16 *lsp_mid, /* o : de-quantized mid-frame LSP vector Q15*/ + const Word16 tdm_low_rate_mode /* i : secondary channel low rate mode flag Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -132,13 +132,13 @@ void lsf_dec_fx( coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - coder_type = INACTIVE; + coder_type = INACTIVE; /* Q0 */ move16(); } test(); if ( EQ_16( coder_type, AUDIO ) && st_fx->GSC_IVAS_mode > 0 ) { - coder_type = GENERIC; + coder_type = GENERIC; /* Q0 */ move16(); } no_param_lpc = 0; @@ -149,7 +149,7 @@ void lsf_dec_fx( /* Find the number of bits for LSF quantization */ IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { - nBits = LSF_BITS_CNG; + nBits = LSF_BITS_CNG; /* Q0 */ move16(); } ELSE @@ -157,25 +157,25 @@ void lsf_dec_fx( test(); IF( st_fx->nelp_mode_dec == 0 && st_fx->ppp_mode_dec == 0 ) { - nBits = st_fx->acelp_cfg.lsf_bits; + nBits = st_fx->acelp_cfg.lsf_bits; /* Q0 */ move16(); } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { IF( EQ_16( coder_type, UNVOICED ) ) { - nBits = 30; + nBits = 30; /* Q0 */ move16(); if ( st_fx->bwidth == NB ) { - nBits = 32; + nBits = 32; /* Q0 */ move16(); } } } ELSE IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nBits = 26; + nBits = 26; /* Q0 */ move16(); } } @@ -197,10 +197,10 @@ void lsf_dec_fx( { st_fx->seed_acelp = 0; move16(); - FOR( i = sub( 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 = extract_l( L_add( imult3216( 31821L, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L ) ); + st_fx->seed_acelp = extract_l( L_add( imult3216( 31821L /* Q0 */, add( shr( ( st_fx->seed_acelp ), 1 ), param_lpc[i] ) ), 13849L /* Q0 */ ) ); /* Q0 */ move16(); // PMTE() /*IVAS_CODE to be completed */ } @@ -240,7 +240,7 @@ void lsf_dec_fx( FOR( i = 1; i < M; i++ ) { - st_fx->lsf_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 ); /* Q2.56 */ move16(); } lsf2lsp_fx( st_fx->lsf_old_fx, st_fx->lsp_old_fx, M, st_fx->sr_core ); @@ -252,8 +252,8 @@ void lsf_dec_fx( 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 ); /* Q15 */ + Copy( lsf_new, st_fx->lsf_old_fx, M ); /* Q2.56 */ } { /* Mid-frame LSF decoding */ @@ -267,10 +267,10 @@ void lsf_dec_fx( { /* 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 ); + enr_old = Enr_1_Az_fx( tmp_old, 2 * L_SUBFR ); /* Q3 */ E_LPC_f_lsp_a_conversion( lsp_new, tmp_new, M ); - enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); + enr_new = Enr_1_Az_fx( tmp_new, 2 * L_SUBFR ); /* Q3 */ IF( LT_16( enr_new, mult_r( 9830 /*0.3 Q15*/, enr_old ) ) ) { @@ -293,8 +293,8 @@ void lsf_dec_fx( IF( EQ_16( st_fx->last_core, HQ_CORE ) && 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 ); + Copy( lsp_mid, st_fx->lsp_old_fx, M ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ } test(); IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( coder_type, UNVOICED ) ) @@ -302,9 +302,9 @@ void lsf_dec_fx( // 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 ); /* Q15 */ + lsp2lsf_fx( lsp_mid, st_fx->lsf_old_fx, M, st_fx->sr_core ); /* Q15 */ + Copy( lsp_new, lsp_mid, M ); /* Q15 */ } /* LSP interpolation and conversion of LSPs to A(z) - two-subframe mode */ @@ -326,7 +326,7 @@ void lsf_dec_fx( } 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 ); /* Q15 */ move16(); } @@ -369,18 +369,18 @@ void lsf_dec_fx( /*========================================================================*/ 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 : 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 */ + Decoder_State *st, /* i/o: decoder state structure */ + Word16 mode2_flag, /* Q0 */ + const Word16 coder_type_org, /* i : coding type Q0*/ + const Word16 bwidth, /* i : input signal bandwidth Q0*/ + const Word16 nBits_in, /* i : number of bits used for ISF quantization Q0*/ + Word16 *qlsf, /* o : quantized LSFs in the cosine domain Qx2.56*/ + Word16 *lpc_param, /* i : LPC parameters Q0*/ + Word16 *LSF_Q_prediction, /* o : LSF prediction mode Q0*/ + Word16 *nb_indices /* o : number of indices Q0*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ + const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel Qx*/ #endif ) { @@ -409,9 +409,9 @@ void lsf_end_dec_fx( #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif - flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); + flag_1bit_gran = (Word16) ( st->element_mode > EVS_MONO ); /* Q0 */ - nBits = nBits_in; + nBits = nBits_in; /* Q0 */ *nb_indices = 0; move16(); move16(); @@ -427,18 +427,18 @@ void lsf_end_dec_fx( #endif { /* this bit is used only for primary channel or mono */ - coder_type = (Word16) get_next_indice_fx( st, 1 ); - coder_type = add( coder_type, 2 ); + coder_type = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ + coder_type = add( coder_type, 2 ); /* Q0 */ 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 ); /* Q0 */ } } ELSE { - coder_type = coder_type_org; + coder_type = coder_type_org; /* Q0 */ move16(); } @@ -475,16 +475,16 @@ void lsf_end_dec_fx( { /* if secondary channel predmode is set to be > 2 */ /*predmode += 3;*/ - predmode = add( predmode, 3 ); + predmode = add( predmode, 3 ); /* Q0 */ } #endif - p_lpc_param = lpc_param; + p_lpc_param = lpc_param; /* Q0 */ move16(); IF( predmode == 0 ) { - safety_net = 1; + safety_net = 1; /* Q0 */ move16(); } ELSE IF( predmode == 1 ) @@ -499,18 +499,18 @@ void lsf_end_dec_fx( 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]; + safety_net = p_lpc_param[0]; /* Q0 */ move16(); p_lpc_param++; - *nb_indices = add( *nb_indices, 1 ); + *nb_indices = add( *nb_indices, 1 ); /* Q0 */ } ELSE { - safety_net = (Word16) get_next_indice_fx( st, 1 ); + safety_net = (Word16) get_next_indice_fx( st, 1 ); /* Q0 */ } } - st->safety_net = safety_net; + st->safety_net = safety_net; /* Q0 */ move16(); /*--------------------------------------------------------------------------* @@ -523,9 +523,9 @@ void lsf_end_dec_fx( { /* use same AR prediction bit allocation for intra and inter modes*/ lsf_allocate_fx( sub( nBits, 1 ), mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); - stages0 = stages1; - Copy( levels1, levels0, stages0 ); - Copy( bits1, bits0, stages0 ); + stages0 = stages1; /* Q0 */ + Copy( levels1, levels0, stages0 ); /* Q0 */ + Copy( bits1, bits0, stages0 ); /* Q0 */ } #endif @@ -538,24 +538,24 @@ void lsf_end_dec_fx( 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; + *nb_indices = 10; /* Q0 */ move16(); - TCQIdx[0] = safety_net; + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 1; i < *nb_indices; i++ ) { - TCQIdx[i] = *p_lpc_param++; + TCQIdx[i] = *p_lpc_param++; /* Q0 */ move16(); } } ELSE { - Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; - TCQIdx[0] = safety_net; + Bit_alloc1 = &BC_TCVQ_BIT_ALLOC_40B[1]; /* Q0 */ + TCQIdx[0] = safety_net; /* Q0 */ move16(); FOR( i = 0; i < M / 2 + 3; i++ ) { - TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); + TCQIdx[i + 1] = get_next_indice_fx( st, Bit_alloc1[i] ); /* Q0 */ move16(); } } @@ -564,20 +564,20 @@ void lsf_end_dec_fx( { IF( safety_net ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - levels = levels0; + levels = levels0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - levels = levels1; + levels = levels1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } test(); @@ -586,19 +586,19 @@ void lsf_end_dec_fx( { FOR( i = 0; i < sub( stages, 1 ); i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); } - cumleft = levels[stages - 1]; + cumleft = levels[stages - 1]; /* Q0 */ move16(); WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ } ELSE { @@ -606,43 +606,43 @@ void lsf_end_dec_fx( move16(); } - lindice[i + 1] = *p_lpc_param++; + lindice[i + 1] = *p_lpc_param++; /* Q0 */ move16(); - i = add( i, 1 ); + i++; } - *nb_indices = add( *nb_indices, i ); + *nb_indices = add( *nb_indices, i ); /* Q0 */ move16(); } ELSE { FOR( i = 0; i < stages - 1; i++ ) { - num_bits = bits[i]; + num_bits = bits[i]; /* Q0 */ move16(); - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); } - cumleft = levels[sub( stages, 1 )]; + cumleft = levels[stages - 1]; /* Q0 */ WHILE( cumleft > 0 ) { IF( GT_16( cumleft, LEN_INDICE ) ) { - cumleft = sub( cumleft, LEN_INDICE ); - num_bits = LEN_INDICE; + cumleft = sub( cumleft, LEN_INDICE ); /* Q0 */ + num_bits = LEN_INDICE; /* Q0 */ move16(); } ELSE { - num_bits = (Word16) cumleft; + num_bits = (Word16) cumleft; /* Q0 */ move16(); cumleft = 0; move16(); } - lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); + lindice[i + 1] = (Word16) get_next_indice_fx( st, num_bits ); /* Q0 */ move16(); - i = add( i, 1 ); + i++; } } } @@ -650,7 +650,7 @@ void lsf_end_dec_fx( { FOR( i = 0; i < M; i++ ) { - st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; + st->mem_AR_fx[i] = ModeMeans_fx[mode_lvq][i]; /* Q2.56 */ move16(); } st->reset_mem_AR = 0; @@ -661,7 +661,7 @@ void lsf_end_dec_fx( * De-quantize LSF vector *------------------------------------------------------------------------------------------*/ - *LSF_Q_prediction = SAFETY_NET; + *LSF_Q_prediction = SAFETY_NET; /* Q0 */ move16(); /* VOICED_WB@16kHz */ test(); @@ -669,14 +669,14 @@ void lsf_end_dec_fx( 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, sub( nBits, 1 ) ); + safety_net = qlsf_ARSN_tcvq_Dec_16k_fx( qlsf, TCQIdx, sub( nBits, 1 ) ); /* Q0 */ /* Update mem_MA */ - Copy( qlsf, st->mem_MA_fx, M ); + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ IF( safety_net ) { - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ } ELSE { @@ -685,7 +685,7 @@ void lsf_end_dec_fx( 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)*/ move16(); } - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } Vr_add( qlsf, pred0, qlsf, M ); @@ -694,11 +694,11 @@ void lsf_end_dec_fx( { /* Safety-net */ - Copy( ModeMeans_fx[mode_lvq], pred0, M ); + Copy( ModeMeans_fx[mode_lvq], pred0, M ); /* Q2.56 */ /* for mem_MA update */ FOR( i = 0; i < M; i++ ) { - pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); + pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); /* Q2.56 */ move16(); } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE @@ -719,7 +719,7 @@ void lsf_end_dec_fx( /* intra mode*/ st->BER_detect = s_or( st->BER_detect, - vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ) ); /* Q0 */ move16(); Vr_add( qlsf, pred3, qlsf, M ); @@ -730,15 +730,15 @@ void lsf_end_dec_fx( { IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 1, qlsf, &lindice[1], stages0, M, mode_lvq, levels0[stages0 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 1, qlsf, &lindice[1], 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] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); Vr_add( qlsf, pred0, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); @@ -757,15 +757,15 @@ void lsf_end_dec_fx( #endif IF( st->element_mode != EVS_MONO ) { - ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); + ber_flag = vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages1, M, mode_lvq_p, levels1[stages1 - 1] ); /* Q0 */ } ELSE { ber_flag = vq_dec_lvq_fx( 0, qlsf, &lindice[1], 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] ); + &st->no_scales_fx[0][0], &st->no_scales_p_fx[0][0] ); /* Q0 */ } - st->BER_detect = s_or( st->BER_detect, ber_flag ); + st->BER_detect = s_or( st->BER_detect, ber_flag ); /* Q0 */ move16(); #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); @@ -774,9 +774,9 @@ void lsf_end_dec_fx( IF( EQ_16( predmode, 1 ) ) /* MA only */ #endif { - Copy( qlsf, st->mem_MA_fx, M ); - Vr_add( qlsf, pred1, qlsf, M ); - *LSF_Q_prediction = MOVING_AVERAGE; + Copy( qlsf, st->mem_MA_fx, M ); /* Q2.56 */ + Vr_add( qlsf, pred1, qlsf, M ); /* Q2.56 */ + *LSF_Q_prediction = MOVING_AVERAGE; /* Q0 */ move16(); } ELSE @@ -784,12 +784,12 @@ void lsf_end_dec_fx( /* AR */ FOR( i = 0; i < M; i++ ) { - pred2[i] = add( pred0[i], mult( Predictors_fx[mode_lvq_p][i], sub( st->mem_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] ) ) ); /* Q2.56 */ move16(); } Vr_add( qlsf, pred2, qlsf, M ); Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); - *LSF_Q_prediction = AUTO_REGRESSIVE; + *LSF_Q_prediction = AUTO_REGRESSIVE; /* Q0 */ move16(); } } @@ -807,9 +807,9 @@ void lsf_end_dec_fx( /* Verify stability */ reorder_lsf_fx( qlsf, MODE1_LSF_GAP_FX, M, st->sr_core ); /* Update predictor memory */ - Copy( qlsf, st->mem_AR_fx, M ); + Copy( qlsf, st->mem_AR_fx, M ); /* Q2.56 */ - st->mode_lvq = mode_lvq; + st->mode_lvq = mode_lvq; /* Q0 */ move16(); @@ -839,10 +839,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 endS Q15*/ + Word16 coder_type, /* i : Coder type Q0*/ + Word16 lsp_mid[] /* o : quantized LSPs Q15*/ ) { Word16 j, idx; @@ -862,19 +862,19 @@ void lsf_mid_dec_fx( /* Codebook selection */ IF( EQ_16( st_fx->ppp_mode_dec, 1 ) ) { - nb_bits = 1; + nb_bits = 1; /* Q0 */ move16(); - ratio = &tbl_mid_voi_wb_1b_fx[0]; + ratio = &tbl_mid_voi_wb_1b_fx[0]; /* Q13 */ } ELSE IF( EQ_16( st_fx->nelp_mode_dec, 1 ) ) { - nb_bits = 4; + nb_bits = 4; /* Q0 */ move16(); - ratio = &tbl_mid_unv_wb_4b_fx[0]; + ratio = &tbl_mid_unv_wb_4b_fx[0]; /* Q13 */ } ELSE { - nb_bits = st_fx->acelp_cfg.mid_lsf_bits; + nb_bits = st_fx->acelp_cfg.mid_lsf_bits; /* Q0 */ move16(); /* codebook selection */ @@ -885,24 +885,24 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_voi_wb_5b_fx; + ratio = tbl_mid_voi_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_voi_wb_4b_fx; + ratio = tbl_mid_voi_wb_4b_fx; /* Q13 */ BREAK; } case 1: { - ratio = tbl_mid_voi_wb_1b_fx; + ratio = tbl_mid_voi_wb_1b_fx; /* Q13 */ break; } } } - ELSE IF( coder_type == UNVOICED ) + ELSE IF( EQ_16( coder_type, UNVOICED ) ) { - ratio = tbl_mid_unv_wb_5b_fx; + ratio = tbl_mid_unv_wb_5b_fx; /* Q13 */ } ELSE { @@ -911,17 +911,17 @@ void lsf_mid_dec_fx( { case 5: { - ratio = tbl_mid_gen_wb_5b_fx; + ratio = tbl_mid_gen_wb_5b_fx; /* Q13 */ BREAK; } case 4: { - ratio = tbl_mid_gen_wb_4b_fx; + ratio = tbl_mid_gen_wb_4b_fx; /* Q13 */ break; } case 2: { - ratio = tbl_mid_gen_wb_2b_fx; + ratio = tbl_mid_gen_wb_2b_fx; /* Q13 */ BREAK; } } @@ -929,7 +929,7 @@ void lsf_mid_dec_fx( } /* Retrieve mid-frame LSF index */ - idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); + idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); /* Q0 */ /* Calculation of mid-LSF vector */ FOR( j = 0; j < M; j++ ) @@ -947,7 +947,7 @@ void lsf_mid_dec_fx( { IF( LT_16( qlsf[j], qlsf[j - 1] ) ) { - bad_spacing = 1; + bad_spacing = 1; /* Q0 */ move16(); BREAK; } @@ -970,7 +970,7 @@ void lsf_mid_dec_fx( test(); 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 ); /* Q2.56 */ move16(); } } @@ -984,7 +984,7 @@ void lsf_mid_dec_fx( test(); 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 ); /* Q2.56 */ move16(); } } @@ -993,7 +993,7 @@ void lsf_mid_dec_fx( if ( st_fx->prev_bfi ) { /* continue redoing mid-LSF interpolation with 0.4 in order not to propagate the error */ - st_fx->mid_lsf_int = 1; + st_fx->mid_lsf_int = 1; /* Q0 */ move16(); } diff --git a/lib_dec/lsf_msvq_ma_dec_fx.c b/lib_dec/lsf_msvq_ma_dec_fx.c index 167f71d4d..f57aee0e1 100644 --- a/lib_dec/lsf_msvq_ma_dec_fx.c +++ b/lib_dec/lsf_msvq_ma_dec_fx.c @@ -26,7 +26,10 @@ * *---------------------------------------------------------------------*/ -Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) +Word16 lsf_msvq_ma_decprm( + Decoder_State *st, + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc, tmp; Word16 bits_midlpc; @@ -34,7 +37,7 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) levels0[MAX_VQ_STAGES], levels1[MAX_VQ_STAGES], *bits; Word16 predmode, mode_lvq, mode_lvq_p, safety_net; - bits_midlpc = 5; + bits_midlpc = 5; /* Q0 */ move16(); test(); @@ -63,54 +66,54 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) 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 ); /* Q0 */ IF( EQ_16( safety_net, 1 ) ) { - stages = stages0; + stages = stages0; /* Q0 */ move16(); - bits = bits0; + bits = bits0; /* Q0 */ move16(); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - *param_lpc = safety_net; + *param_lpc = safety_net; /* Q0 */ move16(); param_lpc++; - nbits_lpc++; + nbits_lpc = add( nbits_lpc, 1 ); } ELSE { - stages = stages1; + stages = stages1; /* Q0 */ move16(); - bits = bits1; + bits = bits1; /* Q0 */ move16(); } - tmp = sub( stages, 1 ); + tmp = sub( stages, 1 ); /* Q0 */ FOR( i = 0; i < tmp; i++ ) { - *param_lpc = get_next_indice_fx( st, bits[i] ); + *param_lpc = get_next_indice_fx( st, bits[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits[i] ); + nbits_lpc = add( nbits_lpc, bits[i] ); /* Q0 */ } - *param_lpc = get_next_indice_fx( st, LEN_INDICE ); + *param_lpc = get_next_indice_fx( st, LEN_INDICE ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, LEN_INDICE ); + nbits_lpc = add( nbits_lpc, LEN_INDICE ); /* Q0 */ - *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); + *param_lpc = get_next_indice_fx( st, sub( bits[i], LEN_INDICE ) ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); + nbits_lpc = add( nbits_lpc, sub( bits[i], LEN_INDICE ) ); /* Q0 */ test(); @@ -118,9 +121,9 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) IF( NE_16( st->coder_type, VOICED ) && st->core == 0 && st->acelp_cfg.midLpc ) { - *param_lpc = get_next_indice_fx( st, bits_midlpc ); + *param_lpc = get_next_indice_fx( st, bits_midlpc ); /* Q0 */ move16(); - nbits_lpc = add( nbits_lpc, bits_midlpc ); + nbits_lpc = add( nbits_lpc, bits_midlpc ); /* Q0 */ } return nbits_lpc; @@ -129,15 +132,16 @@ Word16 lsf_msvq_ma_decprm( Decoder_State *st, Word16 *param_lpc ) Word16 lsf_bctcvq_decprm( Decoder_State *st, - Word16 *param_lpc ) + Word16 *param_lpc /* Q0 */ +) { Word16 i, nbits_lpc; Word16 num_par; const Word16 *bits1; - num_par = 10; + num_par = 10; /* Q0 */ move16(); - bits1 = BC_TCVQ_BIT_ALLOC_40B; + bits1 = BC_TCVQ_BIT_ALLOC_40B; /* Q0 */ nbits_lpc = 0; move16(); @@ -145,10 +149,10 @@ Word16 lsf_bctcvq_decprm( FOR( i = 0; i < num_par; i++ ) { - *param_lpc = get_next_indice_fx( st, bits1[i] ); + *param_lpc = get_next_indice_fx( st, bits1[i] ); /* Q0 */ move16(); param_lpc++; - nbits_lpc = add( nbits_lpc, bits1[i] ); + nbits_lpc = add( nbits_lpc, bits1[i] ); /* Q0 */ } return nbits_lpc; @@ -156,12 +160,12 @@ Word16 lsf_bctcvq_decprm( /* Returns: number of indices */ Word16 D_lsf_tcxlpc( - const Word16 indices[], /* i : VQ indices */ - Word16 lsf_q[], /* o : quantized LSF */ - Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) */ - Word16 narrowband, /* i : narrowband flag */ - Word16 cdk, /* i : codebook selector */ - Word16 mem_MA[] /* i : MA memory */ + const Word16 indices[], /* i : VQ indices Q0*/ + Word16 lsf_q[], /* o : quantized LSF Q1*/ + Word16 lsp_q_ind[], /* o :quantized LSP (w/o MA prediction) Q1*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk, /* i : codebook selector Q0*/ + Word16 mem_MA[] /* i : MA memory Q1*/ ) { Word16 i; @@ -171,7 +175,7 @@ Word16 D_lsf_tcxlpc( const Word16 *means; Word16 lsf_rem_q_ind[M]; - NumIndices = 1; + NumIndices = 1; /* Q0 */ move16(); msvq_dec( @@ -187,7 +191,7 @@ Word16 D_lsf_tcxlpc( #endif lsf_q ); - NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_NUMSTAGES ); /* Q0 */ FOR( i = 0; i < M; ++i ) { @@ -209,32 +213,32 @@ Word16 D_lsf_tcxlpc( 0, NULL, #endif lsf_rem_q_ind ); - NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); + NumIndices = add( NumIndices, TCXLPC_IND_NUMSTAGES ); /* Q0 */ /* Add to MA-removed vector */ FOR( i = 0; i < M; ++i ) { - lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], lsf_rem_q_ind[i] ); /* Q1 */ move16(); } } /* Inter-frame prediction */ move16(); - means = lsf_means[narrowband]; + means = lsf_means[narrowband]; /* Q1 */ FOR( i = 0; i < M; ++i ) { - pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); + pred[i] = add( means[i], mult_r( MU_MA_FX, mem_MA[i] ) ); /* Q1 */ move16(); } /* Add prediction */ FOR( i = 0; i < M; ++i ) { - lsf_q[i] = add( lsf_q[i], pred[i] ); + lsf_q[i] = add( lsf_q[i], pred[i] ); /* Q1 */ move16(); - lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); + lsf_q_ind[i] = add( lsf_q_ind[i], means[i] ); /* Q1 */ move16(); } @@ -251,26 +255,26 @@ Word16 D_lsf_tcxlpc( /* Returns: number of bits read */ 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 */ + Decoder_State *st, /* i/o: Decoder state */ + Word16 **indices, /* o : Ptr to VQ indices Q0*/ + Word16 narrowband, /* i : narrowband flag Q0*/ + Word16 cdk /* i : codebook selector Q0*/ ) { Word16 i, start_bit_pos; Word16 lsf_q_ind[M]; Word16 *flag; - flag = *indices; /* Save pointer */ + flag = *indices; /* Save pointer Q0*/ *flag = 0; move16(); /* Set flag to disabled */ ++*indices; - start_bit_pos = st->next_bit_pos; + start_bit_pos = st->next_bit_pos; /* Q0 */ move16(); FOR( i = 0; i < TCXLPC_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_numbits[i] ); /* Q0 */ ++*indices; move16(); } @@ -290,13 +294,13 @@ Word16 dec_lsf_tcxlpc( lsf_q_ind ); /* Update flag */ - *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); + *flag = lsf_ind_is_active( lsf_q_ind, lsf_means[narrowband], narrowband, cdk ); /* Q0 */ move16(); IF( *flag ) { FOR( i = 0; i < TCXLPC_IND_NUMSTAGES; ++i ) { - **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); + **indices = get_next_indice_fx( st, lsf_ind_numbits[i] ); /* Q0 */ ++*indices; move16(); } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 1f103223e..a1e2bbf39 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -86,7 +86,15 @@ 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, /* Q0 */ + Word16 *exc, /* Q_exc */ + Word16 *Q_exc, + Word16 bfi, /* Q0 */ + const Word16 coder_type, /* Q0 */ + Word16 *gain_buf /* Q14 */ +) { Word16 i, fid = 0; move16(); @@ -126,7 +134,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 { IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); set32_fx( hSC_VBR->bp1_filt_mem_nb_dec_fx, 0, BP1_ORDER * 2 ); @@ -134,7 +142,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 } 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; /* Q0 */ move16(); IF( NE_16( st_fx->last_nelp_mode_dec, 1 ) ) { @@ -154,21 +162,21 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); 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; + iG1 = st_fx->rf_indx_nelp_iG1; /* Q0 */ move16(); - iG2[0] = st_fx->rf_indx_nelp_iG2[0]; + iG2[0] = st_fx->rf_indx_nelp_iG2[0]; /* Q0 */ move16(); - iG2[1] = st_fx->rf_indx_nelp_iG2[1]; + iG2[1] = st_fx->rf_indx_nelp_iG2[1]; /* Q0 */ move16(); } ELSE { /* Do Unvoiced/NELP Decoding */ - iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); + iG1 = (Word16) get_next_indice_fx( st_fx, 5 ); /* Q0 */ move16(); - iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[0] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); - iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); + iG2[1] = (Word16) get_next_indice_fx( st_fx, 6 ); /* Q0 */ move16(); } @@ -179,12 +187,12 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); 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; + fid = st_fx->rf_indx_nelp_fid; /* Q0 */ move16(); } ELSE { - fid = (Word16) get_next_indice_fx( st_fx, 2 ); + fid = (Word16) get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); } } @@ -202,7 +210,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 max_exc_sqr = L_deposit_l( 0 ); FOR( i = 0; i < L_SUBFR; i++ ) { - max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); + max_exc_sqr = L_max( max_exc_sqr, exc_sqr[i] ); /*2*Q_exc */ } IF( max_exc_sqr != 0 ) { @@ -231,7 +239,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 n = norm_l( Gain ); frac = round_fx( L_shl( Gain, n ) ); n = sub( add( n, 24 ), 30 ); - frac = div_s( 16384, frac ); + frac = div_s( 16384, frac ); /* Q15 */ Gain = Isqrt_lc( L_deposit_h( frac ), &n ); /*Q(31-n-exp) */ tmp = round_fx( L_shl( Gain, sub( add( n, exp ), 15 ) ) ); /*Q0 */ } @@ -272,7 +280,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, WB ) || EQ_16( st_fx->bwidth, SWB ) ) ) { - BP1_ORDER = 4; + BP1_ORDER = 4; /* Q0 */ move16(); Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), 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, @@ -280,18 +288,18 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 Scale_sig( hSC_VBR->bp1_filt_mem_wb_dec_fx, shl( BP1_ORDER, 1 ), negate( 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 ); + Copy( ptr_tmp, ptr, L_FRAME ); /* Q0 */ } test(); IF( EQ_16( coder_type, UNVOICED ) && ( EQ_16( st_fx->bwidth, NB ) ) ) { - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ move16(); FOR( i = 0; i < L_FRAME; i++ ) { - max_val = s_max( ptr[i], max_val ); + max_val = s_max( ptr[i], max_val ); /* Q0 */ } tmp = shl( BP1_ORDER, 1 ); FOR( i = 0; i < tmp; i++ ) @@ -306,13 +314,13 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 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 ); /* norm_val */ + Scale_sig( ptr, L_FRAME, norm_val ); /* norm_val + Q_exc */ *Q_exc = add( norm_val, *Q_exc ); move16(); } - BP1_ORDER = 7; + BP1_ORDER = 7; /* Q0 */ 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 ) ) ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index cb326efb2..6e051302f 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -902,6 +902,10 @@ ivas_error init_encoder( st->hTcxEnc->spectrum[0] = st->hTcxEnc->spectrum_long; st->hTcxEnc->spectrum[1] = st->hTcxEnc->spectrum_long + N_TCX10_MAX; +#ifdef MSAN_FIX + set32_fx( st->hTcxEnc->spectrum_fx[0], 0, N_TCX10_MAX ); + set32_fx( st->hTcxEnc->spectrum_fx[1], 0, N_TCX10_MAX ); +#endif set_f( st->hTcxEnc->old_out, 0, L_FRAME32k ); /* MDCT selector */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 48e175a43..20ac14fb6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -1101,9 +1101,11 @@ ivas_error ivas_core_enc( fb_tbe_enc( st, st->input, fb_exc ); #else #ifdef IVAS_FLOAT_FIXED_CONVERSIONS +#ifndef MSAN_FIX Q_fb_exc = Q_factor_arr( fb_exc, L_FRAME16k ); floatToFixed_arr( fb_exc, fb_exc_fx, Q_fb_exc, L_FRAME16k ); - // Q_input is being calculated inside already +#endif + // Q_input is being calculated inside already Word16 Q_input = 0; floatToFixed_arr( st->input_buff, st->input_buff_fx, Q_input, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ); Word16 len_old_input_fhb_fx = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 9e8ba1410..7902d1cf8 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -1138,7 +1138,9 @@ ivas_error ivas_compute_core_buffers( Word16 inp16k_out_buf_fx[2][L_FRAME16k]; Word16 **inp16k_out_fx = (Word16 **) inp16k_out_buf_fx; Word16 new_inp_resamp16k_out_fx[L_FRAME16k]; - +#ifdef MSAN_FIX + set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k ); +#endif signal_in_32fx = st->input32_fx; signal_in_fx = st->input_fx; diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 2a10d92d7..beeec44b7 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -625,12 +625,8 @@ ivas_error ivas_dirac_enc( { for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { - hQMetaData->q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction->band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); if ( hodirac_flag ) { - hQMetaData->q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); - hQMetaData->q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); } else @@ -682,18 +678,51 @@ ivas_error ivas_dirac_enc( #endif - if ( hQMetaData->q_direction->cfg.nbands > 0 ) + IF( hQMetaData->q_direction->cfg.nbands > 0 ) { orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - if ( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ - if ( hQMetaData->dirac_mono_flag ) + IF( hQMetaData->dirac_mono_flag ) { +#ifdef IVAS_FLOAT_FIXED + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + ELSE + { + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + FOR( i_ts = 0; i_ts < 1; i_ts++ ) + { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#endif + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; + hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + } + } + } + +#else for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) @@ -703,6 +732,7 @@ ivas_error ivas_dirac_enc( hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; } } +#endif } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS @@ -711,8 +741,6 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifndef MSAN_FIX floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -720,7 +748,7 @@ ivas_error ivas_dirac_enc( } } #endif - if ( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } @@ -730,17 +758,14 @@ ivas_error ivas_dirac_enc( for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - /*fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES );*/ - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif } - else + ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; + move16(); /* compute directions */ for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) @@ -753,11 +778,6 @@ ivas_error ivas_dirac_enc( for ( j = 0; j < orig_dirac_bands - 1; j++ ) { #ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].azimuth[i], Q22 ); - hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].elevation[i], Q22 ); - /*==========================================flt-2-fix======================================================*/ - ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); /*==========================================fix-2-flt======================================================*/ @@ -784,18 +804,18 @@ ivas_error ivas_dirac_enc( /*==========================================flt-2-fix======================================================*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); - - /*==========================================fix-2-flt======================================================*/ - hQMetaData->q_direction[0].band_data[0].azimuth[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], Q22 ); - hQMetaData->q_direction[0].band_data[0].elevation[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].elevation_fx[i], Q22 ); - /*==========================================fix-2-flt======================================================*/ #else ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); #endif hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; + hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; +#else hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; +#endif hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; } @@ -804,62 +824,58 @@ ivas_error ivas_dirac_enc( /* encode SID parameters */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IVAS_QDIRECTION *q_direction; - q_direction = &( hQMetaData->q_direction[0] ); - - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - FOR( int m = 0; m < q_direction->cfg.nblocks; m++ ) - { - q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); - q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); - } - } -#endif ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( b = 0; b < q_direction->cfg.nbands; b++ ) - { - q_direction->band_data[b].q_azimuth[0] = fixedToFloat( q_direction->band_data[b].q_azimuth_fx[0], Q22 ); - q_direction->band_data[b].q_elevation[0] = fixedToFloat( q_direction->band_data[b].q_elevation_fx[0], Q22 ); - } -#endif #else ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); #endif } - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; + hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; +#else hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; +#endif hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; } } - if ( dtx_vad == 0 ) + IF( dtx_vad == 0 ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) { +#ifdef IVAS_FLOAT_FIXED + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; +#else hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; +#endif hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } } hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + move16(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 978bb371f..c41736176 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -863,19 +863,27 @@ ivas_error ivas_enc( if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) { - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ - #ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } +#endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS + ivas_masa_estimate_energy_fx( st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); /* energy-estimation uses TF-resolution: 4x24 */ + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif +#else + ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -885,13 +893,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -951,32 +955,47 @@ ivas_error ivas_enc( float *data_separated_object; Word32 *data_separated_object_fx; - int16_t idx_separated_object; - int16_t flag_omasa_ener_brate; + Word16 idx_separated_object; + Word16 flag_omasa_ener_brate; flag_omasa_ener_brate = 0; + move16(); /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + IF( EQ_16( sub( st_ivas->hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) + { + v_multc_fixed( data_fx[hEncoderConfig->nchan_ism], L_deposit_h( INV_SQRT2_FX_Q15 ) /* Q31 */, data_fx[hEncoderConfig->nchan_ism], input_frame ); + Copy32( data_fx[hEncoderConfig->nchan_ism], data_fx[hEncoderConfig->nchan_ism + 1], input_frame ); + } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - +#endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); + } +#endif /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - + ivas_masa_estimate_energy_fx( st_ivas->hMasa, &( data_fx[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport, st_ivas->q_data_fx ); -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } + fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS +#endif +#else + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif + +#ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -986,13 +1005,9 @@ ivas_error ivas_enc( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1017,7 +1032,6 @@ ivas_error ivas_enc( /* Estimate MASA parameters for the objects */ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - MASA_ENCODER_HANDLE hMasa = st_ivas->hMasa; int16_t j; int16_t nchan_transport = st_ivas->nchan_transport; int16_t nchan_ism = hEncoderConfig->nchan_ism; @@ -1040,23 +1054,9 @@ ivas_error ivas_enc( { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( hMasa->data.energy[i][j], &hMasa->data.energy_fx[i][j], &hMasa->data.energy_e[i][j] ); - } - } #endif ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy[i][j] = me2f( hMasa->data.energy_fx[i][j], hMasa->data.energy_e[i][j] ); - } - } for ( i = 0; i < nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); @@ -1379,8 +1379,6 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].azimuth_fx[jj], Q22 ); - st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].elevation_fx[jj], Q22 ); st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); } } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1d77e746c..b40665a98 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1203,15 +1203,6 @@ ivas_error ivas_init_encoder( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1222,13 +1213,9 @@ ivas_error ivas_init_encoder( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1878,15 +1865,6 @@ ivas_error ivas_init_encoder_fx( return error; } #else -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -1897,13 +1875,9 @@ ivas_error ivas_init_encoder_fx( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 97101e412..5438bc921 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -397,37 +397,15 @@ ivas_error ivas_masa_encode( ivas_error error; Word16 guard_bits, tmp; + guard_bits = find_guarded_bits_fx( 24 ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) { floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].azimuth, hQMetaData->q_direction[i].band_data[j].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].elevation, hQMetaData->q_direction[i].band_data[j].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - hMasa->data.q_energy = Q31; - // guard_bits = find_guarded_bits_fx( 9 ); - guard_bits = find_guarded_bits_fx( 24 ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hMasa->data.q_energy = s_min( hMasa->data.q_energy, L_get_q_buf1( hMasa->data.energy[i], MASA_FREQUENCY_BANDS ) ); - } - hMasa->data.q_energy -= guard_bits; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_e[i][j] = 31 - hMasa->data.q_energy; - } - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - floatToFixed_arrL32( hMasa->data.energy[i], hMasa->data.energy_fx[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } #endif masa_sid_descriptor = -1; @@ -487,28 +465,29 @@ ivas_error ivas_masa_encode( /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes_fx( hMasa ); + } - /* aligning the exponents */ - s = 0; - move16(); - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); - s = s_max( s, tmp ); - } - FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + /* aligning the exponents of energy_fx */ + s = 0; + move16(); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + maximum_s( hMasa->data.energy_e[i], MASA_FREQUENCY_BANDS, &tmp ); + s = s_max( s, tmp ); + } + s = add( s, guard_bits ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) { - FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); - hMasa->data.energy_e[i][j] = s; - move32(); - move16(); - } + hMasa->data.energy_fx[i][j] = L_shr( hMasa->data.energy_fx[i][j], sub( s, hMasa->data.energy_e[i][j] ) ); + hMasa->data.energy_e[i][j] = s; + move32(); + move16(); } - hMasa->data.q_energy = sub( 31, s ); - move16(); } + hMasa->data.q_energy = sub( 31, s ); + move16(); test(); test(); @@ -881,19 +860,11 @@ ivas_error ivas_masa_encode( } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - fixedToFloat_arrL32( hMasa->data.energy_fx[i], hMasa->data.energy[i], hMasa->data.q_energy, MASA_FREQUENCY_BANDS ); - } for ( i = 0; i < hQMetaData->no_directions; i++ ) { for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].azimuth_fx, hQMetaData->q_direction[i].band_data[j].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].elevation_fx, hQMetaData->q_direction[i].band_data[j].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, hQMetaData->q_direction[i].band_data[j].q_azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation_fx, hQMetaData->q_direction[i].band_data[j].q_elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); } } #endif @@ -1265,8 +1236,113 @@ ivas_error ivas_masa_encode( return IVAS_ERR_OK; } #endif +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------* + * ivas_masa_estimate_energy_fx() + * + * + *-----------------------------------------------------------------------*/ +void ivas_masa_estimate_energy_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ + const Word16 input_frame, /* i : frame length */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + Word16 q_data /* i : q for data_fx */ +) +{ + Word32 Input_RealBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 Input_ImagBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 block_m_idx, band_m_idx; + Word16 mrange[2], brange[2]; + Word16 i, j, ts, l_ts, maxBin; + Word64 energy_fx_temp[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 scale = 63; + move16(); + Word16 q_buf; + maxBin = extract_l( Mpy_32_32( 134217728 /*CLDFB_NO_CHANNELS_MAX / L_FRAME48k in Q31*/, input_frame ) ); + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + FOR( j = 0; j < MASA_FREQUENCY_BANDS; j++ ) + { + energy_fx_temp[i][j] = 0; + move64(); + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + mrange[0] = hMasa->config.block_grouping[block_m_idx]; + move16(); + mrange[1] = hMasa->config.block_grouping[block_m_idx + 1]; + move16(); + set_zero_fx( hMasa->data.energy_fx[block_m_idx], MASA_FREQUENCY_BANDS ); + set16_fx( hMasa->data.energy_e[block_m_idx], 0, MASA_FREQUENCY_BANDS ); + + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + q_buf = q_data; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( data_fx[i][l_ts * ts] ), Input_RealBuffer[i], Input_ImagBuffer[i], l_ts, hMasa->data.cldfbAnaEnc[i], &q_buf ); // (q_data - 5) for Input_RealBuffer[i], Input_ImagBuffer[i] + } + + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + brange[0] = hMasa->config.band_grouping[band_m_idx]; + move16(); + brange[1] = hMasa->config.band_grouping[band_m_idx + 1]; + move16(); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( GT_16( brange[0], maxBin ) ) + { + hMasa->data.energy_fx[block_m_idx][band_m_idx] = 0; + move32(); + CONTINUE; + } + ELSE IF( GE_16( brange[1], maxBin ) ) + { + brange[1] = maxBin; + move16(); + } + + FOR( j = brange[0]; j < brange[1]; j++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_add( energy_fx_temp[block_m_idx][band_m_idx], W_mac_32_32( W_mult_32_32( Input_RealBuffer[i][j], Input_RealBuffer[i][j] ), Input_ImagBuffer[i][j], Input_ImagBuffer[i][j] ) ); // Q: 2 * (q_data - 5) + 1 for energy_fx_temp + move64(); + } + IF( energy_fx_temp[block_m_idx][band_m_idx] != 0 ) + { + scale = s_min( scale, W_norm( energy_fx_temp[block_m_idx][band_m_idx] ) ); // scale calculates minimum shift can be done across a buffer + } + } + } + } + } + + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) + { + energy_fx_temp[block_m_idx][band_m_idx] = W_shl( energy_fx_temp[block_m_idx][band_m_idx], scale ); // Q: 2 * (q_data - 5) + 1 + scale + move64(); + hMasa->data.energy_fx[block_m_idx][band_m_idx] = W_extract_h( energy_fx_temp[block_m_idx][band_m_idx] ); // Q: 2 * (q_data - 5) + 1 + scale - 32 + move32(); + hMasa->data.energy_e[block_m_idx][band_m_idx] = sub( 31, add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ) ); + move16(); + } + } + hMasa->data.q_energy = add( add( imult1616( 2, q_data ), scale ), 1 - 10 - 32 ); + move16(); + + return; +} +#else /*-----------------------------------------------------------------------* * ivas_masa_estimate_energy() * @@ -1332,6 +1408,7 @@ void ivas_masa_estimate_energy( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index f74174689..024532450 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -887,7 +887,11 @@ void ivas_param_mc_enc_fx( { Word16 cpe_idx = shr( ch, 1 ); +#ifndef MSAN_FIX Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], -Q1 - Q11, input_frame ); // Q11 -> Q(-1) +#else + Copy_Scale_sig_32_16( data_dmx_fx[ch], data_dmx_fx16[ch], input_frame, -Q1 - Q11 ); // Q11 -> Q(-1) +#endif RunTransientDetection_ivas_fx( data_dmx_fx16[ch], input_frame, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet ); ivas_param_mc_transient_detection_fx( hParamMC, st_ivas->hCPE[cpe_idx]->hCoreCoder[ch - cpe_idx * CPE_CHANNELS]->hTranDet, &bAttackPresent[ch], &attackIdx[ch] ); diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 821450296..57de41384 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -1696,6 +1696,20 @@ void ivas_mcmasa_param_est_enc_fx( p_Chnl_ImagBuffer_fx[i] = &Chnl_ImagBuffer_fx[i][0]; } + /* initialising energy_fx */ + FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) + { + hMasa->data.energy_fx[block_m_idx][i] = 0; + move32(); + hMasa->data.energy_e[block_m_idx][i] = 31; + move16(); + } + } + hMasa->data.q_energy = 0; + move16(); + /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) { @@ -1767,25 +1781,11 @@ void ivas_mcmasa_param_est_enc_fx( } /* Store energies for guiding metadata encoding */ - hMasa->data.energy_fx[block_m_idx][i] = 0; - move32(); - hMasa->data.energy_e[block_m_idx][i] = 31; - move16(); FOR( j = 0; j < numAnalysisChannels; j++ ) { move32(); hMasa->data.energy_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hMasa->data.energy_fx[block_m_idx][i], hMasa->data.energy_e[block_m_idx][i], COVls[i].xr_fx[j][j], COVls[i].xr_e[j][j], &hMasa->data.energy_e[block_m_idx][i] ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - IF( hMasa->data.energy_e[block_m_idx][i] < 31 ) - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] / (float) ( 1 << ( 31 - hMasa->data.energy_e[block_m_idx][i] ) ); - } - ELSE - { - hMasa->data.energy[block_m_idx][i] = hMasa->data.energy_fx[block_m_idx][i] * (float) ( 1 << ( hMasa->data.energy_e[block_m_idx][i] - 31 ) ); - } -#endif } IF( !hMcMasa->separateChannelEnabled ) diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index f326b1a32..aaa3dd260 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -1771,15 +1771,6 @@ static ivas_error ivas_mc_enc_reconfig( return error; } #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1789,13 +1780,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } @@ -1812,15 +1799,6 @@ static ivas_error ivas_mc_enc_reconfig( { /* reconfigure McMASA instance */ #ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( int i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( int j = 0; j < MASA_FREQUENCY_BANDS; j++ ) - { - f2me( st_ivas->hMasa->data.energy[i][j], &st_ivas->hMasa->data.energy_fx[i][j], &st_ivas->hMasa->data.energy_e[i][j] ); - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS if ( NE_32( ( error = ivas_mcmasa_enc_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -1830,13 +1808,9 @@ static ivas_error ivas_mc_enc_reconfig( { for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); if ( st_ivas->hQMetaData->no_directions == 2 ) { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].elevation_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); } } diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 79a32e4a4..bde299111 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -2231,7 +2231,7 @@ Word16 quantize_direction2D_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); } *phi_q = L_sub( *phi_q, 180 << Q22 ); move32(); @@ -4257,7 +4257,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4400,7 +4400,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( { use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4478,7 +4478,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( v_add_fixed( avg_direction_vector, direction_vector, avg_direction_vector, 3, 0 ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector, Q22, &avg_azimuth, &avg_elevation ); - avg_azimuth_index_upd = quantize_phi_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); + avg_azimuth_index_upd = quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ); } idx = add( idx, 1 ); } @@ -5772,7 +5772,7 @@ static Word16 truncGR0_fx( FOR( i = 0; i < len; i++ ) { - data_idx[i] = quantize_phi_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); + data_idx[i] = quantize_phi_enc_fx( L_add( data_fx[i], DEGREE_180_Q_22 ), 0, &data_hat_fx[i], 8 ); move16(); data_hat_fx[i] = L_sub( data_hat_fx[i], DEGREE_180_Q_22 ); move32(); @@ -5796,7 +5796,7 @@ static Word16 truncGR0_fx( { bits = sub( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[indx[i]], 8, 0 ) ); // data_idx[indx[i]] = quantize_phi( data[indx[i]] + 180, 0, &data_hat[indx[i]], 4 ); - data_idx[indx[i]] = quantize_phi_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); + data_idx[indx[i]] = quantize_phi_enc_fx( L_add( data_fx[indx[i]], DEGREE_180_Q_22 ), 0, &data_hat_fx[indx[i]], 4 ); move16(); // data_hat[indx[i]] -= 180; data_hat_fx[indx[i]] = L_sub( data_hat_fx[indx[i]], DEGREE_180_Q_22 ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index 74a787b2c..d2804108a 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -812,7 +812,7 @@ UWord16 quantize_direction_fx( } ELSE { - id_phi = quantize_phi_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, &phi_hat, no_phi_masa[no_bits - 1][0] ); idx_sph = id_phi; *phi_q = L_sub( phi_hat, DEGREE_180_Q_22 ); id_phi_remap = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_phi_masa[no_bits - 1][0], 1 ) ) ); @@ -1339,7 +1339,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } ELSE @@ -1362,7 +1362,7 @@ static Word32 quantize_theta_phi_fx( // Q22 theta_hat1 = theta_cb[id_th1]; move32(); - id_ph1 = quantize_phi_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); + id_ph1 = quantize_phi_enc_fx( phi, s_and( id_th1, 1 ), &phi_hat1, no_phi_loc[id_th1] ); d_fx = direction_distance_cp_fx( abs_theta, theta_hat, theta_hat1, phi, *phi_hat, phi_hat1, &d1_fx ); @@ -1389,7 +1389,7 @@ static Word32 quantize_theta_phi_fx( // Q22 } ELSE { - id_ph = quantize_phi_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); + id_ph = quantize_phi_enc_fx( phi, s_and( id_th, 1 ), phi_hat, no_phi_loc[id_th] ); } } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ba611679..d7857435a 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -1132,7 +1132,11 @@ static ivas_error ivas_spar_enc_process( { num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } +#ifdef MSAN_FIX + FOR( Word16 m = 0; m < nchan_fb_in; m++ ) +#else FOR( Word16 m = 0; m <= nchan_fb_in + nchan_transport; m++ ) +#endif { IF( data_f[m] != NULL ) { @@ -1294,11 +1298,6 @@ static ivas_error ivas_spar_enc_process( for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) { Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; - for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) - { - hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts], Q22 ); - hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[i_ts] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].elevation[i_ts], Q22 ); - } hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); } #ifdef IVAS_FLOAT_FIXED_CONVERSIONS diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 4c3eca4d9..8e8dc8f84 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1296,16 +1296,17 @@ typedef struct ivas_masa_sync_struct typedef struct ivas_masa_encoder_data_struct { +#ifndef IVAS_FLOAT_FIXED float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 energy_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word16 q_energy; // Common Q for all energy_fx elements + Word16 q_energy; // Common Q for all energy_fx elements #endif - int16_t num_Cldfb_instances; + Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; - int16_t band_mapping[MASA_FREQUENCY_BANDS + 1]; - uint8_t twoDirBands[MASA_FREQUENCY_BANDS]; + Word16 band_mapping[MASA_FREQUENCY_BANDS + 1]; + UWord8 twoDirBands[MASA_FREQUENCY_BANDS]; SPHERICAL_GRID_DATA Sph_Grid16; #ifdef IVAS_FLOAT_FIXED Word32 importanceWeight_fx[MASA_FREQUENCY_BANDS]; /*q30*/ @@ -1319,7 +1320,7 @@ typedef struct ivas_masa_encoder_data_struct #else Word32 prevq_lfeToTotalEnergyRatio_fx; // Q31 #endif - int16_t prevq_lfeIndex; + Word16 prevq_lfeIndex; #ifndef IVAS_FLOAT_FIXED float onset_detector_1; diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 91799b60a..a9dc30e44 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -325,12 +325,11 @@ void stereo_dft_enc_sid_coh_fx( Word16 zeropad; Word16 nr_of_sid_stereo_bits; Word16 coh_pred_index; - Word16 min_pred_err; - Word16 min_pred_err_e; + Word64 min_pred_err; Word16 pred_err; // Q13 Word16 res_index; Word16 i; - Word16 tmp; + Word32 tmp; const Word16 *pptr; Word16 pred; // Q13 Word16 cohBandq[STEREO_DFT_BAND_MAX / 2]; /* Reconstructed coherence values for intra-frame prediction Q15 */ @@ -355,37 +354,33 @@ void stereo_dft_enc_sid_coh_fx( IF( sub( sub( nr_of_sid_stereo_bits, *nb_bits ), STEREO_DFT_N_COH_ALPHA_BITS + STEREO_DFT_PRED_NBITS ) > 0 ) { - min_pred_err = 31250; - move32(); - min_pred_err_e = 20; - move16(); + min_pred_err = 134217728000000; // 1e6 in Q27 + move64(); coh_pred_index = -1; move16(); pptr = dft_cng_coh_pred_fx[0]; // Q13 FOR( k = 0; k < STEREO_DFT_N_COH_PRED; k++ ) { - pred_err = 0; - move16(); + Word64 pred_err64 = 0; + move64(); FOR( b = 1; b < nbands; b++ ) /* Set b=1 to skip first coefficient (same error would otherwise be added for all predictors: (cohBand[0] - 0).^2) */ { - pred = 0; - move16(); + Word64 pred64 = 0; + move64(); FOR( i = 0; i < b; i++ ) { // pred += ( *pptr++ ) * cohBand[i]; - pred = add( pred, mult_r( extract_h( cohBand[i] ), ( *pptr++ ) ) ); // Q13 + pred64 = W_mac_32_16( pred64, cohBand[i], *pptr++ ); // Q45 (31+13+1) } - tmp = sub( shr_r( extract_h( cohBand[b] ), 2 ), pred ); // Q13 + tmp = L_sub( L_shr( cohBand[b], 18 ), W_extract_h( pred64 ) ); // Q13 // pred_err += tmp * tmp; - pred_err = add( pred_err, shl( mult_r( tmp, tmp ), 2 ) ); // Q13 + pred_err64 = W_mac_32_32( pred_err64, tmp, tmp ); // Q27 } // if ( pred_err < min_pred_err ) /* Store best candidate */ - IF( BASOP_Util_Cmp_Mant32Exp( pred_err, 16, min_pred_err, add( min_pred_err_e, 16 ) ) < 0 ) /* Store best candidate */ + IF( LT_64( pred_err64, min_pred_err ) ) /* Store best candidate */ { - min_pred_err = pred_err; - move32(); - min_pred_err_e = 0; - move16(); + min_pred_err = pred_err64; // Q27 + move64(); coh_pred_index = k; move16(); } diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index e9f7d3d33..2d0b9e08d 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -55,8 +55,8 @@ #ifndef IVAS_FLOAT_FIXED #define POLY_THRESH 1e-4f #else -#define POLY_THRESH_Q29 53687 // Q29 -#define POLY_THRESH_Q28 26843 // Q28 +#define POLY_THRESH_Q29 53687LL // Q29 +#define POLY_THRESH_Q28 26843 // Q28 #endif #ifdef IVAS_FLOAT_FIXED #define Q22_1 4194304 @@ -83,7 +83,7 @@ static void sort_vertices( const EFAP_VERTEX *vertexArray, const int16_t *numVtx 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 sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose, Word16 *numTot, const Word16 efip_flag ); +static ivas_error sphere_triangulation_fx( const Word16 numSpk, EFAP_VERTEX_DATA *vtxData, EFAP_POLYSET_DATA *polyData, Word32 ***dmTranspose /*q31*/, 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 ); @@ -100,12 +100,12 @@ static void efap_panning( const float azi, const float ele, const EFAP_POLYSET_D static void get_poly_gains( const float azi, const float ele, const float aziPoly[EFAP_MAX_CHAN_NUM], const float elePoly[EFAP_MAX_CHAN_NUM], const int16_t numChan, float *buffer ); static float get_tri_gain( const float A[2], const float B[2], const float C[2], const float P_minus_A[2] ); #else -static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] ); -static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix ); -static void vertex_init_fx( const Word32 *aziSpk, const Word32 *eleSpk, EFAP_VERTEX_DATA *efapVtxData ); -static void efap_panning_fx( const Word32 azi, const Word32 ele, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL ); -static void get_poly_gains_fx( const Word32 azi, const Word32 ele, const Word32 aziPoly[EFAP_MAX_CHAN_NUM], const Word32 elePoly[EFAP_MAX_CHAN_NUM], const Word16 numChan, Word32 *buffer ); -static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word32 C[2], const Word32 P_minus_A[2] ); +static void flip_plane_fx( const EFAP_VERTEX *vtxArray, Word16 *surface, const Word32 centroid[3] /*q31*/ ); +static void remap_ghosts_fx( EFAP_VERTEX *vtxArray, EFAP_LS_TRIANGLE *triArray, Word16 numSpk, Word16 *numVertex, Word16 numTri, Word32 **downmixMatrix /*q31*/ ); +static void vertex_init_fx( const Word32 *aziSpk /*q22*/, const Word32 *eleSpk /*q22*/, EFAP_VERTEX_DATA *efapVtxData ); +static void efap_panning_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const EFAP_POLYSET_DATA *polyData, Word32 *bufferL /*q31*/ ); +static void get_poly_gains_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word32 aziPoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word32 elePoly[EFAP_MAX_CHAN_NUM] /*q22*/, const Word16 numChan, Word32 *buffer /*q31*/ ); +static Word32 get_tri_gain_fx( const Word32 A[2] /*q22*/, const Word32 B[2] /*q22*/, const Word32 C[2] /*q22*/, const Word32 P_minus_A[2] /*q22*/ ); #endif /*-----------------------------------------------------------------------* @@ -116,7 +116,7 @@ static Word32 get_tri_gain_fx( const Word32 A[2], const Word32 B[2], const Word3 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 ); #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 add_vertex_fx( EFAP_VERTEX *vtxArray, const Word32 azi /*q22*/, const Word32 ele /*q22*/, const Word16 pos, const EFAP_VTX_DMX_TYPE ); static void efap_sort_s_fx( Word16 *x, Word16 *idx, const Word16 len ); #endif @@ -131,9 +131,9 @@ static void remove_vertex( EFAP_VERTEX *vtxArray, const int16_t idx, const int16 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 Word32 point_plane_distance_fx( const Word32 P1[3] /*q31*/, const Word32 P2[3] /*q31*/, const Word32 P3[3] /*q31*/, const Word32 X[3] /*q31*/ ); +static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, const Word32 X[3] /*q31*/ ); +static void efap_crossp_fx( const Word32 *v1 /*q30*/, const Word32 *v2 /*q30*/, Word32 *v /*q29*/ ); 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 ); @@ -145,7 +145,7 @@ static void matrix_times_row( float mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TM 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 matrix_times_row_fx( Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF] /*q31*/, const Word32 *vec /*q31*/, const Word16 L, Word32 *out /*q31*/ ); 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 @@ -160,11 +160,11 @@ static int16_t in_tri( float A[2], float B[2], float C[2], float P_minus_A[2] ); static void sph2cart( const float azi, const float ele, float *pos ); #else static void sort_channels_vertex_fx( const EFAP_VERTEX *vtxArray, const EFAP_LS_TRIANGLE *triArray, Word16 channels[EFAP_MAX_CHAN_NUM], const Word16 lengthChannels, Word16 idxTri ); -static Word32 efap_32mod32( const Word32 x, const Word32 y ); -static Word16 get_poly_num_fx( const Word32 P[2], const EFAP_POLYSET_DATA *polyData ); -static Word16 in_poly_fx( const Word32 P[2], const EFAP_POLYSET poly ); -static Word16 in_tri_fx( Word32 A[2], Word32 B[2], Word32 C[2], Word32 P_minus_A[2] ); -static void sph2cart_fx( const Word32 azi, const Word32 ele, Word32 *pos ); +static Word32 efap_32mod32( const Word32 x /*q22*/, const Word32 y /*q22*/ ); +static Word16 get_poly_num_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET_DATA *polyData ); +static Word16 in_poly_fx( const Word32 P[2] /*q22*/, const EFAP_POLYSET poly ); +static Word16 in_tri_fx( Word32 A[2] /*q22*/, Word32 B[2] /*q22*/, Word32 C[2] /*q22*/, Word32 P_minus_A[2] /*q22*/ ); +static void sph2cart_fx( const Word32 azi /*q22*/, const Word32 ele /*q22*/, Word32 *pos /*q31*/ ); #endif /*-----------------------------------------------------------------------* @@ -245,8 +245,8 @@ ivas_error efap_init_data_fx( move16(); /* Loudspeaker configuration */ - Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); - Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); + Copy32( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); // Q22 + Copy32( speaker_node_ele_deg, efap->eleSpk, num_speaker_nodes ); // Q22 /* Initialization of the vertex */ vertex_init_fx( efap->aziSpk, efap->eleSpk, &efap->vtxData ); @@ -384,10 +384,10 @@ void efap_determine_gains_fx( set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ - panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); + panning_wrap_angles_fx( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); // ouputs in q22 /* Panning */ - efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); + efap_panning_fx( azi_wrap_int, ele_wrap_int, &hEFAPdata->polyData, hEFAPdata->bufferLong_fx ); // hEFAPdata->bufferLong_fx q31 IF( efap_mode == EFAP_MODE_EFAP ) { @@ -407,11 +407,11 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = ISqrt32( normBuffer, &exp ); + normBuffer = ISqrt32( normBuffer, &exp ); // Q=(31-exp) FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); + hEFAPdata->bufferShort_fx[j] = Mpy_32_32( hEFAPdata->bufferShort_fx[j], normBuffer ); // Q=(30+31-exp-31)=>(30-exp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], exp ); /* Q30 */ move32(); @@ -435,12 +435,12 @@ void efap_determine_gains_fx( } Word16 exp = 2; move16(); - normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); + normBuffer = Inv16( extract_l( L_shr( normBuffer, Q16 ) ), &exp ); /*Q=(15-exp)*/ FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { 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] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], extract_l( normBuffer ) ) /*Q(30-exp)*/, &exp_temp ); // Q=(31-exp_temp) move32(); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); /* Q30 */ move32(); @@ -683,8 +683,8 @@ static ivas_error poly_init_fx( FOR( n = 0; n < efap->vtxData.numVtx; ++n ) { test(); - 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 ) ) ) + if ( GT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( Q22_90_DEG /*90.0 Q22*/ - 4 /*1e-6 Q22*/ ) ) || + LT_32( efap->vtxData.vertexArray[n].ele /*Q22*/, ( 4 /*1e-6 Q22*/ - Q22_90_DEG /*90.0 Q22*/ ) ) ) { efap->vtxData.vertexArray[n].isNaN = 1; move16(); @@ -722,35 +722,35 @@ static ivas_error poly_init_fx( maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); minimum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMin ); - IF( GT_32( L_sub( tmpMax, tmpMin ), Q22_180_DEG ) /*180 in Q22*/ ) + IF( GT_32( L_sub( tmpMax /*q22*/, tmpMin /*q22*/ ), Q22_180_DEG /*180 in Q22*/ ) ) { FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { assert( ( m + 2 < EFAP_MAX_POLY_SET ) && "EFAP: maximum polygons exceeded!" ); /* add two new polygons with azimuths wrapped to differing bounds */ - efap->polyData.polysetArray[add( m, 1 )].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 1].polyAzi[j] = efap_32mod32( efap->polyData.polysetArray[m].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].polyAzi[j] = L_sub( efap->polyData.polysetArray[add( m, 1 )].polyAzi[j], Q22_360_DEG ); /* Q22 */ + efap->polyData.polysetArray[m + 2].polyAzi[j] = L_sub( efap->polyData.polysetArray[m + 1].polyAzi[j] /*q22*/, Q22_360_DEG /*360 q22*/ ); /* Q22 */ move32(); /* Copy the rest of the fields */ - efap->polyData.polysetArray[add( m, 1 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 1].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 1].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 1 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 1].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 1 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 1].numChan = lengthTri2PolySorted[n]; move16(); - efap->polyData.polysetArray[add( m, 2 )].chan[j] = efap->polyData.polysetArray[m].chan[j]; + efap->polyData.polysetArray[m + 2].chan[j] = efap->polyData.polysetArray[m].chan[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ + efap->polyData.polysetArray[m + 2].polyEle[j] = efap->polyData.polysetArray[m].polyEle[j]; /* Q22 */ move32(); - efap->polyData.polysetArray[add( m, 2 )].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; + efap->polyData.polysetArray[m + 2].isNaN[j] = efap->polyData.polysetArray[m].isNaN[j]; move16(); - efap->polyData.polysetArray[add( m, 2 )].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m + 2].numChan = lengthTri2PolySorted[n]; move16(); } finalLength = add( finalLength, 2 ); @@ -928,7 +928,7 @@ static ivas_error sphere_triangulation_fx( *dmTranspose_fx = (Word32 **) p_dmTranspose; /* Remap Ghosts */ -remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); +remap_ghosts_fx( vtxData->vertexArray, polyData->triArray, numSpk, &vtxData->numVtx, polyData->numTri, *dmTranspose_fx ); // dmTranspose_fx q31 return IVAS_ERR_OK; } @@ -1161,9 +1161,11 @@ static void initial_polyeder_fx( } /* 1. attempt to create an edge with nonzero length */ - WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi, vtxData->vertexArray[tetrahedron[1]].azi ) && - EQ_32( vtxData->vertexArray[tetrahedron[0]].ele, vtxData->vertexArray[tetrahedron[1]].ele ) ) + test(); + WHILE( EQ_32( vtxData->vertexArray[tetrahedron[0]].azi /*q22*/, vtxData->vertexArray[tetrahedron[1]].azi /*q22*/ ) && + EQ_32( vtxData->vertexArray[tetrahedron[0]].ele /*q22*/, vtxData->vertexArray[tetrahedron[1]].ele /*q22*/ ) ) { + test(); tetrahedron[1] = add( tetrahedron[1], 1 ); move16(); assert( tetrahedron[1] < numVtx && "EFAP: convex hull construction failed, vertices are coincident!" ); @@ -1172,16 +1174,16 @@ static void initial_polyeder_fx( /* 2. attempt to create a triangle with nonzero area */ tmp = 0; move32(); - v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); + v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); // tmp1 Q(31-1) WHILE( LT_16( tetrahedron[2], numVtx ) ) { - v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); - efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 + v_sub_fixed( vtxData->vertexArray[tetrahedron[2]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp2, 3, 1 ); // tmp2 Q(31-1) + efap_crossp_fx( tmp1, tmp2, tmpCross ); // tmpCross Q29 FOR( i = 0; i < 3; i++ ) { tmp = L_add( tmp, Mpy_32_32( tmpCross[i], tmpCross[i] ) ); // tmp Q27 } - IF( GT_32( L_abs( tmp ), Mpy_32_32( POLY_THRESH_Q29, POLY_THRESH_Q29 ) ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ + IF( GT_32( L_abs( tmp ), ( POLY_THRESH_Q29 /*1e-4f Q29*/ * POLY_THRESH_Q29 /*1e-4f Q29*/ ) >> 31 ) ) /* compare tmp against POLY_THRESH^2 instead of sqrtf(tmp) */ { BREAK; } @@ -1197,7 +1199,7 @@ static void initial_polyeder_fx( { v_sub_fixed( vtxData->vertexArray[tetrahedron[3]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp3, 3, 1 ); // tmp3 Q30 tmp = dotp_fixed( tmp3, tmpCross, 3 ); // tmp Q28 - IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 ) ) + IF( GT_32( L_abs( tmp ), POLY_THRESH_Q28 /*1e-4f Q28*/ ) ) { BREAK; } @@ -1211,11 +1213,11 @@ static void initial_polyeder_fx( { vtxInHull[tetrahedron[i]] = 1; /* set vertex as added to hull*/ move16(); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[0], Q2 ) ); // Q29 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[1], Q2 ) ); // Q29 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[tetrahedron[i]].pos[2], Q2 ) ); // Q29 move32(); } /* Executed below float operation @@ -1460,33 +1462,34 @@ static void add_ghost_speakers_fx( Word32 tmpAngleDiff[EFAP_MAX_SIZE_TMP_BUFF]; /* tmp array of angles differences */ Word32 sectors[EFAP_MAX_SIZE_TMP_BUFF]; /* Help us determine the zone where we should extend LS */ EFAP_VTX_DMX_TYPE vtxDmxType; + Word16 new_diff_e; vtxDmxType = EFAP_DMX_INTENSITY; move32(); numVertex = *numVtx; move16(); - maxAngle = 13421773; - move32(); //(1.f / 160.0f) in Q31 + maxAngle = 13421773; //(1.f / 160.0f) in Q31 + move32(); /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; + ele[i] = vertexArray[i].ele; // q22 move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ a = 0; move16(); - maximum_l( ele, numVertex, &tmpEle ); + maximum_l( ele, numVertex, &tmpEle ); // tmpEle q22 lengthVertGhst = 0; move16(); - IF( LT_32( tmpEle, Q22_90_DEG ) ) + IF( LT_32( tmpEle, Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( GT_32( tmpEle, Q22_45_DEG ) ) + IF( GT_32( tmpEle, Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1497,18 +1500,18 @@ static void add_ghost_speakers_fx( move32(); } } - add_vertex_fx( vertexArray, 0, Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); } /* ADD VOH IF NECESSERAY (i.e. if the elevation of the lowest LS is > -90 deg) */ - minimum_l( ele, numVertex, &tmpEle ); - IF( GT_32( tmpEle, -Q22_90_DEG ) ) + minimum_l( ele, numVertex, &tmpEle ); /*tmpEle q22*/ + IF( GT_32( tmpEle, -Q22_90_DEG /*90 q22*/ ) ) { IF( efip_flag ) { - IF( LT_32( tmpEle, -Q22_45_DEG ) ) + IF( LT_32( tmpEle, -Q22_45_DEG /*45 q22*/ ) ) { vtxDmxType = EFAP_DMX_NONE; move32(); @@ -1520,7 +1523,7 @@ static void add_ghost_speakers_fx( } } - add_vertex_fx( vertexArray, 0, -Q22_90_DEG, add( numVertex, a ), vtxDmxType ); + add_vertex_fx( vertexArray, 0, -Q22_90_DEG /*90 q22*/, add( numVertex, a ), vtxDmxType ); lengthVertGhst = add( lengthVertGhst, 1 ); a = add( a, 1 ); @@ -1532,9 +1535,9 @@ static void add_ghost_speakers_fx( FOR( i = 0; i < numVertex; ++i ) { - IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG ) ) + IF( LT_32( L_abs( vertexArray[i].ele ), Q22_45_DEG /*45 q22*/ ) ) { - tmpAzi[k] = vertexArray[i].azi; + tmpAzi[k] = vertexArray[i].azi; // q22 move32(); k = add( k, 1 ); } @@ -1542,44 +1545,44 @@ static void add_ghost_speakers_fx( lengthHorGhst = 0; move16(); - IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ + IF( 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 ); + add_vertex_fx( vertexArray, Q22_120_DEG /*120 q22*/, 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG /*240 q22*/, 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 ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG /*120 q22*/ ), 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG /*240 q22*/ ), 0, add( add( numVertex, a ), 1 ), EFAP_DMX_INTENSITY ); a = add( a, 2 ); lengthHorGhst = add( lengthHorGhst, 2 ); } ELSE /* fill gaps greater than maxAngle */ { /* Here, k correspond to the number of LS whose ele is < 45 deg, should be = numVertex */ - sort_l( tmpAzi, k ); + sort_l( tmpAzi, k ); // tmpAzi q22 /* The next lines correspond to angle_diff = [azi(2:end), azi(1) + 360] - azi; in Matlab */ FOR( i = 0; i < k - 1; ++i ) { - tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); + tmpAngleDiff[i] = L_sub( tmpAzi[i + 1], tmpAzi[i] ); // q22 move32(); - sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); + sectors[i] = ceil_fixed( Mpy_32_32( tmpAngleDiff[i], maxAngle ), Q22 ); // q22 move32(); - IF( GT_32( sectors[i], Q22_1 ) ) + if ( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } } - tmpAngleDiff[sub( k, 1 )] = L_sub( L_add( tmpAzi[0], Q22_360_DEG ), tmpAzi[sub( k, 1 )] ); + tmpAngleDiff[k - 1] = L_sub( L_add( tmpAzi[0], Q22_360_DEG /*360 q22*/ ), tmpAzi[k - 1] ); // q22 - sectors[sub( k, 1 )] = ceil_fixed( Mpy_32_32( tmpAngleDiff[sub( k, 1 )], maxAngle ), Q22 ); + sectors[k - 1] = ceil_fixed( Mpy_32_32( tmpAngleDiff[k - 1], maxAngle ), Q22 ); // q22 - IF( GT_32( sectors[sub( k, 1 )], Q22_1 ) ) + if ( GT_32( sectors[k - 1], Q22_1 /*1 q22*/ ) ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1587,19 +1590,20 @@ static void add_ghost_speakers_fx( /* Adding new virtual speakers */ FOR( i = 0; i < k; ++i ) { - IF( GT_32( sectors[i], Q22_1 ) ) + IF( GT_32( sectors[i], Q22_1 /*1 q22*/ ) ) { - newDiff = tmpAngleDiff[i] / sectors[i]; - num_new = (Word16) L_shr( L_sub( sectors[i], Q22_1 ), Q22 ); + newDiff = BASOP_Util_Divide3232_Scale( tmpAngleDiff[i], sectors[i], &new_diff_e ); // Q=15-new_diff_e + newDiff = L_shl( newDiff, add( new_diff_e, 7 ) ); // q22 + num_new = extract_l( L_shr( L_sub( sectors[i], Q22_1 /*1 q22*/ ), Q22 ) ); // q0 FOR( j = 0; j < num_new; ++j ) { - newAzi = L_add( tmpAzi[i], L_shl( ( j + 1 ) * newDiff, Q22 ) ); + newAzi = L_add( tmpAzi[i], imult3216( newDiff, add( j, 1 ) ) ); // q22 add_vertex_fx( vertexArray, newAzi, 0, add( numVertex, a ), EFAP_DMX_INTENSITY ); a = add( a, 1 ); - IF( j > 0 ) + if ( j > 0 ) { lengthHorGhst = add( lengthHorGhst, 1 ); } @@ -1784,8 +1788,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; // -1e-6f in Q28 + move32(); Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; Word16 tmp16, tmp_e; @@ -1806,30 +1810,30 @@ static void add_vertex_to_convex_hull_fx( IF( vtxInHull[i] ) { numHullVtx = L_add( numHullVtx, 1 ); - centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); + centroid[0] = L_add( centroid[0], L_shr( vtxData->vertexArray[i].pos[0], Q4 ) ); // q27 move32(); - centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); + centroid[1] = L_add( centroid[1], L_shr( vtxData->vertexArray[i].pos[1], Q4 ) ); // q27 move32(); - centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); + centroid[2] = L_add( centroid[2], L_shr( vtxData->vertexArray[i].pos[2], Q4 ) ); // q27 move32(); } } /* numHullVtx = 1.0f / numHullVtx; */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); - tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, numHullVtx, &tmp_e ); // q15-tmp_e + tmp32 = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ - centroid[0] = Mpy_32_32( centroid[0], tmp32 ); + centroid[0] = Mpy_32_32( centroid[0], tmp32 ); // q27 move32(); - centroid[1] = Mpy_32_32( centroid[1], tmp32 ); + centroid[1] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[2] = Mpy_32_32( centroid[1], tmp32 ); + centroid[2] = Mpy_32_32( centroid[1], tmp32 ); // q27 move32(); - centroid[0] = L_shl( centroid[0], 4 ); + centroid[0] = L_shl( centroid[0], 4 ); // q31 move32(); - centroid[1] = L_shl( centroid[1], 4 ); + centroid[1] = L_shl( centroid[1], 4 ); // q31 move32(); - centroid[2] = L_shl( centroid[2], 4 ); + centroid[2] = L_shl( centroid[2], 4 ); // q31 move32(); /* Processing */ @@ -1920,13 +1924,13 @@ static void visible_edges_fx( /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; + tmpMax[i] = triArray[visible[i]].LS[0]; // q0 move16(); FOR( j = 1; j < 3; ++j ) { if ( LT_16( tmpMax[i], triArray[visible[i]].LS[j] ) ) { - tmpMax[i] = triArray[visible[i]].LS[j]; + tmpMax[i] = triArray[visible[i]].LS[j]; // q0 move16(); } } @@ -1977,7 +1981,7 @@ static void visible_edges_fx( { edges[k] = a; move16(); - edges[add( k, 1 )] = b; + edges[k + 1] = b; move16(); k = add( k, 2 ); } @@ -2117,7 +2121,7 @@ static void flip_plane( static void flip_plane_fx( const EFAP_VERTEX *vtxArray, /* i : Vertex array */ Word16 *surface, /* i/o: Surface/vertices to be flipped */ - const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward */ + const Word32 centroid[3] /* i : Centroid of convex hull from which to orient the planes outward q31*/ ) { Word16 tmp; @@ -2127,7 +2131,7 @@ static void flip_plane_fx( vtxArray[surface[0]].pos, vtxArray[surface[1]].pos, vtxArray[surface[2]].pos, - centroid ); + centroid ); // q31 IF( dist > 0 ) { @@ -2319,9 +2323,10 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; /* Q31 */ Word32 tmpDist; - const Word32 thresh = 214748; + Word16 tmpDist_e; + const Word32 thresh = 214748; // 1e-4f in Q31 Word16 tmp16, tmp_e; - move32(); // 1e-4f in Q31 + move32(); set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); @@ -2333,7 +2338,7 @@ static void remap_ghosts_fx( IF( find_int_in_tri_fx( triArray, g, numTri, posFound ) == 0 ) { remove_vertex_fx( vtxArray, g, numVtx ); - --numVtx; + numVtx = sub( numVtx, 1 ); FOR( i = 0; i < numTri; ++i ) { FOR( j = 0; j < 3; ++j ) @@ -2361,9 +2366,9 @@ static void remap_ghosts_fx( set32_fx( tmpMat[i], 0, numTot ); set32_fx( tmpNewMat[i], 0, numTot ); - tmpMat[i][i] = ONE_IN_Q31; + tmpMat[i][i] = ONE_IN_Q31; // q31 move32(); - tmpNewMat[i][i] = ONE_IN_Q31; + tmpNewMat[i][i] = ONE_IN_Q31; // q31 move32(); } @@ -2382,8 +2387,8 @@ static void remap_ghosts_fx( } /* The neighbours are set to 1.0/tmpL */ - tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); - inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( 1, tmpL, &tmp_e ); // Q=15-tmp_e + inv_tmpL = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ FOR( j = 0; j < tmpL; ++j ) { tmpMat[neighbours[j]][i] = inv_tmpL; /* Q31 */ @@ -2405,18 +2410,22 @@ static void remap_ghosts_fx( FOR( i = numSpk; i < numTot; ++i ) { - Copy32( tmpNewMat[i], tmpVec, numTot ); + Copy32( tmpNewMat[i], tmpVec, numTot ); // q31 - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); // Q=31-tmpDist_e - WHILE( GT_32( tmpDist, thresh ) ) + WHILE( EQ_16( BASOP_Util_Cmp_Mant32Exp( tmpDist, tmpDist_e, thresh, 0 ), 1 ) ) { - matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); - Copy32( tmpVec2, tmpVec, numTot ); + matrix_times_row_fx( tmpMat, tmpVec, numTot, tmpVec2 ); // tmpVec2 Q31 + Copy32( tmpVec2, tmpVec, numTot ); // Q31 set32_fx( tmpVec2, 0, numTot ); - tmpDist = sum_l( &tmpVec[numSpk], sub( numTot, numSpk ) ); + tmpDist_e = 0; + move16(); + tmpDist = sum_32_fx( &tmpVec[numSpk], sub( numTot, numSpk ), &tmpDist_e ); } - Copy32( tmpVec, tmpNewMat[i], numTot ); + Copy32( tmpVec, tmpNewMat[i], numTot ); // q31 } FOR( i = 0; i < numSpk; ++i ) @@ -2425,7 +2434,7 @@ static void remap_ghosts_fx( FOR( j = 0; j < numSpk; ++j ) { test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], 0x7fffffff /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2434,9 +2443,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*q31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } } @@ -2456,7 +2465,7 @@ static void remap_ghosts_fx( case EFAP_DMX_INTENSITY: default: test(); - IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 ) ) + IF( tmpNewMat[j][i] == 0 || EQ_32( tmpNewMat[j][i], ONE_IN_Q31 /*q31*/ ) ) { downmixMatrixTranspose[j][i] = tmpNewMat[j][i]; /* Q31 */ move32(); @@ -2465,9 +2474,9 @@ static void remap_ghosts_fx( { Word16 exp = 0; move16(); - Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); - tmp_sqrt = L_shl( tmp_sqrt, exp ); - downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ + Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); /*31-exp*/ + tmp_sqrt = L_shl( tmp_sqrt, exp ); /*31*/ + downmixMatrixTranspose[j][i] = tmp_sqrt; /* Q31 */ move32(); } BREAK; @@ -2515,8 +2524,8 @@ static void vertex_init( *-------------------------------------------------------------------------*/ static void vertex_init_fx( - const Word32 *aziSpk, /* i : Azimuths of the LS setup */ - const Word32 *eleSpk, /* i : Elevations of the LS setup */ + const Word32 *aziSpk, /* i : Azimuths of the LS setup q22 */ + const Word32 *eleSpk, /* i : Elevations of the LS setup q22 */ EFAP_VERTEX_DATA *efapVtxData /* i/o: Vertex data structure that will be updated */ ) { @@ -2606,10 +2615,10 @@ static void efap_panning( *-------------------------------------------------------------------------*/ static void efap_panning_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ const EFAP_POLYSET_DATA *polyData, /* i : Polygon data */ - Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *bufferL /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i; @@ -2622,9 +2631,9 @@ static void efap_panning_fx( Word32 normTmpBuff; Word32 P[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); @@ -2644,32 +2653,32 @@ static void efap_panning_fx( { chan[i] = polyData->polysetArray[polyIdx].chan[i]; move16(); - aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; + aziPoly[i] = polyData->polysetArray[polyIdx].polyAzi[i]; // q22 move32(); if ( EQ_16( polyData->polysetArray[polyIdx].isNaN[i], 1 ) ) { - aziPoly[i] = P[0]; + aziPoly[i] = P[0]; // q22 move32(); } - elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; + elePoly[i] = polyData->polysetArray[polyIdx].polyEle[i]; // q22 move32(); } /* Computing the gain for the polygon */ - get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); + get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); + normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 Word16 exp = 0; move16(); - normTmpBuff = ISqrt32( normTmpBuff, &exp ); + normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp /* Updating the buffer structure */ FOR( i = 0; i < numChan; ++i ) { - bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); + bufferL[chan[i]] = Mpy_32_32( tmpBuff[i], normTmpBuff ); // 31+(31-exp)-31=>31-exp move32(); bufferL[chan[i]] = L_shl( bufferL[chan[i]], exp ); // Q31 move32(); @@ -2742,12 +2751,12 @@ static void get_poly_gains( *-------------------------------------------------------------------------*/ static void get_poly_gains_fx( - const Word32 azi, /* i : Value of the azimuth */ - const Word32 ele, /* i : Value of the elevation */ - const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons */ - const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons */ + const Word32 azi, /* i : Value of the azimuth q22 */ + const Word32 ele, /* i : Value of the elevation q22 */ + const Word32 aziPoly[EFAP_MAX_CHAN_NUM], /* i : Azimuths of the considered polygons q22 */ + const Word32 elePoly[EFAP_MAX_CHAN_NUM], /* i : Elevations of the considered polygons q22 */ const Word16 numChan, /* i : Length of aziPoly & elePoly */ - Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values */ + Word32 *buffer /* o : 1D array of length numSpk that will contain the tmp values q31*/ ) { Word16 i, j; @@ -2756,39 +2765,39 @@ static void get_poly_gains_fx( Word32 A[2], B[2], C[2]; Word32 P_minus_A[2]; - P[0] = azi; + P[0] = azi; // q22 move32(); - P[1] = ele; + P[1] = ele; // q22 move32(); /* Processing, we search for the triangle in which belong P, then we compute the gain */ FOR( i = 1; i < numChan + 1; ++i ) { - A[0] = aziPoly[i - 1]; + A[0] = aziPoly[i - 1]; // q22 move32(); - A[1] = elePoly[i - 1]; + A[1] = elePoly[i - 1]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( j = i; j < numChan - 2 + i; ++j ) { idx1 = add( 1, ( j % numChan ) ); idx2 = add( 1, ( idx1 % numChan ) ); - B[0] = aziPoly[sub( idx1, 1 )]; + B[0] = aziPoly[idx1 - 1]; // q22 move32(); - B[1] = elePoly[sub( idx1, 1 )]; + B[1] = elePoly[idx1 - 1]; // q22 move32(); - C[0] = aziPoly[sub( idx2, 1 )]; + C[0] = aziPoly[idx2 - 1]; // q22 move32(); - C[1] = elePoly[sub( idx2, 1 )]; + C[1] = elePoly[idx2 - 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) { - buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q12 ); + buffer[i - 1] = L_shl_sat( get_tri_gain_fx( A, B, C, P_minus_A ), Q18 ); // q13+q18->q31 move32(); BREAK; } @@ -2847,10 +2856,10 @@ static float get_tri_gain( *-------------------------------------------------------------------------*/ static Word32 get_tri_gain_fx( - const Word32 A[2], /* i : Coordinate of one apex of the triangle */ - const Word32 B[2], /* i : Coordinate of one apex of the triangle */ - const Word32 C[2], /* i : Coordinate of one apex of the triangle */ - const Word32 P_minus_A[2] /* i : Value of (P - A) */ + const Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + const Word32 P_minus_A[2] /* i : Value of (P - A) q22 */ ) { Word32 N[2], tmpN[2]; @@ -2859,32 +2868,38 @@ static Word32 get_tri_gain_fx( Word32 gain; /* Processing */ - tmpN[0] = L_sub( B[1], C[1] ); + tmpN[0] = L_sub( B[1], C[1] ); // q22 move32(); - tmpN[1] = L_sub( C[0], B[0] ); + tmpN[1] = L_sub( C[0], B[0] ); // q22 move32(); - v_sub_fixed( B, A, tmpSub1, 2, 0 ); + v_sub_fixed( B, A, tmpSub1, 2, 0 ); // tmpSub1 q22 tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; + Word16 exp = Q18; move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, 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, add( Q16, exp ) ), N, 2 ); + Word16 inv_tmpDot1 = Inv16( extract_h( inv_tmpDot2 ), &exp ); // 15-exp + v_multc_fixed( tmpN, L_shl( inv_tmpDot1, add( Q16, exp ) ), N, 2 ); // 22+31-31->22 - tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // Q18 + tmpDot2 = dotp_fixed( P_minus_A, N, 2 ); // 22+22-31->13 - gain = L_sub( 0x00040000, tmpDot2 ); + if ( EQ_32( tmpDot2, 8191 ) ) + { + tmpDot2 = 8192; // Q13 + move32(); + } + + gain = L_sub( 8192, tmpDot2 ); // Q13 /* Set gains <= -60dB to 0 to avoid problems in SVD */ - if ( LT_32( L_abs( gain ), 1 ) ) + if ( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_abs( gain ), 18, 2147 /*1e-6 q31*/, 0 ), -1 ) ) { gain = 0; move32(); } - return gain; // Q18 + return gain; // Q13 } #endif @@ -2964,32 +2979,39 @@ static void add_vertex_fx( /* Updating the vertex array */ - tmp = efap_32mod32( L_sub( Q22_180_DEG, azi ), Q22_360_DEG ); - vtxArray[pos].azi = L_sub( Q22_180_DEG, tmp ); + tmp = efap_32mod32( L_sub( Q22_180_DEG /*180 q22*/, azi ), Q22_360_DEG /*360 q22*/ ); // q22 + vtxArray[pos].azi = L_sub( Q22_180_DEG /*180 q22*/, tmp ); // q22 move32(); - tmp = ( LT_32( Q22_180_DEG, ele ) ? Q22_180_DEG : ele ); + IF( LT_32( Q22_180_DEG /*180 q22*/, ele ) ) + tmp = Q22_180_DEG /*180 q22*/; + ELSE + tmp = ele; // Q22 move32(); - vtxArray[pos].ele = ( GT_32( -Q22_180_DEG, tmp ) ? -Q22_180_DEG : tmp ); + IF( GT_32( -Q22_180_DEG /*180 q22*/, tmp ) ) + vtxArray[pos].ele = -Q22_180_DEG /*180 q22*/; + ELSE + vtxArray[pos] + .ele = tmp; // q22 move32(); /* Converting spherical coordinates to cartesians, assuming radius = 1 */ - sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); + sph2cart_fx( vtxArray[pos].azi, vtxArray[pos].ele, &vtxArray[pos].pos[0] ); // vtxArray[pos].pos[0] q31 /* Computing the index defined by idx = idxAziTmp + 181 * idxEleTmp */ /* IdxAziTmp */ - tmp = L_abs( L_sub( Q22_90_DEG, L_abs( vtxArray[pos].azi ) ) ); // Q22 - idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); + tmp = L_abs( L_sub( Q22_90_DEG /*90 q22*/, L_abs( vtxArray[pos].azi ) ) ); // Q22 + idxAziTmp = L_shr( anint_fixed( tmp, Q22 ), Q22 ); // q22-q22->q0 /* IdxEleTmp */ - tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; + tmp = L_abs( vtxArray[pos].ele ); // q22 + idxEleTmp = tmp; // q22 move16(); - idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); + idxEleTmp = L_sub( Q22_90_DEG /*90 q22*/, idxEleTmp ); // q22 /* Final Idx */ - vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); + vtxArray[pos].idx = add( extract_l( idxAziTmp ), i_mult( 181, extract_l( L_shr( idxEleTmp, Q22 ) ) ) ); // q0 /* Setting the nan flag to 0 */ vtxArray[pos].isNaN = 0; @@ -3033,8 +3055,10 @@ static void efap_sort_s_fx( move16(); tempi = idx[i]; move16(); + test(); FOR( j = i + 1; ( j < len ) && ( tempr > x[j] ); j++ ) { + test(); x[j - 1] = x[j]; move16(); idx[j - 1] = idx[j]; @@ -3122,18 +3146,18 @@ static Word32 vertex_distance_fx( /* Assigning the coordinates to the vector */ FOR( i = 0; i < 3; ++i ) { - A[i] = vtxArray[tri.LS[0]].pos[i]; + A[i] = vtxArray[tri.LS[0]].pos[i]; // q31 move32(); - B[i] = vtxArray[tri.LS[1]].pos[i]; + B[i] = vtxArray[tri.LS[1]].pos[i]; // q31 move32(); - C[i] = vtxArray[tri.LS[2]].pos[i]; + C[i] = vtxArray[tri.LS[2]].pos[i]; // q31 move32(); - P[i] = vtxArray[vtxIdx].pos[i]; + P[i] = vtxArray[vtxIdx].pos[i]; // q31 move32(); } - return point_plane_distance_fx( A, B, C, P ); + return point_plane_distance_fx( A, B, C, P ); // q28 } #endif @@ -3166,16 +3190,16 @@ static float point_poly_distance( static Word32 point_poly_distance_fx( const EFAP_POLYSET poly, /* i : The polygon which forms a plane */ - const Word32 X[3] /* i : Cartesian coordinates of the point of interest */ + const Word32 X[3] /* i : Cartesian coordinates of the point of interest q31*/ ) { Word32 P1[3], P2[3], P3[3]; - sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); - sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); - sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); + sph2cart_fx( poly.polyAzi[0], poly.polyEle[0], &P1[0] ); // P1[0] q31 + sph2cart_fx( poly.polyAzi[1], poly.polyEle[1], &P2[0] ); // P2[0] q31 + sph2cart_fx( poly.polyAzi[2], poly.polyEle[2], &P3[0] ); // P3[0] q31 - return point_plane_distance_fx( P1, P2, P3, X ); + return point_plane_distance_fx( P1, P2, P3, X ); // q28 } #endif @@ -3232,10 +3256,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 q31*/ + const Word32 P2[3], /* i : Second point of the triangle q31*/ + const Word32 P3[3], /* i : Third point of the triangle q31*/ + const Word32 X[3] /* i : The point of interest q31*/ ) { Word32 tmpCross1[3], tmpCross2[3]; @@ -3261,8 +3285,8 @@ static Word32 point_plane_distance_fx( // returns output in Q28 } /* Cross Product */ - v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); - v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); + v_sub_fixed( P1, P2, tmpCross1, 3, 1 ); // tmpCross1 q30 + v_sub_fixed( P1, P3, tmpCross2, 3, 1 ); // tmpCross2 q30 /* resultCross = cross(P1-P2,P1-P3) */ efap_crossp_fx( tmpCross1, tmpCross2, resultCross ); // Q29 @@ -3616,10 +3640,10 @@ static void matrix_times_row( *-------------------------------------------------------------------------*/ static void matrix_times_row_fx( - Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix */ - const Word32 *vec, /* i : The input row vector */ + Word32 mat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF], /* i : The input matrix q31 */ + const Word32 *vec, /* i : The input row vector q31*/ const Word16 L, /* i : Row length */ - Word32 *out /* o : Output vector */ + Word32 *out /* o : Output vector q31 */ ) { Word16 i, j; @@ -3628,7 +3652,7 @@ static void matrix_times_row_fx( { FOR( j = 0; j < L; ++j ) { - out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); + out[i] = L_add( out[i], Mpy_32_32( mat[i][j], vec[j] ) ); /*31+31-31=>31*/ move32(); } } @@ -3684,7 +3708,7 @@ static void tri_to_poly_fx( vtxArray[triArray[i].LS[2]].pos, vtxArray[j].pos ) ); // Q28 - IF( LT_32( dist, 268435 ) /* 1e-3f in Q28 */ ) + IF( LT_32( dist, 268435 /* 1e-3f in Q28 */ ) ) { assert( lenPoly < EFAP_MAX_CHAN_NUM && "EFAP: exceeded max polygon vertices!" ); poly[lenPoly] = j; @@ -4068,7 +4092,7 @@ static void sort_channels_vertex_fx( v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 Word16 exp1 = 2; move16(); - normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); + normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ) /*q29*/, &exp1 ); /*q=31-exp1*/ // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -4078,21 +4102,21 @@ static void sort_channels_vertex_fx( FOR( i = 0; i < 3; i++ ) { - tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); + tmpV2[i] = L_shl( tmpV2[i], add( Q2, shl( exp1, 1 ) ) ); // q30 move32(); } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 Word16 exp2 = 2; move16(); - normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); + normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ) /*q29*/, &exp2 ); // q=31-exp2 v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 /* Center of the first Triangle */ FOR( i = 0; i < 3; ++i ) { - MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); + MC[i] = L_shl( Mpy_32_32( L_add( L_add( L_shr( P1[i], Q2 ), L_shr( P2[i], Q2 ) ), L_shr( P3[i], Q2 ) ), 715827883 /* 1 / 3 in Q31 */ ), Q2 ); // q29+2=>q31 move32(); } @@ -4101,7 +4125,7 @@ static void sort_channels_vertex_fx( { FOR( j = 0; j < 3; ++j ) { - tmpP[j] = vtxArray[channels[i]].pos[j]; + tmpP[j] = vtxArray[channels[i]].pos[j]; // q31 move32(); } @@ -4156,19 +4180,19 @@ static float efap_fmodf( *-------------------------------------------------------------------------*/ static Word32 efap_32mod32( - const Word32 x, /* i : Dividend */ - const Word32 y /* i : Divisor */ + const Word32 x, /* i : Dividend q22*/ + const Word32 y /* i : Divisor q22 */ ) { - Word32 result = x % y; + Word32 result = x % y; // q22 move32(); IF( result >= 0 ) { - return result; + return result; // q22 } ELSE { - return L_add( result, y ); + return L_add( result, y ); // q22 } } #endif @@ -4238,7 +4262,7 @@ static int16_t get_poly_num( } #else static Word16 get_poly_num_fx( - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET_DATA *polyData /* i : Polyset struct */ ) { @@ -4253,7 +4277,7 @@ static Word16 get_poly_num_fx( num_poly = 0; move16(); - sph2cart_fx( P[0], P[1], &pos[0] ); + sph2cart_fx( P[0], P[1], &pos[0] ); // pos[0] q31 /* Filter the polygon list with a fast 2d check */ FOR( i = 0; i < polyData->numPoly; ++i ) @@ -4261,7 +4285,7 @@ static Word16 get_poly_num_fx( IF( in_poly_fx( P, polyData->polysetArray[i] ) ) { /* select only polygons which are visible from the point */ - dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); + dist_tmp = point_poly_distance_fx( polyData->polysetArray[i], pos ); // q28 IF( dist_tmp == 0 ) { return i; @@ -4270,7 +4294,7 @@ static Word16 get_poly_num_fx( { poly_tmp[num_poly] = i; move16(); - poly_dist[num_poly] = dist_tmp; + poly_dist[num_poly] = dist_tmp; // q28 move32(); num_poly = add( num_poly, 1 ); } @@ -4284,7 +4308,7 @@ static Word16 get_poly_num_fx( /* select the polygon with the smallest distance */ found_poly = poly_tmp[0]; move16(); - dist_tmp = poly_dist[0]; + dist_tmp = poly_dist[0]; // q28 move32(); FOR( i = 1; i < num_poly; i++ ) { @@ -4292,7 +4316,7 @@ static Word16 get_poly_num_fx( { found_poly = poly_tmp[i]; move16(); - dist_tmp = poly_dist[i]; + dist_tmp = poly_dist[i]; // q28 move32(); } } @@ -4374,7 +4398,7 @@ static int16_t in_poly( } #else static Word16 in_poly_fx( /* Angles are in Q22 */ - const Word32 P[2], /* i : Azimuth and elevation of the point */ + const Word32 P[2], /* i : Azimuth and elevation of the point q22*/ const EFAP_POLYSET poly /* i : Polyset struct */ ) { @@ -4397,45 +4421,45 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; + A[0] = P[0]; // q22 move32(); } ELSE { - A[0] = poly.polyAzi[0]; + A[0] = poly.polyAzi[0]; // q22 move32(); } - A[1] = poly.polyEle[0]; + A[1] = poly.polyEle[0]; // q22 move32(); - v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) */ + v_sub_fixed( P, A, P_minus_A, 2, 0 ); /* Precalculate value of (P-A) q22*/ FOR( n = 1; n < sub( numVertices, 1 ); ++n ) { IF( poly.isNaN[n] ) { - B[0] = P[0]; + B[0] = P[0]; // q22 move32(); } ELSE { - B[0] = poly.polyAzi[n]; + B[0] = poly.polyAzi[n]; // q22 move32(); } - B[1] = poly.polyEle[n]; + B[1] = poly.polyEle[n]; // q22 move32(); IF( poly.isNaN[n + 1] ) { - C[0] = P[0]; + C[0] = P[0]; // q22 move32(); } ELSE { - C[0] = poly.polyAzi[n + 1]; + C[0] = poly.polyAzi[n + 1]; // q22 move32(); } - C[1] = poly.polyEle[n + 1]; + C[1] = poly.polyEle[n + 1]; // q22 move32(); IF( in_tri_fx( A, B, C, P_minus_A ) ) @@ -4509,10 +4533,10 @@ static int16_t in_tri( } #else static Word16 in_tri_fx( - Word32 A[2], /* i : Coordinate of one apex of the triangle */ - Word32 B[2], /* i : Coordinate of one apex of the triangle */ - Word32 C[2], /* i : Coordinate of one apex of the triangle */ - Word32 P_minus_A[2] /* i : Value of (P - A) */ + Word32 A[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 B[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 C[2], /* i : Coordinate of one apex of the triangle q22*/ + Word32 P_minus_A[2] /* i : Value of (P - A) q22*/ ) { Word32 tmpDot1[2], tmpDot2[2]; @@ -4521,7 +4545,7 @@ static Word16 in_tri_fx( Word16 tmp16, tmp_e; Word64 S[2]; /* Threshold adjusted */ - Word64 thresh_int = 21475; // 1e-6f in Q32 + Word64 thresh_int = 4295; // 1e-6f in Q32 move64(); /* @@ -4531,11 +4555,11 @@ static Word16 in_tri_fx( I'll just compute the determinant and if it's equal to 0, that means the two vectors are colinear */ - v_sub_fixed( B, A, tmpDot1, 2, 0 ); - v_sub_fixed( C, A, tmpDot2, 2, 0 ); + v_sub_fixed( B, A, tmpDot1, 2, 0 ); // tmpDot1 q22 + v_sub_fixed( C, A, tmpDot2, 2, 0 ); // tmpDot 2q22 /* Verification of the non-colinearity : Q22 * Q22 = Q13 */ - invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); + invFactor = L_sub( Mpy_32_32( tmpDot1[0], tmpDot2[1] ), Mpy_32_32( tmpDot1[1], tmpDot2[0] ) ); /*q22+q22-q31->q13*/ IF( invFactor == 0 ) { @@ -4543,20 +4567,20 @@ static Word16 in_tri_fx( } /* invFactor = 1.f / invFactor; */ - tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); - invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ + tmp16 = BASOP_Util_Divide3232_Scale( ONE_IN_Q13, invFactor, &tmp_e ); /*15-tmp_e*/ + invFactor = L_shl_sat( tmp16, add( Q16, tmp_e ) ); /* Q31 */ Word16 invFactor_exp = norm_l( invFactor ); - invFactor = L_shl( invFactor, invFactor_exp ); + invFactor = L_shl( invFactor, invFactor_exp ); // 31+invFactor_exp // Q22 = Q22 * Q31 - matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); + matInv[0][0] = Mpy_32_32( tmpDot2[1], invFactor ); // q=22+invFactor_exp move32(); - matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); + matInv[0][1] = Mpy_32_32( L_negate( tmpDot2[0] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); + matInv[1][0] = Mpy_32_32( L_negate( tmpDot1[1] ), invFactor ); // q=22+invFactor_exp move32(); - matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); + matInv[1][1] = Mpy_32_32( tmpDot1[0], invFactor ); // q=22+invFactor_exp move32(); /* Computing S (Q13 + matInv_exp_final[i] + P_minus_A_exp_final + invFactor_exp - 1 ) = @@ -4588,35 +4612,37 @@ static Word16 in_tri_fx( P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[0]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); S[1] = L_add( L_shr( Mpy_32_32( L_shl( matInv[1][0], matInv_exp_final[1] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), - L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); + L_shr( Mpy_32_32( L_shl( matInv[1][1], matInv_exp_final[1] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); //(22+invFactor_exp+matInv_exp_final[1]+22+P_minus_A_exp_final-1)-31=>12+invFactor_exp+matInv_exp_final[0]+P_minus_A_exp_final move64(); /* Checking if we are in the triangle; For the theory, check Christian Borss article, section 3.2 */ // Q32 S IF( sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[0] = W_shr( S[0], sub( add( add( matInv_exp_final[0], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[0] = W_shl( S[0], sub( sub( sub( Q20, matInv_exp_final[0] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } IF( sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) < 0 ) { - S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); + S[1] = W_shr( S[1], sub( add( add( matInv_exp_final[1], P_minus_A_exp_final ), invFactor_exp ), Q20 ) ); // q32 move64(); } ELSE { - S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); + S[1] = W_shl( S[1], sub( sub( sub( Q20, matInv_exp_final[1] ), P_minus_A_exp_final ), invFactor_exp ) ); // q32 move64(); } + test(); + test(); IF( LT_64( S[0], -thresh_int ) || LT_64( S[1], -thresh_int ) || GT_64( W_add( S[0], S[1] ), W_add( W_shl( 1, 32 ), thresh_int ) ) ) { return 0; -- GitLab From 27a86009296d3afa75575bb1779f09da01d316cb Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 12:10:21 +0530 Subject: [PATCH 18/39] Fix for 3GPP issue 950: High MLD for ParamMC 5.1 at 48/64/80kbps or 7.1+4 at 128kbps --- lib_dec/ivas_jbm_dec.c | 11 ++++++----- lib_dec/ivas_mc_param_dec.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index dcbd10839..106affd08 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3302,24 +3302,25 @@ ivas_error ivas_jbm_dec_render_fx( move16(); } } - Word16 tempp; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) + tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len ); + scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); move16(); IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ) ); - scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], imult1616( nchan_transport, nchan_out_cov ), tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) + tempp = getScaleFactor32( 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_len ); + scale_sig32( 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_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp)) st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp ); move16(); } } + ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); + FOR( int ch = 0; ch < nchan_out_cldfb; ch++ ) { IF( st_ivas->cldfbSynDec[ch] ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index abf30acad..b9e9137a1 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -5392,6 +5392,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( 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( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); #ifdef MSAN_FIX set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); #endif @@ -5608,6 +5609,22 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* 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 ); + IF( NE_16( mixing_matrix_res_local_e, mixing_matrix_local_e ) ) + { + tmp = getScaleFactor32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, tmp ); + mixing_matrix_local_e = sub( mixing_matrix_local_e, tmp ); + + tmp = getScaleFactor32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, tmp ); + mixing_matrix_res_local_e = sub( mixing_matrix_res_local_e, tmp ); + + scale_sig32( mixing_matrix_local_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS, sub( mixing_matrix_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + scale_sig32( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS, sub( mixing_matrix_res_local_e, s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ) ) ); + + mixing_matrix_res_local_e = mixing_matrix_local_e = s_max( mixing_matrix_local_e, mixing_matrix_res_local_e ); + move16(); + } IF( remove_lfe ) { set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); -- GitLab From 0fe7c6b52e345d3e40175049458ad8951d684abd Mon Sep 17 00:00:00 2001 From: Archit Tamarapu Date: Fri, 25 Oct 2024 11:04:09 +0200 Subject: [PATCH 19/39] [fix] change loop variables to Word32 --- lib_dec/lib_dec_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 05fd52bfb..9d1fb571c 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1090,7 +1090,7 @@ ivas_error IVAS_DEC_GetSamples( Word16 tmp_apaExecBuffer[APA_BUF]; IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0 } @@ -1098,14 +1098,14 @@ ivas_error IVAS_DEC_GetSamples( { return IVAS_ERR_UNKNOWN; } - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11 } } ELSE { - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q12 ) ); // Q(-1) } @@ -1114,7 +1114,7 @@ ivas_error IVAS_DEC_GetSamples( return IVAS_ERR_UNKNOWN; } - FOR( Word16 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) { hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q12 ); // Q11 } -- GitLab From 0c144928ad68fbddb66af131c37879eb46a02b85 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 25 Oct 2024 16:06:09 +0530 Subject: [PATCH 20/39] Fix for 3GPP issue 957: Assertion error in BWE of SCE decoding in OMASA [x] Adding saturation as suggested by PC group --- lib_com/swb_bwe_com_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 0025812db..d56f1b784 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -3005,7 +3005,8 @@ void hq_generic_decoding_fx( { 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 */ + /* Adding saturation suggested as fix for issue #957 */ + L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ *pit1_fx-- = L_tmp1; move32(); } -- GitLab From 7a52e2c2e6598e545a28b0538f1af040a72a6a65 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 08:33:15 +0530 Subject: [PATCH 21/39] Encoder code cleanup, Q-info doc for decoder and renderer --- lib_dec/jbm_jb4_circularbuffer.c | 4 +- lib_dec/jbm_jb4_inputbuffer.c | 13 +- lib_dec/jbm_jb4sb.c | 53 +- lib_dec/jbm_pcmdsp_apa.c | 175 ++-- lib_dec/jbm_pcmdsp_apa.h | 8 +- lib_dec/jbm_pcmdsp_similarityestimation.c | 30 +- lib_dec/jbm_pcmdsp_similarityestimation.h | 17 +- lib_dec/jbm_pcmdsp_window.c | 4 +- lib_enc/analy_sp_fx.c | 2 + lib_enc/ivas_cpe_enc.c | 6 +- lib_enc/ivas_front_vad.c | 4 +- lib_enc/nois_est_fx.c | 3 +- lib_enc/vad_fx.c | 4 +- lib_rend/ivas_dirac_rend.c | 1054 +++++++++++---------- lib_rend/ivas_prot_rend.h | 106 +-- 15 files changed, 769 insertions(+), 714 deletions(-) diff --git a/lib_dec/jbm_jb4_circularbuffer.c b/lib_dec/jbm_jb4_circularbuffer.c index bf3cbb71b..6bff530be 100644 --- a/lib_dec/jbm_jb4_circularbuffer.c +++ b/lib_dec/jbm_jb4_circularbuffer.c @@ -207,7 +207,7 @@ JB4_CIRCULARBUFFER_ELEMENT JB4_CIRCULARBUFFER_Back( { JB4_CIRCULARBUFFER_ELEMENT ret; - IF( NE_32( h->writePos, 0U ) ) + IF( h->writePos != 0U ) { ret = h->data[h->writePos - 1]; move32(); @@ -408,7 +408,7 @@ void JB4_CIRCULARBUFFER_MinAndPercentile( /* init output variables */ minEle = h->data[h->readPos]; - + move32(); /* To calculate the percentile, a number of elements with the highest values are collected in maxElements in * ascending sorted order. This array has a size of nElementsToIgnore plus one. This additional element is the * lowest of all maxElements, and is called the percentile of all elements. */ diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index 25d02da35..f876c11c0 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -139,7 +139,6 @@ ivas_error JB4_INPUTBUFFER_Init( h->readPos = 0; move16(); h->compareFunction = compareFunction; - move16(); return IVAS_ERR_OK; } @@ -213,8 +212,8 @@ Word16 JB4_INPUTBUFFER_Enque( { IF( replace != 0 ) { - *replacedElement = h->data[L_add( h->readPos, middle ) % h->capacity]; - h->data[L_add( h->readPos, middle ) % h->capacity] = element; + *replacedElement = h->data[( h->readPos + middle ) % h->capacity]; + h->data[( h->readPos + middle ) % h->capacity] = element; return 0; } return 1; @@ -235,7 +234,7 @@ Word16 JB4_INPUTBUFFER_Enque( canMoveRight = (UWord16) LT_32( insertPos, h->writePos ); canMoveLeft = (UWord16) GT_32( insertPos, h->writePos ); } - + test(); assert( canMoveRight != 0 || canMoveLeft != 0 ); IF( canMoveRight ) @@ -260,7 +259,7 @@ Word16 JB4_INPUTBUFFER_Enque( /* move lower elements to the left and insert before insertPos */ FOR( j = 0; j < low; j++ ) { - h->data[L_add( L_sub( h->readPos, 1 ), j )] = h->data[L_add( h->readPos, j )]; + h->data[( h->readPos - 1 ) + j] = h->data[h->readPos + j]; } h->data[insertPos - 1] = element; @@ -337,12 +336,12 @@ JB4_INPUTBUFFER_ELEMENT JB4_INPUTBUFFER_Element( /* return h->data[(h->readPos + index) % h->capacity] without error handling */ IF( LT_32( L_add( h->readPos, index ), h->capacity ) ) { - ret = h->data[L_add( h->readPos, index )]; + ret = h->data[( h->readPos + index )]; } ELSE { /* wrap around */ - ret = h->data[L_sub( L_add( h->readPos, index ), h->capacity )]; + ret = h->data[( ( h->readPos + index ) - h->capacity )]; } return ret; diff --git a/lib_dec/jbm_jb4sb.c b/lib_dec/jbm_jb4sb.c index 44d6abe4b..36fef8f00 100644 --- a/lib_dec/jbm_jb4sb.c +++ b/lib_dec/jbm_jb4sb.c @@ -183,7 +183,7 @@ struct JB4 UWord32 FecOffWin[10]; UWord32 optimum_offset; - Word32 netLossRate_fx; + Word32 netLossRate_fx; // Q15 Word32 nPartialCopiesUsed; Word32 last_nLost; Word32 last_ntot; @@ -479,22 +479,22 @@ Word16 JB4_PushDataUnit( { IF( dataUnit->partialCopyOffset == 0 ) { - if ( h->rfOffset2Active > 0 ) + IF( h->rfOffset2Active > 0 ) { h->rfOffset2Active = sub( h->rfOffset2Active, 1 ); move16(); } - if ( h->rfOffset3Active > 0 ) + IF( h->rfOffset3Active > 0 ) { h->rfOffset3Active = sub( h->rfOffset3Active, 1 ); move16(); } - if ( h->rfOffset5Active > 0 ) + IF( h->rfOffset5Active > 0 ) { h->rfOffset5Active = sub( h->rfOffset5Active, 1 ); move16(); } - if ( h->rfOffset7Active > 0 ) + IF( h->rfOffset7Active > 0 ) { h->rfOffset7Active = sub( h->rfOffset7Active, 1 ); move16(); @@ -641,13 +641,13 @@ Word16 JB4_getFECoffset( Word16 JB4_FECoffset( JB4_HANDLE h ) { - IF( LT_32( h->netLossRate_fx, 1634 ) ) + IF( LT_32( h->netLossRate_fx, 1634 /*.05f in Q15*/ ) ) { - return (Word16) 0; + return 0; } ELSE { - return (Word16) 1; + return 1; } } @@ -663,7 +663,7 @@ Word16 JB4_PopDataUnit( Word16 ret; assert( sysTime >= h->prevPopSysTime ); - if ( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) ) + IF( GT_64( sysTime, W_add( h->prevPopSysTime, 20 ) ) ) { h->lastPlayoutOffset = L_add( h->lastPlayoutOffset, 20 ); move32(); @@ -780,6 +780,7 @@ static Word16 JB4_adaptPlayout( bool stretchTime; /* reset scale */ + test(); IF( scale == NULL || maxScaling == NULL ) { return -1; @@ -901,13 +902,9 @@ static void JB4_adaptActivePlayout( { IF( convertToLateLoss ) { -#ifndef IVAS_FLOAT_FIXED - JB4_dropFromBuffer( h ); -#else JB4_dropFromBuffer( h ); h->nLostOrStretched = L_add( h->nLostOrStretched, 1 ); move32(); -#endif } ELSE IF( dropEarly ) { @@ -924,8 +921,8 @@ static void JB4_adaptActivePlayout( Word32 temp = BASOP_Util_Divide3232_Scale_cadence( W_extract_l( W_sub( dropRateMax, dropRateMin ) ), W_extract_l( dropGapMax ), &exp ); /* limit gap to [gapMin,gapMax] and calculate current drop rate from gap */ Word64 temp2 = W_mult0_32_32( W_extract_l( JB4_MIN( gap, dropGapMax ) ), temp ); - Word64 temp3 = W_shr( temp2, 31 - exp ); - Word64 diff = W_sub( W_shl( temp3 + 1, 31 - exp ), temp2 ); + Word64 temp3 = W_shr( temp2, sub( 31, exp ) ); + Word64 diff = W_sub( W_shl( W_add( temp3, 1 ), sub( 31, exp ) ), temp2 ); if ( LE_64( diff, 21 ) ) { temp3 = W_add( temp3, 1 ); @@ -1124,7 +1121,7 @@ static Word16 JB4_inspectBufferForDropping( { Word16 temp, exp; temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstTs ), (Word32) ( h->frameDuration ), &exp ); - seqNrDiff = L_shl( temp, sub( exp, 15 ) ); + seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0 } ELSE { @@ -1219,7 +1216,7 @@ static Word16 JB4_checkDtxDropping( Word16 temp, exp; temp = BASOP_Util_Divide3232_Scale( JB4_rtpTimeStampDiff( h->nextExpectedTs, firstDu->timeStamp ), (Word32) ( h->frameDuration ), &exp ); - seqNrDiff = L_shl( temp, exp - 15 ); + seqNrDiff = L_shl( temp, sub( exp, 15 ) ); // Q0 if ( seqNrDiff <= 0 ) { /* no not drop first active frame */ @@ -1270,7 +1267,7 @@ static void JB4_estimateShortTermJitter( { duration = (UWord32) W_sub( maxTime, minTime ); maxDuration = (UWord32) W_shl( h->timeScale, 2 ); - WHILE( GT_64( duration, maxDuration ) ) + WHILE( duration > maxDuration ) { JB4_CIRCULARBUFFER_Deque( h->stJitterFifo, &dequedElement ); JB4_CIRCULARBUFFER_Deque( h->stTimeStampFifo, &dequedElement ); @@ -1294,13 +1291,13 @@ static void JB4_estimateShortTermJitter( temp = BASOP_Util_Divide3232_Scale( maxElement, (Word32) h->frameDuration, &exp ); IF( exp < 0 ) { - temp = L_shl( temp, exp ); + temp = L_shl( temp, exp ); // Q31 exp = 0; move16(); } IF( temp != 0 ) { - temp = L_shr( ceil_fixed( temp, 15 - exp ), 15 - exp ); + temp = L_shr( ceil_fixed( temp, sub( 15, exp ) ), sub( 15, exp ) ); // Q31 } h->stJitter = (UWord32) W_mult0_32_32( temp, h->frameDuration ); move32(); @@ -1383,7 +1380,7 @@ static void JB4_popFromBuffer( maxval = h->FecOffWin[i]; move16(); h->optimum_offset = i; - move16(); + move32(); } h->FecOffWin[i] = 0; move32(); @@ -1404,7 +1401,7 @@ static void JB4_popFromBuffer( test(); IF( lost != 0 && total_rec != 0 ) { - h->netLossRate_fx = divide3232( lost, total_rec ); + h->netLossRate_fx = divide3232( lost, total_rec ); // Q15 } ELSE { @@ -1430,7 +1427,7 @@ static void JB4_popFromBuffer( test(); IF( frameoffset > 0 && LT_16( frameoffset, MAXOFFSET ) ) { - h->FecOffWin[frameoffset] = W_extract_l( W_add( h->FecOffWin[frameoffset], 1 ) ); + h->FecOffWin[frameoffset] = (UWord32) ( W_add( h->FecOffWin[frameoffset], 1 ) ); move32(); } } @@ -1503,7 +1500,7 @@ static void JB4_popFromBuffer( test(); IF( !tempDataUnit->partial_frame && !h->lastPoppedWasSilence ) { - frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); + frameoffset = extract_l( Mult_32_32( JB4_rtpTimeStampDiff( h->nextExpectedTs, tempDataUnit->timeStamp ), INV_20_Q31 ) ); // Q0 test(); IF( ( frameoffset > 0 ) && LT_16( frameoffset, MAXOFFSET ) ) { @@ -1523,7 +1520,7 @@ static void JB4_popFromBuffer( /* separate concealments since last available pop in lost and stretched */ Word16 exp; nStretched = BASOP_Util_Divide3232_Scale( tsDiff, h->frameDuration, &exp ); - nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); + nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0 assert( h->nLostOrStretched >= nStretched ); h->nLost = (UWord32) W_add( h->nLost, W_sub( h->nLostOrStretched, nStretched ) ); /* jitter-induced insertion (e.g. buffer underflow) */ @@ -1622,7 +1619,7 @@ static void JB4_dropFromBuffer( /* separate concealments since last available pop in lost and stretched */ Word16 exp; nStretched = BASOP_Util_Divide3232_Scale( tsDiff, (Word32) h->frameDuration, &exp ); - nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); + nStretched = (UWord32) W_shr( nStretched, sub( 15, exp ) ); // Q0 assert( h->nLostOrStretched >= nStretched ); /* convert stretching followed by shrinking to late-loss */ @@ -1636,8 +1633,7 @@ static void JB4_dropFromBuffer( move32(); move32(); move32(); - move32(); - if ( !dataUnit->silenceIndicator ) + IF( !dataUnit->silenceIndicator ) { /* JBM induced removal of a speech frame (intentional frame dropping) */ h->jitterInducedConcealments = (UWord32) W_add( h->jitterInducedConcealments, 1 ); @@ -1752,6 +1748,7 @@ static Word16 JB4_inputBufferCompareFunction( Word16 result; *replaceWithNewElementIfEqual = 0; + move16(); newDataUnit = (JB4_DATAUNIT_HANDLE) newElement; arrayDataUnit = (JB4_DATAUNIT_HANDLE) arrayElement; diff = JB4_rtpTimeStampDiff( arrayDataUnit->timeStamp, newDataUnit->timeStamp ); diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index e5fc42d8d..1ddb7fee6 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -218,7 +218,7 @@ void apa_reset( ps->nFramesSinceSetScale = 0; move32(); ps->scale = 100; - move32(); + move16(); ps->p_min = 0; move16(); ps->l_search = 0; @@ -261,7 +261,7 @@ UWord8 apa_reconfigure( move16(); free( ps->buf_out_fx ); - ps->buf_out_fx = (Word16 *) malloc( sizeof( float ) * ps->buf_out_capacity ); + ps->buf_out_fx = (Word16 *) malloc( sizeof( Word16 ) * ps->buf_out_capacity ); IF( !ps->buf_out_fx ) { return 2; @@ -279,24 +279,24 @@ UWord8 apa_reconfigure( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), (Word16) ps->num_channels ); + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = (UWord16) imult3216( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ), (Word16) ps->num_channels ); + ps->l_frm = (UWord16) imult3216( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = (UWord16) imult3216( Mult_32_16( ps->rate, INV_400_Q15 ), (Word16) ps->num_channels ); + ps->p_min = (UWord16) imult3216( Mult_32_16( ps->rate, INV_400_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), (Word16) ps->num_channels ); + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), (Word16) ps->num_channels ); // Q0 move16(); return 0; @@ -345,36 +345,34 @@ bool apa_set_rate( /* in the order of a pitch, set to 160 samples at 16 kHz */ /* used for windowing and as the correlation length, i.e., */ /* the size of the template segment. */ - ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), ps->num_channels ); + ps->l_seg = (UWord16) imult3216( Mult_32_16( ps->rate, INV_100_Q15 ), ps->num_channels ); // Q0 move16(); /* init Hann window */ /* Note: l_win < APA_BUF_PER_CHANNEL is required */ /* Length of Hann window should be independent of * number of channels - same window applied to all channels */ - ps->l_halfwin = (UWord16) Mult_32_16( ps->rate, INV_100_Q15 ); - move16(); + ps->l_halfwin = (UWord16) Mult_32_16( ps->rate, INV_100_Q15 ); // Q0 move16(); /* set frame size */ /* set to 320 samples at 16 kHz */ - ps->l_frm = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ) ), ps->num_channels ); + ps->l_frm = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_FRAME_PER_SEC_Q15 ) ), ps->num_channels ); // Q0 move16(); /* set minimum pitch */ /* set to 40 samples at 16 kHz */ /* (defines min change in number of samples, i.e., abs(l_in-l_out) >= p_min) */ - ps->p_min = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_400_Q15 ) ), ps->num_channels ); + ps->p_min = (UWord16) imult3216( ( Mult_32_16( ps->rate, INV_400_Q15 ) ), ps->num_channels ); // Q0 move16(); /* set search length */ /* must cover one pitch, set to 200 samples at 16 kHz */ /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ - ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); + ps->l_search = (UWord16) imult3216( Mult_32_16( ps->rate, INV_80_Q15 ), ps->num_channels ); // Q0 move16(); ps->win_fx = pcmdsp_window_hann_640; - move16(); ps->l_halfwin = 320; move16(); ps->win_incrementor = 1; @@ -382,14 +380,12 @@ bool apa_set_rate( IF( EQ_32( ps->rate, 48000 ) ) { ps->win_fx = pcmdsp_window_hann_960; - move16(); ps->l_halfwin = 480; move16(); } IF( EQ_32( ps->rate, 24000 ) ) { ps->win_fx = pcmdsp_window_hann_960; - move16(); ps->l_halfwin = 480; move16(); ps->win_incrementor = 2; @@ -533,12 +529,12 @@ bool apa_set_evs_compat_mode( */ bool apa_set_quality( apa_state_t *ps, - Word32 quality, + Word32 quality, // Q16 UWord16 qualityred, UWord16 qualityrise ) { assert( ps != NULL ); - assert( -131072 <= quality && quality <= 203161 ); + assert( -131072 /*-2.0f in Q16*/ <= quality && quality <= 203161 /*3.1f in Q16*/ ); assert( qualityred > 0 && qualityred <= 20 ); assert( qualityrise > 0 && qualityrise <= 20 ); @@ -670,10 +666,10 @@ bool apa_exit( */ UWord8 apa_exec_fx( apa_state_t *ps, /* i/o: state struct */ - const Word16 a_in[], /* i : input samples */ + const Word16 a_in[], /* i : input samples Q0 */ UWord16 l_in, /* i : number of input samples */ UWord16 maxScaling, /* i : allowed number of inserted/removed samples */ - Word16 a_out[], /* o : output samples */ + Word16 a_out[], /* o : output samples Q0*/ UWord16 *l_out /* o : number of output samples */ ) { @@ -789,7 +785,7 @@ UWord8 apa_exec_fx( IF( NE_32( l_frm_out, ps->l_frm ) ) { test(); - IF( NE_32( maxScaling, 0 ) && + IF( maxScaling != 0 && GT_32( abs_s( extract_l( L_sub( ps->l_frm, l_frm_out ) ) ), maxScaling ) ) { /* maxScaling exceeded -> discard scaled frame */ @@ -875,10 +871,10 @@ UWord8 apa_exec_fx( UWord8 apa_exec_ivas_fx( apa_state_t *ps, /* i/o: state struct */ - const Word16 a_in[], /* i : input samples */ + const Word16 a_in[], /* i : input samples Q(-1) */ UWord16 l_in, /* i : number of input samples */ UWord16 maxScaling, /* i : allowed number of inserted/removed samples */ - Word16 a_out[], /* o : output samples */ + Word16 a_out[], /* o : output samples Q(-1) */ UWord16 *l_out /* o : number of output samples */ ) { @@ -921,8 +917,6 @@ UWord8 apa_exec_ivas_fx( } /* get target length */ - test(); - test(); IF( GT_32( ps->scale, 100 ) ) { // expScaling = (int32_t) ( ( ps->l_frm * ( ps->scale - 100.0f ) / 100.0f ) * ( ps->nFramesSinceSetScale + 1 ) + 0.5f ); @@ -990,7 +984,7 @@ UWord8 apa_exec_ivas_fx( IF( NE_32( l_frm_out, ps->l_frm ) ) { test(); - IF( NE_32( maxScaling, 0 ) && + IF( ( maxScaling != 0 ) && GT_32( abs_s( extract_l( L_sub( ps->l_frm, l_frm_out ) ) ), maxScaling ) ) { /* maxScaling exceeded -> discard scaled frame */ @@ -1109,8 +1103,9 @@ static void get_scaling_quality_fx( const apa_state_t *ps, Word16 offset, Word16 corr_len, Word16 pitch, - Word16 *energydBQ8, - Word32 *qualityQ16 ) + Word16 *energydBQ8, // Q8 + Word32 *qualityQ16 // Q16 +) { Word32 energy, maxEnergy; Word32 qualityOfMaxEnergy; /* we measure the quality for all channels and select the one with highest energy */ @@ -1125,8 +1120,10 @@ static void get_scaling_quality_fx( const apa_state_t *ps, Word16 i; - maxEnergy = L_deposit_l( 0 ); - qualityOfMaxEnergy = L_deposit_l( 0 ); + maxEnergy = 0; + qualityOfMaxEnergy = 0; + move32(); + move32(); FOR( i = 0; i < ps->num_channels; i++ ) { @@ -1177,6 +1174,7 @@ static void get_scaling_quality_fx( const apa_state_t *ps, *qualityQ16 = L_shr( L_mac0( L_mult0( half_pitch_cn, three_halves_pitch_cn ), pitch_cn, double_pitch_cn ), 14 ); + move32(); BASOP_SATURATE_WARNING_OFF_EVS energy = L_add( L_add( L_add( pitch_energy, half_pitch_energy ), three_halves_pitch_energy ), double_pitch_energy ); BASOP_SATURATE_WARNING_ON_EVS @@ -1184,6 +1182,7 @@ static void get_scaling_quality_fx( const apa_state_t *ps, ELSE { *qualityQ16 = L_shl( L_deposit_l( pitch_cn ), 1 ); /* value is negative, thus pass it */ + move32(); energy = L_add( pitch_energy, 0 ); } @@ -1231,9 +1230,9 @@ Word16 apa_getQualityIncreaseForLowEnergy_fx( Word16 energydBQ8 ) { Word16 qualIncreaseMinEnergy, qualIncreaseMaxEnergy, qualIncForLowEnergy; /* Q8 */ - qualIncreaseMinEnergy = -65 * ( 1 << 8 ); + qualIncreaseMinEnergy = -65 * ( 1 << 8 ); // Q8 move16(); - qualIncreaseMaxEnergy = -40 * ( 1 << 8 ); + qualIncreaseMaxEnergy = -40 * ( 1 << 8 ); // Q8 move16(); qualIncForLowEnergy = 0; move16(); @@ -1370,7 +1369,7 @@ static Word8 logarithmic_search_fx( const apa_state_t *ps, inlen = add( sub( s_start_old, s_start ), s_len_old ); } } - WHILE( GT_16( css, 2 ) ); + WHILE( ( css > 2 ) ); return 0; } @@ -1422,8 +1421,8 @@ static Word16 find_synch_fx( apa_state_t *ps, Word16 fixed_pos, Word16 corr_len, Word16 offset, - Word16 *energydBQ8, - Word32 *qualityQ16, + Word16 *energydBQ8, // Q8 + Word32 *qualityQ16, // Q16 Word16 *synch_pos ) { assert( ( corr_len - 1 + s_start + s_len - 1 + offset ) < l_in ); @@ -1446,7 +1445,7 @@ static Word16 find_synch_fx( apa_state_t *ps, /* assert synch_pos is cleanly divisible by number of channels */ assert( *synch_pos % ps->num_channels == 0 ); - *qualityQ16 = L_deposit_l( 0 ); + *qualityQ16 = 0; move32(); get_scaling_quality_fx( ps, in, l_in, offset, corr_len, abs_s( sub( *synch_pos, fixed_pos ) ), energydBQ8, qualityQ16 ); @@ -1480,8 +1479,8 @@ static Word16 find_synch_fx( apa_state_t *ps, */ static bool copy_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], - Word16 frm_out_fx[], + const Word16 frm_in_fx[], // Qx + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { UWord16 i; @@ -1530,9 +1529,9 @@ static bool copy_frm_fx( */ static bool shrink_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], + const Word16 frm_in_fx[], // Qx UWord16 maxScaling, - Word16 frm_out_fx[], + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { bool findSynchResult = 0; @@ -1555,7 +1554,11 @@ static bool shrink_frm_fx( frm_in_fx += l_frm; /* set search range */ - s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + // s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( ps->p_min, ps->num_channels, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + s_start = i_mult( tmp, extract_l( ps->num_channels ) ); s_end = add( s_start, extract_l( ps->l_search ) ); IF( GE_32( L_add( s_end, l_seg ), l_frm ) ) { @@ -1566,9 +1569,9 @@ static bool shrink_frm_fx( IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) { /* maximum scaling */ - energy_fx = -65 * ( 1 << 8 ); + energy_fx = -65 * ( 1 << 8 ); // Q8 move16(); - quality_fx = 5 << Q16; + quality_fx = 5 << Q16; // Q16 move32(); IF( ps->evs_compat_mode == false ) { @@ -1604,7 +1607,7 @@ static bool shrink_frm_fx( { /* find synch */ scaleSignal16( frm_in_fx, ps->frmInScaled, l_frm, ps->signalScaleForCorrelation ); - findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (UWord16) ( s_end - s_start ), 0, l_seg, 0, &energy_fx, &quality_fx, &xtract ); + findSynchResult = find_synch_fx( ps, ps->frmInScaled, l_frm, s_start, (UWord16) ( sub( s_end, s_start ) ), 0, l_seg, 0, &energy_fx, &quality_fx, &xtract ); } /* assert synch_pos is cleanly divisible by number of channels */ @@ -1714,8 +1717,8 @@ static bool shrink_frm_fx( */ static bool extend_frm_fx( apa_state_t *ps, - const Word16 frm_in_fx[], - Word16 frm_out_fx[], + const Word16 frm_in_fx[], // Qx + Word16 frm_out_fx[], // Qx UWord16 *l_frm_out ) { bool findSynchResult = 0; @@ -1727,18 +1730,25 @@ static bool extend_frm_fx( UWord16 over[MAXN + 2]; Word16 l_rem; Word16 s_start = 0; + move16(); Word16 energy_fx; Word32 quality_fx = 0; + move32(); UWord16 l_frm, l_seg; const Word16 *fadeOut_fx, *fadeIn_fx; Word16 *out_fx; l_frm = ps->l_frm; l_seg = ps->l_seg; - + move16(); + move16(); /* number of segments/iterations */ l_frm_out_target = (UWord16) ( L_add( l_frm, L_shr( l_frm, 1 ) ) ); - N = ( l_frm_out_target / l_seg ) - 1; + //(l_frm_out_target/l_seg -1 ) + Word16 tmp, tmp_e; + tmp = BASOP_Util_Divide3232_Scale( l_frm_out_target, l_seg, &tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); + N = sub( ( tmp ), 1 ); if ( LT_16( N, 1 ) ) { N = 1; @@ -1752,21 +1762,23 @@ static bool extend_frm_fx( /* s[n] are given relative to 2nd frame and point to the start of */ /* the search region. The first segment (n=1) will not be moved. */ /* Hence, the iterations will start with n=2. */ - s_min = -( ps->l_search ) - ( ps->p_min ); + s_min = extract_l( L_negate( L_add( ps->l_search, ps->p_min ) ) ); /* (make sure not to exceed array dimension) */ - if ( l_frm + s_min < 0 ) + IF( L_add( l_frm, s_min ) < 0 ) { - s_min = -( l_frm ); + s_min = extract_l( L_negate( l_frm ) ); } - s_max = l_frm - 2 * l_seg - ps->l_search; + s_max = extract_l( L_sub( L_sub( l_frm, L_shl( l_seg, 1 ) ), ps->l_search ) ); if ( s_max < s_min ) { N = 1; + move16(); } /* for just one segment start at s_min */ if ( N == 1 ) { s[2] = s_min; + move16(); } /* else, spread linear in between s_min and s_max */ /* (including s_min and s_max) */ @@ -1774,7 +1786,14 @@ static bool extend_frm_fx( { FOR( n = 2; n <= ( N + 1 ); n++ ) { - s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + // s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + Word16 tmp2, tmp2_e; + tmp2 = sub( s_max, s_min ); + tmp2 = i_mult( tmp2, extract_l( L_sub( n, 2 ) ) ); + tmp2 = BASOP_Util_Divide1616_Scale( tmp2, sub( N, 1 ), &tmp2_e ); + tmp2 = shr( tmp2, sub( 15, tmp2_e ) ); + s[n] = add( s_min, tmp2 ); + move16(); } } @@ -1782,34 +1801,39 @@ static bool extend_frm_fx( * Planning Phase */ - xtract[1] = -( l_seg ); /* make sync_start=0 in 1st iteration */ + xtract[1] = extract_l( L_negate( l_seg ) ); /* make sync_start=0 in 1st iteration */ + move16(); n = 2; - + move16(); /* define synch segment (to be correlated with search region) */ - sync_start = xtract[n - 1] + l_seg; + sync_start = extract_l( L_add( xtract[n - 1], l_seg ) ); over[n] = 1; /* will be reset if overlap is not required */ + move16(); /* check end of search region: should be at least p_min */ /* samples on the left of synch_start */ - IF( ( s[n] + ps->l_search ) < ( sync_start - ( ps->p_min ) ) ) + IF( LT_32( L_add( s[n], ps->l_search ), L_sub( sync_start, ( ps->p_min ) ) ) ) { s_start = s[n]; - s_end = s_start + ps->l_search; + move16(); + s_end = extract_l( L_add( s_start, ps->l_search ) ); } ELSE { /* shrink search region to enforce minimum shift */ - s_end = sync_start - ( ps->p_min ); - IF( s[n] + ps->l_search < sync_start ) + s_end = extract_l( L_sub( sync_start, ( ps->p_min ) ) ); + IF( LT_16( extract_l( L_add( s[n], ps->l_search ) ), sync_start ) ) { s_start = s[n]; /* just do it with normal start position */ + move16(); } - ELSE IF( n == ( N + 1 ) ) /* move search region left for last segment */ + ELSE IF( EQ_32( n, L_add( N, 1 ) ) ) /* move search region left for last segment */ { - s_start = s_end - ( ps->l_search - ps->p_min ); + s_start = extract_l( L_sub( s_end, L_sub( ps->l_search, ps->p_min ) ) ); } ELSE { over[n] = 0; /* don't search/overlap (just copy down) */ + move16(); } } @@ -1819,17 +1843,23 @@ static bool extend_frm_fx( IF( isSilence_fx( frm_in_fx, l_seg, 10 ) ) { /* maximum scaling */ - energy_fx = -65 * ( 1 << 8 ); + energy_fx = -65 * ( 1 << 8 ); // Q8 move16(); - quality_fx = 5 << 16; + quality_fx = 5 << 16; // Q16 move32(); - xtract[n] = s_start + ps->num_channels; + xtract[n] = extract_l( L_add( s_start, ps->num_channels ) ); + move16(); IF( ps->evs_compat_mode == false ) { /* take renderer buffer samples into accout */ - xtract[n] += ps->l_r_buf; + xtract[n] = extract_l( L_add( xtract[n], ps->l_r_buf ) ); /* snap to next renderer time slot border to resynchronize */ - xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + // xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + Word16 tmp3; + tmp3 = extract_l( L_add( L_sub( W_extract_l( W_mult0_32_32( L_sub( N, 1 ), l_seg ) ), xtract[n] ), ps->l_r_buf ) ); + xtract[n] = sub( xtract[n], tmp3 % ps->l_ts ); + move16(); + move16(); } } ELSE @@ -1838,15 +1868,15 @@ static bool extend_frm_fx( frmInScaled = ps->frmInScaled; 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, &energy_fx, &quality_fx, &xtract[n] ); + findSynchResult = find_synch_fx( ps, frmInScaled, extract_l( L_shl( l_frm, 1 ) ), s_start, sub( s_end, s_start ), sync_start, l_seg, l_frm, &energy_fx, &quality_fx, &xtract[n] ); } /* assert synch_pos is cleanly divisible by number of channels */ assert( xtract[n] % ps->num_channels == 0 ); /* test for sufficient quality */ IF( LT_32( quality_fx, L_add( L_sub( ps->targetQuality_fx, - L_mult0( ps->bad_frame_count, 6554 ) ), - L_mult0( ps->good_frame_count, 13107 ) ) ) ) + L_mult0( ps->bad_frame_count, 6554 /*.1f in Q16*/ ) ), + L_mult0( ps->good_frame_count, 13107 /*.1f in Q16*/ ) ) ) ) { /* not sufficient */ over[n] = 0; @@ -1893,7 +1923,8 @@ static bool extend_frm_fx( /* Calculate output data */ FOR( n = 2; n <= N; n++ ) { - IF( over[n] && xtract[n - 1] + l_seg != xtract[n] ) + test(); + IF( over[n] && NE_16( extract_l( L_add( xtract[n - 1], l_seg ) ), xtract[n] ) ) { /* mix 2nd half of previous segment with 1st half of current segment */ fadeOut_fx = frm_in_fx + l_frm + xtract[n - 1] + l_seg; @@ -1933,7 +1964,7 @@ static bool extend_frm_fx( } /* set output length */ - *l_frm_out = ( N - 1 ) * l_seg + l_rem; - + *l_frm_out = (UWord16) ( W_mult0_32_32( L_sub( N, 1 ), L_add( l_seg, l_rem ) ) ); + move16(); return 0; } diff --git a/lib_dec/jbm_pcmdsp_apa.h b/lib_dec/jbm_pcmdsp_apa.h index c1654407c..42215ba16 100644 --- a/lib_dec/jbm_pcmdsp_apa.h +++ b/lib_dec/jbm_pcmdsp_apa.h @@ -144,8 +144,10 @@ bool apa_set_quality( apa_state_t *s, Word32 quality, UWord16 qualityred, UWord1 bool apa_exit( apa_state_t **s ); +#ifndef IVAS_FLOAT_FIXED uint8_t apa_exec( apa_state_t *s, const float a_in[], uint16_t l_in, uint16_t maxScaling, float a_out[], uint16_t *l_out ); -uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out ); -uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], uint16_t l_in, uint16_t maxScaling, Word16 a_out[], uint16_t *l_out ); - +#else +uint8_t apa_exec_ivas_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); +uint8_t apa_exec_fx( apa_state_t *s, const Word16 a_in[], UWord16 l_in, UWord16 maxScaling, Word16 a_out[], UWord16 *l_out ); +#endif #endif /* JBM_PCMDSP_APA_H */ diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.c b/lib_dec/jbm_pcmdsp_similarityestimation.c index 435a5bb4b..6bf8c5c90 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.c +++ b/lib_dec/jbm_pcmdsp_similarityestimation.c @@ -90,10 +90,11 @@ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word32 sum; Word16 i; - sum = L_deposit_l( 0 ); + sum = 0; + move32(); FOR( i = 0; i < corr_len; i += subsampling ) { - sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); + sum = L_mac0( sum, signal[x + i], signal[y + i] ); } return sum; @@ -203,10 +204,12 @@ 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 = 0; + sumXX = 0; + sumYY = 0; + move32(); + move32(); + move32(); FOR( i = 0; i < corr_len; i += subsampling ) { sumXY = L_mac0( sumXY, signalX[i], signalY[i] ); @@ -235,7 +238,7 @@ Word16 normalized_cross_correlation_self_fx( const Word16 *signal, { #ifdef FX_834_OVFL_JBM_CROSSCORR Flag Overflow = 0; - move16(); + move32(); #endif normCC = 0; move16(); @@ -293,10 +296,11 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word32 sum; Word16 i; - sum = L_deposit_l( 0 ); + sum = 0; + move32(); FOR( i = 0; i < corr_len; i++ ) { - sum = L_mac0( sum, signal[add( x, i )], signal[add( y, i )] ); + sum = L_mac0( sum, signal[x + i], signal[y + i] ); } return sum; @@ -320,7 +324,8 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) ret = 1; move16(); - energy = L_deposit_l( 0 ); + energy = 0; + move32(); 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 */ @@ -337,13 +342,14 @@ Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ) /* 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 ); + energy = 0; + move32(); j = add( j, samplesPerSegment ); } } diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 349189119..9a76a63f8 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -41,7 +41,7 @@ #include "options.h" #include "typedef.h" - +#ifndef IVAS_FLOAT_FIXED /* ******************************************************************************** * @@ -67,13 +67,11 @@ * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float cross_correlation_self( const float *signal, uint16_t x, uint16_t y, uint16_t corr_len ); -#endif // !IVAS_FLOAT_FIXED /* ******************************************************************************** @@ -100,14 +98,12 @@ float cross_correlation_self( * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float cross_correlation_subsampled_self( const float *signal, uint16_t x, uint16_t y, uint16_t corr_len, uint16_t subsampling ); -#endif /* ******************************************************************************** * @@ -144,7 +140,6 @@ float cross_correlation_subsampled_self( * ******************************************************************************** */ -#ifndef IVAS_FLOAT_FIXED float normalized_cross_correlation_self( const float *signal, uint16_t x, @@ -152,13 +147,13 @@ float normalized_cross_correlation_self( uint16_t corr_len, uint16_t subsampling, float *energy ); -#endif + /* Splits the signal into segments and checks if all of them have very low energy. */ bool isSilence( const float *signal, uint32_t len, uint32_t segments ); - +#else Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word16 x, Word16 y, @@ -166,10 +161,9 @@ Word32 cross_correlation_subsampled_self_fx( const Word16 *signal, Word16 subsampling ); Word16 getSignalScaleForCorrelation( Word32 sampleRate ); -#ifdef IVAS_FLOAT_FIXED + 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, @@ -186,4 +180,5 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); -#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ +#endif /* IVAS_FLOAT_FIXED */ +#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ \ No newline at end of file diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index a9ed3f82c..8df52a83e 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -41,7 +41,7 @@ #include "jbm_pcmdsp_window.h" #include "cnst.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* * hannWindow() * @@ -68,7 +68,7 @@ void hannWindow( return; } - +#endif /*-----------------------------------------------------------------------* * overlapAdd() diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 82a77f602..2b7f40ce7 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -492,12 +492,14 @@ void ivas_analy_sp_fx( 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 ); + Scale_sig( pt_fft, L_FFT, -1 ); // Q(-1) /*e_min_scaled = Q_new + QSCALE + 2*/ 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; } + LEtot = L_shl_sat( LEtot, 2 ); // Q_new + Q_SCALE - 2 } ELSE { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 7f79fdbc2..89ae59101 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -296,8 +296,8 @@ ivas_error ivas_cpe_enc( fixedToFloat_arr( hCPE->hFrontVad[n]->mem_decim_fx, hCPE->hFrontVad[n]->mem_decim, Q_inp, 90 ); hCPE->hFrontVad[n]->mem_preemph = fixedToFloat( hCPE->hFrontVad[n]->mem_preemph_fx, Q_inp + Qband ); fixedToFloat_arr( hCPE->hFrontVad[n]->buffer_12k8_fx, hCPE->hFrontVad[n]->buffer_12k8, Q_buffer[n], 384 ); - fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE + 2, 40 ); - fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE, 148 ); + fixedToFloat_arrL( fr_bands_fx[n], fr_bands[n], Q_buffer[n] + QSCALE, 40 ); + fixedToFloat_arrL( lf_E_fx[n], lf_E[n], Q_buffer[n] + QSCALE - 2, 148 ); Etot_LR[n] = fixedToFloat( Etot_LR_fx[n], Q8 ); fixedToFloat_arrL( hCPE->hFrontVad[n]->hNoiseEst->bckr_fx, hCPE->hFrontVad[n]->hNoiseEst->bckr, Q_new_old + QSCALE, 20 ); @@ -317,7 +317,7 @@ ivas_error ivas_cpe_enc( } } // fixedToFloat_arrL( band_energies_fx, band_energies, Q_new + QSCALE + 2, 40 ); - fixedToFloat_arrL( &band_energies_LR_fx[0], &band_energies_LR[0], Q_buffer[1] + QSCALE + 2 - band_ener_guardbits, 40 ); + fixedToFloat_arrL( &band_energies_LR_fx[0], &band_energies_LR[0], Q_buffer[1] + QSCALE - band_ener_guardbits, 40 ); } #endif #else diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 61e8f6e62..64296eb11 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -420,8 +420,8 @@ ivas_error front_vad_fx( noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, Q_new + QSCALE - ( Q_new_old + QSCALE ), 20 ); - Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, Q_new + QSCALE - ( Q_new_old + QSCALE ), 20 ); + Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); + Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); hFrontVad->hNoiseEst->sign_dyn_lp_fx = extract_h( hFrontVad->hNoiseEst->sign_dyn_lp_32fx ); hFrontVad->hNoiseEst->Etot_v_h2_fx = extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index c3af6c904..1bfc4a4bf 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -2785,7 +2785,8 @@ void noise_est_ivas_fx( { /* 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 ), 2 ) ); + move16(); } diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 6723304c7..18a71e294 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -2676,8 +2676,8 @@ Word16 wb_vad_ivas_fx( /*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 */ } - 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); */ diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 9e8733d3f..af3d9000c 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -241,7 +241,7 @@ ivas_error ivas_dirac_allocate_parameters_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); + set32_fx( hSpatParamRendCom->diffuseness_vector_fx[i], ONE_IN_Q30, hSpatParamRendCom->num_freq_bands ); // q30 IF( ( hSpatParamRendCom->energy_ratio1_fx[i] = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -339,7 +339,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( DIRAC_CONFIG_FLAG flag_config; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - flag_config = EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + flag_config = DIRAC_RECONFIGURE; + ELSE + flag_config = flag_config_inp; move32(); error = IVAS_ERR_OK; move32(); @@ -367,7 +370,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( IF( EQ_32( flag_config, DIRAC_OPEN ) ) { /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ - hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); + hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); // Q0+Q31-Q31=>Q0 move16(); set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); @@ -380,7 +383,7 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; move16(); /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ - hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // 0+31-31=>0 move16(); hSpatParamRendCom->numSimultaneousDirections = 0; move16(); @@ -454,7 +457,10 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( Word16 num_slots_in_subfr, tmp; tmp = 1; move16(); - num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + IF( dec_param_estim_flag ) + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + ELSE + num_slots_in_subfr = 1; move16(); hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR; move16(); @@ -1890,9 +1896,9 @@ void ivas_dirac_free_mem( #ifdef IVAS_FLOAT_FIXED void compute_hoa_encoder_mtx_fx( - const Word32 *azimuth, - const Word32 *elevation, - Word32 *response_fx, + const Word32 *azimuth, /*q22*/ + const Word32 *elevation, /*q22*/ + Word32 *response_fx, /*q31*/ const Word16 num_responses, const Word16 ambisonics_order ) { @@ -1901,7 +1907,7 @@ void compute_hoa_encoder_mtx_fx( num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { - ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[imult1616( k, num_sh )], ambisonics_order, Q31 ); /* Q31 */ + ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order, Q31 ); /* Q31 */ } return; @@ -1961,12 +1967,12 @@ void ivas_dirac_dec_get_frequency_axis_fx( Word16 k, const_part, scale; /* calc cldfb frequency axis */ - const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); - const_part = shr( const_part, sub( -1, scale ) ); + const_part = BASOP_Util_Divide3216_Scale( output_Fs, shl( num_freq_bands, 1 ), &scale ); // 15-(scale+31-15)=>-1-scale + const_part = shr( const_part, sub( -1, scale ) ); // q(-1-scale)->q0 FOR( k = 0; k < num_freq_bands; k++ ) { /* frequency_axis[k] = ((float)k + 0.5f) * const_part; */ - frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); + frequency_axis[k] = add( i_mult( k, const_part ), shr( const_part, 1 ) ); /*q0*/ move16(); } @@ -2089,7 +2095,7 @@ void initDiffuseResponses( } #else void initDiffuseResponses_fx( - Word16 *diffuse_response_function_fx, + Word16 *diffuse_response_function_fx, /*q15*/ const Word16 num_channels, const AUDIO_CONFIG output_config, const IVAS_OUTPUT_SETUP hOutSetup, @@ -2107,7 +2113,7 @@ void initDiffuseResponses_fx( test(); IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - diffuse_response_function_fx[0] = MAX16B; + diffuse_response_function_fx[0] = MAX16B; /*1 q15*/ move16(); diffuse_response_function_fx[1] = 18918 /*inv_sqrt(3.0f) oin Q15*/; move16(); @@ -2139,7 +2145,7 @@ void initDiffuseResponses_fx( IF( EQ_32( ivas_format, MC_FORMAT ) && ( EQ_32( transport_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( transport_config, IVAS_AUDIO_CONFIG_7_1 ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) { num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); - Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_horizontal_speakers ); // q15 set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; move16(); @@ -2149,24 +2155,24 @@ void initDiffuseResponses_fx( num_horizontal_speakers = sub( num_channels, NUM_ELEVATED_SPEAKERS ); exp_var1 = 15; move16(); - var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); - var1 = shr( var1, negate( exp_var1 ) ); // Q15 - set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); + var1 = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q=15-exp_var1 + var1 = shr( var1, negate( exp_var1 ) ); // Q15 + set16_fx( diffuse_response_function_fx, var1, num_horizontal_speakers ); // q15 set16_fx( &diffuse_response_function_fx[num_horizontal_speakers], 0, NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; move16(); } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) && EQ_16( num_channels, 5 ) ) { - Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP6_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) && EQ_16( num_channels, 7 ) ) { - Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP14_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) ) && EQ_16( num_channels, 9 ) ) { - Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); + Copy( diffuse_response_CICP16_fx, diffuse_response_function_fx, num_channels ); // q15 } ELSE IF( ( EQ_32( ivas_format, MASA_FORMAT ) || EQ_32( ivas_format, MASA_ISM_FORMAT ) || EQ_32( ivas_format, MC_FORMAT ) ) && EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { @@ -2177,10 +2183,10 @@ void initDiffuseResponses_fx( move16(); FOR( i = 0; i < num_channels; i++ ) { - IF( LE_32( abs( hOutSetup.ls_elevation_fx[i] ), 20971520 ) /*5 in Q22*/ ) + IF( LE_32( L_abs( hOutSetup.ls_elevation_fx[i] /*q22*/ ), 20971520 /*5 in Q22*/ ) ) { num_horizontal_speakers = add( num_horizontal_speakers, 1 ); - diffuse_response_function_fx[i] = MAX16B; + diffuse_response_function_fx[i] = MAX16B; // q15 move16(); } ELSE @@ -2196,13 +2202,13 @@ void initDiffuseResponses_fx( { exp_var1 = 15; move16(); - Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); - num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); + Word16 num_horizontal_speakers_isq = ISqrt16( num_horizontal_speakers, &exp_var1 ); // q15-exp_var1 + num_horizontal_speakers_isq = shr( num_horizontal_speakers_isq, negate( exp_var1 ) ); // q15 assert( 0 ); /*No stream hitting*/ FOR( i = 0; i < num_channels; i++ ) { - diffuse_response_function_fx[i] = shr( mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ), Q15 ); + diffuse_response_function_fx[i] = mult( diffuse_response_function_fx[i], num_horizontal_speakers_isq ); // q15 move16(); } } @@ -2211,9 +2217,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1 + res = shr( res, negate( exp_var1 ) ); // q=15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 *num_ele_spk_no_diffuse_rendering = 0; move16(); } @@ -2223,9 +2229,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q=15-exp_var1 + res = shr( res, negate( exp_var1 ) ); // q15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 } } ELSE @@ -2233,9 +2239,9 @@ void initDiffuseResponses_fx( var1 = num_channels, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - res = shr( res, negate( exp_var1 ) ); - set16_fx( diffuse_response_function_fx, res, num_channels ); + res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1) + res = shr( res, negate( exp_var1 ) ); // q15 + set16_fx( diffuse_response_function_fx, res, num_channels ); // q15 } } ELSE @@ -2251,9 +2257,9 @@ void initDiffuseResponses_fx( var1 = j, exp_var1 = 15; move16(); move16(); - res = ISqrt16( var1, &exp_var1 ); - diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); - idx = add( idx, 1 ); + res = ISqrt16( var1, &exp_var1 ); // q(15-exp_var1) + diffuse_response_function_fx[idx] = shr( res, negate( exp_var1 ) ); // q15 + idx = idx + 1; } } } @@ -2271,13 +2277,13 @@ void initDiffuseResponses_fx( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_direct_buffer_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 *proto_direct_buffer_f_fx, /*Q(proto_direct_buffer_f_q)*/ Word16 *proto_direct_buffer_f_q, - Word32 *proto_diffuse_buffer_f_fx, + Word32 *proto_diffuse_buffer_f_fx, /*Q(proto_diffuse_buffer_f_q)*/ Word16 *proto_diffuse_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*Q(reference_power_q)*/ Word16 *reference_power_q, const Word16 slot_index, const Word16 num_inputs, @@ -2305,16 +2311,16 @@ void protoSignalComputation_shd_fx( q_shift = Q31; move16(); - p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); - p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); /*proto_direct_buffer_f_q*/ + p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); /*proto_diffuse_buffer_f_q*/ IF( EQ_16( num_inputs, 1 ) ) { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[2 * l] = RealBuffer_fx[0][0][l]; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = ImagBuffer_fx[0][0][l]; + p_proto_direct_buffer_fx[2 * l + 1] = ImagBuffer_fx[0][0][l]; /*Q(q_cldfb)*/ move32(); } *proto_direct_buffer_f_q = q_cldfb; @@ -2328,19 +2334,19 @@ void protoSignalComputation_shd_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - p_proto_direct_buffer_fx[2 * l] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + p_proto_direct_buffer_fx[2 * ( num_freq_bands + l )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx =>Q(q_cldfb) move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + p_proto_direct_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), Q1 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx => Q(q_cldfb) move32(); } *proto_direct_buffer_f_q = q_cldfb; @@ -2350,16 +2356,16 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); - im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ - p_proto_direct_buffer_fx[2 * l] = re1; + p_proto_direct_buffer_fx[2 * l] = re1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_direct_buffer_fx[2 * l + 1] = im1; /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + p_proto_direct_buffer_fx[2 * num_freq_bands + 2 * l + 1] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); /*Q(q_cldfb)*/ move32(); } } @@ -2368,10 +2374,10 @@ void protoSignalComputation_shd_fx( } ELSE IF( GE_16( num_inputs, 4 ) ) { - p_k_fx[0] = p_proto_direct_buffer_fx; - p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); - p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); - p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); + p_k_fx[0] = p_proto_direct_buffer_fx; /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ + p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); /*Q(proto_direct_buffer_f_q)*/ Rmat_k[0] = 0; move16(); @@ -2399,50 +2405,50 @@ void protoSignalComputation_shd_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ move32(); - reference_power_fx[add( l, num_freq_bands )] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); + reference_power_fx[l + num_freq_bands] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/ move32(); p_k_fx[0]++; - *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ move32(); - reference_power_fx[add( l, num_freq_bands )] = Madd_32_32( reference_power_fx[add( l, num_freq_bands )], *p_k_fx[0], *p_k_fx[0] ); + reference_power_fx[l + num_freq_bands] = Madd_32_32( reference_power_fx[l + num_freq_bands], *p_k_fx[0], *p_k_fx[0] ); /*2*Q(q_cldfb+min_q_shift)-31*/ move32(); p_k_fx[0]++; - reference_power_fx[l] = L_shr( reference_power_fx[add( l, num_freq_bands )], 1 ); + reference_power_fx[l] = L_shr( reference_power_fx[l + num_freq_bands], 1 ); /*2*Q(q_cldfb+min_q_shift)-31-1*/ move32(); FOR( k = 1; k < 4; k++ ) { - re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); - re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); - im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ + im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); /*Q(q_cldfb+min_q_shift)*/ idx = i_mult( 3, Rmat_k[k] ); idx1 = add( l, i_mult( add( k, 1 ), num_freq_bands ) ); - *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], re1 ), p_Rmat_fx[add( idx, 2 )], re2 ), p_Rmat_fx[idx], re3 ); + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], re1 ), p_Rmat_fx[idx + 2], re2 ), p_Rmat_fx[idx], re3 ); /*Q(30 + q_cldfb+min_q_shift-31)=>Q(q_cldfb+min_q_shift-1)*/ move32(); - *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor for p_k_fx + *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor for p_k_fx Q(q_cldfb+min_q_shift) move32(); - reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31) move32(); p_k_fx[k]++; - *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], im1 ), p_Rmat_fx[add( idx, 2 )], im2 ), p_Rmat_fx[idx], im3 ); + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[idx + 1], im1 ), p_Rmat_fx[idx + 2], im2 ), p_Rmat_fx[idx], im3 ); /*Q(q_cldfb+min_q_shift-1)*/ move32(); - *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor + *p_k_fx[k] = L_shl( *p_k_fx[k], Q1 ); // left shift is done to maintain constant Q factor Q(q_cldfb+min_q_shift) move32(); - reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); // Q(2*(q_cldfb + min_q_shift)-31) move32(); p_k_fx[k]++; - reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); /*2*Q(q_cldfb+min_q_shift)-31-1*/ move32(); } @@ -2451,9 +2457,9 @@ void protoSignalComputation_shd_fx( FOR( k = 1; k < 4; k++ ) { - RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); // proto_direct_buffer_f_q -> q_cldfb move32(); - ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1], sub( *proto_direct_buffer_f_q, q_cldfb ) ); // proto_direct_buffer_f_q -> q_cldfb move32(); } } @@ -2465,17 +2471,17 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb move32(); - re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift - reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + reference_power_fx[l + ( k + 1 ) * num_freq_bands] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 move32(); - reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )], 1 ) ); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[l + ( k + 1 ) * num_freq_bands], 1 ) ); // 2*(q_cldfb+min_q_shift)-31-1 move32(); } } @@ -2490,9 +2496,9 @@ void protoSignalComputation_shd_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l )] = RealBuffer_fx[k][0][l]; // q_cldfb move32(); - p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + p_proto_direct_buffer_fx[2 * ( k * num_freq_bands + l ) + 1] = ImagBuffer_fx[k][0][l]; // q_cldfb move32(); } } @@ -2500,7 +2506,7 @@ void protoSignalComputation_shd_fx( /*Copy direct to diffuse proto*/ - Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); + Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); /*proto_diffuse_buffer_f_q -> proto_direct_buffer_f_q*/ *proto_diffuse_buffer_f_q = *proto_direct_buffer_f_q; move16(); @@ -2509,9 +2515,9 @@ void protoSignalComputation_shd_fx( /* Add comfort noise addition (CNA) to diffuse proto only*/ FOR( l = 0; l < num_freq_bands; l++ ) { - p_proto_diffuse_buffer_fx[i_mult( 2, l )] = L_add( p_proto_diffuse_buffer_fx[i_mult( 2, l )], RealBuffer_fx[1][0][l] ); + p_proto_diffuse_buffer_fx[2 * l] = L_add( p_proto_diffuse_buffer_fx[2 * l], RealBuffer_fx[1][0][l] ); // q_cldfb move32(); - p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )] = L_add( p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )], ImagBuffer_fx[1][0][l] ); + p_proto_diffuse_buffer_fx[2 * l + 1] = L_add( p_proto_diffuse_buffer_fx[2 * l + 1], ImagBuffer_fx[1][0][l] ); // q_cldfb move32(); } } @@ -2684,15 +2690,15 @@ void protoSignalComputation_shd( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation1_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, @@ -2709,7 +2715,7 @@ void protoSignalComputation1_fx( q_shift = Q31; move16(); - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( slot_index, i_mult( 2, num_freq_bands ) ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * ( 2 * num_freq_bands ) ); /*proto_direct_buffer_f_q*/ /* calculate the maximum shift possible for the bufferS RealBuffer_fx and ImagBuffer_fx*/ q_shift = L_norm_arr( RealBuffer_fx[0][0], num_freq_bands ); @@ -2723,48 +2729,48 @@ void protoSignalComputation1_fx( q_shift = getScaleFactor32( proto_power_smooth_fx, num_freq_bands ); q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); + Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); /*proto_power_smooth_q+q_shift*/ *proto_power_smooth_q = add( *proto_power_smooth_q, q_shift ); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); FOR( l = 0; l < num_freq_bands; l++ ) { - re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift - reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); + reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 move32(); *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); move16(); IF( LT_16( *reference_power_q, *proto_power_smooth_q ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); // reference_power_q move32(); proto_power_smooth_fx_q = *reference_power_q; move16(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q move32(); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); } - idx = i_mult( 2, l ); - p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; + idx = 2 * l; + p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb move32(); - p_proto_buffer_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + p_proto_buffer_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb move32(); FOR( k = 0; k < num_outputs_diff; k++ ) { idx = add( i_mult( i_mult( 2, k ), num_freq_bands ), i_mult( 2, l ) ); - proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; + proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; // q_cldfb move32(); - proto_frame_f_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + proto_frame_f_fx[idx + 1] = ImagBuffer_fx[0][0][l]; // q_cldfb move32(); } } @@ -2822,15 +2828,15 @@ void protoSignalComputation1( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation2_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*q_proto_frame_f*/ Word16 *q_proto_frame_f, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*q_proto_direct_buffer_f*/ Word16 *q_proto_direct_buffer_f, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*q_reference_power*/ Word16 *q_reference_power, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*q_proto_power_smooth*/ Word16 *q_proto_power_smooth, const Word16 isloudspeaker, const Word16 slot_index, @@ -2895,32 +2901,32 @@ void protoSignalComputation2_fx( IF( isloudspeaker ) { q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ) ); - scale_sig32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ), sub( q_shift, 1 ) ); + scale_sig32( proto_power_smooth_fx, i_mult( 3, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1 } ELSE { q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ) ); - scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); + scale_sig32( proto_power_smooth_fx, i_mult( 2, num_freq_bands ), sub( q_shift, 1 ) ); // q_proto_power_smooth+q_shift-1 } *q_proto_power_smooth = add( *q_proto_power_smooth, sub( q_shift, 1 ) ); move16(); IF( isloudspeaker ) { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 3 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 3 ); // q_proto_direct_buffer_f q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); move16(); FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); W_tmp1 = W_add( W_mult0_32_32( re1, re1 ), W_mult0_32_32( im1, im1 ) ); // 2*(q_cldfb+min_q_shift) @@ -2932,77 +2938,77 @@ void protoSignalComputation2_fx( reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) move64(); - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[i_mult( 2, l )] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = re1; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = re1; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = im1; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = im1; // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); + temp = Madd_32_32( Mpy_32_32( re2, re2 ), im2, im2 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( 2, num_freq_bands ) )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + ( 2 * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( 2 * num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + p_proto_buffer_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + p_proto_buffer_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[i_mult( 2, l )] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, l ), 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); } } ELSE IF( stereo_type_detect != NULL ) { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * 4 * num_freq_bands ); // q_proto_direct_buffer_f left_bb_power_fx = 0; move32(); @@ -3025,7 +3031,7 @@ 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 */ + b_fx = L_sub( ONE_IN_Q31, a_fx ); /* Temporal smoothing coefficient q31*/ // a2_fx = 214748365; /*0.1 in Q31*/ /* Temporal smoothing coefficient */ // b2_fx = L_sub( ONE_IN_Q31, a2_fx ); /* Temporal smoothing coefficient */ @@ -3052,14 +3058,14 @@ void protoSignalComputation2_fx( FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+min_q_shift /* Compute sum signal */ - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+min_q_shift /* Compute reference power */ // Left_power_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); @@ -3073,82 +3079,82 @@ void protoSignalComputation2_fx( reference_power_64fx[l] = W_add( W_tmp1, W_tmp2 ); // 2*(q_cldfb+min_q_shift) move64(); - left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); - right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); + left_bb_power_fx = L_add( left_bb_power_fx, Left_power_fx ); // 2*(q_cldfb+min_q_shift) -31 + right_bb_power_fx = L_add( right_bb_power_fx, Right_power_fx ); // 2*(q_cldfb+min_q_shift) -31 // total_bb_power_fx = L_add( total_bb_power_fx, reference_power_fx[l] ); - total_bb_power_fx = L_add( total_bb_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + total_bb_power_fx = L_add( total_bb_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 IF( GT_16( l, MASA_HI_FREQ_START_BIN ) ) { - left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); - right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); + left_hi_power_fx = L_add( left_hi_power_fx, Left_power_fx ); // 2*(q_cldfb+min_q_shift) -31 + right_hi_power_fx = L_add( right_hi_power_fx, Right_power_fx ); // 2*(q_cldfb+min_q_shift) -31 // total_hi_power_fx = L_add( total_hi_power_fx, reference_power_fx[l] ); - total_hi_power_fx = L_add( total_hi_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + total_hi_power_fx = L_add( total_hi_power_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 } IF( LT_16( l, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) ) { - re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); - im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); + re_aux = L_shl( Real_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift + im_aux = L_shl( Imag_aux_fx, sub( temp_q_shift, min_q_shift ) ); // q_cldfb+temp_q_shift - sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); - temp = Mpy_32_32( a_fx, sum_power_fx ); + sum_power_fx = Madd_32_32( Mpy_32_32( re_aux, re_aux ), im_aux, im_aux ); // 2*(q_cldfb+temp_q_shift)-31 + temp = Mpy_32_32( a_fx, sum_power_fx ); // 2*(q_cldfb+temp_q_shift)-31 IF( LT_16( q_temp2, stereo_type_detect->q_sum_power ) ) { - stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); + stereo_type_detect->sum_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ), sub( stereo_type_detect->q_sum_power, q_temp2 ) ) ); // q_temp2 move32(); } ELSE { - stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); + stereo_type_detect->sum_power_fx[l] = L_add( L_shr( temp, sub( q_temp2, stereo_type_detect->q_sum_power ) ), Mpy_32_32( b_fx, stereo_type_detect->sum_power_fx[l] ) ); // stereo_type_detect->q_sum_power move32(); } - temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + temp = Mpy_32_32( a_fx, W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_power ) ) { - stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); + stereo_type_detect->total_power_fx[l] = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ), sub( stereo_type_detect->q_total_power, q_temp ) ) ); // q_temp move32(); } ELSE { - stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); + stereo_type_detect->total_power_fx[l] = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_power_fx[l] ) ); // stereo_type_detect->q_total_power move32(); } test(); IF( ( stereo_type_detect->sum_power_fx[l] == 0 ) && ( stereo_type_detect->total_power_fx[l] == 0 ) ) { - sum_total_ratio_fx[l] = MAX_16; + sum_total_ratio_fx[l] = MAX_16; // q15 move32(); } ELSE { - sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], L_add( stereo_type_detect->total_power_fx[l], EPSILON_FX ), &exp ); + sum_total_ratio_fx[l] = BASOP_Util_Divide3232_Scale( stereo_type_detect->sum_power_fx[l], L_add( stereo_type_detect->total_power_fx[l], EPSILON_FX ), &exp ); // 15-(exp+s_min( stereo_type_detect->q_total_power, q_temp )-s_min( stereo_type_detect->q_sum_power, q_temp2 )) move32(); q_sum_total_ratio = add( sub( 15, exp ), sub( s_min( stereo_type_detect->q_sum_power, q_temp2 ), s_min( stereo_type_detect->q_total_power, q_temp ) ) ); - sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); + sum_total_ratio_fx[l] = L_shl( sum_total_ratio_fx[l], sub( Q15, q_sum_total_ratio ) ); // q15 move32(); } } IF( l == 0 ) { - RealSubtract_fx = L_sub( re1, re2 ); - ImagSubtract_fx = L_sub( im1, im2 ); + RealSubtract_fx = L_sub( re1, re2 ); // q_cldfb+min_q_shift + ImagSubtract_fx = L_sub( im1, im2 ); // q_cldfb+min_q_shift - temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); + temp = Madd_32_32( Mpy_32_32( RealSubtract_fx, RealSubtract_fx ), ImagSubtract_fx, ImagSubtract_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, stereo_type_detect->q_subtract_power_y ) ) { - stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); + stereo_type_detect->subtract_power_y_fx = L_add( L_shr( stereo_type_detect->subtract_power_y_fx, sub( stereo_type_detect->q_subtract_power_y, q_temp ) ), temp ); // q_temp move32(); stereo_type_detect->q_subtract_power_y = q_temp; move16(); } ELSE { - stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); + stereo_type_detect->subtract_power_y_fx = L_add( stereo_type_detect->subtract_power_y_fx, L_shr( temp, sub( q_temp, stereo_type_detect->q_subtract_power_y ) ) ); // stereo_type_detect->q_subtract_power_y move32(); } } @@ -3160,46 +3166,46 @@ void protoSignalComputation2_fx( { IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) ) { - Real_aux_fx = Madd_32_16( Mpy_32_16_1( Real_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Real_aux_fx, interpolatorDmx_fx ); - Imag_aux_fx = Madd_32_16( Mpy_32_16_1( Imag_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Imag_aux_fx, interpolatorDmx_fx ); + Real_aux_fx = Madd_32_16( Mpy_32_16_1( Real_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift + Imag_aux_fx = Madd_32_16( Mpy_32_16_1( Imag_aux_fx, shr( interpolatorSpaced_fx, 1 ) ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } ELSE { - tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); - tempDmx_fx = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + tempSpaced_fx = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 + tempDmx_fx = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 - temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); + temp = Madd_32_16( Mpy_32_16_1( tempSpaced_fx, interpolatorSpaced_fx ), tempDmx_fx, interpolatorDmx_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[2 * l] = Madd_32_16( Mpy_32_16_1( re1, interpolatorSpaced_fx ), Real_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); + p_proto_buffer_fx[2 * l + 1] = Madd_32_16( Mpy_32_16_1( im1, interpolatorSpaced_fx ), Imag_aux_fx, interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } } @@ -3207,62 +3213,62 @@ void protoSignalComputation2_fx( { IF( L_or( LT_16( l, sub( dipole_freq_range[1], 1 ) ), GE_16( l, MASA_SUM_PROTO_START_BIN ) ) ) { - Real_aux_fx = L_shr( Real_aux_fx, 1 ); - Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + Real_aux_fx = L_shr( Real_aux_fx, 1 ); // q_cldfb+min_q_shift + Imag_aux_fx = L_shr( Imag_aux_fx, 1 ); // q_cldfb+min_q_shift + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } ELSE { - temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + temp = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = re1; + p_proto_buffer_fx[2 * l] = re1; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = im1; + p_proto_buffer_fx[2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); } } ELSE { - temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); + temp = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); } @@ -3271,35 +3277,35 @@ void protoSignalComputation2_fx( { IF( LT_16( l, dipole_freq_range[0] ) ) { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } ELSE IF( LT_16( l, dipole_freq_range[1] ) ) { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( L_sub( im1, im2 ), interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( L_sub( im1, im2 ), interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( -L_sub( re1, re2 ), interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( -L_sub( re1, re2 ), interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } ELSE { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l], interpolatorSpaced_fx ), L_sub( re1, re2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[add( 2 * l, 1 )], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = Madd_32_16( Mpy_32_16_1( p_proto_buffer_fx[2 * l + 1], interpolatorSpaced_fx ), L_sub( im1, im2 ), interpolatorDmx_fx ); // q_cldfb+min_q_shift move32(); } - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } @@ -3307,74 +3313,74 @@ void protoSignalComputation2_fx( { IF( LT_16( l, dipole_freq_range[0] ) ) /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift move32(); - proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; + proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; move32(); } ELSE IF( LT_16( l, dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( im1, im2 ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = -L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = -L_sub( re1, re2 ); // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } ELSE /* proto = W */ { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = p_proto_buffer_fx[2 * l]; + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = p_proto_buffer_fx[2 * l]; // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = p_proto_buffer_fx[add( 2 * l, 1 )]; + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = p_proto_buffer_fx[2 * l + 1]; // q_cldfb+min_q_shift move32(); - proto_power_smooth_fx[add( l, num_freq_bands )] = proto_power_smooth_fx[l]; + proto_power_smooth_fx[l + num_freq_bands] = proto_power_smooth_fx[l]; // min( q_temp, *q_proto_power_smooth ) move32(); } } ELSE { - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // 2*(q_cldfb+min_q_shift)-31 IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } } /* Compute protos for decorrelation */ - proto_frame_f_fx[2 * l] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+min_q_shift move32(); } @@ -3397,67 +3403,67 @@ void protoSignalComputation2_fx( } } - temp = Mpy_32_32( a_fx, left_bb_power_fx ); + temp = Mpy_32_32( a_fx, left_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_left_bb_power ) ) { - stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_temp ) ) ); + stereo_type_detect->left_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ), sub( stereo_type_detect->q_left_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_left_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->left_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ) ); + stereo_type_detect->left_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_bb_power_fx ) ); // stereo_type_detect->q_left_bb_power move32(); } - temp = Mpy_32_32( a_fx, right_bb_power_fx ); + temp = Mpy_32_32( a_fx, right_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_right_bb_power ) ) { - stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_temp ) ) ); + stereo_type_detect->right_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ), sub( stereo_type_detect->q_right_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_right_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->right_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ) ); + stereo_type_detect->right_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_bb_power_fx ) ); // stereo_type_detect->q_right_bb_power move32(); } - temp = Mpy_32_32( a_fx, total_bb_power_fx ); + temp = Mpy_32_32( a_fx, total_bb_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_bb_power ) ) { - stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_temp ) ) ); + stereo_type_detect->total_bb_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ), sub( stereo_type_detect->q_total_bb_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_total_bb_power = q_temp; move16(); } ELSE { - stereo_type_detect->total_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ) ); + stereo_type_detect->total_bb_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_bb_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_bb_power_fx ) ); // stereo_type_detect->q_total_bb_power move32(); } IF( LT_16( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ) { - lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); + lr_bb_power_fx = L_min( stereo_type_detect->left_bb_power_fx, L_shr( stereo_type_detect->right_bb_power_fx, sub( stereo_type_detect->q_right_bb_power, stereo_type_detect->q_left_bb_power ) ) ); // stereo_type_detect->q_left_bb_power move32(); q_lr_bb_power = stereo_type_detect->q_left_bb_power; move16(); } ELSE { - lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); + lr_bb_power_fx = L_min( L_shr( stereo_type_detect->left_bb_power_fx, sub( stereo_type_detect->q_left_bb_power, stereo_type_detect->q_right_bb_power ) ), stereo_type_detect->right_bb_power_fx ); // stereo_type_detect->q_right_bb_power move32(); q_lr_bb_power = stereo_type_detect->q_right_bb_power; move16(); } q_lr_bb_power = sub( q_lr_bb_power, 1 ); /* = (lr_bb_power_fx * 2) */ - temp = BASOP_Util_Divide3232_Scale_cadence( lr_bb_power_fx, L_add( stereo_type_detect->total_bb_power_fx, EPSILON_FX ), &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( lr_bb_power_fx, L_add( stereo_type_detect->total_bb_power_fx, EPSILON_FX ), &exp ); // Q(31-(exp+stereo_type_detect->q_total_bb_power-q_lr_bb_power)) exp = sub( 31, add( sub( 31, exp ), sub( q_lr_bb_power, stereo_type_detect->q_total_bb_power ) ) ); - temp = BASOP_Util_Log2( temp ); + temp = BASOP_Util_Log2( temp ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3465,65 +3471,65 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_bb_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 - temp = Mpy_32_32( a_fx, left_hi_power_fx ); + temp = Mpy_32_32( a_fx, left_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_left_hi_power ) ) { - stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); + stereo_type_detect->left_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ), sub( stereo_type_detect->q_left_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_left_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); + stereo_type_detect->left_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_left_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->left_hi_power_fx ) ); // stereo_type_detect->q_left_hi_power move32(); } - temp = Mpy_32_32( a_fx, right_hi_power_fx ); + temp = Mpy_32_32( a_fx, right_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_right_hi_power ) ) { - stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); + stereo_type_detect->right_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ), sub( stereo_type_detect->q_right_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_right_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); + stereo_type_detect->right_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_right_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->right_hi_power_fx ) ); // stereo_type_detect->q_right_hi_power move32(); } - temp = Mpy_32_32( a_fx, total_hi_power_fx ); + temp = Mpy_32_32( a_fx, total_hi_power_fx ); // 2*(q_cldfb+min_q_shift) -31 IF( LT_16( q_temp, stereo_type_detect->q_total_hi_power ) ) { - stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); + stereo_type_detect->total_hi_power_fx = L_add( temp, L_shr( Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ), sub( stereo_type_detect->q_total_hi_power, q_temp ) ) ); // q_temp move32(); stereo_type_detect->q_total_hi_power = q_temp; move16(); } ELSE { - stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); + stereo_type_detect->total_hi_power_fx = L_add( L_shr( temp, sub( q_temp, stereo_type_detect->q_total_hi_power ) ), Mpy_32_32( b_fx, stereo_type_detect->total_hi_power_fx ) ); // stereo_type_detect->q_total_hi_power move32(); } IF( LT_16( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ) { - lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); + lr_hi_power_fx = L_min( stereo_type_detect->left_hi_power_fx, L_shr( stereo_type_detect->right_hi_power_fx, sub( stereo_type_detect->q_right_hi_power, stereo_type_detect->q_left_hi_power ) ) ); // stereo_type_detect->q_left_hi_power move32(); q_lr_hi_power = stereo_type_detect->q_left_hi_power; } ELSE { - lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); + lr_hi_power_fx = L_min( L_shr( stereo_type_detect->left_hi_power_fx, sub( stereo_type_detect->q_left_hi_power, stereo_type_detect->q_right_hi_power ) ), stereo_type_detect->right_hi_power_fx ); // stereo_type_detect->q_right_hi_power move32(); q_lr_hi_power = stereo_type_detect->q_right_hi_power; } q_lr_hi_power = sub( q_lr_hi_power, 1 ); /* = (q_lr_hi_power * 2) */ - temp = BASOP_Util_Divide3232_Scale_cadence( lr_hi_power_fx, L_add( stereo_type_detect->total_hi_power_fx, EPSILON_FX ), &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( lr_hi_power_fx, L_add( stereo_type_detect->total_hi_power_fx, EPSILON_FX ), &exp ); // Q=31-(exp+ stereo_type_detect->q_total_hi_power-q_lr_hi_power) exp = sub( 31, add( sub( 31, exp ), sub( q_lr_hi_power, stereo_type_detect->q_total_hi_power ) ) ); - temp = BASOP_Util_Log2( temp ); + temp = BASOP_Util_Log2( temp ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3531,9 +3537,9 @@ void protoSignalComputation2_fx( // 20480 = 10 in Q11 lr_total_hi_ratio_fx = Mpy_32_16_1( temp, 20480 ); // Q21 - minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); + minimum_l( sum_total_ratio_fx, s_min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio_fx ); // q_sum_total_ratio exp = sub( 31, q_sum_total_ratio ); - temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); + temp = BASOP_Util_Log2( min_sum_total_ratio_fx ); // q25 IF( NE_32( temp, MIN_32 ) ) { temp = Mpy_32_32( L_add( L_shl( exp, Q25 ), temp ), LOG10_2_Q31 ); // Q25 @@ -3552,69 +3558,69 @@ void protoSignalComputation2_fx( } ELSE { - p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( i_mult( slot_index, 2 ), num_freq_bands ), 2 ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + ( slot_index * num_freq_bands * 4 ); // q_proto_direct_buffer_f q_temp = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); FOR( l = 0; l < num_freq_bands; l++ ) { - re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); - re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); - im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); - im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + re1 = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift + re2 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift + im1 = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); // q_cldfb+ min_q_shift + im2 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); // q_cldfb+ min_q_shift - Real_aux_fx = L_add( re1, re2 ); - Imag_aux_fx = L_add( im1, im2 ); + Real_aux_fx = L_add( re1, re2 ); // q_cldfb+ min_q_shift + Imag_aux_fx = L_add( im1, im2 ); // q_cldfb+ min_q_shift // reference_power_fx[l] = Madd_32_32( Mpy_32_32( Real_aux_fx, Real_aux_fx ), Imag_aux_fx, Imag_aux_fx ); - reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // 2*(q_cldfb+min_q_shift) + reference_power_64fx[l] = W_add( W_mult0_32_32( Real_aux_fx, Real_aux_fx ), W_mult0_32_32( Imag_aux_fx, Imag_aux_fx ) ); // q_temp move64(); IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *q_proto_power_smooth, q_temp ) ), W_extract_l( W_shr( reference_power_64fx[l], 31 ) ) ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( W_extract_l( W_shr( reference_power_64fx[l], 31 ) ), sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - p_proto_buffer_fx[2 * l] = Real_aux_fx; + p_proto_buffer_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[add( 2 * l, 1 )] = Imag_aux_fx; + p_proto_buffer_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( re1, re2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l )] = L_sub( re1, re2 ); // q_cldfb+ min_q_shift move32(); - p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( im1, im2 ); + p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] = L_sub( im1, im2 ); // q_cldfb+ min_q_shift move32(); - temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )], p_proto_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] ), p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )], p_proto_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] ); + temp = Madd_32_32( Mpy_32_32( p_proto_buffer_fx[2 * ( num_freq_bands + l )], p_proto_buffer_fx[2 * ( num_freq_bands + l )] ), p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1], p_proto_buffer_fx[2 * ( num_freq_bands + l ) + 1] ); // q_temp IF( LT_16( q_temp, *q_proto_power_smooth ) ) { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[add( l, num_freq_bands )], sub( *q_proto_power_smooth, q_temp ) ), temp ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( L_shr( proto_power_smooth_fx[l + num_freq_bands], sub( *q_proto_power_smooth, q_temp ) ), temp ); // q_temp move32(); } ELSE { - proto_power_smooth_fx[add( l, num_freq_bands )] = L_add( proto_power_smooth_fx[add( l, num_freq_bands )], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); + proto_power_smooth_fx[l + num_freq_bands] = L_add( proto_power_smooth_fx[l + num_freq_bands], L_shr( temp, sub( q_temp, *q_proto_power_smooth ) ) ); // q_proto_power_smooth move32(); } - proto_frame_f_fx[2 * l] = Real_aux_fx; + proto_frame_f_fx[2 * l] = Real_aux_fx; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( 2 * l, 1 )] = Imag_aux_fx; + proto_frame_f_fx[2 * l + 1] = Imag_aux_fx; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) )] = re1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l] = re1; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 2, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im1; + proto_frame_f_fx[2 * num_freq_bands + 2 * l + 1] = im1; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) )] = re2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l] = re2; // q_cldfb+ min_q_shift move32(); - proto_frame_f_fx[add( add( i_mult( 4, num_freq_bands ), i_mult( 2, l ) ), 1 )] = im2; + proto_frame_f_fx[4 * num_freq_bands + 2 * l + 1] = im2; // q_cldfb+ min_q_shift move32(); } } @@ -3630,7 +3636,7 @@ void protoSignalComputation2_fx( } FOR( l = 0; l < num_freq_bands; l++ ) { - reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); + reference_power_fx[l] = W_extract_h( W_shl( reference_power_64fx[l], norm_shift ) ); // q_reference_power_64fx+norm_shift-32 move32(); } *q_reference_power = sub( add( q_reference_power_64fx, norm_shift ), 32 ); @@ -3976,20 +3982,20 @@ void protoSignalComputation2( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation4_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, const Word16 num_freq_bands, - const Word32 *mtx_hoa_decoder, + const Word32 *mtx_hoa_decoder, /*q29*/ const Word16 nchan_transport, const Word16 *sba_map_tc_ind, Word16 q_cldfb ) @@ -4026,12 +4032,12 @@ void protoSignalComputation4_fx( { FOR( l = 0; l < num_freq_bands; l++ ) { - re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); - im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); // q_cldfb+min_q_shift - sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 - reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 ); // 16384 = 0.5 in Q15 + reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 /*0.5 in Q15*/ ); // 2*(q_cldfb+min_q_shift)-31 move32(); } } @@ -4049,18 +4055,18 @@ void protoSignalComputation4_fx( idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) ); proto_frame_f_fx[idx] = 0; move32(); - proto_frame_f_fx[add( idx, 1 )] = 0; + proto_frame_f_fx[idx + 1] = 0; move32(); FOR( n = 0; n < nchan_transport; n++ ) { idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] ); - re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); - im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); + re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); // q_cldfb+min_q_shift - proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); + proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift+29-31 => q_cldfb+min_q_shift-2 move32(); - proto_frame_f_fx[add( idx, 1 )] = Madd_32_32( proto_frame_f_fx[add( idx, 1 )], im, mtx_hoa_decoder[idx2] ); + proto_frame_f_fx[idx + 1] = Madd_32_32( proto_frame_f_fx[idx + 1], im, mtx_hoa_decoder[idx2] ); // q_cldfb+min_q_shift-2 move32(); } } @@ -4072,7 +4078,7 @@ void protoSignalComputation4_fx( min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) ); min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); + Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); // proto_power_smooth_q+min_q_shift *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift ); move16(); proto_power_smooth_fx_q = *proto_power_smooth_q; @@ -4082,40 +4088,40 @@ void protoSignalComputation4_fx( min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) ); min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); - Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); + Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); // proto_frame_f_q+min_q_shift *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift ); move16(); offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); - p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; + p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; // proto_direct_buffer_f_q FOR( k = 0; k < num_outputs_diff; k++ ) { FOR( l = 0; l < num_freq_bands; l++ ) { - idx = i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ); + idx = 2 * ( k * num_freq_bands + l ); - sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[add( idx, 1 )], proto_frame_f_fx[add( idx, 1 )] ); + sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[idx + 1], proto_frame_f_fx[idx + 1] ); // 2*(proto_frame_f_q)-31 sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 ); IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) ) { - proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); + proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( proto_power_smooth_fx[l + ( k * num_freq_bands )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); // proto_power_smooth_q move32(); proto_power_smooth_fx_q = *proto_power_smooth_q; move16(); } ELSE { - proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); + proto_power_smooth_fx[l + ( k * num_freq_bands )] = L_add( L_shr( proto_power_smooth_fx[l + ( k * num_freq_bands )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); // sq_tmp_q move32(); proto_power_smooth_fx_q = sq_tmp_q; move16(); } - p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; + p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; // proto_frame_f_q move32(); - p_proto_buffer_fx[add( idx, 1 )] = proto_frame_f_fx[add( idx, 1 )]; + p_proto_buffer_fx[idx + 1] = proto_frame_f_fx[idx + 1]; // proto_frame_f_q move32(); } } @@ -4213,7 +4219,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Word32 *p_proto_diff_fx, *p_power_smooth_fx; Word32 *p_hoa_enc_fx; - proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; + proto_frame_dec_f_fx = hDirACRend->proto_frame_dec_f_fx; // hDirACRend->proto_frame_dec_f_q h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); @@ -4225,17 +4231,18 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( return; } - p_diff_buffer_fx = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + imult1616( shl( imult1616( slot_idx, num_freq_bands_diff ), 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ); + p_diff_buffer_fx = h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + ( ( ( slot_idx * num_freq_bands_diff ) << 1 ) * hDirACRend->hOutSetup.nchan_out_woLFE ); // proto_diffuse_buffer_f_q p_diff_buffer_1_fx = p_diff_buffer_fx + 1; - p_power_smooth_fx = h_dirac_output_synthesis_state->proto_power_diff_smooth_fx; + p_power_smooth_fx = h_dirac_output_synthesis_state->proto_power_diff_smooth_fx; // h_dirac_output_synthesis_state->proto_power_diff_smooth_q - Word16 diffuse_start = slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; + Word16 diffuse_start = imult1616( slot_idx, shl( imult1616( num_freq_bands_diff, hDirACRend->hOutSetup.nchan_out_woLFE ), 1 ) ); Word16 diff_e, smooth_e, proto_e, max_e; Word32 diff_square, diff_square_1, diff_square_sum; Word16 diff_square_e; Word16 old_diff_e; diff_e = sub( 31, h_dirac_output_synthesis_state->proto_diffuse_buffer_f_q ); old_diff_e = diff_e; + move16(); smooth_e = sub( 31, h_dirac_output_synthesis_state->proto_power_diff_smooth_q ); proto_e = sub( 31, hDirACRend->proto_frame_dec_f_q ); @@ -4243,22 +4250,22 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( { diff_square_e = add( shl( proto_e, 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); - Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); + Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { - p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); + p_proto_diff_fx = proto_frame_dec_f_fx + shl( imult1616( k, num_freq_bands ), 1 ); // hDirACRend->proto_frame_dec_f_q FOR( l = 0; l < num_freq_bands_diff; l++ ) { - *p_diff_buffer_fx = *( p_proto_diff_fx++ ); + *p_diff_buffer_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q move32(); - *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); + *p_diff_buffer_1_fx = *( p_proto_diff_fx++ ); // hDirACRend->proto_frame_dec_f_q move32(); diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2 * proto_e + 1 diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2 * proto_e + 1 - diff_square_sum = L_add( diff_square, diff_square_1 ); - diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); - *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + diff_square_sum = L_add( diff_square, diff_square_1 ); // Q(31- diff_square_e) + diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // Q(31-max_e) + *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // Q(31-max_e) move32(); p_power_smooth_fx++; @@ -4275,13 +4282,13 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( Word16 gb = find_guarded_bits_fx( hDirACRend->num_outputs_diff ); diff_square_e = add( shl( add( proto_e, gb ), 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); - Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); + Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); // 31-max_e FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) { FOR( l = 0; l < num_freq_bands_diff; l++ ) { - p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; - p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); + p_hoa_enc_fx = hDirACRend->hoa_encoder_fx + k; // q31 + p_proto_diff_fx = proto_frame_dec_f_fx + shl( l, 1 ); // hDirACRend->proto_frame_dec_f_q *p_diff_buffer_fx = 0; move32(); @@ -4291,19 +4298,19 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( /*LS to HOA*/ FOR( m = 0; m < hDirACRend->num_outputs_diff; m++ ) { - *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); + *p_diff_buffer_fx = L_add( *p_diff_buffer_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *p_proto_diff_fx ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb move32(); - *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); + *p_diff_buffer_1_fx = L_add( *p_diff_buffer_1_fx, L_shr( Mpy_32_32( *p_hoa_enc_fx, *( p_proto_diff_fx + 1 ) ), gb ) ); // hDirACRend->proto_frame_dec_f_q-gb move32(); p_hoa_enc_fx += hDirACRend->hOutSetup.nchan_out_woLFE; p_proto_diff_fx += shl( num_freq_bands, 1 ); } - diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 - diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*(2 + proto_e + gb) + 1 - diff_square_sum = L_add( diff_square, diff_square_1 ); - diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); - *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); + diff_square = L_shr( Mpy_32_32( *p_diff_buffer_fx, *p_diff_buffer_fx ), 1 ); // 2*( proto_e + gb) + 1 + diff_square_1 = L_shr( Mpy_32_32( *p_diff_buffer_1_fx, *p_diff_buffer_1_fx ), 1 ); // 2*( proto_e + gb) + 1 + diff_square_sum = L_add( diff_square, diff_square_1 ); // 2*( proto_e + gb) + 1 + diff_square_sum = L_shr( diff_square_sum, sub( max_e, diff_square_e ) ); // 31-max_e + *p_power_smooth_fx = L_add( *p_power_smooth_fx, diff_square_sum ); // 31-max_e move32(); p_power_smooth_fx++; @@ -4318,10 +4325,10 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( move16(); Word16 new_diff_e = s_max( diff_e, old_diff_e ); - Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); + Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx, diffuse_start, sub( old_diff_e, new_diff_e ) ); // 31-new_diff_e #ifdef MSAN_FIX Scale_sig32( h_dirac_output_synthesis_state->proto_diffuse_buffer_f_fx + diffuse_start, - i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); + i_mult( shl( num_freq_bands_diff, 1 ), hDirACRend->hOutSetup.nchan_out_woLFE ), sub( diff_e, new_diff_e ) ); // 31-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 ) ); @@ -4417,9 +4424,9 @@ void ivas_dirac_dec_compute_diffuse_proto( #ifdef IVAS_FLOAT_FIXED void computeDirectionAngles_fx( - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 q_intensity_real, const Word16 num_frequency_bands, Word16 *azimuth, @@ -4441,28 +4448,28 @@ void computeDirectionAngles_fx( exp1 = norm_l( intensity_real_x_fx[k] ); exp2 = norm_l( intensity_real_y_fx[k] ); exp3 = norm_l( intensity_real_z_fx[k] ); - x_re = L_shl( intensity_real_x_fx[k], exp1 ); - y_re = L_shl( intensity_real_y_fx[k], exp2 ); - z_re = L_shl( intensity_real_z_fx[k], exp3 ); + x_re = L_shl( intensity_real_x_fx[k], exp1 ); /*q_intensity_real+exp1*/ + y_re = L_shl( intensity_real_y_fx[k], exp2 ); /*q_intensity_real+exp2*/ + z_re = L_shl( intensity_real_z_fx[k], exp3 ); /*q_intensity_real+exp3*/ - tmp1 = Mpy_32_32( x_re, x_re ); + tmp1 = Mpy_32_32( x_re, x_re ); /*2*(q_intensity_real+exp1)-31*/ q_tmp1 = sub( add( add( q_intensity_real, exp1 ), add( q_intensity_real, exp1 ) ), 31 ); - tmp2 = Mpy_32_32( y_re, y_re ); + tmp2 = Mpy_32_32( y_re, y_re ); /*2*(q_intensity_real+exp2)-31*/ q_tmp2 = sub( add( add( q_intensity_real, exp2 ), add( q_intensity_real, exp2 ) ), 31 ); - temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp - tmp2 = Mpy_32_32( z_re, z_re ); + tmp2 = Mpy_32_32( z_re, z_re ); /*2*(q_intensity_real+exp3)-31*/ q_tmp2 = sub( add( add( q_intensity_real, exp3 ), add( q_intensity_real, exp3 ) ), 31 ); - intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp, exp, tmp2, sub( 31, q_tmp2 ), &exp ); // 31-exp q_intensityNorm = sub( 31, exp ); IF( LE_32( intensityNorm, EPSILON_FX ) ) { - intensityNorm = ONE_IN_Q30; + intensityNorm = ONE_IN_Q30; // q30 move32(); - x = ONE_IN_Q30; + x = ONE_IN_Q30; // q30 move32(); q_x = Q30; move16(); @@ -4477,31 +4484,31 @@ void computeDirectionAngles_fx( } ELSE { - temp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, intensityNorm, &exp ); + temp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, intensityNorm, &exp ); // Q=31-(exp-(30-q_intensityNorm)) exp = sub( exp, sub( Q30, q_intensityNorm ) ); - temp = Sqrt32( temp, &exp ); + temp = Sqrt32( temp, &exp ); // Q=31-exp q_temp = sub( 31, exp ); - x = Mpy_32_32( x_re, temp ); + x = Mpy_32_32( x_re, temp ); /*Q=q_intensity_real+exp1+q_temp-31*/ q_x = sub( add( add( q_intensity_real, exp1 ), q_temp ), 31 ); - y = Mpy_32_32( y_re, temp ); + y = Mpy_32_32( y_re, temp ); /*Q=q_intensity_real+exp2+q_temp-31*/ q_y = sub( add( add( q_intensity_real, exp2 ), q_temp ), 31 ); - z = Mpy_32_32( z_re, temp ); + z = Mpy_32_32( z_re, temp ); /*Q=q_intensity_real+exp3+q_temp-31*/ q_z = sub( add( add( q_intensity_real, exp3 ), q_temp ), 31 ); } - tmp1 = Mpy_32_32( x, x ); + tmp1 = Mpy_32_32( x, x ); /*Q=2*q_x-31*/ q_tmp1 = sub( add( q_x, q_x ), 31 ); - tmp2 = Mpy_32_32( y, y ); + tmp2 = Mpy_32_32( y, y ); /*Q=2*q_y-31*/ q_tmp2 = sub( add( q_y, q_y ), 31 ); - temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); - radius = Sqrt32( temp, &exp ); + temp = BASOP_Util_Add_Mant32Exp( tmp1, sub( 31, q_tmp1 ), tmp2, sub( 31, q_tmp2 ), &exp ); // Q=31-exp + radius = Sqrt32( temp, &exp ); // Q=31-exp - res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */ - res = add( s_max( -23040, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ - azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */ + res = BASOP_util_atan2( y, x, sub( sub( 31, q_y ), sub( 31, q_x ) ) ); /* Q13 */ + res = add( s_max( -23040 /*-180 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */ + azimuth[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); IF( res < 0 ) { @@ -4509,9 +4516,9 @@ void computeDirectionAngles_fx( move16(); } - res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */ - res = add( s_max( -11520, s_min( 23040, mult( res, _180_OVER_PI_Q9 ) ) ), 64 ); /* Q7 */ - elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */ + res = BASOP_util_atan2( z, radius, sub( sub( 31, q_z ), exp ) ); /* Q13 */ + res = add( s_max( -11520 /*-90 q7*/, s_min( 23040 /*180 q7*/, mult( res, _180_OVER_PI_Q9 /*180/pi q9*/ ) ) ), 64 /*0.5 q7*/ ); /* Q7 */ + elevation[k] = shr( abs_s( res ), Q7 ); /* Q0 */ move16(); IF( res < 0 ) { @@ -4719,28 +4726,28 @@ void ivas_masa_stereotype_detection_fx( Word32 lr_total_hi_temp_fx; Word32 temp; - lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; + lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; // q21 move32(); - lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; + lr_total_hi_ratio_db_fx = stereo_type_detect->lr_total_hi_ratio_db_fx; // q21 move32(); - min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; + min_sum_total_ratio_db_fx = stereo_type_detect->min_sum_total_ratio_db_fx; // q21 move32(); - subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; + subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; // q21 move32(); /* Determine if the determined features match the spaced mic type */ change_to_spaced_selection = 0; move16(); - IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 ) ) + IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 /*-3 q21*/ ) ) { /* subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; */ - temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); - subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); - subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */ + temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); // q20 + subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); // q20 + subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */ /* min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); */ min_sum_temp_fx = Mpy_32_32_r( -min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ - min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); + min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); /*q21*/ /* lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; */ lr_total_bb_temp_fx = Mpy_32_32_r( lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ @@ -4770,7 +4777,7 @@ void ivas_masa_stereotype_detection_fx( change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */ - IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 ) ) + IF( GE_32( change_to_downmix_fx, ONE_IN_Q21 /*1 q21*/ ) ) { change_to_downmix_selection = 1; move16(); @@ -4791,7 +4798,7 @@ void ivas_masa_stereotype_detection_fx( change_to_downmix2_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_hi_temp_fx ); // Q21 - IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 ) ) + IF( GE_32( change_to_downmix2_fx, ONE_IN_Q21 /*1 q21*/ ) ) { change_to_downmix_selection = 1; move16(); @@ -4932,13 +4939,13 @@ void ivas_masa_stereotype_detection( #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_dec_fx( - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ Word16 q_cldfb, const Word16 num_frequency_bands, - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 *q_intensity_real ) { /* @@ -4961,24 +4968,24 @@ void computeIntensityVector_dec_fx( FOR( i = 0; i < num_frequency_bands; ++i ) { - re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); - im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); - re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); + re1 = L_shl( Cldfb_RealBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im1 = L_shl( Cldfb_ImagBuffer_fx[0][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + re2 = L_shl( Cldfb_RealBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[3][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_x_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); - re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); + re2 = L_shl( Cldfb_RealBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[1][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_y_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); - re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); - im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); + re2 = L_shl( Cldfb_RealBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ + im2 = L_shl( Cldfb_ImagBuffer_fx[2][0][i], min_q_shift ); /*q_cldfb+min_q_shift*/ - intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); + intensity_real_z_fx[i] = Madd_32_32( Mpy_32_32( re2, re1 ), im2, im1 ); /*2*(q_cldfb+min_q_shift)-31*/ move32(); } @@ -5026,10 +5033,10 @@ void computeIntensityVector_dec( #ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_cldfb_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ const Word16 slot_index, const Word16 subframe_index, const Word16 nchan_transport, @@ -5045,6 +5052,7 @@ void ivas_lfe_synth_with_cldfb_fx( Word16 transportGain_q_fx, lfeGain_q_fx; Word16 exp, min_q_shift; Word32 re, im; + move16(); // temp_q exp = Q31; move16(); @@ -5069,89 +5077,89 @@ void ivas_lfe_synth_with_cldfb_fx( } min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 ); - re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); - im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); + re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); // q_cldfb+min_q_shift - protoLfeReal_fx = re; + protoLfeReal_fx = re; // q_cldfb+min_q_shift move32(); - protoLfeImag_fx = im; + protoLfeImag_fx = im; // q_cldfb+min_q_shift move32(); - transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); // 2*(q_cldfb+min_q_shift)-31 FOR( i = 1; i < nchan_transport; i++ ) { - re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); - im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); + re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift + im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); // q_cldfb+min_q_shift - protoLfeReal_fx = L_add( protoLfeReal_fx, re ); - protoLfeImag_fx = L_add( protoLfeImag_fx, im ); - transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); + protoLfeReal_fx = L_add( protoLfeReal_fx, re ); // q_cldfb+min_q_shift + protoLfeImag_fx = L_add( protoLfeImag_fx, im ); // q_cldfb+min_q_shift + transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); // 2*(q_cldfb+min_q_shift)-31 } transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); + protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); // 2*(q_cldfb+min_q_shift)-31 protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); - targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); + targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); // targetEneLfe_q+14-15 targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 ); - temp = s_max( sub( ONE_IN_Q14, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 ); // 164 = 0.01 in Q14 - targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); + temp = s_max( sub( ONE_IN_Q14 /*1 q14*/, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 /*0.01 in Q14*/ ); // q14 + targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); /*transportEne_q+Q14 -15*/ targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 ); - hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->transportEneSmooth_q+15-15 move32(); - hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->protoLfeEneSmooth_q+15-15 move32(); - hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneLfeSmooth_q+15-15 move32(); - hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); // hMasaLfeSynth->targetEneTransSmooth_q+15-15 move32(); - hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); + hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); + hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); + hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q ); move16(); - hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); + hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); // 31-temp_q move32(); hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q ); move16(); - temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); // 15-(temp_q-(hMasaLfeSynth->targetEneLfeSmooth_q-hMasaLfeSynth->protoLfeEneSmooth_q)) temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) ); exp = sub( Q15, temp_q ); - lfeGain_fx = Sqrt16( temp, &exp ); + lfeGain_fx = Sqrt16( temp, &exp ); // 15-exp lfeGain_q_fx = sub( Q15, exp ); - IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) ) { - lfeGain_fx = ONE_IN_Q14; + lfeGain_fx = ONE_IN_Q14; /*1 q14*/ move16(); lfeGain_q_fx = Q14; move16(); } - temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); // Q=15-(temp_q-(hMasaLfeSynth->targetEneTransSmooth_q-hMasaLfeSynth->transportEneSmooth_q)) temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) ); exp = sub( Q15, temp_q ); - transportGain_fx = Sqrt16( temp, &exp ); + transportGain_fx = Sqrt16( temp, &exp ); // q=15-exp transportGain_q_fx = sub( Q15, exp ); - IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 /*1 q14*/ ) ) { - transportGain_fx = ONE_IN_Q14; + transportGain_fx = ONE_IN_Q14; /*1 q14*/ move16(); transportGain_q_fx = Q14; move16(); @@ -5251,7 +5259,7 @@ void rotateAziEle_DirAC_fx( Word16 *ele, /* i/o: array of elevation values */ const Word16 band1, /* i : bands to work on (lower limit) */ const Word16 band2, /* i : bands to work on (upper bound) */ - const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/ ) { Word16 b; @@ -5260,8 +5268,8 @@ void rotateAziEle_DirAC_fx( Word16 exp, temp; Word32 *ptr_sin, *ptr_cos; - ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] - ptr_cos = cosine_table_Q31; + ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] q31 + ptr_cos = cosine_table_Q31; // q31 push_wmops( "rotateAziEle_DirAC" ); @@ -5271,7 +5279,7 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( ele[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - w_fx = L_negate( ptr_cos[sub( abs_s( ele[b] ), 180 )] ); // Q31 + w_fx = L_negate( ptr_cos[abs( ele[b] ) - 180] ); // Q31 } ELSE { @@ -5282,11 +5290,11 @@ void rotateAziEle_DirAC_fx( IF( GT_16( abs_s( azi[b] ), 180 ) ) { // cos(180 + x) = -cos(x) - tmp = L_negate( ptr_cos[sub( abs_s( azi[b] ), 180 )] ); // Q31 + tmp = L_negate( ptr_cos[abs( azi[b] ) - 180] ); // Q31 } ELSE { - tmp = ptr_cos[abs_s( azi[b] )]; // Q31 + tmp = ptr_cos[abs( azi[b] )]; // Q31 move32(); } @@ -5296,13 +5304,13 @@ void rotateAziEle_DirAC_fx( IF( GT_16( azi[b], 180 ) ) { // sin(180 + x) = -sin(x) - tmp = L_negate( ptr_sin[sub( azi[b], 180 )] ); // Q31 + tmp = L_negate( ptr_sin[azi[b] - 180] ); // Q31 move32(); } ELSE IF( LT_16( azi[b], -180 ) ) { // sin(-(180 + x)) = sin(180 + x) = sinx - tmp = ptr_sin[sub( abs_s( azi[b] ), 180 )]; // Q31 + tmp = ptr_sin[abs( azi[b] ) - 180]; // Q31 move32(); } ELSE @@ -5315,13 +5323,13 @@ void rotateAziEle_DirAC_fx( IF( GT_16( ele[b], 180 ) ) { // sin(180 + x) = -sin(x) - dv_2_fx = L_negate( ptr_sin[sub( ele[b], 180 )] ); // Q31 + dv_2_fx = L_negate( ptr_sin[ele[b] - 180] ); // Q31 move32(); } ELSE IF( LT_16( ele[b], -180 ) ) { // sin(-(180 + x)) = -sin(180 + x) = sinx - dv_2_fx = ptr_sin[sub( abs_s( ele[b] ), 180 )]; // Q31 + dv_2_fx = ptr_sin[abs( ele[b] ) - 180]; // Q31 move32(); } ELSE @@ -5341,7 +5349,7 @@ void rotateAziEle_DirAC_fx( tmp = L_add( Mpy_32_32( dv_r_0_fx, dv_r_0_fx ), Mpy_32_32( dv_r_1_fx, dv_r_1_fx ) ); // Q27 exp = sub( 31, Q27 ); - tmp = Sqrt32( tmp, &exp ); + tmp = Sqrt32( tmp, &exp ); // q=31-exp temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13 ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0 move16(); @@ -5775,7 +5783,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 q11*/ ) { Word16 i, ch, idx_in, idx_lfe; @@ -5826,10 +5834,24 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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; - onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + onset_filter_fx = DirAC_mem.onset_filter_fx; // q31 + reference_power_fix = DirAC_mem.reference_power_fx; // DirAC_mem.reference_power_q + IF( ( DirAC_mem.reference_power_fx == NULL ) ) + { + reference_power_smooth_fx = NULL; + } + ELSE + { + reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; // DirAC_mem.reference_power_q + } + IF( ( DirAC_mem.onset_filter_fx == NULL ) ) + { + onset_filter_subframe_fx = NULL; + } + ELSE + { + onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; // q31 + } coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ move16(); /* Construct default MASA band mapping */ @@ -5857,7 +5879,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); 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 ); + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); // q30 IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { @@ -5889,22 +5911,22 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // 29 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 ); + 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 ); // q29 move32(); - 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 ); + 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 ); // q29 move32(); - surCohRatio_fx[i] = L_deposit_h( BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add( 1, dirEne_fx ), surCohEner_fx ), &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] ) ); // 31-surCohRatio_exp move32(); temp_exp = s_max( temp_exp, surCohRatio_exp[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] ) ); // 31-temp_exp move32(); } Q_surCohRatio = sub( 31, temp_exp ); @@ -5932,7 +5954,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); + surCohRatio_fx[i] = L_deposit_h( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // q31 move32(); } } @@ -6022,18 +6044,18 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ) ); + 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_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 ) ); + 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_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( 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 ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); } @@ -6059,18 +6081,18 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ) ); + 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_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 ) ); + 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_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( 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 ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); @@ -6093,19 +6115,19 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ) ); + 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_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 ) ); + 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_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } temp_proto_frame_q = sub( 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 ); + Scale_sig32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q ); // hDirACRend->proto_frame_f_q+temp_proto_frame_q hDirACRend->proto_frame_f_q = add( hDirACRend->proto_frame_f_q, temp_proto_frame_q ); move16(); @@ -6140,7 +6162,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 */ - p_onset_filter_fx = onset_filter_subframe_fx; + p_onset_filter_fx = onset_filter_subframe_fx; /*q31*/ } ELSE { @@ -6161,23 +6183,23 @@ static void ivas_masa_ext_dirac_render_sf_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_fx = DirAC_mem.frame_dec_f_fx; // DirAC_mem.frame_dec_f_q hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q; move16(); - p_onset_filter_fx = onset_filter_fx; + p_onset_filter_fx = onset_filter_fx; // q31 } } ELSE { 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; + set32_fx( onset_filter_subframe_fx, ONE_IN_Q31, hSpatParamRendCom->num_freq_bands ); // q31 + p_onset_filter_fx = onset_filter_subframe_fx; // q31 } ELSE { /* no frequency domain decorrelation: use prototype frame */ - hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; + hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; // q31 hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q; p_onset_filter_fx = NULL; } @@ -6193,11 +6215,11 @@ static void ivas_masa_ext_dirac_render_sf_fx( /* 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 ) ); + 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 ) ); // q31 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 ) ); + 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 ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); @@ -6221,12 +6243,12 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); + Scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1 ); // DirAC_mem.reference_power_q-1 DirAC_mem.reference_power_q = sub( DirAC_mem.reference_power_q, 1 ); move16(); DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); - 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 ); // DirAC_mem.reference_power_smooth_q } } /*Rescaling proto_direct_buffer_f*/ @@ -6242,14 +6264,14 @@ static void ivas_masa_ext_dirac_render_sf_fx( { 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[( slot_idx * ( 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] ) ); // temp } } ELSE { 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[( slot_idx * ( 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] ) ); // temp } } hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp; @@ -6259,13 +6281,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ) ); + 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 ) ); // q31 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 ) ); + 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 ) ); // q31 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 ) ); + 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 ) ); // q31 hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; move16(); @@ -6276,27 +6298,27 @@ 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( 6, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6 Scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 6, q_cldfb ) ); // q6 } } 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 ) ); + 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 ) ); // q26 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 ) ); + 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 ) ); // q26 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 ) ); + 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 ) ); // q26 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 ) ); + 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 ) ); // q26 hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); @@ -6326,8 +6348,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ); + 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 ); // 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_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 + 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 ); move16(); 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 ); @@ -6340,42 +6362,42 @@ 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 ) ); + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); // q11 scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); + hSpatParamRendCom->num_freq_bands, sub( 11, q_cldfb ) ); // q11 } } 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 ); + scale_sig32( DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q ); /*DirAC_mem.reference_power_q + reference_power_temp_q*/ DirAC_mem.reference_power_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); move16(); DirAC_mem.reference_power_smooth_q = add( DirAC_mem.reference_power_q, reference_power_temp_q ); 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 ); + 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+ 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 ); move16(); - 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 ) ); + 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 ) ); // q31 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 ) ); + 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 ) ); // q31 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 ) ); + Scale_sig32( h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub( 31, h_dirac_output_synthesis_state->direct_responses_q ) ); // q31 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_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 ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) move32(); - 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_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 ) ); // s_min( hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ) move32(); 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 ); @@ -6384,25 +6406,25 @@ static void ivas_masa_ext_dirac_render_sf_fx( move16(); } - 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 ) ); + 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 ) ); // 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 = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); - 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 ) ); + 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 ) ); // 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 = s_min( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); move16(); 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 ); + 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 + 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 ); move16(); 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 ); + 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 + 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 ); move16(); - 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 ) ); + 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 ) ); // 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 ) + 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 ) ); // 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 = 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 ); move16(); 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 ); @@ -6412,8 +6434,8 @@ static void ivas_masa_ext_dirac_render_sf_fx( /*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 ) ); + 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 ) ); // s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_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 ) ); // 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 = s_min( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q ); move16(); @@ -6439,13 +6461,13 @@ static void ivas_masa_ext_dirac_render_sf_fx( 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 ) ); + 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_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 ) ); + 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_smooth_q DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); } @@ -6482,9 +6504,9 @@ 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, scale_factor ); + hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor scale_sig32( Cldfb_ImagBuffer_fx[ch][slot_idx], - hSpatParamRendCom->num_freq_bands, scale_factor ); + hSpatParamRendCom->num_freq_bands, scale_factor ); // q_cldfb+scale_factor } } q_cldfb = add( q_cldfb, scale_factor ); @@ -6503,7 +6525,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF( 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][imult1616( index_slot, hSpatParamRendCom->num_freq_bands )] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, imult1616( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->num_freq_bands ) ); IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -6514,17 +6536,17 @@ static void ivas_masa_ext_dirac_render_sf_fx( { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ Word16 q_out = sub( q_cldfb, 1 ); - scale_sig32( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ); + scale_sig32( hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[idx_in]->cldfb_state_length, sub( q_out, hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state ) ); // q_out hMasaExtRend->cldfbSynRend[idx_in]->Q_cldfb_state = q_out; move16(); 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]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; // q_cldfb + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; // q_cldfb } Word16 out_size = imult1616( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, hMasaExtRend->cldfbSynRend[idx_in] ); - scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); + scale_sig32( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), out_size, sub( 11, q_out ) ); // q11 idx_in++; } } @@ -6580,7 +6602,7 @@ 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 */ + Word32 *output_f[], /* i/o: input/output signals in time domain q11*/ const Word16 num_subframes /* i : number of subframes to render */ ) { @@ -6595,7 +6617,7 @@ void ivas_masa_ext_dirac_render_fx( FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { - output_f_local[n] = output_f[n]; + output_f_local[n] = output_f[n]; // q11 } hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 8a9e8185d..8752094ce 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -442,26 +442,26 @@ void ivas_dirac_free_mem_fx( ); void initDiffuseResponses_fx( - Word16 *diffuse_response_function_fx, - const int16_t num_channels, + Word16 *diffuse_response_function_fx, /*q15*/ + const Word16 num_channels, const AUDIO_CONFIG output_config, const IVAS_OUTPUT_SETUP hOutSetup, - const int16_t ambisonics_order, + const Word16 ambisonics_order, const IVAS_FORMAT ivas_format, - int16_t *num_ele_spk_no_diffuse_rendering, + Word16 *num_ele_spk_no_diffuse_rendering, const AUDIO_CONFIG transport_config ); #endif #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_dec_fx( - Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 Cldfb_RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 Cldfb_ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ Word16 q_cldfb, const Word16 num_frequency_bands, - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 *q_intensity_real ); #else @@ -476,19 +476,19 @@ void computeIntensityVector_dec( #endif #ifdef IVAS_FLOAT_FIXED void protoSignalComputation_shd_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_direct_buffer_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*Q(q_cldfb)*/ + Word32 *proto_direct_buffer_f_fx, /*Q(proto_direct_buffer_f_q)*/ Word16 *proto_direct_buffer_f_q, - Word32 *proto_diffuse_buffer_f_fx, + Word32 *proto_diffuse_buffer_f_fx, /*Q(proto_diffuse_buffer_f_q)*/ Word16 *proto_diffuse_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*Q(reference_power_q)*/ Word16 *reference_power_q, const Word16 slot_index, const Word16 num_inputs, const Word16 num_outputs_diff, const Word16 num_freq_bands, - Word32 *p_Rmat_fx, + Word32 *p_Rmat_fx, /* Q30 */ Word16 q_cldfb ); #endif @@ -507,15 +507,15 @@ void protoSignalComputation_shd( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation1_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, @@ -537,15 +537,15 @@ void protoSignalComputation1( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation2_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*q_proto_frame_f*/ Word16 *q_proto_frame_f, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*q_proto_direct_buffer_f*/ Word16 *q_proto_direct_buffer_f, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*q_reference_power*/ Word16 *q_reference_power, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*q_proto_power_smooth*/ Word16 *q_proto_power_smooth, const Word16 isloudspeaker, const Word16 slot_index, @@ -569,20 +569,20 @@ void protoSignalComputation2( #ifdef IVAS_FLOAT_FIXED void protoSignalComputation4_fx( - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 *proto_frame_f_fx, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 *proto_frame_f_fx, /*proto_frame_f_q*/ Word16 *proto_frame_f_q, - Word32 *proto_direct_buffer_f_fx, + Word32 *proto_direct_buffer_f_fx, /*proto_direct_buffer_f_q*/ Word16 *proto_direct_buffer_f_q, - Word32 *reference_power_fx, + Word32 *reference_power_fx, /*reference_power_q*/ Word16 *reference_power_q, - Word32 *proto_power_smooth_fx, + Word32 *proto_power_smooth_fx, /*proto_power_smooth_q*/ Word16 *proto_power_smooth_q, const Word16 slot_index, const Word16 num_outputs_diff, const Word16 num_freq_bands, - const Word32 *mtx_hoa_decoder, + const Word32 *mtx_hoa_decoder, /*q29*/ const Word16 nchan_transport, const Word16 *sba_map_tc_ind, Word16 q_cldfb @@ -623,9 +623,9 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( #ifdef IVAS_FLOAT_FIXED void computeDirectionAngles_fx( - Word32 *intensity_real_x_fx, - Word32 *intensity_real_y_fx, - Word32 *intensity_real_z_fx, + Word32 *intensity_real_x_fx, /*q_intensity_real*/ + Word32 *intensity_real_y_fx, /*q_intensity_real*/ + Word32 *intensity_real_z_fx, /*q_intensity_real*/ Word16 q_intensity_real, const Word16 num_frequency_bands, Word16 *azimuth, @@ -664,10 +664,10 @@ void ivas_masa_stereotype_detection( #ifdef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_cldfb_fx( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /*q_cldfb*/ const Word16 slot_index, const Word16 subframe_index, const Word16 nchan_transport, @@ -688,11 +688,11 @@ void ivas_lfe_synth_with_cldfb( #ifdef IVAS_FLOAT_FIXED void rotateAziEle_DirAC_fx( - Word16 *azi, - Word16 *ele, - const Word16 band1, - const Word16 band2, - const Word32 *p_Rmat_fx + Word16 *azi, /* i/o: array of azimuth values */ + Word16 *ele, /* i/o: array of elevation values */ + const Word16 band1, /* i : bands to work on (lower limit) */ + const Word16 band2, /* i : bands to work on (upper bound) */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix q30*/ ); #endif void rotateAziEle_DirAC( @@ -953,11 +953,11 @@ void compute_hoa_encoder_mtx( #ifdef IVAS_FLOAT_FIXED void compute_hoa_encoder_mtx_fx( - const Word32 *azimuth, - const Word32 *elevation, - Word32 *response_fx, + const Word32 *azimuth, /*q22*/ + const Word32 *elevation, /*q22*/ + Word32 *response_fx, /*q31*/ const Word16 num_responses, - const Word16 ambisonics_order); + const Word16 ambisonics_order ); #endif #ifndef IVAS_FLOAT_FIXED @@ -1103,9 +1103,9 @@ 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 */ + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + Word32 *output_f[], /* i/o: input/output signals in time domain q11*/ + const Word16 num_subframes /* i : number of subframes to render */ ); #endif /*----------------------------------------------------------------------------------* -- GitLab From 8d6ed7a697a8f4846cfda0beb37a91263ad8743b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 09:51:32 +0530 Subject: [PATCH 22/39] Clang formatting correction for MR 715 --- lib_dec/jbm_pcmdsp_similarityestimation.h | 2 +- lib_enc/ivas_front_vad.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/jbm_pcmdsp_similarityestimation.h b/lib_dec/jbm_pcmdsp_similarityestimation.h index 9a76a63f8..7e18c3394 100644 --- a/lib_dec/jbm_pcmdsp_similarityestimation.h +++ b/lib_dec/jbm_pcmdsp_similarityestimation.h @@ -181,4 +181,4 @@ Word32 cross_correlation_self_fx( const Word16 *signal, Word8 isSilence_fx( const Word16 *signal, Word16 len, Word16 segments ); #endif /* IVAS_FLOAT_FIXED */ -#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ \ No newline at end of file +#endif /* JBM_PCMDSP_SIMILARITYESTIMATION_H */ diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 64296eb11..a4f7731e1 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -420,8 +420,8 @@ ivas_error front_vad_fx( noise_est_pre_32fx( Etot_fx, hFrontVads[0]->ini_frame, hFrontVad->hNoiseEst, 0, 0, 0 ); /* wb_vad */ - Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); - Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE )); + Scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); + Scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, NB_BANDS, Q_new + QSCALE - ( Q_new_old + QSCALE ) ); hFrontVad->hNoiseEst->sign_dyn_lp_fx = extract_h( hFrontVad->hNoiseEst->sign_dyn_lp_32fx ); hFrontVad->hNoiseEst->Etot_v_h2_fx = extract_h( hFrontVad->hNoiseEst->Etot_v_h2_32fx ); hFrontVad->hVAD->vad_flag = wb_vad_ivas_fx( sts[n], fr_bands_fx[n], &dummy, &dummy, &dummy, &snr_sum_he_fx, &localVAD_HE_SAD[n], &dummy_short, Q_new, hFrontVad->hVAD, hFrontVad->hNoiseEst, hFrontVad->lp_speech_fx, hFrontVad->lp_noise_fx ); -- GitLab From b081a0d8247c3e1e2c8799b73e36d3e75ad15f43 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 10:45:54 +0530 Subject: [PATCH 23/39] Fix for 3GPP issue 949 --- lib_com/lpc_tools_fx.c | 214 ++++++++++++++++++++++++++++++++++++++++ lib_com/preemph_fx.c | 55 +++++++++++ lib_com/prot_fx.h | 4 + lib_dec/er_dec_tcx_fx.c | 7 +- 4 files changed, 277 insertions(+), 3 deletions(-) diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 26a9549d6..bfb5d8ed1 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -579,6 +579,220 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[], const Word16 Rl[], Word16 A[], Wor return ( flag ); } +Word16 E_LPC_lev_dur_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *mem ) +{ + return ( E_LPC_lev_dur_stab_ivas_fx( Rh, Rl, A, epsP, order, mem, 32750 ) ); /* 0.99945 in Q15 */ +} + +Word16 E_LPC_lev_dur_stab_ivas_fx( 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 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; +#endif + + + BASOP_SATURATE_WARNING_OFF_EVS + if ( epsP != NULL ) + { + 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++ ) + { + 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 */ + + /* 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 ); +#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*/ + } + + 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) */ + } + test(); + 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 + *------------------------------------------*/ + + 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) */ +#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 */ + + + /* 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 */ + } + + /* 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( sub( norm_l( t1 ), 1 ), 3 ); + A[0] = shl( 2048, k ); + move16(); + FOR( i = 1; i <= order; i++ ) + { + t0 = L_Comp( Ah[i], Al[i] ); +#ifdef BASOP_NOGLOB + A[i] = round_fx_o( L_shl_o( t0, k, &Overflow ), &Overflow ); +#else + A[i] = round_fx( L_shl( t0, k ) ); +#endif + move16(); + } + + BASOP_SATURATE_WARNING_ON_EVS + IF( mem != NULL ) + { + /* Enforce stable LPC filter - parcorr[0] and parcorr[1] are not LPC coeffiecients */ + IF( flag ) + { + Copy( mem, A, add( order, 1 ) ); + } + ELSE /* If stable LPC filter, store into memories */ + { + Copy( A, mem, add( order, 1 ) ); + } + } + + + return ( flag ); +} Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word32 epsP[], const Word16 order, Word32 *mem ) { diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index 63de35dca..13a0b5e42 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -158,3 +158,58 @@ Word16 E_UTIL_f_preemph3( Word16 *signal, const Word16 mu, const Word16 lg, Word return Q_new; } + +Word16 E_UTIL_f_preemph3_ivas_fx( 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 ); + + 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++ ) + { + 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 ); + + Q_new = Q_MAX; + move16(); + IF( tmp_fixed != 0 ) + { + Q_new = sub( norm_s( tmp_fixed ), bits ); + Q_new = s_max( Q_new, 0 ); + Q_new = sub( s_min( Q_new, Q_MAX ), 1 ); + } + + tmp_fixed = signal[lg - 1]; + move16(); + + 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 ); + move16(); + } + + 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 ); + move16(); + *mem = tmp_fixed; + move16(); + + return Q_new; +} diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 70d2f94b0..a148ab903 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1114,6 +1114,9 @@ void autocorr_fx_32( 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_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 A[], Word32 epsP[], const Word16 order, Word16 *parcorr ); +Word16 E_LPC_lev_dur_stab_ivas_fx( 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 ); @@ -2609,6 +2612,7 @@ void preemph_copy_fx( 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 ); +Word16 E_UTIL_f_preemph3_ivas_fx( 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 */ diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 1a1dbce92..bbe1276f1 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1263,7 +1263,7 @@ void con_tcx_ivas_fx( /* apply pre-emphasis to the signal */ mem = synth[( -( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( 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 ); + Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-add( add( 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 - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); @@ -1286,7 +1286,7 @@ void con_tcx_ivas_fx( 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_ivas_fx( 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 ); /*Q14*/ @@ -1308,7 +1308,7 @@ void con_tcx_ivas_fx( /* apply pre-emphasis to the signal */ mem = synth[( -L_frame - 1 )]; /*Q0*/ move16(); - Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); + Q_exc = E_UTIL_f_preemph3_ivas_fx( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q14*/ offset = shr( L_frame, 1 ); @@ -2029,6 +2029,7 @@ void con_tcx_ivas_fx( } } #endif + E_UTIL_synthesis( sub( Q_exc, Q_syn ), A_local, -- GitLab From 90757f51146f38c9fe434f9e5976d0521a05ab55 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 11:53:21 +0530 Subject: [PATCH 24/39] Fix for 3GPP issue 960: Decoder crash for OSBA_2ISM_HOA3 at 32kbps with FER in pitch_pred_linear_fit() --- lib_dec/pitch_extr_fx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index f1e69ae68..54ecc67d8 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -163,6 +163,9 @@ void pitch_pred_linear_fit( { Word32 t1, t2, t3, t4, t5, t6, t7; Word16 e1, e2, e3, e4, e5, e6, e7; +#ifdef BASOP_NOGLOB + Flag Overflow; +#endif t1 = L_mult0( pg[4], pg[3] ); /*Q24*/ /* t1 = pg[4]*pg[3] */ e1 = 7; move16(); @@ -185,8 +188,12 @@ void pitch_pred_linear_fit( t6 = BASOP_Util_Add_Mant32Exp( t3, e3, t4, e4, &e6 ); t7 = BASOP_Util_Add_Mant32Exp( t5, e5, t6, e6, &e7 ); /*Q31,e7*/ sum0_q = norm_l( t7 ); +#ifdef BASOP_NOGLOB + sum0 = round_fx_o( L_shl( t7, sum0_q ), &Overflow ); /*Q15,e7-sum0_q*/ +#else sum0 = round_fx( L_shl( t7, sum0_q ) ); /*Q15,e7-sum0_q*/ - sum0_q = add( 15, sub( sum0_q, e7 ) ); /* sum0 is now Qsum0_q*/ +#endif + sum0_q = add( 15, sub( sum0_q, e7 ) ); /* sum0 is now Qsum0_q*/ } pit = 0; -- GitLab From a9832a36cfb67cb68396ff3b13adceedf27e8917 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 16:22:12 +0530 Subject: [PATCH 25/39] SBA path function integration, dirac enc cleanup, Q-info updates [x] spar_md_enc_process integration and cleanup [x] ivas_dirac_enc_cleanup [x] Q-info_updates --- lib_com/bitallocsum_fx.c | 10 +- lib_com/bits_alloc_fx.c | 197 ++-- lib_com/bitstream.c | 17 +- lib_com/bitstream_fx.c | 110 +- lib_com/ivas_dirac_com.c | 4 +- lib_com/ivas_prot.h | 119 +-- lib_com/ivas_qmetadata_com.c | 3 +- lib_com/ivas_spar_com.c | 1551 ++-------------------------- lib_com/ivas_spar_com_quant_util.c | 87 +- lib_com/ivas_stat_com.h | 26 +- lib_dec/gain_dec_fx.c | 442 ++++---- lib_dec/gaus_dec_fx.c | 44 +- lib_enc/ivas_dirac_enc.c | 534 ++++------ lib_enc/ivas_enc.c | 28 +- lib_enc/ivas_init_enc.c | 61 +- lib_enc/ivas_masa_enc.c | 19 - lib_enc/ivas_mct_enc.c | 26 - lib_enc/ivas_spar_encoder.c | 105 +- lib_enc/ivas_spar_md_enc.c | 361 +++---- lib_enc/ivas_stat_enc.h | 26 +- 20 files changed, 1096 insertions(+), 2674 deletions(-) diff --git a/lib_com/bitallocsum_fx.c b/lib_com/bitallocsum_fx.c index c8ad205e1..fa71c92f8 100644 --- a/lib_com/bitallocsum_fx.c +++ b/lib_com/bitallocsum_fx.c @@ -25,12 +25,12 @@ void bitallocsum_fx( Word16 total, tmp; Word16 diff; - total = (Word16) 0; + total = 0; move16(); 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] ) ); // Q0 + Rsubband[i] = shl( tmp, 3 ); // Q3 move16(); total = add( total, tmp ); } @@ -40,7 +40,7 @@ void bitallocsum_fx( IF( LE_16( length, L_FRAME32k ) ) { diff = sub( num_bits, *sum ); - i = (Word16) 0; + i = 0; move16(); WHILE( diff > 0 ) { @@ -55,7 +55,7 @@ void bitallocsum_fx( i = add( i, 1 ); if ( GE_16( i, nb_sfm ) ) { - i = (Word16) 0; + i = 0; move16(); } } diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 2e0c018c8..1c247a9fb 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -51,14 +51,10 @@ void BITS_ALLOC_init_config_acelp( { Word8 rate_mode_index; - - move16(); - move16(); - move16(); rate_mode_index = (Word8) GT_32( bit_rate, ACELP_9k60 ); pConfigAcelp->mode_index = rate_mode_index; - + move16(); /*LPC: midLpc should be swithced off?*/ pConfigAcelp->midLpc_enable = 1; @@ -155,7 +151,8 @@ Word16 BITS_ALLOC_config_acelp( } } - IF( L_and( EQ_16( band_index, 1 ), EQ_16( nb_subfr, 4 ) ) ) + test(); + IF( EQ_16( band_index, 1 ) && EQ_16( nb_subfr, 4 ) ) { IF( coder_type == INACTIVE ) { @@ -239,7 +236,8 @@ Word16 BITS_ALLOC_config_acelp( move16(); pConfigAcelp->ltf_bits = ACELP_LTF_BITS[pConfigAcelp->ltf_mode]; - IF( L_and( EQ_16( nb_subfr, 5 ), EQ_16( pConfigAcelp->ltf_bits, 4 ) ) ) + test(); + IF( EQ_16( nb_subfr, 5 ) && EQ_16( pConfigAcelp->ltf_bits, 4 ) ) { pConfigAcelp->ltf_bits = add( pConfigAcelp->ltf_bits, 1 ); move16(); @@ -369,14 +367,15 @@ static Word16 BITS_ALLOC_adjust_generic( bits_currsubframe = sub( add( i_mult2( sfr, bits_subframe2 ), bits_subframe2 ), bitsused ); /* try increasing mode while below threshold */ - WHILE( ( LT_16( k, sub( pulseconfig_size, 1 ) ) ) && ( LE_16( i_mult2( pulseconfigbits[k + 1], nb_subfr ), bits_currsubframe ) ) ) + test(); + WHILE( ( ( k < sub( pulseconfig_size, 1 ) ) ) && ( ( i_mult2( pulseconfigbits[k + 1], nb_subfr ) <= bits_currsubframe ) ) ) { test(); k = add( k, 1 ); } /* try decreasing mode until below threshold */ - WHILE( GT_16( i_mult2( pulseconfigbits[k], nb_subfr ), bits_currsubframe ) ) + WHILE( ( i_mult2( pulseconfigbits[k], nb_subfr ) > bits_currsubframe ) ) { k = sub( k, 1 ); @@ -442,7 +441,7 @@ static Word16 fcb_table( static ivas_error acelp_FCB_allocator( Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index */ + Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ @@ -464,7 +463,6 @@ static ivas_error acelp_FCB_allocator( move16(); p_fixed_cdk_index = fixed_cdk_index; - move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); @@ -531,7 +529,6 @@ static ivas_error acelp_FCB_allocator( IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); - move16(); } ELSE { @@ -545,7 +542,7 @@ static ivas_error acelp_FCB_allocator( IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( GE_16( *nBits, step ) ) + WHILE( *nBits >= step ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); @@ -558,14 +555,16 @@ static ivas_error acelp_FCB_allocator( test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { - fixed_cdk_index[sfr]++; + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { - sfr++; - fixed_cdk_index[sfr]++; + sfr = add( sfr, 1 ); + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); } @@ -581,7 +580,7 @@ static ivas_error acelp_FCB_allocator( /* TRANSITION coding: allocate second highest FCBQ bit-budget to the last subframe */ IF( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) { - SWAP( fixed_cdk_index[sub( 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] ); } } @@ -603,7 +602,7 @@ static ivas_error acelp_FCB_allocator( static ivas_error acelp_FCB_allocator_ivas( Word16 *nBits, /* i/o: available bit-budget */ - Word16 fixed_cdk_index[], /* o : codebook index */ + Word16 fixed_cdk_index[], /* o : codebook index Q0 */ Word16 nb_subfr, /* i : number of subframes */ const Word16 L_subfr, /* i : subframe length */ const Word16 coder_type, /* i : coder type */ @@ -625,7 +624,6 @@ static ivas_error acelp_FCB_allocator_ivas( move16(); p_fixed_cdk_index = fixed_cdk_index; - move16(); /* TRANSITION coding: first subframe bit-budget was already fixed, glottal pulse not in the first subframe */ test(); @@ -681,7 +679,6 @@ static ivas_error acelp_FCB_allocator_ivas( IF( cdbk >= 0 ) { nBits_tmp = fcb_table( cdbk, L_subfr ); - move16(); } ELSE { @@ -695,7 +692,7 @@ static ivas_error acelp_FCB_allocator_ivas( IF( LT_16( cdbk, ACELP_FIXED_CDK_NB - 1 ) ) { step = sub( fcb_table( add( cdbk, 1 ), L_subfr ), nBits_tmp ); - WHILE( GE_16( *nBits, step ) ) + WHILE( *nBits >= step ) { ( *p_fixed_cdk_index )++; *nBits = sub( *nBits, step ); @@ -710,14 +707,16 @@ static ivas_error acelp_FCB_allocator_ivas( test(); IF( GE_16( *nBits, step ) && cdbk >= 0 ) { - fixed_cdk_index[sfr]++; + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); test(); IF( GE_16( *nBits, step ) && EQ_16( fixed_cdk_index[sfr + 1], sub( fixed_cdk_index[sfr], 1 ) ) ) { - sfr++; - fixed_cdk_index[sfr]++; + sfr = add( sfr, 1 ); + fixed_cdk_index[sfr] = add( fixed_cdk_index[sfr], 1 ); + move16(); *nBits = sub( *nBits, step ); move16(); } @@ -732,7 +731,7 @@ static ivas_error acelp_FCB_allocator_ivas( 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( idiv1616( tc_subfr, L_SUBFR ) < sub( nb_subfr, 1 ) ) + IF( LT_16( idiv1616( tc_subfr, L_SUBFR ), sub( nb_subfr, 1 ) ) ) { SWAP( fixed_cdk_index[sub( tc_subfr, L_SUBFR ) / L_SUBFR], fixed_cdk_index[nb_subfr - 1] ); } @@ -879,7 +878,7 @@ ivas_error config_acelp1( i = 0; move16(); - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) + WHILE( i < SIZE_BRATE_INTERMED_TBL ) { IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) { @@ -895,14 +894,14 @@ ivas_error config_acelp1( BREAK; } - i++; + i = add( i, 1 ); } test(); test(); test(); - if ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && - LE_32( core_brate_inp, 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( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( coder_type, AUDIO ) && + LE_32( core_brate_inp, 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 ); } @@ -910,14 +909,14 @@ ivas_error config_acelp1( core_brate = brate_intermed_tbl[i]; move32(); - if ( GT_16( element_mode, EVS_MONO ) ) + if ( element_mode > EVS_MONO ) { flag_hardcoded = 0; /* use automatic and flexible ACELP bit-budget allocation */ move16(); } test(); - if ( NE_16( core, ACELP_CORE ) && EQ_16( 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; move16(); @@ -931,11 +930,11 @@ ivas_error config_acelp1( IF( !( EQ_16( coder_type, TRANSITION ) && NE_16( tc_subfr, -1 ) ) || EQ_16( enc_dec, DEC ) ) { /* Set the bit-budget */ - bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + bits = extract_l( Mpy_32_32( core_brate_inp, ONE_BY_FRAMES_PER_SEC_Q31 ) ); // Q0 test(); test(); - if ( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) + IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) { bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } @@ -947,7 +946,7 @@ ivas_error config_acelp1( { bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - if ( EQ_16( tdm_LRTD_flag, 1 ) ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { bits = add( bits, STEREO_BITS_TCA ); } @@ -959,7 +958,7 @@ ivas_error config_acelp1( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { bits = sub( bits, 1 ); } @@ -976,7 +975,7 @@ ivas_error config_acelp1( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { /* extension layer signalling bit is counted in the extension layer bitbudget */ bits = add( bits, 1 ); @@ -1139,7 +1138,7 @@ ivas_error config_acelp1( test(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) && NE_16( coder_type, VOICED ) ) { bits = sub( bits, FEC_BITS_CLS ); } @@ -1151,7 +1150,7 @@ ivas_error config_acelp1( acelp_cfg->FEC_mode = 2; move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_ENR ); } @@ -1163,7 +1162,7 @@ ivas_error config_acelp1( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_POS ); } @@ -1190,7 +1189,7 @@ ivas_error config_acelp1( acelp_cfg->ltf_mode = FULL_BAND; move16(); } - ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && core_brate < ACELP_11k60 ) + ELSE IF( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) ) && LT_32( core_brate, ACELP_11k60 ) ) { acelp_cfg->ltf_mode = LOW_PASS; move16(); @@ -1208,7 +1207,7 @@ ivas_error config_acelp1( { acelp_cfg->ltf_mode = NORMAL_OPERATION; move16(); - if ( coder_type != TRANSITION ) + IF( coder_type != TRANSITION ) { bits = sub( bits, nb_subfr ); } @@ -1229,11 +1228,11 @@ ivas_error config_acelp1( test(); test(); test(); - if ( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) + IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ } - if ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) + IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { bits = sub( bits, 3 * NB_SUBFR ); /* tilt factor */ } @@ -1257,55 +1256,55 @@ ivas_error config_acelp1( { IF( EQ_16( tc_subfr, TC_0_0 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 1 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 2 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signalling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 1 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signalling */ } @@ -1317,7 +1316,7 @@ ivas_error config_acelp1( } ELSE { - if ( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signalling */ } @@ -1330,7 +1329,7 @@ ivas_error config_acelp1( } ELSE /* L_frame == L_FRAME16k */ { - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) { @@ -1342,7 +1341,8 @@ 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 */ + bits = sub( bits, idiv1616_1( sub( L_FRAME16k - L_SUBFR, tc_subfr ), L_SUBFR ) ); /* LP filtering flag */ } /* glottal-shape codebook bits */ @@ -1371,7 +1371,7 @@ ivas_error config_acelp1( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) /* GENERIC low rate mode for secondary channel */ + IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( tdm_low_rate_mode, 1 ) && ( coder_type != INACTIVE ) && NE_16( 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 ); @@ -1387,6 +1387,7 @@ ivas_error config_acelp1( bits = sub( bits, acelp_cfg->pitch_bits[i] ); } acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX_fx( ACELP_7k20, GENERIC, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_fx( tc_subfr ) )]; + move16(); bits = sub( bits, acelp_cfg->gains_mode[i] ); } acelp_cfg->fcb_mode = 1; @@ -1422,6 +1423,7 @@ ivas_error config_acelp1( { IF( EQ_16( L_frame, L_FRAME ) ) { + test(); IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) && EQ_16( idchan, 1 ) ) { acelp_cfg->pitch_bits[i] = 0; @@ -1501,8 +1503,7 @@ ivas_error config_acelp1( IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { i = idiv1616( bits, NB_SUBFR ); - move16(); - if ( i % 2 == 0 ) + IF( s_and( i, 1 ) == 0 ) { i = sub( i, 1 ); /* must be odd */ } @@ -1571,7 +1572,7 @@ ivas_error config_acelp1( move16(); } } - ELSE IF( element_mode != IVAS_CPE_TD && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) + ELSE IF( NE_16( element_mode, IVAS_CPE_TD ) && GSC_IVAS_mode > 0 && EQ_16( L_frame, L_FRAME16k ) ) { bits = 100; /* 9 kbps for fcb */ move16(); @@ -1606,7 +1607,7 @@ ivas_error config_acelp1( test(); test(); - if ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) + IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) { /* harm. flag ACELP AVQ */ bits = sub( bits, 1 ); @@ -1729,6 +1730,8 @@ ivas_error config_acelp1( test(); IF( flag_hardcoded && NE_32( core_brate, PPP_NELP_2k80 ) ) { + test(); + test(); /* unused bits */ IF( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_24k40 ) ) ) { @@ -1997,20 +2000,20 @@ ivas_error config_acelp1_IVAS( i = 0; move16(); - WHILE( LT_16( i, SIZE_BRATE_INTERMED_TBL ) ) + WHILE( i < SIZE_BRATE_INTERMED_TBL ) { IF( EQ_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 1; move16(); - break; + BREAK; } IF( LT_32( core_brate_inp, brate_intermed_tbl[i] ) ) { flag_hardcoded = 0; move16(); - break; + BREAK; } i = add( i, 1 ); @@ -2054,7 +2057,7 @@ ivas_error config_acelp1_IVAS( test(); test(); - if ( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) + IF( EQ_16( coder_type, TRANSITION ) && EQ_16( enc_dec, DEC ) && EQ_16( tc_call, 1 ) ) { bits = add( bits, *nBits_es_Pred ); /* equalize for 4th signaling bit estimated at the encoder in TC_0_192 */ } @@ -2066,7 +2069,7 @@ ivas_error config_acelp1_IVAS( { bits = sub( bits, TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ); - if ( EQ_16( tdm_LRTD_flag, 1 ) ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { bits = add( bits, STEREO_BITS_TCA ); } @@ -2078,7 +2081,7 @@ ivas_error config_acelp1_IVAS( test(); test(); /* subtract TBE/BWE flag */ - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { bits = sub( bits, 1 ); } @@ -2095,7 +2098,7 @@ ivas_error config_acelp1_IVAS( test(); test(); test(); - if ( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) + IF( extl_brate > 0 && ( EQ_16( extl, WB_TBE ) || EQ_16( extl, SWB_TBE ) || EQ_16( extl, FB_TBE ) || EQ_16( extl, WB_BWE ) || EQ_16( extl, SWB_BWE ) || EQ_16( extl, FB_BWE ) ) ) { /* extension layer signaling bit is counted in the extension layer bitbudget */ bits = add( bits, 1 ); @@ -2196,7 +2199,7 @@ ivas_error config_acelp1_IVAS( test(); test(); /* gain Q bit-budget - part 1 */ - IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && NE_16( coder_type, INACTIVE ) && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) || ( EQ_16( coder_type, INACTIVE ) && GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) + IF( ( NE_16( coder_type, UNVOICED ) && NE_16( coder_type, AUDIO ) && ( coder_type != INACTIVE ) && !( LE_32( core_brate, ACELP_8k00 ) && NE_16( coder_type, TRANSITION ) ) ) || ( ( coder_type == INACTIVE ) && GT_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, -1, -1 )]; move16(); @@ -2272,7 +2275,7 @@ ivas_error config_acelp1_IVAS( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_ENR ); } @@ -2284,7 +2287,7 @@ ivas_error config_acelp1_IVAS( move16(); test(); - if ( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) + IF( GT_16( coder_type, UNVOICED ) && LT_16( coder_type, AUDIO ) ) { bits = sub( bits, FEC_BITS_POS ); } @@ -2351,12 +2354,12 @@ ivas_error config_acelp1_IVAS( test(); test(); test(); - if ( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) + IF( ( ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) || ( coder_type == INACTIVE && LE_32( core_brate, ACELP_9k60 ) ) ) && ( idchan == 0 || element_mode == EVS_MONO ) ) { bits = sub( bits, NBITS_NOISENESS ); /* noiseness */ } test(); - if ( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) + IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { bits = sub( bits, ( 3 * NB_SUBFR ) ); /* tilt factor */ } @@ -2380,55 +2383,55 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( tc_subfr, TC_0_0 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 1 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_64 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 3 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_128 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 2 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, TC_0_192 ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signaling */ } - if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) + IF( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { bits = sub( bits, 1 ); /* LP filtering flag */ } } ELSE IF( EQ_16( tc_subfr, L_SUBFR ) ) { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 3 ); /* TC signaling */ } @@ -2441,7 +2444,7 @@ ivas_error config_acelp1_IVAS( } ELSE { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { bits = sub( bits, 4 ); /* TC signaling */ } @@ -2455,7 +2458,7 @@ ivas_error config_acelp1_IVAS( } ELSE /* L_frame == L_FRAME16k */ { - if ( enc_dec == ENC ) + IF( enc_dec == ENC ) { IF( LE_16( tc_subfr, 2 * L_SUBFR ) ) { @@ -2568,10 +2571,10 @@ ivas_error config_acelp1_IVAS( } ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } - acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type_sw, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->gains_mode[i] = gain_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type_sw, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } @@ -2607,12 +2610,12 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( L_frame, L_FRAME ) ) { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX( tc_subfr ) )]; move16(); } ELSE /* L_frame == L_FRAME16k */ { - acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); } bits = sub( bits, acelp_cfg->fixed_cdk_index[i] ); @@ -2624,7 +2627,7 @@ ivas_error config_acelp1_IVAS( IF( EQ_16( coder_type, UNVOICED ) && !( *uc_two_stage_flag ) ) { i = idiv1616( bits, NB_SUBFR ); - if ( i % 2 == 0 ) + IF( s_and( i, 1 ) == 0 ) { i = sub( i, 1 ); /* must be odd */ } @@ -2708,7 +2711,7 @@ ivas_error config_acelp1_IVAS( { IF( flag_hardcoded ) { - acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i * L_SUBFR, TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; + acelp_cfg->AVQ_cdk_bits[i] = AVQ_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( core_brate, coder_type, i_mult( i, L_SUBFR ), TC_SUBFR2IDX_16KHZ( tc_subfr ) )]; move16(); { bits = sub( bits, acelp_cfg->AVQ_cdk_bits[i] ); @@ -2720,7 +2723,7 @@ ivas_error config_acelp1_IVAS( test(); test(); - if ( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) + IF( GE_32( core_brate_inp, MIN_BRATE_AVQ_EXC ) && LE_32( core_brate_inp, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( coder_type, GENERIC ) ) { /* harm. flag ACELP AVQ */ bits = sub( bits, 1 ); @@ -2806,18 +2809,18 @@ ivas_error config_acelp1_IVAS( { IF( EQ_16( L_frame, L_FRAME16k ) ) { - acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_16kHz_tbl[BIT_ALLOC_IDX_16KHZ( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); } ELSE { - acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( Pitch_BR, Pitch_CT, i * L_SUBFR, 0 )]; + acelp_cfg->pitch_bits[i] = ACB_bits_tbl[BIT_ALLOC_IDX( Pitch_BR, Pitch_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->fixed_cdk_index[i] = FCB_bits_tbl[BIT_ALLOC_IDX( Local_BR, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); - acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, LOCAL_CT, i * L_SUBFR, 0 )]; + acelp_cfg->gains_mode[i] = gain_bits_tbl[BIT_ALLOC_IDX( ACELP_7k20, LOCAL_CT, i_mult( i, L_SUBFR ), 0 )]; move16(); } } @@ -3098,7 +3101,7 @@ Word16 set_ACELP_flag( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( 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 ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && ( cng_type == LP_CNG ) ) { return 1; } @@ -3230,7 +3233,7 @@ Word16 set_ACELP_flag_IVAS( test(); test(); test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) && ( 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 ) && ( idchan == 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && ( cng_type == LP_CNG ) ) { return 1; } diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 7d892f8c8..584013e2b 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -698,6 +698,8 @@ Word16 get_ivas_max_num_indices_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) { + test(); + test(); IF( EQ_16( ivas_format, STEREO_FORMAT ) ) { IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) @@ -1179,6 +1181,7 @@ Word16 get_ivas_max_num_indices_metadata_fx( ) { /* set the maximum required number of metadata indices */ + test(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { return 0; @@ -1418,7 +1421,7 @@ ivas_error check_ind_list_limits( { /* reallocate the buffer of indices with increased limit */ - IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1440,7 +1443,7 @@ ivas_error check_ind_list_limits( { /* no available empty slot -> need to re-allocate the buffer */ - IF( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1532,7 +1535,7 @@ ivas_error push_indice( move32(); /* check the limits of the list of indices */ - IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) ) { return IVAS_ERROR( error, "Error occured in push_indice() while re-allocating the list of indices (frame %d) !\n" ); } @@ -1540,8 +1543,10 @@ ivas_error push_indice( /* find the location in the list of indices based on ID */ i = hBstr->nb_ind_tot; move16(); - WHILE( i > 0 && LT_16( id, hBstr->ind_list[i - 1].id ) ) + test(); + WHILE( i > 0 && ( id < hBstr->ind_list[i - 1].id ) ) { + test(); i = sub( i, 1 ); } @@ -1649,7 +1654,7 @@ ivas_error push_next_indice( /* check the limits of the list of indices */ - IF( ( error = check_ind_list_limits( hBstr ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) ) { return error; } @@ -2102,7 +2107,7 @@ UWord16 get_indice_st( FOR( i = 0; i < nb_bits; i++ ) { value = shl( value, 1 ); - value = add( value, st->bit_stream[add( pos, i )] ); + value = add( value, st->bit_stream[pos + i] ); } return value; diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 7ca1ddf81..7d7fa3fdd 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -176,7 +176,7 @@ static Word16 rate2AMRWB_IOmode( Word32 brate /* i: bitrate */ ) { - switch ( brate ) + SWITCH( brate ) { /* EVS AMR-WB IO modes */ case SID_1k75: @@ -289,7 +289,7 @@ void push_indice_fx( /* new indice - find an empty slot in the list */ i = id; move16(); - WHILE( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) + WHILE( hBstr->ind_list[i].nb_bits != -1 ) { i = add( i, 1 ); } @@ -506,7 +506,7 @@ UWord16 get_indice_fx( /* o : value of the indice */ FOR( i = 0; i < nb_bits; i++ ) { value = lshl( value, 1 ); - value = add( value, st_fx->bit_stream[add( pos, i )] ); + value = add( value, st_fx->bit_stream[pos + i] ); } return value; @@ -703,62 +703,65 @@ void write_indices_buf_fx( UWord8 header; Word16 isAmrWb = 0; - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /*-----------------------------------------------------------------* * Encode Sync Header and Frame Length *-----------------------------------------------------------------*/ pt_stream = stream; - for ( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) + FOR( i = 0; i < ( 2 + MAX_BITS_PER_FRAME ); ++i ) { stream[i] = 0; + move16(); } //*pt_stream++ = (Word16) SYNC_GOOD_FRAME; //*pt_stream++ = hBstr->nb_bits_tot; *num_bits = hBstr->nb_bits_tot; - + move16(); /*----------------------------------------------------------------* * Bitstream packing (conversion of individual indices into a serial stream) * Writing the serial stream into file *----------------------------------------------------------------*/ - for ( i = 0; i < MAX_NUM_INDICES; i++ ) + FOR( i = 0; i < MAX_NUM_INDICES; i++ ) { - if ( hBstr->ind_list[i].nb_bits != -1 ) + IF( NE_16( hBstr->ind_list[i].nb_bits, -1 ) ) { /* mask from MSB to LSB */ - mask = 1 << ( hBstr->ind_list[i].nb_bits - 1 ); + mask = L_shl( 1, ( sub( hBstr->ind_list[i].nb_bits, 1 ) ) ); /* write bit by bit */ - for ( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) + FOR( k = 0; k < hBstr->ind_list[i].nb_bits; k++ ) { - if ( hBstr->ind_list[i].value & mask ) + IF( L_and( hBstr->ind_list[i].value, mask ) ) { //*pt_stream++ = G192_BIN1; *pt_stream++ = 1; + move16(); } - else + ELSE { //*pt_stream++ = G192_BIN0; *pt_stream++ = 0; + move16(); } - mask >>= 1; + mask = L_shr( mask, 1 ); } } } } - else + 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 * 50, &isAmrWb ) ); + header = (UWord8) ( s_or( s_or( shl( st_fx->Opt_AMR_WB, 5 ), shl( st_fx->Opt_AMR_WB, 4 ) ), rate2EVSmode( i_mult( hBstr->nb_bits_tot, 50 ), &isAmrWb ) ) ); // fwrite(&header, sizeof(UWord8), 1, file); memcpy( out_buf, &header, sizeof( UWord8 ) ); *num_bits += sizeof( UWord8 ); /* Write speech bits */ // fwrite(pFrame, sizeof(UWord8), (pFrame_size + 7) >> 3, file); - memcpy( out_buf, pFrame, sizeof( UWord8 ) * ( ( pFrame_size + 7 ) >> 3 ) ); - *num_bits += sizeof( UWord8 ) * ( ( pFrame_size + 7 ) >> 3 ); + memcpy( out_buf, pFrame, sizeof( UWord8 ) * ( shr( add( pFrame_size, 7 ), 3 ) ) ); + *num_bits += sizeof( UWord8 ) * ( shr( ( add( pFrame_size, 7 ) ), 3 ) ); } /* Clearing of indices */ @@ -769,7 +772,7 @@ void write_indices_buf_fx( } - if ( st_fx->bitstreamformat == G192 ) + IF( st_fx->bitstreamformat == G192 ) { /* write the serial stream into file */ // fwrite(stream, sizeof(unsigned short), 2 + stream[1], file); @@ -783,6 +786,9 @@ void write_indices_buf_fx( hBstr->nb_bits_tot = 0; hBstr->next_ind_fx = 0; hBstr->last_ind_fx = -1; + move16(); + move16(); + move16(); return; } @@ -920,7 +926,7 @@ void indices_to_serial_generic( FOR( k = 0; k < ind_list[i].nb_bits; k++ ) { pack_bit( ind_list[i].value & mask, &pt_pFrame, &omask ); - j++; + j = add( j, 1 ); mask = L_shr( mask, 1 ); } nb_bits_tot = add( nb_bits_tot, ind_list[i].nb_bits ); @@ -1194,7 +1200,7 @@ void decision_matrix_core_dec( move16(); } /* SC-VBR */ - ELSE IF( st->total_brate == PPP_NELP_2k80 ) + ELSE IF( EQ_32( st->total_brate, PPP_NELP_2k80 ) ) { st->core = ACELP_CORE; move16(); @@ -1232,7 +1238,7 @@ void decision_matrix_core_dec( /* 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 ) ) + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) { start_idx = add( start_idx, 1 ); } @@ -1245,7 +1251,7 @@ void decision_matrix_core_dec( start_idx = add( start_idx, 1 ); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add( start_idx, get_next_indice_fx( st, nBits ) )]; + ind = acelp_sig_tbl[start_idx + get_next_indice_fx( st, nBits )]; st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); move16(); @@ -1573,6 +1579,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem /* read the Sync Header field from the bitstream */ /* in case rew_flag is set, read until first good frame is encountered */ + test(); + test(); DO { /* read the Sync header */ @@ -1647,9 +1655,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem fprintf( stderr, "\nError, invalid number of bits read ! Exiting ! \n" ); exit( -1 ); } - test(); } - WHILE( rew_flag && ( st->bfi || LT_32( total_brate, 2800 ) ) ); + WHILE( rew_flag && ( st->bfi || ( total_brate < 2800 ) ) ); /* G.192 RX DTX handler*/ IF( !rew_flag ) @@ -1807,8 +1814,8 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem test(); test(); test(); - 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 */ + 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; move16(); @@ -1844,7 +1851,7 @@ Word16 read_indices_fx( /* o : 1 = reading OK, 0 = problem { rewind( file ); st->total_brate = total_brate; - move16(); + move32(); return 1; } @@ -1938,7 +1945,7 @@ static Word32 read_indices_mime_handle_dtx( /* SID_UPDATE check */ test(); - IF( total_brate == SID_1k75 || total_brate == SID_2k40 ) + IF( EQ_32( total_brate, SID_1k75 ) || EQ_32( total_brate, SID_2k40 ) ) { IF( st->bfi == 0 ) { @@ -2210,7 +2217,6 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem isAMRWB_IOmode = 1; move16(); qbit = s_and( shr( header, 2 ), 0x01 ); /* b2 bit (b7 is the F bit ) */ - move16(); st->bfi = !qbit; move16(); core_mode = s_and( shr( header, 3 ), 0x0F ); /* b6..b3 */ @@ -2382,8 +2388,14 @@ Word16 read_indices_mime( /* o : 1 = reading OK, 0 = problem IF( st->bfi == 0 ) { /* select MODE1 or MODE2 in MIME */ - decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); - + IF( *st->bit_stream ) + { + decoder_selectCodec( st, total_brate, G192_BIN1 ); + } + ELSE + { + decoder_selectCodec( st, total_brate, 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; move32(); @@ -2523,9 +2535,9 @@ void get_rfFlag( /* 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 ) ) + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) { - start_idx++; + start_idx = add( start_idx, 1 ); assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); } @@ -2725,12 +2737,12 @@ void get_NextCoderType_fx( FOR( k = 0; k < ACELP_13k20 / 50; k++ ) { - bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, ( k % 8 ) ) ), 0x1 ); + bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, s_and( k, 7 ) ) ), 0x1 ); move16(); } start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], ACELP_13k20 ) ) + WHILE( 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" ); @@ -2741,7 +2753,7 @@ void get_NextCoderType_fx( tmp = 0; move16(); - nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + nBits_tmp = extract_l( acelp_sig_tbl[start_idx++] ); move16(); FOR( k = 0; k < nBits_tmp; k++ ) { @@ -2749,7 +2761,7 @@ void get_NextCoderType_fx( tmp = add( tmp, bit_stream[k] ); } /* retrieve the signalling indice */ - *next_coder_type = s_and( (Word16) acelp_sig_tbl[add( start_idx, tmp )], 0x7 ); + *next_coder_type = s_and( extract_l( acelp_sig_tbl[start_idx + tmp] ), 0x7 ); move16(); } @@ -2806,7 +2818,6 @@ void read_indices_from_djb_fx( move16(); no_data = st->CNG_fx != 0; move16(); - move16(); } test(); @@ -2833,7 +2844,7 @@ void read_indices_from_djb_fx( FOR( k = 0; k < num_bits; k++ ) { test(); - IF( st->bitstreamformat == VOIP_RTPDUMP && isAMRWB_IOmode ) + IF( EQ_16( st->bitstreamformat, VOIP_RTPDUMP ) && isAMRWB_IOmode ) { st->bit_stream[sort_ptr[core_mode][k]] = unpack_bit( &pt_stream, &mask ); move16(); @@ -2877,7 +2888,15 @@ void read_indices_from_djb_fx( IF( NE_16( st->bfi, 1 ) ) { /* select Mode 1 or Mode 2 */ - decoder_selectCodec( st, total_brate, *st->bit_stream ? G192_BIN1 : G192_BIN0 ); + IF( *st->bit_stream ) + { + decoder_selectCodec( st, total_brate, G192_BIN1 ); + } + ELSE + { + decoder_selectCodec( st, total_brate, 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; @@ -2908,7 +2927,7 @@ static UWord16 get_indice_preview( bitstreamShortPtr = bitstreamShort; FOR( i = 0; i < bitstreamSize; i++ ) { - *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( i % 8 ) ) ), 0x1 ); + *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( s_and( i, 7 ) ) ) ), 0x1 ); move16(); } @@ -2918,7 +2937,7 @@ static UWord16 get_indice_preview( FOR( i = 0; i < nb_bits; i++ ) { value = shl( value, 1 ); - value = add( value, bitstreamShort[add( pos, i )] ); + value = add( value, bitstreamShort[pos + i] ); } return value; } @@ -2952,7 +2971,7 @@ void evs_dec_previewFrame( /* find the section in the ACELP signalling table corresponding to bitrate */ start_idx = 0; move16(); - WHILE( NE_32( acelp_sig_tbl[start_idx], total_brate ) ) + WHILE( 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" ); @@ -2961,11 +2980,10 @@ void evs_dec_previewFrame( /* skip the bitrate */ start_idx = add( start_idx, 1 ); /* retrieve the number of bits */ - nBits = (Word16) acelp_sig_tbl[start_idx++]; - move16(); + nBits = extract_l( acelp_sig_tbl[start_idx++] ); /* retrieve the signalling indice */ - ind = acelp_sig_tbl[add( start_idx, get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; + ind = acelp_sig_tbl[( start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; move32(); /* convert signalling indice into RF flag. */ diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 01a6d4828..2b696a4b1 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -2156,8 +2156,7 @@ void calculate_hodirac_sector_parameters_fx( return; } -#endif - +#else void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ @@ -2350,6 +2349,7 @@ void calculate_hodirac_sector_parameters( return; } +#endif /*-----------------------------------------------------------------------* diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a2aada6a9..75c7d206f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4934,19 +4934,47 @@ void ivas_sba2mc_cldfb_fixed( * DirAC prototypes *----------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); +#else ivas_error ivas_dirac_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); +#endif ivas_error ivas_dirac_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling_rate */ +); +#else void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); +#endif +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f[], /* i/o: SBA channels */ + Word32 **ppIn_FR_real, /* o : real freq domain values */ + Word32 **ppIn_FR_imag, /* o : imag freq domain values */ + Word16 pp_fr_q, + const int16_t input_frame, /* i : input frame length */ + const int16_t dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const int16_t hodirac_flag /* i : hodirac flag */ +); +#else ivas_error ivas_dirac_enc( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -4959,6 +4987,7 @@ ivas_error ivas_dirac_enc( const IVAS_FORMAT ivas_format, /* i : ivas format */ const int16_t hodirac_flag /* i : hodirac flag */ ); +#endif ivas_error ivas_dirac_config( void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ @@ -5179,8 +5208,7 @@ void calculate_hodirac_sector_parameters_fx( Word32 *ene_fx, /* o : array of sector energy values, flat */ Word16 *ene_exp /* o : array of sector energy exponents, flat */ ); -#endif - +#else void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ @@ -5194,6 +5222,7 @@ void calculate_hodirac_sector_parameters( float *diff, /* o : array of sector diffuseness values, flat */ float *ene /* o : array of sector energy values, flat */ ); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_enc_fx( @@ -6239,19 +6268,17 @@ void ivas_spar_md_enc_close( ivas_error ivas_spar_md_enc_process_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t dtx_vad, - const int16_t nchan_inp, - const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const Word16 dtx_vad, + const Word16 nchan_inp, + const Word16 sba_order, /* i : Ambisonic (SBA) order */ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ); #else ivas_error ivas_spar_md_enc_process( @@ -6268,35 +6295,6 @@ ivas_error ivas_spar_md_enc_process( const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ ); #endif -void ivas_compute_spar_params( - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - ivas_spar_md_com_cfg *hSparCfg, - ivas_spar_md_t *hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag -); - -void ivas_create_fullr_dmx_mat( - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t in_chans, - const int16_t start_band, - const int16_t end_band, - const int16_t active_w, - ivas_spar_md_com_cfg *hMdCfg -); #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( @@ -6314,19 +6312,6 @@ void ivas_create_fullr_dmx_mat_fx( ); #endif // IVAS_FLOAT_FIXED - -void ivas_calc_c_p_coeffs( - ivas_spar_md_t *pSparMd, - float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t i_ts, - float ***mixer_mat, - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad, - const int16_t compute_p_flag, - const int16_t dyn_active_w_flag -); #ifdef IVAS_FLOAT_FIXED void ivas_get_spar_md_from_dirac_fx( Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 @@ -6347,23 +6332,6 @@ void ivas_get_spar_md_from_dirac_fx( const Word16 dyn_active_w_flag ); #endif -void ivas_get_spar_md_from_dirac( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], - const int16_t n_ts, - float ***mixer_mat, - ivas_spar_md_t *hSpar_md, - ivas_spar_md_com_cfg *hSpar_md_cfg, - const int16_t start_band, - const int16_t end_band, - const int16_t order, - const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], - const uint8_t useLowerRes, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag -); /*! r: number of MD subframes */ #ifdef IVAS_FLOAT_FIXED @@ -7044,6 +7012,16 @@ void ivas_quantise_real_values_fx( Word32 *quant_fx, const Word16 dim); +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ); + void ivas_quantise_real_values_enc_fx( const Word32 *values_fx,//Q28 const Word16 q_levels, @@ -7102,11 +7080,6 @@ void ivas_copy_band_coeffs_idx_to_arr( ); #endif -void ivas_clear_band_coeffs( - ivas_band_coeffs_t *pband_coeffs, - const uint16_t num_bands -); - void ivas_clear_band_coeffs_fx( ivas_band_coeffs_t *pband_coeffs, const UWord16 num_bands); diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 3bb90ec8d..a16a4be54 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -192,9 +192,10 @@ ivas_error ivas_qmetadata_allocate_memory( set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif #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 ); +#else + set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif } } diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 9d21cfbb4..f70a74d6e 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -154,17 +154,6 @@ static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][ 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 ); - -static void ivas_reorder_array( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], const int16_t in_chans, const int16_t order[IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t start_band, const int16_t end_band ); - -static void ivas_get_Wscaling_factor( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float ***mixer_mat, const int16_t start_band, const int16_t end_band, const int16_t dtx_vad, const int16_t num_ch, const int16_t *pNum_dmx, const int16_t bands_bw, const int16_t active_w, const int16_t active_w_vlbr, float *pWscale, const int16_t dyn_active_w_flag ); - -static void ivas_calc_post_pred_per_band( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float ***mixer_mat, const int16_t num_ch, const int16_t band_idx, float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ); - -static int16_t ivas_is_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim ); - -static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int16_t dim, float out_re[MAX_MAT_DIM][MAX_MAT_DIM] ); /*-----------------------------------------------------------------------------------------* * Function ivas_get_bw_idx_from_sample_rate() @@ -528,212 +517,6 @@ Word16 ivas_get_sba_num_TCs_fx( * Calculation of prediction coefficients *-----------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs( - float *cov_real[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 ) -{ - int16_t i, j, k, b; - float abs_value; - float w_norm_fac; - float div_factor[IVAS_MAX_NUM_BANDS]; - int16_t pred_dim = in_chans - 1; - - w_norm_fac = ( from_dirac == 1 ) ? 1.0f : 3.0f; - - if ( active_w == 0 ) - { - float pPred_temp[IVAS_MAX_NUM_BANDS]; - - set_zero( pPred_temp, IVAS_MAX_NUM_BANDS ); - for ( k = start_band; k < end_band; k++ ) - { - div_factor[k] = max( 1e-20f, cov_real[0][0][k] ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; - - IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); - - pPred_temp[k] += abs_value; - } - } - - for ( k = start_band; k < end_band; k++ ) - { - pPred_temp[k] = sqrtf( pPred_temp[k] ); - div_factor[k] = max( 1.0f, pPred_temp[k] ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - ppPred_coeffs_re[i][k] = ppPred_coeffs_re[i][k] * div_factor[k]; - ppDM_Fv_re[i][k] = 0; - } - } - } - else - { - float dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; - float dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; - float num_f, den_f, passive_g; - float activew_quad_thresh, g_th_sq; - - if ( dyn_active_w_flag == 1 ) - { - activew_quad_thresh = 1.0f; - } - else - { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH; - } - g_th_sq = activew_quad_thresh * activew_quad_thresh; - - set_zero( dm_alpha, IVAS_MAX_NUM_BANDS ); - - for ( i = 1; i < in_chans; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); - dm_alpha[k] += abs_value; - } - } - - for ( k = start_band; k < end_band; k++ ) - { - dm_alpha[k] = sqrtf( dm_alpha[k] ); - div_factor[k] = max( dm_alpha[k], 1e-20f ); - div_factor[k] = 1 / div_factor[k]; - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( k = start_band; k < end_band; k++ ) - { - dm_v_re[i][k] = cov_real[i + 1][0][k] * div_factor[k]; - } - } - - if ( dtx_vad == 0 ) - { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX; - } - else - { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR : IVAS_ACTIVEW_DM_F; - } - - for ( b = start_band; b < end_band; b++ ) - { - set_zero( real, pred_dim ); - - for ( j = 0; j < pred_dim; j++ ) - { - for ( k = 1; k < in_chans; k++ ) - { - float re; - - IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - real[j] += re; - } - } - dm_beta_re = 0; - for ( k = 0; k < pred_dim; k++ ) - { - float re; - IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); - dm_beta_re += re; - } - - dm_w = cov_real[0][0][b]; - den_f = max( dm_w, 1e-20f ); - passive_g = dm_alpha[b] / den_f; - - if ( dyn_active_w_flag == 1 ) - { - dm_alpha[b] = 0.0f; - dm_w = 0.0f; - for ( i = 0; i < pred_dim; i++ ) - { - dm_v_re[i][b] = 0.0f; - } - dm_v_re[res_ind - 1][b] = 1.0f; - passive_g = activew_quad_thresh; - } - - if ( passive_g < activew_quad_thresh ) - { - /*linear activeW*/ - dm_y = 0; - - for ( k = 1; k < in_chans; k++ ) - { - dm_y += cov_real[k][k][b]; - } - den_f = max( dm_y, 1e-20f ); - den_f = max( den_f, w_norm_fac * dm_w ); - DM_F[b] = ( dm_f_local * dm_alpha[b] ) / den_f; - DM_F[b] = min( 1.0f, DM_F[b] ); - - den_f = dm_w + ( 2 * dm_alpha[b] * DM_F[b] ) + ( DM_F[b] * DM_F[b] * dm_beta_re ); - den_f = max( den_f, 1e-20f ); - - dm_g[b] = ( dm_alpha[b] + ( DM_F[b] * dm_beta_re ) ) / den_f; - } - else - { - float sqrt_val; - - /* quadratic activeW */ - - num_f = ( dm_beta_re - ( 2 * dm_alpha[b] * activew_quad_thresh ) ); - - sqrt_val = 4 * dm_alpha[b] * dm_alpha[b] * g_th_sq; - sqrt_val += dm_beta_re * dm_beta_re; - sqrt_val -= 4 * dm_beta_re * g_th_sq * dm_w; - sqrt_val = sqrtf( sqrt_val ); - num_f += sqrt_val; - - den_f = 2 * dm_beta_re * g_th_sq; - den_f = max( den_f, 1e-20f ); - dm_g[b] = activew_quad_thresh; - DM_F[b] = ( dm_g[b] * num_f ) / den_f; - } - } - - for ( i = 0; i < pred_dim; i++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - ppPred_coeffs_re[i][b] = dm_v_re[i][b] * dm_g[b]; - - ppDM_Fv_re[i][b] = dm_v_re[i][b] * DM_F[b]; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_get_pred_coeffs_fx() @@ -801,13 +584,13 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { ppPred_coeffs_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 move32(); - q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[i + 1][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE @@ -996,13 +779,13 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { dm_v_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 move32(); - dm_v_re_q[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + dm_v_re_q[i][k] = add( sub( add( q_cov_real[i + 1][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE @@ -1044,11 +827,11 @@ static void ivas_get_pred_coeffs_enc_fx( FOR( k = 1; k < in_chans; k++ ) { // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = W_mult0_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); + re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); tmp_shift = W_norm( re ); IF( re != 0 ) { - q_tmp = sub( add( add( q_cov_real[add( j, 1 )][k][b], dm_v_re_q[sub( k, 1 )][b] ), tmp_shift ), 32 ); + q_tmp = sub( add( add( q_cov_real[j + 1][k][b], dm_v_re_q[k - 1][b] ), tmp_shift ), 32 ); } ELSE { @@ -1146,7 +929,7 @@ static void ivas_get_pred_coeffs_enc_fx( dm_v_re_q[i][b] = 31; move16(); } - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; move32(); dm_v_re_q[i][b] = 31; move16(); @@ -1525,7 +1308,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 move32(); // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); @@ -1751,8 +1534,8 @@ static void ivas_get_pred_coeffs_fx( Word32 re; // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 + re = Mpy_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 move32(); } } @@ -1788,12 +1571,12 @@ static void ivas_get_pred_coeffs_fx( } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); move32(); } ELSE { - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; move32(); } passive_g = activew_quad_thresh; @@ -1917,71 +1700,6 @@ static void ivas_get_pred_coeffs_fx( * Calculation of scaling factor for post predicted W channel *-----------------------------------------------------------------------------------------*/ -static void ivas_get_Wscaling_factor( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t *pNum_dmx, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - float *pWscale, - const int16_t dyn_active_w_flag ) -{ - int16_t b, ch; - float dm_f_local, abs_val; - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - for ( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) - { - set_zero( postpred_cov_re[ch], IVAS_SPAR_MAX_CH ); - } - - if ( dtx_vad == 0 ) - { - dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX; - } - else - { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; - } - - for ( b = start_band; b < end_band; b++ ) - { - pWscale[b] = 1; - - if ( ( active_w == 1 ) && ( dyn_active_w_flag == 0 ) ) - { - float Gw_sq, g_sq = 0; - - if ( num_ch != pNum_dmx[b * bands_bw] ) - { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, b, postpred_cov_re ); - } - - Gw_sq = cov_real[0][0][b] / max( postpred_cov_re[0][0], IVAS_FLT_EPS ); - - for ( ch = 0; ch < num_ch - 1; ch++ ) - { - IVAS_CALCULATE_SQ_ABS_N( pred_coeffs_re[ch][b], abs_val ); - - g_sq += abs_val; - } - - pWscale[b] = sqrtf( Gw_sq ); - pWscale[b] = pWscale[b] + sqrtf( Gw_sq + ( 4 * dm_f_local * g_sq ) ); - pWscale[b] *= 0.5f; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_get_Wscaling_factor_enc_fx( @@ -2033,9 +1751,9 @@ static void ivas_get_Wscaling_factor_enc_fx( FOR( b = start_band; b < end_band; b++ ) { - pWscale[b] = 1; + pWscale[b] = ONE_IN_Q31; move32(); - q_pWscale[b] = 0; + q_pWscale[b] = Q31; move16(); test(); @@ -2047,7 +1765,7 @@ static void ivas_get_Wscaling_factor_enc_fx( g_sq = 0; move32(); - IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + IF( NE_16( num_ch, pNum_dmx[b * bands_bw] ) ) { ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); } @@ -2159,7 +1877,7 @@ static void ivas_get_Wscaling_factor_fx( g_sq = 0; move32(); - IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + IF( NE_16( num_ch, pNum_dmx[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 ); } @@ -2217,111 +1935,6 @@ static void ivas_get_Wscaling_factor_fx( * Calculation of downmix matrix *-----------------------------------------------------------------------------------------*/ -void ivas_create_fullr_dmx_mat( - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - float ***mixer_mat, - const int16_t in_chans, - const int16_t start_band, - const int16_t end_band, - const int16_t active_w, - ivas_spar_md_com_cfg *hMdCfg ) -{ - int16_t i, j, k, b; - const int16_t *order; - float tmp_p1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float tmp_p2_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float down_mix_mat1_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - int16_t remix_unmix_order; - int16_t nbands; - nbands = end_band - start_band; - remix_unmix_order = hMdCfg->remix_unmix_order; - - order = remix_order_set[remix_unmix_order]; - - for ( i = 0; i < in_chans; i++ ) - { - for ( j = 0; j < in_chans; j++ ) - { - set_zero( &tmp_p1_re[i][j][start_band], nbands ); - set_zero( &tmp_p2_re[i][j][start_band], nbands ); - set_zero( &down_mix_mat1_re[i][j][start_band], nbands ); - } - } - - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p2_re[j][j][b] = 1.0f; - } - } - - 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]; - } - } - - if ( active_w == 1 ) - { - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - tmp_p1_re[j][j][b] = 1.0f; - } - } - - 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]; - } - } - - /* 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++ ) - { - float tmp_re; - IVAS_RMULT_FLOAT( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b], tmp_re ); - down_mix_mat1_re[i][j][b] += tmp_re; - } - } - } - } - } - 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]; - } - } - } - } - - if ( remix_unmix_order != 3 ) - { - ivas_reorder_array( down_mix_mat1_re, in_chans, order, mixer_mat, start_band, end_band ); - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_create_fullr_dmx_mat_fx( @@ -2380,7 +1993,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[sub( j, 1 )][b] ); + tmp_p2_re[j][0][b] = L_negate( 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] ) ); } @@ -2408,7 +2021,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[sub( j, 1 )][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] ) ); } @@ -2469,32 +2082,6 @@ void ivas_create_fullr_dmx_mat_fx( * reorders the input matrix based on order *-----------------------------------------------------------------------------------------*/ -static void ivas_reorder_array( - float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], - const int16_t in_chans, - const int16_t order[IVAS_SPAR_MAX_CH], - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band ) -{ - int16_t i, j, b, idx; - - for ( i = 0; i < in_chans; i++ ) - { - idx = order[i]; - - for ( j = 0; j < in_chans; j++ ) - { - for ( b = start_band; b < end_band; b++ ) - { - mixer_mat[i][j][b] = in_re[idx][j][b]; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_reorder_array_fx( Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], @@ -2531,70 +2118,6 @@ static void ivas_reorder_array_fx( * Calculate post pred mat per band *-----------------------------------------------------------------------------------------*/ -static void ivas_calc_post_pred_per_band( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float ***mixer_mat, - const int16_t num_ch, - const int16_t band_idx, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) -{ - int16_t i, j, k; - float dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float tmp_re; - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; - } - } - - for ( i = 0; i < num_ch; i++ ) - { - set_zero( postpred_cov_re[i], num_ch ); - } - - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - temp_mat[i][j] = 0; - for ( k = 0; k < num_ch; k++ ) - { - IVAS_RMULT_FLOAT( cov_real[i][k][band_idx], dmx_mat_conj[k][j], tmp_re ); - temp_mat[i][j] += tmp_re; - } - } - } - - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) - { - for ( j = i; j < num_ch; j++ ) - { - for ( k = 0; k < num_ch; k++ ) - { - IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); - postpred_cov_re[i][j] += tmp_re; - } - } - } - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < i; j++ ) - { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_post_pred_per_band_enc_fx( @@ -2879,198 +2402,9 @@ static void ivas_calc_post_pred_per_band_fx( * * Calculate P coeffs per band *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED -static void ivas_calc_p_coeffs_per_band( - ivas_spar_md_t *pSparMd, - const int16_t i_ts, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, - const int16_t dtx_vad, - const int16_t num_dmx, - const int16_t band_idx ) -{ - int16_t i, j, k; - int16_t m; - float factor = 0; - float recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; - float trace = 0; - float p_norm_scaling = 0; - float cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; - float cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; - int16_t b_ts_idx; - - b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - - if ( num_dmx != num_ch ) - { - set_zero( pSparMd->band_coeffs[b_ts_idx].P_re, IVAS_SPAR_MAX_CH - 1 ); - set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); - for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) - { - set_zero( recon_uu_re[i], IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); - } - - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; - } - } - - if ( dtx_vad == 1 ) - { - 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]; - } - } - - if ( num_dmx == 2 ) - { - float re1, re2; - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); - - for ( i = 0; i < 2; i++ ) - { - for ( j = 0; j < 2; j++ ) - { - cov_uu_re[i][j] -= recon_uu_re[i][j]; - } - } - } - else if ( num_dmx == 3 ) - { - float re1[2], re2; - set_f( re1, 0, 2 ); - - for ( j = 0; j < 2; j++ ) - { - for ( k = 0; k < 2; k++ ) - { - float re; - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); - re1[j] += re; - } - } - - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); - recon_uu_re[0][0] = re2; - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); - recon_uu_re[0][0] += re2; - - cov_uu_re[0][0] -= recon_uu_re[0][0]; - } - else if ( num_dmx == 4 ) - { - /* Step 1: Multiply C * cov_dd * C' */ - float re1[3], re; - - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - set_f( re1, 0, 3 ); - for ( m = 0; m < num_dmx - 1; m++ ) - { - for ( k = 0; k < num_dmx - 1; k++ ) - { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); - re1[m] += re; - } - } - for ( j = 0; j < num_ch - num_dmx; j++ ) - { - for ( m = 0; m < num_dmx - 1; m++ ) - { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); - recon_uu_re[i][j] += re; - } - } - } - - /* Step 2: cov_uu - recon_uu */ - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - for ( j = 0; j < num_ch - num_dmx; j++ ) - { - cov_uu_re[i][j] -= recon_uu_re[i][j]; - } - } - } - } - - p_norm_scaling = IVAS_P_NORM_SCALING; - - if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) - { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX; - } - - trace = 0.0f; - - for ( i = num_dmx; i < num_ch; i++ ) - { - float tmp_out; - IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); - trace += tmp_out; - } - - factor = max( 1e-20f, postpred_cov_re[0][0] ); - factor = max( factor, ( p_norm_scaling * trace ) ); - factor = 1 / factor; - - /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - if ( i == j ) - { - /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] *= factor; - } - else - { - /* set off-diag elements to zero */ - cov_uu_re[i - num_dmx][j - num_dmx] = 0; - } - } - } - - /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) - { - cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); - /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ - } - - /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) - { - for ( j = num_dmx; j < num_ch; j++ ) - { - if ( i == j ) - { - pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; - } - } - } - } - - return; -} - -#ifdef IVAS_FLOAT_FIXED - -static void ivas_calc_p_coeffs_per_band_enc_fx( +static void ivas_calc_p_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3111,7 +2445,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; move32(); } } @@ -3124,7 +2458,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3317,7 +2651,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re, q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); move32(); } } @@ -3334,7 +2668,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], 1 ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); move32(); } } @@ -3483,7 +2817,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ) ); + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); @@ -3520,24 +2854,24 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - W_tmp = W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ); + W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); q_tmp = 32; move16(); if ( W_tmp != 0 ) { q_tmp = W_norm( W_tmp ); } - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); + q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); move16(); } ELSE { /* set off-diag elements to zero */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + cov_uu_re[i - num_dmx][j - num_dmx] = 0; move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = 0; move16(); } } @@ -3549,12 +2883,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( /* take sqrt of max of diags and zero */ FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); + 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 ); move32(); - q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] = sub( 31, cov_uu_re_exp ); + q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] = sub( 31, cov_uu_re_exp ); move16(); - q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); + q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); } /* save into MD struct */ @@ -3564,12 +2898,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )], q_tmp ) ); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); move32(); } } } - pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_tmp; + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = Q28; move16(); } @@ -3614,7 +2948,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; move32(); } } @@ -3627,7 +2961,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3741,7 +3075,7 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[sub( i, num_dmx )][sub( 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] ); @@ -3760,7 +3094,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), tmp ) ); + 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 ), tmp ) ); move32(); } ELSE @@ -3777,8 +3111,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); - cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = L_shl( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + 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(); } @@ -3790,7 +3124,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; move32(); } } @@ -3810,96 +3144,6 @@ static void ivas_calc_p_coeffs_per_band_fx( * * Calculate C coeffs per band *-----------------------------------------------------------------------------------------*/ - -static void ivas_calc_c_coeffs_per_band( - ivas_spar_md_t *pSparMd, - const int16_t i_ts, - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad ) -{ - int16_t i, j, k; - - /* worst case for cov_ud is actually 12 x 3 */ - float cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - float cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - float cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; - float trace_cov_dd_re = 0; - float abs_trace; - float re; - int16_t b_ts_idx; - - b_ts_idx = band_idx + i_ts * IVAS_MAX_NUM_BANDS; - - if ( dtx_vad == 0 ) - { - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - 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]; - } - } - - 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 = 0; i < num_dmx - 1; i++ ) - { - trace_cov_dd_re += cov_dd_re[i][i]; - } - trace_cov_dd_re *= 0.005f; - - IVAS_CALCULATE_RABS( trace_cov_dd_re, abs_trace ); - - if ( abs_trace < IVAS_FLT_EPS ) - { - /* protection from cases when variance of residual channels is very small */ - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - } - else - { - for ( i = 0; i < num_dmx - 1; i++ ) - { - cov_dd_re[i][i] += trace_cov_dd_re; - } - if ( ivas_is_mat_inv( cov_dd_re, num_dmx - 1 ) && ( num_dmx < FOA_CHANNELS ) ) - { - set_zero( &pSparMd->band_coeffs[b_ts_idx].C_re[0][0], ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - } - else - { - ivas_calc_mat_inv( cov_dd_re, num_dmx - 1, cov_dd_re_inv ); - - 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[i][j] = 0; - for ( k = 0; k < num_dmx - 1; k++ ) - { - IVAS_RMULT_FLOAT( cov_ud_re[i][k], cov_dd_re_inv[k][j], re ); - pSparMd->band_coeffs[b_ts_idx].C_re[i][j] += re; - } - } - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_c_coeffs_per_band_enc_fx( @@ -3938,7 +3182,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -3954,7 +3198,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { max_val = L_max( max_val, postpred_cov_re[i][j] ); } - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4087,7 +3331,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4096,7 +3340,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; move32(); } } @@ -4187,57 +3431,6 @@ static void ivas_calc_c_coeffs_per_band_fx( * Calculation of C and P coeffs *-----------------------------------------------------------------------------------------*/ -void ivas_calc_c_p_coeffs( - ivas_spar_md_t *pSparMd, - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const int16_t i_ts, - float ***mixer_mat, - const int16_t num_ch, - const int16_t num_dmx, - const int16_t band_idx, - const int16_t dtx_vad, - const int16_t compute_p_flag, - const int16_t dyn_active_w_flag ) -{ - int16_t i, j; - float postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - - if ( num_dmx != num_ch ) - { - ivas_calc_post_pred_per_band( cov_real, mixer_mat, num_ch, band_idx, postpred_cov_re ); - - if ( num_dmx != 1 ) - { - ivas_calc_c_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); - } - - if ( dyn_active_w_flag ) - { - for ( i = 0; i < num_ch - num_dmx; i++ ) - { - for ( j = 0; j < num_dmx - 1; j++ ) - { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re[i][j] = 0.0f; - } - } - } - if ( compute_p_flag == 1 ) - { - ivas_calc_p_coeffs_per_band( pSparMd, i_ts, postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); - } - - if ( dyn_active_w_flag ) - { - for ( i = num_dmx; i < num_ch; i++ ) - { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re[i - num_dmx] = 0; - } - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_calc_c_p_coeffs_enc_fx( @@ -4272,11 +3465,11 @@ void ivas_calc_c_p_coeffs_enc_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( 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; move32(); } } - pSparMd->band_coeffs[add( band_idx, imult1616( 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 ) ) @@ -4288,10 +3481,10 @@ void ivas_calc_c_p_coeffs_enc_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[i - num_dmx] = 0; move32(); } - pSparMd->band_coeffs[add( band_idx, imult1616( 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(); } } @@ -4331,11 +3524,11 @@ void ivas_calc_c_p_coeffs_fx( { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( 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; move32(); } } - pSparMd->band_coeffs[add( band_idx, imult1616( 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 ) ) @@ -4347,10 +3540,10 @@ void ivas_calc_c_p_coeffs_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; + pSparMd->band_coeffs[band_idx + ( i_ts * IVAS_MAX_NUM_BANDS )].P_re_fx[i - num_dmx] = 0; move32(); } - pSparMd->band_coeffs[add( band_idx, imult1616( 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(); } } @@ -4360,58 +3553,6 @@ void ivas_calc_c_p_coeffs_fx( #endif // IVAS_FLOAT_FIXED - -static void ivas_calc_mat_det( - double in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim, - double *det_re ) -{ - if ( dim == IVAS_MAT_DIM_3 ) - { - double re1, re2, re; - IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][2], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][1], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][0], re, re1 ); - - *det_re = re1; - - IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][2], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][2], in_re[2][0], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][1], re, re1 ); - - *det_re -= re1; - - IVAS_RMULT_DOUBLE( in_re[1][0], in_re[2][1], re1 ); - IVAS_RMULT_DOUBLE( in_re[1][1], in_re[2][0], re2 ); - re = re1 - re2; - - IVAS_RMULT_DOUBLE( in_re[0][2], re, re1 ); - - *det_re += re1; - } - else if ( dim == IVAS_MAT_DIM_2 ) - { - double re1, re2; - IVAS_RMULT_DOUBLE( in_re[0][0], in_re[1][1], re1 ); - IVAS_RMULT_DOUBLE( in_re[0][1], in_re[1][0], re2 ); - *det_re = re1 - re2; - } - else if ( dim == IVAS_MAT_DIM_1 ) - { - *det_re = in_re[0][0]; - } - else - { - assert( !"matrix dimention not supported!" ); - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( @@ -4488,36 +3629,6 @@ static void ivas_calc_mat_det_fx( * Calculate cofactor for invert matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_get_mat_cofactor( - double in_re[MAX_MAT_DIM][MAX_MAT_DIM], - double out_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t row, - const int16_t col ) -{ - int16_t i, j; - int16_t r = 0, c = 0; - - for ( i = 0; i < MAX_MAT_DIM; i++ ) - { - for ( j = 0; j < MAX_MAT_DIM; j++ ) - { - if ( i != row && j != col ) - { - - out_re[r][c++] = in_re[i][j]; - } - } - if ( c == 2 ) - { - r++; - c = 0; - } - } - - return; -} - - #ifdef IVAS_FLOAT_FIXED static void ivas_get_mat_cofactor_fx( @@ -4563,99 +3674,6 @@ static void ivas_get_mat_cofactor_fx( * Calculate Invert of a matrix *-----------------------------------------------------------------------------------------*/ -static void ivas_calc_mat_inv( - float in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim, - float out_re[MAX_MAT_DIM][MAX_MAT_DIM] ) -{ - double det; - int16_t i, j; - double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM]; - double dbl_out_re[MAX_MAT_DIM][MAX_MAT_DIM]; - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - dbl_in_re[i][j] = in_re[i][j]; - } - } - - if ( dim == IVAS_MAT_DIM_1 ) - { - det = ( dbl_in_re[0][0] * dbl_in_re[0][0] ); - /* assert to catch cases when input is singular matrix*/ - assert( det > 0 ); - det = 1 / det; - dbl_out_re[0][0] = dbl_in_re[0][0] * det; - } - else if ( dim == IVAS_MAT_DIM_2 ) - { - double det_re; - double re; - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - det = ( det_re * det_re ); - /* assert to catch cases when input is singular matrix*/ - assert( det > 0 ); - det = 1 / det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][1], re ); - dbl_out_re[0][0] = re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][1], re ); - dbl_out_re[0][1] = -re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[1][0], re ); - dbl_out_re[1][0] = -re * det; - - IVAS_RMULT_DOUBLE( det_re, dbl_in_re[0][0], re ); - dbl_out_re[1][1] = re * det; - } - else if ( dim == IVAS_MAT_DIM_3 ) - { - double fac_re[IVAS_MAT_DIM_3][IVAS_MAT_DIM_3]; - double det_re; - int16_t sign = 1; - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - det = det_re > 0 ? 1 / max( IVAS_DBL_EPS, det_re ) : min( det_re, -IVAS_DBL_EPS ); - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - ivas_get_mat_cofactor( dbl_in_re, fac_re, i, j ); - ivas_calc_mat_det( fac_re, IVAS_MAT_DIM_2, &dbl_out_re[j][i] ); - dbl_out_re[j][i] = dbl_out_re[j][i] * det * sign; - - if ( ( ( i + j ) & 1 ) == 0 ) - { - sign = -1; - } - else - { - sign = 1; - } - } - } - } - else - { - assert( !"matrix dimension not supported!" ); - } - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - out_re[i][j] = (float) dbl_out_re[i][j]; - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( @@ -4790,35 +3808,6 @@ static void ivas_calc_mat_inv_fx( * Check if matrix is invertible or not by checking if determinant is 0 or very close to 0 *-----------------------------------------------------------------------------------------*/ -static int16_t ivas_is_mat_inv( - float in_re[MAX_MAT_DIM][MAX_MAT_DIM], - const int16_t dim ) -{ - int16_t is_det_zero = 0; - double det, det_re; - int16_t i, j; - double dbl_in_re[MAX_MAT_DIM][MAX_MAT_DIM]; - - for ( i = 0; i < dim; i++ ) - { - for ( j = 0; j < dim; j++ ) - { - dbl_in_re[i][j] = in_re[i][j]; - } - } - - ivas_calc_mat_det( dbl_in_re, dim, &det_re ); - - det = ( det_re * det_re ); - - if ( det < IVAS_DBL_EPS ) - { - is_det_zero = 1; - } - - return is_det_zero; -} - #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( @@ -4858,60 +3847,6 @@ static Word16 ivas_is_mat_inv_fx( * *-----------------------------------------------------------------------------------------*/ -void ivas_compute_spar_params( - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - const int16_t i_ts, - float ***mixer_mat, - const int16_t start_band, - const int16_t end_band, - const int16_t dtx_vad, - const int16_t num_ch, - const int16_t bands_bw, - const int16_t active_w, - const int16_t active_w_vlbr, - ivas_spar_md_com_cfg *hSparCfg, - ivas_spar_md_t *hSparMd, - float *pWscale, - const int16_t from_dirac, - const int16_t dyn_active_w_flag ) -{ - float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - int16_t b, i, ndm; - - ivas_get_pred_coeffs( cov_real, pred_coeffs_re, dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind ); - - ivas_create_fullr_dmx_mat( pred_coeffs_re, dm_fv_re, mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); - - ivas_get_Wscaling_factor( cov_real, pred_coeffs_re, mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, dyn_active_w_flag ); - - for ( b = start_band; b < end_band; b++ ) - { - float onebyscale = 1.0f / pWscale[b]; - for ( i = 0; i < num_ch - 1; i++ ) - { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[i] = pred_coeffs_re[i][b] * onebyscale; - } - - for ( i = 0; i < num_ch; i++ ) - { - mixer_mat[0][i][b] *= pWscale[b]; - } - } - - for ( b = start_band; b < end_band; b++ ) - { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; - - if ( ndm != num_ch ) - { - ivas_calc_c_p_coeffs( hSparMd, cov_real, i_ts, mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - } - } - - return; -} - #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_enc_fx( @@ -4963,11 +3898,11 @@ void ivas_compute_spar_params_enc_fx( tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); 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[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = tmp; + hSparMd->band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q28; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -4979,7 +3914,7 @@ void ivas_compute_spar_params_enc_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + ndm = hSparCfg->num_dmx_chans_per_band[( b * bands_bw )]; move16(); IF( NE_16( ndm, num_ch ) ) @@ -5034,22 +3969,22 @@ void ivas_compute_spar_params_fx( tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + 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( tmp < 0 ) { tmp = negate( tmp ); - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], add( tmp, 22 ) ); + 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[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], sub( tmp, 22 ) ); + 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[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_pred_re_fx = Q22; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -5061,14 +3996,14 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; move16(); 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 ); - Word16 q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx; + Word16 q_tmp = hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx; IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX @@ -5076,7 +4011,7 @@ void ivas_compute_spar_params_fx( { FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( 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 ) ); move32(); } } @@ -5089,19 +4024,19 @@ void ivas_compute_spar_params_fx( } } #endif - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_C_re_fx = Q22; move16(); } - q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx; + q_tmp = hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx; move16(); FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( 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 ) ); move32(); } - hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = Q22; + hSparMd->band_coeffs[b + imult1616( i_ts, IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; move16(); } } @@ -5206,13 +4141,13 @@ void ivas_get_spar_md_from_dirac_fx( Word32 P_norm_fx[3]; Word16 idx; - ndm = hSpar_md_cfg->num_dmx_chans_per_band[sub( start_band, 1 )]; + ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; move16(); P_norm_fx[0] = 0; move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[0] = L_add( 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] ) ); move32(); } 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, sub( foa_ch, ndm ) ) )] ); @@ -5222,7 +4157,7 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[1] = L_add( 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] ) ); move32(); } 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, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); @@ -5232,7 +4167,7 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ; i < sub( num_ch, ndm ); i++ ) { - P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + P_norm_fx[2] = L_add( 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] ) ); move32(); } 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, sub( num_ch, ndm ) ) )] ); @@ -5240,8 +4175,8 @@ void ivas_get_spar_md_from_dirac_fx( FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + 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] ); move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -5258,8 +4193,8 @@ void ivas_get_spar_md_from_dirac_fx( } FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + 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] ); IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -5275,8 +4210,8 @@ void ivas_get_spar_md_from_dirac_fx( } FOR( ; i < sub( num_ch, ndm ); i++ ) { - idx = sub( remix_order[add( i, ndm )], ndm ); - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + idx = sub( remix_order[i + ndm], ndm ); + 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] ); move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -5574,7 +4509,7 @@ void ivas_get_spar_md_from_dirac_fx( IF( ( GE_16( i, ndm ) ) && ( EQ_16( 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] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[sub( i, ndm )] ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); move32(); } ELSE @@ -5660,7 +4595,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); move32(); } } @@ -5669,7 +4604,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = 0; + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = 0; move32(); } } @@ -5679,7 +4614,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], 2 ), Wscale_d[band] ); + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); move32(); } } @@ -5690,312 +4625,6 @@ void ivas_get_spar_md_from_dirac_fx( return; } #endif -/*-----------------------------------------------------------------------------------------* - * Function ivas_get_spar_md_from_dirac() - * - * - *-----------------------------------------------------------------------------------------*/ - -void ivas_get_spar_md_from_dirac( - float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], - float diffuseness[IVAS_MAX_NUM_BANDS], - const int16_t n_ts, - float ***mixer_mat, - ivas_spar_md_t *hSpar_md, - ivas_spar_md_com_cfg *hSpar_md_cfg, - const int16_t start_band, - const int16_t end_band, - const int16_t order, - const int16_t dtx_vad, - float Wscale_d[IVAS_MAX_NUM_BANDS], - const uint8_t useLowerRes, - const int16_t active_w_vlbr, - const int16_t dyn_active_w_flag ) -{ - int16_t num_ch, band, i, j; - int16_t block, ch; - float response_avg[MAX_OUTPUT_CHANNELS]; - float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; - float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - float Wscale[IVAS_MAX_NUM_BANDS]; - float mixer_mat_local[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 *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; - float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; - int16_t active_w; - - int16_t ndm, foa_ch, hoa2_ch; - float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; - const int16_t *remix_order; - - remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - - num_ch = ivas_sba_get_nchan_metadata( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - - hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - - foa_ch = FOA_CHANNELS; - diff_norm_order1 = 3.0f; - diff_norm_order2 = 5.0f; - diff_norm_order3 = 7.0f; - - 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]; - } - ppMixer_mat[i] = pMixer_mat[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]; - int16_t idx; - - ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; - P_norm[0] = 0.0f; - for ( i = 0; i < max( 0, foa_ch - ndm ); 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[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - - P_norm[1] = 0.0f; - 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] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - - P_norm[2] = 0.0f; - 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] *= diff_norm_order3 / min( diff_norm_order3, 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] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); - } - 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] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); - } - 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] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); - } - } - - for ( int16_t i_ts = 0; i_ts < n_ts; i_ts++ ) - { - for ( band = start_band; band < end_band; band++ ) - { - ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; - - /*SPAR from DirAC*/ - set_f( response_avg, 0.0f, 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 ); - } - else if ( useLowerRes ) - { - ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - } - else - { - 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 ); - } - - /* average responses in all subframes*/ - { - float norm; - int16_t num_ch_order, hoa2_ch_order; - - num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = ivas_sba_get_nchan( SBA_HOA2_ORDER, 0 ); - - for ( ch = 0; ch < num_ch_order; ch++ ) - { - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - response_avg[ch] += response[block][ch]; - } - response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; - } - - /*normalize 1st order*/ - norm = 0.0f; - for ( ch = 1; ch < foa_ch; ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = 1; ch < foa_ch; ch++ ) - { - response_avg[ch] /= norm; - } - - /*normalize 2nd order*/ - norm = 0.0f; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) - { - response_avg[ch] /= norm; - } - - /*normalize 3rd order*/ - norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) - { - norm += response_avg[ch] * response_avg[ch]; - } - norm = max( EPSILON, sqrtf( norm ) ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) - { - response_avg[ch] /= norm; - } - } - } - - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) - { - response_avg[i] = response_avg[HOA_keep_ind[i]]; - } - - en_ratio_fac = ( 1.0f - diffuseness[band] ); - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - if ( i == j ) - { - if ( i == 0 ) - { - cov_real_dirac[i][i][band] = 1.0f; - } - else - { - cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - - if ( hSpar_md_cfg->nchan_transport <= 2 ) - { - - cov_real_dirac[i][j][band] *= en_ratio_fac; - if ( ( i >= ndm ) && ( dtx_vad == 1 ) ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; - } - else - { - if ( i < foa_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; - } - else if ( i < hoa2_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; - } - else - { - cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; - } - } - } - else - { - if ( i < foa_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; - } - else if ( i < hoa2_ch ) - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; - } - else - { - cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; - } - } - } - } - else - { - cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; - } - } - } - } - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - pCov_real[i][j] = cov_real_dirac[i][j]; - } - } - - - active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); - - 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 ); - - if ( mixer_mat != NULL ) - { - for ( band = start_band; band < end_band; band++ ) - { - ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; - - for ( i = 0; i < ndm; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat[i][j][band]; - } - } - - for ( i = ndm; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0.0f; - } - } - - if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_mat[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] *= Wscale_d[band]; - } - } - } - } - } - - return; -} - /*------------------------------------------------------------------------- * ivas_dirac_dec_get_response() * @@ -8228,11 +6857,11 @@ void ivas_dirac_dec_get_response_fx( move16(); c_fx_better = local_result_table[el][a]; move32(); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); } @@ -8247,10 +6876,10 @@ void ivas_dirac_dec_get_response_fx( { c_fx_better = L_negate( c_fx_better ); } - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); } @@ -8810,9 +7439,9 @@ void ivas_spar_bitrate_dist_fx( FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[sub( sub( nchan_transport, 1 ), i )] = sub( core_bits_act[sub( sub( nchan_transport, 1 ), i )], min( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ) ); + core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); move16(); - overflow_bits = sub( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ); + overflow_bits = sub( overflow_bits, core_range_bits[nchan_transport - 1 - i] ); IF( overflow_bits <= 0 ) { @@ -8832,7 +7461,7 @@ void ivas_spar_bitrate_dist_fx( overflow_bits = sub( overflow_bits, overflow_bits_ch ); } - core_bits_act[sub( nchan_transport, 1 )] = sub( core_bits_act[sub( nchan_transport, 1 )], max( 0, overflow_bits ) ); + core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], max( 0, overflow_bits ) ); move16(); } } diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index d26cd9bb8..3c7b4e620 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -90,6 +90,75 @@ void ivas_quantise_real_values( return; } +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ) +{ + Word16 i; + Word32 q_step_fx, one_by_q_step_fx; + test(); + IF( EQ_16( q_levels, 1 ) ) + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = 0; + move32(); + index[i] = 0; + move16(); + } + } + ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) + { + Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // Q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // Q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // Q28 + Word16 exp; + Word16 one_by_max_min = BASOP_Util_Divide3232_Scale( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ), &exp ); // Q(15-exp) + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // Q(15-exp) + Word32 val_fx; + IF( LT_16( inp_q, Q28 ) ) + { + FOR( i = 0; i < dim; i++ ) + { + val_fx = L_max( L_shr( min_value_fx, sub( Q28, inp_q ) ), L_min( values_fx[i], L_shr( max_value_fx, sub( Q28, inp_q ) ) ) ); // Q(inp_q) + val_fx = L_shl( val_fx, sub( Q28, inp_q ) ); // Q28 + index[i] = round_fx( L_shl( Mpy_32_32( one_by_q_step_fx, val_fx ), add( Q4, exp ) ) ); // Q0 + move16(); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // Q28 + move32(); + } + } + ELSE + { + FOR( i = 0; i < dim; i++ ) + { + val_fx = L_max( min_value_fx, L_min( L_shr( values_fx[i], sub( inp_q, Q28 ) ), max_value_fx ) ); // Q28 + index[i] = round_fx( L_shl( Mpy_32_32( one_by_q_step_fx, val_fx ), add( Q4, exp ) ) ); // Q0 + move16(); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // Q28 + move32(); + } + } + } + ELSE + { + FOR( i = 0; i < dim; i++ ) + { + quant_fx[i] = values_fx[i]; + move32(); + } + } + return; +} + + #ifdef IVAS_FLOAT_FIXED void ivas_quantise_real_values_fx( const Word32 *values_fx, @@ -640,24 +709,6 @@ void ivas_copy_band_coeffs_idx_to_arr( * * clear band coeffs array in SPAR MD *-----------------------------------------------------------------------------------------*/ -void ivas_clear_band_coeffs( - ivas_band_coeffs_t *pband_coeffs, - const uint16_t num_bands ) -{ - uint16_t i; - - for ( i = 0; i < num_bands; i++ ) - { - set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) ); - set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); - 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; -} #ifdef IVAS_FLOAT_FIXED void ivas_clear_band_coeffs_fx( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 4fde550bd..bfe312557 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -191,22 +191,15 @@ 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_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; - Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 pred_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q22 for dec Word16 q_C_re_fx; - Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; // Q22 for dec Word16 q_P_re_fx; - Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 - Word32 pred_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 P_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q22 for dec + 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]; - Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; // Q28 + Word32 P_quant_re_fx[IVAS_SPAR_MAX_CH - 1]; } ivas_band_coeffs_t; typedef struct ivas_band_coeffs_ind_t @@ -547,9 +540,10 @@ typedef struct ivas_qdirection_band_data_struct int16_t elevation_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; int16_t azimuth_m_alphabet[MAX_PARAM_SPATIAL_SUBFRAMES]; - float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #ifdef IVAS_FLOAT_FIXED Word32 energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q30 */ +#else + float energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES]; #endif uint8_t distance[MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -562,8 +556,8 @@ typedef struct ivas_qdirection_band_data_struct float q_azimuth[MAX_PARAM_SPATIAL_SUBFRAMES]; float q_elevation[MAX_PARAM_SPATIAL_SUBFRAMES]; #else - Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ - Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_azimuth_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ + Word32 q_elevation_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; /* Q22 */ #endif } IVAS_QDIRECTION_BAND_DATA; @@ -619,7 +613,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; diff --git a/lib_dec/gain_dec_fx.c b/lib_dec/gain_dec_fx.c index 61ef5f11a..e118b787d 100644 --- a/lib_dec/gain_dec_fx.c +++ b/lib_dec/gain_dec_fx.c @@ -43,25 +43,25 @@ void Es_pred_dec_fx( SWITCH( nb_bits ) { case 5: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; /*Q8*/ move16(); BREAK; case 4: - *Es_pred = Es_pred_qua_4b_fx[enr_idx]; + *Es_pred = Es_pred_qua_4b_fx[enr_idx]; /*Q8*/ move16(); BREAK; case 3: - *Es_pred = Es_pred_qua_3b_fx[enr_idx]; + *Es_pred = Es_pred_qua_3b_fx[enr_idx]; /*Q8*/ break; default: - *Es_pred = Es_pred_qua_5b_fx[enr_idx]; + *Es_pred = Es_pred_qua_5b_fx[enr_idx]; /*Q8*/ move16(); BREAK; } } ELSE { - *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; + *Es_pred = Es_pred_qua_4b_no_ltp_fx[enr_idx]; /*Q8*/ move16(); } } @@ -116,7 +116,7 @@ void gain_dec_tc_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code @@ -124,13 +124,13 @@ void gain_dec_tc_fx( /*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) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ @@ -138,7 +138,7 @@ void gain_dec_tc_fx( /* Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ 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 */ @@ -177,7 +177,7 @@ void gain_dec_tc_fx( } ELSE /* nBits == 3 */ { - wgain_code = tbl_gain_code_tc_fx[index]; + wgain_code = tbl_gain_code_tc_fx[index]; /*Q13*/ move16(); } @@ -188,18 +188,18 @@ void gain_dec_tc_fx( /* *gain_code *= gcode0;*/ 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 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 2 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 2 ) ); #endif - move32(); /* Q14 -> Q16 */ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ 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 ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -256,7 +256,7 @@ void gain_dec_tc_ivas_fx( /*----------------------------------------------------------------* * find number of bits for gain dequantization *----------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.gains_mode[shr( i_subfr_fx, 6 )]; + nBits = st_fx->acelp_cfg.gains_mode[( i_subfr_fx / 64 )]; move16(); /*-----------------------------------------------------------------* * calculate the predicted gain code @@ -264,13 +264,13 @@ void gain_dec_tc_ivas_fx( /*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) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); move16(); /* gain_inov in Q12 */ @@ -278,7 +278,7 @@ void gain_dec_tc_ivas_fx( /* Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ 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 */ @@ -302,7 +302,7 @@ void gain_dec_tc_ivas_fx( *------------------------------------------------------------------------------------------*/ /* index = (Word16)get_indice( st_fx,"gain_code", i_subfr_fx, ACELP_CORE);move16();*/ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ IF( GT_16( nBits, 3 ) ) @@ -321,16 +321,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 ) ); - move32(); /* Q13 -> Q16 */ + L_tmp = L_mult( wgain_code, gcode0_fx ); /* Q12*Q0 -> Q13 */ + *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 3 ) ); /* Q13 -> Q16 */ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ 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 ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -388,7 +388,7 @@ 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[( i_subfr_fx / 64 )]; move16(); test(); @@ -400,7 +400,7 @@ void gain_dec_mless_fx( ( 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_fx( st_fx, shr( nBits, 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( nBits, 1 ) ); /*Q0*/ /*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*/ @@ -413,20 +413,20 @@ 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) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ 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 */ @@ -454,7 +454,7 @@ void gain_dec_mless_fx( /* decode normalized codebook gain */ /*index = (short)get_indice( st_fx, "gain_code", i_subfr_fx, ACELP_CORE );move16();*/ - index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); + index = (Word16) get_next_indice_fx( st_fx, shr( add( nBits, 1 ), 1 ) ); /*Q0*/ move16(); /**gain_code = gain_dequant( index, G_CODE_MIN_TC192, G_CODE_MAX_TC192, (nBits+1)>>1 );*/ @@ -463,11 +463,11 @@ void gain_dec_mless_fx( /**gain_code *= gcode0;*/ 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 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); } ELSE { @@ -475,27 +475,27 @@ void gain_dec_mless_fx( { case 7: { - qua_table_fx = gain_qua_mless_7b_fx; + qua_table_fx = gain_qua_mless_7b_fx; /*Q14*/ BREAK; } case 6: { - qua_table_fx = gain_qua_mless_6b_fx; + qua_table_fx = gain_qua_mless_6b_fx; /*Q14*/ if ( st_fx->element_mode > EVS_MONO ) { // PMT("gain_qua_mless_6b_stereo to fixed point") - qua_table_fx = gain_qua_mless_6b_stereo_fx; + qua_table_fx = gain_qua_mless_6b_stereo_fx; /*Q14*/ } BREAK; } case 5: { - qua_table_fx = gain_qua_mless_5b_fx; + qua_table_fx = gain_qua_mless_5b_fx; /*Q14*/ BREAK; } default: { - qua_table_fx = gain_qua_mless_6b_fx; + qua_table_fx = gain_qua_mless_6b_fx; /*Q14*/ BREAK; } } @@ -509,26 +509,26 @@ void gain_dec_mless_fx( index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = qua_table_fx[index * 2]; + *gain_pit_fx = qua_table_fx[index * 2]; /*Q14*/ move16(); /*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) */ + L_tmp = Dot_product12( code_fx, code_fx, L_SUBFR, &expg ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); /*Ei = 10 * (float)log10( Ecode );*/ e_tmp = norm_l( L_tmp1 ); - f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp1, e_tmp ) ); /*Q15*/ 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 */ @@ -559,13 +559,13 @@ void gain_dec_mless_fx( *-----------------------------------------------------------------*/ /**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[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /**norm_gain_code = *gain_code / *gain_inov;*/ @@ -573,7 +573,7 @@ void gain_dec_mless_fx( 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 ) ); + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -614,8 +614,8 @@ void gain_dec_lbr_fx( 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 */ + Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ const Word16 L_subfr /* i : subfr lenght */ ) { @@ -634,14 +634,14 @@ void gain_dec_lbr_fx( { 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 ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -686,9 +686,9 @@ void gain_dec_lbr_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); @@ -696,7 +696,7 @@ void gain_dec_lbr_fx( 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 ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ @@ -724,33 +724,33 @@ void gain_dec_lbr_fx( /* 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_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *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 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ - gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ + gc_mem[0] = *gain_code_fx; /*Q16*/ + move32(); + gp_mem[0] = *gain_pit_fx; /*Q14*/ + move16(); } ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { - b_fx = b_2sfr_fx; + b_fx = b_2sfr_fx; /*Q12*/ move16(); n_pred = 4; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14/Q9 */ SWITCH( nBits ) { case 7: @@ -766,18 +766,18 @@ void gain_dec_lbr_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -798,23 +798,23 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[1] = *gain_code_fx; + gc_mem[1] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[1] = *gain_pit_fx; + gp_mem[1] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) @@ -824,41 +824,41 @@ void gain_dec_lbr_fx( n_pred = 6; move16(); - cdbk_fx = gp_gamma_3sfr_6b_fx; + cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ if ( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_3sfr_7b_fx; + cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + 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 */ move16(); - aux_fx[4] = shr( gp_mem[0], 2 ); + aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); + aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ move16(); /*-----------------------------------------------------------------* @@ -879,29 +879,29 @@ void gain_dec_lbr_fx( index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 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*/ #endif move32(); - gc_mem[2] = *gain_code_fx; + gc_mem[2] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[2] = *gain_pit_fx; + gp_mem[2] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { - b_fx = b_4sfr_fx; + b_fx = b_4sfr_fx; /*Q12*/ n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; + cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ #ifdef IVAS_GAIN_MOD IF( EQ_16( nBits, 7 ) ) { @@ -911,36 +911,36 @@ void gain_dec_lbr_fx( #endif /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ + 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 */ move16(); aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -965,26 +965,26 @@ void gain_dec_lbr_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /* *norm_gain_code = *gain_code / *gain_inov; */ 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 ); /*Q15*/ + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -1000,8 +1000,8 @@ void gain_dec_lbr_ivas_fx( 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 */ + Word32 gc_mem[], /* i/o: gain_code from previous subframes Q16*/ + Word16 gp_mem[], /* i/o: gain_pitch from previous subframes Q14*/ const Word16 L_subfr /* i : subfr lenght */ ) { @@ -1020,14 +1020,14 @@ void gain_dec_lbr_ivas_fx( { 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 ); /*Q31 - 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 ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov_fx = extract_h( L_shl_sat( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1048,11 +1048,11 @@ void gain_dec_lbr_ivas_fx( test(); IF( i_subfr == 0 ) { - b_fx = b_1sfr_fx; + b_fx = b_1sfr_fx; /*Q12*/ move16(); n_pred = 2; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14*/ SWITCH( nBits ) { case 8: @@ -1073,9 +1073,9 @@ void gain_dec_lbr_ivas_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ move16(); /* gcode0 = (float)pow(10, dotp(b, aux, n_pred) - 0.5f * (float)log10(Ecode)); @@ -1083,7 +1083,7 @@ void gain_dec_lbr_ivas_fx( 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 ) ); + f_tmp = Log2_norm_lc( L_shl( L_tmp2, e_tmp ) ); /*Q15*/ e_tmp = sub( expg2, add( 1, e_tmp ) ); L_tmp1 = Mpy_32_16( e_tmp, f_tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ @@ -1111,33 +1111,33 @@ void gain_dec_lbr_ivas_fx( /* 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_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[0] = *gain_code_fx; - move32(); /*Q16*/ - gp_mem[0] = *gain_pit_fx; - move16(); /*Q14*/ + gc_mem[0] = *gain_code_fx; /*Q16*/ + move32(); + gp_mem[0] = *gain_pit_fx; /*Q14*/ + move16(); } ELSE IF( EQ_16( i_subfr, L_SUBFR ) || EQ_16( L_subfr, 2 * L_SUBFR ) ) { - b_fx = b_2sfr_fx; + b_fx = b_2sfr_fx; /*Q12*/ move16(); n_pred = 4; move16(); - cdbk_fx = gp_gamma_1sfr_6b_fx; + cdbk_fx = gp_gamma_1sfr_6b_fx; /*Q14*/ SWITCH( nBits ) { case 7: @@ -1153,18 +1153,18 @@ void gain_dec_lbr_ivas_fx( } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); aux_fx[3] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -1185,67 +1185,67 @@ void gain_dec_lbr_ivas_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[index * 2]; + *gain_pit_fx = cdbk_fx[index * 2]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move16(); /* Q10 -> Q16*/ + move16(); - gc_mem[1] = *gain_code_fx; + gc_mem[1] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[1] = *gain_pit_fx; + gp_mem[1] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 2 * L_SUBFR ) ) { - b_fx = b_3sfr_fx; + b_fx = b_3sfr_fx; /*Q12*/ move16(); n_pred = 6; move16(); - cdbk_fx = gp_gamma_3sfr_6b_fx; + cdbk_fx = gp_gamma_3sfr_6b_fx; /*Q14/Q9 */ if ( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_3sfr_7b_fx; + cdbk_fx = gp_gamma_3sfr_7b_fx; /*Q14*/ // PMT("verify if gp_gamma_3sfr_7b_fx is correct") } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + 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 */ move16(); - aux_fx[4] = shr( gp_mem[0], 2 ); + aux_fx[4] = shr( gp_mem[0], 2 ); /*Q12*/ move16(); - aux_fx[5] = shr( gp_mem[1], 2 ); + aux_fx[5] = shr( gp_mem[1], 2 ); /*Q12*/ move16(); /*-----------------------------------------------------------------* @@ -1263,70 +1263,70 @@ void gain_dec_lbr_ivas_fx( exp_gcode0 = sub( exp_gcode0, 14 ); /* retrieve the codebook index and calculate both gains */ - index = (Word16) get_next_indice_fx( st_fx, nBits ); + index = (Word16) get_next_indice_fx( st_fx, nBits ); /*Q0*/ move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *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[( ( index * 2 ) + 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*/ #endif move32(); - gc_mem[2] = *gain_code_fx; + gc_mem[2] = *gain_code_fx; /*Q16*/ move32(); - gp_mem[2] = *gain_pit_fx; + gp_mem[2] = *gain_pit_fx; /*Q14*/ move16(); } ELSE IF( EQ_16( i_subfr, 3 * L_SUBFR ) ) { - b_fx = b_4sfr_fx; + b_fx = b_4sfr_fx; /*Q12*/ n_pred = 8; move16(); - cdbk_fx = gp_gamma_4sfr_6b_fx; + cdbk_fx = gp_gamma_4sfr_6b_fx; /*Q14*/ IF( EQ_16( nBits, 7 ) ) { - cdbk_fx = gp_gamma_4sfr_7b_fx; + cdbk_fx = gp_gamma_4sfr_7b_fx; /*Q14*/ // PMT( "verify if gp_gamma_4sfr_7b_fx is correct" ) } /* calculate predicted gain */ - aux_fx[0] = 4096; + aux_fx[0] = 4096; /*Q12*/ move16(); - aux_fx[1] = shl( ctype, 12 ); + aux_fx[1] = shl( ctype, 12 ); /*Q12*/ 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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[0], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[1], e_tmp ) ); /*Q15*/ + 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 */ move16(); /*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 */ + f_tmp = Log2_norm_lc( L_shl( gc_mem[2], e_tmp ) ); /*Q15*/ + 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 */ move16(); aux_fx[5] = shr( gp_mem[0], 2 ); /*Q12*/ @@ -1353,24 +1353,24 @@ void gain_dec_lbr_ivas_fx( /* retrieve the codebook index and calculate both gains */ index = (Word16) get_next_indice_fx( st_fx, nBits ); move16(); - *gain_pit_fx = cdbk_fx[shl( index, 1 )]; + *gain_pit_fx = cdbk_fx[( index * 2 )]; /*Q14*/ move16(); - L_tmp = L_mult( cdbk_fx[add( shl( index, 1 ), 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ + L_tmp = L_mult( cdbk_fx[( ( index * 2 ) + 1 )], gcode0_fx ); /* Q9*Q0 -> Q10 */ #ifdef BASOP_NOGLOB - *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); + *gain_code_fx = L_shl_sat( L_tmp, add( exp_gcode0, 6 ) ); /*Q16*/ #else *gain_code_fx = L_shl( L_tmp, add( exp_gcode0, 6 ) ); #endif - move32(); /* Q10 -> Q16*/ + move32(); } /* *norm_gain_code = *gain_code / *gain_inov; */ 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 ); /*Q15*/ + *norm_gain_code_fx = L_shr( Mult_32_16( *gain_code_fx, tmp_fx ), sub( 1, expg ) ); /*Q15*/ move32(); return; @@ -1755,7 +1755,7 @@ 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[( i_subfr / 64 )]; move16(); /*-----------------------------------------------------------------* @@ -1786,7 +1786,7 @@ void gain_dec_SQ_fx( move16(); L_tmp1 = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); - L_tmp = Isqrt_lc( L_tmp, &expg ); + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1822,18 +1822,18 @@ void gain_dec_SQ_fx( 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 ) ); + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ #else *gain_code = L_shl( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); #endif - move32(); /*Q16*/ + move32(); /**norm_gain_code = *gain_code / *gain_inov;*/ 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 ); /*Q15*/ + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp16 ), sub( 1, expg ) ); /*Q16*/ move32(); return; @@ -1848,12 +1848,12 @@ 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 */ - 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 */ + Word16 *gain_pit, /* o : Quantized pitch gain Q14*/ + Word32 *gain_code, /* o : Quantized codeebook gain Q16*/ + Word16 *past_qua_en, /* i/o: gain quantization memory (4 words) Q10*/ + Word16 *gain_inov, /* o : unscaled innovation gain Q12*/ + const Word16 *code, /* i : algebraic code excitation Q9*/ + Word32 *norm_gain_code /* o : norm. gain of the codebook excitation Q16*/ ) { Word16 i, index, index2; @@ -1871,9 +1871,9 @@ 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 ); /*Q31 - expg*/ + expg = sub( expg, 18 + 6 ); /* exp: -18 (code in Q9), -6 (/L_SUBFR) */ + L_tmp = Isqrt_lc( L_tmp, &expg ); /*Q31 - expg*/ *gain_inov = extract_h( L_shl( L_tmp, sub( expg, 3 ) ) ); /* gain_inov in Q12 */ move16(); @@ -1939,23 +1939,23 @@ void gain_dec_amr_wb_fx( /*-----------------------------------------------------------------* * Decode code gain *-----------------------------------------------------------------*/ - qua_en = t_qua_gain[add( index2, 1 )]; + qua_en = t_qua_gain[( 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 ); /* Q-4 */ - *gain_code = L_shl( L_tmp, add( exp_gcode0, 4 ) ); - move32(); /* Q12 -> Q16 */ + L_tmp = L_mult( qua_en, gcode0 ); /* Q11*Q0 -> Q12 */ + tmp = round_fx( L_tmp ); /* Q-4 */ + *gain_code = L_shl( L_tmp, add( exp_gcode0, 4 ) ); /* Q12 -> Q16 */ + move32(); /* adjust gain according to energy of code */ 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 ); /* gcode_inov in Q12*/ #else *gain_code = L_shl( L_tmp, 3 ); #endif - move32(); /* gcode_inov in Q12*/ + move32(); /*-----------------------------------------------------------------* * update table of past quantized energies @@ -1989,8 +1989,8 @@ void gain_dec_amr_wb_fx( 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 ); /*Q15*/ + *norm_gain_code = L_shr( Mult_32_16( *gain_code, tmp ), sub( 1, expg ) ); /*Q16*/ move32(); return; diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index 5221e14f4..802cc3b41 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -53,7 +53,7 @@ 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[( i_subfr / 64 )]; move16(); gaus_dec2v_fx( st_fx, code, L_SUBFR, shr( nb_bits, 1 ) ); @@ -68,7 +68,7 @@ void gaus_dec_fx( *inv_gain_inov = extract_h( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /* inv_gain_inov in Q12 */ move16(); - nb_bits = st_fx->acelp_cfg.gains_mode[shr( i_subfr, 6 )]; + nb_bits = st_fx->acelp_cfg.gains_mode[( i_subfr / 64 )]; move16(); idx = (Word16) get_next_indice_fx( st_fx, nb_bits ); move16(); @@ -83,7 +83,7 @@ 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 ); /*Q16*/ move32(); /* update LP filtered gains for the case of frame erasures */ @@ -102,7 +102,7 @@ void gaus_dec_fx( *tilt_code = 0; move16(); - *voice_fac = -32768; /* only unvoiced */ + *voice_fac = -32768; /* only unvoiced Q15 */ move16(); *gain_pit = 0; /* needed for BASS postfitler */ move16(); @@ -127,11 +127,11 @@ void gaus_dec_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 ) ); + gain_code = round_fx( L_shl( *L_gain_code, *sQ_exc ) ); /*sQ_exc*/ FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_shl( L_mult( gain_code, code[i] ), 6 /*3*/ ); - exc[add( i, i_subfr )] = round_fx( L_tmp ); + exc[( i + i_subfr )] = round_fx( L_tmp ); /*sQ_exc+3*/ move16(); } @@ -164,10 +164,10 @@ void gaus_dec2v_fx( const Word16 *pt1, *pt2; Word16 index_delta; - step = shr( 0x80, nb_bits ); + step = shr( 0x80, nb_bits ); /*Q0*/ - idx = (Word16) get_next_indice_fx( st_fx, add( shl( nb_bits, 1 ), 1 ) ); - index_delta = (Word16) get_next_indice_fx( st_fx, 3 ); + idx = (Word16) get_next_indice_fx( st_fx, add( shl( nb_bits, 1 ), 1 ) ); /*Q0*/ + index_delta = (Word16) get_next_indice_fx( st_fx, 3 ); /*Q0*/ move16(); move16(); @@ -175,7 +175,7 @@ void gaus_dec2v_fx( delta = shl( index_delta, STEP_DELTA_FX ); delta2 = mac_r( 16384 * 65536, shr( delta, 1 ), delta ); - inv_delta = div_s( 16384, delta2 ); + inv_delta = div_s( 16384, delta2 ); /*Q15*/ IF( delta > 0 ) { @@ -184,8 +184,8 @@ void gaus_dec2v_fx( 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] ); /*Q12*/ + gaus_dico2_fx[i] = mult_r( tmp16, inv_delta ); /*Q12*/ move16(); } } @@ -198,14 +198,14 @@ void gaus_dec2v_fx( } } - pt1 = &gaus_dico2_fx[i_mult2( ind1, step )]; - pt2 = &gaus_dico2_fx[i_mult2( ind2, step )]; + pt1 = &gaus_dico2_fx[( ind1 * step )]; /*Q12*/ + pt2 = &gaus_dico2_fx[( ind2 * step )]; /*Q12*/ 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 ) ); /*Q12-exp*/ move16(); } @@ -242,9 +242,9 @@ static void dec_2pos_fx( index = shr( index, 1 ); - *ind1 = shr( index, log2_n ); + *ind1 = shr( index, log2_n ); /*Q0*/ move16(); - *ind2 = sub( index, shl( *ind1, log2_n ) ); + *ind2 = sub( index, shl( *ind1, log2_n ) ); /*Q0*/ move16(); *sign2 = *sign1; move16(); @@ -276,21 +276,21 @@ void gaus_L2_dec( Word32 tmp32; /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ - seed = *seed_acelp; + seed = *seed_acelp; /*Q0*/ move16(); FOR( i = 0; i < L_SUBFR; i++ ) { Random( &seed ); - tmp32 = L_mac( 0, seed, 1 << 9 ); + tmp32 = L_mac( 0, seed, 1 << 9 ); /*Q9*/ Random( &seed ); - tmp32 = L_mac( tmp32, seed, 1 << 9 ); + tmp32 = L_mac( tmp32, seed, 1 << 9 ); /*Q9*/ Random( &seed ); - code[i] = mac_r( tmp32, seed, 1 << 9 ); + code[i] = mac_r( tmp32, seed, 1 << 9 ); /*Q9*/ move16(); } - *seed_acelp = seed; + *seed_acelp = seed; /*Q0*/ move16(); /*Shape the gaussian excitation*/ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index beeec44b7..45a008543 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -41,6 +41,7 @@ #include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "wmc_auto.h" /*------------------------------------------------------------------------- @@ -65,80 +66,67 @@ static void computeIntensityVector_enc( DIRAC_ENC_HANDLE hDirAC, float Cldfb_Rea *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_open( +ivas_error ivas_dirac_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) { - int16_t i, j; + Word16 i, j; DIRAC_ENC_HANDLE hDirAC; - int32_t dirac_slot_ns; + Word32 dirac_slot_ns; ivas_error error; error = IVAS_ERR_OK; + move16(); - if ( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL ) + IF( ( hDirAC = (DIRAC_ENC_HANDLE) malloc( sizeof( DIRAC_ENC_DATA ) ) ) == NULL ) { 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" ) ); } hDirAC->firstrun_sector_params = 1; - set_zero( hDirAC->sec_I_vec_smth_x[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->sec_I_vec_smth_y[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->sec_I_vec_smth_z[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->azi_prev, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->ele_prev, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); - set_zero( hDirAC->energy_smth[0], NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + move16(); + + set32_fx( hDirAC->sec_I_vec_smth_x_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_x_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->sec_I_vec_smth_y_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_y_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->sec_I_vec_smth_z_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->sec_I_vec_smth_z_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->energy_smth_fx[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set16_fx( hDirAC->energy_smth_exp[0], 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->ele_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); + set32_fx( hDirAC->azi_prev_fx, 0, NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS ); /*-----------------------------------------------------------------* * DirAC main configuration *-----------------------------------------------------------------*/ st_ivas->hDirAC = hDirAC; -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_config_fx( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_config( (void *) st_ivas, ENC ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif /* set FB config. */ hDirAC->hFbMixer = NULL; - for ( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ ) + FOR( i = 0; i < DIRAC_MAX_NBANDS + 1; i++ ) { /* adapt band grouping to from CLDFB to MDFT bands */ - hDirAC->band_grouping[i] *= CLDFB_TO_MDFT_FAC; + hDirAC->band_grouping[i] = imult1616( hDirAC->band_grouping[i], CLDFB_TO_MDFT_FAC ); + move16(); } dirac_slot_ns = DIRAC_SLOT_ENC_NS; - + move16(); /* initialize delay for SPAR/DirAC delay synchronization */ /* intensity 3-dim */ - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - if ( ( hDirAC->direction_vector_m[i] = (float **) malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) - { - if ( ( hDirAC->direction_vector_m[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->direction_vector_m[i][j], 0.0f, DIRAC_MAX_NBANDS ); - } -#ifdef IVAS_FLOAT_FIXED IF( ( hDirAC->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 DirAC\n" ) ); @@ -146,38 +134,22 @@ ivas_error ivas_dirac_enc_open( FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - if ( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) + IF( ( hDirAC->direction_vector_m_fx[i][j] = (Word32 *) malloc( DIRAC_MAX_NBANDS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->direction_vector_m_fx[i][j], 0, DIRAC_MAX_NBANDS ); } -#endif } - hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - if ( ( hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( DIRAC_MAX_NBANDS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, DIRAC_MAX_NBANDS ); - } - } + Word16 tmp_e = 0; + move16(); + Word16 tmp = BASOP_Util_Divide3232_Scale( (Word32) DIRAC_NO_COL_AVG_DIFF_NS, dirac_slot_ns, &tmp_e ); + hDirAC->no_col_avg_diff = shr( tmp, sub( 15, tmp_e ) ); + + set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); + set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->buffer_energy, 0.0f, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { IF( ( hDirAC->buffer_intensity_real_fx[i] = (Word32 **) malloc( hDirAC->no_col_avg_diff * sizeof( Word32 * ) ) ) == NULL ) @@ -191,6 +163,7 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->buffer_intensity_real_fx[i][j], 0, DIRAC_MAX_NBANDS ); + set16_fx( hDirAC->buffer_intensity_real_q[i][j], Q31, hDirAC->hConfig->nbands ); } } @@ -199,23 +172,28 @@ ivas_error ivas_dirac_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } set32_fx( hDirAC->buffer_energy_fx, 0, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); -#endif + set16_fx( hDirAC->buffer_energy_q, Q31, DIRAC_MAX_NBANDS * hDirAC->no_col_avg_diff ); - if ( st_ivas->hQMetaData->useLowerRes ) + IF( st_ivas->hQMetaData->useLowerRes ) { hDirAC->block_grouping[0] = 0; hDirAC->block_grouping[1] = MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); + move16(); } - else + ELSE { - mvs2s( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( DirAC_block_grouping_5ms_MDFT, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); } hDirAC->index_buffer_intensity = 0; hDirAC->mono_frame_count = 0; + move16(); + move16(); st_ivas->hDirAC = hDirAC; st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + move16(); return error; } @@ -414,7 +392,66 @@ ivas_error ivas_dirac_enc_reconfigure( * * Close DirAC encoder handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling rate */ +) +{ + Word16 i, j; + DIRAC_ENC_HANDLE hDirAC; + IF( hDirAC_out == NULL || *hDirAC_out == NULL ) + { + return; + } + + hDirAC = *hDirAC_out; + + IF( hDirAC->hFbMixer != NULL ) + { + ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); + } + /* intensity 3-dim */ + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + free( hDirAC->direction_vector_m_fx[i][j] ); + hDirAC->direction_vector_m_fx[i][j] = NULL; + } + + FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) + { + IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) + { + free( hDirAC->buffer_intensity_real_fx[i][j] ); + hDirAC->buffer_intensity_real_fx[i][j] = NULL; + } + } + + free( hDirAC->buffer_intensity_real_fx[i] ); + hDirAC->buffer_intensity_real_fx[i] = NULL; + + free( hDirAC->direction_vector_m_fx[i] ); + hDirAC->direction_vector_m_fx[i] = NULL; + } + + free( hDirAC->buffer_energy_fx ); + hDirAC->buffer_energy_fx = NULL; + + IF( hDirAC->hConfig != NULL ) + { + free( hDirAC->hConfig ); + hDirAC->hConfig = NULL; + } + + free( *hDirAC_out ); + *hDirAC_out = NULL; + + return; +} +#else void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling rate */ @@ -439,14 +476,16 @@ void ivas_dirac_enc_close( { for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { +#ifndef IVAS_FLOAT_FIXED free( hDirAC->direction_vector_m[i][j] ); hDirAC->direction_vector_m[i][j] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hDirAC->direction_vector_m_fx[i][j] ); hDirAC->direction_vector_m_fx[i][j] = NULL; #endif } +#ifndef IVAS_FLOAT_FIXED for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { if ( hDirAC->buffer_intensity_real[i][j] != 0 ) @@ -459,7 +498,7 @@ void ivas_dirac_enc_close( free( hDirAC->buffer_intensity_real[i] ); hDirAC->buffer_intensity_real[i] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else FOR( j = 0; j < hDirAC->no_col_avg_diff; j++ ) { IF( hDirAC->buffer_intensity_real_fx[i][j] != 0 ) @@ -473,16 +512,22 @@ void ivas_dirac_enc_close( hDirAC->buffer_intensity_real_fx[i] = NULL; #endif +#ifndef IVAS_FLOAT_FIXED free( hDirAC->direction_vector_m[i] ); hDirAC->direction_vector_m[i] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hDirAC->direction_vector_m_fx[i] ); hDirAC->direction_vector_m_fx[i] = NULL; #endif } +#ifndef IVAS_FLOAT_FIXED free( hDirAC->buffer_energy ); hDirAC->buffer_energy = NULL; +#else + free( hDirAC->buffer_energy_fx ); + hDirAC->buffer_energy_fx = NULL; +#endif if ( hDirAC->hConfig != NULL ) { @@ -495,7 +540,7 @@ void ivas_dirac_enc_close( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_enc() @@ -505,178 +550,30 @@ void ivas_dirac_enc_close( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - float *data_f[], /* i/o: SBA channels */ - float **ppIn_FR_real, /* o : real freq domain values */ - float **ppIn_FR_imag, /* o : imag freq domain values */ - const int16_t input_frame, /* i : input frame length */ - const int16_t dtx_vad, /* i : DTX vad flag */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - const int16_t hodirac_flag /* i : hodirac flag */ +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f_fx[], /* i/o: SBA channels Qx */ + Word32 **pp_fr_real_fx, /* o : real freq domain values pp_fr_q */ + Word32 **pp_fr_imag_fx, /* o : imag freq domain values pp_fr_q */ + Word16 pp_fr_q, + const Word16 input_frame, /* i : input frame length Q0 */ + const Word16 dtx_vad, /* i : DTX vad flag Q0 */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 hodirac_flag /* i : hodirac flag Q0 */ ) { - int16_t orig_dirac_bands; - float dir[3], avg_dir[3]; -#ifdef IVAS_FLOAT_FIXED + Word16 orig_dirac_bands; Word32 dir_fx[3], avg_dir_fx[3]; -#endif - float energySum, vecLen; - int16_t i, j, b, i_ts; + Word16 i, j, b, i_ts; ivas_error error; push_wmops( "ivas_dirac_enc" ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*---------------------------------------------- float to fixed ----------------------------------------------*/ - - set16_fx( (Word16 *) hDirAC->buffer_energy_q, 0, DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - set16_fx( (Word16 *) hDirAC->buffer_intensity_real_q, 0, DIRAC_NUM_DIMS * DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS ); - Word16 block_m_idx; - Word16 band_m_idx; Word16 nchan_fb_in = hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS; - Word16 nblocks = hQMetaData->useLowerRes ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; - - /* Find Q-factor */ - Word16 pcm_q; - Word16 pp_fr_q; - float max_val = 0; - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( data_f[i][j] ) ); - } - } - pcm_q = Q_factor_L( max_val ); - - max_val = 0; - for ( i = 0; i < nchan_fb_in; i++ ) - { - for ( j = 0; j < input_frame; j++ ) - { - max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); - max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); - } - } - pp_fr_q = Q_factor_L( max_val ); - - Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; - Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; - Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; - Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; - for ( i = 0; i < nchan_fb_in; i++ ) - { - data_f_fx[i] = data_f_buf[i]; - pp_fr_real_fx[i] = fr_real_fx[i]; - pp_fr_imag_fx[i] = fr_imag_fx[i]; - for ( j = 0; j < input_frame; j++ ) - { - data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); - pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); - pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); - } - } - - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - for ( int k = 0; k < hDirAC->hConfig->nbands; k++ ) - { - Word16 tmp; - f2me( hDirAC->buffer_intensity_real[i][j][k], &hDirAC->buffer_intensity_real_fx[i][j][k], &tmp ); - hDirAC->buffer_intensity_real_q[i][j][k] = 31 - tmp; - } - } - } - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - Word16 tmp; - f2me( hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands], &hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], &tmp ); - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] = 31 - tmp; - } - } + move16(); - for ( i = 0; i < NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS; i++ ) - { - hDirAC->azi_prev_fx[i] = float_to_fix( hDirAC->azi_prev[i], Q23 ); - hDirAC->ele_prev_fx[i] = float_to_fix( hDirAC->ele_prev[i], Q23 ); - } - for ( i = 0; i < NUM_ANA_SECTORS; i++ ) - { - for ( j = 0; j < IVAS_MAX_NUM_BANDS; j++ ) - { - f2me( hDirAC->sec_I_vec_smth_x[i][j], &hDirAC->sec_I_vec_smth_x_fx[i][j], &hDirAC->sec_I_vec_smth_x_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_y[i][j], &hDirAC->sec_I_vec_smth_y_fx[i][j], &hDirAC->sec_I_vec_smth_y_exp[i][j] ); - f2me( hDirAC->sec_I_vec_smth_z[i][j], &hDirAC->sec_I_vec_smth_z_fx[i][j], &hDirAC->sec_I_vec_smth_z_exp[i][j] ); - } - } -#endif ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, ivas_format, hodirac_flag, nchan_fb_in, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - /*---------------------------------------------- fixed to float ----------------------------------------------*/ - for ( block_m_idx = 0; block_m_idx < nblocks; block_m_idx++ ) - { - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - if ( hodirac_flag ) - { - hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = fix_to_float( hQMetaData->q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx], Q30 ); - } - else - { - hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[0][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[1][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = me2f( hDirAC->direction_vector_m_fx[2][block_m_idx][band_m_idx], hDirAC->direction_vector_m_exp[block_m_idx] ); - } - } - } - const int N_bands = hDirAC->hConfig->nbands; - for ( int i_sec = 0; i_sec < NUM_ANA_SECTORS; i_sec++ ) - { - for ( int i_band = 0; i_band < IVAS_MAX_NUM_BANDS; i_band++ ) - { - hDirAC->sec_I_vec_smth_x[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_x_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_x_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_y[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_y_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_y_exp[i_sec][i_band] ); - hDirAC->sec_I_vec_smth_z[i_sec][i_band] = me2f( hDirAC->sec_I_vec_smth_z_fx[i_sec][i_band], hDirAC->sec_I_vec_smth_z_exp[i_sec][i_band] ); - hDirAC->azi_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->azi_prev_fx[i_sec * N_bands + i_band], Q23 ); - hDirAC->ele_prev[i_sec * N_bands + i_band] = fix_to_float( hDirAC->ele_prev_fx[i_sec * N_bands + i_band], Q23 ); - } - for ( int i_band = hDirAC->hConfig->enc_param_start_band; i_band < N_bands; i_band++ ) - { - hDirAC->energy_smth[i_sec][i_band] = me2f( hDirAC->energy_smth_fx[i_sec][i_band], hDirAC->energy_smth_exp[i_sec][i_band] ); - } - } - for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) - { - hDirAC->diffuseness_m[band_m_idx] = me2f( hDirAC->diffuseness_m_fx[band_m_idx], hDirAC->diffuseness_m_exp[band_m_idx] ); - me2f_buf( hQMetaData->q_direction->band_data[band_m_idx].energy_ratio_fx, 1, hQMetaData->q_direction->band_data[band_m_idx].energy_ratio, hQMetaData->q_direction->cfg.nblocks ); - } - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - for ( int k = 0; k < N_bands; k++ ) - { - hDirAC->buffer_intensity_real[i][j][k] = me2f( hDirAC->buffer_intensity_real_fx[i][j][k], 31 - hDirAC->buffer_intensity_real_q[i][j][k] ); - } - } - } - for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) - { - for ( j = 0; j < hDirAC->no_col_avg_diff; j++ ) - { - hDirAC->buffer_energy[i + j * hDirAC->hConfig->nbands] = me2f( hDirAC->buffer_energy_fx[i + j * hDirAC->hConfig->nbands], 31 - hDirAC->buffer_energy_q[i + j * hDirAC->hConfig->nbands] ); - } - } -#endif - IF( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -690,19 +587,18 @@ ivas_error ivas_dirac_enc( /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ IF( hQMetaData->dirac_mono_flag ) { -#ifdef IVAS_FLOAT_FIXED IF( EQ_16( dtx_vad, 1 ) ) { FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { FOR( i_ts = 0; i_ts < hQMetaData->q_direction[0].cfg.nblocks; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; -#endif hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + move32(); + move32(); + move32(); } } } @@ -712,136 +608,112 @@ ivas_error ivas_dirac_enc( { FOR( i_ts = 0; i_ts < 1; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; -#endif hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].azimuth_fx[i_ts] = 0; hQMetaData->q_direction[0].band_data[b].elevation_fx[i_ts] = 0; + move32(); + move32(); + move32(); } } } - -#else - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) - { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) - { - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; - hQMetaData->q_direction[0].band_data[b].azimuth[i_ts] = 0.0f; - hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; - } - } -#endif } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifndef MSAN_FIX - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_azimuth, hQMetaData->q_direction[i].band_data[j].q_azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].q_elevation, hQMetaData->q_direction[i].band_data[j].q_elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif - } - } -#endif IF( ( error = ivas_qmetadata_enc_encode_fx( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif } ELSE { hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; move16(); - /* compute directions */ - for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) + FOR( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) { - set_zero( dir, 3 ); - set_zero( avg_dir, 3 ); - energySum = 0.0f; + set32_fx( avg_dir_fx, 0, 3 ); + Word16 avg_dir_e = 0; + Word16 energySum_e = 0; + Word32 energySum_fx = 0; + move32(); + move16(); + move16(); /* combine all DirAC bands except the last one, handle last band separately, last band covers BW above WB */ - for ( j = 0; j < orig_dirac_bands - 1; j++ ) + FOR( j = 0; j < sub( orig_dirac_bands, 1 ); j++ ) { -#ifdef IVAS_FLOAT_FIXED ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); - /*==========================================fix-2-flt======================================================*/ - fixedToFloat_arrL( dir_fx, dir, Q30, 3 ); - /*==========================================fix-2-flt======================================================*/ - -#else - ivas_qmetadata_azimuth_elevation_to_direction_vector( hQMetaData->q_direction[0].band_data[j].azimuth[i], hQMetaData->q_direction[0].band_data[j].elevation[i], &dir[0] ); -#endif - vecLen = hQMetaData->q_direction[0].band_data[j].energy_ratio[i] * hDirAC->buffer_energy[i * orig_dirac_bands + j]; - - avg_dir[0] += dir[0] * vecLen; - avg_dir[1] += dir[1] * vecLen; - avg_dir[2] += dir[2] * vecLen; - - energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; + Word32 vecLen_fx = Mpy_32_32( hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] /*Q30*/, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j] ); + avg_dir_fx[0] = L_add( avg_dir_fx[0], Mpy_32_32( dir_fx[0], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[1] = L_add( avg_dir_fx[1], Mpy_32_32( dir_fx[1], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + avg_dir_fx[2] = L_add( avg_dir_fx[2], Mpy_32_32( dir_fx[2], vecLen_fx ) ); // Q30 + hDirAC->buffer_energy_q[i * orig_dirac_bands + j] - 1 - 31 + move32(); + move32(); + move32(); + avg_dir_e = sub( 31, ( sub( add( Q30, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), 1 - 31 ) ) ); + energySum_fx = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, hDirAC->buffer_energy_fx[i * orig_dirac_bands + j], sub( 31, hDirAC->buffer_energy_q[i * orig_dirac_bands + j] ), &energySum_e ); } -#ifdef IVAS_FLOAT_FIXED - /*==========================================flt-2-fix======================================================*/ - Word16 q_dir_e = 0; - f2me_buf( avg_dir, avg_dir_fx, &q_dir_e, 3 ); - Scale_sig32( avg_dir_fx, 3, -1 ); - /*==========================================flt-2-fix======================================================*/ + Word16 x = getScaleFactor32( avg_dir_fx, 3 ); + Scale_sig32( avg_dir_fx, 3, sub( x, 1 ) ); + avg_dir_e = sub( avg_dir_e, sub( x, 1 ) ); ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); -#else - ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); -#endif - hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); -#ifdef IVAS_FLOAT_FIXED + Word32 tmp = dotp_fixed( avg_dir_fx, avg_dir_fx, 3 ); // 2*avg_dir_e + Word16 tmp_e = shl( avg_dir_e, 1 ); + tmp = Sqrt32( tmp, &tmp_e ); + Word16 er_tmp_e = 0; + move16(); + Word16 er_tmp = 0; + move16(); + Word16 denom_e = 0; + move16(); + Word32 denom = BASOP_Util_Add_Mant32Exp( energySum_fx, energySum_e, EPSILON_FX_M, EPSILON_FX_E, &denom_e ); + + er_tmp = BASOP_Util_Divide3232_Scale( tmp, denom, &er_tmp_e ); + er_tmp_e = add( er_tmp_e, sub( tmp_e, denom_e ) ); + er_tmp = shr( er_tmp, sub( 1, ( er_tmp_e ) ) ); // Q14 + + hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[i] = L_deposit_h( er_tmp ); // Q30 hQMetaData->q_direction[0].band_data[1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i]; hQMetaData->q_direction[0].band_data[1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i]; -#else - hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; - hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; -#endif - hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; + hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i]; + move32(); + move32(); + move32(); + move32(); } /* 1 bit to indicate mode MD coding : temp solution*/ push_next_indice( hMetaData, 1, 1 ); /* encode SID parameters */ -#ifdef IVAS_FLOAT_FIXED ivas_qmetadata_enc_sid_encode_fx( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#else - ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); -#endif } + Word16 len = 0; + move16(); + IF( EQ_16( dtx_vad, 1 ) ) + { + len = hQMetaData->q_direction[0].cfg.nblocks; + } + ELSE + { + len = 1; + } + move16(); FOR( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { - FOR( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + FOR( i_ts = 0; i_ts < len; i_ts++ ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction->band_data[b].azimuth_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth_fx[i_ts]; hQMetaData->q_direction->band_data[b].elevation_fx[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation_fx[i_ts]; -#else - hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; - hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; -#endif - hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + move32(); + move32(); + move32(); } } @@ -849,28 +721,24 @@ ivas_error ivas_dirac_enc( { FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation_fx[i] = hQMetaData->q_direction[0].band_data[1].elevation_fx[0]; -#else - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; -#endif - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio_fx[0]; + move32(); + move32(); + move32(); } FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - FOR( j = orig_dirac_bands - 2; j >= 0; j-- ) + FOR( j = sub( orig_dirac_bands, 2 ); j >= 0; j-- ) { -#ifdef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[0].azimuth_fx[0]; hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = hQMetaData->q_direction[0].band_data[0].elevation_fx[0]; -#else - hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; - hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; -#endif - hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[0]; + move32(); + move32(); + move32(); } } diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c41736176..c3b8c7cbc 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -888,19 +888,6 @@ ivas_error ivas_enc( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1000,19 +987,6 @@ ivas_error ivas_enc( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1379,7 +1353,7 @@ ivas_error ivas_enc( { FOR( jj = 0; jj < nBlocks; jj++ ) { - st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio[jj] = fixedToFloat( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], Q31 ); + st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj] = L_shr( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], 1 ); // Q31 -> Q30 } } #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index b40665a98..3114ae478 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -859,10 +859,17 @@ ivas_error ivas_init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif } else { @@ -1014,10 +1021,17 @@ ivas_error ivas_init_encoder( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->ism_mode == ISM_MODE_NONE ) { @@ -1207,22 +1221,8 @@ ivas_error ivas_init_encoder( { return error; } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } #endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -1530,11 +1530,17 @@ ivas_error ivas_init_encoder_fx( { return error; } - +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif } ELSE { @@ -1679,10 +1685,17 @@ ivas_error ivas_init_encoder_fx( return error; } +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( st_ivas->ism_mode == ISM_MODE_NONE ) { @@ -1869,22 +1882,8 @@ ivas_error ivas_init_encoder_fx( { return error; } - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } #endif -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); #else @@ -2196,7 +2195,11 @@ void ivas_destroy_enc( ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); /* DirAC handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_dirac_enc_close_fx( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#else ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); +#endif /* ParamISM handle */ ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 5438bc921..a8375d542 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -398,15 +398,6 @@ ivas_error ivas_masa_encode( Word16 guard_bits, tmp; guard_bits = find_guarded_bits_fx( 24 ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[i].cfg.start_band; j < hQMetaData->q_direction[i].cfg.nbands; ++j ) - { - floatToFixed_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio, hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif masa_sid_descriptor = -1; h_orig_metadata = NULL; @@ -859,16 +850,6 @@ ivas_error ivas_masa_encode( move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < hQMetaData->no_directions; i++ ) - { - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - fixedToFloat_arrL( hQMetaData->q_direction[i].band_data[j].energy_ratio_fx, hQMetaData->q_direction[i].band_data[j].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } -#endif - return IVAS_ERR_OK; } #else diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index aaa3dd260..472043f02 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -1775,19 +1775,6 @@ static ivas_error ivas_mc_enc_reconfig( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1803,19 +1790,6 @@ static ivas_error ivas_mc_enc_reconfig( { return error; } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - if ( st_ivas->hQMetaData->q_direction != NULL ) - { - for ( int band = 0; band < st_ivas->hMasa->config.numCodingBands; band++ ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - if ( st_ivas->hQMetaData->no_directions == 2 ) - { - fixedToFloat_arrL( st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, st_ivas->hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } -#endif // IVAS_FLOAT_FIXED_CONVERSIONS #else if ( ( error = ivas_mcmasa_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index d7857435a..454b2305f 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -705,7 +705,14 @@ static ivas_error ivas_spar_cov_md_process( } ELSE { - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); + Word16 num_bands = SPAR_DIRAC_SPLIT_START_BAND; + move16(); + if ( hSpar->hMdEnc->spar_hoa_md_flag != 0 ) + { + num_bands = IVAS_MAX_NUM_BANDS; + move16(); + } + ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } } @@ -737,9 +744,9 @@ static ivas_error ivas_spar_cov_md_process( FOR( b = hSpar->hFbMixer->pFb->filterbank_num_bands; b < IVAS_MAX_NUM_BANDS; b++ ) { cov_real_fx[i][j][b] = 0; - move16(); + move32(); cov_dtx_real_fx[i][j][b] = 0; - move16(); + move32(); } } IF( ( q_cov_real[i] = (Word16 *) malloc( sizeof( Word16 ) * nchan_inp ) ) == NULL ) @@ -810,7 +817,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -847,9 +854,6 @@ static ivas_error ivas_spar_cov_md_process( test(); IF( GE_16( d_start_band, 6 ) && EQ_16( dtx_vad, 1 ) ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 ); -#endif Copy32( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re_fx, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re_fx, IVAS_SPAR_MAX_CH - 1 ); } @@ -928,26 +932,21 @@ static ivas_error ivas_spar_cov_md_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < num_ch; i++ ) + for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - for ( j = 0; j < num_ch; j++ ) - { - hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); - } + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); } + hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; + hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; } for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) - { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx ); - } - for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + for ( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) + for ( j = 0; j < num_ch; j++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], hSpar->hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); + hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); } } } @@ -959,7 +958,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag ) { - error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); + error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); } return error; @@ -1273,10 +1272,62 @@ static ivas_error ivas_spar_enc_process( hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); #endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 pcm_q; + Word16 pp_fr_q; + float max_val = 0.0f; + /* Find Q-factor */ + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( data_f[i][j] ) ); + } + } + pcm_q = Q_factor_L( max_val ); + + max_val = 0; + for ( i = 0; i < nchan_fb_in; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + max_val = max( max_val, (float) fabs( ppIn_FR_real[i][j] ) ); + max_val = max( max_val, (float) fabs( ppIn_FR_imag[i][j] ) ); + } + } + pp_fr_q = Q_factor_L( max_val ); + + Word32 fr_real_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 fr_imag_fx[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2]; + Word32 data_f_buf[DIRAC_MAX_ANA_CHANS][L_FRAME48k]; + Word32 *pp_fr_real_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *pp_fr_imag_fx[DIRAC_MAX_ANA_CHANS]; + Word32 *data_f_fx[DIRAC_MAX_ANA_CHANS]; + for ( i = 0; i < nchan_fb_in; i++ ) + { + data_f_fx[i] = data_f_buf[i]; + pp_fr_real_fx[i] = fr_real_fx[i]; + pp_fr_imag_fx[i] = fr_imag_fx[i]; + for ( j = 0; j < input_frame; j++ ) + { + data_f_fx[i][j] = float_to_fix( data_f[i][j], pcm_q ); + pp_fr_real_fx[i][j] = float_to_fix( ppIn_FR_real[i][j], pp_fr_q ); + pp_fr_imag_fx[i][j] = float_to_fix( ppIn_FR_imag[i][j], pp_fr_q ); + } + } +#endif + IF( ( error = ivas_dirac_enc_fx( st_ivas->hDirAC, hQMetaData, hMetaData, data_f_fx, pp_fr_real_fx, pp_fr_imag_fx, pp_fr_q, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_dirac_enc( st_ivas->hDirAC, hQMetaData, hMetaData, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } +#endif /* Set Energy Ratio to 0.0 if the mono flag has been set */ if ( hQMetaData->dirac_mono_flag ) @@ -1285,7 +1336,11 @@ static ivas_error ivas_spar_enc_process( { for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) { +#ifndef IVAS_FLOAT_FIXED hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; +#else + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[i_ts] = 0; +#endif } } } @@ -1294,19 +1349,11 @@ static ivas_error ivas_spar_enc_process( * Covariance and MD processing *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( b = hSpar->enc_param_start_band; b < IVAS_MAX_NUM_BANDS; b++ ) - { - Word16 dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - hSpar->enc_param_start_band; - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] = float_to_fix( hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0], Q30 ); - } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( int ch_idx = 0; ch_idx < nchan_fb_in; ch_idx++ ) { floatToFixed_arrL32( ppIn_FR_real[ch_idx], ppIn_FR_real_fx[ch_idx], Q14 - gb, input_frame ); floatToFixed_arrL32( ppIn_FR_imag[ch_idx], ppIn_FR_imag_fx[ch_idx], Q14 - gb, input_frame ); } -#endif #endif if ( ( error = ivas_spar_cov_md_process( hEncoderConfig, st_ivas->hSpar, st_ivas->hQMetaData, hMetaData, nchan_inp, sba_order, ppIn_FR_real_fx, ppIn_FR_imag_fx, transient_det, dtx_vad, nchan_transport, &dyn_active_w_flag, Q14 - gb ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 357e52230..1bfa16eaf 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -135,8 +135,7 @@ static void ivas_quant_p_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_c #else static void ivas_quant_p_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 num_ch ); #endif -static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t ndec, const int16_t ndm ); - +static void ivas_quant_c_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const Word16 ndec, const Word16 ndm, const Word16 q_C ); #ifndef IVAS_FLOAT_FIXED static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); #else @@ -230,7 +229,7 @@ ivas_error ivas_spar_md_enc_open( hMdEnc->q_mixer_mat_fx = 0; #endif - if ( ( error = ivas_spar_md_enc_init( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_spar_md_enc_init_fx( hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK ) { return error; } @@ -438,8 +437,8 @@ ivas_error ivas_spar_md_enc_init( hMdEnc->spar_md.prior_dyn_active_w_flag = 0; - ivas_spar_set_bitrate_config( &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 ) ); + 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 ) ); /* get FB coefficients */ for ( i = 0; i < IVAS_MAX_NUM_BANDS; i++ ) @@ -498,7 +497,7 @@ ivas_error ivas_spar_md_enc_init( } #endif - ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); + ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, 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 ); @@ -578,6 +577,19 @@ ivas_error ivas_spar_md_enc_init_fx( } } } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + FOR( i = 0; i < num_channels; i++ ) + { + FOR( j = 0; j < num_channels; j++ ) + { + FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + hMdEnc->mixer_mat[i][j][k] = 0.0f; + move32(); + } + } + } +#endif hMdEnc->q_mixer_mat_fx = 0; move16(); ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -775,21 +787,17 @@ static void ivas_band_mixing_fx( static void write_metadata_buffer( BSTR_ENC_HANDLE hMetaData_tmp, BSTR_ENC_HANDLE hMetaData, - const int16_t bit_pos_start, - const int16_t next_ind_start ) + const Word16 bit_pos_start, + const Word16 next_ind_start ) { - int16_t i; + Word16 i; - if ( hMetaData->nb_bits_tot > 0 ) + IF( hMetaData->nb_bits_tot > 0 ) { -#ifdef IVAS_FLOAT_FIXED restore_metadata_buffer_fx( hMetaData, next_ind_start, bit_pos_start ); -#else - restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); -#endif } - for ( i = 0; i < hMetaData_tmp->nb_ind_tot; i++ ) + FOR( i = 0; i < hMetaData_tmp->nb_ind_tot; i++ ) { push_next_indice( hMetaData, hMetaData_tmp->ind_list[i].value, hMetaData_tmp->ind_list[i].nb_bits ); } @@ -807,8 +815,6 @@ static void write_metadata_buffer( ivas_error ivas_spar_md_enc_process_fx( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -839,10 +845,6 @@ ivas_error ivas_spar_md_enc_process_fx( Word16 max_num_indices_tmp; Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - float Wscale[IVAS_MAX_NUM_BANDS]; - float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; -#endif /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = add( hMdEnc->spar_md_cfg.max_bits_per_blk, IVAS_SPAR_ARITH_OVERSHOOT_BITS ); @@ -957,16 +959,6 @@ ivas_error ivas_spar_md_enc_process_fx( bands_bw = 1; move16(); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < num_ch - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } -#endif test(); IF( hMdEnc->spar_hoa_md_flag && hMdEnc->spar_hoa_dirac2spar_md_flag ) { @@ -974,106 +966,13 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) { - pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + pred_coeffs_re_local_fx[i][b] = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; // Q28 move32(); } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < nchan_inp; i++ ) - { - FOR( j = 0; j < nchan_inp; j++ ) - { - FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - cov_real[i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, cov_real_q[i][j][k] ) ); - cov_dtx_real[i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, cov_dtx_real_q[i][j][k] ) ); - } - } - } -#endif - -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - f2me( cov_real[i][j][k], &cov_real_fx[i][j][k], &cov_real_q[i][j][k] ); - cov_real_q[i][j][k] = 31 - cov_real_q[i][j][k]; - } - } - } - -#endif ivas_compute_spar_params_enc_fx( cov_real_fx, cov_real_q, dm_fv_re_fx, &q_dm_fv_re, 0, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale_fx, q_Wscale, 0, dyn_active_w_flag ); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch - 1; i++ ) - { - for ( j = 0; j < nB; j++ ) - { - dm_fv_re[i][j] = fixedToFloat_32( dm_fv_re_fx[i][j], q_dm_fv_re ); - } - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - for ( b = 0; b < nB; b++ ) - { - hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hMdEnc->mixer_mat_fx[i][j][b], hMdEnc->q_mixer_mat_fx ); - } - } - } - Word16 q_tmp; - for ( b = 0; b < nB; b++ ) - { - Wscale[b] = fixedToFloat_32( Wscale_fx[b], q_Wscale[b] ); - for ( i = 0; i < num_ch - 1; i++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx; - hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], q_tmp ); - } - ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; - if ( ndm != num_ch ) - { - for ( i = 0; i < num_ch - ndm; i++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_P_re_fx; - hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], q_tmp ); - } - if ( ndm != 1 ) - { - for ( i = 0; i < num_ch - ndm; i++ ) - { - for ( j = 0; j < ndm - 1; j++ ) - { - q_tmp = hMdEnc->spar_md.band_coeffs[b].q_C_re_fx; - hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], q_tmp ); - } - } - } - } - } -#endif -#else - ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); -#endif - -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < num_ch - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].pred_re[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_re_fx[ii] = float_to_fix( hMdEnc->spar_md.band_coeffs[b].P_re[ii], Q28 ); - } - } -#endif IF( dirac_mono_flag ) { Word16 i_ts; @@ -1091,7 +990,6 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( j = 0; j < ndm + ndec - 1; j++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re[j] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[j] = 0; move32(); } @@ -1099,7 +997,6 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( k = 0; k < ndm - 1; k++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re[j][k] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[j][k] = 0; move32(); } @@ -1107,7 +1004,6 @@ ivas_error ivas_spar_md_enc_process_fx( FOR( j = 0; j < ndec; j++ ) { - hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re[j] = 0.0f; hMdEnc->spar_md.band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = 0; move32(); } @@ -1119,12 +1015,6 @@ ivas_error ivas_spar_md_enc_process_fx( move16(); FOR( qsi = 0; qsi < num_quant_strats; qsi++ ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.min, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].P_r.max, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.min, Q28 ); - hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max_fx = float_to_fix( hMdEnc->spar_md_cfg.quant_strat[qsi].PR.max, Q28 ); -#endif FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; @@ -1172,7 +1062,7 @@ ivas_error ivas_spar_md_enc_process_fx( ivas_quant_strat_t qs; Word16 PR_step_e; qs = hMdEnc->spar_md_cfg.quant_strat[qsi]; - PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; + PR_uq = hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i]; // Q28 move32(); PR_step = BASOP_Util_Divide3216_Scale( L_sub( qs.PR.max_fx, qs.PR.min_fx ), sub( qs.PR.q_levels[0], 1 ), &PR_step_e ); PR_step_e = sub( PR_step_e, Q12 ); @@ -1205,47 +1095,11 @@ ivas_error ivas_spar_md_enc_process_fx( ivas_spar_quant_pred_coeffs_dtx_fx( &hMdEnc->spar_md, hMdEnc->spar_md.band_coeffs[b].pred_re_fx, ndm, hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re, sub( num_ch, 1 ), hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx ); } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < num_bands; b++ ) - { - for ( int ii = 0; ii < IVAS_SPAR_MAX_CH - 1; ii++ ) - { - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[ii], Q28 ); - hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); - } - } - Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; - f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); - - for ( i = 0; i < num_ch - 1; i++ ) - { - dm_fv_re_q = s_min( dm_fv_re_q, Q_factor_arrL( dm_fv_re[i], num_bands ) ); - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - mixer_q = s_min( mixer_q, Q_factor_arrL( hMdEnc->mixer_mat[i][j], num_bands ) ); - } - } - mixer_q = mixer_q - Wscale_e; // Important - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - floatToFixed_arrL32( hMdEnc->mixer_mat[i][j], hMdEnc->mixer_mat_fx[i][j], mixer_q, num_bands ); - } - } - for ( i = 0; i < num_ch - 1; i++ ) - { - floatToFixed_arrL32( dm_fv_re[i], dm_fv_re_fx[i], dm_fv_re_q, num_bands ); - } -#endif FOR( i = 0; i < num_ch - 1; i++ ) { FOR( b = 0; b < num_bands; b++ ) { - pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), Wscale_e ); + pred_coeffs_re_fx[i][b] = L_shl( Mpy_32_32( Wscale_fx[b], hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] ), sub( Q31, q_Wscale[b] ) ); // Q28 move32(); } } @@ -1261,7 +1115,6 @@ ivas_error ivas_spar_md_enc_process_fx( pred_coeffs_re_fx[i][b] = pred_coeffs_re_local_fx[i][b]; move32(); hMdEnc->spar_md.band_coeffs[b].pred_quant_re_fx[i] = 0; - hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] = 0.0f; move32(); hMdEnc->spar_md.band_coeffs_idx[b].pred_index_re[i] = 0; move16(); @@ -1269,8 +1122,27 @@ ivas_error ivas_spar_md_enc_process_fx( } } - ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, dm_fv_re_q, hMdEnc->mixer_mat_fx, &mixer_q, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); - + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, Q28, dm_fv_re_fx, q_dm_fv_re, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, num_ch, 0, num_bands, active_w, &hMdEnc->spar_md_cfg ); + Word16 Wscale_e = Q31; + move16(); + /* Common q for Wscale buffer */ + FOR( b = 0; b < num_bands; b++ ) + { + if ( GT_16( Wscale_e, q_Wscale[b] ) ) + { + Wscale_e = q_Wscale[b]; + move16(); + } + } + FOR( b = 0; b < num_bands; b++ ) + { + Wscale_fx[b] = L_shr( Wscale_fx[b], sub( q_Wscale[b], Wscale_e ) ); // Q(Wscale_e) + move32(); + } + Wscale_e = sub( Q31, Wscale_e ); // Wscale_e is now exp of Wscale + /*mixer-q adjusted for Wscale multplication below */ + hMdEnc->q_mixer_mat_fx = sub( hMdEnc->q_mixer_mat_fx, Wscale_e ); + move16(); FOR( b = 0; b < num_bands; b++ ) { ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; @@ -1280,16 +1152,18 @@ ivas_error ivas_spar_md_enc_process_fx( FOR( i = 0; i < num_ch; i++ ) { - hMdEnc->mixer_mat_fx[0][i][b] = L_shl( Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ), Wscale_e ); + hMdEnc->mixer_mat_fx[0][i][b] = Mpy_32_32( hMdEnc->mixer_mat_fx[0][i][b], Wscale_fx[b] ); move32(); -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->mixer_mat[0][i][b] = fix_to_float( hMdEnc->mixer_mat_fx[0][i][b], mixer_q ); -#endif + FOR( j = 1; j < num_ch; j++ ) + { + hMdEnc->mixer_mat_fx[j][i][b] = L_shr( hMdEnc->mixer_mat_fx[j][i][b], Wscale_e ); // Q(hMdEnc->q_mixer_mat_fx) + move32(); + } } - + test(); IF( NE_16( ndm, num_ch ) && NE_16( ndm, 1 ) ) { - ivas_calc_c_p_coeffs( &hMdEnc->spar_md, cov_real, 0, hMdEnc->mixer_mat, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); + ivas_calc_c_p_coeffs_enc_fx( &hMdEnc->spar_md, cov_real_fx, cov_real_q, 0, hMdEnc->mixer_mat_fx, hMdEnc->q_mixer_mat_fx, num_ch, ndm, b, dtx_vad, 0, dyn_active_w_flag ); IF( dirac_mono_flag ) { @@ -1301,13 +1175,13 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( k = 0; k < ndm - 1; k++ ) { - hMdEnc->spar_md.band_coeffs[b].C_re[j][k] = 0.0f; + hMdEnc->spar_md.band_coeffs[b].C_re_fx[j][k] = 0; + move32(); } } } - - ivas_quant_c_per_band( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], - &hMdEnc->spar_md_cfg.quant_strat[qsi], ndec, ndm ); + ivas_quant_c_per_band_fx( &hMdEnc->spar_md.band_coeffs[b], &hMdEnc->spar_md.band_coeffs_idx[b], + &hMdEnc->spar_md_cfg.quant_strat[qsi], ndec, ndm, hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); } } @@ -1324,88 +1198,107 @@ ivas_error ivas_spar_md_enc_process_fx( { for ( j = 0; j < num_ch; j++ ) { - fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); + fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], hMdEnc->q_mixer_mat_fx, IVAS_MAX_NUM_BANDS ); } } #endif IF( dtx_vad == 0 ) { -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - hMdEnc->spar_md.min_max_fx[0] = float_to_fix( hMdEnc->spar_md.min_max[0], Q28 ); - hMdEnc->spar_md.min_max_fx[1] = float_to_fix( hMdEnc->spar_md.min_max[1], Q28 ); -#endif ivas_write_parameter_bitstream_dtx_fx( &hMdEnc->spar_md, hMetaData, hMdEnc->spar_md_cfg.num_dmx_chans_per_band, hMdEnc->spar_md_cfg.num_decorr_per_band, num_bands ); BREAK; } -#ifdef IVAS_FLOAT_FIXED ivas_select_next_strat_fx( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); -#else - ivas_select_next_strat( hMdEnc->spar_md_cfg.prior_strat, cs, dmx_switch, dtx_vad ); -#endif - for ( i = 0; i < MAX_CODING_STRATS; i++ ) + FOR( i = 0; i < MAX_CODING_STRATS; i++ ) { strat = cs[i]; - if ( strat != NO_STRAT ) + move16(); + IF( NE_16( strat, NO_STRAT ) ) { reset_indices_enc( &hMetaData_tmp, md_indices_allocated ); -#ifdef IVAS_FLOAT_FIXED ivas_write_spar_md_bitstream_fx( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); -#else - ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi ); -#endif /*write to main buffer if its a valid bitstream*/ - if ( hMetaData_tmp.nb_bits_tot > 0 ) + IF( hMetaData_tmp.nb_bits_tot > 0 ) { - if ( hMetaData->nb_bits_tot == bit_pos_start || hMetaData_tmp.nb_bits_tot < ( hMetaData->nb_bits_tot - bit_pos_start ) ) + test(); + IF( EQ_16( hMetaData->nb_bits_tot, bit_pos_start ) || LT_16( hMetaData_tmp.nb_bits_tot, sub( hMetaData->nb_bits_tot, bit_pos_start ) ) ) { write_metadata_buffer( &hMetaData_tmp, hMetaData, bit_pos_start, next_ind_start ); code_strat = strat; + move16(); } - - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk ) + Word16 add_bit; + test(); + IF( ( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( sba_order, SBA_FOA_ORDER ) ) ) + { + add_bit = 1; + move16(); + } + ELSE + { + add_bit = 0; + move16(); + } + IF( LE_16( add( sub( hMetaData->nb_bits_tot, bit_pos_start ), add_bit ), hMdEnc->spar_md_cfg.tgt_bits_per_blk ) ) { packed_ok = 1; - break; + move16(); + BREAK; } } } } - if ( packed_ok == 1 ) + IF( EQ_16( packed_ok, 1 ) ) { - break; + BREAK; } /*only if valid bitstream was written to main buffer*/ - if ( hMetaData->nb_bits_tot > bit_pos_start ) + IF( GT_16( hMetaData->nb_bits_tot, bit_pos_start ) ) { - if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.max_bits_per_blk ) + Word16 add_bit; + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( sba_order, SBA_FOA_ORDER ) ) + { + add_bit = 1; + move16(); + } + ELSE + { + add_bit = 0; + move16(); + } + IF( LE_16( add( sub( hMetaData->nb_bits_tot, bit_pos_start ), add_bit ), hMdEnc->spar_md_cfg.max_bits_per_blk ) ) { packed_ok = 1; - break; + move16(); + BREAK; } } } /* Reuse mixer matrix values for unsent bands */ - if ( ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) && ( code_strat > 3 ) ) + test(); + IF( ( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) && GT_16( code_strat, 3 ) ) { - for ( b = 0; b < num_bands * bands_bw; b += 2 * bands_bw ) + FOR( b = 0; b < num_bands * bands_bw; b += 2 * bands_bw ) { - if ( ( b == 0 ) && ( code_strat % 2 == 0 ) ) + test(); + IF( ( b == 0 ) && ( s_and( code_strat, 1 ) == 0 ) ) { - b += 2; + b = add( b, 2 ); } - for ( i = 0; i < 1; i++ ) + FOR( i = 0; i < 1; i++ ) { - for ( j = 0; j < 4; j++ ) + FOR( j = 0; j < 4; j++ ) { + // TODO once fb-mixer changes are final hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; } @@ -3188,34 +3081,38 @@ static void ivas_quant_pred_coeffs_per_band( * * Quantization of cross prediction c coeffs for each band *-----------------------------------------------------------------------------------------*/ - -static void ivas_quant_c_per_band( +static void ivas_quant_c_per_band_fx( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, - const int16_t ndec, - const int16_t ndm ) + const Word16 ndec, + const Word16 ndm, + const Word16 q_C ) { - int16_t i; - int16_t j, k; - float C_re[IVAS_SPAR_MAX_C_COEFF]; + Word16 i; + Word16 j, k; + Word32 C_re[IVAS_SPAR_MAX_C_COEFF]; k = 0; - for ( i = 0; i < ndec; i++ ) + move16(); + FOR( i = 0; i < ndec; i++ ) { - for ( j = 0; j < ndm - 1; j++ ) + FOR( j = 0; j < ndm - 1; j++ ) { - C_re[k] = pband_coeffs->C_re[i][j]; - k++; + C_re[k] = pband_coeffs->C_re_fx[i][j]; + move32(); + k = add( k, 1 ); } } - ivas_quantise_real_values( C_re, pQs->C.q_levels[0], pQs->C.min, pQs->C.max, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ) ); + ivas_quantise_real_values_enc_fx_varq( C_re, pQs->C.q_levels[0], pQs->C.min_fx, pQs->C.max_fx, pBand_coeffs_idx->drct_index_re, C_re, ndec * ( ndm - 1 ), q_C ); k = 0; - for ( i = 0; i < ndec; i++ ) + move16(); + FOR( i = 0; i < ndec; i++ ) { - for ( j = 0; j < ndm - 1; j++ ) + FOR( j = 0; j < ndm - 1; j++ ) { - pband_coeffs->C_quant_re[i][j] = C_re[k]; - k++; + pband_coeffs->C_quant_re_fx[i][j] = C_re[k]; + move32(); + k = add( k, 1 ); } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 8e8dc8f84..0286115d7 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -938,22 +938,20 @@ typedef struct ivas_dirac_enc_data_structure IVAS_FB_MIXER_HANDLE hFbMixer; /* DirAC parameter estimation */ - float **direction_vector[DIRAC_NUM_DIMS]; - float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ - float diffuseness_m[DIRAC_MAX_NBANDS]; #ifdef IVAS_FLOAT_FIXED Word32 **direction_vector_m_fx[DIRAC_NUM_DIMS]; /* Average direction vector */ Word16 direction_vector_m_exp[MAX_PARAM_SPATIAL_SUBFRAMES]; // direction_vector_m_fx[i][j][k] will map to direction_vector_m_exp[j] exponent. Word32 diffuseness_m_fx[DIRAC_MAX_NBANDS]; Word16 diffuseness_m_exp[DIRAC_MAX_NBANDS]; +#else + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + float **direction_vector[DIRAC_NUM_DIMS]; + float diffuseness_m[DIRAC_MAX_NBANDS]; #endif int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; int16_t firstrun_sector_params; - float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 sec_I_vec_smth_x_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 sec_I_vec_smth_x_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; @@ -961,29 +959,35 @@ typedef struct ivas_dirac_enc_data_structure Word16 sec_I_vec_smth_y_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word32 sec_I_vec_smth_z_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 sec_I_vec_smth_z_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; +#else + float sec_I_vec_smth_x[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float sec_I_vec_smth_y[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float sec_I_vec_smth_z[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; #endif - float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; - float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; - float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 energy_smth_fx[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word16 energy_smth_exp[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; Word32 azi_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; Word32 ele_prev_fx[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; +#else + float energy_smth[NUM_ANA_SECTORS][IVAS_MAX_NUM_BANDS]; + float azi_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; + float ele_prev[NUM_ANA_SECTORS * IVAS_MAX_NUM_BANDS]; #endif /* diffuseness */ int16_t index_buffer_intensity; int16_t no_col_avg_diff; - float **buffer_intensity_real[DIRAC_NUM_DIMS]; - float *buffer_energy; #ifdef IVAS_FLOAT_FIXED Word32 **buffer_intensity_real_fx[DIRAC_NUM_DIMS]; Word16 buffer_intensity_real_q[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF][DIRAC_MAX_NBANDS]; Word32 *buffer_energy_fx; Word16 buffer_energy_q[DIRAC_NO_COL_AVG_DIFF * DIRAC_MAX_NBANDS]; +#else + float **buffer_intensity_real[DIRAC_NUM_DIMS]; + float *buffer_energy; #endif /* Frame count for detecting mono */ -- GitLab From c7d55a4db19d993a88dc8bc58b720359bf357ddc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 17:19:31 +0530 Subject: [PATCH 26/39] Fix for 3gpp issue 866 --- lib_com/fd_cng_com.c | 3 --- lib_com/fd_cng_com_fx.c | 2 -- lib_com/stat_com.h | 5 +---- lib_dec/acelp_core_dec_ivas_fx.c | 1 - lib_dec/fd_cng_dec.c | 21 +++++++++++---------- lib_dec/ivas_stereo_cng_dec.c | 6 +++--- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 11 ++--------- lib_dec/ivas_tcx_core_dec.c | 10 +++------- 8 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 14c9b3c21..a03edf290 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -118,9 +118,6 @@ void initFdCngCom_flt( hFdCngCom->frame_type_previous = ACTIVE_FRAME; hFdCngCom->flag_noisy_speech = 0; hFdCngCom->likelihood_noisy_speech_flt = 0.f; -#ifdef IVAS_FLOAT_FIXED - hFdCngCom->likelihood_noisy_speech_32fx = 0; -#endif hFdCngCom->numCoreBands = 0; hFdCngCom->stopBand = 0; hFdCngCom->startBand = 0; diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 8f5528014..e11d67d69 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -163,8 +163,6 @@ void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); set16_fx( hFdCngCom->exc_cng, 0, L_FRAME16k ); - hFdCngCom->likelihood_noisy_speech_32fx = 0; - move32(); return; } diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 7cc45ae38..97fec1041 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -532,10 +532,7 @@ typedef struct int16_t flag_noisy_speech; float likelihood_noisy_speech_flt; -#ifdef IVAS_FLOAT_FIXED - Word32 likelihood_noisy_speech_32fx; -#endif - Word16 likelihood_noisy_speech; + Word16 likelihood_noisy_speech; // Q15 #ifndef IVAS_FLOAT_FIXED float coherence_flt; /* inter-channel coherence of noise */ diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 679120dbb..834691ce0 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1552,7 +1552,6 @@ ivas_error acelp_core_dec_ivas_fx( 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 ); move32(); } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 10c25db4d..0c3f8afd6 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -59,7 +59,7 @@ #define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */ #endif // IVAS_FLOAT_FIXED -#define DELTA_MASKING_NOISE_Q31 0 +#define DELTA_MASKING_NOISE_Q15 0 #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ #define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */ #define LOG_10_BASE_2 1783446566 /* Q29 */ @@ -1955,7 +1955,7 @@ void generate_masking_noise_ivas_fx( /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ *exp_out = Q15; move16(); - IF( GT_32( hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 ) ) + IF( GT_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { IF( NE_16( core, AMR_WB_CORE ) ) { @@ -1997,7 +1997,7 @@ void generate_masking_noise_ivas_fx( } /* Exclude clean speech */ - scale_fx = Mpy_32_32( scale_fx, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 + scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); // Q30 /* 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 */ @@ -2680,7 +2680,7 @@ void generate_masking_noise_lb_dirac_fx( 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_16( hFdCngCom->likelihood_noisy_speech, DELTA_MASKING_NOISE_Q15 ) ) { /* Compute additional CN level */ FOR( i = 0; i < 15; i++ ) @@ -2695,8 +2695,8 @@ void generate_masking_noise_lb_dirac_fx( } } - scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ - scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); /* Q30 */ + scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ + scale = Mpy_32_16_1( scale, hFdCngCom->likelihood_noisy_speech ); /* Q30 */ } } @@ -2738,7 +2738,7 @@ void generate_masking_noise_lb_dirac_fx( FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); - Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); + Word16 exp2 = 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 move32(); @@ -2758,6 +2758,7 @@ void generate_masking_noise_lb_dirac_fx( /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); + scale_sig32( tdBuffer + n_samples_start, n_samples_out_loop, Q9 ); // Q2 -> Q11 } ELSE @@ -2935,7 +2936,7 @@ void generate_masking_noise_dirac_ivas_fx( } } - scale_fx = L_shr( scaleTable_cn_dirac[i].scale_ivas, Q3 ); /* Q11 */ + scale_fx = L_shr( L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ), Q3 ); /* Q27 */ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); } } @@ -2959,11 +2960,11 @@ void generate_masking_noise_dirac_ivas_fx( /*HF CLDFB - CNA and/or FD-CNG*/ if ( fd_cng_flag ) { - scale_fx = L_add( scale_fx, 2048 ); // 1 in Q11 + scale_fx = L_add( scale_fx, ONE_IN_Q27 ); // 1 in Q27 } IF( scale_fx != 0 ) { - q_scale = 11; + q_scale = 27; move16(); q_shift = norm_l( scale_fx ); scale_fx = L_shl( scale_fx, q_shift ); diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 7737a251d..60375dd78 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1384,9 +1384,9 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); st->hFdCngDec->hFdCngCom->flag_noisy_speech = extract_l( LT_32( L_shr( L_sub( st->hFdCngDec->lp_speech, st->hFdCngDec->lp_noise ), q_lp_noise ), 28 ) ); /* Q0 */ move16(); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), + mult_r( 328 /* 0.01 in Q15 */, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q15 */ + move16(); } test(); diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 6731b8b0d..155e207b8 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -535,11 +535,6 @@ void stereo_mdct_core_dec_fx( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( sts[ch]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, s ); } test(); - 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 ); /* 16 - q_likelihood_noisy_speech */ - } - test(); test(); IF( sts[ch]->igf != 0 && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) { @@ -1066,10 +1061,8 @@ static void run_min_stats_fx( 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 ) ); /* q_likelihood_noisy_speech */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* q_likelihood_noisy_speech - 16 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99 in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01 in Q15 */ ) ); /* Q15 */ + move16(); st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move32(); } diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 4ac7c32a8..7930720f3 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -954,14 +954,10 @@ void stereo_tcx_core_dec_fx( IF( st->hFdCngDec != NULL && ( EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) { noisy_speech_detection_fx( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); - - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - imult3216( Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech ) ); /* Q31 */ - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); /* Q15 */ - st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ - move32(); - move32(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( mult_r( 32440 /* 0.99f in Q15 */, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech ), mult_r( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 328 /* 0.01f in Q15 */ ) ); /* Q15 */ + st->lp_noise = st->hFdCngDec->lp_noise; /* Q9.23 */ move16(); + move32(); IF( NE_16( st->element_mode, IVAS_CPE_TD ) ) { -- GitLab From 08d9a3e192508bcefb91c9e4a5e29e8dc4b10145 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 17:47:12 +0530 Subject: [PATCH 27/39] Fix for 3gpp issue 965: Decoder crash for OMASA ISM3_1TC at 24.4 kbps FER in stereo_icBWE_dec_fx() --- lib_dec/ivas_stereo_icbwe_dec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 32751a338..b79d52d7e 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -789,6 +789,7 @@ void stereo_icBWE_dec_fx( } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { + Word32 temp; hStereoICBWE->refChanIndx_bwe = L_CH_INDX; move16(); hStereoICBWE->prevSpecMapping_fx = 0; @@ -796,9 +797,9 @@ void stereo_icBWE_dec_fx( prevgsMapping_fx = hStereoICBWE->prevgsMapping_fx; move16(); - temp1_fx = shr( extract_h( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1] ), 1 ); - icbweM2Ref_fx = add( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ - gsMapping_fx = sub( 16384 /*1.f in Q14*/, temp1_fx ); /* Q14 */ + temp = L_shr( hStereoDft->side_gain_fx[2 * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1], 1 ); // Q30 + icbweM2Ref_fx = extract_h( L_add( ONE_IN_Q30, temp ) ); // Q14 + gsMapping_fx = extract_h( L_sub( ONE_IN_Q30, temp ) ); // Q14 winLen_fx = extract_l( Mpy_32_16_1( st->output_Fs, 41 ) ); //(int16_t)((SHB_OVERLAP_LEN * st->output_Fs) / 16000); Q0 winSlope_fx = div_s( 1, winLen_fx ); /* Q15 */ -- GitLab From f1b9b09f90d5ed135433661d1d0071e964625054 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 19:32:04 +0530 Subject: [PATCH 28/39] MASA path cleanup, Q-info update for decoder/common files --- lib_com/ACcontextMapping.c | 18 +-- lib_com/ACcontextMapping_fx.c | 50 +++--- lib_com/ari_fx.c | 5 +- lib_com/ari_hm.c | 144 +++++++++--------- lib_com/ari_hm_fx.c | 128 ++++++++-------- lib_com/cldfb.c | 18 ++- lib_com/ivas_prot_fx.h | 23 +++ lib_com/ivas_qmetadata_com.c | 17 +-- lib_com/ivas_qspherical_com.c | 8 +- lib_com/prot.h | 38 ++--- lib_com/prot_fx.h | 69 +++++---- lib_enc/ivas_enc.c | 102 +++++++------ lib_enc/ivas_masa_enc.c | 245 +++++++++++++++++++++++++++++- lib_enc/ivas_qmetadata_enc.c | 277 ++++++++++++++++++++-------------- lib_enc/ivas_qspherical_enc.c | 9 +- lib_enc/lib_enc.c | 112 +++++++++++++- lib_rend/ivas_efap.c | 17 ++- 17 files changed, 872 insertions(+), 408 deletions(-) diff --git a/lib_com/ACcontextMapping.c b/lib_com/ACcontextMapping.c index 1af3286bf..15dcfc0be 100644 --- a/lib_com/ACcontextMapping.c +++ b/lib_com/ACcontextMapping.c @@ -67,21 +67,21 @@ int16_t get_next_coeff_mapped_ivas( } #else Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *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 Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { UWord32 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); - p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); - *pp = p; + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ + p = UL_lshr( p, sub( sizeof( p ) * 8, 1 ) ); /* Q0 */ + *pp = p; /* Q0 */ move32(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; diff --git a/lib_com/ACcontextMapping_fx.c b/lib_com/ACcontextMapping_fx.c index d55bcd6ac..9fa89cb7e 100644 --- a/lib_com/ACcontextMapping_fx.c +++ b/lib_com/ACcontextMapping_fx.c @@ -11,15 +11,15 @@ /* 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 Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { Word16 p; - p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); + p = s_and( sub( ii[1], hm_cfg->numPeakIndices ), sub( hm_cfg->indexBuffer[ii[1]], hm_cfg->indexBuffer[ii[0]] ) ); /* Q0 */ if ( p > 0 ) { p = 0; @@ -30,63 +30,69 @@ Word16 get_next_coeff_mapped( p = 1; move16(); } - *pp = p; + *pp = p; /* Q0 */ move16(); - *idx = ii[p]; + *idx = ii[p]; /* Q0 */ move16(); - ii[p] = add( ii[p], 1 ); + ii[p] = add( ii[p], 1 ); /* Q0 */ move16(); return hm_cfg->indexBuffer[*idx]; } /* 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 Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ) { (void) pp; (void) hm_cfg; - *idx = ii[0]; + *idx = ii[0]; /* Q0 */ move16(); - ii[0] = add( ii[0], 1 ); + ii[0] = add( ii[0], 1 ); /* Q0 */ move16(); return *idx; } -Word16 update_mixed_context( Word16 ctx, Word16 a ) +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; Word16 t = 0; /* initialize just to avoid compiler warning */ - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ if ( t32 <= 0 ) { - t = extract_l( t32 ); + t = extract_l( t32 ); /* Q0 */ } a = shr( a, 3 ); if ( t32 > 0 ) { - t = s_min( a, 2 ); + t = s_min( a, 2 ); /* Q0 */ } return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) ); } #ifdef IVAS_FLOAT_FIXED -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ) +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +) { Word32 t32; - t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); + t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) ); /* Q0 */ - a = shr( a, 3 ); + a = shr( a, 3 ); /* Q0 */ IF( t32 > 0 ) { - t32 = L_min( a, 2 ); + t32 = L_min( a, 2 ); /* Q0 */ } return L_add( L_shl( L_and( ctx, 0xf ), 4 ), L_add( t32, 13 ) ); } diff --git a/lib_com/ari_fx.c b/lib_com/ari_fx.c index 3b36d10b3..aef9a6635 100644 --- a/lib_com/ari_fx.c +++ b/lib_com/ari_fx.c @@ -39,7 +39,10 @@ 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, /* Q0 */ + Word16 c /* Q0 */ +) { Word32 ret; diff --git a/lib_com/ari_hm.c b/lib_com/ari_hm.c index 8306376e2..159660927 100644 --- a/lib_com/ari_hm.c +++ b/lib_com/ari_hm.c @@ -101,12 +101,13 @@ void UnmapIndex_ivas( } void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -114,54 +115,54 @@ void UnmapIndex_fx( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ 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 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ } } @@ -262,19 +263,20 @@ int16_t CountIndexBits_ivas( } Word16 CountIndexBits_fx( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; - result = 8; + result = 8; /* Q0 */ move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -290,9 +292,9 @@ Word16 CountIndexBits_fx( *-------------------------------------------------------------------*/ Word16 tcx_hm_render_ivas( - const Word16 lag, /* i : pitch lag */ - const Word16 fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ) { Word16 k; @@ -305,14 +307,14 @@ Word16 tcx_hm_render_ivas( 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 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + 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 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( sub( 13915, PeakDeviation ) > 0 ) { @@ -321,22 +323,22 @@ Word16 tcx_hm_render_ivas( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); FOR( k = 1; k <= kTcxHmParabolaHalfWidth; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); + p[kTcxHmParabolaHalfWidth + k] = round_fx( Mpy_32_16_1( BASOP_Util_InvLog2( L_shl( L_mult0( mult0( negate( k ), k ), tmp ), 10 ) ), height ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ } return 0; @@ -356,15 +358,15 @@ Word32 tcx_hm_render_fx( 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 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 /* 0.8 in Q15 */ ) ); /* Q29 */ + 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 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -373,12 +375,12 @@ Word32 tcx_hm_render_fx( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ p[kTcxHmParabolaHalfWidth] = height; @@ -386,12 +388,12 @@ Word32 tcx_hm_render_fx( 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 ) ); /* Q13 */ } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -405,12 +407,12 @@ Word32 tcx_hm_render_fx( *-------------------------------------------------------------------*/ void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const Word16 lag, - const Word16 fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const Word16 L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ) { Word16 k, h, x; @@ -423,7 +425,7 @@ void tcx_hm_modify_envelope_ivas( FOR( k = 0; k < 2 * kTcxHmParabolaHalfWidth + 1; ++k ) { - inv_shape[k] = div_s( 512, add( 512, round_fx( L_mult( gain, p[k] ) ) ) ); + inv_shape[k] = div_s( 512 /* 1 in Q24 */, add( 512 /* 1 in Q24 */, round_fx( L_mult( gain, p[k] ) ) ) ); /* Q15 */ move16(); } @@ -435,11 +437,11 @@ void tcx_hm_modify_envelope_ivas( FOR( x = max( 0, k - kTcxHmParabolaHalfWidth ); x <= min( k + kTcxHmParabolaHalfWidth, L_frame - 1 ); ++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] ); /* Q16 */ move32(); } - ++h; - k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( L_mult0( h, lag ), fract_res ) ); /* Q0 */ } return; @@ -465,7 +467,7 @@ void tcx_hm_modify_envelope_fx( 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] ) ) ); /* Q15 */ move16(); } @@ -473,21 +475,21 @@ void tcx_hm_modify_envelope_fx( move16(); 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 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ - WHILE( LE_16( k, L_frame_for_loop ) ) + WHILE( k <= L_frame_for_loop ) { - l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); - l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); + l1 = s_max( 0, sub( k, kTcxHmParabolaHalfWidth ) ); /* Q0 */ + l2 = s_min( add( k, kTcxHmParabolaHalfWidth ), L_frame_m1 ); /* Q0 */ 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] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/ari_hm_fx.c b/lib_com/ari_hm_fx.c index 767aea860..ea0c59972 100644 --- a/lib_com/ari_hm_fx.c +++ b/lib_com/ari_hm_fx.c @@ -13,12 +13,13 @@ #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) void UnmapIndex( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word16 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ) + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +) { Word16 LtpPitchIndex, Multiplier; Word16 Lag16; @@ -26,65 +27,65 @@ void UnmapIndex( test(); IF( ( LtpPitchLag > 0 ) && ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) ) { - LtpPitchIndex = shr( PeriodicityIndex, 9 ); - Multiplier = s_and( PeriodicityIndex, 0xff ); + LtpPitchIndex = shr( PeriodicityIndex, 9 ); /* Q0 */ + Multiplier = s_and( PeriodicityIndex, 0xff ); /* Q0 */ assert( 0 <= LtpPitchIndex && LtpPitchIndex <= 16 ); assert( 1 <= Multiplier && Multiplier <= ( 1 << NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *FractionalResolution = kLtpHmFractionalResolution; + *FractionalResolution = kLtpHmFractionalResolution; /* Q0 */ move16(); - *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][sub( Multiplier, 1 )] ), 8 ); + *Lag = L_shr( L_mult0( LtpPitchLag, Ratios_fx[Bandwidth][LtpPitchIndex][Multiplier - 1] ), 8 ); /* Q0 */ move32(); } ELSE { IF( LT_16( PeriodicityIndex, 16 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 0, 6, 3 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 80 ) ) { - *FractionalResolution = 4; + *FractionalResolution = 4; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 16, 8, 4 ) ); /* Q0 */ } ELSE IF( LT_16( PeriodicityIndex, 208 ) ) { - *FractionalResolution = 3; + *FractionalResolution = 3; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 80, 12, 3 ) ); /* Q0 */ } ELSE { test(); IF( LT_16( PeriodicityIndex, 224 ) || SmallerLags != 0 ) { - *FractionalResolution = 1; + *FractionalResolution = 1; /* Q0 */ move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 208, 28, 1 ) ); /* Q0 */ } ELSE { *FractionalResolution = 0; move16(); - Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); + Lag16 = add( PeriodicityIndex, GET_ADJ2( 224, 188, 0 ) ); /* Q0 */ } } - *Lag = L_deposit_l( Lag16 ); + *Lag = L_deposit_l( Lag16 ); /* Q0 */ move32(); } } 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 Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* (O) Context-based harmonic model configuration */ ) { Word8 Bandwidth, SmallerLags; @@ -97,7 +98,7 @@ void ConfigureContextHm( move16(); if ( GE_16( NumCoeffs, 256 ) ) { - Bandwidth = 1; + Bandwidth = 1; /* Q0 */ move16(); } @@ -106,7 +107,7 @@ void ConfigureContextHm( test(); if ( ( LE_16( TargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( Bandwidth == 0 ) ) { - SmallerLags = 1; + SmallerLags = 1; /* Q0 */ move16(); } @@ -117,28 +118,28 @@ void ConfigureContextHm( &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 ); + hm_cfg->peakIndices = hm_cfg->indexBuffer; /* Q0 */ + tmp = hm_cfg->peakIndices; /* Q0 */ + Limit = L_shl( L_deposit_l( sub( NumCoeffs, 1 ) ), FractionalResolution ); /* Q0 */ IF( LT_32( Lag, Limit ) ) { FOR( i = Lag; i < Limit; i += Lag ) { - Index = extract_l( L_shr( i, FractionalResolution ) ); - *tmp++ = sub( Index, 1 ); + Index = extract_l( L_shr( i, FractionalResolution ) ); /* Q0 */ + *tmp++ = sub( Index, 1 ); /* Q0 */ move16(); - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); - *tmp++ = add( Index, 1 ); + *tmp++ = add( Index, 1 ); /* Q0 */ move16(); } } - hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); + hm_cfg->numPeakIndices = (Word16) ( tmp - hm_cfg->indexBuffer ); /* Q0 */ move16(); /* Set up and fill holeIndices */ - hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; - tmp = hm_cfg->holeIndices; + hm_cfg->holeIndices = hm_cfg->indexBuffer + hm_cfg->numPeakIndices; /* Q0 */ + tmp = hm_cfg->holeIndices; /* Q0 */ Index = 0; move16(); IF( hm_cfg->numPeakIndices > 0 ) @@ -147,7 +148,7 @@ void ConfigureContextHm( { FOR( ; Index < hm_cfg->peakIndices[j]; ++Index ) { - *tmp++ = Index; + *tmp++ = Index; /* Q0 */ move16(); } Index = add( Index, 3 ); /* Skip the peak */ @@ -168,19 +169,20 @@ void ConfigureContextHm( } Word16 CountIndexBits( - Word16 Bandwidth, - Word16 PeriodicityIndex ) + Word16 Bandwidth, /* Q0 */ + Word16 PeriodicityIndex /* Q0 */ +) { Word16 result; Word16 PeriodicityIndexS; result = 8; move16(); - PeriodicityIndexS = shr( PeriodicityIndex, 9 ); + PeriodicityIndexS = shr( PeriodicityIndex, 9 ); /* Q0 */ if ( s_and( PeriodicityIndex, kLtpHmFlag ) != 0 ) { - result = NumRatioBits[Bandwidth][PeriodicityIndexS]; + result = NumRatioBits[Bandwidth][PeriodicityIndexS]; /* Q0 */ move16(); } @@ -202,15 +204,15 @@ Word32 tcx_hm_render( 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 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q29 */ + tmp32 = L_sub( 603979776L /* 1.125 in Q29 */, tmp32 ); /* Q29 */ + tmp32 = L_add( L_add( tmp32, tmp32 ), Mpy_32_16_1( tmp32, 26214 ) ); /* Q29 */ + 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 = L_shr_r( BASOP_Util_InvLog2( L_shl( tmp32, 7 ) ), 2 ); /* Q30 */ + tmp32 = L_sub( 1395864371L /* 1.3 in Q30 */, tmp32 ); /* Q30 */ + PeakDeviation = round_fx( tmp32 ); /* Q14 */ IF( GT_16( 13915, PeakDeviation ) ) { @@ -219,26 +221,26 @@ Word32 tcx_hm_render( } ELSE { - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ } - tmp = div_s( 13915, PeakDeviation ); - tmp = mult_r( tmp, tmp ); /* Q15 */ + tmp = div_s( 13915, PeakDeviation ); /* Q15 */ + tmp = mult_r( tmp, tmp ); /* Q15 */ /* Render the prototype peak */ - p[kTcxHmParabolaHalfWidth] = height; + p[kTcxHmParabolaHalfWidth] = height; /* Q13 */ move16(); 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 ) ); /* Q13 */ move16(); } /* Mirror */ FOR( k = -kTcxHmParabolaHalfWidth; k < 0; ++k ) { - p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; + p[kTcxHmParabolaHalfWidth + k] = p[kTcxHmParabolaHalfWidth - k]; /* Q13 */ move16(); } @@ -265,16 +267,16 @@ void tcx_hm_modify_envelope( 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] ) ) ); /* Q15 */ move16(); } h = 1; move16(); - k = extract_l( L_shr( lag, fract_res ) ); + k = extract_l( L_shr( lag, fract_res ) ); /* Q0 */ - L_frame_m1 = sub( L_frame, 1 ); - L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); + L_frame_m1 = sub( L_frame, 1 ); /* Q0 */ + L_frame_for_loop = add( L_frame, kTcxHmParabolaHalfWidth - 1 ); /* Q0 */ WHILE( LE_16( k, L_frame_for_loop ) ) { @@ -282,11 +284,11 @@ void tcx_hm_modify_envelope( 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[add( sub( x, k ), kTcxHmParabolaHalfWidth )] ); + env[x] = Mpy_32_16_1( env[x], inv_shape[( x - k ) + kTcxHmParabolaHalfWidth] ); /* Q16 */ move32(); } - h = add( h, 1 ); - k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); + h = add( h, 1 ); /* Q0 */ + k = extract_l( L_shr( imult3216( lag, h ), fract_res ) ); /* Q0 */ } } diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 9568ab75a..4eae5458f 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -70,7 +70,7 @@ static float GetEnergyCldfb_ivas( float *energyValuesSum, float *energyLookahead * * Conduct complex multiplication *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static void cplxMult( float *yr, /* o : real output */ float *yi, /* o : imag output */ @@ -85,14 +85,14 @@ static void cplxMult( return; } - +#endif /*-------------------------------------------------------------------* * cldfbAnalysis_ivas() * * Conduct multiple overlap complex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas( const float *timeIn, /* i : time buffer */ float **realBuffer, /* o : real value buffer */ @@ -260,7 +260,7 @@ void cldfbAnalysis_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ivas_fx( const Word32 *timeIn_fx, /* i : time buffer Qx */ @@ -477,7 +477,7 @@ void cldfbAnalysis_ivas_fx( * * *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_ivas( const float *timeIn, /* i : time buffer */ float realBuffer[CLDFB_NO_CHANNELS_MAX], /* o : real value buffer */ @@ -691,7 +691,7 @@ void cldfbAnalysis_ts_ivas( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void cldfbAnalysis_ts_fx( const Word32 *timeIn_fx, @@ -1238,7 +1238,7 @@ void cldfbAnalysis_ts_fx_fixed_q( * * Conduct inverse multple overlap cmplex low delay MDCT *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas( float **realBuffer, /* i : real values */ float **imagBuffer, /* i : imag values */ @@ -1419,6 +1419,7 @@ void cldfbSynthesis_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfbSynthesis_ivas_fx( Word32 **realBuffer_fx, /* i : real values Qx*/ @@ -3390,7 +3391,7 @@ void cldfb_restore_memory_ivas( * * Resets the memory of filter. *--------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void cldfb_reset_memory_ivas( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ ) @@ -3412,6 +3413,7 @@ void cldfb_reset_memory_ivas( return; } +#endif #ifdef IVAS_FLOAT_FIXED void cldfb_reset_memory_fx( HANDLE_CLDFB_FILTER_BANK hs /* i/o: filter bank handle */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index a9ca1f48d..4a0e4ddb1 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3524,4 +3524,27 @@ void ivas_masa_estimate_energy_fx( const Word16 nchan_transport, /* i : number of MASA input/transport channels */ Word16 q_data /* i : q for data_fx */ ); + +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_masa_encode_fx( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word16 *nb_bits_metadata, /* o : number of metadata bits written */ + const Word16 nchan_transport, /* i : number of MASA input/transport channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 Opt_DTX_ON, /* i : DTX on flag */ + const Word16 element_mode, /* i : element mode */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const Word16 nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const Word16 idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const Word16 ism_imp, /* i : importance of separated object */ + const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +); #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index a16a4be54..552adb118 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -177,26 +177,13 @@ ivas_error ivas_qmetadata_allocate_memory( FOR( j = 0; j < nbands; j++ ) { -#ifndef IVAS_FLOAT_FIXED - set_zero( hQMetaData->q_direction[dir].band_data[j].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef MSAN_FIX - set_zero( hQMetaData->q_direction[dir].band_data[j].q_elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[j].q_azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif -#else 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].azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #ifdef MSAN_FIX set32_fx( hQMetaData->q_direction[dir].band_data[j].q_elevation_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); set32_fx( hQMetaData->q_direction[dir].band_data[j].q_azimuth_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #endif -#endif -#ifdef IVAS_FLOAT_FIXED set32_fx( hQMetaData->q_direction[dir].band_data[j].energy_ratio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); -#else - set_zero( hQMetaData->q_direction[dir].band_data[j].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif } } @@ -1193,8 +1180,8 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( } #else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth */ - const Word32 el, /* i : elevation */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ Word32 *dv /* o : direction vector */ ) { diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index db931df0f..4c15510fe 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -293,14 +293,20 @@ void small_reduction_direction( { Word16 i, j, k; + test(); FOR( k = 0; ( k < 2 ) && ( *diff > 0 ); k++ ) { + test(); + test(); FOR( i = q_direction->cfg.start_band; ( i < q_direction->cfg.nbands ) && ( *diff > 0 ); i++ ) { + test(); IF( EQ_16( raw_flag[i], 1 ) ) { + test(); FOR( j = 0; ( j < q_direction->cfg.nblocks ) && ( *diff > 0 ); j++ ) { + test(); IF( GT_32( bits_dir[i][j], MASA_MIN_BITS_TF ) ) { bits_dir[i][j] = (UWord16) L_sub( bits_dir[i][j], 1 ); @@ -569,7 +575,7 @@ ELSE } } -*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +*phi_hat = L_add_sat( L_add_sat( ( imult3216( delta_phi_fx, id_phi ) ), dd_fx ), DEGREE_180_Q_22 ); move32(); id_phi = add( id_phi, shr( n, 1 ) ); diff --git a/lib_com/prot.h b/lib_com/prot.h index d286851e0..f895ef5f2 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7926,12 +7926,13 @@ void UnmapIndex_ivas( int32_t *Lag ); void UnmapIndex_fx( - const Word16 PeriodicityIndex, - const Word16 Bandwidth, - const Word16 LtpPitchLag, - const Word8 SmallerLags, - Word16 *FractionalResolution, - Word32 *Lag ); + const Word16 PeriodicityIndex, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word8 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); /*! r: PeriodicityIndex */ int16_t SearchPeriodicityIndex( @@ -7962,8 +7963,9 @@ int16_t CountIndexBits_ivas( const int16_t PeriodicityIndex ); Word16 CountIndexBits_fx( - Word16 Bandwidth, /* 0: NB, 1: (S)WB */ - Word16 PeriodicityIndex ); + Word16 Bandwidth, /* 0: NB, 1: (S)WB Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); int16_t DecodeIndex( Decoder_State *st, @@ -7973,10 +7975,10 @@ int16_t DecodeIndex( #define GET_ADJ( T, L ) GET_ADJ2( T, L, *FractionalResolution ) #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) -int16_t tcx_hm_render_ivas( - const int16_t lag, /* i : pitch lag */ - const int16_t fract_res, /* i : fractional resolution of the lag */ - Word16 p[] /* o : harmonic model (Q13) */ +Word16 tcx_hm_render_ivas( + const Word16 lag, /* i : pitch lag Q0*/ + const Word16 fract_res, /* i : fractional resolution of the lag Q0*/ + Word16 p[] /* o : harmonic model Q13*/ ); Word32 tcx_hm_render_fx( @@ -7986,12 +7988,12 @@ Word32 tcx_hm_render_fx( ); void tcx_hm_modify_envelope_ivas( - const Word16 gain, /* i : HM gain (Q11) */ - const int16_t lag, - const int16_t fract_res, - const Word16 p[], /* i : harmonic model (Q13) */ - Word32 env[], /* i/o: envelope (Q16) */ - const int16_t L_frame /* i : number of spectral lines */ + const Word16 gain, /* i : HM gain Q11*/ + const Word16 lag, /* Q0 */ + const Word16 fract_res, /* Q0 */ + const Word16 p[], /* i : harmonic model Q13*/ + Word32 env[], /* i/o: envelope Q16*/ + const Word16 L_frame /* i : number of spectral lines Q0*/ ); void tcx_hm_modify_envelope_fx( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a148ab903..942135fbd 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5704,7 +5704,10 @@ Word16 IGFCommonFuncsIGFGetCFTables( ); // ari_fx.c Word32 L_multi31x16_X2( Word16 xh, Word16 xl, Word16 y ); -Word32 mul_sbc_14bits( Word32 r, Word16 c ); +Word32 mul_sbc_14bits( + Word32 r, /* Q0 */ + Word16 c /* Q0 */ +); // window.c void ham_cos_window( Word16 *fh, const Word16 n1, const Word16 n2 ); @@ -8750,26 +8753,28 @@ void getLPCparam_fx( // 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, /* Q0 */ + const Word16 Bandwidth, /* Q0 */ + const Word16 LtpPitchLag, /* Q0 */ + const Word16 SmallerLags, /* Q0 */ + Word16 *FractionalResolution, /* Q0 */ + Word32 *Lag /* Q0 */ +); 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 Q0*/ + const Word16 TargetBits, /* (I) Target bit budget (excl. Done flag) Q0*/ + const Word16 PeriodicityIndex, /* (I) Pitch related index Q0*/ + const Word16 LtpPitchLag, /* (I) TCX-LTP pitch in F.D. Q0*/ + 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 Q0*/ + Word16 PeriodicityIndex /* Q0 */ +); -int tcx_hm_render( +Word32 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 */ @@ -9035,23 +9040,29 @@ void lsf_weight_2st( const Word16 *lsfq, /* i : quantized lsf coefficients (3Q1 /* 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 Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + 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 Q0*/ + Word16 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); -Word16 update_mixed_context( Word16 ctx, Word16 a ); +Word16 update_mixed_context( + Word16 ctx, /* Q0 */ + Word16 a /* Q0 */ +); -Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a ); +Word32 update_mixed_context_ivas_fx( + Word32 ctx, /* Q0 */ + Word16 a /* Q0 */ +); // ACcontextMapping_dec_fx.c @@ -10847,10 +10858,10 @@ ivas_error push_next_bits( /*! r: index of next coefficient */ Word16 get_next_coeff_mapped_ivas( - Word16 ii[2], /* i/o: coefficient indexes */ - Word32 *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 Q0*/ + Word32 *pp, /* o : peak(1)/hole(0) indicator Q0*/ + Word16 *idx, /* o : index in unmapped domain Q0*/ + CONTEXT_HM_CONFIG *hm_cfg /* i : HM configuration */ ); void RCcontextMapping_encode2_no_mem_s17_LCS_fx( diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c3b8c7cbc..1a5a95af5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -632,7 +632,7 @@ ivas_error ivas_enc( #else ivas_error ivas_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 *data, /* i : input signal */ + const Word16 *data, /* i : input signal Q0 */ const Word16 n_samples /* i : number of input samples */ ) { @@ -642,7 +642,9 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Word16 nb_bits_metadata[MAX_SCE + 1]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; +#endif Word32 *data_fx[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS]; Word32 ivas_total_brate; ivas_error error; @@ -685,7 +687,9 @@ ivas_error ivas_enc( FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n] = st_ivas->p_data_f[n]; // float initialization to be removed +#endif data_fx[n] = st_ivas->p_data_fx[n]; } @@ -697,8 +701,10 @@ ivas_error ivas_enc( { FOR( i = 0; i < n_samples_chan; i++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS data_f[n][i] = (float) data[i * nchan_inp + n]; // float initialization to be removed - data_fx[n][i] = L_mult0( data[add( imult1616( i, nchan_inp ), n )], shl( 1, st_ivas->q_data_fx ) ); +#endif + data_fx[n][i] = L_mult0( data[i * nchan_inp + n], shl( 1, st_ivas->q_data_fx ) ); move32(); } n = add( n, 1 ); @@ -708,7 +714,9 @@ ivas_error ivas_enc( { FOR( n = 0; n < nchan_inp; n++ ) { +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan ); // float initialization to be removed +#endif set32_fx( data_fx[n] + n_samples_chan, 0, sub( input_frame, n_samples_chan ) ); } } @@ -741,19 +749,11 @@ ivas_error ivas_enc( test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) ) && !( GT_16( st_ivas->sba_analysis_order, 1 ) ) ) { -#ifndef IVAS_FLOAT_FIXED - 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 hp20_fix32( data_fx[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } ELSE IF( !( EQ_32( ivas_format, MC_FORMAT ) && EQ_16( i, LFE_CHANNEL ) ) ) { -#ifndef IVAS_FLOAT_FIXED - hp20_flt( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs ); // To be removed -#else hp20_fix32( data_fx[i], input_frame, st_ivas->mem_hp20_in_fx[i], input_Fs ); -#endif } } @@ -768,11 +768,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * write IVAS format signaling *----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - ivas_write_format( st_ivas ); -#else ivas_write_format_fx( st_ivas ); -#endif + /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ @@ -850,20 +847,28 @@ ivas_error ivas_enc( } } } - else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { /* MASA configuration */ - if ( ivas_format == MASA_FORMAT ) + IF( EQ_32( ivas_format, MASA_FORMAT ) ) { - ivas_masa_enc_reconfigure( st_ivas ); + ivas_masa_enc_reconfigure_fx( st_ivas ); } /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */ - hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + /* hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; */ + IF( st_ivas->nSCE > 0 ) + { + hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData; + } + ELSE + { + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + } - if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT ) + test(); + IF( st_ivas->hQMetaData != NULL && EQ_32( ivas_format, MASA_FORMAT ) ) { -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < st_ivas->nchan_transport; i++ ) { @@ -879,65 +884,68 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */ -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + + IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->hCPE[0]->element_mode, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } -#endif // IVAS_FLOAT_FIXED - - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + ELSE { - return error; + IF( NE_32( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ), + IVAS_ERR_OK ) ) + { + return error; + } } } - else if ( ivas_format == SBA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) ) { - if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK ) { return error; } } - if ( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { ivas_sba_getTCs( data_f, st_ivas, input_frame ); } /* core-coding of transport channels */ - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */ + ELSE IF( GT_16( st_ivas->nCPE, 1 ) ) /* FOA/HOA format */ { - if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { float *data_separated_object; Word32 *data_separated_object_fx; @@ -1085,8 +1093,8 @@ ivas_error ivas_enc( } /* Encode MASA parameters and write MASA metadata bitstream */ - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -1360,8 +1368,8 @@ ivas_error ivas_enc( #else ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); #endif - if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, - ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a8375d542..9b975d935 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -172,7 +172,132 @@ static void masa_metadata_direction_alignment( MASA_ENCODER_HANDLE hMasa ); * * open and initialize MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_masa_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + Word16 i; + MASA_ENCODER_HANDLE hMasa; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + Word32 ism_total_brate; + + error = IVAS_ERR_OK; + move32(); + + IF( ( hMasa = (MASA_ENCODER_HANDLE) malloc( sizeof( MASA_ENCODER ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); + } + + hEncoderConfig = st_ivas->hEncoderConfig; + + generate_gridEq_fx( &( hMasa->data.Sph_Grid16 ) ); + + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_FORMAT ) || EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + hMasa->data.num_Cldfb_instances = st_ivas->nchan_transport; + move16(); + } + ELSE + { + hMasa->data.num_Cldfb_instances = 0; + move16(); + } + + FOR( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) + { + IF( ( error = openCldfb_ivas_enc( &( hMasa->data.cldfbAnaEnc[i] ), CLDFB_ANALYSIS, hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[i]->element_brate ); + } + } + + ivas_masa_set_elements_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + + Copy( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + Copy( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); + + hMasa->data.onset_detector_1_fx = 0; + hMasa->data.onset_detector_2_fx = 0; + hMasa->data.q_onset_detector = 0; + move32(); + move32(); + move16(); + + set32_fx( hMasa->data.lfeToTotalEnergyRatio_fx, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + set16_fx( hMasa->data.lfeToTotalEnergyRatio_e, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + hMasa->data.prevq_lfeToTotalEnergyRatio_fx = 0; + move32(); + + hMasa->data.prevq_lfeIndex = 0; + move16(); + + hMasa->data.sync_state.prev_sim_stop = 0; + hMasa->data.sync_state.prev_offset = 0; + hMasa->data.sync_state.frame_mode = MASA_FRAME_4SF; + move16(); + move16(); + move32(); + + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir1_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_azi_dir2_fx, MASA_FREQUENCY_BANDS ); + set_zero_fx( hMasa->data.dir_align_state.previous_ele_dir2_fx, MASA_FREQUENCY_BANDS ); + + IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) + { + OMASA_ENCODER_DATA_HANDLE hOmasaData; + + IF( ( hOmasaData = (OMASA_ENCODER_DATA_HANDLE) malloc( sizeof( OMASA_ENCODER_DATA_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); + } + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set32_fx( hOmasaData->masa_to_total_energy_ratio_fx[i], 0, MASA_FREQUENCY_BANDS ); + } + + hOmasaData->lp_noise_CPE_fx = -256; /* -1 in Q8 */ + move16(); + hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + move16(); + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); + set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); + } + + hMasa->data.hOmasaData = hOmasaData; + } + ELSE + { + hMasa->data.hOmasaData = NULL; + } + + st_ivas->hMasa = hMasa; + return error; +} +#else ivas_error ivas_masa_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -326,14 +451,43 @@ ivas_error ivas_masa_enc_open( return error; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_enc_close() * * close MASA encoder *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_masa_enc_close( + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ +) +{ + Word16 i; + test(); + IF( hMasa == NULL || *hMasa == NULL ) + { + return; + } + + FOR( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) + { + deleteCldfb_ivas( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); + } + + IF( ( *hMasa )->data.hOmasaData != NULL ) + { + free( ( *hMasa )->data.hOmasaData ); + ( *hMasa )->data.hOmasaData = NULL; + } + + free( ( *hMasa ) ); + ( *hMasa ) = NULL; + + return; +} +#else void ivas_masa_enc_close( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ) @@ -361,7 +515,7 @@ void ivas_masa_enc_close( return; } - +#endif /*-----------------------------------------------------------------------* * ivas_masa_encode() @@ -370,7 +524,7 @@ void ivas_masa_enc_close( *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_masa_encode( +ivas_error ivas_masa_encode_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ @@ -1620,6 +1774,7 @@ ivas_error ivas_masa_enc_config_fx( maxBin = extract_l( Mpy_32_32( st_ivas->hEncoderConfig->input_Fs /*q0*/, INV_CLDFB_BANDWIDTH_Q31 /*Q31*/ ) ); /*q0+q31-q31->q0*/ maxBand = 0; move16(); + test(); WHILE( LE_16( maxBand, MASA_FREQUENCY_BANDS ) && LE_16( MASA_band_grouping_24[maxBand], maxBin ) ) { test(); @@ -1645,6 +1800,7 @@ ivas_error ivas_masa_enc_config_fx( Word16 continueLoop; continueLoop = 1; move16(); + test(); WHILE( GT_16( maxBand, 5 ) && continueLoop ) { test(); @@ -2862,7 +3018,7 @@ void ivas_masa_combine_directions_fx( move32(); } - if ( numSf != 1 ) + IF( NE_16( numSf, 1 ) ) { importance_fx[i] = L_shr( importance_fx[i], 2 ); move32(); @@ -4777,7 +4933,7 @@ static int16_t encode_lfe_to_total_energy_ratio( * * Reconfigure IVAS MASA encoder *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -4845,7 +5001,86 @@ void ivas_masa_enc_reconfigure( return; } +#else +void ivas_masa_enc_reconfigure_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + Word16 n, tmp; + Word16 sce_id, cpe_id; + Word32 ivas_total_brate; + Word32 ism_total_brate; + Word32 tmp_br, tmp_mod; + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); + + ism_total_brate = 0; + move32(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate = L_add( ism_total_brate, st_ivas->hSCE[sce_id]->element_brate ); + } + } + + IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) + { + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp_mod, 0 ); + FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); + st_ivas->hSCE[sce_id]->element_brate = tmp_br; + st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + move32(); + } + + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->element_brate = imult3216( tmp_br, 2 ); //( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + + IF( st_ivas->nCPE > 1 ) + { + tmp = 1; + } + ELSE + { + tmp = CPE_CHANNELS; + } + move16(); + /* prepare bitstream buffers */ + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); + /* st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); */ + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, sub( tmp, 1 ) ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + + IF( LT_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + } + ELSE + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } + move16(); + } + + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); + } + + return; +} +#endif /*-------------------------------------------------------------------* * average_masa_metadata() diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index bde299111..f34ae9ef0 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -558,7 +558,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( move16(); /* This sets bit budget correctly for the second direction */ - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { bits_diff[d] = bits_diff_sum; move16(); @@ -714,6 +714,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( } /* Requantized directions */ + test(); IF( LE_16( add( total_bits_1dir, bits_surround_coh ), hQMetaData->qmetadata_max_bit_req ) && GT_16( add( add( add( bits_dir[d], bits_diff[d] ), bits_coherence[d] ), bits_signaling[d] ), total_bits_1dir ) ) { @@ -1447,7 +1448,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( Word16 ndirections, d; Word16 all_coherence_zero; Word16 bits_ec; - Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 azimuth_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; // Q22 ivas_error error; error = IVAS_ERR_OK; @@ -1487,7 +1488,7 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512_fx( move16(); FOR( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { - IF( hQMetaData->twoDirBands[i] == 1 ) + IF( EQ_16( hQMetaData->twoDirBands[i], 1 ) ) { Copy32( hQMetaData->q_direction[1].band_data[i].azimuth_fx, hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].cfg.nblocks ); Copy32( hQMetaData->q_direction[1].band_data[i].elevation_fx, hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].cfg.nblocks ); @@ -1620,7 +1621,7 @@ void ivas_qmetadata_enc_sid_encode_fx( const Word16 ivas_format /* i : IVAS format */ ) { - Word16 b, m; + Word16 b, m, i; Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; Word16 nbands, nblocks, start_band; @@ -1717,8 +1718,10 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta > 0 ) { + test(); FOR( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) { + test(); IF( LT_16( q_direction->band_data[b].bits_sph_idx[0], 11 ) ) { bits_delta = sub( bits_delta, 1 ); @@ -1732,7 +1735,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1741,15 +1744,17 @@ void ivas_qmetadata_enc_sid_encode_fx( { WHILE( bits_delta < 0 ) { + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( GE_16( q_direction->band_data[b].bits_sph_idx[0], 4 ) ) { bits_delta = add( bits_delta, 1 ); q_direction->band_data[b].bits_sph_idx[0] = sub( q_direction->band_data[b].bits_sph_idx[0], 1 ); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } } @@ -1765,10 +1770,11 @@ void ivas_qmetadata_enc_sid_encode_fx( bits_diff = add( bits_diff, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].energy_ratio_index[0], 4 ), DIRAC_DIFFUSE_LEVELS - 4 ) ); q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; move16(); + move16(); IF( q_direction->not_in_2D == 0 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, ( s_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); bits_dir = add( bits_dir, ivas_qmetadata_encode_quasi_uniform_length( sub( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ), q_direction->band_data[b].azimuth_m_alphabet[0] ) ); } @@ -1784,8 +1790,11 @@ void ivas_qmetadata_enc_sid_encode_fx( test(); WHILE( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) { + test(); + test(); FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { + test(); IF( LT_16( q_direction->band_data[b].energy_ratio_index[0], ( DIRAC_DIFFUSE_LEVELS - 1 ) ) ) { bits_delta = add( bits_delta, q_direction->band_data[b].bits_sph_idx[0] ); @@ -1814,7 +1823,7 @@ void ivas_qmetadata_enc_sid_encode_fx( { /*compute the average direction */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - FOR( int i = 0; i < 3; i++ ) + FOR( i = 0; i < 3; i++ ) { avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); move32(); @@ -2227,13 +2236,13 @@ Word16 quantize_direction2D_fx( IF( NE_32( mc_format, MC_LS_SETUP_INVALID ) ) { - id_phi = quantize_phi_chan_compand_fx( L_add( phi, 180 << Q22 ), phi_q, no_cw, 0, mc_format ); + id_phi = quantize_phi_chan_compand_fx( L_add( phi, DEGREE_180_Q_22 ), phi_q, no_cw, 0, mc_format ); } ELSE { - id_phi = quantize_phi_enc_fx( L_add( phi, 180 << Q22 ), 0, phi_q, no_cw ); + id_phi = quantize_phi_enc_fx( L_add( phi, DEGREE_180_Q_22 ), 0, phi_q, no_cw ); } - *phi_q = L_sub( *phi_q, 180 << Q22 ); + *phi_q = L_sub( *phi_q, DEGREE_180_Q_22 ); move32(); *index_phi = ivas_qmetadata_reorder_generic( sub( id_phi, shr( no_cw, 1 ) ) ); @@ -2517,10 +2526,10 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( #ifdef IVAS_FLOAT_FIXED static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t *nbits_diff, - int16_t *dfRatioBits, - const int16_t hodirac_flag ) + Word16 *needed_bits, + Word16 *nbits_diff, + Word16 *dfRatioBits, + const Word16 hodirac_flag ) { Word16 j, k, dir2band; Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; @@ -2531,10 +2540,16 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( needed_bits[0] = 0; needed_bits[1] = 0; dir2band = 0; + move16(); + move16(); + move16(); + move16(); + move16(); FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { - IF( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + test(); + IF( EQ_16( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { Word32 diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; /* Q30 */ Word32 dirRatio1, dirRatio2, sumRatio; /* Q30 */ @@ -2547,22 +2562,34 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { /* already encoded as total and ratios in HO-DirAC */ - diffRatio = ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; + diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; + move32(); + move32(); } ELSE { - // TODO dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; - sumRatio = dirRatio1 + dirRatio2; - diffRatio = ( 1 << 30 ) - sumRatio; - dfRatio = sumRatio < EPSILON_FIX ? ( 1 << 29 ) : ( (Word32) div_l( dirRatio1, extract_h( sumRatio ) ) << 15 ); + move32(); + move32(); + sumRatio = L_add( dirRatio1, dirRatio2 ); + diffRatio = L_sub( ONE_IN_Q30, sumRatio ); + IF( LT_32( sumRatio, EPSILON_FIX ) ) + { + dfRatio = ONE_IN_Q30 / 2; // 0.5 in Q30 + move32(); + } + ELSE + { + dfRatio = L_shl( L_deposit_l( div_l( dirRatio1, extract_h( sumRatio ) ) ), 15 ); // Q30 + } } index_diff = masa_sq_fx( diffRatio, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - diffRatioQ = diffuseness_reconstructions_fx[index_diff]; + diffRatioQ = diffuseness_reconstructions_fx[index_diff]; // Q30 + move32(); IF( hodirac_flag ) { @@ -2574,29 +2601,29 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( } dfRatioBits[dir2band] = dfRatio_bits; + move16(); - dfRatio_qsteps = ( 1 << dfRatio_bits ); + dfRatio_qsteps = shl( 1, dfRatio_bits ); IF( hodirac_flag ) { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 2 ), dfRatio_qsteps ); - dfRatioQ = (Word32) dfRatioQ16 << 16; - dirRatio1Q = ( 1 << 30 ) - diffRatioQ; + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ) /* Q13 */, dfRatio_qsteps ); + dfRatioQ = L_deposit_h( dfRatioQ16 ); // Q30 + dirRatio1Q = L_sub( ONE_IN_Q30, diffRatioQ ); // Q30 dirRatio2Q = dfRatioQ; + move32(); } ELSE { - // TODO Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ( 1 << 13 ), ( div_s( 1, ( dfRatio_qsteps - 1 ) ) >> 3 ), dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ONE_IN_Q13, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ) /* Q12 */, dfRatio_qsteps ); /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ - dirRatio1Q = L_shl( Mpy_32_16_1( ( ( 1 << 30 ) - diffRatioQ ), dfRatioQ16 ), 1 ); - dirRatio2Q = ( ( 1 << 30 ) - diffRatioQ ) - dirRatio1Q; + dirRatio1Q = L_shl( Mpy_32_16_1( L_sub( ONE_IN_Q30, diffRatioQ ), dfRatioQ16 ), 1 ); // Q30 + dirRatio2Q = L_sub( L_sub( ONE_IN_Q30, diffRatioQ ), dirRatio1Q ); // Q30 } - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio1Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio1Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are @@ -2605,26 +2632,31 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; + move16(); + move32(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); IF( hodirac_flag ) { - // TODO Word16 tmp; /* Q14 */ - index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, ( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ) >> 2 ), DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, shr( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ), 2 ) /* Q13 */, DIRAC_DIFFUSE_LEVELS ); } - else + ELSE { - index_dirRatio2Inv = masa_sq_fx( ( 1 << 30 ) - dirRatio2Q, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio2Q ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); } FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; + move16(); + move32(); } - nbits_diff[1] += dfRatio_bits; + nbits_diff[1] = add( nbits_diff[1], dfRatio_bits ); + move16(); /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values @@ -2636,33 +2668,45 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( { hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; + move16(); + move16(); } - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv_mod] ) ); + move16(); FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; + move16(); + move16(); } - needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + needed_bits[1] = add( needed_bits[1], imult1616( hQMetaData->q_direction[1].cfg.nblocks, bits_direction_masa[index_dirRatio2Inv_mod] ) ); + move16(); - dir2band++; + dir2band = add( dir2band, 1 ); } ELSE { - index_dirRatio1Inv = masa_sq_fx( ( 1 << 30 ) - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0], diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = ( 1 << 30 ) - diffuseness_reconstructions_fx[index_dirRatio1Inv]; + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; + move16(); + move16(); + move32(); + move16(); } - nbits_diff[0] += MASA_BITS_ER; + nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); + move16(); - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv] ) ); + move16(); } } @@ -2836,7 +2880,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( { IF( idx > 0 ) { - push_next_indice( hMetaData, ( 1 << idx ) - 1, idx ); + push_next_indice( hMetaData, (UWord16) L_sub( L_shl( 1, idx ), 1 ), idx ); nbits = add( nbits, idx ); } push_next_indice( hMetaData, 0, 1 ); @@ -2845,7 +2889,7 @@ static Word16 ivas_diffuseness_huff_ec_encode_fx( ELSE { push_next_indice( hMetaData, 511, DIFF_EC_HUFF_GR0_LIMIT + 1 ); - push_next_indice( hMetaData, idx - DIFF_EC_HUFF_GR0_LIMIT - 1, 2 ); + push_next_indice( hMetaData, (UWord16) L_sub( idx, DIFF_EC_HUFF_GR0_LIMIT + 1 ), 2 ); nbits = add( nbits, DIFF_EC_HUFF_GR0_LIMIT + 3 ); } return nbits; @@ -2934,6 +2978,7 @@ static void ivas_diffuseness_huff_ec_prepare_fx( { ui_sh_idx[b] = sub( shl( sh_idx, 1 ), 1 ); } + move16(); if ( GE_32( ui_sh_idx[b], 2 * DIRAC_DIFFUSE_LEVELS - 3 ) ) { bits = 100; /* to avoid difference larger than 6 in absolute value */ @@ -3372,7 +3417,7 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( IF( EQ_16( min_index, max_index ) && ec_mode > 0 ) /* all values are equal */ { push_next_indice( hMetaData, 0, 1 ); /* Signal between EC and raw */ - if ( GT_16( ec_mode, 1 ) ) + IF( GT_16( ec_mode, 1 ) ) { /* Only use bit for signaling if necessary */ push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ @@ -3384,11 +3429,11 @@ static Word16 ivas_qmetadata_entropy_encode_df_ratio_fx( { push_next_indice( hMetaData, 0, 1 ); push_next_indice( hMetaData, 1, 1 ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size - 1 ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, sub( max_alphabet_size, 1 ) ); FOR( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_index, 1 ); /* Band-wise offset values */ + push_next_indice( hMetaData, sub( q_direction->band_data[b].energy_ratio_index[0], min_index ), 1 ); /* Band-wise offset values */ } } ELSE /* raw coding */ @@ -3747,7 +3792,7 @@ static Word16 GR_bits_azimuth_context( move16(); FOR( i = 0; i < no_data_in; i++ ) { - IF( data_in[i] < MASA_NO_INDEX ) + IF( LT_32( data_in[i], MASA_NO_INDEX ) ) { no_symb_local[no_data] = no_symb[i]; move16(); @@ -4257,7 +4302,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( } } - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); /* Elevation only if not 2D */ IF( q_direction->not_in_2D > 0 ) @@ -4398,9 +4443,9 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); IF( GE_16( sub( nbands, start_band ), 5 ) && NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, 180 << Q22 ), &avg_azimuth ); // 180.Q22 + use_adapt_avg = calc_var_azi_fx( q_direction, diffuseness_index_max_ec_frame, L_sub( avg_azimuth, DEGREE_180_Q_22 ), &avg_azimuth ); // 180.Q22 - avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, 180 << Q22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); + avg_azimuth_index = (UWord16) ( quantize_phi_enc_fx( L_add( avg_azimuth, DEGREE_180_Q_22 ), 0, &avg_azimuth, avg_azimuth_alphabet ) ); } avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ move16(); @@ -4526,7 +4571,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( test(); test(); test(); - if ( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) + IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( dist_count, 4 ) && NE_16( gr_param_azimuth_best, 5 ) && GT_16( nblocks, 1 ) ) { azimuth_bits_ec_best = add( azimuth_bits_ec_best, 1 ); } @@ -4598,7 +4643,7 @@ static Word16 ivas_qmetadata_entropy_encode_dir_fx( IF( NE_16( gr_param_azimuth_best, 5 ) ) /* not all zero */ { - FOR( idx = 0; idx < min( nblocks, dist_count ); idx++ ) + FOR( idx = 0; idx < s_min( nblocks, dist_count ); idx++ ) { test(); test(); @@ -5739,6 +5784,18 @@ static Word16 truncGR0_fx( Word32 diff_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 indx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 L_temp; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); bits = 0; move16(); set_val_Word32( data_hat_fx, 0, len ); @@ -5781,7 +5838,7 @@ static Word16 truncGR0_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 8, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[i] - data_hat[i] ) ); /*(data[i] - data_hat[i])*(data[i] - data_hat[i]);*/ L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5807,7 +5864,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } IF( LE_16( bits, bits_allowed ) ) @@ -5848,7 +5905,7 @@ static Word16 truncGR0_fx( // diff[indx[i]] = -st[i] - ct[i] * cosf( PI_OVER_180 * ( data[indx[i]] - data_hat[indx[i]] ) ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[indx[i]], data_hat_fx[indx[i]] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[indx[i]] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[indx[i]] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -5866,7 +5923,7 @@ static Word16 truncGR0_fx( FOR( i = len - 1; i >= 0; i-- ) { - if ( data_idx[indx[i]] > 0 ) + IF( data_idx[indx[i]] > 0 ) { bits = sub( bits, data_idx[indx[i]] ); data_idx[indx[i]] = 0; @@ -6070,7 +6127,7 @@ static Word16 truncGR0_chan_fx( bits = add( bits, ivas_qmetadata_encode_extended_gr_length( data_idx[i], 9, 0 ) ); // diff[i] = -st[i] - ct[i] * cosf( ( data[i] - data_hat[i] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[i], data_hat_fx[i] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 + diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); } @@ -6083,18 +6140,18 @@ static Word16 truncGR0_chan_fx( move16(); idx_crt = -1; move16(); - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); FOR( i = 0; i < len; i++ ) { IF( data_idx[i] > 0 ) { // sort_diff[i] = -st[i] - ct[i] * cosf( ( fabsf( data[i] ) - cb_azi_chan[( ( data_idx[i] + 1 ) >> 1 ) - 1] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( L_abs( data_fx[i] ), cb_azi_chan_fx[( ( data_idx[i] + 1 ) >> 1 ) - 1] ), 91 ), 7 ) ) ) ); // Q31 - sort_diff_fx[i] = -L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ); // Q30 // Q30 + sort_diff_fx[i] = L_negate( L_add( L_shr( st_fx[i], 1 ), L_shr( Mpy_32_32( ct_fx[i], L_temp ), 1 ) ) ); // Q30 move32(); sum_diff_fx = sum2_f_32_fx( sort_diff_fx, len, gb ); // Q(2*Q30-31-gb)= Q(Q29-gb) Word16 flag = BASOP_Util_Cmp_Mant32Exp( sum_diff_fx, sub( Q31, sub( Q29, gb ) ), min_diff_fx, min_diff_e ); - if ( EQ_16( flag, -1 ) ) + IF( EQ_16( flag, -1 ) ) { min_diff_fx = sum_diff_fx; move32(); @@ -6116,7 +6173,7 @@ static Word16 truncGR0_chan_fx( // diff[idx_crt] = -st[idx_crt] - ct[idx_crt] * cosf( ( data[idx_crt] - data_hat[idx_crt] ) * PI_OVER_180 ); L_temp = L_deposit_h( getCosWord16R2( extract_l( L_shr( Mpy_32_16_1( L_sub( data_fx[idx_crt], data_hat_fx[idx_crt] ), 91 ), 7 ) ) ) ); // Q31 - diff_fx[idx_crt] = -L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ); // Q30 + diff_fx[idx_crt] = L_negate( L_add( L_shr( st_fx[idx_crt], 1 ), L_shr( Mpy_32_32( ct_fx[idx_crt], L_temp ), 1 ) ) ); // Q30 move32(); } ELSE @@ -6127,7 +6184,7 @@ static Word16 truncGR0_chan_fx( IF( GT_16( bits, bits_allowed ) ) { - MVR2R_WORD32( diff_fx, sort_diff_fx, len ); + Copy32( diff_fx, sort_diff_fx, len ); sort_desc_ind_32_fx( sort_diff_fx, len, indx ); FOR( i = len - 1; i >= 0; i-- ) @@ -6360,7 +6417,7 @@ static Word16 common_direction_fx( // dist += ( elevation_orig[k] - theta_cb[i] ) * ( elevation_orig[k] - theta_cb[i] ); dist_fx = L_add( dist_fx, L_shr( Mpy_32_32( L_sub( elevation_orig_fx[k], theta_cb_fx[i] ), L_sub( elevation_orig_fx[k], theta_cb_fx[i] ) ), gb ) ); // Q(2*Q22-31) = Q13-gb } - if ( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) + IF( LT_32( L_shr( dist_fx, sub( sub( Q13, gb ), best_dist_q ) ), best_dist_fx ) ) { id_th = i; move16(); @@ -6706,7 +6763,7 @@ static Word16 encode_directions_subband_fx( move16(); FOR( k = 0; k < no_subframes; k++ ) { - if ( GT_16( bits_dir0[k], use_vq ) ) + IF( GT_16( bits_dir0[k], use_vq ) ) { use_vq = bits_dir0[k]; move16(); @@ -6717,7 +6774,8 @@ static Word16 encode_directions_subband_fx( IF( GT_16( no_subframes, 1 ) ) { - if ( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) + test(); + IF( GT_16( use_vq, 1 ) && LE_16( use_vq, LIMIT_USE_COMMON ) ) { bits_dir0[max_nb_idx] = sub( bits_dir0[max_nb_idx], 1 ); move16(); @@ -6753,8 +6811,8 @@ static Word16 encode_directions_subband_fx( IF( last_subband == 0 ) { - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); joint_encoding_fx( q_direction, j, next_j, coding_subbands, bits_dir0, allowed_bits, hMetaData, &diff ); } ELSE @@ -6777,8 +6835,8 @@ static Word16 encode_directions_subband_fx( ELSE { /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -6805,8 +6863,8 @@ static Word16 encode_directions_subband_fx( { /* 1 subframe case */ /* there is only joint coding */ - MVR2R_WORD32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); - MVR2R_WORD32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); + Copy32( elevation_orig_fx, q_direction->band_data[j].elevation_fx, no_subframes ); + Copy32( azimuth_orig_fx, q_direction->band_data[j].azimuth_fx, no_subframes ); IF( last_subband == 0 ) { @@ -7341,6 +7399,7 @@ static ivas_error requantize_direction_EC_3_fx( } } + test(); IF( LE_16( use_vq, 3 ) && LE_16( allowed_bits, 11 ) ) { @@ -7480,14 +7539,10 @@ static void joint_encoding_fx( q_direction->band_data[j].bits_sph_idx[k] = bits_dir0[k]; move16(); -/* requantize the direction */ -#if 1 + /* requantize the direction */ q_direction->band_data[j].spherical_index[k] = quantize_direction_fx( q_direction->band_data[j].elevation_fx[k], q_direction->band_data[j].azimuth_fx[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation_fx[k], &q_direction->band_data[j].azimuth_fx[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#else - q_direction->band_data[j].spherical_index[k] = quantize_direction( q_direction->band_data[j].elevation[k], q_direction->band_data[j].azimuth[k], q_direction->band_data[j].bits_sph_idx[k], &q_direction->band_data[j].elevation[k], - &q_direction->band_data[j].azimuth[k], &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); -#endif + move16(); IF( GE_32( bits_dir0[k], 3 ) ) { @@ -7541,7 +7596,7 @@ static void joint_encoding_fx( /* encode indexes for current subband and count the number of bits */ - + test(); IF( EQ_16( q_direction->cfg.nblocks, 1 ) && LE_32( q_direction->band_data[j].bits_sph_idx[0], MASA_MIN_BITS_TF + 1 ) ) { /* encode with fixed rate only if only one subframe and very low number of bits */ @@ -7566,12 +7621,13 @@ static void joint_encoding_fx( move16(); FOR( k = 1; k < q_direction->cfg.nblocks; k++ ) { - IF( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) + if ( NE_32( q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].elevation_index[0] ) ) { same = 0; move16(); } } + test(); IF( EQ_16( same, 1 ) && LT_32( q_direction->band_data[j].elevation_index[0], 4 ) ) { nbits = 3; @@ -7619,6 +7675,7 @@ static void joint_encoding_fx( } } *diff = add( *diff, sub( nbits, allowed_bits ) ); + move16(); update_bits_next_block( q_direction, diff, next_j, coding_subbands, q_direction->cfg.nblocks ); return; @@ -8744,7 +8801,7 @@ static Word16 encode_spread_coherence_1sf_fx( IF( idx_ER > 0 ) { // idx_sp_coh[j] = (uint16_t) roundf( q_direction->coherence_band_data[j].spread_coherence[0] / ( 255.0f / (float) idx_ER ) ); - idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 ) ); + idx_sp_coh[j] = extract_l( Mpy_32_32_r( imult1616( q_direction->coherence_band_data[j].spread_coherence[0], idx_ER ), 8421505 /* 1/255.f in Q31 */ ) ); move16(); // q_direction->coherence_band_data[j].spread_coherence[0] = (uint8_t) roundf( idx_sp_coh[j] * ( 255.0f / (float) idx_ER ) ); IF( idx_sp_coh[j] ) @@ -8781,12 +8838,12 @@ static Word16 encode_spread_coherence_1sf_fx( nbits_max = 0; move16(); - if ( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) + IF( GT_16( coding_subbands, MASA_LIMIT_NO_BANDS_SUR_COH ) ) { j = maximum_s( (Word16 *) idx_sp_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -8893,7 +8950,7 @@ static Word16 encode_spread_coherence_1sf_fx( /* write the min */ bits_GR = hMasaMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv, 0 ); + ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, add( MASA_MAX_NO_CV_SUR_COH, extra_cv ), 0 ); nbits = add( nbits, sub( hMasaMetaData->nb_bits_tot, bits_GR ) ); /* write GR data */ @@ -9197,7 +9254,7 @@ static Word16 encode_surround_coherence_fx( j = maximum_s( (Word16 *) idx_sur_coh, coding_subbands, &max_val ); FOR( j = 0; j < coding_subbands; j++ ) { - if ( GT_16( no_cv[j], add( max_val, 1 ) ) ) + IF( GT_16( no_cv[j], add( max_val, 1 ) ) ) { no_cv[j] = add( max_val, 1 ); move16(); @@ -9225,7 +9282,7 @@ static Word16 encode_surround_coherence_fx( /* write max value*/ bits_GR = hMetaData->nb_bits_tot; move16(); - ivas_qmetadata_encode_extended_gr( hMetaData, MASA_MAX_NO_CV_SUR_COH - max_val - 1, MASA_MAX_NO_CV_SUR_COH, 0 ); + ivas_qmetadata_encode_extended_gr( hMetaData, sub( MASA_MAX_NO_CV_SUR_COH - 1, max_val ), MASA_MAX_NO_CV_SUR_COH, 0 ); nbits = add( nbits, sub( hMetaData->nb_bits_tot, bits_GR ) ); } @@ -10509,12 +10566,14 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { d = 0; + move16(); FOR( j = 0; j < coding_subbands_0; j++ ) { - if ( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) + IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - two_dir_band[d++] = j; + two_dir_band[d] = j; move16(); + d = add( d, 1 ); } } } @@ -10569,7 +10628,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( { /* make two indxes */ no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands / 2; j++ ) { @@ -10587,7 +10646,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( nbits = sub( 63, W_norm( W_sub( no_cb, 1 ) ) ); } no_cb = 1; - move16(); + move64(); FOR( j = coding_subbands / 2; j < coding_subbands; j++ ) { @@ -10607,7 +10666,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( ELSE { no_cb = 1; - move16(); + move64(); FOR( j = 0; j < coding_subbands; j++ ) { @@ -10631,17 +10690,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( FOR( j = 0; j < coding_subbands; j++ ) { /* inverse DCT transform */ - -#ifdef IVAS_FLOAT_FIXED - - /*================================flt-2-fix========================================*/ - // floatToFixed_arrL( dct_coh[j], dct_coh_fx[j], Q21, MAX_PARAM_SPATIAL_SUBFRAMES ); // Q21 is used in decoder hence chosed otherwise function can work with variable Q - /*================================fix-2-flt========================================*/ - invdct4_transform_fx( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence, Q21 ); -#else - invdct4_transform( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence ); -#endif } nbits = encode_coherence_indexesDCT0_fx( idx_dct, coding_subbands, no_cb_vec, hMetaData, *indice_coherence, nbits, nbits1 ); @@ -10665,7 +10714,7 @@ static Word16 ivas_qmetadata_quantize_coherence_fx( move16(); WHILE( k > 0 ) { - push_next_indice( hMetaData, 0, min( 16, k ) ); + push_next_indice( hMetaData, 0, s_min( 16, k ) ); k = sub( k, 16 ); } } @@ -11131,23 +11180,23 @@ static void transform_azimuth_dir2_fx( FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nblocks; b++ ) { Word64 azimuth; - azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), 180 << Q22 ); + azimuth = W_add( W_deposit32_l( L_sub( hQMetaData->q_direction[1].band_data[i].azimuth_fx[b], hQMetaData->q_direction[0].band_data[dir2_bands[i]].azimuth_fx[b] ) ), DEGREE_180_Q_22 ); - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } - if ( GE_64( azimuth, 180 << Q22 ) ) + IF( GE_64( azimuth, DEGREE_180_Q_22 ) ) { - azimuth = W_sub( azimuth, 360 << Q22 ); + azimuth = W_sub( azimuth, DEGREE_360_Q_22 ); } - if ( LT_64( azimuth, -( 180 << Q22 ) ) ) + IF( LT_64( azimuth, -DEGREE_180_Q_22 ) ) { - azimuth = W_add( azimuth, 360 << Q22 ); + azimuth = W_add( azimuth, DEGREE_360_Q_22 ); } hQMetaData->q_direction[1].band_data[i].azimuth_fx[b] = W_extract_l( azimuth ); diff --git a/lib_enc/ivas_qspherical_enc.c b/lib_enc/ivas_qspherical_enc.c index d2804108a..48e4bb93d 100644 --- a/lib_enc/ivas_qspherical_enc.c +++ b/lib_enc/ivas_qspherical_enc.c @@ -206,6 +206,7 @@ void quantize_direction_frame_fx( &q_direction->band_data[i].azimuth_fx[j], &q_direction->band_data[i].elevation_index[j], &q_direction->band_data[i].azimuth_index[j], q_direction->cfg.mc_ls_setup ); + move16(); q_direction->not_in_2D = add( q_direction->not_in_2D, q_direction->band_data[i].elevation_index[j] ); move16(); @@ -216,11 +217,15 @@ void quantize_direction_frame_fx( { q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3]; q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][q_direction->band_data[i].elevation_index[j]]; + move16(); + move16(); } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[0] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[0] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[0] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; + move16(); + move16(); } } ELSE @@ -234,7 +239,7 @@ void quantize_direction_frame_fx( } ELSE { - q_direction->band_data[i].elevation_m_alphabet[j] = no_theta_masa[bits_direction_masa[idx] - 3] * 2 - 1; + q_direction->band_data[i].elevation_m_alphabet[j] = sub( imult1616( no_theta_masa[bits_direction_masa[idx] - 3], 2 ), 1 ); q_direction->band_data[i].azimuth_m_alphabet[j] = no_phi_masa[bits_direction_masa[idx] - 1][( q_direction->band_data[i].elevation_index[j] + 1 ) >> 1]; move16(); move16(); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 4ba0f3444..ac29e728e 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -347,7 +347,62 @@ ivas_error IVAS_ENC_ConfigureForStereo( * * Configure and initialize the combined MASA and ISM encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMASAObjects( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ + 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 UWord16 numObjects, /* i : number of objects to be encoded */ + const Word16 masaVariant /* i : index specifying the number of MASA transport channels */ +) +{ + Encoder_Struct *st_ivas; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF( GT_16( numObjects, MAX_NUM_OBJECTS ) ) + { + return IVAS_ERR_TOO_MANY_INPUTS; + } + st_ivas = hIvasEnc->st_ivas; + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_2CH: + st_ivas->hEncoderConfig->nchan_inp = add( CPE_CHANNELS, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_1CH: + st_ivas->hEncoderConfig->nchan_inp = add( 1, numObjects ); + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + st_ivas = hIvasEnc->st_ivas; + + /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT; + st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); + move16(); + move16(); + + return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); +} +#else ivas_error IVAS_ENC_ConfigureForMASAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -395,6 +450,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } +#endif /*---------------------------------------------------------------------* @@ -646,7 +702,56 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( * * Configure and initialize the MASA encoder. *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_ConfigureForMasa( + 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_MASA_VARIANT masaVariant /* i : type of MASA input (either 1 or 2 channels) */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + hEncoderConfig->ivas_format = MASA_FORMAT; + move32(); + + SWITCH( masaVariant ) + { + case IVAS_ENC_MASA_1CH: + hEncoderConfig->nchan_inp = 1; + hEncoderConfig->element_mode_init = IVAS_SCE; + move16(); + move16(); + BREAK; + case IVAS_ENC_MASA_2CH: + hEncoderConfig->nchan_inp = 2; + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + move16(); + move16(); + BREAK; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + BREAK; + } + + hIvasEnc->maxBandwidthUser = max_bwidth_user; + + error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); + + return error; +} +#else ivas_error IVAS_ENC_ConfigureForMasa( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ const int32_t inputFs, /* i : input sampling frequency */ @@ -690,6 +795,7 @@ ivas_error IVAS_ENC_ConfigureForMasa( return error; } +#endif /*---------------------------------------------------------------------* @@ -703,12 +809,13 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ) { - if ( !hIvasEnc->isConfigured ) + IF( !hIvasEnc->isConfigured ) { return IVAS_ERR_NOT_CONFIGURED; } - if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) + test(); + IF( NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) && NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { return IVAS_ERR_METADATA_NOT_EXPECTED; } @@ -2379,6 +2486,7 @@ static ivas_error setChannelAwareConfig_fx( static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ) { + test(); IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 2d0b9e08d..2871969ca 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2670,7 +2670,22 @@ static void efap_panning_fx( get_poly_gains_fx( P[0], P[1], aziPoly, elePoly, numChan, tmpBuff ); // tmpBuff q31 /* Computing the norm of the tmp buffer */ - normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); // q31 + Word64 suma; + suma = Mpy_32_32( tmpBuff[0], tmpBuff[0] ); + FOR( i = 1; i < numChan; i++ ) + { + suma = W_add( suma, Mpy_32_32( tmpBuff[i], tmpBuff[i] ) ); + } + IF( GT_64( suma, MAX_32 ) ) + { + normTmpBuff = MAX_32; + move32(); + } + ELSE + { + normTmpBuff = W_extract_l( suma ); // Q31 + } + Word16 exp = 0; move16(); normTmpBuff = ISqrt32( normTmpBuff, &exp ); // Q=31-exp -- GitLab From f3958a078260f161026ae0bd2e946d6656378f8a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 21:18:15 +0530 Subject: [PATCH 29/39] Fix for 3gpp issue 962: Decoder crash for OSBA_ISM1_HOA3 at 80kbps FER in ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx() --- lib_rend/ivas_dirac_dec_binaural_functions.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 166c9135a..e0d8fa302 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -2808,9 +2808,12 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric test(); IF( ( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, SBA_ISM_FORMAT ) ) && LT_16( bin, BINAURAL_COHERENCE_DIFFERENCE_BINS ) ) { - Word32 diffuseFieldCoherence_fx; - diffuseFieldCoherence_fx = L_add( L_add( Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioX_fx[bin], hDiracDecBin->diffuseFieldCoherenceX_fx[bin] ), Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioY_fx[bin], hDiracDecBin->diffuseFieldCoherenceY_fx[bin] ) ), Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioZ_fx[bin], hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] ) ); - hDiracDecBin->ChCrossReOut_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossReOut_fx[bin], hDiracDecBin->ChCrossReOut_e[bin], Mpy_32_32( L_add( Mpy_32_16_1( diffuseFieldCoherence_fx, sub( 32767, surCoh_fx ) ), L_shl( surCoh_fx, 16 ) ), diffEne_fx ), sub( 31, q_diffEne ), &hDiracDecBin->ChCrossReOut_e[bin] ); + Word32 diffuseFieldCoherence_fx, temp; + Word16 tmp_exp; + temp = BASOP_Util_Add_Mant32Exp( Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioX_fx[bin], hDiracDecBin->diffuseFieldCoherenceX_fx[bin] ), 0, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioY_fx[bin], hDiracDecBin->diffuseFieldCoherenceY_fx[bin] ), 0, &tmp_exp ); + diffuseFieldCoherence_fx = BASOP_Util_Add_Mant32Exp( temp, tmp_exp, Mpy_32_32( hDiracDecBin->hDiffuseDist->diffuseRatioZ_fx[bin], hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] ), 0, &tmp_exp ); + temp = BASOP_Util_Add_Mant32Exp( Mpy_32_16_1( diffuseFieldCoherence_fx, sub( 32767, surCoh_fx ) ), tmp_exp, L_shl( surCoh_fx, 16 ), 0, &tmp_exp ); + hDiracDecBin->ChCrossReOut_fx[bin] = BASOP_Util_Add_Mant32Exp( hDiracDecBin->ChCrossReOut_fx[bin], hDiracDecBin->ChCrossReOut_e[bin], Mpy_32_32( temp, diffEne_fx ), add( tmp_exp, sub( 31, q_diffEne ) ), &hDiracDecBin->ChCrossReOut_e[bin] ); } ELSE { -- GitLab From d6078d98eb7a9aad302cc18d97daa39fce06fcc1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 28 Oct 2024 21:24:45 +0530 Subject: [PATCH 30/39] Fix for 3GPP issue 966: Decoder crash for OMASA ISM3_1TC with bitrate switching and FER in perform_noise_estimation_dec_ivas_fx() --- lib_dec/fd_cng_dec_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b6ba82895..51c2c4643 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2800,9 +2800,10 @@ void perform_noise_estimation_dec_ivas_fx( } ELSE { - Copy32( msPeriodog, msNoiseEst, npart ); - scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); - hFdCngDec->msNoiseEst_exp = hFdCngDec->msPeriodog_exp; + Word16 tmp = s_max( sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); + Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); + scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); + hFdCngDec->msNoiseEst_exp = tmp; move16(); } -- GitLab From f7d3da918b4dc6ed4f5edb44b7fc544d55208fb2 Mon Sep 17 00:00:00 2001 From: Adriana Vasilache Date: Mon, 28 Oct 2024 20:04:32 +0200 Subject: [PATCH 31/39] fix 982 --- lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 6 ++++++ lib_dec/ivas_qmetadata_dec.c | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index f1023d3b6..3ff81cd74 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -194,7 +194,7 @@ #define NONBE_FIX_943_PORT_1208_DFT_STEREO_PLC_BURST /* Ericsson: BASOP Issue 943, Float Issue 1208, fix for overflow of sample offset counter for burst error in DFT Stereo PLC. */ #define FIX_853_DECODE_MASA_ISM_AZIMUTH_PREC /* Nokia: Fixes ivas_decode_masaism_metadata decision logic change due to precision difference; needs corresponding fix in floating point */ #define FIX_953_WRONG_ENERGY_RATIO_MASA_EXT /* Nok: Fix 953 wrong energy ratio value after shift and cast to Word8 */ - +#define FIX_982_WRONG_DECODED_ENERGY_RATIO /* Nokia: Fix 982 wrong energy in EXT mode and in second direction when present */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f3962ced2..da6d2360e 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4377,6 +4377,12 @@ static void create_masa_ext_out_meta_fx( { FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { +#ifdef FIX_982_WRONG_DECODED_ENERGY_RATIO + IF( EQ_32( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], ONE_IN_Q30 ) ) + { + hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--; + } +#endif UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); // Q8 move16(); extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; // Q8 diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index f213a059d..2e17020cd 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -1725,6 +1725,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { #ifdef MSAN_FIX +#ifdef FIX_982_WRONG_DECODED_ENERGY_RATIO + FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) + { + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); /*Q30*/ + move32(); + } + } +#else FOR( b = 0; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) @@ -1733,6 +1743,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move32(); } } +#endif #else FOR( b = 0; b < MASA_MAXIMUM_CODING_SUBBANDS; b++ ) { -- GitLab From 077a57433a28f1fa30f7cf9eff304b1d4c800080 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 08:50:46 +0530 Subject: [PATCH 32/39] Q info updates for dec and rend files --- lib_com/gs_bitallocation_ivas_fx.c | 1 + lib_com/ivas_cov_smooth.c | 1 + lib_com/ivas_filters.c | 30 +- lib_com/ivas_ism_com.c | 109 +- lib_com/ivas_lfe_com.c | 18 +- lib_com/ivas_masa_com.c | 115 +- lib_com/ivas_mc_param_com.c | 29 +- lib_com/ivas_mct_com.c | 10 +- lib_com/ivas_mdft_imdft.c | 123 +- lib_com/ivas_omasa_com.c | 100 +- lib_com/ivas_pca_tools.c | 137 +- lib_com/ivas_prot.h | 2620 ++------------------ lib_com/ivas_prot_fx.h | 2352 +++++++++++++++++- lib_com/ivas_qmetadata_com.c | 46 +- lib_com/ivas_qspherical_com.c | 58 +- lib_com/ivas_rom_com.c | 233 +- lib_com/ivas_rom_com.h | 270 +- lib_com/ivas_rom_com_fx.c | 33 +- lib_com/ivas_rom_com_fx.h | 6 +- lib_com/ivas_spar_com_quant_util.c | 1 + lib_com/ivas_stereo_ica_com_fx.c | 1 + lib_com/prot_fx.h | 12 +- lib_dec/ACcontextMapping_dec_fx.c | 1 + lib_dec/acelp_core_dec_ivas_fx.c | 1 + lib_dec/ivas_binRenderer_internal.c | 1 + lib_dec/ivas_pca_dec_fx.c | 1 + lib_dec/ivas_qspherical_dec.c | 1 + lib_dec/ivas_range_uni_dec.c | 1 + lib_dec/ivas_sns_dec_fx.c | 1 + lib_dec/ivas_spar_md_dec.c | 2 +- lib_dec/ivas_svd_dec.c | 2 +- lib_dec/ivas_td_low_rate_dec.c | 1 + lib_dec/lsf_dec_fx.c | 1 + lib_enc/cod_tcx.c | 1 + lib_enc/find_uv.c | 1 + lib_enc/ivas_enc_cov_handler.c | 1 + lib_enc/ivas_front_vad.c | 1 + lib_enc/ivas_stereo_adapt_GR_enc.c | 2 +- lib_enc/ivas_stereo_switching_enc.c | 1 + lib_enc/swb_tbe_enc_fx.c | 1 + lib_rend/ivas_crend.c | 1 + lib_rend/ivas_dirac_decorr_dec.c | 1 + lib_rend/ivas_dirac_output_synthesis_dec.c | 1 + lib_rend/ivas_hrtf.c | 1 + lib_rend/ivas_sba_rendering.c | 1 + lib_rend/ivas_vbap.c | 1 + lib_util/hrtf_file_reader.c | 1 + 47 files changed, 3192 insertions(+), 3141 deletions(-) diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index e13d04495..f8a45b4f8 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -10,6 +10,7 @@ #include "ivas_prot.h" /* Function prototypes */ #include "assert.h" /* Debug prototypes */ #include "stl.h" +#include "ivas_prot_fx.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 ); diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 143ac2290..d03d548b6 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -37,6 +37,7 @@ #include "wmc_auto.h" #include "prot.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------------------------* * Local constants diff --git a/lib_com/ivas_filters.c b/lib_com/ivas_filters.c index bc0a2fce2..425149fe0 100644 --- a/lib_com/ivas_filters.c +++ b/lib_com/ivas_filters.c @@ -38,6 +38,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com.h" +#include "ivas_prot_fx.h" #endif /*------------------------------------------------------------------------------------------* @@ -46,7 +47,12 @@ #ifndef IVAS_FLOAT_FIXED static void ivas_iir_2_filter( ivas_filters_process_state_t *filter_state, float *pIn_Out, const int16_t length, const int16_t stage ); #else -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 *pIn_Out_e ); +static void ivas_iir_2_filter_fx( + ivas_filters_process_state_t *filter_state, + Word32 *pIn_Out_fx, // Q(31-*pIn_Out_e) + const Word16 length, + const Word16 stage, + Word16 *pIn_Out_e ); #endif /*-----------------------------------------------------------------------------------------* * Function ivas_filters_init() @@ -102,7 +108,7 @@ void ivas_filters_init( #else 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 Word32 *filt_coeff_fx, /* i : filter coefficients Q31- *filt_coeff_e */ const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ const Word16 order ) /* i : filter order */ { @@ -233,7 +239,7 @@ void ivas_filter_process( #else 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 Q(q_factor) */ const Word16 length, /* i : filter order */ Word16 q_factor ) { @@ -248,7 +254,7 @@ void ivas_filter_process_fx( /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) move32(); } BREAK; @@ -261,7 +267,7 @@ void ivas_filter_process_fx( /* Scale pIn_Out_fx back to input Q */ FOR( i = 0; i < length; i++ ) { - pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); + pIn_Out_fx[i] = L_shr_r_sat( pIn_Out_fx[i], sub( sub( 31, q_factor ), pIn_Out_e[i] ) ); // Q(31-pIn_Out_e[i]) -> Q(q_factor) move32(); } BREAK; @@ -308,7 +314,7 @@ static void ivas_iir_2_filter( #else static void ivas_iir_2_filter_fx( ivas_filters_process_state_t *filter_state, - Word32 *pIn_Out_fx, + Word32 *pIn_Out_fx, // Q(31-*pIn_Out_e) const Word16 length, const Word16 stage, Word16 *pIn_Out_e ) @@ -330,23 +336,23 @@ static void ivas_iir_2_filter_fx( tmp_pIn_buf_i_e = pIn_Out_e[i]; move16(); - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][0], pIn_fx[i] ); // Q31 -(pIn_Out_e[i]+ filter_state->num_e[stage][0]) L_prod_e = add( pIn_Out_e[i], filter_state->num_e[stage][0] ); - pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); + pOut_fx[i] = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][0], filter_state->state_e[stage][0], L_tmp_prod, L_prod_e, &pIn_Out_e[i] ); // Q31 - pIn_Out_e[i] move32(); FOR( j = 1; j < filter_state->filt_len; j++ ) { - L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); + L_tmp_prod = Mpy_32_32( filter_state->num_fx[stage][j], tmp_pIn_buf_i_fx ); // Q31-L_prod_e L_prod_e = add( filter_state->num_e[stage][j], tmp_pIn_buf_i_e ); - L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( filter_state->state_fx[stage][j], filter_state->state_e[stage][j], L_tmp_prod, L_prod_e, &L_tmp_e ); // Q31 - L_tmp_e - L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); + L_tmp_prod = Mpy_32_32( filter_state->den_fx[stage][j], pOut_fx[i] ); // Q31 - ( pIn_Out_e[i]+filter_state->den_e[stage][j] ) L_prod_e = add( pIn_Out_e[i], filter_state->den_e[stage][j] ); - filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); + filter_state->state_fx[stage][j - 1] = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, L_negate( L_tmp_prod ), L_prod_e, &filter_state->state_e[stage][j - 1] ); // Q31 - filter_state->state_e[stage][j - 1] move32(); } } diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 583051b23..d871ebe6d 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -52,10 +52,10 @@ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) #define BETA_ISM_LOW_IMP 0.6f -#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) +#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) // 0.6 in Q31 #define BETA_ISM_MEDIUM_IMP 0.8f -#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) -#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) +#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) // 0.8 in Q31 +#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) // 0.8 in Q29 #define MAX_BRATE_TCX_32k 48000 #define BITS_IVAS_512k ( IVAS_512k / FRAMES_PER_SEC ) @@ -74,8 +74,8 @@ #ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( - const Word16 x[], /* i : bitbudgets */ - Word32 y[], /* o : bitrates */ + const Word16 x[], /* i : bitbudgets Q0 */ + Word32 y[], /* o : bitrates Q0 */ const Word16 N /* i : number of entries to be converted */ ) { @@ -83,7 +83,7 @@ void bitbudget_to_brate( FOR( i = 0; i < N; i++ ) { - y[i] = FRAMES_PER_SEC * x[i]; + y[i] = L_mult0( FRAMES_PER_SEC, x[i] ); move32(); } @@ -466,10 +466,10 @@ ivas_error ivas_ism_config_fx( { /* 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 ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); + bits_ism = (Word16) Mpy_32_32( 42949673, ism_total_brate ); // 42949673 is 1/FRAMES_PER_SEC in Q31 + tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); - bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); /* ISM common signaling bits are counted in MASA MD bit-budget */ @@ -480,17 +480,17 @@ ivas_error ivas_ism_config_fx( // 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 ); // 42949673 is 1/FRAMES_PER_SEC in Q31 + tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); - bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); + bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); bitbudget_to_brate( bits_element, element_brate, n_ISms ); /* count ISm common signaling bits */ IF( hIsmMeta != NULL ) { - nb_bits_metadata[0] = add( nb_bits_metadata[0], add( n_ISms * ISM_METADATA_FLAG_BITS, nchan_ism ) ); + nb_bits_metadata[0] = add( nb_bits_metadata[0], add( imult1616( n_ISms, ISM_METADATA_FLAG_BITS ), nchan_ism ) ); move16(); IF( GE_32( ism_total_brate, ISM_EXTENDED_METADATA_BRATE ) ) @@ -534,9 +534,9 @@ ivas_error ivas_ism_config_fx( IF( nb_bits_metadata != NULL ) { bits_side = sum_s( nb_bits_metadata, n_ISms ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); - set16_fx( 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 ); + tmp1 = BASOP_Util_Divide1616_Scale( bits_side, n_ISms, &exp ); // Q15 - exp + set16_fx( nb_bits_metadata, shr( tmp1, sub( 15, exp ) ), n_ISms ); + nb_bits_metadata[n_ISms - 1] = add( nb_bits_metadata[n_ISms - 1], bits_side % n_ISms ); // Q0 move16(); v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms ); bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); @@ -629,7 +629,7 @@ ivas_error ivas_ism_config_fx( ELSE IF( EQ_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) { // tmp = (Word16) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] ); - tmp = extract_l( Mpy_32_32( BETA_ISM_MEDIUM_IMP_BY_8_Q31, L_shl( bits_CoreCoder[ch], Q3 ) ) ); + tmp = extract_l( Mpy_32_32( BETA_ISM_MEDIUM_IMP_BY_8_Q31, L_shl( bits_CoreCoder[ch], Q3 ) ) ); // Q0 tmp = s_max( limit, tmp ); } ELSE /* ism_imp[ch] == ISM_HIGH_IMP */ @@ -638,7 +638,7 @@ ivas_error ivas_ism_config_fx( move16(); } - diff = add( diff, sub( bits_CoreCoder[ch], tmp ) ); + diff = add( diff, sub( bits_CoreCoder[ch], tmp ) ); // Q0 bits_CoreCoder[ch] = tmp; move16(); } @@ -646,8 +646,8 @@ ivas_error ivas_ism_config_fx( test(); IF( diff > 0 && n_higher > 0 ) { - tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); - tmp = shr( tmp, sub( 15, exp ) ); + tmp = BASOP_Util_Divide1616_Scale( diff, n_higher, &exp ); // Q15-exp + tmp = shr( tmp, sub( 15, exp ) ); // Q0 FOR( ch = 0; ch < n_ISms; ch++ ) { IF( flag_higher[ch] ) @@ -696,7 +696,7 @@ ivas_error ivas_ism_config_fx( diff = 0; move16(); limit_high = BITS_MAX_BRATE_TCX_32k; - + move16(); FOR( ch = 0; ch < n_ISms; ch++ ) { tmp = (Word16) s_min( bits_CoreCoder[ch], limit_high ); @@ -788,7 +788,7 @@ void ivas_ism_reset_metadata( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; + hIsmMeta->radius_fx = ONE_IN_Q9; // Q9 move16(); hIsmMeta->ism_metadata_flag = 0; @@ -811,7 +811,7 @@ void ivas_ism_reset_metadata_enc( move32(); hIsmMeta->pitch_fx = 0; move32(); - hIsmMeta->radius_fx = 1 << 9; // Q9 + hIsmMeta->radius_fx = ONE_IN_Q9; // Q9 move16(); hIsmMeta->ism_metadata_flag = 0; move16(); @@ -897,8 +897,8 @@ Word16 ism_quant_meta_fx( { qlow_fx = borders_fx[1]; move32(); - tmp = BASOP_Util_Divide3232_Scale( L_sub( borders_fx[1], borders_fx[0] ), q_step_border_fx, &tmp_e ); - idx_start = shr( tmp, sub( 15, tmp_e ) ); + tmp = BASOP_Util_Divide3232_Scale( L_sub( borders_fx[1], borders_fx[0] ), q_step_border_fx, &tmp_e ); // Q15-tmp_e + idx_start = shr( tmp, sub( 15, tmp_e ) ); // Q0 step_fx = q_step_fx; move32(); } @@ -906,21 +906,21 @@ Word16 ism_quant_meta_fx( { qlow_fx = borders_fx[2]; move32(); - tmp = BASOP_Util_Divide3232_Scale( L_add( L_sub( borders_fx[3], borders_fx[2] ), L_sub( q_step_border_fx, ONE_IN_Q22 ) ), q_step_border_fx, &tmp_e ); - idx_start = sub( cbsize, add( 1, shr( tmp, sub( 15, tmp_e ) ) ) ); + tmp = BASOP_Util_Divide3232_Scale( L_add( L_sub( borders_fx[3], borders_fx[2] ), L_sub( q_step_border_fx, ONE_IN_Q22 ) ), q_step_border_fx, &tmp_e ); // Q15-tmp_e + idx_start = sub( cbsize, add( 1, shr( tmp, sub( 15, tmp_e ) ) ) ); // Q0 step_fx = q_step_border_fx; move32(); } - tmp = BASOP_Util_Divide3232_Scale( L_sub( val, qlow_fx ), step_fx, &tmp_e ); - tmp = shl( tmp, sub( Q1, sub( 15, tmp_e ) ) ); + tmp = BASOP_Util_Divide3232_Scale( L_sub( val, qlow_fx ), step_fx, &tmp_e ); // Q15-tmp_e + tmp = shl( tmp, sub( Q1, sub( 15, tmp_e ) ) ); // Q0 tmp = add( tmp, 1 ); tmp = shr( tmp, 1 ); - idx = add( idx_start, s_max( 0, s_min( sub( cbsize, 1 ), tmp ) ) ); + idx = add( idx_start, s_max( 0, s_min( sub( cbsize, 1 ), tmp ) ) ); // Q0 // idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow_fx ) / step_fx + 0.5f ) ) ); - *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); + *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); // Q0 move32(); return idx; @@ -973,29 +973,29 @@ int16_t ism_quant_meta( /*! r: dequantized value */ #ifdef IVAS_FLOAT_FIXED -Word32 ism_dequant_meta_fx( - 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 */ +Word32 ism_dequant_meta_fx( /* o : Q22*/ + const Word16 idx, /* i : quantizer index */ + const Word32 borders_fx[], /* i : level borders Q22*/ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22*/ + const Word16 cbsize /* i : codebook size */ ) { Word16 idx_start, tmp1, tmp2, exp1, exp2; Word32 qlow_fx, step_fx, valQ_fx; tmp1 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[1], borders_fx[0] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp1 ); - tmp1 = shr( tmp1, sub( 15, exp1 ) ); + tmp1 = shr( tmp1, sub( 15, exp1 ) ); // Q0 tmp2 = BASOP_Util_Divide3232_Scale( L_shr( L_sub( borders_fx[3], borders_fx[2] ), 21 ), L_shr( q_step_border_fx, 21 ), &exp2 ); - tmp2 = shr( tmp2, sub( 15, exp2 ) ); + tmp2 = shr( tmp2, sub( 15, exp2 ) ); // Q0 IF( LE_16( idx, tmp1 ) ) { - qlow_fx = borders_fx[0]; + qlow_fx = borders_fx[0]; // Q22 idx_start = 0; - step_fx = q_step_border_fx; + step_fx = q_step_border_fx; // Q22 move32(); move32(); @@ -1003,9 +1003,9 @@ Word32 ism_dequant_meta_fx( } ELSE IF( LE_16( idx, sub( sub( cbsize, 1 ), tmp2 ) ) ) { - qlow_fx = borders_fx[1]; + qlow_fx = borders_fx[1]; // Q22 idx_start = tmp1; - step_fx = q_step_fx; + step_fx = q_step_fx; // Q22 move32(); move32(); @@ -1015,14 +1015,14 @@ Word32 ism_dequant_meta_fx( { qlow_fx = borders_fx[2]; idx_start = (Word16) sub( sub( cbsize, 1 ), tmp2 ); - step_fx = q_step_border_fx; + step_fx = q_step_border_fx; // Q22 move32(); move32(); move16(); } - valQ_fx = L_add( sub( idx, idx_start ) * step_fx, qlow_fx ); + valQ_fx = L_add( sub( idx, idx_start ) * step_fx, qlow_fx ); // Q22 return valQ_fx; } @@ -1129,7 +1129,8 @@ void ivas_param_ism_config_fx( move16(); } - hParamIsm->last_dmx_gain_fx = (Word16) 16384; + hParamIsm->last_dmx_gain_fx = (Word16) 16384; // Q15-last_dmx_gain_e + move16(); hParamIsm->last_dmx_gain_e = 1; move16(); set16_fx( hParamIsm->last_cardioid_left_fx, (Word16) 16384, MAX_NUM_OBJECTS ); @@ -1293,9 +1294,9 @@ void update_last_metadata_fx( { IF( EQ_16( updt_flag[ch], 1 ) ) { - hIsmMeta[ch]->last_azimuth_fx = hIsmMeta[ch]->azimuth_fx; + hIsmMeta[ch]->last_azimuth_fx = hIsmMeta[ch]->azimuth_fx; // Q22 move32(); - hIsmMeta[ch]->last_elevation_fx = hIsmMeta[ch]->elevation_fx; + hIsmMeta[ch]->last_elevation_fx = hIsmMeta[ch]->elevation_fx; // Q22 move32(); } } @@ -1315,16 +1316,16 @@ 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 */ + Word32 *q_step_fx, /* o : quantization step Q22*/ + Word32 *q_step_border_fx, /* o : quantization step at the border Q22*/ 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; *nBits_elevation = ISM_DTX_ELE_BITS_HIGH; - *q_step_fx = ISM_Q_STEP_HIGH_FX; - *q_step_border_fx = ISM_Q_STEP_BORDER_HIGH_FX; + *q_step_fx = ISM_Q_STEP_HIGH_FX; // Q22 + *q_step_border_fx = ISM_Q_STEP_BORDER_HIGH_FX; // Q22 *nBits_coh = ISM_DTX_COH_SCA_BITS; *nBits_sce_id = 1; @@ -1339,8 +1340,8 @@ void ivas_get_ism_sid_quan_bitbudget_fx( { *nBits_azimuth = ISM_DTX_AZI_BITS_LOW; *nBits_elevation = ISM_DTX_ELE_BITS_LOW; - *q_step_fx = ISM_Q_STEP_LOW_FX; - *q_step_border_fx = ISM_Q_STEP_BORDER_LOW_FX; + *q_step_fx = ISM_Q_STEP_LOW_FX; // Q22 + *q_step_border_fx = ISM_Q_STEP_BORDER_LOW_FX; // Q22 *nBits_sce_id = 2; move16(); diff --git a/lib_com/ivas_lfe_com.c b/lib_com/ivas_lfe_com.c index 95797ef84..7f68dda86 100644 --- a/lib_com/ivas_lfe_com.c +++ b/lib_com/ivas_lfe_com.c @@ -116,13 +116,13 @@ void ivas_lfe_lpf_select_filt_coeff_fx( SWITCH( sampling_rate ) { case 16000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_16k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_16k_fx; // Q30 BREAK; case 32000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_32k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_32k_fx; // Q30 BREAK; case 48000: - *ppFilt_coeff_fx = ivas_lpf_2_butter_48k_fx; + *ppFilt_coeff_fx = ivas_lpf_2_butter_48k_fx; // Q30 BREAK; default: BREAK; @@ -132,15 +132,15 @@ void ivas_lfe_lpf_select_filt_coeff_fx( SWITCH( sampling_rate ) { case 16000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_16k_sos_fx; // Q31-ivas_lpf_4_butter_16k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_16k_sos_e; BREAK; case 32000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_32k_sos_fx; // Q31-ivas_lpf_4_butter_32k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_32k_sos_e; BREAK; case 48000: - *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; + *ppFilt_coeff_fx = ivas_lpf_4_butter_48k_sos_fx; // Q31-ivas_lpf_4_butter_48k_sos_e *ppFilt_coeff_e = ivas_lpf_4_butter_48k_sos_e; BREAK; default: @@ -172,15 +172,15 @@ void ivas_lfe_window_init_fx( /* Set window coefficients */ IF( EQ_32( sampling_rate, 48000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_48k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_48k_fx; // Q31 } ELSE IF( EQ_32( sampling_rate, 32000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_32k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_32k_fx; // Q31 } ELSE IF( EQ_32( sampling_rate, 16000 ) ) { - hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_16k_fx; + hLFEWindow->pWindow_coeffs_fx = ivas_lfe_window_coeff_16k_fx; // Q31 } ELSE { diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 5d91190bb..fc19d2dc1 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -63,9 +63,18 @@ static int16_t quantize_theta_masa( float x, const int16_t no_cb, float *xhat ); static int16_t quantize_phi_masa( float phi, const int16_t flag_delta, float *phi_hat, const int16_t n ); #else -static Word16 quantize_theta_masa_fx( const Word32 x_fx, const Word16 no_cb, Word32 *xhat_fx ); +static Word16 quantize_theta_masa_fx( + const Word32 x_fx, /* i : theta value to be quantized Q22*/ + const Word16 no_cb, /* i : number of codewords */ + Word32 *xhat_fx /* o : quantized value Q22*/ +); -static Word16 quantize_phi_masa_fx( const Word32 phi, const Word16 flag_delta, Word32 *phi_hat, const Word16 n ); +static Word16 quantize_phi_masa_fx( + const Word32 phi_fx, /* i : azimuth value Q22 */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat_fx, /* o : quantized azimuth Q22 */ + const Word16 n /* i : azimuth codebook size */ +); static Word32 estim_round[MASA_NO_CIRCLES + 1] = { /* Q0 */ @@ -452,7 +461,7 @@ void ivas_masa_set_elements_fx( *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(); @@ -464,7 +473,7 @@ void ivas_masa_set_elements_fx( 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(); @@ -478,7 +487,7 @@ 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(); @@ -489,7 +498,7 @@ void ivas_masa_set_elements_fx( test(); test(); test(); - 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 ) ) ) + 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 ) ) ) { /* hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); */ tmp = extract_l( Mpy_32_32( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); @@ -818,7 +827,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( GT_32( ivas_total_brate, IVAS_96k ) && !config->joinedSubframes ) || ( GT_32( ivas_total_brate, IVAS_80k ) && config->joinedSubframes ) ) + if ( ( GT_32( ivas_total_brate, IVAS_96k ) && !config->joinedSubframes ) || ( GT_32( ivas_total_brate, IVAS_80k ) && config->joinedSubframes ) ) { idx_bands = sub( idx_bands, 1 ); } @@ -839,7 +848,7 @@ void ivas_masa_set_coding_config_fx( move16(); test(); - IF( EQ_32( ivas_total_brate, IVAS_64k ) && GT_16( config->numberOfDirections, 1 ) ) + if ( EQ_32( ivas_total_brate, IVAS_64k ) && GT_16( config->numberOfDirections, 1 ) ) { /* At 64k, we increase metadata bit budget when there is two directions present. */ config->max_metadata_bits = (UWord16) add( config->max_metadata_bits, MASA_EXTRA_BAND_META_BITS ); @@ -849,7 +858,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( ( EQ_32( ivas_total_brate, IVAS_32k ) && EQ_16( nchan_transport, 2 ) ) || EQ_32( ivas_total_brate, IVAS_48k ) ) && config->joinedSubframes ) + if ( ( ( EQ_32( ivas_total_brate, IVAS_32k ) && EQ_16( nchan_transport, 2 ) ) || EQ_32( ivas_total_brate, IVAS_48k ) ) && config->joinedSubframes ) { /* At 32k and 48k, we increase metadata bit budget when joinedSubframes. */ config->max_metadata_bits = (UWord16) add( config->max_metadata_bits, MASA_SMALL_INC_META_BITS ); @@ -906,7 +915,7 @@ void ivas_masa_set_coding_config_fx( test(); test(); test(); - IF( ( !isMcMasa && LT_32( ivas_total_brate, IVAS_48k ) ) || ( isMcMasa && LT_32( ivas_total_brate, IVAS_16k4 ) ) ) + if ( ( !isMcMasa && LT_32( ivas_total_brate, IVAS_48k ) ) || ( isMcMasa && LT_32( ivas_total_brate, IVAS_16k4 ) ) ) { config->useCoherence = FALSE; move16(); @@ -1262,8 +1271,8 @@ uint16_t index_theta_phi_16( } #else UWord16 index_theta_phi_16_fx( - Word32 *p_theta, /* i/o: input elevation to be indexed */ - Word32 *p_phi, /* i/o: input azimuth to be indexed */ + Word32 *p_theta, /* i/o: input elevation to be indexed Q22 */ + Word32 *p_phi, /* i/o: input azimuth to be indexed Q22 */ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ) { @@ -1274,25 +1283,25 @@ UWord16 index_theta_phi_16_fx( Word32 theta_hat_fx, phi_hat_fx; Word32 theta_fx, phi_fx; - theta_fx = *p_theta; + theta_fx = *p_theta; // Q22 move32(); - phi_fx = *p_phi; + phi_fx = *p_phi; // Q22 move32(); phi_hat_fx = 0; move32(); theta_hat_fx = 0; move32(); - phi_fx = L_add( phi_fx, L_shl( 180, Q22 ) ); + phi_fx = L_add( phi_fx, L_shl( 180, Q22 ) ); // Q22 IF( theta_fx < 0 ) { - abs_theta_fx = L_negate( theta_fx ); + abs_theta_fx = L_negate( theta_fx ); // Q22 sign_th = -1; move16(); } ELSE { - abs_theta_fx = theta_fx; + abs_theta_fx = theta_fx; // Q22 move32(); sign_th = 1; move16(); @@ -1309,7 +1318,7 @@ UWord16 index_theta_phi_16_fx( { id_phi = 0; move16(); - phi_hat_fx = L_shl( 180, Q22 ); + phi_hat_fx = L_shl( 180, Q22 ); // Q22 } } ELSE @@ -1319,12 +1328,12 @@ UWord16 index_theta_phi_16_fx( *p_theta = theta_hat_fx; move32(); - IF( EQ_16( sign_th, -1 ) ) + if ( EQ_16( sign_th, -1 ) ) { - *p_theta = L_negate( theta_hat_fx ); + *p_theta = L_negate( theta_hat_fx ); // Q22 move32(); } - *p_phi = L_sub( phi_hat_fx, L_shl( 180, Q22 ) ); + *p_phi = L_sub( phi_hat_fx, L_shl( 180, Q22 ) ); // Q22 move32(); /* Starting from Equator, alternating positive and negative */ @@ -1337,34 +1346,34 @@ UWord16 index_theta_phi_16_fx( { IF( EQ_16( id_th, sub( gridData->no_theta, 1 ) ) ) { - idx_sph = 65534; + idx_sph = 65534; // Q0 move16(); if ( sign_th < 0 ) { - idx_sph = 65535; + idx_sph = 65535; // Q0 move16(); } } ELSE { - cum_n = cum_n_for_id_th[id_th]; + cum_n = cum_n_for_id_th[id_th]; // Q0 move16(); - cum_n = (UWord16) L_add( cum_n, gridData->no_phi[0] ); + cum_n = (UWord16) L_add( cum_n, gridData->no_phi[0] ); // Q0 IF( sign_th > 0 ) { - cum_n = (UWord16) L_sub( cum_n, shl( gridData->no_phi[id_th], 1 ) ); + cum_n = (UWord16) L_sub( cum_n, shl( gridData->no_phi[id_th], 1 ) ); // Q0 } ELSE { - cum_n = (UWord16) L_sub( cum_n, gridData->no_phi[id_th] ); + cum_n = (UWord16) L_sub( cum_n, gridData->no_phi[id_th] ); // Q0 } - idx_sph = (UWord16) L_add( cum_n, id_phi ); + idx_sph = (UWord16) L_add( cum_n, id_phi ); // Q0 } } - return idx_sph; + return idx_sph; // Q0 } #endif @@ -1412,9 +1421,9 @@ static int16_t quantize_theta_masa( } #else static Word16 quantize_theta_masa_fx( - const Word32 x_fx, /* i : theta value to be quantized */ + const Word32 x_fx, /* i : theta value to be quantized Q22*/ const Word16 no_cb, /* i : number of codewords */ - Word32 *xhat_fx /* o : quantized value */ + Word32 *xhat_fx /* o : quantized value Q22*/ ) { Word16 imin; @@ -1425,7 +1434,7 @@ static Word16 quantize_theta_masa_fx( IF( GE_16( imin, sub( no_cb, 1 ) ) ) { imin = sub( no_cb, 1 ); - diff1_fx = L_sub( x_fx, L_shl( 90, Q22 ) ); + diff1_fx = L_sub( x_fx, L_shl( 90, Q22 ) ); // Q22 diff2_fx = L_sub( x_fx, Mpy_32_16_1( MASA_ANGLE_AT_EQUATOR_DEG_Q31, shl( sub( imin, 1 ), 6 ) ) ); // q31 + q0+6 - 15 = q22 IF( GT_32( L_abs( diff1_fx ), L_abs( diff2_fx ) ) ) { @@ -1435,7 +1444,7 @@ static Word16 quantize_theta_masa_fx( } ELSE { - *xhat_fx = L_shl( 90, Q22 ); + *xhat_fx = L_shl( 90, Q22 ); // Q22 move32(); } } @@ -1505,9 +1514,9 @@ static int16_t quantize_phi_masa( } #else static Word16 quantize_phi_masa_fx( - const Word32 phi_fx, /* i : azimuth value */ + const Word32 phi_fx, /* i : azimuth value Q22 */ const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat_fx, /* o : quantized azimuth */ + Word32 *phi_hat_fx, /* o : quantized azimuth Q22 */ const Word16 n /* i : azimuth codebook size */ ) { @@ -1519,7 +1528,7 @@ static Word16 quantize_phi_masa_fx( Word16 tmp_e, delta_phi_e; delta_phi_fx = L_deposit_h( BASOP_Util_Divide1616_Scale( 360, n, &delta_phi_e ) ); - delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); + delta_phi_fx = L_shr( delta_phi_fx, sub( sub( 31, delta_phi_e ), 22 ) ); // Q22 IF( EQ_16( n, 1 ) ) { @@ -1531,7 +1540,7 @@ static Word16 quantize_phi_masa_fx( IF( EQ_16( flag_delta, 1 ) ) { - dd_fx = L_shr( delta_phi_fx, 1 ); + dd_fx = L_shr( delta_phi_fx, 1 ); // Q22 } ELSE { @@ -1541,15 +1550,15 @@ static Word16 quantize_phi_masa_fx( tmp32 = L_add( L_sub( phi_fx, dd_fx ), L_shr( delta_phi_fx, 1 ) ); id_phi = BASOP_Util_Divide3232_Scale( tmp32, delta_phi_fx, &tmp_e ); - id_phi = shr( id_phi, sub( 15, tmp_e ) ); + id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0 - IF( EQ_16( id_phi, n ) ) + if ( EQ_16( id_phi, n ) ) { id_phi = 0; move16(); } - IF( EQ_16( id_phi, -1 ) ) + if ( EQ_16( id_phi, -1 ) ) { id_phi = sub( n, 1 ); } @@ -1557,7 +1566,7 @@ static Word16 quantize_phi_masa_fx( *phi_hat_fx = L_add( L_shl( Mpy_32_16_1( delta_phi_fx, id_phi ), 15 ), dd_fx ); // q22 + q0 - 15 = q7 -> q7 + 15 = q22 move32(); - return id_phi; + return id_phi; // Q0 } #endif @@ -1716,8 +1725,8 @@ void deindex_sph_idx( void deindex_sph_idx_fx( const UWord16 sphIndex, /* i : Spherical index */ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - Word32 *theta_fx, /* o : Elevation */ - Word32 *phi_fx /* o : Azimuth */ + Word32 *theta_fx, /* o : Elevation Q22*/ + Word32 *phi_fx /* o : Azimuth Q22 */ ) { Word32 ba_crt_fx, del_crt_fx, div_crt_fx, a4_crt_fx; @@ -1788,14 +1797,15 @@ void deindex_sph_idx_fx( tmp32 = Mpy_32_32( a4_crt_fx, L_shl_sat( sphIndex, Q15 ) ); /* Q10 */ tmp32 = L_add( del_crt_fx, tmp32 ); /* Q10 */ tmp16 = Q31 - Q10; - tmp32 = Sqrt32( tmp32, &tmp16 ); - tmp32 = Mpy_32_32( div_crt_fx, tmp32 ); + move16(); + tmp32 = Sqrt32( tmp32, &tmp16 ); // Q31-tmp16 + tmp32 = Mpy_32_32( div_crt_fx, tmp32 ); // Q31-tmp16 tmp32 = L_shr( tmp32, sub( Q8, tmp16 ) ); /* Q23 */ estim_fx = L_add( ba_crt_fx, tmp32 ); /* Q23 */ if ( GT_32( estim_fx, MASA_NO_CIRCLES_Q23 ) ) { - estim_fx = MASA_NO_CIRCLES_Q23; + estim_fx = MASA_NO_CIRCLES_Q23; // Q23 move32(); } @@ -1990,6 +2000,7 @@ Word16 valid_ratio_index_fx( FOR( i = 1; i < len; i++ ) { base[i] = i_mult( base[i - 1], 10 ); + move16(); } sum = 0; move16(); @@ -2075,7 +2086,7 @@ void reconstruct_ism_ratios_fx( q_energy_ratio_ism[i] = L_shl( L_mult( ratio_ism_idx[i], step ), 14 ); // q0 + q15 + 1 + 14 = q30; move32(); - sum = L_add( sum, q_energy_ratio_ism[i] ); + sum = L_add( sum, q_energy_ratio_ism[i] ); // Q30 } q_energy_ratio_ism[nchan_ism - 1] = L_sub( ONE_IN_Q30, sum ); @@ -2207,9 +2218,9 @@ void distribute_evenly_ism( } #else void distribute_evenly_ism_fx( - Word16 *idx, /* o : index values */ - const Word16 K, /* i : sum of indexes */ - const Word16 nchan_ism /* i : number of objects */ + Word16 *idx, /* o : index values Q0 */ + const Word16 K, /* i : sum of indexes Q0*/ + const Word16 nchan_ism /* i : number of objects Q0 */ ) { Word16 i; @@ -2226,7 +2237,7 @@ void distribute_evenly_ism_fx( } ELSE { - idx[i] = idiv1616( K, nchan_ism ); + idx[i] = idiv1616( K, nchan_ism ); // Q0 move16(); } sum = add( sum, idx[i] ); @@ -2238,7 +2249,7 @@ void distribute_evenly_ism_fx( move16(); WHILE( LT_16( sum, K ) ) { - IF( EQ_16( i, nchan_ism ) ) + if ( EQ_16( i, nchan_ism ) ) { i = 0; move16(); diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 064677bbd..dc26644b9 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -832,7 +832,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -842,7 +842,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -854,7 +854,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -864,7 +864,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -876,7 +876,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -886,7 +886,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -899,7 +899,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; /*Q15*/ hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; move16(); hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -909,7 +909,7 @@ static void ivas_param_mc_set_coding_scheme_fx( 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_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; /*Q8*/ hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; move16(); hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -920,6 +920,7 @@ static void ivas_param_mc_set_coding_scheme_fx( } hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate ); + move16(); return; } @@ -966,7 +967,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -977,7 +978,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -990,7 +991,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1001,7 +1002,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; @@ -1015,7 +1016,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; + hMetadataPMC->icc_coding.quantizer_fx = &ivas_param_mc_quant_icc_fx[0]; // Q15 #endif hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER; hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT; @@ -1026,7 +1027,7 @@ static void ivas_param_mc_set_coding_scheme( 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]; #ifdef IVAS_FLOAT_FIXED - hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; + hMetadataPMC->ild_coding.quantizer_fx = &ivas_param_mc_quant_ild_5d1_48_fx[0]; // Q8 #endif hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS; hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT; diff --git a/lib_com/ivas_mct_com.c b/lib_com/ivas_mct_com.c index dd7910748..ec8f0907b 100644 --- a/lib_com/ivas_mct_com.c +++ b/lib_com/ivas_mct_com.c @@ -198,7 +198,7 @@ void splitAvailableBitsMCT( void splitAvailableBitsMCT( void **sts, /* i/o: encoder/decoder state structure */ const Word16 total_bits, /* i : total number of available bits */ - const Word16 split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits */ + const Word16 split_ratio[MCT_MAX_CHANNELS], /* i : ratio for splitting the bits Q0 */ const Word16 enc_dec, /* i : encoder or decoder flag */ const Word16 nchan /* i : number of channels */ ) @@ -274,7 +274,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel; } - + move16(); IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) ) { assert( split_ratio[i] >= 1 && split_ratio[i] < BITRATE_MCT_RATIO_RANGE ); @@ -282,7 +282,7 @@ void splitAvailableBitsMCT( bits_split = add( bits_split, *bits_frame_channel ); /*determine channel with most bits (energy)*/ - IF( GT_16( *bits_frame_channel, tmp ) ) + if ( GT_16( *bits_frame_channel, tmp ) ) { tmp = *bits_frame_channel; move16(); @@ -311,7 +311,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[i] )->bits_frame_channel; } - + move16(); IF( NE_32( mct_chan_mode[i], MCT_CHAN_MODE_IGNORE ) ) { Word32 temp_res; @@ -346,7 +346,7 @@ void splitAvailableBitsMCT( { bits_frame_channel = &( (Decoder_State *) sts[max_chn] )->bits_frame_channel; } - + move16(); *bits_frame_channel = add( *bits_frame_channel, sub( total_bits, bits_split ) ); /*if all channels are silent assign bits to ch 0*/ diff --git a/lib_com/ivas_mdft_imdft.c b/lib_com/ivas_mdft_imdft.c index 579efe5da..0369afa71 100644 --- a/lib_com/ivas_mdft_imdft.c +++ b/lib_com/ivas_mdft_imdft.c @@ -49,6 +49,7 @@ #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif /*-----------------------------------------------------------------------------------------* @@ -77,33 +78,34 @@ static void ivas_get_mdft_twid_factors_fx( const Word16 length, - const Word32 **ppTwid ) + const Word32 **ppTwid // Q31 +) { SWITCH( length ) { case L_FRAME48k: - *ppTwid = &ivas_mdft_coeff_cos_twid_960_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_960_fx[0]; // Q31 BREAK; case L_FRAME32k: - *ppTwid = &ivas_mdft_coeff_cos_twid_640_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_640_fx[0]; // Q31 BREAK; case L_FRAME16k: - *ppTwid = &ivas_mdft_coeff_cos_twid_320_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_320_fx[0]; // Q31 BREAK; case IVAS_240_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_240_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_240_fx[0]; // Q31 BREAK; case IVAS_160_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_160_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_160_fx[0]; // Q31 BREAK; case IVAS_120_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_120_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_120_fx[0]; // Q31 BREAK; case IVAS_80_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_80_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_80_fx[0]; // Q31 BREAK; case IVAS_40_PT_LEN: - *ppTwid = &ivas_mdft_coeff_cos_twid_40_fx[0]; + *ppTwid = &ivas_mdft_coeff_cos_twid_40_fx[0]; // Q31 BREAK; default: assert( !"Not supported FFT length!" ); @@ -120,27 +122,28 @@ static void ivas_get_mdft_twid_factors_fx( static void ivas_get_imdft_twid_factors_fx( const Word16 length, - const Word32 **ppTwid ) + const Word32 **ppTwid // Q31 +) { SWITCH( length ) { case L_FRAME48k: - *ppTwid = ivas_mdft_coeff_cos_twid_960_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_960_fx; // Q31 BREAK; case L_FRAME32k: - *ppTwid = ivas_mdft_coeff_cos_twid_640_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_640_fx; // Q31 BREAK; case L_FRAME16k: - *ppTwid = ivas_mdft_coeff_cos_twid_320_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_320_fx; // Q31 BREAK; case 240: - *ppTwid = ivas_mdft_coeff_cos_twid_240_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_240_fx; // Q31 BREAK; case 160: - *ppTwid = ivas_mdft_coeff_cos_twid_160_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_160_fx; // Q31 BREAK; case 80: - *ppTwid = ivas_mdft_coeff_cos_twid_80_fx; + *ppTwid = ivas_mdft_coeff_cos_twid_80_fx; // Q31 BREAK; default: assert( !"Not supported FFT length!" ); @@ -268,37 +271,37 @@ static void get_one_by_length( #ifdef IVAS_FLOAT_FIXED static void get_one_by_length_fx( - Word32 *one_by_length, + Word32 *one_by_length, // Q37 const Word16 length ) { IF( EQ_16( length, L_FRAME48k ) ) { - *one_by_length = IVAS_ONE_BY_960_Q37; + *one_by_length = IVAS_ONE_BY_960_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, L_FRAME32k ) ) { - *one_by_length = IVAS_ONE_BY_640_Q37; + *one_by_length = IVAS_ONE_BY_640_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, L_FRAME16k ) ) { - *one_by_length = IVAS_ONE_BY_320_Q37; + *one_by_length = IVAS_ONE_BY_320_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_240_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_240_Q37; + *one_by_length = IVAS_ONE_BY_240_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_160_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_160_Q37; + *one_by_length = IVAS_ONE_BY_160_Q37; // Q37 move32(); } ELSE IF( EQ_16( length, IVAS_80_PT_LEN ) ) { - *one_by_length = IVAS_ONE_BY_80_Q37; + *one_by_length = IVAS_ONE_BY_80_Q37; // Q37 move32(); } ELSE @@ -316,32 +319,32 @@ static void get_one_by_length_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_ifft_cplx1_fx( - Word32 *re, - Word32 *im, + Word32 *re, // inp: Qin -> out: Qin + 6 + Word32 *im, // inp: Qin -> out: Qin + 6 const Word16 length ) { Word16 i; Word32 one_by_length, tmp; - get_one_by_length_fx( &one_by_length, length ); + get_one_by_length_fx( &one_by_length, length ); // Q37 /* re-arrange inputs to use fft as ifft */ - re[0] = Mpy_32_32( re[0], one_by_length ); + re[0] = Mpy_32_32( re[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); - im[0] = Mpy_32_32( im[0], one_by_length ); + im[0] = Mpy_32_32( im[0], one_by_length ); // ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); FOR( i = 1; i <= length >> 1; i++ ) { - tmp = Mpy_32_32( re[sub( length, i )], one_by_length ); /*stl_arr_index*/ - re[sub( length, i )] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( re[length - i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ + re[length - i] = Mpy_32_32( re[i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ move32(); re[i] = tmp; move32(); - tmp = Mpy_32_32( im[sub( length, i )], one_by_length ); /*stl_arr_index*/ - im[sub( length, i )] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index*/ + tmp = Mpy_32_32( im[length - i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ + im[length - i] = Mpy_32_32( im[i], one_by_length ); /*stl_arr_index Q: ( Qin + Q37 ) - Q31 -> Qin + 6 */ move32(); - im[i] = tmp; + im[i] = tmp; // Q: ( Qin + Q37 ) - Q31 -> Qin + 6 move32(); } @@ -359,17 +362,17 @@ 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 Word16 input_length, /* i : signal length */ - const Word16 mdft_length /* i : MDFT length */ + const Word32 *pIn, /* i : input time-domain signal Qin */ + Word32 *pOut_re, /* o : Real part of MDFT signal Qin */ + Word32 *pOut_im, /* o : Imag. part of MDFT signal Qin */ + const Word16 input_length, /* i : signal length */ + const Word16 mdft_length /* i : MDFT length */ ) { Word32 re[L_FRAME48k]; Word32 im[L_FRAME48k]; Word16 j, len_by_2; - const Word32 *pTwid; + const Word32 *pTwid; // Q31 len_by_2 = shr( mdft_length, 1 ); ivas_get_mdft_twid_factors_fx( mdft_length, &pTwid ); @@ -377,9 +380,9 @@ void ivas_mdft_fx( { FOR( j = 0; j < mdft_length; j++ ) { - re[j] = Mpy_32_32( pIn[j], pTwid[j] ); + re[j] = Mpy_32_32( pIn[j], pTwid[j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); - im[j] = Mpy_32_32( L_negate( pIn[j] ), pTwid[sub( mdft_length, j )] ); + im[j] = Mpy_32_32( L_negate( pIn[j] ), pTwid[mdft_length - j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); } } @@ -387,9 +390,9 @@ void ivas_mdft_fx( { FOR( j = 0; j < mdft_length; j++ ) { - re[j] = Msub_32_32( Mpy_32_32( pIn[j], pTwid[j] ), pIn[add( mdft_length, j )], pTwid[sub( mdft_length, j )] ); + re[j] = Msub_32_32( Mpy_32_32( pIn[j], pTwid[j] ), pIn[add( mdft_length, j )], pTwid[mdft_length - j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); - im[j] = Msub_32_32( Mpy_32_32( L_negate( pIn[j] ), pTwid[sub( mdft_length, j )] ), pIn[add( mdft_length, j )], pTwid[j] ); + im[j] = Msub_32_32( Mpy_32_32( L_negate( pIn[j] ), pTwid[mdft_length - j] ), pIn[mdft_length + j], pTwid[j] ); // ( Qin + Q31 ) - Q31 -> Qin move32(); } } @@ -397,14 +400,14 @@ void ivas_mdft_fx( fft_fx( re, im, mdft_length, 1 ); FOR( j = 0; j < len_by_2; j++ ) { - pOut_re[2 * j] = re[j]; + pOut_re[2 * j] = re[j]; // Qin move32(); - pOut_re[add( imult1616( 2, j ), 1 )] = re[sub( sub( mdft_length, j ), 1 )]; + pOut_re[2 * j + 1] = re[mdft_length - j - 1]; // Qin move32(); - pOut_im[2 * j] = im[j]; + pOut_im[2 * j] = im[j]; // Qin move32(); - pOut_im[add( imult1616( 2, j ), 1 )] = L_negate( im[sub( sub( mdft_length, j ), 1 )] ); + pOut_im[2 * j + 1] = L_negate( im[mdft_length - j - 1] ); // Qin move32(); } return; @@ -419,10 +422,10 @@ 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 Word16 length /* i : signal length */ + const Word32 *pRe, /* i : Real part of MDFT signal Qin */ + const Word32 *pIm, /* i : Imag. part of MDFT signal Qin */ + Word32 *pOut, /* o : output time-domain signal Qin */ + const Word16 length /* i : signal length */ ) { Word32 *re_tmp = pOut; @@ -430,32 +433,34 @@ void ivas_imdft_fx( Word32 tmp; Word16 j; Word16 len_by_2; - const Word32 *pTwid; + const Word32 *pTwid; // Q31 len_by_2 = shr( length, 1 ); ivas_get_imdft_twid_factors_fx( length, &pTwid ); FOR( j = 0; j < len_by_2; j++ ) { - re_tmp[j] = pRe[2 * j]; + re_tmp[j] = pRe[2 * j]; // Qin move32(); - re_tmp[add( j, len_by_2 )] = pRe[sub( sub( length, imult1616( 2, j ) ), 1 )]; + re_tmp[j + len_by_2] = pRe[length - 2 * j - 1]; // Qin move32(); - im_tmp[j] = pIm[2 * j]; + im_tmp[j] = pIm[2 * j]; // Qin move32(); - im_tmp[add( j, len_by_2 )] = L_negate( pIm[sub( sub( length, imult1616( 2, j ) ), 1 )] ); + im_tmp[j + len_by_2] = L_negate( pIm[length - 2 * j - 1] ); // Qin move32(); } ivas_ifft_cplx1_fx( re_tmp, im_tmp, length ); + // re_tmp: Qin + 6 + // im_tmp: Qin + 6 FOR( j = 0; j < length; j++ ) { - tmp = Msub_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[j] ), L_shr( im_tmp[j], Q6 ), pTwid[sub( length, j )] ); - im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[sub( length, j )] ), L_shr( im_tmp[j], Q6 ), pTwid[j] ) ); + tmp = Msub_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[j] ), L_shr( im_tmp[j], Q6 ), pTwid[length - j] ); // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin + im_tmp[j] = L_negate( Madd_32_32( Mpy_32_32( L_shr( re_tmp[j], Q6 ), pTwid[length - j] ), L_shr( im_tmp[j], Q6 ), pTwid[j] ) ); // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin move32(); - re_tmp[j] = tmp; + re_tmp[j] = tmp; // ( ( Qin + Q6 - Q6 ) + Q31 ) - Q31 -> Qin move32(); } return; diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 5dbe03866..037364420 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -882,7 +882,9 @@ void calculate_nbits_meta( return; } #else -static Word16 get_bits_ism( Word32 val ) +static Word16 get_bits_ism( + Word32 val // Q29 +) { Word16 res; test(); @@ -891,33 +893,41 @@ static Word16 get_bits_ism( Word32 val ) test(); test(); test(); - IF( LE_32( val, 536870912 ) && GT_32( val, 447750340 ) ) + /* Considering only 3 points after decimal point, and replacing the other digits with 9 after that*/ + IF( LE_32( val, 536870912 /*1 (in Q29)*/ ) && GT_32( val, 447750340 /*5/6 (in Q29)*/ ) ) { + // 1 (in Q29) <= val <= 5/6 (in Q29) => res = 0 res = 0; move16(); } - ELSE IF( LE_32( val, 447750340 ) && GT_32( val, 358092897 ) ) + ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092897 /*4/6 (in Q29)*/ ) ) { + // 5/6 (in Q29) <= val <= 4/6 (in Q29) => res = 1 res = 1; move16(); } - ELSE IF( LE_32( val, 358092897 ) && GT_32( val, 268972326 ) ) + ELSE IF( LE_32( val, 358092897 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) { + // 4/6 (in Q29) <= val <= 3/6 (in Q29) => res = 2 res = 2; move16(); } - ELSE IF( LE_32( val, 268972326 ) && GT_32( val, 179314884 ) ) + ELSE IF( LE_32( val, 268972326 /*3/6 (in Q29)*/ ) && GT_32( val, 179314884 /* 2/6 (in Q29) */ ) ) { + // 3/6 (in Q29) <= val <= 2/6 (in Q29) => res = 3 res = 3; move16(); } - ELSE IF( LE_32( val, 179314884 ) && GT_32( val, 89657442 ) ) + ELSE IF( LE_32( val, 179314884 /* 2/6 (in Q29) */ ) && GT_32( val, 89657442 /* 1/6 => res (in Q29) */ ) ) { + // 2/6 (in Q29) <= val <= 1/6 => res (in Q29) = 4 res = 4; move16(); } - ELSE IF( LE_32( val, 89657442 ) && GT_32( val, 536870 ) ) + ELSE IF( LE_32( val, 89657442 /* 1/6 => res (in Q29) */ ) && GT_32( val, 536870 /* 0.0009999999 ( in Q29 )*/ ) ) { + // 1/6 (in Q29) <= val <= 0 (in Q29) => res = 5 + // 0.0009999999 in Q29-> 536870 res = 5; move16(); } @@ -952,7 +962,7 @@ void calculate_nbits_meta_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { - priority[obj] = L_max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( 1073741824 /* 1.0f in Q30 */, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 + priority[obj] = L_max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( ONE_IN_Q30 /* 1.0f in Q30 */, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 move32(); } } @@ -960,7 +970,7 @@ void calculate_nbits_meta_fx( } ELSE { - priority[0] = 536870912; /* 1.0f in Q29 */ + priority[0] = ONE_IN_Q29; /* 1.0f in Q29 */ move32(); } @@ -972,12 +982,12 @@ void calculate_nbits_meta_fx( { IF( EQ_16( ism_imp, 3 ) ) { - priority[obj] = 536870912; /* 1.0f in Q29 */ + priority[obj] = ONE_IN_Q29; /* 1.0f in Q29 */ move32(); } ELSE IF( EQ_16( ism_imp, 2 ) ) { - priority[obj] = L_shr( L_add( 536870912, max_p ), 1 ); + priority[obj] = L_shr( L_add( ONE_IN_Q29, max_p ), 1 ); // Q29 move32(); } ELSE @@ -1043,12 +1053,13 @@ void ivas_get_stereo_panning_gains( #define SIN_30_DEGREES_Q15 ( (Word16) 0x4000 ) void get_panning_gain( - const Word16 sinAngleMapped, - Word16 *panningGains ) + const Word16 sinAngleMapped, // Q15 + Word16 *panningGains // Q15 +) { Word16 tbl_len, idx, lim_l, lim_r; - const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; - const Word16 *ptr_tan_0 = ivas_tan_panning_gain_tbl_fx; + const Word16 *ptr_sin = &ivas_sine_panning_tbl_fx[0]; // Q15 + const Word16 *ptr_tan_0 = ivas_tan_panning_gain_tbl_fx; // Q15 tbl_len = 601; move16(); @@ -1064,17 +1075,17 @@ void get_panning_gain( test(); IF( GE_16( idx, tbl_len ) ) { - panningGains[0] = ptr_tan_0[tbl_len - 1]; + panningGains[0] = ptr_tan_0[tbl_len - 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[0]; + panningGains[1] = ptr_tan_0[0]; // Q15 move16(); BREAK; } ELSE IF( idx < 0 ) { - panningGains[0] = ptr_tan_0[0]; + panningGains[0] = ptr_tan_0[0]; // Q15 move16(); - panningGains[1] = ptr_tan_0[tbl_len - 1]; + panningGains[1] = ptr_tan_0[tbl_len - 1]; // Q15 move16(); BREAK; } @@ -1082,17 +1093,17 @@ void get_panning_gain( { IF( EQ_16( sinAngleMapped, ptr_sin[idx + 1] ) ) { - panningGains[0] = ptr_tan_0[idx + 1]; + panningGains[0] = ptr_tan_0[idx + 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 2 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 2]; // Q15 move16(); BREAK; } ELSE IF( EQ_16( sinAngleMapped, ptr_sin[idx] ) ) { - panningGains[0] = ptr_tan_0[idx]; + panningGains[0] = ptr_tan_0[idx]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 1 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 1]; // Q15 move16(); BREAK; } @@ -1102,16 +1113,16 @@ void get_panning_gain( mid = extract_l( L_shr( L_add( L_deposit_l( ptr_sin[idx] ), L_deposit_l( ptr_sin[idx + 1] ) ), 1 ) ); IF( LE_16( sinAngleMapped, mid ) ) { - panningGains[0] = ptr_tan_0[idx]; + panningGains[0] = ptr_tan_0[idx]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 1 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 1]; // Q15 move16(); } ELSE { - panningGains[0] = ptr_tan_0[idx + 1]; + panningGains[0] = ptr_tan_0[idx + 1]; // Q15 move16(); - panningGains[1] = ptr_tan_0[sub( sub( tbl_len, idx ), 2 )]; + panningGains[1] = ptr_tan_0[tbl_len - idx - 2]; // Q15 move16(); } BREAK; @@ -1132,48 +1143,49 @@ void get_panning_gain( void ivas_get_stereo_panning_gains_fx( - const Word16 aziDeg, - const Word16 eleDeg, - Word16 panningGains[2] ) + const Word16 aziDeg, // Q0 + const Word16 eleDeg, // Q0 + Word16 panningGains[2] // Q15 +) { /* Convert azi and ele to an azi value of the cone of confusion */ - Word16 azAddEl = add( aziDeg, eleDeg ); - Word16 azSubEl = sub( aziDeg, eleDeg ); + Word16 azAddEl = add( aziDeg, eleDeg ); // Q0 + Word16 azSubEl = sub( aziDeg, eleDeg ); // Q0 - const Word16 *ptr_sin_az = ivas_sin_az_fx; + const Word16 *ptr_sin_az = ivas_sin_az_fx; // Q15 WHILE( GT_16( azAddEl, 180 ) ) { - azAddEl = sub( azAddEl, 360 ); + azAddEl = sub( azAddEl, 360 ); // Q0 } WHILE( LT_16( azAddEl, -180 ) ) { - azAddEl = add( azAddEl, 360 ); + azAddEl = add( azAddEl, 360 ); // Q0 } WHILE( GT_16( azSubEl, 180 ) ) { - azSubEl = sub( azSubEl, 360 ); + azSubEl = sub( azSubEl, 360 ); // Q0 } WHILE( LT_16( azSubEl, -180 ) ) { - azSubEl = add( azSubEl, 360 ); + azSubEl = add( azSubEl, 360 ); // Q0 } // sin_az_cos_el = (ptr_sin_az[azAddEl] + ptr_sin_az[azSubEl])/2; Word16 sin_az_cos_el; - sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); + sin_az_cos_el = extract_l( L_shr( L_add( L_deposit_l( ptr_sin_az[azAddEl + 180] ), L_deposit_l( ptr_sin_az[azSubEl + 180] ) ), 1 ) ); // Q15 IF( GE_16( sin_az_cos_el, SIN_30_DEGREES_Q15 ) ) - { /* Left side */ - panningGains[0] = (Word16) 0x7fff; + { /* Left side */ + panningGains[0] = (Word16) 0x7fff; // Q15 move16(); - panningGains[1] = 0; + panningGains[1] = 0; // Q15 move16(); } ELSE IF( LE_16( sin_az_cos_el, SIN_NEG_30_DEGREES_Q15 ) ) - { /* Right side */ - panningGains[0] = 0; + { /* Right side */ + panningGains[0] = 0; // Q15 move16(); - panningGains[1] = (Word16) 0x7fff; + panningGains[1] = (Word16) 0x7fff; // Q15 move16(); } ELSE /* Tangent panning law */ diff --git a/lib_com/ivas_pca_tools.c b/lib_com/ivas_pca_tools.c index 4df06a23d..e0fed0fa6 100644 --- a/lib_com/ivas_pca_tools.c +++ b/lib_com/ivas_pca_tools.c @@ -41,6 +41,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*---------------------------------------------------------------------* @@ -85,9 +86,10 @@ static Word16 check_bound( Word32 tmp ) #ifdef IVAS_FLOAT_FIXED void eye_matrix_fx( - Word16 *mat, + Word16 *mat, // Q const Word16 n, - const Word16 d ) + const Word16 d // Q +) { Word16 i; @@ -98,7 +100,7 @@ void eye_matrix_fx( } FOR( i = 0; i < n; i++ ) { - mat[add( imult1616( i, n ), i )] = d; + mat[i * n + i] = d; // Q move16(); } @@ -120,7 +122,7 @@ void eye_matrix_fx32( } FOR( i = 0; i < n; i++ ) { - mat[i * n + i] = d; + mat[i * n + i] = d; // Q move32(); } @@ -190,7 +192,7 @@ void cov_subfr_fx( FOR( k = 0; k < n_channels; k++ ) { t_fx = &ptr_sig_fx[k][0]; - s_fx = W_shr( W_mult0_32_32( t_fx[0], t_fx[0] ), 11 ); // Q11 + s_fx = W_shr( W_mult0_32_32( t_fx[0], t_fx[0] ), 11 ); // Q11 + Q11 - Q11 -> Q11 FOR( j = 1; j < len; j++ ) { if ( s_fx != 0 ) @@ -198,7 +200,7 @@ void cov_subfr_fx( t_fx[j] = t_fx[j]; move32(); } - s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], t_fx[j] ), 11 ) ); // Q11 + s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], t_fx[j] ), 11 ) ); // Q11 + Q11 - Q11 -> Q11 } r_fx_64[k * n_channels + k] = s_fx; // Q11 move64(); @@ -211,7 +213,7 @@ void cov_subfr_fx( FOR( l = k + 1; l < n_channels; l++ ) { tt_fx = &ptr_sig_fx[l][0]; - s_fx = W_shr( W_mult0_32_32( t_fx[0], tt_fx[0] ), 11 ); // Q11 + s_fx = W_shr( W_mult0_32_32( t_fx[0], tt_fx[0] ), 11 ); // Q11 + Q11 - Q11 -> Q11 FOR( j = 1; j < len; j++ ) { s_fx = W_add( s_fx, W_shr( W_mult0_32_32( t_fx[j], tt_fx[j] ), 11 ) ); @@ -278,7 +280,7 @@ static void house_refl_fx( const Word16 sizex, Word32 *pu_fx, // Q: pu_q Word16 *pu_fx_q, - Word32 *normu_fx, // Q: q_norm + Word32 *normu_fx, // Q: q_normu Word16 *q_normu ) { Word16 i; @@ -292,7 +294,7 @@ static void house_refl_fx( move64(); FOR( Word16 k = 0; k < sizex; k++ ) { - L64_sum = W_mac_32_32( L64_sum, pu_fx[k], pu_fx[k] ); + L64_sum = W_mac_32_32( L64_sum, pu_fx[k], pu_fx[k] ); // pu_q } Word16 norm = W_norm( L64_sum ); L64_sum = W_shl( L64_sum, norm ); @@ -307,17 +309,17 @@ static void house_refl_fx( IF( ( *normu_fx ) == 0 ) { - pu_fx[0] = SQRT2_FIXED; // same q as other elements + pu_fx[0] = SQRT2_FIXED; // same q as other elements -> Q30 pu_e[0] = 1; move32(); move16(); } ELSE { - tmp = BASOP_Util_Divide3232_Scale( 1073741824, *normu_fx, &exp ); // Q30 + px_q, 1073741824 ->1 in Q30 + tmp = BASOP_Util_Divide3232_Scale( ONE_IN_Q30, *normu_fx, &exp ); // Q30 + px_q, 1073741824 ->1 in Q30 exp = add( exp, sub( 1, sub( 31, normu_q ) ) ); - Word32 rcp_fx = L_deposit_h( tmp ); + Word32 rcp_fx = L_deposit_h( tmp ); // rcp_q Word16 rcp_q = sub( Q31, exp ); rcp_fx = L_shr( rcp_fx, sub( rcp_q, Q31 ) ); // making rcp_fx in Q31 @@ -333,7 +335,7 @@ static void house_refl_fx( IF( pu_fx[0] >= 0 ) { - pu_fx[0] = L_add( pu_fx[0], L_shl( 1, 31 - pu_e[0] ) ); + pu_fx[0] = L_add( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); ( *normu_fx ) = L_negate( *normu_fx ); move32(); @@ -341,7 +343,7 @@ static void house_refl_fx( } ELSE { - pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, 31 - pu_e[0] ) ); + pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) ); move32(); } @@ -518,7 +520,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pa_fx[i] = A_fx[i * n + c]; + pa_fx[i] = A_fx[i * n + c]; // pA_q move32(); } @@ -527,7 +529,7 @@ static void house_qr_fx( Word16 norm; FOR( Word16 l = 0; l < n_rows - k; l++ ) { - L64_sum = W_mac_32_32( L64_sum, pa_fx[k + l], pu_fx[l] ); + L64_sum = W_mac_32_32( L64_sum, pa_fx[k + l], pu_fx[l] ); // pA_q + pu_fx_q } norm = W_norm( L64_sum ); L64_sum = W_shl( L64_sum, norm ); @@ -550,8 +552,8 @@ static void house_qr_fx( FOR( r = k + 1; r < n_rows; r++ ) { - A_fx[s * n_rows + r] = BASOP_Util_Add_Mant32Exp( A_fx[s * n_rows + r], sub( 31, pA_q ), L_negate( Mpy_32_32( pv_fx[j], pu_fx[i] ) ), add( sub( 31, pu_fx_q ), pv_exp[j] ), &exp2 ); - A_fx[s * n_rows + r] = L_shr_sat( A_fx[s * n_rows + r], sub( sub( 31, exp2 ), pA_q ) ); + A_fx[s * n_rows + r] = BASOP_Util_Add_Mant32Exp( A_fx[s * n_rows + r], sub( 31, pA_q ), L_negate( Mpy_32_32( pv_fx[j], pu_fx[i] ) ), add( sub( 31, pu_fx_q ), pv_exp[j] ), &exp2 ); // exp2 + A_fx[s * n_rows + r] = L_shr_sat( A_fx[s * n_rows + r], sub( sub( 31, exp2 ), pA_q ) ); // pA_q move32(); j = add( j, 1 ); } @@ -571,7 +573,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); + pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); // pu_fx_q move32(); } @@ -579,7 +581,7 @@ static void house_qr_fx( { FOR( i = 0; i < n_rows; i++ ) { - pa_fx[i] = pQ_fx[i * n + s]; + pa_fx[i] = pQ_fx[i * n + s]; // Q31 move32(); } @@ -711,7 +713,7 @@ void eig_qr_fx( move16(); /* check zero matrix */ - d_fx = dotp_fixed( A_fx, A_fx, n * n ); + d_fx = dotp_fixed( A_fx, A_fx, n * n ); // A_q + A_q - Q31 -> d_q d_q = sub( add( A_q, A_q ), 31 ); if ( d_fx != 0 ) @@ -720,14 +722,14 @@ void eig_qr_fx( move16(); } /* duplicate */ - Copy32( A_fx, Ak_fx, n * n ); + Copy32( A_fx, Ak_fx, n * n ); // A_q /* identity */ set_zero_fx( EV_fx, n * n ); FOR( i = 0; i < n; i++ ) { - EV_fx[i * n + i] = 2147483647; // 1 in Q31 + EV_fx[i * n + i] = ONE_IN_Q31; // 1 in Q31 move32(); } set_zero_fx( Vals_fx, n ); @@ -742,12 +744,12 @@ void eig_qr_fx( FOR( i = 0; i < n; i++ ) { - D_fx[i * n + i] = Vals_fx[i]; + D_fx[i * n + i] = Vals_fx[i]; // A_q move32(); } /* stop condition */ - d_fx = dotp_fixed_guarded( D_fx, D_fx, n * n ); + d_fx = dotp_fixed_guarded( D_fx, D_fx, n * n ); // ( A_q + A_q - 31 ) - find_guarded_bits_fx( n * n ) d_q = sub( sub( add( A_q, A_q ), 31 ), find_guarded_bits_fx( n * n ) ); exp = sub( 31, d_q ); d_fx = Sqrt32( d_fx, &exp ); @@ -761,11 +763,11 @@ void eig_qr_fx( house_qr_fx( Ak_fx, A_q, Qk_fx, Rk_fx, n ); - matrix_product_fx( Qk_fx, n, n, 0, Rk_fx, n, n, 0, Ak_fx ); - matrix_product_mant_exp_fx( Qk_fx, 0, n, n, 0, EV_fx, 0, n, n, 0, D_fx, &exp ); - Scale_sig32( D_fx, imult1616( n, n ), exp ); + matrix_product_fx( Qk_fx, n, n, 0, Rk_fx, n, n, 0, Ak_fx ); // A_q + Q31 - Q31 -> A_q + matrix_product_mant_exp_fx( Qk_fx, 0, n, n, 0, EV_fx, 0, n, n, 0, D_fx, &exp ); // Q31 + Q31 - Q31 -> Q31 + Scale_sig32( D_fx, imult1616( n, n ), exp ); // Q31 - Copy32( D_fx, EV_fx, imult1616( n, n ) ); + Copy32( D_fx, EV_fx, imult1616( n, n ) ); // Q31 } @@ -1056,8 +1058,8 @@ void mat2dquat_fx( /* determine (absolute) left and right terms */ i_ql = 0; i_qr = 0; - ql_max = MIN_16; - qr_max = MIN_16; + ql_max = MIN_16; // Q15 + qr_max = MIN_16; // Q15 move16(); move16(); move16(); @@ -1082,7 +1084,7 @@ void mat2dquat_fx( } - ql[i] = Sqrt16( tmp_l, &tmp_l_e ); + ql[i] = Sqrt16( tmp_l, &tmp_l_e ); // tmp_l_e ql[i] = check_bound( L_shl( ql[i], tmp_l_e ) ); // Q15 move16(); move16(); @@ -1094,13 +1096,13 @@ void mat2dquat_fx( move16(); } - qr[i] = Sqrt16( tmp_r, &tmp_r_e ); + qr[i] = Sqrt16( tmp_r, &tmp_r_e ); // tmp_r_e qr[i] = check_bound( L_shl( qr[i], tmp_r_e ) ); // Q15 move16(); move16(); IF( GT_16( qr[i], qr_max ) ) { - qr_max = qr[i]; + qr_max = qr[i]; // Q15 i_qr = i; move16(); move16(); @@ -1112,7 +1114,7 @@ void mat2dquat_fx( { IF( AM[i_ql * 4 + k] < 0 ) { - qr[k] = negate( qr[k] ); + qr[k] = negate( qr[k] ); // Q15 move16(); } } @@ -1122,7 +1124,7 @@ void mat2dquat_fx( temp = mult( AM[k * 4 + i_qr], mult( ql[k], qr[i_qr] ) ); // Q15 IF( temp < 0 ) { - ql[k] = negate( ql[k] ); + ql[k] = negate( ql[k] ); // Q15 move16(); } } @@ -1241,6 +1243,7 @@ void dquat2mat_fx( dx = mult( d, x ); dy = mult( d, y ); dz = mult( d, z ); + // Q15 m[0] = check_bound( L_sub( L_sub( aw, bx ), L_add( cy, dz ) ) ); move16(); m[1] = check_bound( L_sub( L_sub( cz, dy ), L_add( ax, bw ) ) ); @@ -1504,31 +1507,32 @@ static void norm_quat( #ifdef IVAS_FLOAT_FIXED -static Word32 dotp16_fixed_guarded( const Word16 x[], /* i : vector x[] */ - const Word16 y[], /* i : vector y[] */ - const Word16 n /* i : vector length */ ) +static Word32 dotp16_fixed_guarded( const Word16 x[], /* i : vector x[] Qx */ + const Word16 y[], /* i : vector y[] Qy */ + const Word16 n /* i : vector length */ ) { Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); - suma = L_shr( L_mult( x[0], y[0] ), guarded_bits ); + suma = L_shr( L_mult( x[0], y[0] ), guarded_bits ); // Qx + Qy - guarded_bits FOR( i = 1; i < n; i++ ) { - suma = L_add( suma, L_shr( L_mult( x[i], y[i] ), guarded_bits ) ); + suma = L_add( suma, L_shr( L_mult( x[i], y[i] ), guarded_bits ) ); // Qx + Qy - guarded_bits } return suma; } static void norm_quat_fx( - Word16 *q ) + Word16 *q // Q15 +) { Word32 norm_q; Word16 i, exp1; exp1 = 0; move16(); - norm_q = dotp16_fixed_guarded( q, q, IVAS_PCA_INTERP ); + norm_q = dotp16_fixed_guarded( q, q, IVAS_PCA_INTERP ); // (Q15 + Q15 - Q15) - exp1 exp1 = find_guarded_bits_fx( IVAS_PCA_INTERP ); norm_q = ISqrt32( norm_q, &exp1 ); /*Q(31 - exp)*/ @@ -1562,10 +1566,11 @@ 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, // Q15 + const Word16 *q1, // Q15 + const Word16 alpha, // Q15 + Word16 *q_slerp // Q15 +) { Word16 i; Word16 tmp1, tmp2; @@ -1574,12 +1579,13 @@ static void quat_nlerp_preproc_fx( { tmp1 = mult( sub( MAX_16, alpha ), q1[i] ); tmp2 = mult_r( alpha, q0[i] ); - if ( EQ_16( alpha, q0[i] ) && EQ_16( alpha, 32767 ) ) + test(); + if ( EQ_16( alpha, q0[i] ) && EQ_16( alpha, MAX_16 ) ) { - tmp2 = 32767; + tmp2 = MAX_16; move16(); } - q_slerp[i] = add( tmp1, tmp2 ); + q_slerp[i] = add( tmp1, tmp2 ); // Q15 move16(); } @@ -1614,13 +1620,14 @@ 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 *prev_ql, // Q15 + const Word16 *prev_qr, // Q15 + const Word16 *ql, // Q15 + const Word16 *qr, // Q15 const Word16 len, - Word16 *ql_interp, - Word16 *qr_interp ) + Word16 *ql_interp, // Q15 + Word16 *qr_interp // Q15 +) { Word16 alpha; Word16 j; @@ -1641,7 +1648,7 @@ void pca_interp_preproc_fx( tmp2 = mult( EVS_PI_FX, alpha ); /* Q13 */ tmp3 = getCosWord16( tmp2 ); /* Q14 */ alpha = sub_sat( ONE_IN_Q14, tmp3 ); /* Q15 */ - alpha = sub( MAX_16, alpha ); + alpha = sub( MAX_16, alpha ); // Q15 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] ); } @@ -1669,11 +1676,11 @@ static Word16 acos_clip_fx( { Word16 ph_fx; - v_fx = check_bounds_s_fx( v_fx, -32767, 32767 ); + v_fx = check_bounds_s_fx( v_fx, -32767, 32767 ); // Q15 Word32 tmp1_fx, tmp2_fx; Word16 tmp1_e, tmp2_e; - tmp1_fx = L_sub( 2147483647, L_deposit_h( mult( v_fx, v_fx ) ) ); // Q31 + tmp1_fx = L_sub( ONE_IN_Q31, L_deposit_h( mult( v_fx, v_fx ) ) ); // Q31 tmp1_e = 0; tmp2_e = 0; move16(); @@ -1718,7 +1725,7 @@ static void sp2cart_fx( Word16 s1, s2, s1s2; Word16 sin_ph3, cos_ph3; - sin_ph3 = cos_ph3 = ph3; + sin_ph3 = cos_ph3 = ph3; // Q12 move16(); move16(); @@ -2063,8 +2070,8 @@ static void q_ang_circ_fx( } assert( ( *index >= 0 ) && ( *index <= ( N - 1 ) ) ); - d_fx = shl( d_fx, sub( 12, sub( 15, d_e ) ) ); - *a_q_fx = extract_l( L_mult0( *index, d_fx ) ); + d_fx = shl( d_fx, sub( 12, sub( 15, d_e ) ) ); // Q12 + *a_q_fx = extract_l( L_mult0( *index, d_fx ) ); // Q12 move16(); return; @@ -2548,9 +2555,9 @@ void pca_dec_s3_fx( assert( index1 > -1 ); - ph1_q_fx = ph1_q_n2_tbl[index1][0]; + ph1_q_fx = ph1_q_n2_tbl[index1][0]; // Q13 move16(); - n2 = ph1_q_n2_tbl[index1][1]; + n2 = ph1_q_n2_tbl[index1][1]; // Q0 move16(); j = L_sub( j, ivas_pca_offset_index1[index1] ); @@ -2576,7 +2583,7 @@ void pca_dec_s3_fx( ELSE { - num_fx = 12868; + num_fx = 12868; // EVS_PI in Q12 move16(); d_fx = BASOP_Util_Divide1616_Scale( num_fx, sub( n2, 1 ), &exp ); /* Q12 */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 75c7d206f..b63a975d3 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -86,10 +86,6 @@ void copy_encoder_config( void ivas_write_format( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#else -void ivas_write_format_fx( /* i/o: IVAS encoder structure */ - Encoder_Struct *st_ivas -); #endif #ifndef IVAS_FLOAT_FIXED @@ -98,12 +94,6 @@ void ivas_write_format_sid( const int16_t element_mode, /* i : element bitrate */ BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ ); -#else -void ivas_write_format_sid_fx( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 element_mode, /* i : element bitrate */ - BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ -); #endif ivas_error create_sce_enc( @@ -112,12 +102,6 @@ ivas_error create_sce_enc( const int32_t element_brate /* i : element bitrate */ ); -ivas_error create_sce_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 sce_id, /* i : SCE # identifier */ - const Word32 element_brate /* i : element bitrate */ -); - ivas_error create_evs_sce_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t sce_id, /* i : SCE # identifier */ @@ -130,12 +114,6 @@ ivas_error create_cpe_enc( const int32_t element_brate /* i : element bitrate */ ); -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 */ -); - ivas_error create_mct_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -180,16 +158,7 @@ ivas_error ivas_sce_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cpe_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - float data_f_ch0[], /* i : input signal for channel 0 */ - float data_f_ch1[], /* i : input signal for channel 1 */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_cpe_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t cpe_id, /* i : CPE # identifier */ @@ -200,6 +169,15 @@ ivas_error ivas_cpe_enc( ); #endif +ivas_error ivas_cpe_enc( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + float data_f_ch0[], /* i : input signal for channel 0 */ + float data_f_ch1[], /* i : input signal for channel 1 */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + ivas_error ivas_mct_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ float *data[MCT_MAX_CHANNELS], /* i : input signal buffers */ @@ -381,15 +359,6 @@ void ivas_syn_output_f( float *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_syn_output_f_fx( - 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 */ -); -#endif - void ivas_initialize_handles_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -398,10 +367,6 @@ ivas_error ivas_init_encoder( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -ivas_error ivas_init_encoder_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -); - void destroy_core_enc( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ); @@ -426,13 +391,6 @@ ivas_error ivas_init_decoder_front( ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_output_buff_dec_fx( - 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 */ -); -#else ivas_error ivas_output_buff_dec( float *p_output_f[], /* i/o: output audio buffers */ @@ -461,12 +419,6 @@ ivas_error ivas_dec_setup( uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ int16_t *data /* o : output synthesis signal */ ); -#else -ivas_error ivas_dec_setup( - 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 */ -); #endif #ifndef IVAS_FLOAT_FIXED @@ -482,12 +434,7 @@ ivas_error create_cpe_dec( const int32_t element_brate /* i : element bitrate */ ); #endif // !IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error create_mct_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); @@ -497,13 +444,6 @@ ivas_error mct_dec_reconfigure( const uint16_t b_nchan_change /* i : flag indicating different channel count */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error mct_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 b_nchan_change /* i : flag indicating different channel count */ -); -#endif - #ifndef IVAS_FLOAT_FIXED void destroy_sce_dec( SCE_DEC_HANDLE hSCE /* i/o: SCE decoder structure */ @@ -518,17 +458,6 @@ void ivas_mct_dec_close( MCT_DEC_HANDLE *hMCT /* i/o: MCT decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_corecoder_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nSCE_old, /* i : number of SCEs in previous frame */ - Word16 nCPE_old, /* i : number of CPEs in previous frame */ - const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ - const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ - const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ - const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ -); -#endif ivas_error ivas_corecoder_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSCE_old, /* i : number of SCEs in previous frame */ @@ -538,12 +467,6 @@ ivas_error ivas_corecoder_dec_reconfig( const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */ const int32_t brate_CPE /* i : bitrate to be set for the CPEs */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_hp20_dec_reconfig_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nchan_hp20_old /* i : number of HP20 filters in previous frame*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_hp20_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -574,11 +497,7 @@ ivas_error ivas_mct_dec( ); /*! r: number of channels to be synthesised */ -#ifdef IVAS_FLOAT_FIXED -Word16 getNumChanSynthesis( - Decoder_Struct *st_ivas /* i : IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t getNumChanSynthesis( Decoder_Struct *st_ivas /* i : IVAS decoder structure */ ); @@ -597,10 +516,6 @@ void destroy_core_dec( void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#else -void ivas_destroy_dec_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); #endif void ivas_initialize_handles_dec( @@ -634,19 +549,7 @@ ivas_error ivas_core_enc( const int16_t ivas_format, /* i : IVAS format */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_core_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const int16_t n_channels, /* i : number of channels to be decoded */ - Word32 *output_fx[], /* o : output synthesis signal */ - Word32 outputHB[][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 */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_core_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -693,22 +596,6 @@ void decod_gen_2sbfr( const float tdm_Pri_pitch_buf[] /* i : pitch values for primary channel */ ); -#ifdef IVAS_FLOAT_FIXED -void decod_gen_2sbfr_ivas_fx( - Decoder_State *st, /* i/o: decoder static memory */ - const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ - const Word16 *Aq, /* i : LP filter coefficient Q12*/ - Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ - const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ -); -#endif - void synchro_synthesis( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -758,6 +645,19 @@ void stereo_tcx_core_dec( ); #endif // !IVAS_FLOAT_FIXED +void stereo_tcx_core_enc( + Encoder_State *st, /* i/o: encoder state structure */ + const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ + const float new_samples_16k[], /* i : buffer of input signal @16 kHz */ + const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ + float lsp_new[], /* i : LSPs at the end of the frame, Q15 */ + float lsp_mid[], /* i : LSPs in the middle of the frame, Q15 */ + Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ + const Word16 last_element_mode, /* i : last element mode, Q0 */ + const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ +); + + void stereo_tcx_init_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -779,27 +679,7 @@ int16_t ivas_smc_gmm( int16_t *high_lpn_flag, /* i/o: sp/mus LPN flag */ const int16_t flag_spitch /* i : flag to indicate very short stable pitch */ ); -#ifdef IVAS_FLOAT_FIXED -/*! r: S/M decision (0=speech or noise,1=unclear,2=music) */ -Word16 ivas_smc_gmm_fx( - Encoder_State *st, /* i/o: state structure */ - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ - const Word16 Etot_fx, /* i : total frame energy */ - Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ - Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ - Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ - Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ - const Word16 non_sta_fx, /* i : unbound non-stationarity */ - const Word16 relE_fx, /* i : relative frame energy */ - Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ - const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ - , - Word16 Qfact_PS, - Word16 Q_esp, - Word16 Qfact_PS_past -); -#endif + void ivas_smc_mode_selection( Encoder_State *st, /* i/o: encoder state structure */ const int32_t element_brate, /* i : element bitrate */ @@ -835,26 +715,9 @@ void ivas_decision_matrix_enc( const float enerBuffer[], /* i : energy buffer */ const int16_t last_element_mode /* i : last element mode */ ); -#else -void ivas_decision_matrix_enc_fx( - Encoder_State *st, /* i : encoder state structure */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 fft_buff[], /* i : FFT buffer */ - const Word32 enerBuffer[], /* i : energy buffer */ - Word16 enerBuffer_exp, - const Word16 last_element_mode /* i : last element mode */ -); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_signaling_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 element_brate, /* i : element bitrate */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_signaling_enc( Encoder_State *st, /* i/o: encoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -964,20 +827,12 @@ void smooth_dft2td_transition( const int16_t output_frame /* i : output frame length */ ); -void smooth_dft2td_transition_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ - const Word16 output_frame /* i : output frame lenght Q0*/ -); + /*! r: flag indicating a valid bitrate */ int16_t is_IVAS_bitrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); -Word16 is_IVAS_bitrate_fx( - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - int16_t is_DTXrate( const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); @@ -1002,35 +857,7 @@ void ivas_imdft( float *pOut, /* o : output time-domain signal */ const int16_t length /* i : signal length */ ); -#ifdef IVAS_FLOAT_FIXED -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 Word16 length, /* i : signal length */ - const Word16 mdft_length /* i : MDFT length */ -); -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 Word16 length /* i : signal length */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -void TonalMdctConceal_create_concealment_noise_ivas_fx( - Word32 concealment_noise[L_FRAME48k], - Word16 *concealment_noise_exp, - CPE_DEC_HANDLE hCPE, - const Word16 L_frameTCX, - const Word16 L_frame, - const Word16 idchan, - const Word16 subframe_idx, - const Word16 core, - const Word16 crossfade_gain, - const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode); -#endif void TonalMdctConceal_create_concealment_noise_ivas( float concealment_noise[L_FRAME48k], CPE_DEC_HANDLE hCPE, @@ -1061,16 +888,6 @@ int16_t get_igf_startline_flt( float rand_triangular_signed( int16_t *seed ); -#ifdef IVAS_FLOAT_FIXED -Word16 rand_triangular_signed_fx( - Word16 *seed, - Word16 *exp_fac); -#endif -Word64 var_32_fx( - const Word32 *x, /* i : input vector */ - const Word16 len, /* i : length of inputvector */ - Word16 q /* q : q-factor for the array */ -); void dtx_read_padding_bits( DEC_CORE_HANDLE st, @@ -1090,17 +907,13 @@ void ivas_apply_non_diegetic_panning( * JBM prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *data_fx -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *data /* o : output synthesis signals */ ); #endif + #ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1110,19 +923,6 @@ ivas_error ivas_jbm_dec_render( int16_t *data /* o : output synthesis signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_flush_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 tc_granularity_new, /* i : new renderer granularity */ - const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ - const AUDIO_CONFIG intern_config_old, /* i : old internal config */ - const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ - const MC_MODE mc_mode_old, /* i : old MC mode */ - const ISM_MODE ism_mode_old, /* i : old ISM mode */ - UWord16 *nSamplesRendered, /* o : number of samples flushed */ - Word16 *data /* o : output synthesis signal */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1142,19 +942,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ float *data /* i/o: transport channels/output synthesis signal */ ); -void ivas_jbm_dec_feed_tc_to_renderer_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ - Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - Word32 *data /* i/o: transport channels/output synthesis signal */ -); - -void ivas_jbm_dec_feed_tc_to_renderer_fx( - 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*/ - Word32 *data /* i/o: transport channels/output synthesis signal */ -); ivas_error ivas_jbm_dec_set_discard_samples( Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ @@ -1166,13 +953,7 @@ void ivas_jbm_dec_get_adapted_linear_interpolator( float *interpolator /* o : the interpolator */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_adapted_subframes( - 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 */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_adapted_subframes( const int16_t nCldfbTs, /* i : number of time slots in the current frame */ int16_t *subframe_nbslots, /* i/o: subframe grid */ @@ -1180,16 +961,7 @@ void ivas_jbm_dec_get_adapted_subframes( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_md_map( - const Word16 default_len, /* i : default frame length in metadata slots */ - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_md_map( const int16_t default_len, /* i : default frame length in metadata slots */ const int16_t len, /* i : length of the modfied frames in metadata slots */ @@ -1210,15 +982,7 @@ void ivas_jbm_dec_copy_tc_no_tsm( const int16_t output_frame /* i : output frame size */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_get_md_map_even_spacing( - const Word16 len, /* i : length of the modfied frames in metadata slots */ - const Word16 subframe_len, /* i : default length of a subframe */ - const Word16 offset, /* i : current read offset into the md buffer */ - const Word16 buf_len, /* i : length of the metadata buffer */ - Word16 *map /* o : metadata index map */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_jbm_dec_get_md_map_even_spacing( const int16_t len, /* i : length of the modfied frames in metadata slots */ const int16_t subframe_len, /* i : default length of a subframe */ @@ -1295,9 +1059,9 @@ ivas_error ivas_ism_config( #ifdef IVAS_FLOAT_FIXED void bitbudget_to_brate( - const Word16 x[], /* i : bitbudgets */ - Word32 y[], /* o : bitrates */ - const Word16 N /* i : number of entries to be converted */ + const Word16 x[], /* i : bitbudgets Q0 */ + Word32 y[], /* o : bitrates Q0 */ + const Word16 N /* i : number of entries to be converted */ ); #else void bitbudget_to_brate( @@ -1321,12 +1085,12 @@ void ivas_ism_reset_metadata_API( /*! r: index of the winning codeword */ #ifdef IVAS_FLOAT_FIXED Word16 ism_quant_meta_fx( - const Word32 val, /* i : scalar value to quantize */ - Word32 *valQ, /* o : quantized value */ - 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 Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ ); #endif @@ -1348,17 +1112,7 @@ float ism_dequant_meta( const int16_t cbsize /* i : codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_set_ism_metadata_fx( - ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ - const Word32 azimuth, /* i : azimuth value */ - const Word32 elevation, /* i : elevation value */ - const Word16 radius_meta, /* i : radius */ - const Word32 yaw, /* i : yaw */ - const Word32 pitch, /* i : pitch */ - const Word16 non_diegetic_flag /* i : non-diegetic object flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ @@ -1389,25 +1143,7 @@ ivas_error ivas_ism_enc( const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_ism_metadata_enc( - Word32 *ism_total_brate, /* i/o: ISM total bitrate */ - const Word16 nchan_ism, /* i : number of ISM channels */ - const Word16 nchan_transport, /* i : number of transport channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ - Word16 nb_bits_metadata[], /* o : number of metadata bits */ - const Word16 localVAD[], /* i : VAD flag */ - const Word16 ism_mode, /* i : ISM mode */ - const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ - const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ - const Word16 lp_noise_CPE, /* i : LP filtered total noise estimation */ - const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ - Word16 *omasa_stereo_sw_cnt, - const Word16 ini_frame -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc( int32_t *ism_total_brate, /* i/o: ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -1492,15 +1228,8 @@ void ivas_param_ism_config( ivas_error ivas_ism_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -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 */ - UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ - Word16 *data /* o : output synthesis signal */ -); -#else +#ifndef IVAS_FLOAT_FIXED 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 */ @@ -1509,23 +1238,13 @@ ivas_error ivas_ism_dec_config( ); #endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_ism_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_param_ism_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_close_fx( - PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ - SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ - const AUDIO_CONFIG output_config /* i : output audio configuration */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_dec_close( PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ @@ -1538,23 +1257,11 @@ void ivas_param_ism_dec( float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dec_digest_tc_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif void ivas_ism_dec_digest_tc( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_digest_tc_fx( - 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 */ - Word16 q_tc_in -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_param_ism_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ @@ -1579,19 +1286,6 @@ void ivas_param_ism_dec_render( float *output_f[] /* o : rendered time signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_ism_dec_render_fx( - 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 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[] -); -void ivas_param_ism_params_to_masa_param_mapping_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif - void ivas_param_ism_params_to_masa_param_mapping( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); @@ -1604,19 +1298,6 @@ void ivas_param_ism_params_to_masa_param_mapping( ivas_error ivas_ism_dtx_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_ism_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nchan_ism, /* i : number of objects */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - Word16 md_diff_flag[], /* o : metadata differential flag */ - Word16 *sid_flag /* o : indication of SID frame */ -); -#endif // IVAS_FLOAT_FIXED /*! r: indication of DTX frame */ int16_t ivas_ism_dtx_enc( @@ -1630,12 +1311,6 @@ int16_t ivas_ism_dtx_enc( int16_t md_diff_flag[], /* o : metadata differential flag */ int16_t *sid_flag /* o : indication of SID frame */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dtx_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 *nb_bits_metadata /* o : number of metadata bits */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_dtx_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1667,14 +1342,6 @@ void ivas_ism_metadata_sid_dec( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ int16_t nb_bits_metadata[] /* o : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_get_sce_id_dtx_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length per channel */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_get_sce_id_dtx( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ @@ -1687,14 +1354,6 @@ void ivas_param_ism_compute_noisy_speech_flag( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_coh_estim_dtx_enc_fx( - ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 input_frame /* i : input frame length */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_coh_estim_dtx_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ @@ -1717,14 +1376,6 @@ void ivas_get_ism_sid_quan_bitbudget( int16_t *nBits_coh, /* o : number of Q bits for coherence */ int16_t *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( - SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ - const Word16 sce_id_dtx, /* i : SCE DTX ID */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *Q_cngNoiseLevel -); -#endif // IVAS_FLOAT_FIXED void ivas_ism_dtx_limit_noise_energy_for_near_silence( SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ @@ -1742,34 +1393,15 @@ ivas_error stereo_dft_enc_create( const int16_t max_bwidth /* i : maximum encoded bandwidth */ ); -ivas_error stereo_dft_enc_create_fx( - STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ -); - void stereo_dft_enc_reset( STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ ); -void stereo_dft_enc_reset_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ -); - void stereo_enc_itd_init( ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ ); -void stereo_enc_itd_init_fx( - ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ -); - -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_enc_update_fx( - STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ - const Word16 max_bwidth /* i : maximum encoded bandwidth */ -); -#else +#ifndef IVAS_FLOAT_FIXED void stereo_dft_enc_update( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder DFT stereo handle */ const int16_t max_bwidth /* i : maximum encoded bandwidth */ @@ -1840,16 +1472,6 @@ void stereo_dft_cng_side_gain( const int16_t bwidth /* i : audio band-width */ ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_quantize_res_gains_fx( - const Word32 *g, //Q31 - const Word32 *r, //Q31 - Word32 *gq, //Q31 - Word32 *rq, //Q31 - Word16 *ig, - Word16 *ir); -#endif - void stereo_dft_quantize_res_gains( const float *g, const float *r, @@ -1858,13 +1480,6 @@ void stereo_dft_quantize_res_gains( int16_t *ig, int16_t *ir ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dequantize_itd_fx( - Word16 *ind, /* Q0 */ - Word32 *out, /* Q15 */ - const Word32 output_Fs /* Q0 */ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dequantize_itd( int16_t *ind, @@ -1891,14 +1506,6 @@ void stereo_dft_enc_sid_coh( float *cohBand /* i/o: Coherence per band */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dec_sid_coh_fx( - Decoder_State *st, /* i/o: decoder state structure */ - const Word16 nbands, /* i : number of DFT stereo bands Q0*/ - Word16 *coh, /* i/o: coherence Q15*/ - Word16 *nb_bits /* i/o: number of bits read Q0*/ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dec_sid_coh( Decoder_State *st, /* i/o: decoder state structure */ @@ -2009,11 +1616,6 @@ float stereo_dft_dmx_swb_nrg( const int16_t frame_length /* i : frame lanegth */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 stereo_dft_sg_recovery_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ -); -#endif int16_t stereo_dft_sg_recovery( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ ); @@ -2031,33 +1633,12 @@ int16_t res_bpf_adapt( const float *bpf_error_signal_8k, /* i : BPF modification signal */ float res_buf[STEREO_DFT_N_8k] /* i : residual buffer */ ); -#else // IVAS_FLOAT_FIXED -Word16 res_bpf_adapt_ivas_fx( - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ - const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */ - Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q_res */ - Word16 q_res -); #endif + void bpf_pitch_coherence( Decoder_State *st, /* i/o: decoder state structure */ const float pitch_buf[] /* i : pitch for each subframe [0,1,2,3] */ ); -#ifdef IVAS_FLOAT_FIXED -void stereo_dft_dec_read_BS_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ - const Word32 element_brate, /* i : element bitrate Q0*/ - Word32 *total_brate, /* o : total bitrate Q0*/ - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ - const Word16 bwidth, /* i : bandwidth Q0*/ - const Word16 output_frame, /* i : output frame length Q0*/ - Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ - Word16 *nb_bits, /* o : number of bits read Q0*/ - Word16 *coh_fx, /* i/o: Coherence Q15*/ - const Word16 ivas_format /* i : ivas format Q0*/ -); -#endif // IVAS_FLOAT_FIXED void stereo_dft_dec_read_BS( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -2117,16 +1698,7 @@ void filter_with_allpass( ); /*! r: used GR order */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_bitstream_adapt_GR( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : values to be written in bitstream */ - const Word16 len, /* i : values vector length */ - const Word16 GR_ord, /* i : GR order to be used */ - const Word16 no_GR_ord /* i : speech/music 0/1 */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_bitstream_adapt_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t Indice, /* i : identifier for bitstream index */ @@ -2138,24 +1710,7 @@ int16_t write_bitstream_adapt_GR( #endif /*! r: used GR order */ -#ifdef IVAS_FLOAT_FIXED -Word16 adapt_GR_ief_fx( - const Word16 *in, /* i : vector to encode */ - Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ - const Word16 *prev, /* i : previous frame data */ - const Word16 len, /* i : input vector length */ - const Word16 no_symb, /* i : number of symbols */ - Word16 *nbits, /* o : number of used bits */ - Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ - const Word16 *map0, /* i : mapping array */ - const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ - Word16 *nbits_diff, /* o : number bits in diff encoding */ - const Word16 side_gain_counter, /* i : number of frames since last abs coding */ - Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ - Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ - const Word16 try_diff /* i : diff coding allowed 1/0 */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t adapt_GR_ief( const int16_t *in, /* i : vector to encode */ int16_t *in_diff, /* o : encoded symbols in case of differential encoding */ @@ -2173,21 +1728,7 @@ int16_t adapt_GR_ief( ); #endif -#ifdef IVAS_FLOAT_FIXED -Word16 adapt_GR_rpg1_ief( - const Word16 *in, /* i : res pred gains input vector */ - Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ - const Word16 *prev, /* i : previous frame data */ - const Word16 len, /* i : input vector length */ - const Word16 no_symb, /* i : number of symbols */ - Word16 *nbits, /* o : number of used bits */ - Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ - const Word16 *maps, /* i : mapping array */ - Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ - const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ - const Word16 try_diff /* i : diff coding allowed 1/0 */ -); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: used GR order */ int16_t adapt_GR_rpg1_ief( const int16_t *in, /* i : res pred gains input vector */ @@ -2205,14 +1746,7 @@ int16_t adapt_GR_rpg1_ief( #endif /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_GR1( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : data to be encoded */ - const Word16 len /* i : input data length */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_GR1( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -2222,15 +1756,7 @@ int16_t write_GR1( #endif /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_bitstream_GR( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : input vector */ - const Word16 len, /* i : input vector length */ - const Word16 GR_ord /* i : GR order */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_bitstream_GR( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -2289,12 +1815,6 @@ int16_t read_BS_adapt_GR_sg( ); #endif -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 */ -); - void stereo_dft_enc_compute_itd( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ float *DFT_L, @@ -2396,11 +1916,6 @@ void rc_uni_dec_init( uint16_t *bit_buffer, /* i : Bit buffer */ const int16_t max_available_bits /* i : Total maximum bits available */ ); -void rc_uni_dec_init_fx( - RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ - UWord16 *bit_buffer, /* i : Bit buffer */ - const Word16 max_available_bits /* i : Total maximum bits available */ -); /*! r: Read symbol */ uint16_t rc_uni_dec_read_symbol_fastS( @@ -2410,14 +1925,6 @@ uint16_t rc_uni_dec_read_symbol_fastS( const uint16_t alphabet_size, /* i : Number of symbols in the alphabet */ const uint16_t tot_shift /* i : Total frequency as a power of 2 */ ); -/*! r: Read symbol */ -UWord16 rc_uni_dec_read_symbol_fastS_fx( - RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ - const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ - const UWord16 sym_freq_table[], /* i : Symbol frequency */ - const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ - const UWord16 tot_shift /* i : Total frequency as a power of 2 */ -); /*! r: Read bit */ uint16_t rc_uni_dec_read_bit( @@ -2442,9 +1949,6 @@ int16_t rc_uni_dec_virtual_finish( RangeUniDecState *rc_st_dec /* i/o: RC state handle */ ); -Word16 rc_uni_dec_virtual_finish_fx( - RangeUniDecState *rc_st_dec /* i/o: RC state handle */ -); /*! r: Total number of bits consumed */ int16_t rc_uni_dec_finish( RangeUniDecState *rc_st_dec /* i/o: RC state handle */ @@ -2519,11 +2023,6 @@ void stereo_tca_init_enc( const int32_t input_Fs /* i : input sampling frequency */ ); -void stereo_tca_init_enc_fx( - STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ - const Word32 input_Fs /* i : input sampling frequency */ -); - void stereo_tca_enc( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : length of a frame per channel */ @@ -2539,24 +2038,12 @@ void stereo_tca_dec( const int16_t output_frame /* i : length of a frame per channel */ ); -void stereo_tca_dec_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ - const Word16 output_frame /* i : length of a frame per channel Q0*/ -); - void stereo_tca_scale_R_channel( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *output, /* i/o: output synthesis, R channel */ const int16_t output_frame /* i : frame length */ ); -void stereo_tca_scale_R_channel_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ - const Word16 output_frame /* i : frame length Q0*/ -); - void adjustTargetSignal( float *target, const int16_t prevShift, @@ -2565,12 +2052,6 @@ void adjustTargetSignal( const int16_t method ); -void adjustTargetSignal_fx( - Word32 *target_fx, - const Word16 prevShift, - const Word16 currShift, - const Word16 L_shift_adapt, - const Word16 method); /*----------------------------------------------------------------------------------* * IC-BWE Stereo prototypes *----------------------------------------------------------------------------------*/ @@ -2579,10 +2060,6 @@ void stereo_icBWE_init_enc( STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ ); -void stereo_icBWE_init_enc_fx( - STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ -); - void spectral_balancer( float *signal, float *mem, @@ -2640,10 +2117,6 @@ int16_t select_stereo_mode( void stereo_classifier_init( STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ ); -#else -void stereo_classifier_init_fx( - STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ -); #endif void stereo_classifier_features( @@ -2661,11 +2134,7 @@ void stereo_classifier_features( const int16_t clas /* i : signal class */ ); -#ifdef IVAS_FLOAT_FIXED -void unclr_classifier_dft_fx( - CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED void unclr_classifier_dft( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); @@ -2675,13 +2144,7 @@ void unclr_classifier_td( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void xtalk_classifier_dft_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word16 itd, /* i : ITD from DFT stereo - used as a feature */ - const Word32 gcc_phat[] /* i : GPHAT cross-channel correlation function Q31*/ -); -#endif + void xtalk_classifier_dft( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const int16_t itd, /* i : ITD from DFT stereo - used as a feature */ @@ -2702,35 +2165,19 @@ void stereo_td_init_enc( const int16_t last_element_mode /* i : last element mode */ ); -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 */ -); #ifndef IVAS_FLOAT_FIXED ivas_error stereo_set_tdm( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int16_t input_frame /* i : input frame length per channel */ ); -#else -ivas_error stereo_set_tdm_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word16 input_frame, /* i : input frame length per channel */ - Word16 input_q -); #endif + #ifndef IVAS_FLOAT_FIXED void stereo_tdm_prep_dwnmx ( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float *input1, /* i : right channel input */ const int16_t input_frame /* i : frame lenght */ ); -#else -void stereo_tdm_prep_dwnmx_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const Word32 *input1, /* i : right channel input */ - const Word16 input_frame, /* i : frame lenght */ - const Word16 input_q /* i : frame lenght */ -); #endif #ifndef IVAS_FLOAT_FIXED @@ -2757,11 +2204,6 @@ void stereo_td_init_dec( const int16_t last_element_mode /* i : last element mode */ ); -void stereo_td_init_dec_fx( - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const Word16 last_element_mode /* i : last element mode Q0*/ -); - void tdm_configure_dec( const int16_t ivas_format, /* i : IVAS format */ const int16_t ism_mode, /* i : ISM mode in combined format */ @@ -2782,18 +2224,6 @@ void tdm_upmix_plain( const int16_t plus_minus_flag /* i : plus/minus flag */ ); -void tdm_upmix_plain_fx( - Word32 Left_fx[], /* o : left channel Qx*/ - Word32 Right_fx[], /* o : right channel Qx*/ - const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ - const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ - const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ - const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ - const Word16 start_index, /* i : start index Q0*/ - const Word16 end_index, /* i : end index Q0*/ - const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ -); - void stereo_tdm_combine( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float *PCh_2_L, /* i/o: Primary channel -> output as L channel */ @@ -2803,29 +2233,7 @@ void stereo_tdm_combine( const int16_t tdm_ratio_idx /* i : TDM ratio index */ ); -void stereo_tdm_combine_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ - Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ - const Word16 output_frame, /* i : Number of samples Q0*/ - const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ -); -#ifdef IVAS_FLOAT_FIXED -Word16 tdm_lp_comparison_fx( - STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ - STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ - Encoder_State *st, /* i/o: Encoder structure */ - Word32 *speech_buff, /* i : Current speech frame Q_speech */ - const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ - const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ - const Word16 m, /* i : filter length */ - const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ - const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ - const Word16 L_frame, /* i : frame length */ - const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ - Word16 Q_speech ); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: replication decision; 1 = Use old LP */ int16_t tdm_lp_comparison( STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ @@ -2860,13 +2268,7 @@ void tdm_configure_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error signaling_enc_secondary_fx( - Encoder_State *st, /* i/o: Encoder structure */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ - const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error signaling_enc_secondary( Encoder_State *st, /* i/o: Encoder structure */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ @@ -2932,21 +2334,6 @@ void tdm_low_rate_enc( const float *lsf_new, /* i : current frame ISF vector */ float *tmp_noise /* o : long-term noise energy */ ); -#else -void tdm_low_rate_enc( - Encoder_State *st, /* i/o: State structure */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ // Q_new - Word16 *synth, /* i/o: core synthesis */ // Q_new - Word16 *exc_fx, /* 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_fx, /* o : excitation for SWB TBE */ // Q_new - const Word16 attack_flag, /* i : attck flag */ - const Word16 *lsf_new, /* i : current frame ISF vector */ // x2.56 - Word16 *tmp_noise, /* o : long-term noise energy */ // Q8 - Word16 *Q_new -); #endif /*! r: value of the indice */ @@ -2957,19 +2344,6 @@ uint16_t get_indice_st( const int16_t nb_bits /* i : number of bits to quantize the indice */ ); -#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 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ - Word16 *voice_factors, /* o : voicing factors Q15*/ - Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ - Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ - Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ - const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ -); -#endif - void tdm_low_rate_dec( Decoder_State *st, /* i/o: decoder static memory */ float dct_epit[], /* o : GSC excitation in DCT domain */ @@ -2981,30 +2355,14 @@ void tdm_low_rate_dec( float *bwe_exc, /* o : excitation for SWB TBE */ const float *lsf_new /* i : ISFs at the end of the frame */ ); -#ifdef IVAS_FLOAT_FIXED -void tdm_SCh_LSF_intra_pred_fx( - const Word32 element_brate, /* i : element bitrate */ - const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ - Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ -); -#endif + void tdm_SCh_LSF_intra_pred( const int32_t element_brate, /* i : element bitrate */ const float *tdm_lsfQ_PCh, /* i : primary channel LSFs */ float *pred_lsf_SCh /* o : predicted secondary channel LSFs */ ); -#ifdef IVAS_FLOAT_FIXED -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 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 */ -); -#else +#ifndef IVAS_FLOAT_FIXED void tdm_SCh_lsf_reuse( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t element_brate, /* i : element bitrate */ @@ -3076,21 +2434,7 @@ void QuantizeTCXSpectrum( float *gain_tcx, /* o : global gain */ int16_t prm[] /* o : tcx parameters */ ); -#ifdef IVAS_FLOAT_FIXED -void EstimateStereoTCXNoiseLevel_fx( - Encoder_State **sts, /* i : state handle */ - Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ - Word16 gain_tcx[][NB_DIV], /* i : global gain */ - Word16 gain_tcx_e, /* i : global gain exponent */ - Word16 L_frame[][NB_DIV], /* i : frame length */ - Word16 noiseFillingBorder[][NB_DIV], /* i : noise filling border */ - Word16 hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ - const Word16 ignore_chan[], /* i : flag indicating whether the channel should be ignored */ - Word16 fac_ns[][NB_DIV], /* o : noise filling level */ - Word16 param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ - const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ -); -#endif + void EstimateStereoTCXNoiseLevel( Encoder_State **sts, /* i : state handle */ float *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ @@ -3113,17 +2457,7 @@ void TNSAnalysisStereo( int16_t param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ const int16_t mct_on /* i : flag mct block (1) or stereo (0) */ ); -#ifdef IVAS_FLOAT_FIXED -void TNSAnalysisStereo_fx( - Encoder_State **sts, /* i : encoder state handle */ - Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/ - const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/ - Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/ - Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/ - Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/ - const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/ -); -#endif + void InternalTCXDecoder( Encoder_State *st, /* i/o: state handle */ const int16_t frame_cnt, /* i : frame counter in the super_frame */ @@ -3164,17 +2498,6 @@ void initMdctStereoEncData( const int16_t mem_init /* i : initialize memory after malloc */ ); -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 */ -); - ivas_error initMdctItdHandling( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const int32_t input_Fs /* i : input sampling rate */ @@ -3209,15 +2532,6 @@ void stereo_mdct_init_igf_start_band( const int32_t element_brate /* i : element bitrate */ ); -#ifdef IVAS_FLOAT_FIXED -void init_tcx_enc_info_fx( - Encoder_State *st, /* i/o: coder memory state */ - Word16 *L_frame, - Word16 *L_frameTCX, - Word16 *L_spec -); -#endif - void init_tcx_enc_info( Encoder_State *st, /* i : coder memory state */ int16_t *L_frame, @@ -3409,12 +2723,6 @@ void SetCurrentPsychParams( const int16_t last_frame_was_concealed_cng, TCX_CONFIG_HANDLE hTcxCfg ); -#else -void SetCurrentPsychParams( - const Word16 core, - const Word16 last_frame_was_concealed_cng, - TCX_CONFIG_HANDLE hTcxCfg -); #endif void stereo_coder_tcx( @@ -3543,32 +2851,7 @@ void dequantize_sns( float snsQ_out[CPE_CHANNELS][NB_DIV][M], Decoder_State **sts ); -#ifdef IVAS_FLOAT_FIXED -void sns_avq_cod_fx( - const Word32 *sns_fx, /* i : Input sns vectors */ - Word16 exp_sns, - const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ - Word16 exp_snsmid, - Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ - Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ - Word16 *index, /* o : Quantization indices */ - const Word16 core, /* i : core */ - const Word16 L_frame, - const Word16 low_brate_mode /* i : flag low bit operating mode */ -); - -void sns_avq_cod_stereo_fx( - const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ - Word16 exp_snl, - const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ - Word16 exp_snr, - const Word16 L_frame, - Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ - Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ - Word16 *indexl, /* o : Quantization indices (left channel) */ - Word16 *indexr /* o : Quantization indices (right channel) */ -); -#else +#ifndef IVAS_FLOAT_FIXED void sns_avq_cod( const float *sns, /* i : Input sns vectors */ const float *snsmid, /* i : Input mid-sns vectors */ @@ -3632,11 +2915,6 @@ void FdCngEncodeMDCTStereoSID( void FdCngDecodeMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error initMdctStereoDtxData_fx( - CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ -); -#endif // IVAS_FLOAT_FIXED ivas_error initMdctStereoDtxData( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder handle */ @@ -3660,13 +2938,6 @@ void applyDmxMdctStereo( const int16_t output_frame /* i : output frame length */ ); -void applyDmxMdctStereo_fx( - const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ - Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ - const Word16 output_frame /* i : output frame length Q0*/ -); - - /*----------------------------------------------------------------------------------* * Front-VAD prototypes *----------------------------------------------------------------------------------*/ @@ -3676,19 +2947,9 @@ ivas_error front_vad_create( const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ); -ivas_error front_vad_create_fx( - FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ -); - void front_vad_destroy( FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ ); -#ifdef IVAS_FLOAT_FIXED -void front_vad_destroy_fx( - FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ -); -#endif ivas_error front_vad( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ @@ -3707,28 +2968,7 @@ ivas_error front_vad( float *PS_out, /* o : energy spectrum */ float *Bin_E_out /* o : log-energy spectrum of the current frame*/ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error front_vad_fx( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ - Encoder_State * st, /* i/o: encoder state structure */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word16 input_frame, /* i : frame length */ - Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ - Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands Q_buffer[n] + QSCALE + 2 */ - Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8 */ - Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels Q_buffer[n] + QSCALE */ - Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ - Word16 vad_hover_flag[], /* o : VAD hangover flag */ - Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN Q_buffer[1] + QSCALE + 2 - band_ener_guardbits*/ - Word32 *PS_out_fx, /* o : energy spectrum Q_buffer + QSCALE */ - Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7 */ - Word16 Q_inp, - Word16 *Q_buffer, - Word16 Q_add, - Word16 *front_create_flag ); -#endif + ivas_error front_vad_spar( SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder structure */ const float *omni_in, /* i : omnidirectional input signal */ @@ -3777,12 +3017,7 @@ void stereo_cna_update_params( const int16_t output_frame, /* i : Output frame length */ const int16_t tdm_ratio_idx /* i : TDM ratio index */ ); -void stereo_cna_update_params_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ - const Word16 output_frame, /* i : Output frame length Q0*/ - const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ -); + void dtx_enc_init( Encoder_State *st, /* i : Encoder state handle */ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ @@ -3802,23 +3037,6 @@ void mvr2r_inc( const int16_t n /* i : vector size */ ); -#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 */ -); - -void mvr2r_inc_fixed( - const Word32 x_fx[], /* i : input vector */ - const int16_t x_inc, /* i : increment for vector x[] */ - Word32 y_fx[], /* o : output vector */ - const int16_t y_inc, /* i : increment for vector y[] */ - const int16_t n /* i : vector size */ -); -#endif void v_add_inc( const float x1[], /* i : Input vector 1 */ const int16_t x_inc, /* i : Increment for input vector 1 */ @@ -3829,45 +3047,6 @@ void v_add_inc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_mult_inc_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ - Word16 *x1_q_fx, - const Word16 x1_inc, /* i : Increment for input vector 1 */ - const Word32 x2_fx[], /* i : Input vector 2 */ - Word16 *x2_q_fx, - const Word16 x2_inc, /* i : Increment for input vector 1 */ - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 *y_q_fx, - const Word16 y_inc, /* i : increment for vector y[i] */ - const Word16 N /* i : Vector length */ -); - -void v_add_inc_fx( - 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 */ -); -Word32 logsumexp_fx( - const Word32 x[], /* i : input array x */ - const Word16 x_e, - const Word16 N /* i : number of elements in array x */ -); -Word32 lin_interp32_fx( - const Word32 x, /* i : the value to be mapped */ - const Word32 x1, /* i : source range interval: low end */ - const Word32 y1, /* i : source range interval: high end */ - const Word32 x2, /* i : target range interval: low */ - const Word32 y2, /* i : target range interval: high */ - const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ - Word16 *Q_io /*i/o : i/o Q factor of the output*/ -); -#endif - void v_mult_inc( const float x1[], /* i : Input vector 1 */ const int16_t x1_inc, /* i : Increment for input vector 1 */ @@ -3878,21 +3057,6 @@ void v_mult_inc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_addc_fx( - const Word32 x_fx[], /* i : Input vector */ - const Word32 c_fx, /* i : Constant */ - Word32 y_fx[], /* o : Output vector that contains c*x */ - const Word16 N /* i : Vector length */ -); -#endif - -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 */ -); void v_addc( const float x[], /* i : Input vector */ const float c, /* i : Constant */ @@ -3900,28 +3064,6 @@ void v_addc( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_min_fx( - const Word32 x1_fx[], /* i : Input vector 1 */ - Word16 *x1_q_fx, - const Word32 x2_fx[], /* i : Input vector 2 */ - Word16 *x2_q_fx, - Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ - Word16 *y_q_fx, - const Word16 N /* i : Vector length */ -); - -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 */ -); -#endif - void v_min( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -3929,15 +3071,6 @@ void v_min( const int16_t N /* i : Vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_sqrt_fx( - const Word32 x[], /* i : Input vector */ - Word16 exp[], - Word32 y[], /* o : Output vector that contains sqrt(x) */ - const Word16 N /* i : Vector length */ -); -#endif - void v_sqrt( const float x[], /* i : Input vector */ float y[], /* o : Output vector that contains sqrt(x) */ @@ -3950,13 +3083,6 @@ float sumAbs( const int16_t lvec /* i : length of input vector */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 sumAbs_fx( - const Word32 *vec, /* i : input vector */ - const Word16 lvec /* i : length of input vector */ -); -#endif - void mvc2c( const uint8_t x[], /* i : input vector */ uint8_t y[], /* o : output vector */ @@ -3970,42 +3096,6 @@ float dot_product_cholesky( const int16_t N /* i : vector & matrix size */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 dot_product_cholesky_fx( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N /* i : vector & matrix size */ -); -Word32 dot_product_cholesky_fixed( - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : Cholesky matrix A */ - const Word16 N, /* i : vector & matrix size */ - const Word16 exp_x, - const Word16 exp_A, - Word16 *exp_sum ); -#endif - -#ifdef IVAS_FLOAT_FIXED -void v_mult_mat_fx( - Word32 *y_fx, /* o : the product x*A */ - Word16 *y_q_fx, - const Word32 *x_fx, /* i : vector x */ - Word16 *x_q_fx, - const Word32 *A_fx, /* i : matrix A */ - Word16 *A_q_fx, - const Word16 N, /* i : number of rows */ - const Word16 C /* i : number of columns */ -); -void v_mult_mat_fixed( - Word32 *y, /* o : the product x*A */ - const Word32 *x, /* i : vector x */ - const Word32 *A, /* i : matrix A */ - const Word16 Nr, /* i : number of rows */ - const Word16 Nc, /* i : number of columns */ - Word16 guardbits -); -#endif - void v_mult_mat( float *y, /* o : the product x*A */ const float *x, /* i : vector x */ @@ -4044,29 +3134,7 @@ int16_t check_bounds_s( const int16_t high /* i : High limit */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 check_bounds_s_fx( - const Word16 value, /* i : Input value */ - const Word16 low, /* i : Low limit */ - const Word16 high /* i : High limit */ -); -#endif - -Word32 check_bounds_l( - const Word32 value, /* i : Input value */ - const Word32 low, /* i : Low limit */ - const Word32 high /* i : High limit */ -); -#ifdef IVAS_FLOAT_FIXED -ivas_error stereo_memory_enc_fx( - CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t max_bwidth, /* i : maximum audio bandwidth */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t nchan_transport /* i : number transport chans */ - -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error stereo_memory_enc( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const int32_t input_Fs, /* i : input sampling rate */ @@ -4087,20 +3155,15 @@ ivas_error stereo_memory_dec( const MC_MODE mc_mode, /* i : MC mode */ const int16_t nchan_transport /* i : number of transport channels */ ); -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void stereo_switching_enc_fx( CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ Word16 old_input_signal_pri[], /* i : old input signal of primary channel */ const Word16 input_frame, /* i : input frame length */ const Word16 q_inp ); -#else -void stereo_switching_enc( - CPE_ENC_HANDLE hCPE, /* i : CPE structure */ - float old_input_signal_pri[], /* i : old input signal of primary channel */ - const int16_t input_frame /* i : input frame length */ -); #endif + void stereo_switching_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 ivas_total_brate /* i : IVAS total bitrate Q0*/ @@ -4115,34 +3178,15 @@ void stereo_td2dft_update( const int16_t output_frame /* i : frame length */ ); -void stereo_td2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - const Word16 n, /* i : channel number Q0*/ - Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ - Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ - Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ - const Word16 output_frame /* i : frame length Q0*/ -); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output0[], /* i/o: synthesis @internal Fs, ch0 */ float synth0[] /* i/o: synthesis @output Fs, ch0 */ ); -void stereo_mdct2dft_update_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ - Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ -); + /*! r: number of bits written */ -#ifdef IVAS_FLOAT_FIXED -Word16 write_GR0( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - const Word16 ind, /* i : bitstream index */ - const Word16 *in, /* i : data to be encoded */ - const Word16 len /* i : input data length */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t write_GR0( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ const int16_t ind, /* i : bitstream index */ @@ -4292,15 +3336,7 @@ void ivas_mdct_core_tns_ns( const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_mct_core_dec( - 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 */ - Word32 *signal_out_fx[], - Word16 q_x[MCT_MAX_CHANNELS] -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_mct_core_dec( MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ @@ -4369,10 +3405,10 @@ void deindex_sph_idx( float *phi /* o : Azimuth */ ); void deindex_sph_idx_fx( - const UWord16 sphIndex, /* i : Spherical index */ - const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ - Word32 *theta_fx, /* o : Elevation */ - Word32 *phi_fx /* o : Azimuth */ + const UWord16 sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + Word32 *theta_fx, /* o : Elevation Q22*/ + Word32 *phi_fx /* o : Azimuth Q22 */ ); /*! r: output index for direction */ @@ -4429,18 +3465,8 @@ int16_t ivas_qmetadata_dec_sid_decode( int16_t *element_mode, /* o : element mode */ const int16_t ivas_format /* i : IVAS format */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_qmetadata_to_dirac_fx( - const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ - MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ - SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ -); -#else + +#ifndef IVAS_FLOAT_FIXED void ivas_qmetadata_to_dirac( const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ @@ -4452,6 +3478,7 @@ void ivas_qmetadata_to_dirac( int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ); #endif + #ifndef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ @@ -4483,13 +3510,6 @@ int16_t masa_sq( const int16_t cb_sz /* i : codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 masa_sq_fx( - const Word32 in, /* i : input value */ - const Word32 *threshold, /* i : partition */ - const Word16 cb_sz /* i : codebook size */ -); -#endif void ivas_qmetadata_azimuth_elevation_to_direction_vector( const float az, /* i : azimuth */ const float el, /* i : elevation */ @@ -4530,16 +3550,6 @@ uint16_t quantize_direction( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 quantize_direction2D_fx( - Word32 phi, /* i : input azimuth value Q22 */ - const Word16 no_cw, /* i : number of bits */ - Word32 *phi_q, /* o : quantized azimuth value Q22 */ - UWord16 *index_phi, /* o : quantized azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#endif - int16_t quantize_direction2D( float phi, /* i : input azimuth value */ const int16_t no_cw, /* i : number of bits */ @@ -4556,15 +3566,6 @@ float companding_azimuth( const int16_t direction /* i : direction of companding (direct or inverse)*/ ); -#ifdef IVAS_FLOAT_FIXED -Word32 companding_azimuth_fx( - const Word32 azi_fx, /* i : input azimuth value */ - const MC_LS_SETUP mc_format, /* i : input channel format */ - const Word16 theta_flag, /* i : zero/non zero elevation flag */ - const Word16 direction /* i : direction of companding (direct or inverse)*/ -); -#endif - /*! r: index azimuth */ int16_t quantize_phi_chan_lbr( const float phi, /* i : azimuth value */ @@ -4603,21 +3604,7 @@ int16_t quantize_phi( float *phi_hat, /* o : quantized azimuth */ const int16_t n /* i : azimuth codebook size */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 quantize_phi_fx( - Word32 phi, /* i : azimuth value */ - const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat, /* o : quantized azimuth */ - const Word16 n /* i : azimuth codebook size */ -); -Word16 quantize_phi_enc_fx( - Word32 phi, /* i : azimuth value */ - const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ - Word32 *phi_hat, /* o : quantized azimuth */ - const Word16 n /* i : azimuth codebook size */ -); -#endif /*! r: decoded elevation value */ float deindex_elevation( uint16_t *id_th, /* i : input index */ @@ -4625,14 +3612,6 @@ float deindex_elevation( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 deindex_elevation_fx( - UWord16 *id_th, /* i : input index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#endif - float deindex_azimuth( int16_t id_phi, /* i : index */ const int16_t no_bits, /* i : number of bits for the spherical grid */ @@ -4641,24 +3620,7 @@ float deindex_azimuth( const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ); -#ifdef IVAS_FLOAT_FIXED -Word32 deindex_azimuth_fx( - Word16 id_phi, /* i : index */ - const Word16 no_bits, /* i : number of bits for the spherical grid */ - const Word16 id_th, /* i : elevation index */ - const Word16 remap, /* i : remapping flag */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -void deindex_spherical_component_fx( - const UWord16 sph_idx, /* i : spherical index */ - Word32 *az_fx, /* o : decoded azimuth value */ - Word32 *el_fx, /* o : decoded elevation value */ - UWord16 *az_idx, /* o : azimuth index */ - UWord16 *el_idx, /* o : elevation index */ - const UWord16 no_bits, /* i : number of bits for the spherical grid */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -); -#else +#ifndef IVAS_FLOAT_FIXED void deindex_spherical_component( const uint16_t sph_idx, /* i : spherical index */ float *az, /* o : decoded azimuth value */ @@ -4713,23 +3675,7 @@ int16_t ivas_chan_project_elevation_index( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_param_est_enc( - DIRAC_ENC_HANDLE hDirAC, - IVAS_QDIRECTION *q_direction, - const UWord8 useLowerRes, - Word32 *data_f_fx[], - Word32 **pp_fr_real_fx, - Word32 **pp_fr_imag_fx, - Word16 pp_fr_q, - const Word16 input_frame, - const IVAS_FORMAT ivas_format, - const Word16 hodirac_flag, - const Word16 nchan_fb_in, - Word16 *mono_frame_count, - Word16 *dirac_mono_flag -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -4783,14 +3729,8 @@ void ivas_init_dec_get_num_cldfb_instances( int16_t *numCldfbSyntheses /* o : number of CLDFB synthesis instances */ ); #endif // !IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_cldfb_dec_reconfig_fx( - 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 */ -); -#else + +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_cldfb_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nchan_transport_old, /* i : number of TCs in previous frame */ @@ -4805,20 +3745,6 @@ int16_t ivas_sba_get_order( const int16_t sba_planar /* i : SBA planar flag */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_get_order_fx( - const Word16 nb_channels, /* i : Number of ambisonic channels */ - const Word16 sba_planar /* i : SBA planar flag */ -); - -#endif - -/*! r: Ambisonic (SBA) order used for analysis and coding */ -Word16 ivas_sba_get_analysis_order( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ -); - /*! r: number of Ambisonic channels */ int16_t ivas_sba_get_nchan( const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -4826,32 +3752,13 @@ int16_t ivas_sba_get_nchan( ); /*! r: number of ambisonics metadata channels */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_get_nchan_metadata( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ ); #endif -void ivas_sba_get_spar_hoa_ch_ind( - const Word16 num_md_chs, /* i : number of MD channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] -); - -/*! r: flag indicating to code SPAR HOA MD for all bands */ -void ivas_sba_get_spar_hoa_md_flag( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 *spar_hoa_md_flag, - Word16 *spar_hoa_dirac2spar_md_flag -); - void ivas_sba_zero_vert_comp( float *sba_data[], /* i : SBA signals */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -4865,14 +3772,6 @@ void ivas_sba_getTCs( const int16_t input_frame /* i : frame length */ ); -/*! r: SBA DirAC stereo flag */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_remapTCs_fx( - Word32 *sba_data[], /* i/o: SBA signals */ - Decoder_Struct *st_ivas, /* i/o: decoder struct */ - const Word16 output_frame /* i : frame length */ -); -#endif // IVAS_FLOAT_FIXED int16_t ivas_sba_remapTCs( float *sba_data[], /* i/o: SBA signals */ Decoder_Struct *st_ivas, /* i/o: decoder struct */ @@ -4918,27 +3817,13 @@ void ivas_sba2mc_cldfb( const int16_t nb_timeslots, /* i : number of time slots to process */ const float *hoa_dec_mtx /* i : HOA decoding mtx */ ); -#else -void ivas_sba2mc_cldfb_fixed( - IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */ - Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part (Q_real) */ - Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part (Q_imag) */ - const Word16 nb_channels_out, /* i : nb of output channels */ - const Word16 nb_bands, /* i : nb of CLDFB bands to process */ - const Word16 nb_timeslots, /* i : number of time slots to process */ - const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ -); #endif /*----------------------------------------------------------------------------------* * DirAC prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_open_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); @@ -4948,33 +3833,14 @@ ivas_error ivas_dirac_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_enc_close_fx( - DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ - const Word32 input_Fs /* i : input sampling_rate */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_enc_close( DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_dirac_enc_fx( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - Word32 *data_f[], /* i/o: SBA channels */ - Word32 **ppIn_FR_real, /* o : real freq domain values */ - Word32 **ppIn_FR_imag, /* o : imag freq domain values */ - Word16 pp_fr_q, - const int16_t input_frame, /* i : input frame length */ - const int16_t dtx_vad, /* i : DTX vad flag */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - const int16_t hodirac_flag /* i : hodirac flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_enc( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -5004,17 +3870,6 @@ void ivas_dirac_config_bands( IVAS_FB_MIXER_HANDLE hFbMdft ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_config_bands_fx( - Word16 *band_grouping, /* o : band grouping */ - const Word16 nbands, /* i : number of bands */ - const Word16 max_band, /* i : maximal band index +1 */ - Word16 *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ - const Word8 useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ - const Word16 enc_param_start_band, /* i : band index of first DirAC parameter band */ - IVAS_FB_MIXER_HANDLE hFbMdft -); -#endif void ivas_get_dirac_sba_max_md_bits( const int32_t sba_total_brate, int16_t *bits_frame_nominal, @@ -5063,23 +3918,8 @@ void generate_masking_noise_lb_dirac( const int16_t cna_flag /* i : CNA flag for LB and HB */ ); #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 */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_close_fx( - DIRAC_DEC_HANDLE *hDirAC_out -); -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 */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_set_md_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ @@ -5110,29 +3950,7 @@ void computeDiffuseness_mdft( const uint16_t no_col_avg_diff, float *diffuseness ); -#ifdef IVAS_FLOAT_FIXED -void computeDirectionVectors_fixed( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - 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*/); -void computeDirectionVectors_fx( - Word32 *intensity_real_x, - Word32 *intensity_real_y, - Word32 *intensity_real_z, - const Word16 enc_param_start_band, - const Word16 num_frequency_bands, - Word32 *direction_vector_x, - Word32 *direction_vector_y, - Word32 *direction_vector_z , - Word16 *q_factor -); -#endif + void computeDirectionVectors( float *intensity_real_x, float *intensity_real_y, @@ -5151,64 +3969,14 @@ void computeDiffuseness( float *diffuseness ); -#ifdef IVAS_FLOAT_FIXED - -void computeDiffuseness_fx( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - Word32 *diffuseness , - Word16 q_factor_intensity, - Word16 q_factor_energy, - Word16 *out_exp - -); -#endif -#ifdef IVAS_FLOAT_FIXED -void computeDiffuseness_fixed( - Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], - const Word32 *buffer_energy, - const Word16 num_freq_bands, - Word32 *diffuseness , - Word16 *q_factor_intensity, - Word16 *q_factor_energy, - Word16 *q_diffuseness -); -#endif void ivas_dirac_dec_get_response( const int16_t azimuth, const int16_t elevation, float *response, const int16_t ambisonics_order ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_get_response_fx( - const Word16 azimuth, - const Word16 elevation, - Word32 * response, - const Word16 ambisonics_order, - Word16 Q_out); -#endif - -#ifdef IVAS_FLOAT_FIXED -void calculate_hodirac_sector_parameters_fx( - DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ - Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ - Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ - Word16 Qfac, /* i : Q-factor of signal vector */ - const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ - const Word16 *band_grouping, /* i : indices of band groups */ - const Word16 N_bands, /* i : number of bands (groups) */ - const Word16 enc_param_start_band, /* i : first band to process */ - Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ - Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ - Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ - Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ - Word32 *ene_fx, /* o : array of sector energy values, flat */ - Word16 *ene_exp /* o : array of sector energy exponents, flat */ -); -#else +#ifndef IVAS_FLOAT_FIXED void calculate_hodirac_sector_parameters( DIRAC_ENC_HANDLE hDirAC, float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ @@ -5224,14 +3992,7 @@ void calculate_hodirac_sector_parameters( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_mc_paramupmix_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - Word32 *data_fx[], - const int16_t input_frame /* i : input frame length */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_enc( Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ @@ -5269,17 +4030,7 @@ void ivas_mc_paramupmix_dec_digest_tc( const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_mc_paramupmix_dec_render( - 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 *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 */ -); -#else - +#ifndef IVAS_FLOAT_FIXED 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 */ @@ -5315,12 +4066,7 @@ void ivas_param_mc_create_full_icc_mapping( ); #endif /*! r: number of IVAS transport channels */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_param_mc_getNumTransportChannels( - const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */ - const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_param_mc_getNumTransportChannels( const int32_t ivas_total_bitrate, /* i : IVAS total bitrate */ const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ @@ -5346,30 +4092,16 @@ void ivas_param_mc_enc( float *data_f[], /* i/o: input/transport MC data */ const int16_t input_frame /* i : input frame length */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_param_mc_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_param_mc_dec_reconfig_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#endif // IVAS_FLOAT_FIXED - ivas_error ivas_param_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_close_fx( - PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ -); -#else + +#ifndef IVAS_FLOAT_FIXED void ivas_param_mc_dec_close( PARAM_MC_DEC_HANDLE *hParamMC /* i/o: Parametric MC decoder handle */ ); @@ -5390,23 +4122,6 @@ void ivas_param_mc_dec_digest_tc( float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/ ); -void ivas_param_mc_dec_digest_tc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - Word32 *transport_channels_f_fx[], - Word16 transport_f_e ); - -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_dec_render_fx( - 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 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_f_fx[], /* o : rendered time signal */ - Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] -); -#endif - void ivas_param_mc_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -5457,79 +4172,7 @@ int16_t matrix_product( float *Z /* o : resulting matrix after the matrix multiplication */ ); -#ifdef IVAS_FLOAT_FIXED -Word16 matrix_product_mant_exp_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 X_fx_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 Y_fx_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ - Word16 *Z_fx_e /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_q30_fx( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ -); - -Word16 matrix_product_mant_exp( - const Word32 *X_fx, /* i : left hand matrix */ - const Word16 *X_e, /* i : left hand matrix */ - const Word16 rowsX, /* i : number of rows of the left hand matrix */ - const Word16 colsX, /* i : number of columns of the left hand matrix */ - const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ - const Word32 *Y_fx, /* i : right hand matrix */ - const Word16 *Y_e, /* i : right hand matrix */ - const Word16 rowsY, /* i : number of rows of the right hand matrix */ - const Word16 colsY, /* i : number of columns of the right hand matrix */ - const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ - Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ - Word16 *Z_e /* o : resulting matrix after the matrix multiplication */ -); -#endif - -#ifdef IVAS_FLOAT_FIXED -void mat2svdMat_fx( - const Word32 *mat, /* i : matrix as column ordered vector Qx*/ - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols, /* i : number of columns of the matrix Q0*/ - const Word16 transpose /* i : flag indication transposition Q0*/ -); - -void svdMat2mat_fx( - Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ - Word32 *mat, /* o : matrix as column ordered vector Qx*/ - const Word16 nRows, /* i : number of rows of the matrix Q0*/ - const Word16 mCols /* i : number of columns of the matrix Q0*/ -); -#else - +#ifndef IVAS_FLOAT_FIXED void mat2svdMat( const float *mat, /* i : matrix as column ordered vector */ float svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry */ @@ -5600,27 +4243,6 @@ int16_t computeMixingMatrices( float *mixing_matrix, /* o : resulting mixing matrix */ float *Cr /* o : residual covariance matrix */ ); - -#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 */ - Word16 Cx_e, - const Word32 *Cy, /* i : target covariance matrix */ - Word16 Cy_e, - 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 */ - Word16 reg_Sx_e, - const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ - Word16 reg_ghat_e, - Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ - Word16 *mixing_matrix_out_e, - Word32 *Cr_fx, /* o : residual covariance matrix */ - Word16 *Cr_e -); #endif #ifndef IVAS_FLOAT_FIXED @@ -5632,36 +4254,9 @@ int16_t computeMixingMatricesResidual( const float reg_ghat, /* i : regularization factor for the normalization matrix */ float *mixing_matrix /* o : resulting residual mixing matrix */ ); - -#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 Word16 Cx_e, - 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 Word16 reg_Sx_e, - 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 -); #endif -#ifdef IVAS_FLOAT_FIXED -/*! r: error or success */ -Word16 svd_fx( - Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ - 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) singularValues_fx_e*/ - Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ - Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], - const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ - const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ -); -#else +#ifndef IVAS_FLOAT_FIXED /*! r: error or success */ int16_t svd( float InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) */ @@ -5673,20 +4268,6 @@ int16_t svd( ); #endif -#ifdef IVAS_FLOAT_FIXED -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) */ -); -#endif // IVAS_FLOAT_FIXED - ivas_error ivas_dirac_dec_output_synthesis_cov_open( 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: handle for the covariance synthesis state */ @@ -5699,26 +4280,10 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open( const float *proto_matrix /* i : the prototype (upmix) matrix (only used if mode == 1) */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_output_synthesis_get_interpolator_fx( - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ - const UWord16 interp_length /* i : interpolator length */ -); -#endif - void ivas_dirac_dec_output_synthesis_get_interpolator( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ const uint16_t interp_length /* i : interpolator length */ ); -#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 */ -); -#endif void ivas_dirac_dec_output_synthesis_cov_init( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state, /* i/o: pointer to the state of the covariance synthesis */ @@ -5727,12 +4292,6 @@ void ivas_dirac_dec_output_synthesis_cov_init( const int16_t n_param_bands, /* i : number of total parameter bands */ const int16_t n_param_bands_res /* i : number of parameter bands with a residual mixing matrix (i.e. decorrelation */ ); -#ifdef IVAS_FLOAT_FIXED1 -void ivas_dirac_dec_output_synthesis_cov_close_fx( - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ - DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ -); -#endif // IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_cov_close( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i : handle for the covariance synthesis parameters */ @@ -5764,44 +4323,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot( PARAM_MC_DEC_HANDLE hParamMC /* i : handle to the Parametric MC decoder state */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - Word32 *Cldfb_RealBuffer_in_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 */ -); -#endif - -#ifdef IVAS_FLOAT_FIXED -Word16 computeMixingMatricesISM_fx( - const Word16 num_inputs, - const Word16 num_responses, - const Word16 num_outputs, - const Word32 *responses_fx, - const Word16 responses_e, - const Word32 *ener_fx, - const Word16 ener_e, - const Word32 *Cx_diag_fx, - const Word16 Cx_diag_e, - const Word32 *Cy_diag_fx, - const Word16 Cy_diag_e, - const Word16 *Q_16fx, //Q15 - const Word16 energy_compensation_flag, - const Word32 reg_Sx_fx, - const Word32 reg_ghat_fx, - Word32 *mixing_matrix_fx, - Word16 *mixing_matrix_e); -#else +#ifndef IVAS_FLOAT_FIXED int16_t computeMixingMatricesISM( const int16_t num_inputs, const int16_t num_responses, @@ -5836,11 +4358,6 @@ ivas_error ivas_spar_enc_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -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 */ -); - void ivas_spar_enc_close( SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ @@ -5867,12 +4384,6 @@ void ivas_spar_dec_close( const int32_t output_Fs, /* i : output sampling rate */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -#else -void ivas_spar_dec_close_fx( - SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ - const Word32 output_Fs, /* i : output sampling rate */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); #endif ivas_error ivas_spar_dec( @@ -5889,16 +4400,6 @@ void ivas_spar_config( int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ const int16_t sid_format /* i : IVAS format indicator from SID frame */ ); -#ifdef IVAS_FLOAT_FIXED -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 */ - const AUDIO_CONFIG output_config, /* i : output audio configuration */ - const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ @@ -5908,17 +4409,6 @@ ivas_error ivas_sba_linear_renderer( const AUDIO_CONFIG output_config, /* i : output audio configuration */ const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ ); -#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 */ - 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*/ - const Word16 Q_output /* i : Q of transport/output audio channels */ -); -#endif // IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ @@ -5935,10 +4425,6 @@ void ivas_sba_mix_matrix_determiner( int16_t ivas_agc_enc_get_flag( const int16_t nchan_transport /* i : number of transport channels */ ); -#else -Word16 ivas_agc_enc_get_flag( - const Word16 nchan_transport /* i : number of transport channels */ -); #endif ivas_error ivas_spar_agc_enc_open( @@ -5947,34 +4433,10 @@ ivas_error ivas_spar_agc_enc_open( const int16_t nchan_inp /* i : number of input channels */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_agc_enc_open_fx( - ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp /* i : number of input channels */ -); -#endif - void ivas_spar_agc_enc_close( ivas_agc_enc_state_t **hAgcEnc /* i/o: AGC encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_agc_enc_close_fx( - ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ -); - -void ivas_agc_enc_process_fx( - ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - Word32 **ppPcm_in, /* i : input audio channels */ - Word32 **ppPcm_out, /* o : output audio channels */ - const Word16 n_channels, /* i : number of channels */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - Word16 *q_ppPcm -); -#endif - void ivas_agc_enc_process( ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ @@ -6000,12 +4462,6 @@ ivas_error ivas_spar_md_enc_init const int16_t sba_order /* i : Ambisonic (SBA) order */ ); -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 */ -); - void ivas_agc_dec_process( ivas_agc_dec_state_t *hAgcDec, /* i/o: AGC decoder handle */ float *pcm_in[], /* i : input audio channels */ @@ -6072,15 +4528,6 @@ void ivas_spar_set_bitrate_config( const int16_t agc_flag ); -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); - void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -6125,12 +4572,6 @@ void ivas_itda( const int16_t length ); -void ivas_spar_get_cldfb_gains_fx( - SPAR_DEC_HANDLE hSpar, - HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, - HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, - const DECODER_CONFIG_HANDLE hDecoderConfig -); void ivas_spar_get_cldfb_gains( SPAR_DEC_HANDLE hSpar, HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, @@ -6144,41 +4585,19 @@ int16_t ivas_is_res_channel( const int16_t ch, /* i : ch index in WYZX ordering */ const int16_t nchan_transport /* i : number of transport channels (1-4) */ ); - -#else -Word16 ivas_is_res_channel( - const Word16 ch, /* i : ch index in WYZX ordering */ - const Word16 nchan_transport /* i : number of transport channels (1-4) */ -); #endif + void ivas_spar_dec_agc_pca( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float *output[], /* i/o: input/output audio channels */ const Word16 output_frame /* i : output frame length */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_agc_pca_fx( - 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 */ -); -#endif -#ifdef IVAS_FLOAT_FIXED -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 */ -); -#endif + void ivas_spar_dec_set_render_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_set_render_params_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ -); -#endif + void ivas_spar_dec_set_render_params( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */ @@ -6190,34 +4609,12 @@ void ivas_spar_dec_digest_tc( const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_digest_tc_fx( - 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 */ -); -#endif + void ivas_sba_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_sba_dec_digest_tc_fx( - 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 */ -); -ivas_error ivas_sba_dec_render_fx( - 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 Q11*/ - Word16 out_len/*Store the length of values in each channel*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -6226,14 +4623,6 @@ ivas_error ivas_sba_dec_render( uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ float *output_f[] /* o : rendered time signal */ ); -#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 */ - const Word16 nchan_internal, /* i : number of internal channels */ - Word16 out_len -); -#endif // IVAS_FLOAT_FIXED void ivas_spar_dec_upmixer_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -6255,32 +4644,11 @@ ivas_error ivas_spar_md_enc_open( const int16_t sba_order /* i : Ambisonic (SBA) order */ ); -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 */ -); - void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_md_enc_process_fx( - ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const Word16 dtx_vad, - const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); -#else + +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_md_enc_process( ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -6296,51 +4664,69 @@ ivas_error ivas_spar_md_enc_process( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_create_fullr_dmx_mat_fx( - 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 ***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 +void ivas_compute_spar_params( + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const int16_t i_ts, + float ***mixer_mat, + const int16_t start_band, + const int16_t end_band, + const int16_t dtx_vad, + const int16_t num_ch, + const int16_t bands_bw, + const int16_t active_w, + const int16_t active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + float *pWscale, + const int16_t from_dirac, + const int16_t dyn_active_w_flag +); + +void ivas_create_fullr_dmx_mat( + float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float ***mixer_mat, + const int16_t in_chans, + const int16_t start_band, + const int16_t end_band, + const int16_t active_w, + ivas_spar_md_com_cfg *hMdCfg ); -#endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED -void ivas_get_spar_md_from_dirac_fx( - Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 - Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 - Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 - const Word16 n_ts, - Word32 ***mixer_mat_fx, - Word16 *q_mixer_mat_fx, +void ivas_calc_c_p_coeffs( + ivas_spar_md_t *pSparMd, + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const int16_t i_ts, + float ***mixer_mat, + const int16_t num_ch, + const int16_t num_dmx, + const int16_t band_idx, + const int16_t dtx_vad, + const int16_t compute_p_flag, + const int16_t dyn_active_w_flag +); + +void ivas_get_spar_md_from_dirac( + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float diffuseness[IVAS_MAX_NUM_BANDS], + const int16_t n_ts, + float ***mixer_mat, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, - const Word16 start_band, - const Word16 end_band, - const Word16 order, - const Word16 dtx_vad, - Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 - const UWord8 useLowerRes, - const Word16 active_w_vlbr, - const Word16 dyn_active_w_flag + const int16_t start_band, + const int16_t end_band, + const int16_t order, + const int16_t dtx_vad, + float Wscale_d[IVAS_MAX_NUM_BANDS], + const uint8_t useLowerRes, + const int16_t active_w_vlbr, + const int16_t dyn_active_w_flag ); -#endif /*! r: number of MD subframes */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_get_spar_dec_md_num_subframes( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_spar_dec_md_num_subframes( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -6372,15 +4758,6 @@ void ivas_spar_md_dec_close( ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ ); -void ivas_spar_get_parameters_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 ts, /* i : time slot index */ - const Word16 num_ch_out, /* i : number of channels out */ - const Word16 num_ch_in, /* i : number of channels in */ - const Word16 num_spar_bands, /* i : number of SPAR bands */ - Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ -); void ivas_spar_get_parameters( SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -6413,14 +4790,7 @@ void ivas_spar_to_dirac( const int16_t bw, /* i : band joining factor */ const int16_t dyn_active_w_flag /* i : dynamic active W flag */ ); -void ivas_spar_to_dirac_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 dtx_vad, /* i : DTX frame flag */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bw, /* i : band joining factor */ - const Word16 dyn_active_w_flag /* i : dynamic active W flag */ -); + void ivas_spar_update_md_hist( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ ); @@ -6429,10 +4799,6 @@ int16_t ivas_spar_chk_zero_coefs( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -Word16 ivas_spar_chk_zero_coefs_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ -); - void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ @@ -6444,15 +4810,6 @@ void ivas_spar_setup_md_smoothing( const int16_t num_bands_out, /* i : number of output bands */ const int16_t num_md_sub_frames /* i : number of metadata subframes */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_spar_dec_gen_umx_mat_fx( - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames -); -#endif // IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ @@ -6462,21 +4819,7 @@ void ivas_spar_dec_gen_umx_mat( const int16_t num_md_sub_frames ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_enc_open_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp, /* i : number of input channels */ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - -void ivas_spar_covar_enc_close_fx( - ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ - const Word16 nchan_inp /* i : number of input channels */ -); -#else +#ifndef IVAS_FLOAT_FIXED /* Covariance module */ ivas_error ivas_spar_covar_enc_open( ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ @@ -6493,30 +4836,7 @@ void ivas_spar_covar_enc_close( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_enc_cov_handler_process_fx( - ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ - Word32 **ppIn_FR_real, - Word32 **ppIn_FR_imag, - Word16 q_ppIn_FR, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *q_cov_real[IVAS_SPAR_MAX_CH], - Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 start_band, - const Word16 end_band, - const Word16 num_ch, - const Word16 dtx_vad, - const Word16 transient_det[2], - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 *res_ind, - const Word16 *remix_order, - Word16 *dyn_active_w_flag, - const Word16 nchan_transport, - const Word16 is_sba -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -6538,21 +4858,7 @@ void ivas_enc_cov_handler_process( ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_spar_covar_smooth_enc_open_fx( - ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ - const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 nchan_inp, /* i : number of input channels */ - const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ - const Word32 ivas_total_brate /* i : IVAS total bitrate */ -); - -void ivas_spar_covar_smooth_enc_close_fx( - ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ - const Word16 nchan_inp /* i : number of input channels */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ @@ -6568,18 +4874,7 @@ void ivas_spar_covar_smooth_enc_close( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_cov_smooth_process_fx( - ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - ivas_filterbank_t *pFb, /* i/o: FB handle */ - const Word16 start_band, - const Word16 end_band, - const Word16 num_ch, - const Word16 transient_det[2], - Word16 *q_cov[IVAS_SPAR_MAX_CH] -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -6654,17 +4949,6 @@ void ivas_pca_enc( const int16_t n_channels /* i : number of channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_pca_enc_fx( - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - Word32 *data_f[8], /* i : input/transformed audio channels Q11 */ - const Word16 input_frame, /* i : input frame length */ - const Word16 n_channels /* i : number of channels */ -); -#endif - void ivas_pca_read_bits( Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ @@ -6683,44 +4967,14 @@ void ivas_pca_dec( const int16_t bfi, /* i : bad frame indicator */ float *pcm_out[] /* o : output audio channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_pca_read_bits_fx( - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ -); -void ivas_pca_dec_init_fx( - PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ -); - -void ivas_pca_dec_fx( - PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ - const Word16 output_frame, /* i : output frame length */ - const Word16 n_channels, /* i : number of channels */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ - const Word16 bfi, /* i : bad frame indicator */ - Word32 *pcm_out[] /* o : output audio channels */ -); -#endif /* PCA utilities */ void eye_matrix( float *mat, const int16_t n, const float d ); -#ifdef IVAS_FLOAT_FIXED -void eye_matrix_fx( - Word16 *mat, - const Word16 n, - const Word16 d -); -void eye_matrix_fx32( - Word32 *mat, // Q - const Word16 n, - const Word32 d ); // Q -#endif void cov_subfr( float **ptr_sig, float *r, @@ -6728,14 +4982,6 @@ void cov_subfr( const int16_t len ); -#ifdef IVAS_FLOAT_FIXED -void cov_subfr_fx( - Word32 **ptr_sig_fx, // Q11 - Word64 *r_fx_64, // Q11 - const Word16 n_channels, - const Word16 len ); -#endif - void eig_qr( const float *A, const int16_t num_iter, @@ -6743,39 +4989,16 @@ void eig_qr( const int16_t n ); -#ifdef IVAS_FLOAT_FIXED -void eig_qr_fx( - const Word32 *A_fx, // A_q - Word16 A_q, - const Word16 num_iter, - Word32 *EV_fx, // Q31 - Word32 *Vals_fx, // A_q - const Word16 n ); -#endif - void exhst_4x4( float *cost_mtx, int16_t *path, const int16_t maximize ); -#ifdef IVAS_FLOAT_FIXED -void exhst_4x4_fx( - Word16 *cost_mtx, // Q - Word16 *path, - const Word16 maximize ); -#endif - float mat_det4( const float *m ); -#ifdef IVAS_FLOAT_FIXED -Word16 mat_det4_fx( - const Word16 *m // Q15 -); -#endif - /* quaternion utilities */ void mat2dquat( const float *a, @@ -6783,14 +5006,6 @@ void mat2dquat( float *qr ); -#ifdef IVAS_FLOAT_FIXED -void mat2dquat_fx( - const Word16 *a, // Q15 - Word16 *ql, // Q15 - Word16 *qr // Q15 -); -#endif - void dquat2mat( const float *ql, const float *qr, @@ -6814,50 +5029,16 @@ void pca_interp_preproc( float *qr_interp ); -#ifdef IVAS_FLOAT_FIXED -void dquat2mat_fx( - const Word16 *ql, - const Word16 *qr, - Word16 *m); - -void quat_shortestpath_fx( - const Word16 *q00, - Word16 *q01, - const Word16 *q10, - Word16 *q11); - -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); -#endif void pca_enc_s3( float *q, int32_t *index ); -#ifdef IVAS_FLOAT_FIXED -void pca_enc_s3_fx( - Word16 *q, // Q15 - Word32 *index -); -#endif - void pca_dec_s3( const int32_t index, float *q ); -#ifdef IVAS_FLOAT_FIXED -void pca_dec_s3_fx( - const Word32 index, - Word16 *q); -#endif - #ifndef IVAS_FLOAT_FIXED int16_t ivas_get_bits_to_encode( int32_t val @@ -6871,17 +5052,6 @@ void ivas_huffman_encode( int16_t *hlen ); -void ivas_spar_huff_coeffs_com_init( - ivas_huff_coeffs_t *pHuff_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const Word16 table_idx, - const Word16 enc_dec); - -void ivas_spar_arith_coeffs_com_init( - ivas_arith_coeffs_t *pArith_coeffs, - ivas_spar_md_com_cfg *pSpar_cfg, - const Word16 table_idx, - const Word16 enc_dec); #ifndef IVAS_FLOAT_FIXED int16_t ivas_arith_encode_cmplx_cell_array( @@ -6920,12 +5090,6 @@ void ivas_ari_start_decoding_14bits_ext_1_lfe( Tastat *s, int16_t *extra_bits_read ); -#else -void ivas_ari_start_decoding_14bits_ext_1_lfe( - Decoder_State *st, - Tastat *s, - Word16 *extra_bits_read -); #endif #ifndef IVAS_FLOAT_FIXED @@ -6934,12 +5098,6 @@ uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( const uint16_t *cum_freq, int16_t *extra_bits_read ); -#else -UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( - Decoder_State *st, Tastat *s, - const UWord16 *cum_freq, - Word16 *extra_bits_read -); #endif #ifndef IVAS_FLOAT_FIXED @@ -6947,11 +5105,6 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const int16_t extra_bits_read ); -#else -void ivas_ari_done_decoding_14bits_ext_1_lfe( - Decoder_State *st, - const Word16 extra_bits_read -); #endif void ivas_ari_done_encoding_14bits( @@ -7003,59 +5156,17 @@ void ivas_quantise_real_values( float *quant, const int16_t dim ); -void ivas_quantise_real_values_fx( - const Word32 *values_fx, - const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, - Word16 *index, - Word32 *quant_fx, - const Word16 dim); - -void ivas_quantise_real_values_enc_fx_varq( - const Word32 *values_fx, - const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, - Word16 *index, - Word32 *quant_fx, - const Word16 dim, - Word16 inp_q ); - -void ivas_quantise_real_values_enc_fx( - const Word32 *values_fx,//Q28 - const Word16 q_levels, - const Word32 min_value_fx,//Q28 - const Word32 max_value_fx,//Q28 - Word16 *index, - Word32 *quant_fx,//Q28 - const Word16 dim); - void ivas_spar_get_uniform_quant_strat( ivas_spar_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ); -void ivas_spar_get_uniform_quant_strat_fx( - ivas_spar_md_com_cfg *pSpar_md_com_cfg, - const Word16 table_idx); - void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ); -void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max -); - -void ivas_spar_quant_dtx_init_fx( - ivas_spar_md_t *spar_md, - Word32 *min_max -); - void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_md_com_cfg *pSpar_md_cfg, @@ -7063,14 +5174,7 @@ void ivas_map_prior_coeffs_quant( const int16_t nB ); -#ifdef IVAS_FLOAT_FIXED -void ivas_copy_band_coeffs_idx_to_arr( - ivas_band_coeffs_ind_t *pBands_idx, - const Word16 nB, - Word16 *pSymbol_re, - ivas_cell_dim_t *pCell_dims, - const ivas_coeffs_type_t coeff_type); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_copy_band_coeffs_idx_to_arr( ivas_band_coeffs_ind_t *pBands_idx, const int16_t nB, @@ -7080,9 +5184,10 @@ void ivas_copy_band_coeffs_idx_to_arr( ); #endif -void ivas_clear_band_coeffs_fx( - ivas_band_coeffs_t *pband_coeffs, - const UWord16 num_bands); +void ivas_clear_band_coeffs( + ivas_band_coeffs_t *pband_coeffs, + const uint16_t num_bands +); void ivas_clear_band_coeff_idx( ivas_band_coeffs_ind_t *pband_coeff_idx, @@ -7196,14 +5301,7 @@ void distribute_evenly_ism( const int16_t nchan_ism ); -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_qmetadata_DecodeExtendedGR( - UWord16* bitstream, - Word16* index, - const Word16 alph_size, - const Word16 gr_param -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_qmetadata_DecodeExtendedGR( uint16_t* bitstream, int16_t* index, @@ -7235,11 +5333,7 @@ void ivas_merge_masa_metadata( OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_masa_combine_directions_fx( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_masa_combine_directions( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ ); @@ -7302,7 +5396,7 @@ void ivas_set_qmetadata_maxbit_req( const IVAS_FORMAT ivas_format /* i : IVAS format */ ); -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ Word16 ivas_get_df_ratio_bits_hodirac( const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ @@ -7312,16 +5406,6 @@ Word16 ivas_get_df_ratio_bits_hodirac( Word16 ivas_get_df_ratio_bits( const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ ); -#else -/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ -int16_t ivas_get_df_ratio_bits_hodirac( - const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ -); - -/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ -int16_t ivas_get_df_ratio_bits( - const int16_t index_diff /* i : Index of quantized diffuse-to-total ratio */ -); #endif @@ -7339,14 +5423,6 @@ void invdct4_transform( uint8_t *invdct_v /* o : transformed vector */ ); -#ifdef IVAS_FLOAT_FIXED -void invdct4_transform_fx( - Word32 *v_fx, /* i : input vector */ - UWord8 *invdct_v, /* o : transformed vector */ - Word16 q -); -#endif - #ifndef IVAS_FLOAT_FIXED void update_bits_next_block( IVAS_QDIRECTION *q_direction, /* i/o: qdirection */ @@ -7371,33 +5447,16 @@ void ivas_spar_param_to_masa_param_mapping( const int16_t subframe /* i : Subframe to map */ ); -void ivas_spar_param_to_masa_param_mapping_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ - Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], - const Word16 subframe /* i : Subframe to map */ -); - - /*---------------------------------------------------------------------------------* * Binaural FastConv Renderer Prototypes *-----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_binRenderer_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_binRenderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_binRenderer_close_fx( - BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_binRenderer_close( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ ); @@ -7406,24 +5465,12 @@ void ivas_binRenderer_close( void ivas_binaural_hrtf_close( HRTFS_FASTCONV_HANDLE *hHrtfFastConv /* i/o: decoder binaural hrtf handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_init_binaural_hrtf_fx( - HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_init_binaural_hrtf( HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_allocate_binaural_hrtf_fx( - HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ - const AUDIO_CONFIG input_config, /* i : input audio configuration */ - const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ - const RENDERER_TYPE renderer_type, /* i : renderer type */ - const Word16 allocate_init_flag /* i : Memory allocation flag */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_allocate_binaural_hrtf( HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ const AUDIO_CONFIG input_config, /* i : input audio configuration */ @@ -7443,29 +5490,12 @@ void ivas_binRenderer( float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] /* i : LS signals */ ); -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 Word16 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 */ -); - void ivas_binaural_add_LFE( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ int16_t output_frame, /* i : length of input frame */ float *input_f[], /* i : transport channels */ float *output_f[] /* o : synthesized core-coder transport channels/DirAC output */ ); -void ivas_binaural_add_LFE_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word16 output_frame, /* i : length of input frame */ - Word32 *input_fx[], /* i : transport channels */ - Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output */ -); /*----------------------------------------------------------------------------------* * renderer prototypes @@ -7494,17 +5524,6 @@ void ivas_ism_get_stereo_gains( ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_mc2sba_fx( - IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ - Word32 *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ - Word32 *buffer_td[], /* 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 /* i : gain for LFE, 0 = ignore LFE */ -); -#endif // IVAS_FLOAT_FIXED - void ivas_mc2sba( IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ float *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ @@ -7513,17 +5532,6 @@ void ivas_mc2sba( const int16_t sba_order, /* i : SBA order */ const float gain_lfe /* i : gain for LFE, 0=ignore LFE */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_param_mc_mc2sba_cldfb_fx( - IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ - Word32 *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ - const Word16 slot_idx, /* i : current slot in the subframe */ - Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ - Word32 Cldfb_ImagBuffer[][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 gain_lfe /* i : gain applied to LFE */ -); -#endif // IVAS_FLOAT_FIXED void ivas_param_mc_mc2sba_cldfb( IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ @@ -7535,17 +5543,7 @@ void ivas_param_mc_mc2sba_cldfb( const float gain_lfe /* i : gain applied to LFE */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ism2sba_sf_fx( - Word32 *buffer_in_fx[], /* i : TC buffer */ - 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 */ -); -#else // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED void ivas_ism2sba_sf( float *buffer_in[], /* i : TC buffer */ float *buffer_out[], /* o : TD signal buffers */ @@ -7567,26 +5565,12 @@ void panning_wrap_angles( float *azi_wrapped, /* o : wrapped azimuth component */ float *ele_wrapped /* o : wrapped elevation component */ ); -#ifdef IVAS_FLOAT_FIXED -void panning_wrap_angles_fx( - const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ - const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ - Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ - Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ -); -#endif + void v_sort_ind( float *x, /* i/o: Vector to be sorted */ int16_t *idx, /* o : Original index positions */ const int16_t len /* i : vector length */ ); -#ifdef IVAS_FLOAT_FIXED -void v_sort_ind_fixed( - Word32 *x, /* i/o: Vector to be sorted */ - Word16 *idx, /* o : Original index positions */ - const Word16 len /* i : vector length */ -); -#endif /*----------------------------------------------------------------------------------* * LS Renderer prototypes @@ -7613,13 +5597,6 @@ void ivas_ls_setup_conversion_process_mdct( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output[] /* i/o: output synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_ls_setup_conversion_process_mdct_param_mc_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *x_fx[][NB_DIV], /* i/o: Fixed output synthesis signal */ - Word16 x_e[CPE_CHANNELS][NB_DIV]/* i/o: Exponent for output synthesis signal */ -); -#endif // IVAS_FLOAT_FIXED void ivas_ls_setup_conversion_process_mdct_param_mc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -7750,14 +5727,6 @@ void lls_interp_n( const int16_t upd /* i : use 1 to update x[] with the interpolated output*/ ); -void lls_interp_n_fx( - 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 */ - const Word16 upd /* i : use 1 to update x[] with the interpolated output */ -); - void computeReferencePower_enc( const int16_t *band_grouping, /* i : Band grouping for estimation */ float Cldfb_RealBuffer[][DIRAC_NO_FB_BANDS_MAX], /* i : Real part of input signal */ @@ -7794,15 +5763,7 @@ void ivas_mono_stereo_downmix_mcmasa( int16_t output_frame /* i : output frame length per channel */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_lfe_synth_with_filters_fx( - MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ - Word32 *data_f[], /* o : output signals */ - const Word16 output_frame, /* i : output frame length per channel */ - const Word16 separateChannelIndex, /* i : separate channel index */ - const Word16 lfeChannelIndex /* i : LFE channel index */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_lfe_synth_with_filters( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ float *data_f[], /* o : output signals */ @@ -7852,16 +5813,6 @@ void ivas_lfe_enc( BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_lfe_enc_fx( - LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ - Word32 data_lfe_ch[], /* i : input LFE signal */ - Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ - const Word16 input_frame, /* i : input frame length per channel */ - BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ -); -#endif // IVAS_FLOAT_FIXED - #ifndef IVAS_FLOAT_FIXED ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ @@ -7903,16 +5854,6 @@ void ivas_lfe_lpf_select_filt_coeff( const float **ppFilt_coeff /* o : filter coefficients */ ); -#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 Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ -); -#endif - - void ivas_filters_init( ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ const float *filt_coeff, /* i : filter coefficients */ @@ -7921,11 +5862,10 @@ 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, /* i : filter coefficients */ - const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ - const Word16 order /* i : filter order */ -); + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const Word32 *filt_coeff_fx, /* i : filter coefficients Q31- *filt_coeff_e */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ + const Word16 order ) ; #endif void ivas_filter_process( @@ -7936,30 +5876,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 : signal subject to filtering */ - const Word16 length, /* i : filter order */ - Word16 q_factor -); + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word32 *pIn_Out_fx, /* i/o: signal subject to filtering Q(q_factor) */ + const Word16 length, /* i : filter order */ + Word16 q_factor ); #endif /*----------------------------------------------------------------------------------* * OSBA prototypes *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_enc_open_fx( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_enc_open( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_osba_enc_close_fx( - OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_osba_enc_close( OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ ); @@ -7979,36 +5910,10 @@ void ivas_osba_enc( const int32_t input_Fs, /* i : input sampling rate */ const int16_t sba_planar /* i : planar SBA flag */ ); -#else -void ivas_osba_enc_fx( - OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in_fx[], /* i/o: Input / transport audio signals */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_ism, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - const int16_t sba_analysis_order, /* i : SBA order evaluated in DirAC/SPAR encoder */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t sba_planar, /* i : planar SBA flag */ - Word16 *q_data - ); #endif ivas_error ivas_osba_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_data_open_fx( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ -); -ivas_error ivas_osba_dirac_td_binaural_jbm_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ - UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ - UWord16 *nSamplesAvailable, /* 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*/ -); -#endif // IVAS_FLOAT_FIXED ivas_error ivas_osba_dirac_td_binaural_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -8018,14 +5923,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm( float *output_f[] /* o : rendered time signal */ ); -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_ism_metadata_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word32 ism_total_brate, /* i : ISM total bitrate */ - Word16 *nchan_ism, /* o : number of ISM separated channels */ - Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_ism_metadata_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int32_t ism_total_brate, /* i : ISM total bitrate */ @@ -8033,15 +5931,7 @@ ivas_error ivas_osba_ism_metadata_dec( int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); #endif -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_osba_render_sf_fx( - 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 */ -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_osba_render_sf( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -8050,11 +5940,7 @@ ivas_error ivas_osba_render_sf( float *output_f[] /* o : rendered time signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_osba_data_close_fx( - SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ -); -#endif + void ivas_osba_data_close( SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ ); @@ -8122,16 +6008,6 @@ void ivas_set_surplus_brate_dec( int32_t *ism_total_brate /* i : ISM total bitrate */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_set_ism_importance_interformat_fx( - const Word32 ism_total_brate, /* i/o: ISms total bitrate */ - const Word16 nchan_transport, /* i : number of transported channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ - Word16 ism_imp[] /* o : ISM importance flags */ -); -#endif void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ @@ -8235,16 +6111,7 @@ void ivas_omasa_dirac_rend_jbm( float *output_f[] /* o : rendered time signal */ ); #endif -#ifdef IVAS_FLOAT_FIXED -void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( - Decoder_Struct *st_ivas, - Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ - Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ - Word16 *cldfb_buf_q, - const Word16 nBins, - const Word16 subframe -); -#endif + void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -8286,15 +6153,6 @@ void ivas_omasa_decode_masa_to_total( const int16_t nblocks ); -#ifdef IVAS_FLOAT_FIXED -void ivas_omasa_decode_masa_to_total_fx( - UWord16 *bit_stream, - Word16 *index, - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const Word16 nbands, - const Word16 nblocks); -#endif - void ivas_omasa_modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] @@ -8304,26 +6162,12 @@ void ivas_omasa_modify_masa_energy_ratios( /*----------------------------------------------------------------------------------* * TD Binaural Object renderer *----------------------------------------------------------------------------------*/ -#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 -); -#else +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); #endif // IVAS_FLOAT_FIXED -#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 */ - const Word16 output_frame /* i : output frame length */ -); -#endif - ivas_error ivas_td_binaural_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output[], /* i/o: SCE channels / Binaural synthesis */ @@ -8357,15 +6201,6 @@ ivas_error ivas_FB_mixer_open( const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_FB_mixer_close_fx( - IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ - const Word32 sampling_rate, /* i : sampling rate in Hz */ - const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ -); - -#endif - void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate in Hz */ @@ -8379,16 +6214,6 @@ void ivas_fb_mixer_pcm_ingest( const int16_t frame_length, /* i : frame length */ const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ); -#ifdef IVAS_FLOAT_FIXED -void ivas_fb_mixer_pcm_ingest_fx( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ - Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ - const Word16 frame_len, /* i : frame length */ - const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], - Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], - Word16 *q_ppOut_pcm ); -#endif void ivas_fb_mixer_update_prior_input( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ @@ -8407,17 +6232,7 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -#ifdef IVAS_FLOAT_FIXED -void ivas_fb_mixer_process( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ - Word16 *q_mixer_mat_fx, /* i : mixer matrix */ - Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ - Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ - const int16_t frame_len, /* i : frame length in samples */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); -#else +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_process( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float ***mixer_mat, /* i : mixer matrix */ @@ -8442,49 +6257,12 @@ void ivas_fb_mixer_cross_fading( ); /*! r: number of spectral bands */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_get_num_bands_from_bw_idx( - const Word16 bwidth /* i : audio bandwidth */ -); -#else +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_num_bands_from_bw_idx( const int16_t bwidth /* i : audio bandwidth */ ); #endif -#ifdef IVAS_FLOAT_FIXED -/*to be moved to prot_fx1.h*/ -void sns_avq_dec_fx( - Word16 *index, /* i : Quantization indices */ - Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ - Word16 *q_snsq, - const Word16 L_frame, /* i : frame length */ - const Word16 numlpc /* i : Number of sets of lpc */ -); - -void sns_avq_dec_stereo_fx( - Word16 *indexl, /* i : Quantization indices (left channel) */ - Word16 *indexr, /* i : Quantization indices (right channe) */ - const Word16 L_frame, /* i : frame length */ - Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ - Word16 *q_l, - Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ - Word16 *q_r ); - -void dequantize_sns_fx( - Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], - Word32 snsQ_out[CPE_CHANNELS][NB_DIV][M], - Decoder_State **sts ); - -void inverseMS_fx( - const Word16 L_frame, /* i : frame length Q0*/ - Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ - Word32 x1[], /* i/o: side/right channel coefficients Qx*/ - const Word32 norm_fac /* i : normalization factor Q31*/ -); - -#endif - /* clang-format on */ #endif /* IVAS_PROT_H */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4a0e4ddb1..3123d4475 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -121,8 +121,8 @@ Word16 valid_ratio_index_fx( ); UWord16 index_theta_phi_16_fx( - Word32 *p_theta, /* i/o: input elevation to be indexed */ - Word32 *p_phi, /* i/o: input azimuth to be indexed */ + Word32 *p_theta, /* i/o: input elevation to be indexed Q22 */ + Word32 *p_phi, /* i/o: input azimuth to be indexed Q22 */ const SPHERICAL_GRID_DATA *gridData /* i : generated grid data */ ); @@ -138,7 +138,6 @@ void ivas_omasa_rearrange_channels_fx( const Word16 output_frame /* i : output frame length per channel */ ); -#ifdef IVAS_FLOAT_FIXED ivas_error ivas_omasa_ism_metadata_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word32 ism_total_brate, /* i : ISM total bitrate */ @@ -159,7 +158,6 @@ ivas_error ivas_td_binaural_renderer_sf_fx( Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ 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 */ @@ -186,46 +184,46 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( ); void ivas_dct_windowing_fx( - const Word16 fade_len, - const Word16 full_len, - const Word16 dct_len, - const Word16 zero_pad_len, - const Word32 *pWindow_coeffs, - const Word16 frame_len, - Word32 *pOut_buf, - Word32 *pBuffer_prev, + const Word16 fade_len, /*Q0*/ + const Word16 full_len, /*Q0*/ + const Word16 dct_len, /*Q0*/ + const Word16 zero_pad_len, /*Q0*/ + const Word32 *pWindow_coeffs, /*Q31*/ + const Word16 frame_len, /*Q0*/ + Word32 *pOut_buf, // Q10 + Word32 *pBuffer_prev, // Q10 Word32 *pTemp_lfe ); void ivas_get_twid_factors_fx1( - const Word16 length, - const Word16 **pTwid_re, + const Word16 length, // Q0 + const Word16 **pTwid_re, // Q15 const Word16 **pTwid_im ); Word32 ivas_get_mdct_scaling_gain_fx( const Word16 dct_len_by_2 ); void ivas_imdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // Q24 + Word32 *pOut, // q_out Q9 + const Word16 length /*Q0*/, Word16 *q_out ); void ivas_mdct_fx( - const Word32 *pIn, - Word32 *pOut, - const Word16 length, + const Word32 *pIn, // q_out + Word32 *pOut, // q_out + const Word16 length, // Q0 Word16 *q_out ); void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ + const Word32 *re, /* i : time alised signal after IDCT Q24 */ Word32 *pOut, /* o : time domain buffer of size 2*length */ - const Word16 length /* i : length of time alised signal buffer */ + const Word16 length /* i : length of time alised signal buffer Q0 */ ); 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 Word16 length /* i : length of time alised signal buffer */ + const Word32 *pIn, /* i : time domain buffer of size 2*length Q10*/ + Word32 *pOut, /* o : time domain buffer of size length Q10 */ + const Word16 length /* i : length of time alised signal buffer Q0*/ ); // ivas_agc_dec_fx.c @@ -253,7 +251,6 @@ void ivas_agc_read_bits_fx( const Word16 AGC_flag /* i : AGC on/off flag */ ); -#ifdef IVAS_FLOAT_FIXED // ivas_agc_com_fx.c void ivas_agc_initWindowFunc_fx( Word16 *pWinFunc, @@ -285,7 +282,6 @@ void ECSQ_decode( ECSQ_instance *ecsq_inst, const Word16 N, Word16 *output ); -#endif // IVAS_FLOAT_FIXED // bass_psfilter.c Word16 res_bpf_adapt_fx( @@ -447,7 +443,6 @@ Word16 get_igf_startline( const Word16 L_frameTCX /* i : full band frame length */ ); -#ifdef IVAS_FLOAT_FIXED void stereo_dft_dec_reset_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: decoder DFT stereo handle */ ); @@ -503,8 +498,6 @@ void stereo_dft_generate_res_pred_fx( const Word16 bfi /* i : BFI flag */ ); -#endif - void stereo_dft_dec_analyze_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const Word32 *input_fx, /* i : input signal */ @@ -565,10 +558,8 @@ void ivas_sba_config_fx( Word16 *element_mode /* o : element mode of the core coder */ ); -#ifdef IVAS_FLOAT_FIXED Word16 ivas_get_bits_to_encode( Word32 val ); -#endif Word16 ivas_get_spar_table_idx_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ @@ -613,7 +604,6 @@ void ivas_ism_param_dec_tc_gain_ajust_fx( Word16 *Q_tc /* i/o : Q of input tc buffer */ ); -#ifdef IVAS_FLOAT_FIXED /*! r: number of bits read */ Word16 read_GR0( const UWord16 *bit_stream, /* i : bitstream to be read */ @@ -667,12 +657,12 @@ Word16 read_flag_EC_DFT( const UWord16 *bit_stream, /* i : bitstream */ Word16 *flag /* o : flag value */ ); -#ifdef IVAS_FLOAT_FIXED + /*file : ivas_mc_param_dec_fx.c*/ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( Decoder_Struct *st_ivas /* i : Parametric MC handle */ ); -#endif + void ivas_init_dec_get_num_cldfb_instances( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ Word16 *numCldfbAnalyses, /* o : number of CLDFB analysis instances */ @@ -684,7 +674,6 @@ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( Word16 *numCldfbAnalyses, /* o : number of needed CLDFB analysis instances */ Word16 *numCldfbSyntheses /* o : number of needed CLDFB synthesis instances */ ); -#endif Word16 masa_sq_fx( const Word32 in, /* i : input value */ @@ -756,8 +745,8 @@ 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 */ + Word32 *q_step_fx, /* o : quantization step Q22*/ + Word32 *q_step_border_fx, /* o : quantization step at the border Q22*/ Word16 *nBits_coh, /* o : number of Q bits for coherence */ Word16 *nBits_sce_id /* o : number of Q bits for sce_id_dtx */ ); @@ -775,7 +764,6 @@ void ivas_ism_metadata_sid_dec_fx( Word16 nb_bits_metadata[] /* o : number of metadata bits */ ); -#ifdef IVAS_FLOAT_FIXED // ivas_sce_dec_fx.c ivas_error create_sce_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -827,7 +815,6 @@ void ivas_post_proc_fx( const Word16 output_frame, /* i : output frame length */ const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ Word16 output_q ); -#endif // ivas_lfe_dec_fx.c @@ -1215,11 +1202,9 @@ void stereo_dft_dec_fx( ); // ivas_stereo_dft_enc.c -#ifdef IVAS_FLOAT_FIXED Word32 stereo_dft_enc_synthesize_fx( STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ - // float *output, /* o : output synthesis */ - Word32 *output_fx, /* o : output synthesis Q16 */ + Word32 *output_fx, /* o : output synthesis Q16 */ Word16 *output_start_index, Word16 *output_end_index, const Word16 chan, /* i : channel number */ @@ -1227,7 +1212,6 @@ Word32 stereo_dft_enc_synthesize_fx( const Word32 output_sampling_rate, /* i : output sampling rate */ const Word16 L_frame, /* i : frame length at internal Fs */ Word16 *nrg_out_fx_e ); -#endif void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ @@ -2056,13 +2040,10 @@ Word16 is_DTXrate( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); -#ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dereorder_generic( const UWord16 uns_value /* i : unsigned value result of ReorderGeneric */ ); -#endif -#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 */ @@ -2070,17 +2051,15 @@ void update_bits_next_block( 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: Word32 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 */ Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); -#ifdef IVAS_FLOAT_FIXED void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ @@ -2095,7 +2074,6 @@ void stereo_tcx_core_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ ); -#endif // IVAS_FLOAT_FIXED void masa_compensate_two_dir_energy_ratio_index_fx( const Word16 ratio_index_1, /* i : Input ratio for direction 1 */ @@ -2105,17 +2083,14 @@ void masa_compensate_two_dir_energy_ratio_index_fx( const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ); -#ifdef IVAS_FLOAT_FIXED -int16_t stereo_tdm_ener_analysis_fx( +Word16 stereo_tdm_ener_analysis_fx( const Word16 ivas_format, /* i : IVAS format */ CPE_ENC_HANDLE hCPE, /* i : CPE structure */ const Word16 input_frame, /* i : Number of samples */ Word16 *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ Word16 *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ ); -#endif -#ifdef IVAS_FLOAT_FIXED /*! r: projected azimuth index */ Word16 ivas_dirac_project_azimuth_index( const Word16 az_idx, /* i : azimuth index */ @@ -2142,7 +2117,7 @@ void small_reduction_direction( UWord16 bits_dir[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], const Word16 raw_flag[MASA_MAXIMUM_CODING_SUBBANDS], Word16 *diff ); -#endif + void sort_desc_ind_16_fx( Word16 *s, /* i/o: vector to be sorted Qx*/ @@ -2165,9 +2140,9 @@ ivas_error only_reduce_bits_direction_fx( Word16 *ind_order ); void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth */ - const Word32 el, /* i : elevation */ - Word32 *dv /* o : direction vector */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ + Word32 *dv /* o : direction vector Q30 */ ); void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( @@ -2177,7 +2152,6 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( Word32 *el /* o : elevation */ ); -#ifdef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ); @@ -2281,7 +2255,6 @@ void stereo_dtf_cng_fx( Word16 q_dft /* i : Q factor of the DFT data */ ); -#endif // IVAS_FLOAT_FIXED void ivas_spar_update_md_hist_fx( ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ @@ -2627,12 +2600,12 @@ Word16 calculate_brate_limit_flag_fx( const Word16 nchan_ism /* i : number of objects */ ); Word16 ism_quant_meta_fx( - const Word32 val, /* i : scalar value to quantize */ - Word32 *valQ, /* o : quantized value */ - 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 Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ ); /*! r: number of channels to be analysed */ @@ -2690,30 +2663,30 @@ void ivas_ari_encode_14bits_ext_fx( void ms_inv_mask_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ - int16_t ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t iSubframe, /* i : subframe number */ + Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ + const Word16 iSubframe, /* i : subframe number */ const Word32 x_0_fx[], /* i : spectrum 1 */ const Word32 x_1_fx[], /* i : spectrum 2 */ Word32 x_inv_0_fx[], /* o : inverse spectrum 1 */ Word32 x_inv_1_fx[], /* o : inverse spectrum 2 */ - int16_t maxSfb /* i : number of stereo frequency bands */ + Word16 maxSfb /* i : number of stereo frequency bands */ ); void ms_processing_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: Stereo MDCT encoder structure */ Encoder_State **sts, /* i/o: Encoder state structure */ Word16 ms_mask[NB_DIV][MAX_SFB], /* i : bandwise MS mask */ - const int16_t iSubframe, /* i : subframe number */ + const Word16 iSubframe, /* i : subframe number */ Word32 x_0_fx[], /* i/o: spectrum 1 */ Word32 x_1_fx[], /* i/o: spectrum 1 */ Word16 maxSfb /* i : number of stereo frequency bands*/ ); void convertToMS_fx( - const int16_t L_frame, /* i : frame length */ - Word32 x0[], /* i/o: mid/left channel coefficients */ - Word32 x1[], /* i/o: side/right channel coefficients */ - const Word32 norm_fac /* i : normalization factor */ + const Word16 L_frame, /* i : frame length */ + Word32 x0[], /* i/o: mid/left channel coefficients */ + Word32 x1[], /* i/o: side/right channel coefficients */ + const Word32 norm_fac /* i : normalization factor */ ); void FindSplitRatio_fx( @@ -3094,19 +3067,6 @@ void InternalTCXDecoder_fx( Word16 *gain_tcx_q /* o : quantized global gain (at low bitrates) */ ); -void stereo_tcx_core_enc( - Encoder_State *st, /* i/o: encoder state structure */ - const float new_samples_12k8[], /* i : buffer of input signal @12.8 kHz */ - const float new_samples_16k[], /* i : buffer of input signal @16 kHz */ - const Word16 Aw_fx[], /* i : weighted A(z) unquant. for subframes, Q12 */ - float lsp_new[], /* i : LSPs at the end of the frame, Q15 */ - float lsp_mid[], /* i : LSPs in the middle of the frame, Q15 */ - Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ - const Word16 last_element_mode, /* i : last element mode, Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag, Q0 */ -); - - Word16 transient_analysis_ivas_fx( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ const Word16 cor_map_LT[], /* i : LT correlation map Q_cor_map = Qx */ @@ -3194,8 +3154,6 @@ void small_requantize_direction_frame_fx( Word16 bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], Word16 *diff ); -#ifdef IVAS_FLOAT_FIXED - void ivas_param_ism_stereo_dmx_fx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ Word32 *data[MAX_NUM_OBJECTS], /* i/o: input signal/stereo dmx Qx */ @@ -3207,7 +3165,6 @@ void ivas_param_ism_enc_fx( Word32 *data[MAX_NUM_OBJECTS], /* i : input signal q_pcm_in */ const Word16 input_frame, /* i : input frame length per channel */ const Word16 q_pcm_in ); -#endif ISM_MODE ivas_ism_mode_select( const Word16 nchan_inp, /* i : number of input objects */ @@ -3226,9 +3183,9 @@ void ivas_fb_mixer_get_windowed_fr_fx( Word32 *pcm_in_fx[], Word32 *frame_f_real_fx[], Word32 *frame_f_imag_fx[], - const int16_t length, /* i : number of new samples in time slot */ - const int16_t mdft_len, /* i : MDFT frame length */ - const int16_t nchan_fb_in, /* i : number of analysis channels */ + const Word16 length, /* i : number of new samples in time slot */ + const Word16 mdft_len, /* i : MDFT frame length */ + const Word16 nchan_fb_in, /* i : number of analysis channels */ Word16 gb ); void ivas_omasa_set_config_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ @@ -3547,4 +3504,2211 @@ ivas_error ivas_masa_encode_fx( const Word16 ism_imp, /* i : importance of separated object */ const Word16 flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ ); + +void ivas_write_format_sid_fx( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 element_mode, /* i : element bitrate */ + BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle */ +); + +void ivas_write_format_fx( /* i/o: IVAS encoder structure */ + Encoder_Struct *st_ivas ); + +ivas_error create_sce_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 sce_id, /* i : SCE # identifier */ + const Word32 element_brate /* i : element bitrate */ +); + +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 */ +); + +void ivas_quantise_real_values_fx( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim ); + +void ivas_quantise_real_values_enc_fx( + const Word32 *values_fx, // Q28 + const Word16 q_levels, + const Word32 min_value_fx, // Q28 + const Word32 max_value_fx, // Q28 + Word16 *index, + Word32 *quant_fx, // Q28 + const Word16 dim ); + +void ivas_quantise_real_values_enc_fx_varq( + const Word32 *values_fx, + const Word16 q_levels, + const Word32 min_value_fx, + const Word32 max_value_fx, + Word16 *index, + Word32 *quant_fx, + const Word16 dim, + Word16 inp_q ); + +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max ); + +void ivas_spar_quant_dtx_init_fx( + ivas_spar_md_t *spar_md, + Word32 *min_max ); + +void ivas_copy_band_coeffs_idx_to_arr( + ivas_band_coeffs_ind_t *pBands_idx, + const Word16 nB, + Word16 *pSymbol_re, + ivas_cell_dim_t *pCell_dims, + const ivas_coeffs_type_t coeff_type ); + +void ivas_clear_band_coeffs_fx( + ivas_band_coeffs_t *pband_coeffs, + const UWord16 num_bands ); + +Word16 ivas_qmetadata_DecodeExtendedGR( + UWord16 *bitstream, + Word16 *index, + const Word16 alph_size, + const Word16 gr_param ); + +void ivas_masa_combine_directions_fx( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +); + +/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ +Word16 ivas_get_df_ratio_bits_hodirac( + const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ +); + +/*! r: Bits to be used for quantizing distribution ratio of direct-to-total ratios */ +Word16 ivas_get_df_ratio_bits( + const Word16 index_diff /* i : index of quantized diffuse-to-total ratio */ +); + +void invdct4_transform_fx( + Word32 *v_fx, /* i : input vector */ + UWord8 *invdct_v, /* o : transformed vector */ + Word16 q ); + +void ivas_spar_param_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], + const Word16 subframe /* i : Subframe to map */ +); + +ivas_error ivas_binRenderer_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_binRenderer_close_fx( + BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: decoder binaural renderer handle */ +); + +void ivas_init_binaural_hrtf_fx( + HRTFS_FASTCONV *HrtfFastConv /* i/o: FASTCONV HRTF structure */ +); + +ivas_error ivas_allocate_binaural_hrtf_fx( + HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ + const AUDIO_CONFIG input_config, /* i : input audio configuration */ + const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const Word16 allocate_init_flag /* i : Memory allocation flag */ +); + +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 Word16 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 */ +); + +void ivas_binaural_add_LFE_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 output_frame, /* i : length of input frame */ + Word32 *input_fx[], /* i : transport channels */ + Word32 *output_fx[] /* o : synthesized core-coder transport channels/DirAC output */ +); + +void ivas_mc2sba_fx( + IVAS_OUTPUT_SETUP hIntSetup, /* i : Format of decoder output */ + Word32 *in_buffer_td[], /* i : MC signals (on input) and the HOA3 (on output) */ + Word32 *buffer_td[], /* 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 /* i : gain for LFE, 0 = ignore LFE */ +); + +void ivas_param_mc_mc2sba_cldfb_fx( + IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ + Word32 *hoa_encoder, /* i : HOA3 encoder for the transported MC format */ + const Word16 slot_idx, /* i : current slot in the subframe */ + Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */ + Word32 Cldfb_ImagBuffer[][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 gain_lfe /* i : gain applied to LFE */ +); + +void ivas_ism2sba_sf_fx( + Word32 *buffer_in_fx[], /* i : TC buffer */ + 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 */ +); + +void panning_wrap_angles_fx( + const Word32 azi_deg, /* i : azimuth in degrees for panning direction (positive left) Q22 */ + const Word32 ele_deg, /* i : elevation in degrees for panning direction (positive up) Q22 */ + Word32 *azi_wrapped, /* o : wrapped azimuth component Q22 */ + Word32 *ele_wrapped /* o : wrapped elevation component Q22 */ +); + +void v_sort_ind_fixed( + Word32 *x, /* i/o: Vector to be sorted */ + Word16 *idx, /* o : Original index positions */ + const Word16 len /* i : vector length */ +); + +void ivas_ls_setup_conversion_process_mdct_param_mc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *x_fx[][NB_DIV], /* i/o: Fixed output synthesis signal */ + Word16 x_e[CPE_CHANNELS][NB_DIV] /* i/o: Exponent for output synthesis signal */ +); + +void lls_interp_n_fx( + 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 */ + const Word16 upd /* i : use 1 to update x[] with the interpolated output */ +); + +void ivas_lfe_synth_with_filters_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, /* i/o: LFE synthesis structure for McMASA */ + Word32 *data_f[], /* o : output signals */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 separateChannelIndex, /* i : separate channel index */ + const Word16 lfeChannelIndex /* i : LFE channel index */ +); + +void ivas_lfe_enc_fx( + LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ + Word32 data_lfe_ch[], /* i : input LFE signal */ + Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ + const Word16 input_frame, /* i : input frame length per channel */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +); + +void ivas_filter_process_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + Word32 *pIn_Out_fx, /* i : signal subject to filtering */ + const Word16 length, /* i : filter order */ + Word16 q_factor ); + +ivas_error ivas_osba_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_osba_enc_close_fx( + OSBA_ENC_HANDLE *hOSba /* i/o: encoder OSBA handle */ +); + +void ivas_osba_enc_fx( + OSBA_ENC_HANDLE hOSba, /* i/o: OSBA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + Word32 *data_in_fx[], /* i/o: Input / transport audio signals */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word16 sba_analysis_order, /* i : SBA order evaluated in DirAC/SPAR encoder */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 sba_planar, /* i : planar SBA flag */ + Word16 *q_data ); + +ivas_error ivas_osba_data_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); +ivas_error ivas_osba_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* 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*/ +); + +ivas_error ivas_osba_ism_metadata_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + Word16 *nchan_ism, /* o : number of ISM separated channels */ + Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ +); + +ivas_error ivas_osba_render_sf_fx( + 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 */ +); + +void ivas_osba_data_close_fx( + SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle */ +); + +void ivas_set_ism_importance_interformat_fx( + const Word32 ism_total_brate, /* i/o: ISms total bitrate */ + const Word16 nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const Word16 lp_noise_CPE_fx, /* i : LP filtered total noise estimation */ + Word16 ism_imp[] /* o : ISM importance flags */ +); + +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /*cldfb_buf_q*/ + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe ); + + +void ivas_omasa_decode_masa_to_total_fx( + UWord16 *bit_stream, + Word16 *index, + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + const Word16 nbands, + const Word16 nblocks ); + + +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 ); + +ivas_error ivas_td_binaural_renderer_fx( + 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 */ +); + +void ivas_FB_mixer_close_fx( + IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ + const Word32 sampling_rate, /* i : sampling rate in Hz */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +void ivas_fb_mixer_pcm_ingest_fx( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ + Word32 **ppOut_pcm, /* o : output audio channels Qq_ppOut_pcm[] */ + const Word16 frame_len, /* i : frame length */ + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], + Word16 q_data_fix[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS], + Word16 *q_ppOut_pcm ); + +void ivas_fb_mixer_process( + IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ + Word32 ***mixer_mat_fx, /* i : mixer matrix in q_mixer_mat_fx */ + Word16 *q_mixer_mat_fx, /* i : mixer matrix */ + Word32 **ppOut_pcm_fx, /* o : output audio channels in ppOut_pcm_fx resultant */ + Word16 *q_ppOut_pcm_fx, /*ppOut_pcm_fx resultant q*/ + const Word16 frame_len, /* i : frame length in samples */ + Word16 in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ +); + +Word16 ivas_get_num_bands_from_bw_idx( + const Word16 bwidth /* i : audio bandwidth */ +); + +void sns_avq_dec_fx( + Word16 *index, /* i : Quantization indices */ + Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ + Word16 *q_snsq, + const Word16 L_frame, /* i : frame length */ + const Word16 numlpc /* i : Number of sets of lpc */ +); + +void sns_avq_dec_stereo_fx( + Word16 *indexl, /* i : Quantization indices (left channel) */ + Word16 *indexr, /* i : Quantization indices (right channe) */ + const Word16 L_frame, /* i : frame length */ + Word32 *SNS_Ql, /* o : Quantized SNS vectors (left channel) */ + Word16 *q_l, + Word32 *SNS_Qr, /* o : Quantized SNS vectors (right channe) */ + Word16 *q_r ); + +void dequantize_sns_fx( + Word16 indices[CPE_CHANNELS][NPRM_LPC_NEW], + Word32 snsQ_out[CPE_CHANNELS][NB_DIV][M], + Decoder_State **sts ); + +void inverseMS_fx( + const Word16 L_frame, /* i : frame length Q0*/ + Word32 x0[], /* i/o: mid/left channel coefficients Qx*/ + Word32 x1[], /* i/o: side/right channel coefficients Qx*/ + const Word32 norm_fac /* i : normalization factor Q31*/ +); + +void ivas_syn_output_f_fx( + Word32 *synth[], /* i/o: Word32 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 */ +); + + +ivas_error ivas_init_encoder_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_output_buff_dec_fx( + 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 */ +); + +ivas_error ivas_dec_setup( + 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 */ +); + +ivas_error create_mct_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error mct_dec_reconfigure_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 b_nchan_change /* i : flag indicating different channel count */ +); + +ivas_error ivas_corecoder_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSCE_old, /* i : number of SCEs in previous frame */ + Word16 nCPE_old, /* i : number of CPEs in previous frame */ + const Word16 nchan_transport_old, /* i : number of TCs in previous frame */ + const Word16 sba_dirac_stereo_flag_old, /* i : signal stereo rendering using DFT upmix in previous frame */ + const Word32 brate_SCE, /* i : bitrate to be set for the SCEs */ + const Word32 brate_CPE /* i : bitrate to be set for the CPEs */ +); + +ivas_error ivas_hp20_dec_reconfig_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nchan_hp20_old /* i : number of HP20 filters in previous frame*/ +); + +Word16 getNumChanSynthesis( + Decoder_Struct *st_ivas /* i : IVAS decoder structure */ +); + +void ivas_destroy_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_core_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const Word16 n_channels, /* i : number of channels to be decoded */ + Word32 *output_fx[], /* o : output synthesis signal */ + Word32 outputHB[][L_FRAME48k], /* o : output HB synthesis signal */ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); + +void decod_gen_2sbfr_ivas_fx( + Decoder_State *st, /* i/o: decoder static memory */ + const Word16 sharpFlag, /* i : formant sharpening flag `Q0*/ + const Word16 *Aq, /* i : LP filter coefficient Q12*/ + Word16 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + Word16 *gain_buf, /* o : Word16 pitch gain for each subframe Q14*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[] /* i : pitch values for primary channel Q6*/ +); + +Word16 ivas_smc_gmm_fx( + Encoder_State *st, /* i/o: state structure */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + const Word16 localVAD_HE_SAD, /* i : HE-SAD flag without hangover */ + const Word16 Etot_fx, /* i : total frame energy */ + Word16 lsp_new_fx[M], /* i : LSPs in current frame TODO:For now removing 'const' to avoid warning */ + Word16 cor_map_sum_fx, /* i : correlation map sum (from multi-harmonic anal.) */ + Word32 epsP_fx[M + 1], /* i : LP prediciton error TODO:For now removing 'const' to avoid warning */ + Word32 PS_fx[], /* i : energy spectrum TODO:For now removing 'const' to avoid warning */ + const Word16 non_sta_fx, /* i : unbound non-stationarity */ + const Word16 relE_fx, /* i : relative frame energy */ + Word16 *high_lpn_flag, /* i/o: sp/mus LPN flag */ + const Word16 flag_spitch /* i : flag to indicate very short stable pitch */ + , + Word16 Qfact_PS, + Word16 Q_esp, + Word16 Qfact_PS_past ); + +void ivas_signaling_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ +); + +void smooth_dft2td_transition_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i/o: synthesis @external Fs Q11*/ + const Word16 output_frame /* i : output frame lenght Q0*/ +); + + +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_mdft_fx( + const Word32 *pIn, /* i : input time-domain signal Qin */ + Word32 *pOut_re, /* o : Real part of MDFT signal Qin */ + Word32 *pOut_im, /* o : Imag. part of MDFT signal Qin */ + const Word16 length, /* i : signal length */ + const Word16 mdft_length /* i : MDFT length */ +); + +void ivas_imdft_fx( + const Word32 *pRe, /* i : Real part of MDFT signal Qin */ + const Word32 *pIm, /* i : Imag. part of MDFT signal Qin */ + Word32 *pOut, /* o : output time-domain signal Qin */ + const Word16 length /* i : signal length */ +); + +void TonalMdctConceal_create_concealment_noise_ivas_fx( + Word32 concealment_noise[L_FRAME48k], + Word16 *concealment_noise_exp, + CPE_DEC_HANDLE hCPE, + const Word16 L_frameTCX, + const Word16 L_frame, + const Word16 idchan, + const Word16 subframe_idx, + const Word16 core, + const Word16 crossfade_gain, + const TONALMDCTCONC_NOISE_GEN_MODE noise_gen_mode ); + + +Word16 rand_triangular_signed_fx( + Word16 *seed, + Word16 *exp_fac ); + +Word64 var_32_fx( + const Word32 *x, /* i : input vector */ + const Word16 len, /* i : length of inputvector */ + Word16 q /* q : q-factor for the array */ +); + +ivas_error ivas_jbm_dec_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *data_fx ); + +ivas_error ivas_jbm_dec_flush_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 tc_granularity_new, /* i : new renderer granularity */ + const RENDERER_TYPE renderer_type_old, /* i : old renderer type */ + const AUDIO_CONFIG intern_config_old, /* i : old internal config */ + const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */ + const MC_MODE mc_mode_old, /* i : old MC mode */ + const ISM_MODE ism_mode_old, /* i : old ISM mode */ + UWord16 *nSamplesRendered, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ +); + +void ivas_jbm_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + Word32 *data /* i/o: transport channels/output synthesis signal */ +); + +void ivas_jbm_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + Word32 *data /* i/o: transport channels/output synthesis signal */ +); + +void ivas_jbm_dec_get_adapted_subframes( + 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_get_md_map( + const Word16 default_len, /* i : default frame length in metadata slots */ + const Word16 len, /* i : length of the modfied frames in metadata slots */ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +); + +void ivas_jbm_dec_get_md_map_even_spacing( + const Word16 len, /* i : length of the modfied frames in metadata slots */ + const Word16 subframe_len, /* i : default length of a subframe */ + const Word16 offset, /* i : current read offset into the md buffer */ + const Word16 buf_len, /* i : length of the metadata buffer */ + Word16 *map /* o : metadata index map */ +); + +void bitbudget_to_brate( + const Word16 x[], /* i : bitbudgets */ + Word32 y[], /* o : bitrates */ + const Word16 N /* i : number of entries to be converted */ +); + +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize */ + Word32 *valQ, /* o : quantized value */ + 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 */ +); + +ivas_error ivas_set_ism_metadata_fx( + ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ + const Word32 azimuth, /* i : azimuth value */ + const Word32 elevation, /* i : elevation value */ + const Word16 radius_meta, /* i : radius */ + const Word32 yaw, /* i : yaw */ + const Word32 pitch, /* i : pitch */ + const Word16 non_diegetic_flag /* i : non-diegetic object flag */ +); + +ivas_error ivas_ism_metadata_enc( + Word32 *ism_total_brate, /* i/o: ISM total bitrate */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word16 nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + Word16 nb_bits_metadata[], /* o : number of metadata bits */ + const Word16 localVAD[], /* i : VAD flag */ + const Word16 ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ + const Word16 ism_extended_metadata_flag, /* i : Extended metadata flag */ + const Word16 lp_noise_CPE, /* i : LP filtered total noise estimation */ + const Word16 flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + Word16 *omasa_stereo_sw_cnt, + const Word16 ini_frame ); + +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 */ + UWord16 *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ + Word16 *data /* o : output synthesis signal */ +); + +ivas_error ivas_param_ism_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_ism_dec_close_fx( + PARAM_ISM_DEC_HANDLE *hParamIsmDec, /* i/o: decoder ParamISM handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ + const AUDIO_CONFIG output_config /* i : output audio configuration */ +); + +void ivas_ism_dec_digest_tc_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_ism_dec_digest_tc_fx( + 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 */ + Word16 q_tc_in ); + +void ivas_param_ism_dec_render_fx( + 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 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_f_fx[] ); + +void ivas_param_ism_params_to_masa_param_mapping_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +Word16 ivas_ism_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 vad_flag[MAX_NUM_OBJECTS], /* i : VAD flag */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + Word16 md_diff_flag[], /* o : metadata differential flag */ + Word16 *sid_flag /* o : indication of SID frame */ +); + +void ivas_ism_dtx_dec_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word16 *nb_bits_metadata /* o : number of metadata bits */ +); + +void ivas_ism_get_sce_id_dtx_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length per channel */ +); + +void ivas_ism_coh_estim_dtx_enc_fx( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + SCE_ENC_HANDLE hSCE[MAX_SCE], /* i/o: SCE encoder structure */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 input_frame /* i : input frame length */ +); + +void ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( + SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder structures */ + const Word16 sce_id_dtx, /* i : SCE DTX ID */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word16 *Q_cngNoiseLevel ); + + +ivas_error stereo_dft_enc_create_fx( + STEREO_DFT_ENC_DATA_HANDLE *hStereoDft, /* o : encoder DFT stereo handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + +void stereo_dft_enc_reset_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft /* i/o: encoder stereo handle */ +); + +void stereo_enc_itd_init_fx( + ITD_DATA_HANDLE hItd /* i/o: encoder ITD handle */ +); + +void stereo_dft_enc_update_fx( + STEREO_DFT_ENC_DATA_HANDLE hStereoDft, /* i/o: encoder stereo handle */ + const Word16 max_bwidth /* i : maximum encoded bandwidth */ +); + +void stereo_dft_quantize_res_gains_fx( + const Word32 *g, // Q31 + const Word32 *r, // Q31 + Word32 *gq, // Q31 + Word32 *rq, // Q31 + Word16 *ig, + Word16 *ir ); + +void stereo_dft_dequantize_itd_fx( + Word16 *ind, /* Q0 */ + Word32 *out, /* Q15 */ + const Word32 output_Fs /* Q0 */ +); + +Word16 stereo_dft_sg_recovery_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft /* i/o: Decoder DFT stereo handle */ +); + +Word16 res_bpf_adapt_ivas_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */ + const Word32 *bpf_error_signal_8k, /* i : BPF modification signal */ + Word32 res_buf[STEREO_DFT_N_8k], /* i : residual buffer Q_res */ + Word16 q_res ); + +void stereo_dft_dec_read_BS_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + Word32 *total_brate, /* o : total bitrate Q0*/ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder stereo handle */ + const Word16 bwidth, /* i : bandwidth Q0*/ + const Word16 output_frame, /* i : output frame length Q0*/ + Word32 res_buf_fx[STEREO_DFT_N_8k], /* o : residual buffer Q0*/ + Word16 *nb_bits, /* o : number of bits read Q0*/ + Word16 *coh_fx, /* i/o: Coherence Q15*/ + const Word16 ivas_format /* i : ivas format Q0*/ +); + +Word16 write_bitstream_adapt_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : values to be written in bitstream */ + const Word16 len, /* i : values vector length */ + const Word16 GR_ord, /* i : GR order to be used */ + const Word16 no_GR_ord /* i : speech/music 0/1 */ +); + +Word16 adapt_GR_ief_fx( + const Word16 *in, /* i : vector to encode */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *map0, /* i : mapping array */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + Word16 *nbits_diff, /* o : number bits in diff encoding */ + const Word16 side_gain_counter, /* i : number of frames since last abs coding */ + Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff */ + Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); + +Word16 adapt_GR_rpg1_ief( + const Word16 *in, /* i : res pred gains input vector */ + Word16 *in_diff, /* o : encoded symbols in case of differential encoding */ + const Word16 *prev, /* i : previous frame data */ + const Word16 len, /* i : input vector length */ + const Word16 no_symb, /* i : number of symbols */ + Word16 *nbits, /* o : number of used bits */ + Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */ + const Word16 *maps, /* i : mapping array */ + Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */ + const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */ + const Word16 try_diff /* i : diff coding allowed 1/0 */ +); + +Word16 write_GR1( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); + +Word16 write_bitstream_GR( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : input vector */ + const Word16 len, /* i : input vector length */ + const Word16 GR_ord /* i : GR order */ +); + +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 */ +); + +void rc_uni_dec_init_fx( + RangeUniDecState *rc_st_dec, /* i/o: RC state handle */ + UWord16 *bit_buffer, /* i : Bit buffer */ + const Word16 max_available_bits /* i : Total maximum bits available */ +); + +UWord16 rc_uni_dec_read_symbol_fastS_fx( + RangeUniDecState *rc_st_dec, /* i/o: Decoder State */ + const UWord16 cum_freq_table[], /* i : Cumulative frequency up to symbol */ + const UWord16 sym_freq_table[], /* i : Symbol frequency */ + const UWord16 alphabet_size, /* i : Number of symbols in the alphabet */ + const UWord16 tot_shift /* i : Total frequency as a power of 2 */ +); + +Word16 rc_uni_dec_virtual_finish_fx( + RangeUniDecState *rc_st_dec /* i/o: RC state handle */ +); + +void unclr_classifier_dft_fx( + CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structure */ +); + +void xtalk_classifier_dft_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + const Word16 itd, /* i : ITD from DFT stereo - used as a feature */ + const Word32 gcc_phat[] /* i : GPHAT cross-channel correlation function Q31*/ +); + +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 */ +); + +ivas_error stereo_set_tdm_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word16 input_frame, /* i : input frame length per channel */ + Word16 input_q ); + +void stereo_tdm_prep_dwnmx_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word32 *input1, /* i : right channel input */ + const Word16 input_frame, /* i : frame lenght */ + const Word16 input_q /* i : frame lenght */ +); + +void tdm_upmix_plain_fx( + Word32 Left_fx[], /* o : left channel Qx*/ + Word32 Right_fx[], /* o : right channel Qx*/ + const Word32 PCh_2_L_fx[], /* i : primary channel Qx*/ + const Word32 SCh_2_R_fx[], /* i : secondary channel Qx*/ + const Word32 LR_ratio_fx, /* i : mixing ratio Q31*/ + const Word32 inv_den_LR_ratio_fx, /* i : inverse mixing ration Q31*/ + const Word16 start_index, /* i : start index Q0*/ + const Word16 end_index, /* i : end index Q0*/ + const Word16 plus_minus_flag /* i : plus/minus flag Q0*/ +); + +void stereo_tdm_combine_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *PCh_2_L_fx, /* i/o: Primary channel -> output as left channel Qx*/ + Word32 *SCh_2_R_fx, /* i/o: Secondary channel -> output as right channel Qx*/ + const Word16 output_frame, /* i : Number of samples Q0*/ + const Word16 flag_HB, /* i : flag to distinguish between core (0) and HB (1) synthesis Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ +); + +Word16 tdm_lp_comparison_fx( + STEREO_TD_ENC_DATA_HANDLE hStereoTD, /* i/o: TD stereo encoder handle */ + STEREO_CLASSIF_HANDLE hStereoClassif, /* i/o: stereo classifier structure */ + Encoder_State *st, /* i/o: Encoder structure */ + Word32 *speech_buff, /* i : Current speech frame Q_speech */ + const Word16 *A_PCh_fx, /* i : primary channel LP coefficients Q12*/ + const Word16 *A_SCh_fx, /* i : secondary channel LP coeff. Q12*/ + const Word16 m, /* i : filter length */ + const Word32 *isp_PCh_fx, /* i : primary channel LSPs Q31 */ + const Word32 *isp_SCh_fx, /* i : secondary channel LSPs Q31 */ + const Word16 L_frame, /* i : frame length */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata*/ + Word16 Q_speech ); + +ivas_error signaling_enc_secondary_fx( + Encoder_State *st, /* i/o: Encoder structure */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ +); + +void tdm_low_rate_enc( + Encoder_State *st, /* i/o: State structure */ + const Word16 Aq[], /* i : 12k8 Lp coefficient */ + const Word16 *res, + /* i : residual signal */ // Q_new + Word16 *synth, + /* i/o: core synthesis */ // Q_new + Word16 *exc_fx, + /* 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_fx, + /* o : excitation for SWB TBE */ // Q_new + const Word16 attack_flag, /* i : attck flag */ + const Word16 *lsf_new, + /* i : current frame ISF vector */ // x2.56 + Word16 *tmp_noise, + /* o : long-term noise energy */ // Q8 + Word16 *Q_new ); + +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 *pitch_buf, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 *exc, /* i/o: adapt. excitation exc Q_exc*/ + Word16 *exc2, /* i/o: adapt. excitation/total exc Q_exc*/ + Word16 *bwe_exc, /* o : excitation for SWB TBE Q_exc*/ + const Word16 *lsf_new /* i : ISFs at the end of the frame Q8/100 (2.56x)*/ +); + +void tdm_SCh_LSF_intra_pred_fx( + const Word32 element_brate, /* i : element bitrate */ + const Word16 *tdm_lsfQ_PCh_fx, /* i : primary channel LSFs */ + Word16 *pred_lsf_SCh_fx /* o : predicted secondary channel LSFs */ +); + +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 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 */ +); + +void EstimateStereoTCXNoiseLevel_fx( + Encoder_State **sts, /* i : state handle */ + Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i : quantized MDCT spectrum */ + Word16 gain_tcx[][NB_DIV], /* i : global gain */ + Word16 gain_tcx_e, /* i : global gain exponent */ + Word16 L_frame[][NB_DIV], /* i : frame length */ + Word16 noiseFillingBorder[][NB_DIV], /* i : noise filling border */ + Word16 hm_active[][NB_DIV], /* i : flag indicating if the harmonic model is active */ + const Word16 ignore_chan[], /* i : flag indicating whether the channel should be ignored */ + Word16 fac_ns[][NB_DIV], /* o : noise filling level */ + Word16 param_core[][NB_DIV * NPRM_DIV], /* o : quantized noise filling level */ + const Word16 MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +); + +void TNSAnalysisStereo_fx( + Encoder_State **sts, /* i : encoder state handle */ + Word32 *mdst_spectrum_fx[CPE_CHANNELS][NB_DIV], /* o : MDST spectrum Qx*/ + const Word16 bWhitenedDomain, /* i : whitened domain flag Q0*/ + Word16 tnsSize[CPE_CHANNELS][NB_DIV], /* i : number of tns parameters put into prm Q0*/ + Word16 tnsBits[CPE_CHANNELS][NB_DIV], /* i : number of tns bits in the frame Q0*/ + Word16 param_core[][NB_DIV * NPRM_DIV], /* o : TNS parameters Q0*/ + const Word16 mct_on /* i : flag mct block (1) or stereo (0) Q0*/ +); + +void init_tcx_enc_info_fx( + Encoder_State *st, /* i/o: coder memory state */ + Word16 *L_frame, + Word16 *L_frameTCX, + Word16 *L_spec ); + +void SetCurrentPsychParams( + const Word16 core, + const Word16 last_frame_was_concealed_cng, + TCX_CONFIG_HANDLE hTcxCfg ); + +void sns_avq_cod_fx( + const Word32 *sns_fx, /* i : Input sns vectors */ + Word16 exp_sns, + const Word32 *snsmid_fx, /* i : Input mid-sns vectors */ + Word16 exp_snsmid, + Word32 *sns_q_fx, /* o : Quantized LFS vectors Q16 */ + Word32 *snsmid_q_fx, /* o : Quantized mid-LFS vectors Q16 */ + Word16 *index, /* o : Quantization indices */ + const Word16 core, /* i : core */ + const Word16 L_frame, + const Word16 low_brate_mode /* i : flag low bit operating mode */ +); + +void sns_avq_cod_stereo_fx( + const Word32 *snsl_fx, /* i : Input sns vector (left channel) */ + Word16 exp_snl, + const Word32 *snsr_fx, /* i : Input sns vector (right channel) */ + Word16 exp_snr, + const Word16 L_frame, + Word32 *snsl_q_fx, /* o : Quantized sns vector (left channel) Q16 */ + Word32 *snsr_q_fx, /* o : Quantized sns vector (right channel) Q16 */ + Word16 *indexl, /* o : Quantization indices (left channel) */ + Word16 *indexr /* o : Quantization indices (right channel) */ +); + +ivas_error initMdctStereoDtxData_fx( + CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ +); + +void applyDmxMdctStereo_fx( + const CPE_DEC_HANDLE hCPE, /* i : CPE handle */ + Word32 *output_fx[CPE_CHANNELS], /* o : output from core decoder q_out*/ + const Word16 output_frame /* i : output frame length Q0*/ +); + +ivas_error front_vad_create_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad, /* i/o: front-VAD handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + +void front_vad_destroy_fx( + FRONT_VAD_ENC_HANDLE *hFrontVad /* i/o: front-VAD handle */ +); + +ivas_error front_vad_fx( + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure, nullable */ + Encoder_State *st, /* i/o: encoder state structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + FRONT_VAD_ENC_HANDLE *hFrontVads, /* i/o: FrontVad handles */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word16 input_frame, /* i : frame length */ + Word16 vad_flag_dtx[], /* o : HE-SAD flag with additional DTX HO */ + Word32 fr_bands_fx[][2 * NB_BANDS], /* o : energy in frequency bands Q_buffer[n] + QSCALE + 2 */ + Word16 Etot_LR_fx[], /* o : total energy Left & Right channel Q8 */ + Word32 lf_E_fx[][2 * VOIC_BINS], /* i : per bin spectrum energy in lf, LR channels Q_buffer[n] + QSCALE */ + Word16 localVAD_HE_SAD[], /* o : HE-SAD flag without hangover, LR channels */ + Word16 vad_hover_flag[], /* o : VAD hangover flag */ + Word32 band_energies_LR_fx[2 * NB_BANDS], /* o : energy in critical bands without minimum noise floor E_MIN Q_buffer[1] + QSCALE + 2 - band_ener_guardbits*/ + Word32 *PS_out_fx, /* o : energy spectrum Q_buffer + QSCALE */ + Word16 *Bin_E_out_fx, /* o : log-energy spectrum of the current frame Q7 */ + Word16 Q_inp, + Word16 *Q_buffer, + Word16 Q_add, + Word16 *front_create_flag ); + +void stereo_cna_update_params_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx[CPE_CHANNELS], /* i : Output signal OUTPUT_Q*/ + const Word16 output_frame, /* i : Output frame length Q0*/ + const Word16 tdm_ratio_idx /* i : TDM ratio index Q0*/ +); + +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 */ +); + +void mvr2r_inc_fixed( + 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 */ +); + +void v_mult_inc_fx( + const Word32 x1_fx[], /* i : Input vector 1 */ + Word16 *x1_q_fx, + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + Word16 *x2_q_fx, + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word16 *y_q_fx, + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ +); + +void v_add_inc_fx( + 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 */ +); +Word32 logsumexp_fx( + const Word32 x[], /* i : input array x */ + const Word16 x_e, + const Word16 N /* i : number of elements in array x */ +); +Word32 lin_interp32_fx( + const Word32 x, /* i : the value to be mapped */ + const Word32 x1, /* i : source range interval: low end */ + const Word32 y1, /* i : source range interval: high end */ + const Word32 x2, /* i : target range interval: low */ + const Word32 y2, /* i : target range interval: high */ + const Word16 flag_sat, /* i : flag to indicate whether to apply saturation */ + Word16 *Q_io /*i/o : i/o Q factor of the output*/ +); + +void v_addc_fx( + const Word32 x_fx[], /* i : Input vector */ + const Word32 c_fx, /* i : Constant */ + Word32 y_fx[], /* o : Output vector that contains c*x */ + const Word16 N /* i : Vector length */ +); + +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 */ +); + +void v_min_fx( + const Word32 x1_fx[], /* i : Input vector 1 */ + Word16 *x1_q_fx, + const Word32 x2_fx[], /* i : Input vector 2 */ + Word16 *x2_q_fx, + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + Word16 *y_q_fx, + const Word16 N /* i : Vector length */ +); + +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 */ +); + +void v_sqrt_fx( + const Word32 x[], /* i : Input vector */ + Word16 exp[], + Word32 y[], /* o : Output vector that contains sqrt(x) */ + const Word16 N /* i : Vector length */ +); + +Word32 sumAbs_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec /* i : length of input vector */ +); + +Word32 dot_product_cholesky_fx( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N /* i : vector & matrix size */ +); +Word32 dot_product_cholesky_fixed( + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : Cholesky matrix A */ + const Word16 N, /* i : vector & matrix size */ + const Word16 exp_x, + const Word16 exp_A, + Word16 *exp_sum ); + +void v_mult_mat_fx( + Word32 *y_fx, /* o : the product x*A */ + Word16 *y_q_fx, + const Word32 *x_fx, /* i : vector x */ + Word16 *x_q_fx, + const Word32 *A_fx, /* i : matrix A */ + Word16 *A_q_fx, + const Word16 N, /* i : number of rows */ + const Word16 C /* i : number of columns */ +); +void v_mult_mat_fixed( + Word32 *y, /* o : the product x*A */ + const Word32 *x, /* i : vector x */ + const Word32 *A, /* i : matrix A */ + const Word16 Nr, /* i : number of rows */ + const Word16 Nc, /* i : number of columns */ + Word16 guardbits ); + +Word32 check_bounds_l( + const Word32 value, /* i : Input value */ + const Word32 low, /* i : Low limit */ + const Word32 high /* i : High limit */ +); + +Word16 check_bounds_s_fx( + const Word16 value, /* i : Input value */ + const Word16 low, /* i : Low limit */ + const Word16 high /* i : High limit */ +); + +ivas_error stereo_memory_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 max_bwidth, /* i : maximum audio bandwidth */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 nchan_transport /* i : number transport chans */ + +); + +void stereo_switching_enc_fx( + CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ + Word16 old_input_signal_pri[], /* i : old input signal of primary channel */ + const Word16 input_frame, /* i : input frame length */ + const Word16 q_inp ); + + +void stereo_td2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number Q0*/ + Word32 output_fx[], /* i/o: synthesis @internal Fs Q11*/ + Word32 synth_fx[], /* i/o: synthesis @output Fs Q11*/ + Word32 hb_synth_fx[], /* i/o: hb synthesis Q11*/ + const Word16 output_frame /* i : frame length Q0*/ +); + +void stereo_mdct2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 Q11*/ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 Q11*/ +); + +Word16 write_GR0( + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ + const Word16 ind, /* i : bitstream index */ + const Word16 *in, /* i : data to be encoded */ + const Word16 len /* i : input data length */ +); + +void ivas_mct_core_dec( + 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 */ + Word32 *signal_out_fx[], + Word16 q_x[MCT_MAX_CHANNELS] ); + +void ivas_qmetadata_to_dirac_fx( + const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ + DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ + MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const Word16 hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + Word16 *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ +); + +Word16 masa_sq_fx( + const Word32 in, /* i : input value */ + const Word32 *threshold, /* i : partition */ + const Word16 cb_sz /* i : codebook size */ +); + +Word16 quantize_direction2D_fx( + Word32 phi, /* i : input azimuth value Q22 */ + const Word16 no_cw, /* i : number of bits */ + Word32 *phi_q, /* o : quantized azimuth value Q22 */ + UWord16 *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +Word32 companding_azimuth_fx( + const Word32 azi_fx, /* i : input azimuth value */ + const MC_LS_SETUP mc_format, /* i : input channel format */ + const Word16 theta_flag, /* i : zero/non zero elevation flag */ + const Word16 direction /* i : direction of companding (direct or inverse)*/ +); + +Word16 quantize_phi_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word32 deindex_elevation_fx( + UWord16 *id_th, /* i : input index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +Word32 deindex_azimuth_fx( + Word16 id_phi, /* i : index */ + const Word16 no_bits, /* i : number of bits for the spherical grid */ + const Word16 id_th, /* i : elevation index */ + const Word16 remap, /* i : remapping flag */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); +void deindex_spherical_component_fx( + const UWord16 sph_idx, /* i : spherical index */ + Word32 *az_fx, /* o : decoded azimuth value */ + Word32 *el_fx, /* o : decoded elevation value */ + UWord16 *az_idx, /* o : azimuth index */ + UWord16 *el_idx, /* o : elevation index */ + const UWord16 no_bits, /* i : number of bits for the spherical grid */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ +); + +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const UWord8 useLowerRes, + Word32 *data_f_fx[], + Word32 **pp_fr_real_fx, + Word32 **pp_fr_imag_fx, + Word16 pp_fr_q, + const Word16 input_frame, + const IVAS_FORMAT ivas_format, + const Word16 hodirac_flag, + const Word16 nchan_fb_in, + Word16 *mono_frame_count, + Word16 *dirac_mono_flag ); + +ivas_error ivas_cldfb_dec_reconfig_fx( + 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 */ +); + +Word16 ivas_sba_get_order_fx( + const Word16 nb_channels, /* i : Number of ambisonic channels */ + const Word16 sba_planar /* i : SBA planar flag */ +); + +/*! r: Ambisonic (SBA) order used for analysis and coding */ +Word16 ivas_sba_get_analysis_order( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +Word16 ivas_sba_get_nchan_metadata( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_sba_get_spar_hoa_ch_ind( + const Word16 num_md_chs, /* i : number of MD channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); + +/*! r: flag indicating to code SPAR HOA MD for all bands */ +void ivas_sba_get_spar_hoa_md_flag( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 *spar_hoa_md_flag, + Word16 *spar_hoa_dirac2spar_md_flag ); + +Word16 ivas_sba_remapTCs_fx( + Word32 *sba_data[], /* i/o: SBA signals */ + Decoder_Struct *st_ivas, /* i/o: decoder struct */ + const Word16 output_frame /* i : frame length */ +); + +void ivas_sba2mc_cldfb_fixed( + IVAS_OUTPUT_SETUP hInSetup, /* i : Format of input layout */ + Word32 RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part (Q_real) */ + Word32 ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part (Q_imag) */ + const Word16 nb_channels_out, /* i : nb of output channels */ + const Word16 nb_bands, /* i : nb of CLDFB bands to process */ + const Word16 nb_timeslots, /* i : number of time slots to process */ + const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ +); + +void ivas_dirac_config_bands_fx( + Word16 *band_grouping, /* o : band grouping */ + const Word16 nbands, /* i : number of bands */ + const Word16 max_band, /* i : maximal band index +1 */ + Word16 *dirac_to_spar_md_bands, /* o : mapping of DirAC parameter band index to SPAR FB band index */ + const Word8 useLowerBandRes, /* i : flag indicating lower band resolution for DirAC */ + const Word16 enc_param_start_band, /* i : band index of first DirAC parameter band */ + IVAS_FB_MIXER_HANDLE hFbMdft ); + +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out ); + +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 */ +); + +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 */ +); + +void ivas_dirac_dec_close_fx( + DIRAC_DEC_HANDLE *hDirAC_out ); + +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 */ +); + +void computeDirectionVectors_fixed( + Word32 *intensity_real_x, + Word32 *intensity_real_y, + 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*/ ); + +void computeDirectionVectors_fx( + Word32 *intensity_real_x, + Word32 *intensity_real_y, + Word32 *intensity_real_z, + const Word16 enc_param_start_band, + const Word16 num_frequency_bands, + Word32 *direction_vector_x, + Word32 *direction_vector_y, + Word32 *direction_vector_z, + Word16 *q_factor ); + + +void computeDiffuseness_fx( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness, + Word16 q_factor_intensity, + Word16 q_factor_energy, + Word16 *out_exp + +); + +void computeDiffuseness_fixed( + Word32 *buffer_intensity[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF], + const Word32 *buffer_energy, + const Word16 num_freq_bands, + Word32 *diffuseness, + Word16 *q_factor_intensity, + Word16 *q_factor_energy, + Word16 *q_diffuseness ); + +void ivas_dirac_dec_get_response_fx( + const Word16 azimuth, + const Word16 elevation, + Word32 *response, + const Word16 ambisonics_order, + Word16 Q_out ); + +void calculate_hodirac_sector_parameters_fx( + DIRAC_ENC_HANDLE hDirAC, /* i : DirAC handle */ + Word32 RealBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector (L+1)^2 x N_bins, real part */ + Word32 ImagBuffer_fx[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : signal vector, imaginary part */ + Word16 Qfac, /* i : Q-factor of signal vector */ + const Word32 beta_fx, /* i : forgetting factor for average filtering, Q30 */ + const Word16 *band_grouping, /* i : indices of band groups */ + const Word16 N_bands, /* i : number of bands (groups) */ + const Word16 enc_param_start_band, /* i : first band to process */ + Word32 *azi_fx, /* o : array of sector azimuth angles, flat Q23 */ + Word32 *ele_fx, /* o : array of sector elevation angles, flat Q23 */ + Word32 *diff_fx, /* o : array of sector diffuseness values, flat */ + Word16 *diff_exp, /* o : array of sector diffuseness exponents, flat */ + Word32 *ene_fx, /* o : array of sector energy values, flat */ + Word16 *ene_exp /* o : array of sector energy exponents, flat */ +); + +void ivas_mc_paramupmix_enc_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + Word32 *data_fx[], + const Word16 input_frame /* i : input frame length */ +); + +void ivas_mc_paramupmix_dec_render( + 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 *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 */ +); + +Word16 ivas_param_mc_getNumTransportChannels( + const Word32 ivas_total_bitrate, /* i : IVAS total bitrate */ + const MC_LS_SETUP mc_ls_setup /* i : MC ls setup */ +); + +ivas_error ivas_param_mc_dec_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +ivas_error ivas_param_mc_dec_reconfig_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_param_mc_dec_close_fx( + PARAM_MC_DEC_HANDLE *hParamMC_out /* i/o: Parametric MC decoder handle */ +); + +void ivas_param_mc_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + Word32 *transport_channels_f_fx[], + Word16 transport_f_e ); + +void ivas_param_mc_dec_render_fx( + 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 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *output_f_fx[], /* o : rendered time signal */ + Word16 channel_active_fx[MAX_OUTPUT_CHANNELS] ); + +Word16 matrix_product_mant_exp_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 X_fx_e, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 Y_fx_e, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + Word16 *Z_fx_e /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication */ +); + +Word16 matrix_product_mant_exp( + const Word32 *X_fx, /* i : left hand matrix */ + const Word16 *X_e, /* i : left hand matrix */ + const Word16 rowsX, /* i : number of rows of the left hand matrix */ + const Word16 colsX, /* i : number of columns of the left hand matrix */ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication */ + const Word32 *Y_fx, /* i : right hand matrix */ + const Word16 *Y_e, /* i : right hand matrix */ + const Word16 rowsY, /* i : number of rows of the right hand matrix */ + const Word16 colsY, /* i : number of columns of the right hand matrix */ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication */ + Word32 *Z_fx, /* o : resulting matrix after the matrix multiplication */ + Word16 *Z_e /* o : resulting matrix after the matrix multiplication */ +); + +void mat2svdMat_fx( + const Word32 *mat, /* i : matrix as column ordered vector Qx*/ + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* o : matrix as two-dimensional arry Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols, /* i : number of columns of the matrix Q0*/ + const Word16 transpose /* i : flag indication transposition Q0*/ +); + +void svdMat2mat_fx( + Word32 svdMat[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS], /* i : matrix as two-dimensional arry Qx*/ + Word32 *mat, /* o : matrix as column ordered vector Qx*/ + const Word16 nRows, /* i : number of rows of the matrix Q0*/ + const Word16 mCols /* i : number of columns of the matrix Q0*/ +); + +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 */ + Word16 Cx_e, + const Word32 *Cy, /* i : target covariance matrix */ + Word16 Cy_e, + 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 */ + Word16 reg_Sx_e, + const Word32 reg_ghat_fx, /* i : regularization factor for the normalization matrix */ + Word16 reg_ghat_e, + Word32 *mixing_matrix_fx, /* o : resulting mixing matrix */ + Word16 *mixing_matrix_out_e, + Word32 *Cr_fx, /* o : residual covariance matrix */ + Word16 *Cr_e ); + +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 Word16 Cx_e, + 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 Word16 reg_Sx_e, + 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 ); + +Word16 svd_fx( + Word32 InputMatrix[][MAX_OUTPUT_CHANNELS], /* i : matrix to be decomposed (M) InputMatrix_e*/ + 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) singularValues_fx_e*/ + Word32 singularVectors_Right_fx[][MAX_OUTPUT_CHANNELS], /* o : right singular vectors (V) Q31*/ + Word16 singularValues_fx_e[MAX_OUTPUT_CHANNELS], + const Word16 nChannelsL, /* i : number of rows in the matrix to be decomposed Q0*/ + const Word16 nChannelsC /* i : number of columns in the matrix to be decomposed Q0*/ +); + +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) */ +); + +void ivas_dirac_dec_output_synthesis_get_interpolator_fx( + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params, /* i/o: handle for the covariance synthesis parameters */ + const UWord16 interp_length /* i : interpolator length */ +); + +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 */ +); + +void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( + Word32 *Cldfb_RealBuffer_in_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 */ +); + +Word16 computeMixingMatricesISM_fx( + const Word16 num_inputs, + const Word16 num_responses, + const Word16 num_outputs, + const Word32 *responses_fx, + const Word16 responses_e, + const Word32 *ener_fx, + const Word16 ener_e, + const Word32 *Cx_diag_fx, + const Word16 Cx_diag_e, + const Word32 *Cy_diag_fx, + const Word16 Cy_diag_e, + const Word16 *Q_16fx, // Q15 + const Word16 energy_compensation_flag, + const Word32 reg_Sx_fx, + const Word32 reg_ghat_fx, + Word32 *mixing_matrix_fx, + Word16 *mixing_matrix_e ); + +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 */ +); + +void ivas_spar_dec_close_fx( + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + +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 */ + const AUDIO_CONFIG output_config, /* i : output audio configuration */ + const IVAS_OUTPUT_SETUP output_setup /* i : output format setup */ +); + +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 */ + 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*/ + const Word16 Q_output /* i : Q of transport/output audio channels */ +); + +Word16 ivas_agc_enc_get_flag( + const Word16 nchan_transport /* i : number of transport channels */ +); + +ivas_error ivas_spar_agc_enc_open_fx( + ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_spar_agc_enc_close_fx( + ivas_agc_enc_state_t **hAgcEnc /* i/o: SPAR AGC encoder handle */ +); + +void ivas_agc_enc_process_fx( + ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + Word32 **ppPcm_in, /* i : input audio channels */ + Word32 **ppPcm_out, /* o : output audio channels */ + const Word16 n_channels, /* i : number of channels */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + Word16 *q_ppPcm ); + +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 ); + +Word16 ivas_is_res_channel( + const Word16 ch, /* i : ch index in WYZX ordering */ + const Word16 nchan_transport /* i : number of transport channels (1-4) */ +); + +void ivas_spar_dec_agc_pca_fx( + 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 */ +); + +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 */ +); + +void ivas_spar_dec_set_render_params_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ +); + +void ivas_spar_dec_digest_tc_fx( + 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 */ +); + +void ivas_sba_dec_digest_tc_fx( + 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 */ +); +ivas_error ivas_sba_dec_render_fx( + 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 Q11*/ + Word16 out_len /*Store the length of values in each channel*/ +); + +void ivas_spar_dec_upmixer_sf_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output_fx[], /* o : output audio channels */ + const Word16 nchan_internal, /* i : number of internal channels */ + Word16 out_len ); + +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 */ +); + +void ivas_create_fullr_dmx_mat_fx( + 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 ***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 ); + +void ivas_get_spar_md_from_dirac_fx( + Word32 azi_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 + Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 + const Word16 n_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat_fx, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const Word16 start_band, + const Word16 end_band, + const Word16 order, + const Word16 dtx_vad, + Word32 Wscale_d[IVAS_MAX_NUM_BANDS], // Q29 + const UWord8 useLowerRes, + const Word16 active_w_vlbr, + const Word16 dyn_active_w_flag ); + +ivas_error ivas_spar_md_enc_process_fx( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *cov_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *cov_dtx_real_q[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const Word16 dtx_vad, + const Word16 nchan_inp, + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ +); + +Word16 ivas_get_spar_dec_md_num_subframes( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ +); + +void ivas_spar_get_parameters_fx( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const Word16 ts, /* i : time slot index */ + const Word16 num_ch_out, /* i : number of channels out */ + const Word16 num_ch_in, /* i : number of channels in */ + const Word16 num_spar_bands, /* i : number of SPAR bands */ + Word32 par_mat_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ +); + +void ivas_spar_to_dirac_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const Word16 dtx_vad, /* i : DTX frame flag */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bw, /* i : band joining factor */ + const Word16 dyn_active_w_flag /* i : dynamic active W flag */ +); + +void ivas_spar_dec_gen_umx_mat_fx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 num_bands_out, /* i : number of output bands */ + const Word16 bfi, /* i : bad frame indicator */ + const Word16 num_md_sub_frames ); + +ivas_error ivas_spar_covar_enc_open_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word32 input_Fs, /* i : input sampling rate */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC*/ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_spar_covar_enc_close_fx( + ivas_enc_cov_handler_state_t **hCovEnc, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_enc_cov_handler_process_fx( + ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ + Word32 **ppIn_FR_real, + Word32 **ppIn_FR_imag, + Word16 q_ppIn_FR, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH], + Word32 *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_dtx_real[IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 transient_det[2], + const Word16 HOA_md_ind[IVAS_SPAR_MAX_CH], + Word16 *res_ind, + const Word16 *remix_order, + Word16 *dyn_active_w_flag, + const Word16 nchan_transport, + const Word16 is_sba ); + +ivas_error ivas_spar_covar_smooth_enc_open_fx( + ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ + const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i : SPAR config. handle */ + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 nchan_inp, /* i : number of input channels */ + const COV_SMOOTHING_TYPE smooth_mode, /* i : Smooth covariance for SPAR or MC */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_spar_covar_smooth_enc_close_fx( + ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. encoder handle */ + const Word16 nchan_inp /* i : number of input channels */ +); + +void ivas_cov_smooth_process_fx( + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 transient_det[2], + Word16 *q_cov[IVAS_SPAR_MAX_CH] ); + +void ivas_pca_enc_fx( + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + PCA_ENC_STATE *hPCA, /* i : PCA encoder structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + Word32 *data_f[8], /* i : input/transformed audio channels Q11 */ + const Word16 input_frame, /* i : input frame length */ + const Word16 n_channels /* i : number of channels */ +); + +void cov_subfr_fx( + Word32 **ptr_sig_fx, // Q11 + Word64 *r_fx_64, // Q11 + const Word16 n_channels, + const Word16 len ); + +void ivas_pca_read_bits_fx( + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + PCA_DEC_STATE *hPCA /* i/o: PCA encoder structure */ +); + +void ivas_pca_dec_init_fx( + PCA_DEC_STATE *hPCA /* i/o: PCA decoder structure */ +); + +void ivas_pca_dec_fx( + PCA_DEC_STATE *hPCA, /* i/o: PCA decoder structure */ + const Word16 output_frame, /* i : output frame length */ + const Word16 n_channels, /* i : number of channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word32 last_ivas_total_brate, /* i : last IVAS total bitrate */ + const Word16 bfi, /* i : bad frame indicator */ + Word32 *pcm_out[] /* o : output audio channels */ +); + +void eye_matrix_fx( + Word16 *mat, + const Word16 n, + const Word16 d ); + +void eye_matrix_fx32( + Word32 *mat, // Q + const Word16 n, + const Word32 d ); // Q + +void eig_qr_fx( + const Word32 *A_fx, // A_q + Word16 A_q, + const Word16 num_iter, + Word32 *EV_fx, // Q31 + Word32 *Vals_fx, // A_q + const Word16 n ); + +void exhst_4x4_fx( + Word16 *cost_mtx, // Q + Word16 *path, + const Word16 maximize ); + +Word16 mat_det4_fx( + const Word16 *m // Q15 +); + +void mat2dquat_fx( + const Word16 *a, // Q15 + Word16 *ql, // Q15 + Word16 *qr // Q15 +); + +void dquat2mat_fx( + const Word16 *ql, + const Word16 *qr, + Word16 *m ); + +void quat_shortestpath_fx( + const Word16 *q00, + Word16 *q01, + const Word16 *q10, + Word16 *q11 ); + +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 ); + +void pca_dec_s3_fx( + const Word32 index, + Word16 *q ); + +void ivas_spar_huff_coeffs_com_init( + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +void ivas_spar_arith_coeffs_com_init( + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +void ivas_ari_start_decoding_14bits_ext_1_lfe( + Decoder_State *st, + Tastat *s, + Word16 *extra_bits_read ); + +UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( + Decoder_State *st, + Tastat *s, + const UWord16 *cum_freq, + Word16 *extra_bits_read ); + +void ivas_ari_done_decoding_14bits_ext_1_lfe( + Decoder_State *st, + const Word16 extra_bits_read ); + +Word16 quantize_phi_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word16 quantize_phi_enc_fx( + Word32 phi, /* i : azimuth value */ + const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ + Word32 *phi_hat, /* o : quantized azimuth */ + const Word16 n /* i : azimuth codebook size */ +); + +Word16 ivas_spar_chk_zero_coefs_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +); + +void pca_enc_s3_fx( + Word16 *q, // Q15 + Word32 *index ); + +void ivas_spar_get_uniform_quant_strat_fx( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const Word16 table_idx ); + +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 Word16 **ppFilt_coeff_e /* o : exponents of filter coefficients */ +); + +void ivas_filters_init_fx( + ivas_filters_process_state_t *filter_state, /* i/o: filter state handle */ + const Word32 *filt_coeff, /* i : filter coefficients */ + const Word16 *filt_coeff_e, /* i : exponents of filter coefficients */ + const Word16 order /* i : filter order */ +); + +void ivas_decision_matrix_enc_fx( + Encoder_State *st, /* i : encoder state structure */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 fft_buff[], /* i : FFT buffer */ + const Word32 enerBuffer[], /* i : energy buffer */ + Word16 enerBuffer_exp, + const Word16 last_element_mode /* i : last element mode */ +); + +void stereo_dft_dec_sid_coh_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const Word16 nbands, /* i : number of DFT stereo bands Q0*/ + Word16 *coh, /* i/o: coherence Q15*/ + Word16 *nb_bits /* i/o: number of bits read Q0*/ +); + +void stereo_tca_init_enc_fx( + STEREO_TCA_ENC_HANDLE hStereoTCA, /* i/o: Stereo ICA handle */ + const Word32 input_Fs /* i : input sampling frequency */ +); + +void stereo_tca_dec_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *synth[CPE_CHANNELS], /* i/o: output synth qsynth*/ + const Word16 output_frame /* i : length of a frame per channel Q0*/ +); + +void stereo_tca_scale_R_channel_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *output_fx, /* i/o: output synthesis, R channel q_out*/ + const Word16 output_frame /* i : frame length Q0*/ +); + +void adjustTargetSignal_fx( + Word32 *target_fx, + const Word16 prevShift, + const Word16 currShift, + const Word16 L_shift_adapt, + const Word16 method ); + +void stereo_icBWE_init_enc_fx( + STEREO_ICBWE_ENC_HANDLE hStereoICBWE /* i/o: Stereo inter-channel BWE handle */ +); + +void stereo_classifier_init_fx( + STEREO_CLASSIF_HANDLE hStereoClassif /* i/o: stereo classifier structure */ +); + +void stereo_td_init_dec_fx( + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode /* i : last element mode Q0*/ +); + +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 */ +); + +void deindex_sph_idx_fx( + const UWord16 sphIndex, /* i : Spherical index */ + const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ + Word32 *theta_fx, /* o : Elevation */ + Word32 *phi_fx /* o : Azimuth */ +); + +ivas_error ivas_dirac_enc_open_fx( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_dirac_enc_close_fx( + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ + const Word32 input_Fs /* i : input sampling_rate */ +); + +ivas_error ivas_dirac_enc_fx( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + Word32 *data_f[], /* i/o: SBA channels */ + Word32 **ppIn_FR_real, /* o : real freq domain values */ + Word32 **ppIn_FR_imag, /* o : imag freq domain values */ + Word16 pp_fr_q, + const Word16 input_frame, /* i : input frame length */ + const Word16 dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const Word16 hodirac_flag /* i : hodirac flag */ +); + +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 */ +); + +void ivas_spar_get_cldfb_gains_fx( + SPAR_DEC_HANDLE hSpar, + HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, + const DECODER_CONFIG_HANDLE hDecoderConfig ); + + #endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 552adb118..88821d0b3 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -990,25 +990,26 @@ void invdct4_transform( } #else void invdct4_transform_fx( - Word32 *v_fx, /* i : input vector */ - UWord8 *invdct_v, /* o : inverse transformed vector */ + Word32 *v_fx, /* i : input vector q */ + UWord8 *invdct_v, /* o : inverse transformed vector */ Word16 q ) { Word32 a_fx, b_fx, c_fx, d_fx; Word16 i; Word32 f_invdct_v_fx[4]; - a_fx = L_add( v_fx[0], v_fx[2] ); - b_fx = L_sub( v_fx[0], v_fx[2] ); - c_fx = L_shl( L_add( Mpy_32_32( 1402911360, v_fx[1] ), Mpy_32_32( 581104896, v_fx[3] ) ), Q31 - Q30 ); - d_fx = L_shl( L_sub( Mpy_32_32( 581104896, v_fx[1] ), Mpy_32_32( 1402911360, v_fx[3] ) ), Q31 - Q30 ); - f_invdct_v_fx[0] = L_shl( L_add( a_fx, c_fx ), 7 ); + a_fx = L_add( v_fx[0], v_fx[2] ); // q + b_fx = L_sub( v_fx[0], v_fx[2] ); // q + // 1.306562964876376f * 2 ^ 30 -> 1402911360, 0.541196100146198f * 2 ^ 30 -> 581104896 + c_fx = L_shl( L_add( Mpy_32_32( 1402911360, v_fx[1] ), Mpy_32_32( 581104896, v_fx[3] ) ), Q31 - Q30 ); // q + d_fx = L_shl( L_sub( Mpy_32_32( 581104896, v_fx[1] ), Mpy_32_32( 1402911360, v_fx[3] ) ), Q31 - Q30 ); // q + f_invdct_v_fx[0] = L_shl( L_add( a_fx, c_fx ), 7 ); // q move32(); - f_invdct_v_fx[1] = L_shl( L_add( b_fx, d_fx ), 7 ); + f_invdct_v_fx[1] = L_shl( L_add( b_fx, d_fx ), 7 ); // q move32(); - f_invdct_v_fx[2] = L_shl( L_sub( b_fx, d_fx ), 7 ); + f_invdct_v_fx[2] = L_shl( L_sub( b_fx, d_fx ), 7 ); // q move32(); - f_invdct_v_fx[3] = L_shl( L_sub( a_fx, c_fx ), 7 ); + f_invdct_v_fx[3] = L_shl( L_sub( a_fx, c_fx ), 7 ); // q move32(); FOR( i = 0; i < 4; i++ ) @@ -1022,10 +1023,10 @@ void invdct4_transform_fx( { IF( GT_32( f_invdct_v_fx[i], L_shl( 255, q ) ) ) { - f_invdct_v_fx[i] = L_shl( 255, q ); + f_invdct_v_fx[i] = L_shl( 255, q ); // q move32(); } - invdct_v[i] = (UWord8) L_shr( f_invdct_v_fx[i], q ); + invdct_v[i] = (UWord8) L_shr( f_invdct_v_fx[i], q ); // Q0 move16(); } } @@ -1180,16 +1181,17 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( } #else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( - const Word32 az, /* i : azimuth Q22 */ - const Word32 el, /* i : elevation Q22 */ - Word32 *dv /* o : direction vector */ + const Word32 az, /* i : azimuth Q22 */ + const Word32 el, /* i : elevation Q22 */ + Word32 *dv /* o : direction vector Q30 */ ) { Word16 radius_length; Word16 elevation_fx, azimuth_fx; - elevation_fx = extract_l( L_shr( Mpy_32_32( el, 5965232 ), 7 ) ); - azimuth_fx = extract_l( L_shr( Mpy_32_32( az, 5965232 ), 7 ) ); + // (2 ^ 31 - 1) / 360 -> 5965232 + elevation_fx = extract_l( L_shr( Mpy_32_32( el, ONE_BY_360_Q31 ), 7 ) ); // ( ( Q22 + Q31 - Q31 ) - Q7 ) -> Q15 + azimuth_fx = extract_l( L_shr( Mpy_32_32( az, ONE_BY_360_Q31 ), 7 ) ); // ( ( Q22 + Q31 - Q31 ) - Q7 ) -> Q15 dv[2] = L_shl( getSineWord16R2( elevation_fx ), Q15 ); /* Q30 */ move32(); @@ -1226,10 +1228,10 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation( #ifdef IVAS_FLOAT_FIXED void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( - const Word32 *dv, /* i : direction vector */ + const Word32 *dv, /* i : direction vector dv_q */ const Word16 dv_q, - Word32 *az, /* o : azimuth */ - Word32 *el /* o : elevation */ + Word32 *az, /* o : azimuth Q22 */ + Word32 *el /* o : elevation Q22 */ ) { /* note: dv does not need to have unit L_2 norm, because the conversion is scale invariant */ @@ -1237,9 +1239,11 @@ void ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( Word16 e_tmp; L_tmp = L_add( Mpy_32_32( dv[0], dv[0] ), Mpy_32_32( dv[1], dv[1] ) ); /* 2 * dv_q - 31 */ e_tmp = shl( sub( 31, dv_q ), 1 ); - L_tmp = Sqrt32( L_tmp, &e_tmp ); + L_tmp = Sqrt32( L_tmp, &e_tmp ); // e_tmp + // 29335 -> 180 / PI in Q9 *el = L_mult0( BASOP_util_atan2( dv[2], L_tmp, sub( sub( 31, dv_q ), e_tmp ) ), 29335 ); /* Q22 */ move32(); + // 29335 -> 180 / PI in Q9 *az = L_mult0( BASOP_util_atan2( dv[1], dv[0], 0 ), 29335 ); /* Q22 */ move32(); return; diff --git a/lib_com/ivas_qspherical_com.c b/lib_com/ivas_qspherical_com.c index 4c15510fe..52cfb9323 100644 --- a/lib_com/ivas_qspherical_com.c +++ b/lib_com/ivas_qspherical_com.c @@ -441,9 +441,9 @@ Word16 quantize_phi_fx( Word32 inv_delta_phi_fx; Word32 temp_res; - delta_phi_fx = delta_phi_val[n]; + delta_phi_fx = delta_phi_val[n]; // Q22 move32(); - inv_delta_phi_fx = inv_delta_phi_val[n]; + inv_delta_phi_fx = inv_delta_phi_val[n]; // Q31 move32(); IF( EQ_16( n, 1 ) ) { @@ -465,8 +465,8 @@ Word16 quantize_phi_fx( move32(); } - temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); - id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); + temp_res = Mpy_32_32( L_sub( L_sub( phi, DEGREE_180_Q_22 ), dd_fx ), inv_delta_phi_fx ); // Q22 + Q31 - Q31 -> Q22 + id_phi = round_fx( L_shr( temp_res, Q22 - Q16 ) ); // Q0 assert( L_sub( L_abs( temp_res ), abs( id_phi ) * ONE_IN_Q22 ) <= ONE_IN_Q21 ); @@ -497,7 +497,7 @@ ELSE } } -*phi_hat = L_add_sat( L_add_sat( ( id_phi * delta_phi_fx ), dd_fx ), DEGREE_180_Q_22 ); +*phi_hat = L_add_sat( L_add_sat( imult3216( delta_phi_fx, id_phi ), dd_fx ), DEGREE_180_Q_22 ); // Q22 move32(); id_phi = add( id_phi, shr( n, 1 ) ); @@ -676,8 +676,8 @@ Word32 companding_azimuth_fx( const Word16 direction /* i : direction of companding (direct or inverse)*/ ) { - const Word16 pointsA[] = { 0, 60, 110, 150, 180, 0, 50, 90, 150, 180, 0, 30, 80, 150, 180 }; - const Word16 pointsB[] = { 0, 90, 110, 170, 180, 0, 90, 110, 170, 180, 0, 10, 100, 170, 180 }; + const Word16 pointsA[] = { 0, 60, 110, 150, 180, 0, 50, 90, 150, 180, 0, 30, 80, 150, 180 }; // Q0 + const Word16 pointsB[] = { 0, 90, 110, 170, 180, 0, 90, 110, 170, 180, 0, 10, 100, 170, 180 }; // Q0 const Word16 *pA; const Word32 pointsA_fx[] = { 0, 251658240, 461373440, 629145600, 754974720, 0, 209715200, 377487360, 629145600, 754974720, 0, 125829120, 335544320, 629145600, 754974720 }; // q=22 const Word32 pointsB_fx[] = { 0, 377487360, 461373440, 713031680, 754974720, 0, 377487360, 461373440, 713031680, 754974720, 0, 41943040, 419430400, 713031680, 754974720 }; // q=22 @@ -806,38 +806,46 @@ Word32 companding_azimuth_fx( not_done = 0; move16(); /* calculate companding */ - comp_azi_fx = Mpy_32_32( L_sub( pB_fx[i + 1], pB_fx[i] ), L_sub( abs_azi_fx, pA_fx[i] ) ); + comp_azi_fx = Mpy_32_32( L_sub( pB_fx[i + 1], pB_fx[i] ), L_sub( abs_azi_fx, pA_fx[i] ) ); // ( Q22 + Q22 - Q31 ) -> Q13 SWITCH( sub( pA[i + 1], pA[i] ) ) { case 10: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 214748364 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 214748364 ); // 1 / 10 in 2 ^ 31 BREAK; case 20: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 107374182 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 107374182 ); // 1 / 20 in 2 ^ 31 BREAK; case 30: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 71582788 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 71582788 ); // 1 / 30 in 2 ^ 31 BREAK; case 40: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 53687091 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 53687091 ); // 1 / 40 in 2 ^ 31 BREAK; case 50: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 42949672 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 42949672 ); // 1 / 50 in 2 ^ 31 BREAK; case 60: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 35791394 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 35791394 ); // 1 / 60 in 2 ^ 31 BREAK; case 70: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 30678337 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 30678337 ); // 1 / 70 in 2 ^ 31 BREAK; case 90: - comp_azi_fx = Mpy_32_32( comp_azi_fx, 23860929 ); + // Q13 + Q31 - Q31 -> Q13 + comp_azi_fx = Mpy_32_32( comp_azi_fx, 23860929 ); // 1 / 90 in 2 ^ 31 BREAK; default: assert( 0 ); BREAK; } - comp_azi_fx = L_add( pB_fx[i], L_shl( comp_azi_fx, 31 - 22 ) ); + comp_azi_fx = L_add( pB_fx[i], L_shl( comp_azi_fx, Q22 - Q13 ) ); // Q22 // comp_azi = pB[i] + ( pB[i + 1] - pB[i] ) / ( pA[i + 1] - pA[i] ) * ( abs_azi - pA[i] ); } ELSE @@ -848,16 +856,16 @@ Word32 companding_azimuth_fx( IF( azi_fx < 0 ) { - comp_azi_fx = L_negate( comp_azi_fx ); + comp_azi_fx = L_negate( comp_azi_fx ); // Q22 } IF( EQ_16( not_done, 1 ) ) { - comp_azi_fx = azi_fx; + comp_azi_fx = azi_fx; // Q22 move32(); } - return comp_azi_fx; + return comp_azi_fx; // Q22 } #endif @@ -926,7 +934,7 @@ Word16 quantize_phi_chan_lbr_fx( IF( phi < 0 && id_phi > 0 ) { id_phi = sub( shl( id_phi, 1 ), 1 ); - *phi_hat = L_negate( *phi_hat ); + *phi_hat = L_negate( *phi_hat ); // Q22 move32(); } ELSE @@ -1038,8 +1046,8 @@ Word16 quantize_phi_chan_compand_fx( delta_phi = BASOP_Util_Divide3232_Scale_cadence( 360, n, &tmp_e ); delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); // Q22 // id_phi = (int16_t) round_f( ( phi / (float) delta_phi ) ); - id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); - id_phi = shr( id_phi, sub( 15, tmp_e ) ); + id_phi = BASOP_Util_Divide3232_Scale( phi, delta_phi, &tmp_e ); // Q15 + id_phi = shr( id_phi, sub( 15, tmp_e ) ); // Q0 IF( add( id_phi, shr( n, 1 ) ) < 0 ) { @@ -1066,14 +1074,14 @@ ELSE } } //*phi_hat = id_phi * delta_phi; -*phi_hat = imult3216( delta_phi, id_phi ); +*phi_hat = imult3216( delta_phi, id_phi ); // Q22 move32(); // id_phi += ( n >> 1 ); id_phi = add( id_phi, shr( n, 1 ) ); -*phi_hat = L_add( companding_azimuth_fx( *phi_hat, mc_format, theta_flag, -1 ), DEGREE_180_Q_22 ); +*phi_hat = L_add( companding_azimuth_fx( *phi_hat, mc_format, theta_flag, -1 ), DEGREE_180_Q_22 ); // Q22 move32(); return id_phi; diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 9f08e3dfe..805900f8f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -58,13 +58,13 @@ const int32_t ivas_brate_tbl[SIZE_IVAS_BRATE_TBL] = *------------------------------------------------------------------------*/ /*4xERB scale: max of 14 bands*/ -const int16_t dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] = +const Word16 dft_band_limits_erb4[STEREO_DFT_ERB4_BANDS] = { 1, 3, 5, 10, 18, 26, 41, 56, 84, 132, 214, 342, 470, 601 }; /*8xERB scale: max of 8 bands*/ -const int16_t dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] = +const Word16 dft_band_limits_erb8[STEREO_DFT_ERB8_BANDS] = { 1, 5, 18, 41, 84, 214, 470, 601 }; @@ -76,20 +76,21 @@ const float dft_res_cod_alpha[STEREO_DFT_BAND_MAX] = }; #endif -const int16_t dft_band_ipd[3][4] = +const Word16 dft_band_ipd[3][4] = { {0,8,10,13}, {0,5,6,8}, {0,2,3,4} }; -const int16_t dft_band_res_cod[3][4] = +const Word16 dft_band_res_cod[3][4] = { {0,8,10,11}, {0,5,6,7}, {0,5,6,7} }; +// Q31 const Word32 dft_res_gains_q_Q31[][2] = { /* quantization points for joint quantization of prediction gain and residual energy */ @@ -501,17 +502,17 @@ const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1] = }; /* tables for adaptive Golomb-Rice coding of DFT stereo parameters */ -const int16_t dft_code_itd[] = +const Word16 dft_code_itd[] = { 0, 3, 4, 13, 8, 9, 12, 5, 10, 44, 23, 60, 45, 31, 235, 59, 28, 61, 234, 116 }; -const int16_t dft_len_itd[] = +const Word16 dft_len_itd[] = { 2, 3, 4, 4, 4, 4, 4, 4, 4, 6, 5, 6, 6, 5, 8, 6, 5, 6, 8, 7 }; -const int16_t dft_maps_rpg[] = +const Word16 dft_maps_rpg[] = { 0, 1, 2, 3, 4, 5, 6, 7, 2, 0, 1, 3, 4, 5, 6, 7, @@ -524,7 +525,7 @@ const int16_t dft_maps_rpg[] = 6, 5, 4, 3, 1, 0, 2, 7, }; -const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = +const Word16 dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, @@ -565,7 +566,7 @@ const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G] = *------------------------------------------------------------------------*/ /* Create separate tables for cumulative frequency and symbol frequency */ -const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] = +const UWord16 cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] = { { 0,16,47,153,241,269,325,468,591,674,798,912,1017,1082,1183,1277,1364,16384 }, { 0,7401,7844,7886,7899,12065,12718,12790,12805,14099,14476,14533,14549,15058,15264,15299,15310,16384 }, @@ -633,7 +634,7 @@ const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS] { 0,6720,8878,9325,9467,11564,13248,13744,13929,14384,14880,15087,15167,15311,15488,15569,15607,16384 }, }; -const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = +const UWord16 sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = { { 16,31,106,88,28,56,143,123,83,124,114,105,65,101,94,87,15020 }, { 7401,443,42,13,4166,653,72,15,1294,377,57,16,509,206,35,11,1074 }, @@ -707,7 +708,7 @@ const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS] = *------------------------------------------------------------------------*/ /* table with round(ECSQ_PROB_TOTAL / index) for entropy coding, with i in {1, .., ECSQ_SEGMENT_SIZE} */ -const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] = +const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE] = { 0, 16384, 8192, 5461, 4096, 3277, 2731, 2341, 2048 }; @@ -792,7 +793,7 @@ const float tdm_den_ratio_tabl[TDM_NQ+1] = /* 1.0f/(2*LR_ratio*LR_ratio-2*LR_ra 1.2088f, 1.1429f, 1.0902f, 1.0501f, 1.0221f, 1.0000f, 1.0000f, 1.0000f }; -const int16_t tdm_bit_allc_tbl[5][6] = +const Word16 tdm_bit_allc_tbl[5][6] = { /* IC -- UC -- GC -- TM --AC */ { 1650, 3500, 0, 4400, 0, 5000 }, /* IVAS_13k2 */ @@ -879,9 +880,9 @@ const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15] = 0.1193f, 0.6574f, }; -const int16_t fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/}; +const Word16 fast_FCB_bits_2sfr[] = {8, 14, 18, 20, 24, 128/*stop value*/}; -const int16_t fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50}; +const Word16 fast_FCB_rates_2sfr[] = {/*16*50,*/ (8+14)*50, 28*50, 32*50, 34*50, 36*50, 38*50, 40*50, 42*50, 44*50, 48*50}; /*----------------------------------------------------------------------------------* @@ -970,11 +971,11 @@ const float dft_cng_coh_pred[STEREO_DFT_N_COH_PRED][STEREO_DFT_COH_PRED_COEFFS] { 1.393664f, -0.131401f, 0.989429f, 0.738330f, 0.683865f, 0.001677f, -0.225448f, -0.012158f, 1.084608f, -0.115464f, 0.022371f, -0.045560f, -0.336230f, 0.422742f, 0.499163f} }; -const int16_t dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ +const Word16 dft_cng_coh_u2i[9] = { 4, 5, 3, 6, 2, 7, 1, 8, 0 }; /* Coherence unary codeword -> residual codeword conversion table */ -const int16_t dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */ +const Word16 dft_cng_coh_i2u[9] = { 8, 6, 4, 2, 0, 1, 3, 5, 7 }; /* Coherence residual codeword -> unary codeword conversion table */ -const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 }; +const Word16 dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1] = { 15, 16, 17, 18 }; const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS] = { @@ -1015,28 +1016,28 @@ const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1] = 2.0f /* out-of-range large value to make searching easier */ }; -const int16_t DirAC_band_grouping_12[12 + 1] = +const Word16 DirAC_band_grouping_12[12 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 11, 17, 25, 40, 60 }; -const int16_t DirAC_band_grouping_6[6 + 1] = +const Word16 DirAC_band_grouping_6[6 + 1] = { 0, 1, 4, 8, 20, 30, 60 }; -const int16_t DirAC_band_grouping_5[5 + 1] = +const Word16 DirAC_band_grouping_5[5 + 1] = { 0, 1, 3, 7, 15, 60 }; -const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +const Word16 DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = { 0, 4, 8, 12, 16 }; -const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = +const Word16 DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1] = { 0, 1, 2, 3, 4 }; @@ -1686,18 +1687,18 @@ const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = /* DTX quantization and bitstream constants */ const float dtx_pd_real_min_max[2] = { 0, 1.6f }; -const int16_t dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } }; -const int16_t dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } }; -const int16_t pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } }; -const int16_t pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } }; +const Word16 dtx_pd_real_q_levels[3][3] = { { 7,7,7 },{ 7,7,0 },{ 3,0,0 } }; +const Word16 dtx_pr_real_q_levels[3][3] = { { 9,9,9 },{ 9,7,9 },{ 9,5,7 } }; +const Word16 pr_pr_idx_pairs[3][3][2] = { { { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 0, 0 },{ 0, 0 } },{ { 0, 0 },{ 1, 3 },{ 0, 0 } } }; +const Word16 pr_pd_idx_pairs[3][3][2] = { { { 1, 1 },{ 2, 2 },{ 3, 3 } },{ { 1, 1 },{ 3, 2 },{ 2, 0 } },{ { 2, 1 },{ 0, 0 },{ 0, 0 } } }; -const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS] = { /* WYZX --> WYXZ... */ +const Word16 remix_order_set[1][DIRAC_MAX_ANA_CHANS] = { /* WYZX --> WYXZ... */ { 0, 1, 3, 2, 4, 5, 6, 7, 8, 9, 10 } }; -const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15}; -const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10}; -const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; +const Word16 HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15}; +const Word16 HOA_keep_ind_spar[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 8, 9, 10, 10, 10, 10}; +const Word16 HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; /*----------------------------------------------------------------------* @@ -1719,7 +1720,7 @@ const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1] = 463455, 463456 }; -const int16_t ivas_pca_offset_index2[2692] = +const Word16 ivas_pca_offset_index2[2692] = { 0, 1, 0, 1, 7, 8, 0, 1, 7, 19, 33, 45, 51, 52, 0, 1, 9, 23, 41, 61, @@ -1993,7 +1994,7 @@ const int16_t ivas_pca_offset_index2[2692] = 10365, 10366 }; -const int16_t ivas_pca_offset_n2[IVAS_PCA_N1] = +const Word16 ivas_pca_offset_n2[IVAS_PCA_N1] = { 0, 2, 6, 14, 24, 38, 56, 76, 100, 126, 156, 188, 224, 262, 302, 346, 392, 442, 494, 548, 604, 664, 726, 790, @@ -2106,53 +2107,53 @@ const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2] = { /* ph1_q : Q13, n2 : Q0 */ * Parametric MC ROM tables *----------------------------------------------------------------------------------*/ -const int16_t param_mc_band_grouping_20[20 + 1] = +const Word16 param_mc_band_grouping_20[20 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 23, 27, 33, 40, 52, 60 }; -const int16_t param_mc_coding_band_mapping_20[20] = +const Word16 param_mc_coding_band_mapping_20[20] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -const int16_t param_mc_bands_coded_20[4] = +const Word16 param_mc_bands_coded_20[4] = { 10, 14, 18, 20 }; -const int16_t param_mc_band_grouping_14[14 + 1] = +const Word16 param_mc_band_grouping_14[14 + 1] = { 0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 28, 40, 60 }; -const int16_t param_mc_coding_band_mapping_14[14] = +const Word16 param_mc_coding_band_mapping_14[14] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; -const int16_t param_mc_bands_coded_14[4] = +const Word16 param_mc_bands_coded_14[4] = { 8, 11, 13, 14 }; -const int16_t param_mc_band_grouping_10[10 + 1] = +const Word16 param_mc_band_grouping_10[10 + 1] = { 0, 1, 2, 3, 5, 7, 10, 14, 20, 40, 60 }; -const int16_t param_mc_bands_coded_10[4] = +const Word16 param_mc_bands_coded_10[4] = { 6, 8, 9, 10 }; -const int16_t param_mc_coding_band_mapping_10[10] = +const Word16 param_mc_coding_band_mapping_10[10] = { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; -const int16_t Param_MC_index[MAX_CICP_CHANNELS] = +const Word16 Param_MC_index[MAX_CICP_CHANNELS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; @@ -2914,161 +2915,161 @@ const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER] = }; /* Alphabet for delta coding for the ICCs in Parametric MC processing */ -const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 24, 224, 20873, 42384, 51699, 57122, 60572, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 24, 200, 20649, 21511, 9315, 5423, 3450, 4963 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 4, 9, 124, 447, 1311, 4453, 18116, 48636, 60573, 63692, 64746, 65327, 65531, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 4, 5, 115, 323, 864, 3142, 13663, 30520, 11937, 3119, 1054, 581, 204, 3, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 30, 848, 26611, 47846, 57358, 61679, 63237, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 30, 818, 25763, 21235, 9512, 4321, 1558, 2298 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 2, 7, 53, 243, 979, 3994, 16732, 49642, 61343, 64331, 65158, 65438, 65532, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 2, 5, 46, 190, 736, 3015, 12738, 32910, 11701, 2988, 827, 280, 94, 2, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 46, 826, 27798, 49552, 58447, 62046, 63284, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={ +const UWord16 ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER ]={ 46, 780, 26972, 21754, 8895, 3599, 1238, 2251 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 3, 8, 36, 172, 763, 3436, 15845, 50168, 62005, 64676, 65298, 65481, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2* PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 3, 5, 28, 136, 591, 2673, 12409, 34323, 11837, 2671, 622, 183, 52, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = +const UWord16 ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1] = { 0, 34, 552, 24717, 45819, 54772, 59054, 61166, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER] = { 34, 518, 24165, 21102, 8953, 4282, 2112, 4369 }; -const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = +const UWord16 ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER] = { 0, 3, 7, 74, 304, 1009, 3870, 16502, 49834, 61384, 64217, 65020, 65369, 65531, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = +const UWord16 ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1] = { 3, 4, 67, 230, 705, 2861, 12632, 33332, 11550, 2833, 803, 349, 162, 3, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 1092, 5574, 8315, 10652, 13875, 19656, 27664, 36284, 47058, 56251, 62579, 65118, 65462, 65513, 65532, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 1092, 4482, 2741, 2337, 3223, 5781, 8008, 8620, 10774, 9193, 6328, 2539, 344, 51, 19, 3 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 38, 146, 352, 638, 997, 1559, 2323, 3570, 5859, 10556, 21075, 44682, 55617, 60408, 62739, 63833, 64443, 64809, 65074, 65279, 65400, 65484, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 33, 108, 206, 286, 359, 562, 764, 1247, 2289, 4697, 10519, 23607, 10935, 4791, 2331, 1094, 610, 366, 265, 205, 121, 84, 47, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 967, 6335, 9941, 12837, 16652, 22416, 29814, 38807, 48497, 57184, 62661, 64916, 65466, 65514, 65530, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 967, 5368, 3606, 2896, 3815, 5764, 7398, 8993, 9690, 8687, 5477, 2255, 550, 48, 16, 5 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 18, 61, 149, 320, 592, 1083, 1793, 2974, 5257, 10133, 21274, 44342, 55891, 60895, 63174, 64244, 64793, 65100, 65287, 65406, 65477, 65517, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 13, 43, 88, 171, 272, 491, 710, 1181, 2283, 4876, 11141, 23068, 11549, 5004, 2279, 1070, 549, 307, 187, 119, 71, 40, 14, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = +const UWord16 ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1] = { 0, 229, 7068, 10910, 13856, 17467, 22629, 29174, 36906, 46558, 55579, 61802, 65222, 65505, 65527, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 229, 6839, 3842, 2946, 3611, 5162, 6545, 7732, 9652, 9021, 6223, 3420, 283, 22, 7, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 4, 12, 56, 153, 278, 475, 856, 1430, 2489, 4723, 9580, 20685, 45423, 56274, 60948, 63097, 64128, 64679, 65002, 65208, 65348, 65445, 65517, 65531, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 1, 8, 44, 97, 125, 197, 381, 574, 1059, 2234, 4857, 11105, 24738, 10851, 4674, 2149, 1031, 551, 323, 206, 140, 97, 72, 14, 1, 1, 1, 1 }; -const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] = +const UWord16 ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS+1] = { 0, 1453, 8326, 12221, 15164, 18764, 24177, 31297, 39520, 49154, 57135, 62460, 64821, 65468, 65514, 65530, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 1453, 6873, 3895, 2943, 3600, 5413, 7120, 8223, 9634, 7981, 5325, 2361, 647, 46, 16, 5 }; -const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = +const UWord16 ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS] = { 0, 1, 2, 3, 5, 29, 98, 220, 414, 699, 1186, 1876, 3049, 5304, 10013, 20612, 45247, 56109, 60818, 63022, 64081, 64647, 64977, 65198, 65348, 65443, 65502, 65530, 65532, 65533, 65534, 65535 }; -const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = +const UWord16 ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1] = { 1, 1, 1, 2, 24, 69, 122, 194, 285, 487, 690, 1173, 2255, 4709, 10599, 24635, 10862, 4709, 2204, 1059, 566, 330, 221, 150, 95, 59, 28, 2, 1, 1, 1 }; @@ -3156,7 +3157,7 @@ const Word32 diffuseness_thresholds_hr_fx[HR_MASA_ER_LEVELS + 1] = { /* Q30 */ MAX_32 /* out-of-range large value to make searching easier */ }; -const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS] = +const Word16 bits_direction_masa[DIRAC_DIFFUSE_LEVELS] = { 11, 11, @@ -3218,7 +3219,7 @@ const float coherence_cb1_masa[MASA_NO_CV_COH1*MASA_MAXIMUM_CODING_SUBBANDS] = 0.0017f, 0.2521f, -0.2479f, 0.7217f, -0.7157f }; -const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 }; +const Word16 len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS] = { 7, 6, 5, 4, 4, 4, 3, 2 }; const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] = { @@ -3231,18 +3232,18 @@ const uint8_t sur_coherence_cb_masa[MASA_MAX_NO_CV_SUR_COH*MASA_NO_CB_SUR_COH] = 6, 20, 38, 60, 86, 119, 165, 249 }; -const int16_t idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 }; +const Word16 idx_cb_sur_coh_masa[MASA_MAX_NO_CV_SUR_COH] = { 0, 1, 2, 3, 4, 5, 5, 6 }; -const int16_t len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 }; +const Word16 len_huf_masa[MASA_NO_CV_COH1] = { 4, 2, 1, 3, 4 }; -const int16_t huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 }; +const Word16 huff_code_av_masa[MASA_NO_CV_COH1] = { 15, 2, 0, 6, 14 }; -const int16_t no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */ +const Word16 no_theta_masa[NO_SPHERICAL_GRIDS-2] = /* from 1 to 11 bits */ { /*1, 1,*/ 2 ,2 , 4, 5, 6, 7, 10, 14, 19 /*0, 2, 8, 6, 7, 12, 14, 16*/ }; -const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/ +const Word16 no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA] = /* from 1 to 11 bits*/ { { 2 }, { 4 }, @@ -3278,63 +3279,63 @@ const float azimuth_cb[8] = 0.0f, -180.0f, -90.0f, 90.0f, -45.0f, 45.0f, -135.0f, 135.0f }; -const int16_t MASA_band_grouping_24[24 + 1] = +const Word16 MASA_band_grouping_24[24 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40, 60 }; -const int16_t MASA_band_mapping_24_to_18[18 + 1] = +const Word16 MASA_band_mapping_24_to_18[18 + 1] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 17, 20, 21, 22, 23, 24 }; -const int16_t MASA_band_mapping_24_to_12[12 + 1] = +const Word16 MASA_band_mapping_24_to_12[12 + 1] = { 0, 1, 2, 3, 4, 5, 7, 9, 12, 15, 20, 22, 24 }; -const int16_t MASA_band_mapping_24_to_8[8 + 1] = +const Word16 MASA_band_mapping_24_to_8[8 + 1] = { 0, 1, 2, 3, 5, 8, 12, 20, 24 }; -const int16_t MASA_band_mapping_24_to_5[5 + 1] = +const Word16 MASA_band_mapping_24_to_5[5 + 1] = { 0, 1, 3, 7, 15, 24 }; -const int16_t MASA_grouping_8_to_5[8] = +const Word16 MASA_grouping_8_to_5[8] = { 0, 1, 1, 2, 3, 3, 4, 4 }; -const int16_t MASA_grouping_12_to_5[12] = +const Word16 MASA_grouping_12_to_5[12] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4 }; -const int16_t MASA_grouping_18_to_5[18] = +const Word16 MASA_grouping_18_to_5[18] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 }; -const int16_t MASA_grouping_24_to_5[24] = +const Word16 MASA_grouping_24_to_5[24] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; /* IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k */ -const int16_t masa_bits[IVAS_NUM_ACTIVE_BRATES] = +const Word16 masa_bits[IVAS_NUM_ACTIVE_BRATES] = { 50, 60, 70, 85, 140, 180, 220, 256, 350, 432, 528, 832, 1024, MASA_MAX_BITS }; -const int16_t masa_bits_LR_stereo[4] = +const Word16 masa_bits_LR_stereo[4] = { 50, 50, 60, 70 }; -const int16_t mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] = +const Word16 mcmasa_bits[IVAS_NUM_ACTIVE_BRATES] = { 50, 70, 80, 120, 140, 160, 220, 256, 288, 432, 528, 832, 1024, MASA_MAX_BITS }; @@ -3497,7 +3498,7 @@ const float ism_elevation_borders[4] = * Param ISM ROM tables *----------------------------------------------------------------------------------*/ -const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] = +const Word16 Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1] = { 0, 1, 2, 3, 4, 6, 8, 11, 15, 21, 31, 60 }; @@ -3780,7 +3781,7 @@ const ivas_lfe_freq_models ivas_str_lfe_freq_models = { 16384, 4468, 1489, 745, 0 }, 0, }; -const int16_t ivas_lfe_num_ele_in_coder_models[2][4] = +const Word16 ivas_lfe_num_ele_in_coder_models[2][4] = { { 63, 31, 7, 1 },{ 31, 15, 3, 0 } }; @@ -3790,9 +3791,9 @@ const Word16 ivas_lfe_log2_num_ele_in_coder_models_fx[2][4] = { 6, 5, 3, 1 },{ 5, 4, 2, 0 } }; -const int16_t ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 }; +const Word16 ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 8, 6 }; -const int16_t ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 }; +const Word16 ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP] = { 1, 0 }; const float ivas_lfe_lpf_delay[2] = { 0.00175f, 0.0035f }; const Word16 ivas_lfe_lpf_delay_Q15[2] = { 57, 114 }; @@ -4752,7 +4753,7 @@ const float ivas_cos_twiddle_80[IVAS_80_PT_LEN >> 1] = 0.151584296010041f, 0.112661287574648f, 0.0735645635996675f, 0.0343544083996823f }; -const int16_t dirac_gains_P_idx[16] = +const Word16 dirac_gains_P_idx[16] = { -1, 1, 0, 1, 4, 3, 2, 3, 4, 8, 7, 6, 5, 6, 7, 8 }; @@ -5120,21 +5121,21 @@ const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12] = 465288128, 715827904, 1091637520, 1735882615 };/*Q31*/ -const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 291, 367 }, { 24, 30, 30, 30, 30, 30, 42, 76, 124, 182, 260, 47 }, { 24, 30, 30, 30, 30, 30, 42, 75, 122, 73, 0, 0 } }; -const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, {0, 9, 25, 41, 57, 73, 88, 110, 158, 246, 380, 593 }, {0, 9, 25, 41, 57, 73, 88, 110, 159, 247, 0, 0 } }; -const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { IVAS_FB_12_1MS_48K_END_BINS_BAND_0 - IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, @@ -5180,7 +5181,7 @@ const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BA }, }; -const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = +const Word16 ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12] = { { IVAS_FB_12_1MS_48K_START_OFFSET_BAND_0, IVAS_FB_12_1MS_48K_START_OFFSET_BAND_1, @@ -6275,7 +6276,7 @@ const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1] = 0.500000000000000f }; -const int16_t ivas_num_active_bands[FB - WB + 1] = +const Word16 ivas_num_active_bands[FB - WB + 1] = { IVAS_16K_12BANDS_ACTIVE_BANDS, IVAS_FB_BANDS_12, IVAS_FB_BANDS_12 }; @@ -6284,9 +6285,9 @@ const int16_t ivas_num_active_bands[FB - WB + 1] = * SNS MSVQ codebooks and means *------------------------------------------------------------------------------------------*/ -const int16_t ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 32, 32 }; +const Word16 ivas_sns_cdbks_tcx20_levels[SNS_MSVQ_NSTAGES_TCX20] = { 128, 64, 32, 32 }; -const int16_t ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 }; +const Word16 ivas_sns_cdbks_tcx20_bits[SNS_MSVQ_NSTAGES_TCX20] = { 7, 6, 5, 5 }; /* pre-rounded codebook vectors for singed Q4.12 represantation */ const float ivas_sns_cdbk_tcx20_stage1[ 128 * 16 ] = @@ -6563,9 +6564,9 @@ const float ivas_sns_cdbk_tcx20_stage4[ 32 * 16 ] = const float *const ivas_sns_cdbks_tcx20[SNS_MSVQ_NSTAGES_TCX20] = { ivas_sns_cdbk_tcx20_stage1, ivas_sns_cdbk_tcx20_stage2, ivas_sns_cdbk_tcx20_stage3, ivas_sns_cdbk_tcx20_stage4 }; -const int16_t ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 }; +const Word16 ivas_sns_cdbks_tcx10_levels[SNS_MSVQ_NSTAGES_TCX10] = { 128, 32, 8 }; -const int16_t ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 }; +const Word16 ivas_sns_cdbks_tcx10_bits[SNS_MSVQ_NSTAGES_TCX10] = { 7, 5, 3 }; const float ivas_sns_cdbk_tcx10_stage1[ 128 * 16 ] = { @@ -6749,10 +6750,10 @@ const float ivas_sns_cdbk_tcx10_stage3[ 8 * 16 ] = const float *const ivas_sns_cdbks_tcx10[SNS_MSVQ_NSTAGES_TCX10] = { ivas_sns_cdbk_tcx10_stage1, ivas_sns_cdbk_tcx10_stage2, ivas_sns_cdbk_tcx10_stage3}; -const int16_t ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 }; -const int16_t ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 }; -const int16_t ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 }; -const int16_t ivas_sns_cdbks_side_tcx10_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 3 }; +const Word16 ivas_sns_cdbks_side_tcx20_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 32 }; +const Word16 ivas_sns_cdbks_side_tcx20_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 5 }; +const Word16 ivas_sns_cdbks_side_tcx10_levels[SNS_MSVQ_NSTAGES_SIDE] = { 32, 8 }; +const Word16 ivas_sns_cdbks_side_tcx10_bits[SNS_MSVQ_NSTAGES_SIDE] = { 5, 3 }; const float ivas_sns_cdbks_side_tcx20_stage1[ 32 * 16 ] = { @@ -6879,7 +6880,7 @@ const float ivas_sns_cdbks_side_tcx10_stage2[ 8 * 16 ] = const float *const ivas_sns_cdbks_side_tcx10[SNS_MSVQ_NSTAGES_SIDE] = { ivas_sns_cdbks_side_tcx10_stage1, ivas_sns_cdbks_side_tcx10_stage2 }; -const int16_t sns_1st_cdbk[2][2][8 * 32] = +const Word16 sns_1st_cdbk[2][2][8 * 32] = { { /* split 1 */ { /* TCX 20 */ @@ -7023,7 +7024,7 @@ const int16_t sns_1st_cdbk[2][2][8 * 32] = } }; -const int16_t sns_1st_means_16k[2][16] = +const Word16 sns_1st_means_16k[2][16] = { { /* TCX 20 */ 14210, 19017, 14362, 9309, 5385, 2674, 1055, -211, -1407, -3059, -4393, -8597, -11180, -11756, -12131, -13281, @@ -7033,7 +7034,7 @@ const int16_t sns_1st_means_16k[2][16] = } }; -const int16_t sns_1st_means_25k6[2][16] = +const Word16 sns_1st_means_25k6[2][16] = { { /* TCX 20 */ 14973, 20323, 16461, 9554, 4017, 3103, 1602, 1694, -221, -1401, -6817, -10071, -11503, -11805, -13158, -16749, @@ -7043,7 +7044,7 @@ const int16_t sns_1st_means_25k6[2][16] = } }; -const int16_t sns_1st_means_32k[2][16] = +const Word16 sns_1st_means_32k[2][16] = { { /* TCX 20 */ 15041, 20603, 16969, 10289, 4973, 4283, 3003, 3316, 1684, -259, -6614, -9535, -10363, -11834, -16625, -24930, @@ -7058,7 +7059,7 @@ const int16_t sns_1st_means_32k[2][16] = * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ -const int16_t ivas_param_upmx_mx_qmap[33] = +const Word16 ivas_param_upmx_mx_qmap[33] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 6d1648c4e..f70ad7937 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -45,16 +45,16 @@ * General IVAS ROM tables *----------------------------------------------------------------------------------*/ -extern const int32_t ivas_brate_tbl[]; +extern const Word32 ivas_brate_tbl[]; /*------------------------------------------------------------------------- * DFT Stereo ROM tables *------------------------------------------------------------------------*/ -extern const int16_t dft_band_limits_erb4[]; -extern const int16_t dft_band_limits_erb8[]; -extern const int16_t dft_band_ipd[3][4]; -extern const int16_t dft_band_res_cod[3][4]; +extern const Word16 dft_band_limits_erb4[]; +extern const Word16 dft_band_limits_erb8[]; +extern const Word16 dft_band_ipd[3][4]; +extern const Word16 dft_band_res_cod[3][4]; extern const float dft_res_gains_q[][2]; #ifndef IVAS_FLOAT_FIXED @@ -66,23 +66,23 @@ extern const float dft_trigo_32k[STEREO_DFT_N_32k_ENC / 4 + 1]; extern const float dft_trigo_48k[STEREO_DFT_N_MAX_ENC / 4 + 1]; /* Golomb-Rice encoding tables */ -extern const int16_t dft_maps_rpg[]; -extern const int16_t dft_code_itd[]; -extern const int16_t dft_len_itd[]; -extern const int16_t dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G]; +extern const Word16 dft_maps_rpg[]; +extern const Word16 dft_code_itd[]; +extern const Word16 dft_len_itd[]; +extern const Word16 dft_maps_sg[NO_SYMB_GR_SIDE_G * NO_SYMB_GR_SIDE_G]; /*----------------------------------------------------------------------------------* * Range Coder ROM tables *----------------------------------------------------------------------------------*/ -extern const uint16_t cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS]; -extern const uint16_t sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; +extern const UWord16 cum_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][1 + RANGE_N_SYMBOLS]; +extern const UWord16 sym_freq_ari_pk_s17_LC_ext[RANGE_N_CONTEXT][RANGE_N_SYMBOLS]; /*----------------------------------------------------------------------------------* * ECLVQ Stereo ROM tables *----------------------------------------------------------------------------------*/ -extern const uint16_t ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE]; +extern const UWord16 ECSQ_tab_inverse[1 + ECSQ_SEGMENT_SIZE]; /*----------------------------------------------------------------------------------* * Stereo ICA ROM tables @@ -105,7 +105,7 @@ extern const float icbwe_gsMappingDFT_tbl[]; extern const float tdm_ratio_tabl[]; extern const float tdm_den_ratio_tabl[]; -extern const int16_t tdm_bit_allc_tbl[5][6]; +extern const Word16 tdm_bit_allc_tbl[5][6]; /* LSFs Intra-frame prediction tables */ #ifdef IVAS_FLOAT_FIXED @@ -141,8 +141,8 @@ extern const float tdm_LSF_MEAN_PRED_QNT_IN[M]; extern const float tdm_LSF_MEAN_PRED_QNT[M]; extern const float tdm_PRED_QNT_fixed_beta_prd_diag_3[15 + 16 + 15]; -extern const int16_t fast_FCB_bits_2sfr[]; -extern const int16_t fast_FCB_rates_2sfr[]; +extern const Word16 fast_FCB_bits_2sfr[]; +extern const Word16 fast_FCB_rates_2sfr[]; /*----------------------------------------------------------------------------------* * MDCT Stereo ROM tables @@ -161,11 +161,11 @@ extern const float nf_tw_smoothing_coeffs[N_LTP_GAIN_MEMS]; extern const Word16 dft_cng_coh_pred_fx[][STEREO_DFT_COH_PRED_COEFFS]; extern const float dft_cng_coh_pred[][STEREO_DFT_COH_PRED_COEFFS]; -extern const int16_t dft_cng_coh_u2i[9]; -extern const int16_t dft_cng_coh_i2u[9]; +extern const Word16 dft_cng_coh_u2i[9]; +extern const Word16 dft_cng_coh_i2u[9]; extern const Word16 dft_cng_alpha_bits_fx[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS]; extern const float dft_cng_alpha_bits[STEREO_DFT_N_COH_ALPHA_STEPS][STEREO_DFT_N_COH_ALPHA_LEVELS]; -extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; +extern const Word16 dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; /*----------------------------------------------------------------------------------* * DirAC ROM tables @@ -173,11 +173,11 @@ extern const int16_t dft_cng_coh_alpha_start[STEREO_DFT_N_COH_ALPHA_STEPS - 1]; extern const float diffuseness_reconstructions[DIRAC_DIFFUSE_LEVELS]; extern const float diffuseness_thresholds[DIRAC_DIFFUSE_LEVELS + 1]; -extern const int16_t DirAC_band_grouping_12[12 + 1]; -extern const int16_t DirAC_band_grouping_6[6 + 1]; -extern const int16_t DirAC_band_grouping_5[5 + 1]; -extern const int16_t DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; -extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +extern const Word16 DirAC_band_grouping_12[12 + 1]; +extern const Word16 DirAC_band_grouping_6[6 + 1]; +extern const Word16 DirAC_band_grouping_5[5 + 1]; +extern const Word16 DirAC_block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; +extern const Word16 DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + 1]; #ifdef IVAS_FLOAT_FIXED extern const Word32 c_weights_fx[DIRAC_NO_FB_BANDS_MAX]; // Q30 @@ -201,24 +201,24 @@ extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN]; extern const ivas_spar_br_table_t ivas_spar_br_table_consts_fx[IVAS_SPAR_BR_TABLE_LEN]; -extern const int16_t remix_order_set[1][DIRAC_MAX_ANA_CHANS]; -extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN]; -extern const int16_t HOA_keep_ind_spar[IVAS_SPAR_MAX_CH]; -extern const int16_t HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH]; +extern const Word16 remix_order_set[1][DIRAC_MAX_ANA_CHANS]; +extern const Word16 HOA_keep_ind[IVAS_SPAR_MAX_FB_IN_CHAN]; +extern const Word16 HOA_keep_ind_spar[IVAS_SPAR_MAX_CH]; +extern const Word16 HOA_keep_ind_spar512[IVAS_SPAR_MAX_CH]; extern const float dtx_pd_real_min_max[2]; -extern const int16_t dtx_pd_real_q_levels[3][3]; -extern const int16_t dtx_pr_real_q_levels[3][3]; -extern const int16_t pr_pr_idx_pairs[3][3][2]; -extern const int16_t pr_pd_idx_pairs[3][3][2]; +extern const Word16 dtx_pd_real_q_levels[3][3]; +extern const Word16 dtx_pr_real_q_levels[3][3]; +extern const Word16 pr_pr_idx_pairs[3][3][2]; +extern const Word16 pr_pd_idx_pairs[3][3][2]; /*----------------------------------------------------------------------* * PCA ROM tables *-----------------------------------------------------------------------*/ -extern const int32_t ivas_pca_offset_index1[IVAS_PCA_N1 + 1]; -extern const int16_t ivas_pca_offset_index2[2692]; -extern const int16_t ivas_pca_offset_n2[IVAS_PCA_N1]; +extern const Word32 ivas_pca_offset_index1[IVAS_PCA_N1 + 1]; +extern const Word16 ivas_pca_offset_index2[2692]; +extern const Word16 ivas_pca_offset_n2[IVAS_PCA_N1]; extern const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2]; @@ -226,98 +226,98 @@ extern const Word16 ph1_q_n2_tbl[IVAS_PCA_N1][2]; * Parametric MC ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t param_mc_band_grouping_20[20 + 1]; -extern const int16_t param_mc_coding_band_mapping_20[20]; -extern const int16_t param_mc_bands_coded_20[4]; -extern const int16_t param_mc_band_grouping_14[14 + 1]; -extern const int16_t param_mc_coding_band_mapping_14[14]; -extern const int16_t param_mc_bands_coded_14[4]; -extern const int16_t param_mc_band_grouping_10[10 + 1]; -extern const int16_t param_mc_coding_band_mapping_10[10]; -extern const int16_t param_mc_bands_coded_10[4]; -extern const int16_t param_mc_start_bin_per_band_20[20]; -extern const int16_t param_mc_active_bins_per_band_20[20]; -extern const int16_t param_mc_start_bin_per_band_14[14]; -extern const int16_t param_mc_active_bins_per_band_14[14]; -extern const int16_t param_mc_start_bin_per_band_10[10]; -extern const int16_t param_mc_active_bins_per_band_10[10]; -extern const int16_t Param_MC_index[MAX_CICP_CHANNELS]; +extern const Word16 param_mc_band_grouping_20[20 + 1]; +extern const Word16 param_mc_coding_band_mapping_20[20]; +extern const Word16 param_mc_bands_coded_20[4]; +extern const Word16 param_mc_band_grouping_14[14 + 1]; +extern const Word16 param_mc_coding_band_mapping_14[14]; +extern const Word16 param_mc_bands_coded_14[4]; +extern const Word16 param_mc_band_grouping_10[10 + 1]; +extern const Word16 param_mc_coding_band_mapping_10[10]; +extern const Word16 param_mc_bands_coded_10[4]; +extern const Word16 param_mc_start_bin_per_band_20[20]; +extern const Word16 param_mc_active_bins_per_band_20[20]; +extern const Word16 param_mc_start_bin_per_band_14[14]; +extern const Word16 param_mc_active_bins_per_band_14[14]; +extern const Word16 param_mc_start_bin_per_band_10[10]; +extern const Word16 param_mc_active_bins_per_band_10[10]; +extern const Word16 Param_MC_index[MAX_CICP_CHANNELS]; extern const PARAM_MC_CONF ivas_param_mc_conf[PARAM_MC_NUM_CONFIGS]; extern const float ivas_param_mc_quant_ild_5d1_48[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; extern const float ivas_param_mc_quant_icc[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - -extern const uint16_t ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; -extern const uint16_t ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; -extern const uint16_t ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; -extern const uint16_t ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; -extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; -extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp6_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp6_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp12_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp12_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_cicp14_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_cicp14_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; + +extern const UWord16 ivas_param_mc_cum_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS + 1]; +extern const UWord16 ivas_param_mc_sym_freq_ild_combined_48_16bits[PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS]; +extern const UWord16 ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[2 * PARAM_MC_SZ_ILD_QUANTIZER_4BITS - 1]; +extern const UWord16 ivas_param_mc_cum_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER + 1]; +extern const UWord16 ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; +extern const UWord16 ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; /*----------------------------------------------------------------------------------* * MASA ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t bits_direction_masa[DIRAC_DIFFUSE_LEVELS]; -extern const int16_t no_theta_masa[NO_SPHERICAL_GRIDS - 2]; -extern const int16_t no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; +extern const Word16 bits_direction_masa[DIRAC_DIFFUSE_LEVELS]; +extern const Word16 no_theta_masa[NO_SPHERICAL_GRIDS - 2]; +extern const Word16 no_phi_masa[NO_SPHERICAL_GRIDS][MAX_NO_THETA]; extern const float delta_theta_masa[NO_SPHERICAL_GRIDS - 2]; extern const float azimuth_cb[8]; extern const float coherence_cb0_masa[DIRAC_DIFFUSE_LEVELS * 2 * MASA_NO_CV_COH]; extern const float coherence_cb1_masa[MASA_NO_CV_COH1 * MASA_MAXIMUM_CODING_SUBBANDS]; /* 25 */ -extern const int16_t len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS]; -extern const uint8_t sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH]; -extern const int16_t idx_cb_sur_coh_masa[MASA_NO_CV_COH]; -extern const int16_t len_huf_masa[MASA_NO_CV_COH1]; -extern const int16_t huff_code_av_masa[MASA_NO_CV_COH1]; - -extern const int16_t MASA_band_grouping_24[24 + 1]; -extern const int16_t MASA_band_mapping_24_to_18[18 + 1]; -extern const int16_t MASA_band_mapping_24_to_12[12 + 1]; -extern const int16_t MASA_band_mapping_24_to_8[8 + 1]; -extern const int16_t MASA_band_mapping_24_to_5[5 + 1]; - -extern const int16_t MASA_grouping_8_to_5[8]; -extern const int16_t MASA_grouping_12_to_5[12]; -extern const int16_t MASA_grouping_18_to_5[18]; -extern const int16_t MASA_grouping_24_to_5[24]; -extern const int16_t masa_bits[14]; -extern const int16_t masa_bits_LR_stereo[4]; -extern const int16_t mcmasa_bits[]; -extern const uint8_t masa_nbands[]; -extern const uint8_t masa_joined_nbands[]; -extern const uint8_t masa_twodir_bands[]; -extern const uint8_t masa_twodir_bands_joined[]; +extern const Word16 len_cb_dct0_masa[DIRAC_DIFFUSE_LEVELS]; +extern const UWord8 sur_coherence_cb_masa[MASA_NO_CB_SUR_COH * MASA_MAX_NO_CV_SUR_COH]; +extern const Word16 idx_cb_sur_coh_masa[MASA_NO_CV_COH]; +extern const Word16 len_huf_masa[MASA_NO_CV_COH1]; +extern const Word16 huff_code_av_masa[MASA_NO_CV_COH1]; + +extern const Word16 MASA_band_grouping_24[24 + 1]; +extern const Word16 MASA_band_mapping_24_to_18[18 + 1]; +extern const Word16 MASA_band_mapping_24_to_12[12 + 1]; +extern const Word16 MASA_band_mapping_24_to_8[8 + 1]; +extern const Word16 MASA_band_mapping_24_to_5[5 + 1]; + +extern const Word16 MASA_grouping_8_to_5[8]; +extern const Word16 MASA_grouping_12_to_5[12]; +extern const Word16 MASA_grouping_18_to_5[18]; +extern const Word16 MASA_grouping_24_to_5[24]; +extern const Word16 masa_bits[14]; +extern const Word16 masa_bits_LR_stereo[4]; +extern const Word16 mcmasa_bits[]; +extern const UWord8 masa_nbands[]; +extern const UWord8 masa_joined_nbands[]; +extern const UWord8 masa_twodir_bands[]; +extern const UWord8 masa_twodir_bands_joined[]; extern const float diffuseness_reconstructions_hr[HR_MASA_ER_LEVELS]; extern const float diffuseness_thresholds_hr[HR_MASA_ER_LEVELS + 1]; @@ -347,7 +347,7 @@ extern const float McMASA_LFEGain_vectors[64]; * MASA and ISM (OMASA) combined format ROM tables *----------------------------------------------------------------------------------*/ -extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS]; +extern const Word32 sep_object_brate[][MAX_NUM_OBJECTS]; extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; @@ -364,7 +364,7 @@ extern const float ism_elevation_borders[4]; * Param ISM ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; +extern const Word16 Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; /*----------------------------------------------------------------------------------* * LFE coding ROM tables @@ -381,10 +381,10 @@ extern const float ivas_lfe_window_coeff_48k[IVAS_LFE_FADE_LEN_48K]; extern const float ivas_lfe_window_coeff_32k[IVAS_LFE_FADE_LEN_32K]; extern const float ivas_lfe_window_coeff_16k[IVAS_LFE_FADE_LEN_16K]; -extern const int16_t ivas_lfe_num_ele_in_coder_models[2][4]; +extern const Word16 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 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 Word16 ivas_lfe_num_dct_pass_bins_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; +extern const Word16 ivas_lfe_min_shift_tbl[IVAS_LFE_NUM_COEFFS_IN_SUBGRP]; extern const ivas_lfe_freq_models ivas_str_lfe_freq_models; extern const float ivas_lfe_lpf_delay[2]; extern const Word16 ivas_lfe_lpf_delay_Q15[2]; @@ -414,7 +414,7 @@ extern const float ivas_mdft_coeff_cos_twid_40[IVAS_40_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_960[IVAS_960_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_640[IVAS_640_PT_LEN + 1]; extern const float ivas_mdft_coeff_cos_twid_320[IVAS_320_PT_LEN + 1]; -extern const int16_t dirac_gains_P_idx[16]; +extern const Word16 dirac_gains_P_idx[16]; extern const float dirac_gains_norm_term[9]; extern const float dirac_gains_Pnm[91][9]; extern const float dirac_gains_trg_term[181][2]; @@ -429,10 +429,10 @@ extern const Word32 ivas_fb_fcs_12band_1ms_fx[IVAS_FB_BANDS_12]; extern const float ivas_fb_fr_12band_1ms_re[IVAS_FB_12_1MS_LEN]; extern const float ivas_fb_fr_12band_1ms_im[IVAS_FB_12_1MS_LEN]; -extern const int16_t ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; -extern const int16_t ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_abs_bins_per_band_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; +extern const Word16 ivas_fb_abs_bins_start_offset_12band_1ms[IVAS_NUM_SUPPORTED_FS][IVAS_FB_BANDS_12]; extern const float ivas_fb_cf_4ms_48k[IVAS_FB_4MS_48K_SAMP]; extern const float ivas_fb_cf_1ms_48k[IVAS_FB_1MS_48K_SAMP]; @@ -444,41 +444,41 @@ extern const float ivas_fb_cf_1ms_16k[IVAS_FB_1MS_16K_SAMP]; extern const float ivas_fb_resp_cheby_ramp_32del[IVAS_FB_1MS_32K_SAMP + 1]; extern const float ivas_fb_resp_cheby_ramp_16del[IVAS_FB_1MS_16K_SAMP + 1]; -extern const int16_t ivas_num_active_bands[FB - WB + 1]; +extern const Word16 ivas_num_active_bands[FB - WB + 1]; /*------------------------------------------------------------------------------------------* * SNS MSVQ codebooks and means *------------------------------------------------------------------------------------------*/ -extern const int16_t ivas_sns_cdbks_tcx20_levels[]; -extern const int16_t ivas_sns_cdbks_tcx20_bits[]; +extern const Word16 ivas_sns_cdbks_tcx20_levels[]; +extern const Word16 ivas_sns_cdbks_tcx20_bits[]; -extern const int16_t ivas_sns_cdbks_tcx10_levels[]; -extern const int16_t ivas_sns_cdbks_tcx10_bits[]; +extern const Word16 ivas_sns_cdbks_tcx10_levels[]; +extern const Word16 ivas_sns_cdbks_tcx10_bits[]; extern const float *const ivas_sns_cdbks_tcx20[]; extern const float *const ivas_sns_cdbks_tcx10[]; -extern const int16_t ivas_sns_cdbks_side_tcx20_levels[]; -extern const int16_t ivas_sns_cdbks_side_tcx20_bits[]; -extern const int16_t ivas_sns_cdbks_side_tcx10_levels[]; -extern const int16_t ivas_sns_cdbks_side_tcx10_bits[]; +extern const Word16 ivas_sns_cdbks_side_tcx20_levels[]; +extern const Word16 ivas_sns_cdbks_side_tcx20_bits[]; +extern const Word16 ivas_sns_cdbks_side_tcx10_levels[]; +extern const Word16 ivas_sns_cdbks_side_tcx10_bits[]; extern const float *const ivas_sns_cdbks_side_tcx20[]; extern const float *const ivas_sns_cdbks_side_tcx10[]; /* means and codebooks for the split VQ in the 2-stage SNS VQ */ -extern const int16_t sns_1st_cdbk[2][2][8 * 32]; -extern const int16_t sns_1st_means_16k[2][16]; -extern const int16_t sns_1st_means_25k6[2][16]; -extern const int16_t sns_1st_means_32k[2][16]; +extern const Word16 sns_1st_cdbk[2][2][8 * 32]; +extern const Word16 sns_1st_means_16k[2][16]; +extern const Word16 sns_1st_means_25k6[2][16]; +extern const Word16 sns_1st_means_32k[2][16]; /*----------------------------------------------------------------------* * MC ParamUpmix ROM tables *-----------------------------------------------------------------------*/ -extern const int16_t ivas_param_upmx_mx_qmap[33]; +extern const Word16 ivas_param_upmx_mx_qmap[33]; extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_alpha_quant_table; extern const ACPL_QUANT_TABLE ivas_mc_paramupmix_beta_quant_table[9]; diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 269c62d28..dc2e0ad4e 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -605,6 +605,7 @@ const Word32 pow_10_q23[14] = { #endif /* clang-format on */ +// Q15 const Word16 ivas_tan_panning_gain_dirac_tbl_fx[601] = { SHC( 0x8000 ), SHC( 0x8001 ), @@ -1298,6 +1299,7 @@ const Masa_Diffuseness_Ratios masa_diffuse_ratios[DIRAC_DIFFUSE_LEVELS][DIRAC_DI * Stereo ICA ROM tables *----------------------------------------------------------------------------------*/ +// Q31 const Word32 ica_sincInterp2_fx[2 * SINC_ORDER1 + 1] = { 0, -4988604, 0, 7486127, 0, -12594991, 0, 20905753, 0, -33172179, 0, @@ -1310,10 +1312,12 @@ const Word32 ica_sincInterp2_fx[2 * SINC_ORDER1 + 1] = { -4988604, 0 }; +// Q31 const Word32 ica_sincInterp4_fx[2 * SINC_ORDER1 + 1] = { 0, -7054484, -11890617, -10587094, 0, 17813376, 32618130, 29564408, 0, -46911780, -82209968, -71380208, 0, 105465072, 180201792, 153819952, 0, -226492960, -394310208, -349923872, 0, 621904832, 1345701248, 1925805312, 2147483647, 1925805312, 1345701248, 621904832, 0, -349923872, -394310208, -226492960, 0, 153819952, 180201792, 105465072, 0, -71380208, -82209968, -46911780, 0, 29564408, 32618130, 17813376, 0, -10587094, -11890617, -7054484, 0 }; +// Q31 const Word32 ica_sincInterp6_fx[2 * SINC_ORDER1 + 1] = { 0, -7481833, -15444702, -22462678, -25151328, -18893562, 0, 31359704, 68816112, 99516536, 106796512, 75709536, 0, -111862424, -234090752, -326303712, -341870816, -240232560, 0, 371151744, 833251584, 1319259392, 1748116096, 2042624128, 2147483647, 2042624128, 1748116096, 1319259392, 833251584, 371151744, 0, -240232560, -341870816, -326303712, -234090752, -111862424, 0, 75709536, 106796512, 99516536, 68816112, 31359704, 0, -18893562, -25151328, -22462678, -15444702, -7481833, 0 }; @@ -1476,6 +1480,7 @@ const Word32 diffuseness_reconstructions_fx[DIRAC_DIFFUSE_LEVELS] = { 0, 42467328, 96206848, 170655744, 331087872, 508821504, 678952960, 912785408 }; +// Q30 const Word32 diffuseness_thresholds_fx[DIRAC_DIFFUSE_LEVELS + 1] = { 0, 20447232, @@ -1492,10 +1497,12 @@ const Word32 diffuseness_thresholds_fx[DIRAC_DIFFUSE_LEVELS + 1] = { * SPAR ROM tables *------------------------------------------------------------------------------------------*/ +// Q28 const Word32 dtx_pd_real_min_max_fx[2] = { 0, 429496729 }; +// Q31 const Word32 one_by_q_level[64] = { 0, 2147483647, 1073741824, 715827904, 536870912, 429496736, 357913952, 306783392, 268435456, 238609296, 214748368, @@ -1634,6 +1641,7 @@ const Word32 shoebox_sin_cos_tbl_fx[11][2] = { { 0, 1073741824 }, // 0 { 759250112, -759250112 }, { -759250112, -759250112 } }; // 135, -135 //Q.30 +// Q22 const Word32 delta_phi_val[90] = { 0, 1509949440, 754974720, 503316480, 377487360, 301989888, 251658240, 215707056, 188743680, 167772160, 150994944, @@ -1655,6 +1663,7 @@ const Word32 delta_phi_val[90] = { 17557552, 17355740, 17158516, 16965724 }; +// Q31 const Word32 inv_delta_phi_val[90] = { 0, 5965232, 11930464, 17895697, 23860929, 29826161, 35791394, 41756626, 47721858, 53687091, 59652323, @@ -1676,6 +1685,7 @@ const Word32 inv_delta_phi_val[90] = { 513009982, 518975214, 524940447, 530905679 }; +// Q22 const Word32 dd_val[90] = { 0, 754974720, 377487360, 251658240, 188743680, 150994944, 125829120, 107853528, 94371840, 83886080, 75497472, @@ -1749,10 +1759,12 @@ const Word32 dct12_fx[12 * 12] = { // Q31 * ISM ROM tables *----------------------------------------------------------------------------------*/ +// Q22 const Word32 ism_azimuth_borders_fx[4] = { ISM_AZIMUTH_MIN_FX, ISM_AZIMUTH_LOW_BORDER_FX, ISM_AZIMUTH_HIGH_BORDER_FX, ISM_AZIMUTH_MAX_FX }; +// Q22 const Word32 ism_elevation_borders_fx[4] = { ISM_ELEVATION_MIN_FX, ISM_ELEVATION_LOW_BORDER_FX, ISM_ELEVATION_HIGH_BORDER_FX, ISM_ELEVATION_MAX_FX }; @@ -1804,15 +1816,15 @@ const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1] = { /* Q30 */ 0x12c07, 0x2580d, 0x12c07, 0x40000000, 0x818a4580, 0x3e7a6a80 }; -const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { +const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K] = { // Q31 0x0003a373, 0x000608f6, 0x000888a7, 0x000b3e1b, 0x000e34f1, 0x001174a2, 0x00150328, 0x0018e5e1, 0x001d21eb, 0x0021bc4d, 0x0026ba09, 0x002c202f, 0x0031f3dc, 0x00383a43, 0x003ef8ad, 0x0046347b, 0x004df325, 0x00563a3f, 0x005f0f74, 0x00687888, 0x00727b59, 0x007d1ddb, 0x0088661c, 0x00945a41, 0x00a10087, 0x00ae5f3d, 0x00bc7ccd, 0x00cb5fb3, 0x00db0e7d, 0x00eb8fd0, 0x00fcea61, 0x010f24f8, 0x0122466a, 0x013655a0, 0x014b598e, 0x01615936, 0x01785ba8, 0x01906800, 0x01a9855e, 0x01c3baf0, 0x01df0fee, 0x01fb8b90, 0x02193514, 0x023813c4, 0x02582ee4, 0x02798db8, 0x029c378c, 0x02c033a4, 0x02e58944, 0x030c3fa8, 0x03345e0c, 0x035deba0, 0x0388ef8c, 0x03b570f0, 0x03e376dc, 0x04130858, 0x04442c58, 0x0476e9b8, 0x04ab4760, 0x04e14c00, 0x0518fe48, 0x055264c8, 0x058d8600, 0x05ca6850, 0x06091200, 0x06498930, 0x068bd3f0, 0x06cff830, 0x0715fba8, 0x075de408, 0x07a7b6c8, 0x07f37940, 0x084130a0, 0x0890e200, 0x08e29220, 0x093645c0, 0x098c0150, 0x09e3c940, 0x0a3da180, 0x0a998e30, 0x0af792e0, 0x0b57b320, 0x0bb9f240, 0x0c1e5360, 0x0c84d940, 0x0ced8690, 0x0d585dc0, 0x0dc560f0, 0x0e349200, 0x0ea5f2b0, 0x0f198450, 0x0f8f4820, 0x10073f00, 0x10816980, 0x10fdc840, 0x117c5b00, 0x11fd21e0, 0x12801c60, 0x130549a0, 0x138ca8c0, 0x14163880, 0x14a1f740, 0x152fe320, 0x15bffa00, 0x16523980, 0x16e69ee0, 0x177d2700, 0x1815cec0, 0x18b09260, 0x194d6e00, 0x19ec5d60, 0x1a8d5c20, 0x1b306580, 0x1bd57440, 0x1c7c8300, 0x1d258c40, 0x1dd08a00, 0x1e7d7600, 0x1f2c49a0, 0x1fdcfe20, 0x208f8c40, 0x2143ed00, 0x21fa1840, 0x22b20680, 0x236baf40, 0x24270a00, 0x24e40e00, 0x25a2b280, 0x2662ee00, 0x2724b700, 0x27e80400, 0x28acca80, 0x297300c0, 0x2a3a9c00, 0x2b039180, 0x2bcdd680, 0x2c995fc0, 0x2d6621c0, 0x2e341140, 0x2f032240, 0x2fd34900, 0x30a47900, 0x3176a640, 0x3249c440, 0x331dc600, 0x33f29f40, 0x34c842c0, 0x359ea340, 0x3675b3c0, 0x374d66c0, 0x3825af00, 0x38fe7ec0, 0x39d7c880, 0x3ab17e40, 0x3b8b9240, 0x3c65f6c0, 0x3d409d80, 0x3e1b7880, 0x3ef679c0, 0x3fd19340, 0x40acb680, 0x4187d580, 0x4262e280, 0x433dce80, 0x44188c00, 0x44f30c80, 0x45cd4180, 0x46a71e00, 0x47809300, 0x48599300, 0x49320f80, 0x4a09fb80, 0x4ae14880, 0x4bb7e900, 0x4c8dcf80, 0x4d62ee80, 0x4e373880, 0x4f0aa080, 0x4fdd1900, 0x50ae9600, 0x517f0980, 0x524e6780, 0x531ca380, 0x53e9b100, 0x54b58400, 0x55801080, 0x56494b00, 0x57112800, 0x57d79c00, 0x589c9c00, 0x59601d00, 0x5a221480, 0x5ae27880, 0x5ba13e00, 0x5c5e5c00, 0x5d19c880, 0x5dd37a80, 0x5e8b6800, 0x5f418980, 0x5ff5d580, 0x60a84480, 0x6158ce00, 0x62076a80, 0x62b41280, 0x635ebf80, 0x64076a80, 0x64ae0d00, 0x6552a100, 0x65f52080, 0x66958680, 0x6733cd00, 0x67cff000, 0x6869ea80, 0x6901b880, 0x69975600, 0x6a2abf80, 0x6abbf200, 0x6b4aea80, 0x6bd7a680, 0x6c622300, 0x6cea5f80, 0x6d705900, 0x6df40f00, 0x6e758080, 0x6ef4ac80, 0x6f719300, 0x6fec3380, 0x70648f00, 0x70daa580, 0x714e7880, 0x71c00880, 0x722f5780, 0x729c6700, 0x73073980, 0x736fd100, 0x73d62f80, 0x743a5900, 0x749c5080, 0x74fc1880, 0x7559b600, 0x75b52b80, 0x760e7e80, 0x7665b280, 0x76bacc80, 0x770dd180, 0x775ec600, 0x77adb000, 0x77fa9480, 0x78457900, 0x788e6400, 0x78d55b80, 0x791a6500, 0x795d8780, 0x799ec900, 0x79de3100, 0x7a1bc580, 0x7a578d80, 0x7a919100, 0x7ac9d600, 0x7b006500, 0x7b354400, 0x7b687b80, 0x7b9a1300, 0x7bca1180, 0x7bf87f80, 0x7c256400, 0x7c50c780, 0x7c7ab180, 0x7ca32a00, 0x7cca3900, 0x7cefe600, 0x7d143900, 0x7d373a80, 0x7d58f280, 0x7d796800, 0x7d98a380, 0x7db6ad00, 0x7dd38c80, 0x7def4900, 0x7e09eb00, 0x7e237a00, 0x7e3bfd80, 0x7e537d80, 0x7e6a0180, 0x7e7f9080, 0x7e943200, 0x7ea7ed80, 0x7ebaca00, 0x7ecccf00, 0x7ede0300, 0x7eee6d00, 0x7efe1400, 0x7f0cfe80, 0x7f1b3380, 0x7f28b900, 0x7f359500, 0x7f41ce80, 0x7f4d6b80, 0x7f587180, 0x7f62e680, 0x7f6cd000, 0x7f763400, 0x7f7f1780, 0x7f878080, 0x7f8f7380, 0x7f96f580, 0x7f9e0b80, 0x7fa4bb00, 0x7fab0780, 0x7fb0f600, 0x7fb68b00, 0x7fbbca00, 0x7fc0b800, 0x7fc55880, 0x7fc9af80, 0x7fcdc080, 0x7fd18f00, 0x7fd51e80, 0x7fd87280, 0x7fdb8d80, 0x7fde7380, 0x7fe12700, 0x7fe3aa80, 0x7fe60100, 0x7fe82d00, 0x7fea3180, 0x7fec1000, 0x7fedcb00, 0x7fef6500, 0x7ff0e000, 0x7ff23e00, 0x7ff38080, 0x7ff4a980, 0x7ff5ba80, 0x7ff6b580, 0x7ff79c00, 0x7ff86e80, 0x7ff92f80, 0x7ff9e000, 0x7ffa8100, 0x7ffb1380, 0x7ffb9880, 0x7ffc1180, 0x7ffc7f80, 0x7ffce300, 0x7ffd3c80, 0x7ffd8d80, 0x7ffdd680, 0x7ffe1880, 0x7ffe5300, 0x7ffe8800, 0x7ffeb700, 0x7ffee100, 0x7fff0600, 0x7fff2700, 0x7fff4480, 0x7fff5e80, 0x7fff7500, 0x7fff8900, 0x7fff9a80, 0x7fffaa00, 0x7fffb780, 0x7fffc300, 0x7fffcd00, 0x7fffd580, 0x7fffdc80, 0x7fffe300, 0x7fffe880, 0x7fffec80, 0x7ffff080, 0x7ffff380, 0x7ffff680, 0x7ffff880, 0x7ffffa00, 0x7ffffb80, 0x7ffffc80, 0x7ffffd80, 0x7ffffe80, 0x7fffff00, 0x7fffff00, 0x7fffff80, 0x7fffff80, 0x7fffffff, 0x7fffffff }; -const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K] = { +const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K] = { // Q31 0x000474c9, 0x0007fdfd, 0x000c0272, 0x0010a35b, 0x0015f4ae, 0x001c079e, 0x0022ecc2, 0x002ab4c6, 0x003370ac, 0x003d31e5, 0x00480a5f, 0x00540c87, 0x00614b4e, 0x006fda25, 0x007fccfb, 0x0091383a, 0x00a430c2, 0x00b8cbe7, 0x00cf1f67, 0x00e74167, 0x0101486c, 0x011d4b52, 0x013b614e, 0x015ba1d8, 0x017e24ae, 0x01a301c8, 0x01ca514e, 0x01f42b90, 0x0220a900, 0x024fe224, 0x0281ef88, 0x02b6e9c0, 0x02eee954, 0x032a06b4, 0x03685a34, 0x03a9fc00, 0x03ef0408, 0x043789f8, 0x0483a538, 0x04d36cd0, 0x0526f760, 0x057e5b20, 0x05d9adc0, 0x06390470, 0x069c73c0, 0x07040fa8, 0x076feb68, 0x07e01990, 0x0854abe0, 0x08cdb350, 0x094b4000, 0x09cd6120, 0x0a5424d0, 0x0adf9870, 0x0b6fc830, 0x0c04bf20, 0x0c9e8760, 0x0d3d29c0, 0x0de0ade0, 0x0e891a50, 0x0f367440, 0x0fe8bfa0, 0x109fff00, 0x115c33a0, 0x121d5d80, 0x12e37b00, 0x13ae8960, 0x147e8440, 0x155365c0, 0x162d26c0, 0x170bbe80, 0x17ef22e0, 0x18d74820, 0x19c42100, 0x1ab59f20, 0x1babb200, 0x1ca64840, 0x1da54e80, 0x1ea8b080, 0x1fb057e0, 0x20bc2d80, 0x21cc1800, 0x22dffd40, 0x23f7c1c0, 0x25134800, 0x26327200, 0x27552000, 0x287b30c0, 0x29a48280, 0x2ad0f180, 0x2c005940, 0x2d329440, 0x2e677c00, 0x2f9ee880, 0x30d8b100, 0x3214ac40, 0x3352afc0, 0x34929040, 0x35d421c0, 0x37173780, 0x385ba480, 0x39a13b00, 0x3ae7cc40, 0x3c2f2a00, 0x3d7724c0, 0x3ebf8d80, 0x40083400, 0x4150e980, 0x42997d80, 0x43e1c000, 0x45298180, 0x46709200, 0x47b6c280, 0x48fbe380, 0x4a3fc600, 0x4b823b80, 0x4cc31600, 0x4e022800, 0x4f3f4500, 0x507a4080, 0x51b2ee80, 0x52e92580, 0x541cba80, 0x554d8580, 0x567b5e00, 0x57a61d80, 0x58cd9e00, 0x59f1bb80, 0x5b125200, 0x5c2f3f00, 0x5d486280, 0x5e5d9d00, 0x5f6ecf80, 0x607bde00, 0x6184ad00, 0x62892280, 0x63892680, 0x6484a280, 0x657b8100, 0x666daf00, 0x675b1980, 0x6843b100, 0x69276680, 0x6a062d00, 0x6adff980, 0x6bb4c180, 0x6c847d80, 0x6d4f2680, 0x6e14b800, 0x6ed52e80, 0x6f908900, 0x7046c680, 0x70f7e880, 0x71a3f300, 0x724aea00, 0x72ecd300, 0x7389b680, 0x74219c80, 0x74b48f80, 0x75429b80, 0x75cbcc80, 0x76503100, 0x76cfd800, 0x774ad280, 0x77c13180, 0x78330780, 0x78a06880, 0x79096800, 0x796e1b80, 0x79ce9980, 0x7a2af880, 0x7a835000, 0x7ad7b800, 0x7b284980, 0x7b751c80, 0x7bbe4c00, 0x7c03f080, 0x7c462580, 0x7c850480, 0x7cc0a880, 0x7cf92c00, 0x7d2eaa80, 0x7d613e00, 0x7d910180, 0x7dbe0f80, 0x7de88300, 0x7e107600, 0x7e360300, 0x7e594280, 0x7e7a4f80, 0x7e994200, 0x7eb63280, 0x7ed13a00, 0x7eea6f00, 0x7f01e980, 0x7f17c000, 0x7f2c0800, 0x7f3ed780, 0x7f504280, 0x7f605d80, 0x7f6f3c00, 0x7f7cf100, 0x7f898e00, 0x7f952500, 0x7f9fc600, 0x7fa98200, 0x7fb26800, 0x7fba8680, 0x7fc1eb80, 0x7fc8a400, 0x7fcebd80, 0x7fd44380, 0x7fd94100, 0x7fddc180, 0x7fe1ce80, 0x7fe57180, 0x7fe8b400, 0x7feb9d80, 0x7fee3680, 0x7ff08600, 0x7ff29280, 0x7ff46300, 0x7ff5fc80, 0x7ff76500, 0x7ff8a180, 0x7ff9b600, 0x7ffaa780, 0x7ffb7900, 0x7ffc2e80, 0x7ffccb80, 0x7ffd5200, 0x7ffdc580, 0x7ffe2800, 0x7ffe7b80, 0x7ffec200, 0x7ffefd80, 0x7fff2f00, 0x7fff5880, 0x7fff7a80, 0x7fff9680, 0x7fffad80, 0x7fffc000, 0x7fffcf00, 0x7fffdb00, 0x7fffe480, 0x7fffeb80, 0x7ffff180, 0x7ffff580, 0x7ffff900, 0x7ffffb00, 0x7ffffd00, 0x7ffffe00, 0x7fffff00, 0x7fffff80, 0x7fffffff, 0x7fffffff }; -const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K] = { +const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K] = { // Q31 0x00064d50, 0x000e283c, 0x0018b753, 0x00267552, 0x0037e397, 0x004d8c2b, 0x006801d2, 0x0087dfb9, 0x00adc8fc, 0x00da680b, 0x010e6df8, 0x014a91a0, 0x018f8ecc, 0x01de252a, 0x02371734, 0x029b2908, 0x030b1f1c, 0x0387bd00, 0x0411c3e8, 0x04a9f148, 0x0550fd60, 0x060799b0, 0x06ce6f88, 0x07a61e78, 0x088f3ad0, 0x098a4c30, 0x0a97cc00, 0x0bb82430, 0x0cebadd0, 0x0e32afe0, 0x0f8d5df0, 0x10fbd760, 0x127e2680, 0x14143f40, 0x15bdff00, 0x177b2bc0, 0x194b7440, 0x1b2e6f00, 0x1d239ae0, 0x1f2a5ee0, 0x21420ac0, 0x2369d700, 0x25a0e640, 0x27e64500, 0x2a38ebc0, 0x2c97bfc0, 0x2f019400, 0x31752b00, 0x33f13800, 0x36746180, 0x38fd42c0, 0x3b8a6cc0, 0x3e1a6a80, 0x40abc080, 0x433cf080, 0x45cc7c80, 0x4858e600, 0x4ae0b400, 0x4d627280, 0x4fdcb500, 0x524e1b00, 0x54b54e80, 0x57110880, 0x59601300, 0x5ba14800, 0x5dd39780, 0x5ff60500, 0x6207aa80, 0x6407ba80, 0x65f57e80, 0x67d05b00, 0x6997cc80, 0x6b4b6b00, 0x6ceae880, 0x6e761080, 0x6fecc980, 0x714f1280, 0x729d0480, 0x73d6ce80, 0x74fcb800, 0x760f1d80, 0x770e6e80, 0x77fb2f00, 0x78d5f280, 0x799f5b80, 0x7a581b80, 0x7b00ec80, 0x7b9a9480, 0x7c25df80, 0x7ca39e80, 0x7d14a680, 0x7d79ce00, 0x7dd3eb00, 0x7e23d180, 0x7e6a5180, 0x7ea83680, 0x7ede4580, 0x7f0d3a80, 0x7f35cb00, 0x7f58a180, 0x7f765e80, 0x7f8f9880, 0x7fa4db80, 0x7fb6a700, 0x7fc57100, 0x7fd1a400, 0x7fdb9f80, 0x7fe3b980, 0x7fea3e00, 0x7fef6f80, 0x7ff38900, 0x7ff6bc80, 0x7ff93500, 0x7ffb1780, 0x7ffc8300, 0x7ffd9080, 0x7ffe5500, 0x7ffee280, 0x7fff4580, 0x7fff8a00, 0x7fffb800, 0x7fffd580, 0x7fffe880, 0x7ffff400, 0x7ffffa00, 0x7ffffd80, 0x7fffff00, 0x7fffffff }; @@ -1826,6 +1838,7 @@ const UWord32 d_hamm_lfe_plc_fx[LFE_PLC_LENANA / 2] = { 171798688, 172140032, 17 * MDFT/iMDFT ROM tables *------------------------------------------------------------------------------------------*/ +// Q31 const Word32 ivas_mdft_coeff_cos_twid_960_fx[IVAS_960_PT_LEN + 1] = { 2147483647, 2147480832, 2147472128, 2147457792, 2147437696, @@ -2070,6 +2083,7 @@ const Word32 ivas_mdft_coeff_cos_twid_960_fx[IVAS_960_PT_LEN + 1] = { 10541393, 7027612, 3513810, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_640_fx[IVAS_640_PT_LEN + 1] = { 2147483647, 2147477120, 2147457792, 2147425408, 2147380096, @@ -2234,6 +2248,7 @@ const Word32 ivas_mdft_coeff_cos_twid_640_fx[IVAS_640_PT_LEN + 1] = { 15812011, 10541393, 5270713, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_320_fx[IVAS_320_PT_LEN + 1] = { 2147483647, 2147457792, 2147380096, 2147250816, 2147069696, @@ -2318,6 +2333,7 @@ const Word32 ivas_mdft_coeff_cos_twid_320_fx[IVAS_320_PT_LEN + 1] = { 31623164, 21082532, 10541393, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_240_fx[IVAS_240_PT_LEN + 1] = { 2147483647, 2147437696, 2147299712, 2147069696, 2146747776, @@ -2382,6 +2398,7 @@ const Word32 ivas_mdft_coeff_cos_twid_240_fx[IVAS_240_PT_LEN + 1] = { 42163032, 28109692, 14055147, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_160_fx[IVAS_160_PT_LEN + 1] = { 2147483647, 2147380096, 2147069696, 2146552320, 2145827968, @@ -2426,6 +2443,7 @@ const Word32 ivas_mdft_coeff_cos_twid_160_fx[IVAS_160_PT_LEN + 1] = { 63239472, 42163032, 21082532, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_120_fx[IVAS_120_PT_LEN + 1] = { 2147483647, 2147299712, 2146747776, 2145827968, 2144540544, @@ -2460,6 +2478,7 @@ const Word32 ivas_mdft_coeff_cos_twid_120_fx[IVAS_120_PT_LEN + 1] = { 84309816, 56214568, 28109692, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_80_fx[IVAS_80_PT_LEN + 1] = { 2147483647, 2147069696, 2145827968, 2143759104, 2140863616, @@ -2484,6 +2503,7 @@ const Word32 ivas_mdft_coeff_cos_twid_80_fx[IVAS_80_PT_LEN + 1] = { 126424088, 84309816, 42163032, 0 }; +// Q31 const Word32 ivas_mdft_coeff_cos_twid_40_fx[IVAS_40_PT_LEN + 1] = { 2147483647, 2145827968, 2140863616, 2132598272, 2121044608, @@ -2978,26 +2998,32 @@ const Word32 dirac_gains_trg_term_fx[181][2] = { * FB ROM tables *------------------------------------------------------------------------------------------*/ +// Q15 const Word16 ivas_fb_cf_4ms_48k_fx[IVAS_FB_4MS_48K_SAMP] = { 0, 4, 13, 26, 44, 66, 92, 123, 158, 197, 241, 289, 341, 398, 458, 524, 593, 667, 744, 826, 913, 1003, 1097, 1196, 1298, 1405, 1516, 1630, 1749, 1871, 1998, 2128, 2262, 2400, 2541, 2687, 2836, 2988, 3144, 3304, 3467, 3634, 3804, 3977, 4154, 4334, 4517, 4704, 4893, 5086, 5282, 5480, 5682, 5886, 6094, 6304, 6516, 6732, 6949, 7170, 7393, 7618, 7846, 8076, 8308, 8542, 8779, 9017, 9258, 9500, 9744, 9990, 10238, 10487, 10738, 10990, 11244, 11499, 11756, 12014, 12273, 12533, 12794, 13056, 13319, 13582, 13847, 14112, 14378, 14644, 14911, 15178, 15446, 15713, 15981, 16249, 16518, 16786, 17054, 17321, 17589, 17856, 18123, 18389, 18655, 18920, 19185, 19448, 19711, 19973, 20234, 20494, 20753, 21011, 21268, 21523, 21777, 22029, 22280, 22529, 22777, 23023, 23267, 23509, 23750, 23988, 24225, 24459, 24691, 24921, 25149, 25374, 25597, 25818, 26035, 26251, 26463, 26673, 26881, 27085, 27287, 27485, 27681, 27874, 28063, 28250, 28433, 28613, 28790, 28963, 29133, 29300, 29463, 29623, 29779, 29931, 30080, 30226, 30367, 30505, 30639, 30769, 30896, 31018, 31137, 31251, 31362, 31469, 31571, 31670, 31764, 31854, 31941, 32023, 32100, 32174, 32243, 32309, 32369, 32426, 32478, 32526, 32570, 32609, 32644, 32675, 32701, 32723, 32741, 32754, 32763, 32767 }; +// Q15 const Word16 ivas_fb_cf_4ms_32k_fx[IVAS_FB_4MS_32K_SAMP] = { 1, 11, 30, 60, 99, 149, 208, 276, 355, 443, 541, 648, 765, 891, 1026, 1171, 1325, 1488, 1660, 1840, 2030, 2228, 2435, 2650, 2873, 3105, 3345, 3592, 3847, 4110, 4380, 4657, 4941, 5233, 5530, 5835, 6146, 6463, 6786, 7115, 7449, 7789, 8134, 8483, 8838, 9197, 9561, 9928, 10300, 10675, 11054, 11435, 11820, 12208, 12598, 12990, 13385, 13781, 14179, 14578, 14978, 15379, 15780, 16182, 16585, 16987, 17388, 17789, 18189, 18588, 18986, 19382, 19777, 20169, 20559, 20947, 21332, 21713, 22092, 22467, 22839, 23206, 23570, 23929, 24284, 24633, 24978, 25318, 25652, 25981, 26304, 26621, 26932, 27237, 27534, 27826, 28110, 28387, 28657, 28920, 29175, 29422, 29662, 29894, 30117, 30332, 30539, 30737, 30927, 31107, 31279, 31442, 31596, 31741, 31876, 32002, 32119, 32226, 32324, 32412, 32491, 32559, 32618, 32668, 32707, 32737, 32756, 32766 }; +// Q15 const Word16 ivas_fb_cf_4ms_16k_fx[IVAS_FB_4MS_16K_SAMP] = { 4, 44, 123, 241, 398, 593, 826, 1097, 1405, 1749, 2128, 2541, 2988, 3467, 3977, 4517, 5086, 5682, 6304, 6949, 7618, 8308, 9017, 9744, 10487, 11244, 12014, 12794, 13582, 14378, 15178, 15981, 16786, 17589, 18389, 19185, 19973, 20753, 21523, 22280, 23023, 23750, 24459, 25149, 25818, 26463, 27085, 27681, 28250, 28790, 29300, 29779, 30226, 30639, 31018, 31362, 31670, 31941, 32174, 32369, 32526, 32644, 32723, 32763 }; +// Q15 const Word16 ivas_fb_cf_1ms_48k_fx[IVAS_FB_1MS_48K_SAMP] = { 8, 78, 218, 427, 705, 1050, 1460, 1934, 2470, 3066, 3718, 4425, 5184, 5990, 6840, 7732, 8660, 9622, 10612, 11627, 12663, 13715, 14778, 15847, 16920, 17989, 19052, 20104, 21140, 22155, 23145, 24107, 25035, 25927, 26777, 27583, 28342, 29049, 29701, 30297, 30833, 31307, 31717, 32062, 32340, 32549, 32689, 32759 }; +// Q15 const Word16 ivas_fb_cf_1ms_32k_fx[IVAS_FB_1MS_32K_SAMP] = { 19, 177, 491, 957, 1573, 2330, 3224, 4244, 5381, 6624, 7960, 9378, 10864, 12403, 13979, 15580, 17187, 18788, 20364, 21903, 23389, 24807, 26143, 27386, 28523, 29543, 30437, 31194, 31810, 32276, 32590, 32748 }; +// Q15 const Word16 ivas_fb_cf_1ms_16k_fx[IVAS_FB_1MS_16K_SAMP] = { 78, 705, 1934, 3718, 5990, 8660, 11627, 14778, 17989, 21140, 24107, 26777, 29049, 30833, 32062, 32689 }; @@ -4020,6 +4046,7 @@ const Word32 ivas_sine_frame_len_640_del_32_fx[577] = { }; +/* Q Factor is 30 */ const Word32 ivas_sine_frame_len_640_del_16_fx[289] = { 1073725952, 1073678400, 1073599104, 1073488064, 1073345344, 1073170880, 1072964736, 1072726912, 1072457408, 1072156160, 1071823296, diff --git a/lib_com/ivas_rom_com_fx.h b/lib_com/ivas_rom_com_fx.h index 4cf61f9ae..2460cd383 100644 --- a/lib_com/ivas_rom_com_fx.h +++ b/lib_com/ivas_rom_com_fx.h @@ -224,9 +224,9 @@ extern const Word32 ivas_lpf_2_butter_16k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_32k_fx[IVAS_BIQUAD_FILT_LEN << 1]; extern const Word32 ivas_lpf_2_butter_48k_fx[IVAS_BIQUAD_FILT_LEN << 1]; -extern const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K]; -extern const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K]; -extern const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K]; +extern const Word32 ivas_lfe_window_coeff_48k_fx[IVAS_LFE_FADE_LEN_48K]; // Q31 +extern const Word32 ivas_lfe_window_coeff_32k_fx[IVAS_LFE_FADE_LEN_32K]; // Q31 +extern const Word32 ivas_lfe_window_coeff_16k_fx[IVAS_LFE_FADE_LEN_16K]; // Q31 extern const UWord32 d_hamm_lfe_plc_fx[LFE_PLC_LENANA / 2]; diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 3c7b4e620..0207e3e19 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -41,6 +41,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index f5f4c423d..829f4e5e8 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -42,6 +42,7 @@ #include "wmc_auto.h" #include "rom_com.h" #include "ivas_rom_com.h" +#include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 942135fbd..d615e511b 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9593,12 +9593,12 @@ void addBassPostFilter_ivas_fx( Word32 **iAnalysis_fx, HANDLE_CLDFB_FILTER_BANK cldfb ); -Word32 ism_dequant_meta_fx( - 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 */ +Word32 ism_dequant_meta_fx( /* o : Q22*/ + const Word16 idx, /* i : quantizer index */ + const Word32 borders_fx[], /* i : level borders Q22*/ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22*/ + const Word16 cbsize /* i : codebook size */ ); void save_synthesis_hq_fec_fx( diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index df1ae4cc8..677e37baf 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -10,6 +10,7 @@ #include "basop_util.h" #include "cnst.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #include "ivas_prot.h" #include "ivas_rom_com.h" diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 834691ce0..3fcf4610b 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -45,6 +45,7 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index f38fe4612..fa0a6c053 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #include "ivas_rom_com_fx.h" #include "debug.h" #define NUM_TAPS_F0_6 ( Word16 )( 58 ) // (Word16) ceil( 0.6f * hBinRenConvModule->numTaps ) diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 9765facd6..bec9d70d9 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -40,6 +40,7 @@ #include "wmc_auto.h" #include "prot_fx.h" #include "math.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local function definitions diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 3f50f3816..ef42ebe55 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -40,6 +40,7 @@ #include "prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" #endif diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 8a82dabd2..b2e00ffc2 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -41,6 +41,7 @@ #include "prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" #include "prot_fx.h" #endif diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index 1863e11ae..a2ca9f3c2 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -42,6 +42,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" #include "ivas_rom_com_fx.h" +#include "ivas_prot_fx.h" /*------------------------------------------------------------------- * sns_1st_dec_fx() diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 886db7651..5b3d2000b 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -4459,7 +4459,7 @@ static void ivas_parse_parameter_bitstream_dtx( move16(); } pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); - val_fx = dtx_pd_real_min_max_fx[0]; /*Q0*/ + val_fx = dtx_pd_real_min_max_fx[0]; /*Q28*/ move32(); 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 = add( pd, idx ); diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index e0c210a2f..1cb20cc22 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -39,7 +39,7 @@ #include #include "wmc_auto.h" #include "prot_fx.h" - +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 03f85a5d6..73214cb3c 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -41,6 +41,7 @@ #include "prot_fx.h" #include "ivas_prot.h" #include "wmc_auto.h" +#include "ivas_prot_fx.h" #ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * tdm_low_rate_dec() diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index a81e22f25..a50c98d09 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -9,6 +9,7 @@ #include "prot_fx.h" /* Function prototypes */ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE #include "ivas_prot.h" +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_enc/cod_tcx.c b/lib_enc/cod_tcx.c index 502b22aed..a5152dcb6 100644 --- a/lib_enc/cod_tcx.c +++ b/lib_enc/cod_tcx.c @@ -47,6 +47,7 @@ #include "ivas_rom_com_fx.h" #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*-------------------------------------------------------------------* * HBAutocorrelation() diff --git a/lib_enc/find_uv.c b/lib_enc/find_uv.c index f51a259bc..7acb99f49 100644 --- a/lib_enc/find_uv.c +++ b/lib_enc/find_uv.c @@ -562,6 +562,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); #ifdef BASOP_NOGLOB if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, 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], 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 */ diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 7c5223b42..3804b1a9e 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -38,6 +38,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*------------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index a4f7731e1..ca21f7b64 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -45,6 +45,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_adapt_GR_enc.c b/lib_enc/ivas_stereo_adapt_GR_enc.c index f98b453a0..b1c490c78 100644 --- a/lib_enc/ivas_stereo_adapt_GR_enc.c +++ b/lib_enc/ivas_stereo_adapt_GR_enc.c @@ -38,7 +38,7 @@ #include "stat_enc.h" #include "wmc_auto.h" #include "ivas_rom_com.h" - +#include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local function prototypes diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 683907e8a..ef62186fe 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -45,6 +45,7 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx_enc.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 18ef67dbf..4618eaaa6 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -14,6 +14,7 @@ #include "prot_fx_enc.h" /* Function prototypes */ #include "ivas_prot.h" /* Function prototypes */ #include "stl.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------* diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 78ebf384d..95ab75f93 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -49,6 +49,7 @@ #ifdef IVAS_FLOAT_FIXED #include "control.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) #endif diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index 01bd6edab..dd71510d7 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -42,6 +42,7 @@ #include "ivas_rom_rend.h" #include "wmc_auto.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*------------------------------------------------------------------------- * Local constants diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index ef7f34e82..f30bb1237 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -45,6 +45,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx.h" /* Function prototypes */ +#include "ivas_prot_fx.h" #endif #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 28ba346ca..f12d122b7 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -37,6 +37,7 @@ #include "ivas_error.h" #include "wmc_auto.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open() diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 4a23da243..ccf81a09d 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -40,6 +40,7 @@ #include "ivas_cnst.h" #include #include "wmc_auto.h" +#include "ivas_prot_fx.h" /*-------------------------------------------------------------------* * ivas_sba_prototype_renderer() diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 4c14067ec..ad0de1534 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -40,6 +40,7 @@ #include "ivas_stat_dec.h" #include "wmc_auto.h" #include "prot_fx.h" +#include "ivas_prot_fx.h" /*-----------------------------------------------------------------------* * Local constants diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 0fe9ed71d..625302e11 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -36,6 +36,7 @@ #include "ivas_prot_rend.h" #include "prot_fx.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" /*---------------------------------------------------------------------* * Local structures -- GitLab From 0da5f29bef3fefb7071cec64d16bf0ce913ec319 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:37:01 +0530 Subject: [PATCH 33/39] Q info updates, encoder cleanup --- lib_com/arith_coder.c | 162 ++-- lib_com/arith_coder_fx.c | 124 ++-- lib_com/basop_com_lpc.c | 79 +- lib_com/basop_lsf_tools.c | 64 +- lib_com/basop_proto_func.h | 61 +- lib_com/basop_tcx_utils.c | 89 ++- lib_com/bitalloc.c | 209 +++--- lib_com/bitalloc_fx.c | 165 +++-- lib_com/core_com_config.c | 296 ++++---- lib_com/deemph.c | 54 +- lib_com/delay_comp.c | 24 +- lib_com/dlpc_bfi_fx.c | 26 +- lib_com/enhancer_fx.c | 78 +- lib_com/est_tilt_fx.c | 20 +- lib_com/fd_cng_com.c | 45 +- lib_com/fd_cng_com_fx.c | 102 +-- lib_com/ivas_prot_fx.h | 52 +- lib_com/ivas_sba_config.c | 13 +- lib_com/ivas_sns_com_fx.c | 71 +- lib_com/ivas_spar_com.c | 1099 ++++++++++++++-------------- lib_com/ivas_spar_com_quant_util.c | 76 +- lib_com/ivas_stat_com.h | 2 +- lib_com/ivas_stereo_dft_com.c | 17 +- lib_com/ivas_stereo_eclvq_com_fx.c | 15 +- lib_com/log2.c | 10 +- lib_com/log2.h | 14 +- lib_com/logqnorm_fx.c | 30 +- lib_com/low_rate_band_att_fx.c | 8 +- lib_com/lpc_tools.c | 16 +- lib_com/lpc_tools_fx.c | 54 +- lib_com/lsf_dec_bfi_fx.c | 10 +- lib_com/lsf_msvq_ma_fx.c | 6 +- lib_com/lsf_tools.c | 96 +-- lib_com/lsf_tools_fx.c | 237 +++--- lib_com/lsp_conv_poly_fx.c | 4 +- lib_com/modif_fs.c | 187 ++--- lib_com/modif_fs_fx.c | 34 +- lib_com/mslvq_com_fx.c | 8 + lib_com/nelp_fx.c | 4 +- lib_com/parameter_bitmaping.c | 3 + lib_com/prot.h | 14 +- lib_com/prot_fx.h | 222 +++--- lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/hq_core_dec_fx.c | 2 +- lib_enc/core_enc_init.c | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 4 + 48 files changed, 2028 insertions(+), 1890 deletions(-) diff --git a/lib_com/arith_coder.c b/lib_com/arith_coder.c index bba7ab973..ce16e7a7b 100644 --- a/lib_com/arith_coder.c +++ b/lib_com/arith_coder.c @@ -65,11 +65,11 @@ Word16 expfp_evs( assert( x <= 0 ); - L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); + L_tmp = L_negate( L_shl( L_deposit_h( x ), sub( x_e, 15 ) ) ); /* Q16 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q0 */ + xf = extract_l( L_tmp ); /* Q16 */ BASOP_SATURATE_WARNING_OFF; xf = negate( xf ); @@ -81,13 +81,13 @@ Word16 expfp_evs( + ((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 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ + tmp = shr( mult( xf, xf ), 2 ); /* Q15 */ + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -105,7 +105,7 @@ Word16 expfp_evs( 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 ) ) ); /* Q16 */ /* zero for xi >= 16 */ if ( shr( xi, 4 ) > 0 ) @@ -157,44 +157,44 @@ void powfp_odd2_evs( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } - k = sub( k, 1 ); + k--; h = shl( 1, k ); /* highest bit of exp2 */ - out2 = base; + out2 = base; /* Q15 */ move16(); - out = mult_r( out, pows[add( 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 ) { - out2 = mult_r( out2, pows[add( k, 1 )] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); - FOR( k = sub( k, 1 ); k >= 0; k-- ) + FOR( k = k - 1; k >= 0; k-- ) { if ( s_and( exp, h ) != 0 ) { - out = mult_r( out, pows[k + 1] ); + out = mult_r( out, pows[k + 1] ); /* Q15 */ } if ( s_and( exp2, h ) != 0 ) { - out2 = mult_r( out2, pows[k + 1] ); + out2 = mult_r( out2, pows[k + 1] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); return; @@ -256,8 +256,8 @@ void tcx_arith_scale_envelope_ivas( 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 ); + assert( LE_32( L_tmp, 32768 ) ); + target_bits = extract_l( L_tmp ); /* Q0 */ /* Calculate inverse envelope and find initial scale guess based on mean */ mean = L_deposit_l( 0 ); @@ -271,22 +271,22 @@ void tcx_arith_scale_envelope_ivas( #ifndef BASOP_NOGLOB tmp = Inv16( round_fx( L_shl( env[k], tmp ) ), &tmp2 ); #else /* BASOP_NOGLOB */ - tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); + tmp = Inv16( round_fx_o( L_shl( env[k], tmp ), &Overflow ), &tmp2 ); /* exp(tmp2) */ #endif /* BASOP_NOGLOB */ ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); - mean = L_add( mean, ienv[k] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); - tmp2 = div_s( 8192, shl( L_frame, tmp ) ); + tmp2 = div_s( 8192, shl( L_frame, tmp ) ); /* Q15 */ tmp = shl( tmp2, 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 = powf(mean, (float)L_frame / target_bits * 0.357f); */ - tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); - tmp = mult_r( tmp, FL2WORD16( 0.357f ) ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + tmp = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ + tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(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 @@ -294,22 +294,22 @@ void tcx_arith_scale_envelope_ivas( * 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, FL2WORD16_SCALE( 2.71828183f, 2 ) ), tmp ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ a_e = add( shl( mean_e, 1 ), 3 ); /* b = (0.15f - powf(2.0f, target_bits/(float)L_frame)) * mean; */ - tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); + tmp = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(tmp2) */ tmp = round_fx( BASOP_util_Pow2( L_deposit_h( tmp ), tmp2, &tmp2 ) ); - b_e = BASOP_Util_Add_MantExp( FL2WORD16( 0.15f ), 0, negate( tmp ), tmp2, &b ); - b = mult_r( b, round_fx( mean ) ); + b_e = BASOP_Util_Add_MantExp( 4915 /*0.15f in Q15*/, 0, negate( tmp ), tmp2, &b ); + b = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + sqrtf(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ #ifndef BASOP_NOGLOB tmp = round_fx( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), a_e, &tmp2 ) ); #else - tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, FL2WORD16( -4.0f * 0.035f ) ), 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 ); /* Q15 - a_e */ #endif IF( tmp <= 0 ) @@ -328,34 +328,34 @@ void tcx_arith_scale_envelope_ivas( } tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); - scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); + scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); /* exp(tmp) */ #ifndef BASOP_NOGLOB scale = shl( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */ #else - 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 */ #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 ); /* exp(iscale_e) */ lob = 0; move16(); hib = 0; move16(); - max_iter = 2; + max_iter = 2; /* Q0 */ move16(); if ( low_complexity ) { - max_iter = 1; + max_iter = 1; /* Q0 */ move16(); } FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -364,65 +364,65 @@ void tcx_arith_scale_envelope_ivas( { s = Mpy_32_16_1( ienv[k], scale ); /* Q16 */ - IF( L_sub( s, FL2WORD32_SCALE( 0.08f, 15 ) ) <= 0 ) + IF( L_sub( s, 5243l /*0.08f Q16*/ ) <= 0 ) { /* 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, FL2WORD16_SCALE( 1.0224, 1 ) ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } - ELSE IF( L_sub( s, FL2WORD32_SCALE( 255.0, 15 ) ) <= 0 ) + ELSE IF( L_sub( s, 16711680l /*255.0 Q16*/ ) <= 0 ) { /* a = 5.436564f * s + 0.15f + 0.035f * env[k] * iscale; */ - L_tmp = L_shl( Mpy_32_16_1( s, FL2WORD16_SCALE( 5.436564f, 3 ) ), 3 ); - L_tmp = L_add( L_tmp, FL2WORD32_SCALE( 0.15f, 15 ) ); - L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( FL2WORD16( 0.035f ), iscale ) ), iscale_e ) ); + L_tmp = L_shl( Mpy_32_16_1( s, 22268 /*5.436564f Q12*/ ), 3 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifndef BASOP_NOGLOB statesi = mult_r( statesi, round_fx( L_shl( L_tmp, tmp ) ) ); -#else /* BASOP_NOGLOB */ - statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); -#endif /* BASOP_NOGLOB */ - bits = add( bits, sub( 15, tmp ) ); +#else /* BASOP_NOGLOB */ + statesi = mult_r( statesi, round_fx_o( L_shl( L_tmp, tmp ), &Overflow ) ); /* */ +#endif /* BASOP_NOGLOB */ + bits = add( bits, sub( 15, tmp ) ); /* Q0 */ tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } 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, FL2WORD16_SCALE( 5.436564f * 1.4142f, 3 ) ); /* 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 ) ) ); /* Q0 */ } } IF( sub( bits, target_bits ) <= 0 ) { /* Bits leftover => scale is too small */ - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); 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 ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ /* adjust = 1.05f * target_bits / (float)bits; scale *= adjust; */ - adjust = mult_r( FL2WORD16_SCALE( 1.05f, 1 ), target_bits ); - adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); + adjust = mult_r( 17203 /*1.05f Q14*/, target_bits ); /* Q15 */ + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -431,13 +431,13 @@ void tcx_arith_scale_envelope_ivas( /* Ran out of bits => scale is too large */ hib = scale; move16(); - hib_bits = bits; + hib_bits = bits; /* Q0 */ move16(); 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 ) ); /* Q15 */ + scale = add( mult_r( sub( lob, hib ), adjust ), hib ); /* Q0 */ } ELSE { /* Initial scale adaptation */ @@ -449,13 +449,13 @@ void tcx_arith_scale_envelope_ivas( FOR( k = 0; k < L_frame; k++ ) { - s_env[k] = 0; + s_env[k] = 0; /* Q15 - e */ move16(); } } 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 ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -476,10 +476,10 @@ void tcx_arith_scale_envelope_ivas( } ELSE { - iscale = Inv16( scale, &iscale_e ); + iscale = Inv16( scale, &iscale_e ); /* exp(iscale_e) */ } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -495,9 +495,9 @@ void tcx_arith_scale_envelope_ivas( 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 ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } @@ -519,13 +519,13 @@ void tcx_arith_scale_envelope_ivas( *-------------------------------------------------------------------------*/ void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - 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 Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ) { Word16 k; @@ -545,7 +545,7 @@ void tcx_arith_render_envelope_ivas( /* Compute weighted signal envelope in perceptual domain */ 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] ); /* exp(signal_env_e + gainlpc_e) */ move16(); signal_env_e[k] = add( signal_env_e[k], gainlpc_e[k] ); move16(); @@ -554,7 +554,7 @@ void tcx_arith_render_envelope_ivas( /* Adaptive low frequency emphasis */ FOR( k = 0; k < L_frame; k++ ) { - env[k] = 0x10000; + env[k] = 0x10000; /* 1 in Q16 */ move32(); } @@ -565,7 +565,7 @@ void tcx_arith_render_envelope_ivas( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 64cc81d04..58ab13175 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -21,11 +21,11 @@ Word32 expfp( /* o: Q31 */ assert( x > 0 ); - L_tmp = L_shl( L_deposit_h( x ), x_e ); + L_tmp = L_shl( L_deposit_h( x ), x_e ); /* Q31 */ /* split into integer and fractional parts */ - xi = round_fx( L_tmp ); - xf = extract_l( L_tmp ); + xi = round_fx( L_tmp ); /* Q15 */ + xf = extract_l( L_tmp ); /* Q31 */ BASOP_SATURATE_WARNING_OFF_EVS; xf = negate( xf ); @@ -37,13 +37,13 @@ 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 ); + y = L_mac0( 65536, xf, 1 ); /* Q16 */ tmp = shr( mult( xf, xf ), 2 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( shr( mult( tmp, xf ), 1 ), 65536 / 3 ), 1 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ tmp = shr( mult( tmp, xf ), 3 ); - y = L_mac0( y, tmp, 1 ); + y = L_mac0( y, tmp, 1 ); /* Q16 */ /* Integer part */ b0 = s_and( xi, 1 ); @@ -51,19 +51,19 @@ Word32 expfp( /* o: Q31 */ 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 */ } - if ( b1 != 0 ) + IF( b1 != 0 ) { 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 */ } - if ( b3 != 0 ) + IF( b3 != 0 ) { y = Mpy_32_16_1( y, 22513 ); /* exp(-8) in -11Q26 */ } @@ -104,9 +104,9 @@ void powfp_odd2( assert( exp >= 0 ); - out = base; + out = base; /* Q15 */ move16(); - out2 = 0x7FFF; + out2 = 0x7FFF; /* 1 in Q15 */ move16(); IF( exp != 0 ) { @@ -114,11 +114,11 @@ void powfp_odd2( maxk = sub( 15, norm_s( exp ) ); assert( maxk < 12 ); - pows[0] = base; + pows[0] = base; /* Q15 */ move16(); FOR( k = 0; k < maxk; k++ ) { - pows[k + 1] = mult_r( pows[k], pows[k] ); + pows[k + 1] = mult_r( pows[k], pows[k] ); /* Q15 */ move16(); } k = sub( k, 1 ); @@ -127,31 +127,31 @@ void powfp_odd2( move16(); 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] ); /* Q15 */ } 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] ); /* Q15 */ } - 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] ); /* Q15 */ } h = shr( h, 1 ); } } - *pout1 = out2; + *pout1 = out2; /* Q15 */ move16(); - *pout2 = out; + *pout2 = out; /* Q15 */ move16(); } @@ -223,13 +223,13 @@ void tcx_arith_scale_envelope( 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 ); /* exp(tmp2) */ #else 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] ); + mean = L_add( mean, ienv[k] ); /* Q16 */ } tmp = norm_s( L_frame ); tmp = shl( div_s( 8192, shl( L_frame, tmp ) ), sub( tmp, 7 ) ); @@ -237,9 +237,9 @@ void tcx_arith_scale_envelope( /* 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 = BASOP_Util_Divide1616_Scale( L_frame, target_bits, &tmp2 ); /* exp(tmp2) */ tmp = mult_r( tmp, 11698 /*0.357f Q15*/ ); - mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); + mean = BASOP_Util_fPow( mean, 15, L_deposit_h( tmp ), tmp2, &mean_e ); /* exp(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 @@ -247,15 +247,15 @@ 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 ); + tmp = round_fx( mean ); /* Q15 - mean_e */ + a = L_mult( mult_r( tmp, 22268 /*2.71828183f Q13*/ ), tmp ); /* 2 * mean_e + 3 */ 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 = BASOP_Util_Divide1616_Scale( target_bits, L_frame, &tmp2 ); /* exp(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 = mult_r( b, round_fx( mean ) ); /* exp(b_e + mean_e) */ b_e = add( b_e, mean_e ); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ @@ -272,7 +272,7 @@ void tcx_arith_scale_envelope( tmp = Sqrt16( tmp, &tmp2 ); } - tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); + tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); /* exp(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 */ @@ -283,7 +283,7 @@ void tcx_arith_scale_envelope( /* iscale = 1.0f / scale; */ iscale_e = 0; move16(); - iscale = Inv16( s_max( 1, scale ), &iscale_e ); + iscale = Inv16( s_max( 1, scale ), &iscale_e ); /* exp(isacle_e) */ lob = 0; move16(); @@ -300,7 +300,7 @@ void tcx_arith_scale_envelope( FOR( iter = 0; iter < max_iter; iter++ ) { - statesi = 0x7FFF; + statesi = 0x7FFF; /* 1 in Q15 */ move16(); bits = 0; move16(); @@ -314,17 +314,17 @@ void tcx_arith_scale_envelope( /* 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*/ ); + statesi = mult_r( statesi, 16751 /*1.0224 Q14*/ ); /* Q14 */ tmp = norm_s( statesi ); - statesi = shl( statesi, tmp ); - bits = add( bits, sub( 1, tmp ) ); + statesi = shl( statesi, tmp ); /* Q15 */ + bits = add( bits, sub( 1, tmp ) ); /* Q0 */ } 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 ); /* Q16 */ + L_tmp = L_add( L_tmp, 9830l /*0.15f Q16*/ ); /* Q16 */ + L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); #ifdef BASOP_NOGLOB @@ -336,7 +336,7 @@ void tcx_arith_scale_envelope( tmp = norm_s( statesi ); statesi = shl( statesi, tmp ); - bits = sub( bits, tmp ); + bits = sub( bits, tmp ); /* Q0 */ } ELSE { @@ -344,20 +344,20 @@ void tcx_arith_scale_envelope( * 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 ) ) ); + bits = add( bits, sub( 17, norm_l( L_tmp ) ) ); /* Q0 */ } } IF( LE_16( bits, target_bits ) ) /* Bits leftover => scale is too small */ { - lob = scale; + lob = scale; /* Q0 */ move16(); - lob_bits = bits; + lob_bits = bits; /* Q0 */ move16(); IF( hib > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE /* Initial scale adaptation */ @@ -365,7 +365,7 @@ void tcx_arith_scale_envelope( /* 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 ); + adjust = BASOP_Util_Divide1616_Scale( adjust, bits, &tmp ); /* exp(tmp) */ scale = shl( mult_r( scale, adjust ), add( 1, tmp ) ); } } @@ -378,7 +378,7 @@ void tcx_arith_scale_envelope( IF( lob > 0 ) /* Bisection search */ { - adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); + adjust = div_s( sub( hib_bits, target_bits ), sub( hib_bits, lob_bits ) ); /* Q15 */ scale = add( mult_r( sub( lob, hib ), adjust ), hib ); } ELSE @@ -392,7 +392,7 @@ 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 ); /* Q15 */ } scale = mult_r( scale, adjust ); } @@ -411,7 +411,7 @@ void tcx_arith_scale_envelope( iscale = Inv16( scale, &iscale_e ); } } - L_frame = L_spec_core; + L_frame = L_spec_core; /* Q0 */ move16(); tmp = getScaleFactor32( env, L_frame ); @@ -427,9 +427,9 @@ void tcx_arith_scale_envelope( 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 ); /* Q31 - e */ + L_tmp = L_min( L_tmp, a ); /* Q31 - e */ + s_env[k] = round_fx( L_tmp ); /* Q15 - e */ move16(); } } @@ -447,13 +447,13 @@ 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 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 Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ) { Word16 k; @@ -474,14 +474,14 @@ void tcx_arith_render_envelope( /* Compute weighted signal envelope in perceptual domain */ 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] ); /* exp(signal_env_e + gainlpc_e) */ move16(); 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 /* 1 in Q16 */, L_frame ); AdaptLowFreqDeemph( env, 15, 1, @@ -493,7 +493,7 @@ void tcx_arith_render_envelope( FOR( k = L_frame; k < L_spec; ++k ) { - env[k] = env[k - 1]; + env[k] = env[k - 1]; /* Q16 */ move32(); } } diff --git a/lib_com/basop_com_lpc.c b/lib_com/basop_com_lpc.c index 669b976e6..5de4fa5d3 100644 --- a/lib_com/basop_com_lpc.c +++ b/lib_com/basop_com_lpc.c @@ -67,32 +67,36 @@ * Returns: * void */ -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +) { Word16 i, fac; Word32 Amax; Word16 shift; - fac = gamma; - Amax = L_mult( 16384, a[0] ); + fac = gamma; /* Q15 */ + Amax = L_mult( 16384, a[0] ); /* Q27 */ FOR( i = 1; i < M; i++ ) { Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) ); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); + Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); /* Q27 */ shift = norm_l( Amax ); fac = gamma; ap[0] = shl( a[0], sub( shift, 1 ) ); move16(); FOR( i = 1; i < M; i++ ) { - ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); + ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q12 */ move16(); - fac = mult_r( fac, gamma ); + fac = mult_r( fac, gamma ); /* Q15 */ } - ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); + ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); /* Q12 */ move16(); @@ -113,7 +117,11 @@ void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ) * Returns: * void */ -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +) { Word16 i; static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924, /* Q14 */ @@ -130,7 +138,7 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) { FOR( i = 0; i <= M; i++ ) { - ap[i] = a[i]; + ap[i] = a[i]; /* Q12 */ move16(); } return; @@ -138,37 +146,37 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV ); - inv_gamma_tab = inv_gamma_tab_12k8; + inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */ move16(); if ( sub( inv_gamma, GAMMA16k_INV ) == 0 ) { - inv_gamma_tab = inv_gamma_tab_16k; + inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */ move16(); } Amax = L_mult( 16384, a[0] ); FOR( i = 1; i < 9; i++ ) { - Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); + Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */ } FOR( i = 9; i < 17; i++ ) { - Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); + Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */ } shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i < 9; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } shift = add( shift, 1 ); FOR( i = 9; i < 17; i++ ) { - L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); - ap[i] = round_fx( L_shl( L_tmp, shift ) ); + L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */ + ap[i] = round_fx( L_shl( L_tmp, shift ) ); /* Q11 + shift */ move16(); } @@ -190,39 +198,45 @@ void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ) * Returns: * void */ -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ) +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q15 */ +) { Word16 i; Word32 Amax, Atmp[M + 2]; Word16 shift; - Amax = L_mult( 16384, a[0] ); + Amax = L_mult( 16384, a[0] ); /* Q27 */ 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] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[i] ) ); + Amax = L_max( Amax, L_abs( Atmp[i] ) ); /* Q27 */ } - Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); + Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); /* Q27 */ move32(); - Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); + Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); /* Q27 */ shift = norm_l( Amax ); - ap[0] = shl( a[0], sub( shift, 1 ) ); + ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */ move16(); FOR( i = 1; i <= M; i++ ) { - ap[i] = round_fx( L_shl( Atmp[i], shift ) ); + ap[i] = round_fx( L_shl( Atmp[i], shift ) ); /* Q11 + shift */ move16(); } - ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); + ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); /* Q12 */ move16(); return; } -static Word16 xsf_to_xsp( Word16 xsf ) +static Word16 xsf_to_xsp( + Word16 xsf /* Q2.56 */ +) { /* xsp = cos(xsf * 3.1415/6400); */ return getCosWord16R2( xsf ); @@ -244,7 +258,10 @@ static Word16 xsf_to_xsp( Word16 xsf ) * Returns: * void */ -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +) { Word16 i; @@ -252,7 +269,7 @@ void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ) /* convert ISFs to the cosine domain */ FOR( i = 0; i < M; i++ ) { - *lsp++ = xsf_to_xsp( *lsf++ ); + *lsp++ = xsf_to_xsp( *lsf++ ); /* Q15 */ move16(); } diff --git a/lib_com/basop_lsf_tools.c b/lib_com/basop_lsf_tools.c index f378bcbaa..aac96ae5f 100644 --- a/lib_com/basop_lsf_tools.c +++ b/lib_com/basop_lsf_tools.c @@ -62,9 +62,10 @@ static Word16 E_LPC_f_lsp_pol_get( const Word16 lsp[], Word32 f[], const Word16 * void */ void basop_E_LPC_f_lsp_a_conversion( - const Word16 *lsp, - Word16 *a, - const Word16 m ) + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +) { Word16 i, j, k; Word32 f1[NC_MAX + 1], f2[NC_MAX + 1]; @@ -83,8 +84,8 @@ void basop_E_LPC_f_lsp_a_conversion( 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 ); + Ovf = E_LPC_f_lsp_pol_get( &lsp[0], f1, nc, Ovf, 1 ); /* Q0 */ + Ovf2 = E_LPC_f_lsp_pol_get( &lsp[1], f2, nc, Ovf, 1 ); /* Q0 */ IF( sub( Ovf2, Ovf ) != 0 ) { /* to ensure similar scaling for f1 and f2 in case @@ -99,9 +100,9 @@ void basop_E_LPC_f_lsp_a_conversion( k = sub( nc, 1 ); FOR( i = 0; i <= k; i++ ) { - f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); + f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); /* Q23 */ move32(); - f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); + f2[nc - i] = L_sub( f2[nc - i], f2[nc - i - 1] ); /* Q23 */ move32(); } @@ -113,8 +114,8 @@ void basop_E_LPC_f_lsp_a_conversion( t0 = L_deposit_l( 0 ); FOR( i = 1; i <= nc; 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] ) ) ); + t0 = L_max( t0, L_abs( L_add( f1[i], f2[i] ) ) ); /* Q23 */ + t0 = L_max( t0, L_abs( L_sub( f1[i], f2[i] ) ) ); /* Q23 */ } k = s_min( norm_l( t0 ), 6 ); a[0] = shl( 256, k ); @@ -129,12 +130,12 @@ void basop_E_LPC_f_lsp_a_conversion( FOR( i = 1; i <= nc; i++ ) { /* a[i] = 0.5*(f1[i] + f2[i]) */ - t0 = L_add( f1[i], f2[i] ); + t0 = L_add( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[i] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ /* a[j] = 0.5*(f1[i] - f2[i]) */ - t0 = L_sub( f1[i], f2[i] ); + t0 = L_sub( f1[i], f2[i] ); /* Q23 */ t0 = L_shl( t0, k ); a[j] = round_fx( t0 ); /* from Q23 to Qx and * 0.5 */ j--; @@ -153,14 +154,14 @@ void basop_E_LPC_f_lsp_a_conversion( void basop_reorder_lsf( 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 */ + const Word16 n, /* i : LPC order Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ ) { Word16 i, lsf_min, n_m_1; Word16 lsf_max; - lsf_min = min_dist; + lsf_min = min_dist; /* Q2.56 */ move16(); /*-----------------------------------------------------------------------* @@ -171,10 +172,10 @@ void basop_reorder_lsf( { if ( sub( lsf[i], lsf_min ) < 0 ) { - lsf[i] = lsf_min; + lsf[i] = lsf_min; /* Q2.56 */ move16(); } - lsf_min = add( lsf[i], min_dist ); + lsf_min = add( lsf[i], min_dist ); /* Q2.56 */ } /*-----------------------------------------------------------------------* @@ -183,17 +184,17 @@ void basop_reorder_lsf( 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 ); + n_m_1 = sub( n, 1 ); /* Q0 */ IF( sub( lsf[n_m_1], lsf_max ) > 0 ) /* 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 ( sub( lsf[i], lsf_max ) > 0 ) { - lsf[i] = lsf_max; + lsf[i] = lsf_max; /* Q2.56 */ move16(); } - lsf_max = sub( lsf[i], min_dist ); + lsf_max = sub( lsf[i], min_dist ); /* Q2.56 */ } } @@ -229,11 +230,12 @@ void basop_reorder_lsf( *-----------------------------------------------------------* */ static Word16 E_LPC_f_lsp_pol_get( - const Word16 lsp[], - Word32 f[], - const Word16 n, - const Word16 past_Ovf, - const Word16 isMODE1 ) + const Word16 lsp[], /* Q15 */ + Word32 f[], /* Q23 */ + const Word16 n, /* Q0 */ + const Word16 past_Ovf, /* Q0 */ + const Word16 isMODE1 /* Q0 */ +) { /* All computation in Q23 */ const Word16 *plsp; @@ -245,8 +247,8 @@ static Word16 E_LPC_f_lsp_pol_get( Word16 m2; #ifdef BASOP_NOGLOB Flag Overflow; -#endif /* BASOP_NOGLOB */ - +#endif /* BASOP_NOGLOB */ + move16(); // move for Ovf = 0 Q_out = 31 - 23; move16(); @@ -271,7 +273,7 @@ static Word16 E_LPC_f_lsp_pol_get( b = *plsp; move16(); m2 = shl( -2, sub( 15, Q_out ) ); - f[1] = L_mult( b, m2 ); + f[1] = L_mult( b, m2 ); /* Q23 */ move32(); FOR( i = 2; i <= n; i++ ) @@ -284,16 +286,16 @@ static Word16 E_LPC_f_lsp_pol_get( /*f[i] = -b*f[i-1] + 2.0f*f[i-2];*/ move32(); - 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 ); /* Q23 */ FOR( j = i - 1; j > 1; j-- ) { /*f[j] += b*f[j-1] + f[j-2];*/ move32(); - 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 ) ) ); /* Q23 */ } move32(); - f[1] = L_add( f[1], b32 ); + f[1] = L_add( f[1], b32 ); /* Q23 */ } @@ -305,7 +307,7 @@ static Word16 E_LPC_f_lsp_pol_get( #endif /* BASOP_NOGLOB */ /* 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 ); + Ovf = E_LPC_f_lsp_pol_get( lsp, f, n, Ovf, isMODE1 ); /* Q0 */ } return Ovf; } diff --git a/lib_com/basop_proto_func.h b/lib_com/basop_proto_func.h index d8b9768a1..0580db98e 100644 --- a/lib_com/basop_proto_func.h +++ b/lib_com/basop_proto_func.h @@ -53,18 +53,59 @@ #define INT_FS_FX 12800 /* internal sampling frequency */ void basop_lsp2a_stab( const Word16 *lsp, Word16 *a ); -void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] ); -void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma ); -void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma ); -void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma ); -void basop_reorder_lsf( Word16 *lsf, const Word16 min_dist, const Word16 n, const Word32 Fs ); -void basop_E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ); +void basop_lsf2lsp( + const Word16 lsf[], /* Q2.56 */ + Word16 lsp[] /* Q15 */ +); + +void basop_weight_a( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 gamma /* Q15 */ +); + +void basop_weight_a_inv( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + const Word16 inv_gamma /* Q14 */ +); +void basop_E_LPC_a_add_tilt( + const Word16 *a, /* Q12 */ + Word16 *ap, /* Q12 */ + Word16 gamma /* Q14 */ +); +void basop_reorder_lsf( + 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 Q0*/ + const Word32 Fs /* i : sampling frequency Q0*/ +); +void basop_E_LPC_f_lsp_a_conversion( + const Word16 *lsp, /* Q15 */ + Word16 *a, /* Qx */ + const Word16 m /* Q0 */ +); /* tcx_utils.c */ -void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Word16 *mdct_gains_exp, Word16 *mdct_inv_gains, Word16 *mdct_inv_gains_exp ); - -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ); -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ); +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ); + +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +); +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ); #endif diff --git a/lib_com/basop_tcx_utils.c b/lib_com/basop_tcx_utils.c index 5730b2212..579711080 100644 --- a/lib_com/basop_tcx_utils.c +++ b/lib_com/basop_tcx_utils.c @@ -60,7 +60,13 @@ // 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 ) +void basop_lpc2mdct( + Word16 *lpcCoeffs, /* Q12 */ + Word16 lpcOrder, /* Q0 */ + Word16 *mdct_gains, /* Q12 */ + Word16 *mdct_gains_exp, + Word16 *mdct_inv_gains, /* Q12 */ + Word16 *mdct_inv_gains_exp ) { Word32 RealData[FDNS_NPTS]; Word32 ImagData[FDNS_NPTS]; @@ -80,9 +86,9 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /* pre-twiddle */ FOR( i = 0; i <= lpcOrder; i++ ) { - RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); + RealData[i] = L_mult( lpcCoeffs[i], ptwiddle->v.re ); /* Q28 */ move32(); - ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); + ImagData[i] = L_negate( L_mult( lpcCoeffs[i], ptwiddle->v.im ) ); /* Q28 */ move32(); ptwiddle += step; } @@ -103,7 +109,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor /*Get amplitude*/ - j = FDNS_NPTS - 1; + j = FDNS_NPTS - 1; /* Q0 */ k = 0; move16(); move16(); @@ -135,7 +141,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -147,7 +153,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -157,7 +163,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - k = add( k, 1 ); + k++; s = sub( norm_l( L_max( L_abs( RealData[j] ), L_abs( ImagData[j] ) ) ), 1 ); @@ -185,7 +191,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_gains != NULL ) { - mdct_gains[k] = g; + mdct_gains[k] = g; /* exp(g_e) */ move16(); } @@ -197,7 +203,7 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor if ( mdct_inv_gains != NULL ) { - mdct_inv_gains[k] = ig; + mdct_inv_gains[k] = ig; /* exp(ig_e) */ move16(); } @@ -207,13 +213,17 @@ void basop_lpc2mdct( Word16 *lpcCoeffs, Word16 lpcOrder, Word16 *mdct_gains, Wor move16(); } - j = sub( j, 1 ); - k = add( k, 1 ); + j--; + k++; } } -void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word16 gains_exp[] ) +void basop_mdct_noiseShaping_interp( + Word32 x[], /* Q16 */ + Word16 lg, /* Q0 */ + Word16 gains[], /* exp(gain_exp) */ + Word16 gains_exp[] ) { Word16 i, j, jp, jn, k, l; Word16 g, pg, ng, e, tmp; @@ -251,16 +261,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.375f ) ), g, FL2WORD16( 0.625f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 12288 /* 0.375 in Q15 */ ), g, 20480 /* 0.625 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.125f ) ), g, FL2WORD16( 0.875f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 4096 /* 0.125 in Q15*/ ), g, 28672 /* 0.875 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ move32(); /* common exponent for g and ng */ - g = gains[j]; + g = gains[j]; /* exp(gains_exp) */ move16(); tmp = sub( gains_exp[j], gains_exp[jn] ); if ( tmp > 0 ) @@ -269,19 +279,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.875f ) ), ng, FL2WORD16( 0.125f ) ); - x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); + tmp = mac_r( L_mult( g, 28672 /* 0.875 in Q15 */ ), ng, 4096 /* 0.125 in Q15*/ ); /* exp(gains_exp) */ + x[i + 2] = L_shl( Mpy_32_16_1( x[i + 2], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.625f ) ), ng, FL2WORD16( 0.375f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 20480 /* 0.625 in Q15 */ ), ng, 12288 /* 0.375 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ 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 ); /* Q0 */ } } ELSE IF( sub( k, 5 ) == 0 ) @@ -310,16 +320,16 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jp] ); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.40f ) ), g, FL2WORD16( 0.60f ) ); - x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); + tmp = mac_r( L_mult( pg, 13107 /* 0.4 in Q15 */ ), g, 19661 /* 0.6 in Q15 */ ); /* exp(gains_exp) */ + x[i] = L_shl( Mpy_32_16_1( x[i], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( pg, FL2WORD16( 0.20f ) ), g, FL2WORD16( 0.80f ) ); - x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); + tmp = mac_r( L_mult( pg, 6554 /* 0.2 in Q15 */ ), g, 26214 /* 0.8 in Q15 */ ); /* exp(gains_exp) */ + x[i + 1] = L_shl( Mpy_32_16_1( x[i + 1], tmp ), e ); /* Q16 */ 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] ); /* Q16 */ move32(); /* common exponent for g and ng */ @@ -332,19 +342,19 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word g = shl( g, tmp ); e = s_max( gains_exp[j], gains_exp[jn] ); - tmp = mac_r( L_mult( g, FL2WORD16( 0.80f ) ), ng, FL2WORD16( 0.20f ) ); - x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); + tmp = mac_r( L_mult( g, 26214 /* 0.8 in Q15 */ ), ng, 6554 /* 0.2 in Q15 */ ); /* exp(gains_exp) */ + x[i + 3] = L_shl( Mpy_32_16_1( x[i + 3], tmp ), e ); /* Q16 */ move32(); - tmp = mac_r( L_mult( g, FL2WORD16( 0.60f ) ), ng, FL2WORD16( 0.40f ) ); - x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); + tmp = mac_r( L_mult( g, 19661 /* 0.6 in Q15 */ ), ng, 13107 /* 0.4 in Q15 */ ); /* exp(gains_exp) */ + x[i + 4] = L_shl( Mpy_32_16_1( x[i + 4], tmp ), e ); /* Q16 */ 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 ); /* Q0 */ } } ELSE /* no interpolation */ @@ -353,7 +363,7 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word { 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 ); /* Q16 */ move32(); x++; } @@ -366,7 +376,12 @@ void basop_mdct_noiseShaping_interp( Word32 x[], Word16 lg, Word16 gains[], Word } -void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const Word16 lpcGains_e[], Word16 lf_deemph_factors[] ) +void basop_PsychAdaptLowFreqDeemph( + Word32 x[], /* Q16 */ + const Word16 lpcGains[], /* exp(lpcGains_e) */ + const Word16 lpcGains_e[], + Word16 lf_deemph_factors[] /* Qx */ +) { Word16 i; Word16 max_val, max_e, fac, min_val, min_e, tmp, tmp_e; @@ -424,14 +439,14 @@ void basop_PsychAdaptLowFreqDeemph( Word32 x[], const Word16 lpcGains[], const W /* gradual lowering of lowest 32 bins; DC is lowered by (max/tmp)^1/4 */ FOR( i = 31; i >= 0; i-- ) { - x[i] = Mpy_32_16_1( x[i], fac ); + x[i] = Mpy_32_16_1( x[i], fac ); /* Q16 */ move32(); 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 ); /* Qx */ move16(); } - fac = mult_r( fac, tmp ); + fac = mult_r( fac, tmp ); /* Q15 */ } } } diff --git a/lib_com/bitalloc.c b/lib_com/bitalloc.c index 7e1c92f9c..0daed8fc5 100644 --- a/lib_com/bitalloc.c +++ b/lib_com/bitalloc.c @@ -228,14 +228,14 @@ void bitalloc( /*! r: Integer (truncated) number of allocated bits */ int16_t BitAllocF( - int16_t *y, /* i : norm of sub-vectors */ - int32_t bit_rate, /* i : bitrate */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband, /* o : sub-band bit-allocation vector (Q3) */ - const int16_t hqswb_clas, /* i : hq swb class */ - const int16_t num_env_bands /* i : Number sub bands to be encoded for HQ_SWB_BWE */ + 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, /* 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 HQ_SWB_BWE Q0*/ ) { Word16 fac; @@ -256,18 +256,18 @@ int16_t BitAllocF( fac = 3; if ( L_sub( bit_rate, 32000 ) < 0 ) { - bs = 2; + bs = 2; /* Q0 */ } else { - bs = 3; + bs = 3; /* Q0 */ } - low_rate = 1; + low_rate = 1; /* Q0 */ - Nmin = N; + Nmin = N; /* Q0 */ if ( sub( Nmin, SFM_N ) > 0 ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ } /* Initial bits distribution */ @@ -278,13 +278,13 @@ int16_t BitAllocF( m_fx = 0; 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] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +303,7 @@ int16_t BitAllocF( 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] ); /*Q15*/ } else { @@ -319,14 +319,14 @@ int16_t BitAllocF( m_fx = 0; 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] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = 0; n = 0; - tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -334,7 +334,7 @@ int16_t BitAllocF( 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 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ if ( Rsubband_w32_fx[i] > 0 ) @@ -344,7 +344,7 @@ int16_t BitAllocF( 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] ); /*Q15*/ } else { @@ -381,7 +381,7 @@ int16_t BitAllocF( { 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] ); /* Q15 */ } else { @@ -409,14 +409,14 @@ int16_t BitAllocF( } else if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) <= 0 ) { - B = sub( B, Nb[i] ); - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + B = sub( B, Nb[i] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } else { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -448,18 +448,18 @@ int16_t BitAllocF( { if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 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] ); /* Q15 */ if ( L_sub( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) > 0 ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } else { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -472,7 +472,7 @@ int16_t BitAllocF( { if ( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = 0; move32(); if ( B >= 0 ) @@ -489,12 +489,12 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); - tmp = add( tmp, Rsubband[i] ); + Rsubband[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ + tmp = add( tmp, Rsubband[i] ); /* Q3 */ } - B = Bits; - B_w16_fx = shl( B, 3 ); + B = Bits; /* Q0 */ + B_w16_fx = shl( B, 3 ); /* Q3 */ if ( sub( tmp, B_w16_fx ) > 0 ) { tmp = sub( tmp, B_w16_fx ); @@ -502,19 +502,19 @@ int16_t BitAllocF( { if ( sub( Rsubband[i], add( shl( Nb[i], 3 ), tmp ) ) >= 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } } else { - tmp = sub( tmp, B_w16_fx ); + tmp = sub( tmp, B_w16_fx ); /* Q3 */ for ( i = 0; i < N; i++ ) { if ( Rsubband[i] > 0 ) { - Rsubband[i] = sub( Rsubband[i], tmp ); + Rsubband[i] = sub( Rsubband[i], tmp ); /* Q3 */ BREAK; } } @@ -524,8 +524,8 @@ int16_t BitAllocF( tmp = 0; for ( i = 0; i < N; i++ ) { - tmp = add( tmp, Rsubband[i] ); - R[i] = shr( Rsubband[i], 3 ); + tmp = add( tmp, Rsubband[i] ); /* Q3 */ + R[i] = shr( Rsubband[i], 3 ); /* Q0 */ } return shr( tmp, 3 ); @@ -552,6 +552,9 @@ static void Bit_group_fx( Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; UWord32 lo; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -576,9 +579,9 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); - index[i] = i; + index[i] = i; /* Q0 */ move16(); } @@ -622,15 +625,15 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move16(); /*Q21 = 1 move16(); */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move16(); } 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] ); /* Q0 */ } FOR( j = 0; j < band_num; j++ ) @@ -653,7 +656,7 @@ static void Bit_group_fx( FOR( k = 0; k <= i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ @@ -665,7 +668,7 @@ static void Bit_group_fx( { R_temp_fx[i] = 0; move32(); - norm_sum = sub( norm_sum, y_index[i] ); + norm_sum = sub( norm_sum, y_index[i] ); /* Q0 */ i--; } ELSE @@ -683,8 +686,8 @@ static void Bit_group_fx( y_index[j] = 0; move16(); } - R_temp_fx[j] = 2097152; - move32(); /*Q21 = 1 */ + R_temp_fx[j] = 2097152; /* 1 in Q21 */ + move32(); } FOR( j = bit_band; j < band_num; j++ ) @@ -696,7 +699,7 @@ static void Bit_group_fx( norm_sum = 0; FOR( k = 0; k < bit_band; k++ ) { - norm_sum = add( norm_sum, y_index[k] ); + norm_sum = add( norm_sum, y_index[k] ); /* Q0 */ } i = bit_band; @@ -719,7 +722,7 @@ static void Bit_group_fx( FOR( k = 0; k < i; k++ ) { L_tmp = L_shl( L_deposit_l( y_index[k] ), 24 ); - Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); + Mpy_32_32_ss( Bits_avg_fx, L_tmp, &L_tmp, &lo ); /*Q(30-exp) */ R_temp_fx[k] = L_shl( L_tmp, sub( exp, 2 ) ); move32(); /*Q21 */ } @@ -732,7 +735,7 @@ static void Bit_group_fx( { FOR( m = k; m < i; m++ ) { - norm_sum = sub( norm_sum, y_index[m] ); + norm_sum = sub( norm_sum, y_index[m] ); /* Q0 */ R_temp_fx[m] = 0; move32(); /*Q21 */ } @@ -758,7 +761,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -772,12 +775,12 @@ static void Bit_group_fx( *-------------------------------------------------------------------*/ /*! r: Integer (truncated) number of allocated bits */ -int16_t BitAllocWB( - int16_t *y, /* i : norm of sub-vectors */ - int16_t B, /* i : number of available bits */ - int16_t N, /* i : number of sub-vectors */ - int16_t *R, /* o : bit-allocation indicator */ - int16_t *Rsubband /* o : sub-band bit-allocation vector (Q3) */ +Word16 BitAllocWB( + 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 /* o : sub-band bit-allocation vector (Q3) Q3*/ ) { Word16 t_fx; @@ -791,18 +794,18 @@ int16_t BitAllocWB( Word32 Rsubband_buf[NB_SFM]; UWord16 lo; - BANDS = N; + BANDS = N; /* Q0 */ move16(); IF( sub( BANDS, SFM_N ) > 0 ) { - BANDS = SFM_N; + BANDS = SFM_N; /* Q0 */ move16(); } /* Init Rsubband to non-zero values for bands to be allocated bits */ FOR( k = 0; k < BANDS; k++ ) { Rsubband_buf[k] = 2097152; - move32(); /*Q21 */ + move32(); /*1 in Q21 */ } /* Calculate the norm sum and average of sub-band */ Rsum_sub_fx[0] = 0; @@ -857,7 +860,7 @@ int16_t BitAllocWB( R_diff_32_fx[1] = L_sub( Ravg_sub_32_fx[1], Ravg_sub_32_fx[2] ); move32(); /*Q16 */ - IF( L_sub( R_diff_32_fx[0], 393216 ) < 0 && L_sub( R_diff_32_fx[1], 245760 ) < 0 ) + IF( L_sub( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) < 0 && L_sub( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) < 0 ) { IF( Rsum_fx == 0 ) { @@ -878,47 +881,47 @@ int16_t BitAllocWB( B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[1] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B2 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B2, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B2, 1 ), Rsum_fx ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + L_tmp1 = L_mult( B, Rsum_sub_fx[2] ); /*Q1 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B3 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B3, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B3, 1 ), Rsum_fx ) ) >= 0 ) { - B3 = add( B3, 1 ); + B3 = add( B3, 1 ); /* Q0 */ } } - IF( L_sub( Ravg_sub_32_fx[2], 786432 ) > 0 ) + IF( L_sub( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) > 0 ) { B_saved = 0; move16(); IF( sub( B1, 288 ) > 0 ) { - B_saved = sub( B1, 288 ); - B1 = 288; + B_saved = sub( B1, 288 ); /* Q0 */ + B1 = 288; /* Q0 */ move16(); } IF( sub( B2, 256 ) > 0 ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); - B2 = 256; + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B2 = 256; /* Q0 */ move16(); } IF( sub( B3, 96 ) > 0 ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); - B3 = 96; + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ + B3 = 96; /* Q0 */ move16(); } @@ -926,24 +929,24 @@ int16_t BitAllocWB( { IF( sub( B1, 288 ) == 0 ) { - tmp = shr( B_saved, 1 ); - B2 = add( B2, tmp ); - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( sub( B2, 256 ) == 0 ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -968,24 +971,24 @@ int16_t BitAllocWB( 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 */ - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); + 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 */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(15-exp) */ B1 = extract_h( L_shl( L_tmp, add( exp, 1 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_mult( B1, Rsum_fx ) ) > 0 && L_sub( L_tmp1, L_mult( add( B1, 1 ), Rsum_fx ) ) >= 0 ) { - B1 = add( B1, 1 ); + B1 = add( B1, 1 ); /* Q0 */ } - Mpy_32_16_ss( 1975684956, shl( B, 5 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); - Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); - B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ + Mpy_32_16_ss( 1975684956 /* 0.92 in Q31 */, shl( B, 5 ), &L_tmp1, &lo ); /*Q(31+5-15=21) */ + Mpy_32_16_ss( L_tmp1, shl( Rsum_sub_fx[1], 7 ), &L_tmp1, &lo ); /*Q(21+7-15=13) */ + Mpy_32_16_ss( L_tmp1, tmp, &L_tmp, &lo ); /*Q(27-exp) */ + B2 = extract_h( L_shl( L_tmp, sub( exp, 11 ) ) ); /*Q0 */ IF( L_sub( L_tmp1, L_shl( L_mult( B2, Rsum_fx ), 12 ) ) > 0 && L_sub( L_add( L_tmp1, 2 ), L_shl( L_mult( add( B2, 1 ), Rsum_fx ), 12 ) ) >= 0 ) { - B2 = add( B2, 1 ); + B2 = add( B2, 1 ); /* Q0 */ } - tmp = sub( B, B1 ); + tmp = sub( B, B1 ); /* Q0 */ B3 = sub( tmp, B2 ); } } @@ -1004,7 +1007,7 @@ int16_t BitAllocWB( Bit_group_fx( y, SFM_G1G2, BANDS, B3, 7, Rsubband_buf, factor_fx ); FOR( i = 0; i < BANDS; i++ ) { - Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); + Rsubband[i] = extract_l( L_shr( Rsubband_buf[i], 18 ) ); /* Q3 */ move16(); } diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index c20235e39..e7d7602d6 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -30,22 +30,22 @@ void bitalloc_fx( Word16 SFM_thr = SFM_G1G2; move16(); - N = sub( N, 1 ); + N = sub( N, 1 ); /* Q0 */ if ( EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - SFM_thr = 22; + SFM_thr = 22; /* Q0 */ move16(); } fac = 3; move16(); - K = sub( K, 2 ); + K = sub( K, 2 ); /* Q0 */ im = 1; move16(); - diff = sum; + diff = sum; /* Q0 */ move16(); - n = shr( sum, 3 ); + n = shr( sum, 3 ); /* Q0 */ FOR( i = 0; i < n; i++ ) { k = 0; @@ -55,14 +55,14 @@ void bitalloc_fx( FOR( m = 1; m < im; m++ ) { #ifdef BASOP_NOGLOB - v = sub_o( temp, y[m], &Overflow ); -#else /* BASOP_NOGLOB */ + v = sub_o( temp, y[m], &Overflow ); /* Q0 */ +#else /* BASOP_NOGLOB */ v = sub( temp, y[m] ); #endif temp = s_max( temp, y[m] ); if ( v < 0 ) { - k = m; + k = m; /* Q0 */ move16(); } } @@ -73,7 +73,7 @@ void bitalloc_fx( move16(); if ( LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -83,9 +83,9 @@ void bitalloc_fx( test(); IF( GE_16( sum, sfmsize[j] ) && LT_16( r[j], K ) ) { - y[k] = sub( y[k], fac ); + y[k] = sub( y[k], fac ); /* Q0 */ move16(); - r[j] = add( r[j], 1 ); + r[j] = add( r[j], 1 ); /* Q0 */ move16(); if ( GE_16( r[j], K ) ) @@ -93,7 +93,7 @@ void bitalloc_fx( y[k] = -32768; move16(); } - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ } ELSE { @@ -103,7 +103,7 @@ void bitalloc_fx( test(); if ( EQ_16( k, im ) && LT_16( im, N ) ) { - im = add( im, 1 ); + im = add( im, 1 ); /* Q0 */ } } @@ -113,9 +113,9 @@ void bitalloc_fx( BREAK; } - diff = sum; + diff = sum; /* Q0 */ move16(); - v = sub( N, 1 ); + v = sub( N, 1 ); /* Q0 */ IF( GT_16( k, v ) ) { @@ -125,7 +125,7 @@ void bitalloc_fx( { if ( LT_16( ii, N ) ) { - im = add( ii, 1 ); + im = add( ii, 1 ); /* Q0 */ } BREAK; } @@ -138,7 +138,7 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); test(); @@ -146,7 +146,7 @@ void bitalloc_fx( { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -167,7 +167,7 @@ void bitalloc_fx( { r[j] = 2; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1] ) ) { BREAK; @@ -180,14 +180,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && r[j] == 0 ) { r[j] = 1; move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -200,14 +200,14 @@ void bitalloc_fx( { FOR( i = 0; i <= N; i++ ) { - j = idx[i]; + j = idx[i]; /* Q0 */ move16(); test(); IF( LT_16( j, SFM_G1 ) && EQ_16( r[j], 1 ) ) { - r[j] = 2; + r[j] = 2; /* Q0 */ move16(); - sum = sub( sum, sfmsize[j] ); + sum = sub( sum, sfmsize[j] ); /* Q0 */ IF( LT_16( sum, sfmsize[SFM_G1 - 1] ) ) { BREAK; @@ -239,6 +239,7 @@ Word16 BitAllocF_fx( { Word16 fac; Word16 i, n, Nmin, Bits, bs, low_rate = 0; + move16(); Word16 m_fx; Word32 t_fx, B_fx; @@ -248,6 +249,7 @@ Word16 BitAllocF_fx( Word16 B_w16_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif set32_fx( Rsubband_w32_fx, 0, NB_SFM ); @@ -268,11 +270,11 @@ Word16 BitAllocF_fx( low_rate = 1; move16(); - Nmin = N; + Nmin = N; /* Q0 */ move16(); if ( GT_16( Nmin, SFM_N ) ) { - Nmin = SFM_N; + Nmin = SFM_N; /* Q0 */ move16(); } @@ -287,14 +289,14 @@ Word16 BitAllocF_fx( move16(); 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] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( num_env_bands, 1 )], shl( band_end_HQ[sub( num_env_bands, 1 )], 1 ) ); + tmp = add( band_end_HQ[num_env_bands - 1], shl( band_end_HQ[num_env_bands - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -303,7 +305,7 @@ Word16 BitAllocF_fx( FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[num_env_bands - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -331,15 +333,15 @@ Word16 BitAllocF_fx( move16(); 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] ); /* Q0 */ } - L_tmp1 = L_msu0( L_tmp1, fac, B ); + L_tmp1 = L_msu0( L_tmp1, fac, B ); /* Q0 */ t_fx = L_deposit_l( 0 ); n = 0; move16(); - tmp = add( band_end_HQ[sub( N, 1 )], shl( band_end_HQ[sub( N, 1 )], 1 ) ); + tmp = add( band_end_HQ[N - 1], shl( band_end_HQ[N - 1], 1 ) ); /* Q0 */ exp1 = norm_s( tmp ); tmp = div_s( 16384, shl( tmp, exp1 ) ); /*15 + 14 - exp1*/ exp2 = norm_s( tmp ); @@ -347,7 +349,7 @@ Word16 BitAllocF_fx( exp1 = add( 29, sub( exp2, exp1 ) ); FOR( i = 0; i < N; i++ ) { - L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[sub( N, 1 )] ), L_tmp1 ); + L_tmp2 = L_sub( L_mult0( y[i], band_end_HQ[N - 1] ), L_tmp1 ); /* Q0 */ Rsubband_w32_fx[i] = L_mult0( extract_l( L_tmp2 ), Nb[i] ); move32(); /*Q0*/ IF( Rsubband_w32_fx[i] > 0 ) @@ -357,7 +359,7 @@ Word16 BitAllocF_fx( 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] ); /*Q15*/ } ELSE { @@ -387,14 +389,14 @@ Word16 BitAllocF_fx( { 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] ); /* Q15 */ move32(); IF( Rsubband_w32_fx[i] > 0 ) { 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] ); /* Q15 */ } ELSE { @@ -404,7 +406,7 @@ Word16 BitAllocF_fx( } } } - Bits = B; + Bits = B; /* Q0 */ move16(); /* Impose bit-constraints to subbands with less than minimum bits*/ @@ -423,14 +425,14 @@ Word16 BitAllocF_fx( } 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] ); /* Q0 */ + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } ELSE { - n = add( n, Nb[i] ); - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + n = add( n, Nb[i] ); /* Q0 */ + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } } } @@ -463,19 +465,19 @@ Word16 BitAllocF_fx( { 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] ); /* Q15 */ move32(); IF( GT_32( Rsubband_w32_fx[i], L_shl( Nb[i], 15 ) ) ) { - n = add( n, Nb[i] ); + n = add( n, Nb[i] ); /* Q0 */ - t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); + t_fx = L_add( t_fx, Rsubband_w32_fx[i] ); /* Q15 */ } ELSE { - B = sub( B, Nb[i] ); + B = sub( B, Nb[i] ); /* Q0 */ - Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); + Rsubband_w32_fx[i] = L_shl( Nb[i], 15 ); /* Q15 */ move32(); } } @@ -488,7 +490,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_w32_fx[i] > 0 ) { - B = add( B, Nb[i] ); + B = add( B, Nb[i] ); /* Q0 */ Rsubband_w32_fx[i] = L_deposit_l( 0 ); move32(); IF( B >= 0 ) @@ -506,9 +508,9 @@ Word16 BitAllocF_fx( move16(); FOR( i = 0; i < N; i++ ) { - Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); + Rsubband_fx[i] = extract_l( L_shr( Rsubband_w32_fx[i], 12 ) ); /* Q3 */ move16(); - tmp = add( tmp, Rsubband_fx[i] ); + tmp = add( tmp, Rsubband_fx[i] ); /* Q3 */ } B = Bits; @@ -520,7 +522,7 @@ Word16 BitAllocF_fx( { 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 ); /* Q3 */ move16(); BREAK; } @@ -533,7 +535,7 @@ Word16 BitAllocF_fx( { IF( Rsubband_fx[i] > 0 ) { - Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); + Rsubband_fx[i] = sub( Rsubband_fx[i], tmp ); /* Q3 */ move16(); BREAK; } @@ -545,8 +547,8 @@ Word16 BitAllocF_fx( move16(); 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] ); /* Q3 */ + R[i] = shr( Rsubband_fx[i], 3 ); /* Q0 */ move16(); } return shr( tmp, 3 ); @@ -571,6 +573,9 @@ static void Bit_group_fx( Word16 factor_fx; Word32 R_temp_fx[16], R_sum_fx = 0, R_sum_org_fx = 0, Bits_avg_fx = 0; Word32 L_tmp; + move32(); + move32(); + move32(); /* initialization for bit allocation in one group*/ tmp = 6554; @@ -595,7 +600,7 @@ static void Bit_group_fx( FOR( i = 0; i < band_num; i++ ) { - y_index[i] = y[add( i, start_band )]; + y_index[i] = y[i + start_band]; /* Q0 */ move16(); index[i] = i; move16(); @@ -687,7 +692,7 @@ static void Bit_group_fx( R_temp_fx[i] = L_deposit_h( 0 ); move32(); norm_sum = sub( norm_sum, y_index[i] ); - i = sub( i, 1 ); + i--; } ELSE { @@ -767,7 +772,7 @@ static void Bit_group_fx( } 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] ); /* Q21 */ } } IF( EQ_32( R_sum_fx, R_sum_org_fx ) ) @@ -785,7 +790,7 @@ static void Bit_group_fx( { j = index[k]; move16(); - Rsubband_fx[add( j, start_band )] = R_temp_fx[k]; + Rsubband_fx[j + start_band] = R_temp_fx[k]; /* Q21 */ move32(); } @@ -898,7 +903,7 @@ Word16 BitAllocWB_fx( /* o : t move32(); /*Q16 */ test(); - IF( LT_32( R_diff_32_fx[0], 393216 ) && LT_32( R_diff_32_fx[1], 245760 ) ) + IF( LT_32( R_diff_32_fx[0], 393216 /* 32 in Q16 */ ) && LT_32( R_diff_32_fx[1], 245760 /* 3.75 in Q16 */ ) ) { IF( Rsum_fx == 0 ) { @@ -939,29 +944,29 @@ Word16 BitAllocWB_fx( /* o : t B3 = add( B3, 1 ); } } - IF( GT_32( Ravg_sub_32_fx[2], 786432 ) ) + IF( GT_32( Ravg_sub_32_fx[2], 786432 /* 12 in Q16 */ ) ) { B_saved = 0; move16(); IF( GT_16( B1, 288 ) ) { - B_saved = sub( B1, 288 ); + B_saved = sub( B1, 288 ); /* Q0 */ B1 = 288; move16(); } IF( GT_16( B2, 256 ) ) { - tmp = sub( B2, 256 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B2, 256 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B2 = 256; move16(); } IF( GT_16( B3, 96 ) ) { - tmp = sub( B3, 96 ); - B_saved = add( B_saved, tmp ); + tmp = sub( B3, 96 ); /* Q0 */ + B_saved = add( B_saved, tmp ); /* Q0 */ B3 = 96; move16(); } @@ -970,24 +975,24 @@ Word16 BitAllocWB_fx( /* o : t { 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 ); /* Q0 */ + B2 = add( B2, tmp ); /* Q0 */ + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = shr( B_saved, 1 ); - B1 = add( B1, tmp ); + tmp = shr( B_saved, 1 ); /* Q0 */ + B1 = add( B1, tmp ); /* Q0 */ IF( EQ_16( B2, 256 ) ) { - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } ELSE { - tmp = sub( B, B1 ); - B2 = sub( tmp, B3 ); + tmp = sub( B, B1 ); /* Q0 */ + B2 = sub( tmp, B3 ); /* Q0 */ } } } @@ -1020,7 +1025,7 @@ Word16 BitAllocWB_fx( /* o : t test(); 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 ); /* 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) */ @@ -1031,15 +1036,15 @@ Word16 BitAllocWB_fx( /* o : t { B2 = add( B2, 1 ); } - tmp = sub( B, B1 ); - B3 = sub( tmp, B2 ); + tmp = sub( B, B1 ); /* Q0 */ + B3 = sub( tmp, B2 ); /* Q0 */ } } } IF( LT_16( Rsum_sub_fx[2], 3 ) ) { - B2 = add( B2, B3 ); + B2 = add( B2, B3 ); /* Q0 */ B3 = 0; move16(); } @@ -1050,7 +1055,7 @@ Word16 BitAllocWB_fx( /* o : t 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 ) ); /* Q3 */ move16(); } diff --git a/lib_com/core_com_config.c b/lib_com/core_com_config.c index 77f904055..6c9c8fa32 100644 --- a/lib_com/core_com_config.c +++ b/lib_com/core_com_config.c @@ -53,8 +53,8 @@ /*! r: flag indicating a valid bitrate */ Word16 is_EVS_bitrate( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word16 *Opt_AMR_WB /* i : AMR-WB IO flag */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + Word16 *Opt_AMR_WB /* i : AMR-WB IO flag Q0*/ ) { Word16 j; @@ -109,7 +109,7 @@ Word16 is_EVS_bitrate( /*! r: codec mode */ Word16 get_codec_mode( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 codec_mode; @@ -168,7 +168,7 @@ Word16 get_codec_mode( BREAK; } - return codec_mode; + return codec_mode; /*Q0*/ } @@ -178,11 +178,12 @@ Word16 get_codec_mode( * *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED int16_t getTcxonly_ivas( - const int16_t element_mode, /* i : IVAS element mode */ - const int32_t total_brate, /* i : total bitrate */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ - const int16_t is_ism_format /* i : flag indicating ISM format */ + const int16_t element_mode, /* i : IVAS element mode */ + const int32_t total_brate, /* i : total bitrate */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t is_ism_format /* i : flag indicating ISM format */ ) { int16_t tcxonly = 0; @@ -230,13 +231,12 @@ int16_t getTcxonly_ivas( return tcxonly; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 getTcxonly_ivas_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 */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly = 0; @@ -298,7 +298,7 @@ Word16 getTcxonly_ivas_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } #endif @@ -364,14 +364,14 @@ Word16 getTcxonly( #ifdef IVAS_CODE_SWITCHING } #endif - return tcxonly; + return tcxonly; /*Q0*/ } 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 */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) Q0*/ + const Word16 is_ism_format /* i : flag indicating ISM format Q0*/ ) { Word16 tcxonly; @@ -435,7 +435,7 @@ Word16 getTcxonly_fx( BREAK; } - return tcxonly; + return tcxonly; /*Q0*/ } /*-------------------------------------------------------------------* @@ -445,9 +445,9 @@ Word16 getTcxonly_fx( *-------------------------------------------------------------------*/ 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 Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 rf_flag /* i : flag to signal the RF mode Q0*/ ) { Word16 ctx_hm; @@ -469,7 +469,7 @@ Word16 getCtxHm( move16(); } - return ctx_hm; + return ctx_hm; /*Q0*/ } /*-------------------------------------------------------------------* @@ -479,7 +479,7 @@ Word16 getCtxHm( *-------------------------------------------------------------------*/ Word16 getResq( - const Word32 total_brate /* i : total bitrate */ + const Word32 total_brate /* i : total bitrate Q0*/ ) { Word16 resq; @@ -492,7 +492,7 @@ Word16 getResq( move16(); } - return resq; + return resq; /*Q0*/ } /*-------------------------------------------------------------------* @@ -502,9 +502,9 @@ Word16 getResq( *-------------------------------------------------------------------*/ 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 Q0*/ + const Word16 igf, /* i : flag indicating IGF activity Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tnsAllowed; @@ -530,7 +530,7 @@ Word16 getTnsAllowed( } } - return tnsAllowed; + return tnsAllowed; /*Q0*/ } /*-------------------------------------------------------------------* @@ -540,9 +540,9 @@ Word16 getTnsAllowed( *-------------------------------------------------------------------*/ 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 */ + const Word16 element_mode, /* i : IVAS element mode Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 Opt_AMR_WB /* i : flag indicating AMR-WB IO mode Q0*/ ) { Word16 restrictedMode; @@ -569,7 +569,7 @@ Word16 getRestrictedMode( move16(); } - return restrictedMode; + return restrictedMode; /*Q0*/ } /*-------------------------------------------------------------------* @@ -577,7 +577,7 @@ Word16 getRestrictedMode( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED int16_t getMdctWindowLength( const int16_t fscale ) { @@ -587,14 +587,14 @@ int16_t getMdctWindowLength( return mdctWindowLength; } -#ifdef IVAS_FLOAT_FIXED +#else Word16 getMdctWindowLength_fx( - const Word16 fscale ) + const Word16 fscale /*Q0*/ ) { Word16 mdctWindowLength; mdctWindowLength = extract_l( L_shr( L_mult0( L_LOOK_12k8, fscale ), LD_FSCALE_DENOM ) ); - return mdctWindowLength; + return mdctWindowLength; /*Q0*/ } #endif // IVAS_FLOAT_FIXED @@ -605,10 +605,10 @@ Word16 getMdctWindowLength_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED Word16 sr2fscale_fx( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { - return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); + return extract_l( Mpy_32_16_1( sr_core, FSCALE_DENOM_BY_12800_Q15 ) ); /*Q0*/ } #endif @@ -678,12 +678,12 @@ int32_t getCoreSamplerateMode2_flt( } 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 Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const IVAS_FORMAT is_ism_format /* i : flag indicating ISM format Q0*/ ) { @@ -767,11 +767,11 @@ Word32 getCoreSamplerateMode2( assert( 0 ); } - return sr_core; + return sr_core; /*Q0*/ } Word16 getTcxBandwidth( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { @@ -785,7 +785,7 @@ Word16 getTcxBandwidth( move16(); } - return tcxBandwidth; + return tcxBandwidth; /*Q15*/ } /*-------------------------------------------------------------------* @@ -908,10 +908,10 @@ int16_t getIgfPresent( } #else 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 Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth, /* i : audio bandwidth Q0*/ + const Word16 rf_mode /* i : flag to signal the RF mode Q0*/ ) { Word16 igfPresent; @@ -1008,7 +1008,7 @@ Word16 getIgfPresent_fx( move16(); } - return igfPresent; + return igfPresent; /*Q0*/ } #endif @@ -1053,10 +1053,10 @@ int16_t getCnaPresent( } 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 Q0*/ + const Word32 element_brate, /* i : element bitrate Q0*/ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 flag_cna; @@ -1079,7 +1079,7 @@ Word16 getCnaPresent_fx( } } - return flag_cna; + return flag_cna; /*Q0*/ } /*-------------------------------------------------------------------* * getTcxLtp() @@ -1088,7 +1088,7 @@ Word16 getCnaPresent_fx( *-------------------------------------------------------------------*/ Word16 getTcxLtp( - const Word32 sr_core /* i : internal sampling rate */ + const Word32 sr_core /* i : internal sampling rate Q0*/ ) { Word16 tcxltp; @@ -1102,7 +1102,7 @@ Word16 getTcxLtp( move16(); } - return tcxltp; + return tcxltp; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1112,12 +1112,12 @@ Word16 getTcxLtp( *-------------------------------------------------------------------*/ 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, /*Q0*/ + Word16 *pit_min, /*Q0*/ + Word16 *pit_fr1, /*Q0*/ + Word16 *pit_fr1b, /*Q0*/ + Word16 *pit_fr2, /*Q0*/ + Word16 *pit_max /*Q0*/ ) { Word16 pit_res_max; @@ -1182,7 +1182,7 @@ Word16 initPitchLagParameters( move16(); } - return pit_res_max; + return pit_res_max; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1192,7 +1192,7 @@ Word16 initPitchLagParameters( *-------------------------------------------------------------------*/ Word16 getNumTcxCodedLines( - const Word16 bwidth /* i : audio bandwidth */ + const Word16 bwidth /* i : audio bandwidth Q0*/ ) { Word16 tcx_coded_lines; @@ -1224,7 +1224,7 @@ Word16 getNumTcxCodedLines( BREAK; } - return tcx_coded_lines; + return tcx_coded_lines; /*Q0*/ } /*-------------------------------------------------------------------* @@ -1234,9 +1234,9 @@ Word16 getNumTcxCodedLines( *-------------------------------------------------------------------*/ 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 Q0*/ + const Word16 rf_mode, /* i : flag to signal the RF mode Q0*/ + const Word16 element_mode /* i : IVAS element mode Q0*/ ) { Word16 tcx_lpc_shaped_ari; @@ -1253,7 +1253,7 @@ Word16 getTcxLpcShapedAri( move16(); } - return tcx_lpc_shaped_ari; + return tcx_lpc_shaped_ari; /*Q0*/ } @@ -1399,7 +1399,7 @@ void init_tcx_cfg( 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 ); + mdctWindowLength = getMdctWindowLength_fx( 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 ); @@ -1503,21 +1503,21 @@ void init_tcx_cfg( #ifdef IVAS_FLOAT_FIXED void init_tcx_cfg_ivas_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 Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1527,14 +1527,14 @@ void init_tcx_cfg_ivas_fx( 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 Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core ); init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode ); @@ -1556,16 +1556,16 @@ void init_tcx_cfg_ivas_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1585,11 +1585,11 @@ void init_tcx_cfg_ivas_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1630,7 +1630,7 @@ void init_tcx_cfg_ivas_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } @@ -1652,14 +1652,14 @@ void init_tcx_cfg_ivas_fx( #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 */ + TCX_CONFIG_HANDLE hTcxCfg, /* i/o: TCX Config handle Q0*/ + const Word32 sr_core, /* i : SR core Q0*/ + const Word32 input_Fs, /* i : input/output SR Q0*/ + const Word16 L_frame, /* i : L_frame at sr_core Q0*/ + const Word16 L_frameTCX, /* i : L_frame at i/o SR Q0*/ + const Word16 mdctWindowLength, /* i : window length at sr_core Q0*/ + const Word16 mdctWindowLengthFB, /* i : window length at i/o SR Q0*/ + const Word16 element_mode /* i : mode of CPE/SCE Q0*/ ) { /* Symmetric window = sine LD window*/ @@ -1675,7 +1675,7 @@ void init_tcx_window_cfg_fx( IF( EQ_16( hTcxCfg->tcx_mdct_window_length, hTcxCfg->tcx_mdct_window_lengthFB ) ) { - Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window, hTcxCfg->tcx_mdct_windowFB, shr( hTcxCfg->tcx_mdct_window_length, 1 ) ); /*Q15*/ } ELSE { @@ -1687,14 +1687,14 @@ void init_tcx_window_cfg_fx( 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 ) ); /*1.25ms transition window for ACELP->TCX*/ - hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); + hTcxCfg->tcx_mdct_window_trans_length = NS2SA_FX2( sr_core, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); 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 ); + hTcxCfg->tcx_mdct_window_trans_lengthFB = NS2SA_FX2( input_Fs, ACELP_TCX_TRANS_NS ); /*Q0*/ move16(); 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, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_transFB, shr( hTcxCfg->tcx_mdct_window_trans_length, 1 ) ); /*Q15*/ } ELSE { @@ -1702,8 +1702,8 @@ void init_tcx_window_cfg_fx( } /*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 ) ); + 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 ) ); /*Q0*/ + 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 ) ); /*Q0*/ move16(); move16(); assert( GT_16( hTcxCfg->tcx_mdct_window_half_length, 16 ) && "Half window can not be large enough!" ); @@ -1711,7 +1711,7 @@ void init_tcx_window_cfg_fx( 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, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_halfFB, shr( hTcxCfg->tcx_mdct_window_half_length, 1 ) ); /*Q15*/ } ELSE { @@ -1726,7 +1726,7 @@ void init_tcx_window_cfg_fx( /* 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, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_minimum, shr( hTcxCfg->tcx_mdct_window_min_length, 1 ) ); /*Q15*/ } ELSE { @@ -1735,19 +1735,19 @@ void init_tcx_window_cfg_fx( 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, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } 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, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); + Copy_pword( hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_minimumFB, shr( hTcxCfg->tcx_mdct_window_min_lengthFB, 1 ) ); /*Q15*/ } 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 ); + hTcxCfg->tcx_offset = shr( hTcxCfg->tcx_mdct_window_delay, 1 ); /*Q0*/ + hTcxCfg->tcx_offsetFB = shr( hTcxCfg->tcx_mdct_window_delayFB, 1 ); /*Q0*/ /*<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 ) ); @@ -1761,22 +1761,22 @@ void init_tcx_window_cfg_fx( 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, /*Q15*/ - 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 ) + const Word32 total_brate, /*Q0*/ + const Word32 sr_core, /*Q0*/ + const Word32 input_Fs, /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 bwidth, /*Q0*/ + const Word16 L_frameTCX, /*Q0*/ + const Word16 fscale, /*Q0*/ + const Word16 preemph_fac, /*Q15*/ + const Word16 tcxonly, /*Q0*/ + const Word16 rf_mode, /*Q0*/ + const Word16 igf, /*Q0*/ + const Word16 infoIGFStopFreq, /*Q0*/ + const Word16 element_mode, /*Q0*/ + const Word16 ini_frame, /*Q0*/ + const Word16 MCT_flag, /*Q0*/ + const Word16 fscaleFB /*Q0*/ ) { Word16 i; Word16 mdctWindowLength; @@ -1786,15 +1786,15 @@ void init_tcx_cfg_fx( 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 Q0*/ + hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms Q0*/ move16(); move16(); - hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; + hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length; /*Q0*/ move16(); - mdctWindowLength = getMdctWindowLength_fx( fscale ); - mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); + mdctWindowLength = getMdctWindowLength_fx( fscale ); /*Q0*/ + mdctWindowLengthFB = getMdctWindowLength_fx( fscaleFB ); /*Q0*/ 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)*/ @@ -1814,16 +1814,16 @@ void init_tcx_cfg_fx( hTcxCfg->tcxRateLoopOpt = 3; move16(); } - hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); + hTcxCfg->bandwidth = getTcxBandwidth( bwidth ); /*Q15*/ move16(); /* set number of coded lines */ - hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); + hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); /*Q0*/ move16(); /* TNS in TCX */ hTcxCfg->pCurrentTnsConfig = NULL; - hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); + hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode ); /*Q0*/ move16(); IF( hTcxCfg->fIsTNSAllowed ) @@ -1843,11 +1843,11 @@ void init_tcx_cfg_fx( } /* Context HM*/ - hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); + hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode ); /*Q0*/ move16(); /* Residual Coding*/ - hTcxCfg->resq = getResq( total_brate ); + hTcxCfg->resq = getResq( total_brate ); /*Q0*/ move16(); test(); if ( hTcxCfg->resq && !tcxonly ) @@ -1888,7 +1888,7 @@ void init_tcx_cfg_fx( { i = sub( i, 1 ); } - hTcxCfg->na_scale = scaleTcxTable[i].scale; + hTcxCfg->na_scale = scaleTcxTable[i].scale; /*Q15*/ move16(); BREAK; } diff --git a/lib_com/deemph.c b/lib_com/deemph.c index 9583a79d4..4e1093120 100644 --- a/lib_com/deemph.c +++ b/lib_com/deemph.c @@ -75,22 +75,22 @@ void deemph_fx_32( Word32 *signal, /* i/o: signal Qx*/ const Word16 mu, /* i : deemphasis factor Q15*/ const int16_t L, /* i : vector size */ - Word32 *mem /* i/o: memory (y[-1]) Qx*/ + Word32 *mem /* i/o: memory (y[-1]) Qx+shift*/ ) { Word16 i; - signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); + signal[0] = L_add( signal[0], Mpy_32_16_1( ( *mem ), mu ) ); /*Qx*/ move32(); 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 ) ); /*Qx*/ + signal[i] = L_shl( signal[i], shift ); /*Qx+shift*/ move32(); move32(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx+shift*/ move32(); return; @@ -132,10 +132,10 @@ void deemph_fx( move32(); #endif - L_tmp = L_deposit_h( signal[0] ); + L_tmp = L_deposit_h( signal[0] ); /*Qx+16*/ #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 ); /*Qx+16*/ + signal[0] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ #else L_tmp = L_mac( L_tmp, *mem, mu ); signal[0] = round_fx( L_tmp ); @@ -144,18 +144,18 @@ void deemph_fx( FOR( i = 1; i < L; i++ ) { - L_tmp = L_deposit_h( signal[i] ); + L_tmp = L_deposit_h( signal[i] ); /*Qx+16*/ #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_o( L_tmp, signal[i - 1], mu, &Overflow ); /*Qx+16*/ + signal[i] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ +#else /* BASOP_NOGLOB */ L_tmp = L_mac( L_tmp, signal[i - 1], mu ); signal[i] = round_fx( L_tmp ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ move16(); } - *mem = signal[L - 1]; + *mem = signal[L - 1]; /*Qx*/ move16(); } @@ -181,22 +181,22 @@ void Deemph2( #endif /* saturation can occur in L_mac() */ - L_tmp = L_mult( x[0], 16384 ); - x[0] = mac_r( L_tmp, *mem, mu ); + L_tmp = L_mult( x[0], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ + x[0] = mac_r( L_tmp, *mem, mu ); /*Qx-1*/ move16(); FOR( i = 1; i < L; i++ ) { - L_tmp = L_mult( x[i], 16384 ); + L_tmp = L_mult( x[i], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ #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 ); /*Qx-1*/ #else x[i] = mac_r( L_tmp, x[i - 1], mu ); #endif move16(); } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-1*/ move16(); } @@ -229,15 +229,15 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W #endif /* signal[0] = signal[0] + mu * (*mem); */ - L_tmp = L_deposit_h( *mem ); + L_tmp = L_deposit_h( *mem ); /*Qx+16*/ IF( shift >= 0 ) { - shift = shr( -32768, shift ); + shift = shr( -32768, shift ); /*Q15 - 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 ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ #else L_tmp = L_msu( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); x[i] = round_fx( L_tmp ); @@ -250,9 +250,9 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W 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 ); -#else /* BASOP_NOGLOB */ + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768 /*1.0f in Q15*/, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#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 ); #endif @@ -260,7 +260,7 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W } } - *mem = x[L - 1]; + *mem = x[L - 1]; /*Qx-shift*/ move16(); return; diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index c1e1e869c..8e522ccd6 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -113,8 +113,8 @@ int32_t get_delay( } #else 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 Word16 what_delay, /* i : what delay? (ENC or DEC) Q0*/ + const Word32 io_fs, /* i : input/output sampling frequency Q0*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ HANDLE_CLDFB_FILTER_BANK hCldfb /* i : Handle of Cldfb analysis */ #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -123,7 +123,7 @@ Word32 get_delay_fx( /* o : delay value in ms #endif ) { - Word32 delay; + Word32 delay; /*Q0*/ delay = 0; move32(); @@ -131,12 +131,12 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_16( ivas_format, MONO_FORMAT ) ) /* EVS mono */ { - delay = ( DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS ); + delay = DELAY_FIR_RESAMPL_NS + ACELP_LOOK_NS; /*Q0*/ move32(); } ELSE { - delay = IVAS_ENC_DELAY_NS; + delay = IVAS_ENC_DELAY_NS; /*Q0*/ move32(); test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) @@ -149,7 +149,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( EQ_16( ivas_format, SBA_FORMAT ) || EQ_16( ivas_format, SBA_ISM_FORMAT ) ) { /* compensate for DirAC/SPAR filterbank delay */ - delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); /*Q0*/ } } ELSE @@ -158,18 +158,18 @@ Word32 get_delay_fx( /* o : delay value in ms { IF( EQ_32( io_fs, 8000 ) ) { - delay = DELAY_CLDFB_NS; + delay = DELAY_CLDFB_NS; /*Q0*/ move32(); } ELSE { - delay = DELAY_BWE_TOTAL_NS; + delay = DELAY_BWE_TOTAL_NS; /*Q0*/ move32(); } } ELSE /* IVAS */ { - delay = IVAS_DEC_DELAY_NS; + delay = IVAS_DEC_DELAY_NS; /*Q0*/ move32(); #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -180,7 +180,7 @@ Word32 get_delay_fx( /* o : delay value in ms if ( hCldfb != NULL ) { /* compensate for filterbank delay */ - delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); + delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); /*Q0*/ } #ifdef SPLIT_REND_WITH_HEAD_ROT } @@ -188,11 +188,11 @@ Word32 get_delay_fx( /* o : delay value in ms test(); if ( EQ_16( ivas_format, MASA_FORMAT ) || EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ + delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ /*Q0*/ } } } - return delay; + return delay; /*Q0*/ } #endif diff --git a/lib_com/dlpc_bfi_fx.c b/lib_com/dlpc_bfi_fx.c index be4b27696..2d6b11268 100644 --- a/lib_com/dlpc_bfi_fx.c +++ b/lib_com/dlpc_bfi_fx.c @@ -10,20 +10,20 @@ 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_cng[], + Word16 *lsf_q, /* o : quantized LSFs 14Q1*1.28*/ + const Word16 *lsfold, /* i : past quantized LSF 14Q1*1.28*/ + const Word16 last_good, /* i : last good received frame Q0*/ + const Word16 nbLostCmpt, /* i : counter of consecutive bad frames Q0*/ + Word16 mem_MA[], /* i/o: quantizer memory for MA model 14Q1*1.28*/ + Word16 mem_AR[], /* i/o: quantizer memory for AR model 14Q1*1.28*/ + Word16 *stab_fac, /* i : LSF stability factor Q15*/ + Word16 *lsf_adaptive_mean, /* i : LSF adaptive mean, updated when BFI==0 14Q1*1.28*/ + Word16 numlpc, /* i : Number of division per superframe Q0*/ + Word16 lsf_cng[], /*Q1*1.28*/ 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 */ + Word16 *lsf_q_cng, /* o : quantized LSFs 14Q1*1.28*/ + Word16 *old_lsf_q_cng, /* o : old quantized LSFs for background noise 14Q1*1.28*/ + const Word16 *lsfBase, /* i : base for differential LSF coding Q1*1.28*/ Word8 tcxonly ) { diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 8211bb406..8d8bb2ef3 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -100,7 +100,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -118,7 +118,7 @@ void enhancer_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || 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 ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -138,7 +138,7 @@ 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 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -147,13 +147,13 @@ void enhancer_fx( 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 /*0.19.Q15*/ ); /*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 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -199,9 +199,9 @@ void enhancer_fx( 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 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -215,13 +215,13 @@ void enhancer_fx( { /* 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 /*0.15.Q15*/ ); /*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 /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -241,7 +241,6 @@ void enhancer_fx( pt_exc2[0] = msu_r( L_tmp, -32768, pt_exc2[0] ); move16(); #endif - move16(); /* in Q_exc */ FOR( i = 1; i < L_SUBFR - 1; i++ ) { @@ -257,8 +256,8 @@ void enhancer_fx( tmp16 = msu_r( L_tmp, code[i - 1], tmp ); L_tmp = L_shl( L_mult( gain_code_hi, tmp16 ), sc ); pt_exc2[i] = msu_r( L_tmp, -32768, pt_exc2[i] ); -#endif move16(); /* in Q_exc */ +#endif } /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */ @@ -272,12 +271,11 @@ void enhancer_fx( pt_exc2[L_SUBFR - 1] = msu_r( L_tmp, -32768, pt_exc2[L_SUBFR - 1] ); move16(); #endif - 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 ) ) + IF( GT_16( pit_sharp, 16384 /*0.5.Q115*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -334,7 +332,7 @@ void enhancer_fx( 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 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 */ @@ -379,7 +377,7 @@ void enhancer_ivas_fx( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -443,7 +441,7 @@ void enhancer_ivas_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 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q14*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -452,13 +450,13 @@ void enhancer_ivas_fx( 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 /*0.19.Q15*/ ); /*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 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -504,9 +502,9 @@ void enhancer_ivas_fx( 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 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -520,13 +518,13 @@ void enhancer_ivas_fx( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*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 /*0.125.Q31*/, voice_fac, 4096 ); /*Q15 */ } /*----------------------------------------------------------------- @@ -566,7 +564,7 @@ void enhancer_ivas_fx( test(); 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 /*0.5.Q14*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -624,7 +622,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( LE_32( core_brate, ACELP_8k85 ) ) + ELSE IF( LE_32( core_brate, ACELP_8k85 ) ) { i = 1; move16(); /* low dispersion */ @@ -642,7 +640,7 @@ void enhancer_ivas_fx2( i = 0; move16(); /* high dispersion */ } - ELSE if ( ( EQ_16( coder_type, GENERIC ) || EQ_16( coder_type, TRANSITION ) || EQ_16( coder_type, AUDIO ) || 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 ) || coder_type == INACTIVE ) && LE_32( core_brate, ACELP_9k60 ) ) { i = 1; move16(); /* low dispersion */ @@ -662,7 +660,7 @@ void enhancer_ivas_fx2( /* 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 /*0.5.Q31*/, voice_fac, 16384 /*0.5.Q15*/ ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #else tmp = msu_r( 0x40000000, voice_fac, 16384 ); /*Q15 */ /* 1=unvoiced, 0=voiced */ #endif @@ -671,13 +669,13 @@ void enhancer_ivas_fx2( 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 /*0.19.Q15*/ ); /*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 /*0.84.Q15*/ ); /*Q16 */ + L_tmp = L_max( L_tmp, *gc_threshold ); /*Q16 */ } *gc_threshold = L_tmp; move32(); /*Q16 */ @@ -723,9 +721,9 @@ void enhancer_ivas_fx2( 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 /*0.5.Q15*/ ) ) { - tmp16 = mult( pit_sharp, 8192 ); + tmp16 = mult( pit_sharp, 8192 /*0.25.Q15*/ ); FOR( i = 0; i < L_SUBFR; i++ ) { /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */ @@ -739,13 +737,13 @@ void enhancer_ivas_fx2( { /* tmp = 0.150 * (1.0 + voice_fac) */ /* 0.30=voiced, 0=unvoiced */ - tmp = mac_r( 0x13333333L, voice_fac, 4915 ); /*Q15 */ + tmp = mac_r( 0x13333333L /*0.150.Q31*/, voice_fac, 4915 /*0.150.Q15*/ ); /*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 /*0.125.Q31*/, voice_fac, 4096 /*0.125.Q15*/ ); /*Q15 */ } /*----------------------------------------------------------------- @@ -801,7 +799,7 @@ void enhancer_ivas_fx2( test(); 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 /*0.5.Q15*/ ) ) { FOR( i = 0; i < L_SUBFR; i++ ) { @@ -979,7 +977,7 @@ Word16 E_UTIL_enhancer( #endif move16(); - FOR( i = 1; i < sub( L_subfr, 1 ); i++ ) + FOR( i = 1; i < L_subfr - 1; i++ ) { /* exc2[i] = exc2[i] + code[i] - tmp*(code[i+1]+code[i-1]); */ L_tmp = L_mult( code[i], 16384 ); diff --git a/lib_com/est_tilt_fx.c b/lib_com/est_tilt_fx.c index 6f541c11f..d47a47191 100644 --- a/lib_com/est_tilt_fx.c +++ b/lib_com/est_tilt_fx.c @@ -93,7 +93,7 @@ Word16 est_tilt_fx( /* 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 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ return tilt_code; } @@ -173,7 +173,7 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -185,19 +185,19 @@ Word16 est_tilt_ivas_fx( /* 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 ); /*Q15 */ + tilt_code = mac_r( 8192L /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); /*Q15 */ } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( 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 = mac_r( 12288L /*0.375.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4096 /*0.125.Q15*/ ); /*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 = mac_r( 13763L /*0.42.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 4588 /*0.14.Q15*/ ); /*Q15 */ } return tilt_code; @@ -249,7 +249,7 @@ Word16 Est_tilt2( /* o : tilt of the code /* find voice factor (1=voiced, -1=unvoiced) */ exp = div_s( abs_s( tmp ), ener1 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { exp = negate( exp ); } @@ -259,7 +259,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 /*0.25.Q15*/ * 65536 /*1.Q16*/ - 0x8000 /*1.Q15*/, *voice_fac, 8192 /*0.25.Q15*/ ); return tilt_code; } @@ -289,7 +289,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f IF( shift != 0 ) { - fac = shl( 0x4000, add( 1, shift ) ); + fac = shl( 0x4000 /*1.Q14*/, 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 ); @@ -377,7 +377,7 @@ void E_UTIL_voice_factor( Word16 *exc, /* i : pointer to the excitation f move16(); *tilt_code = add( 8192 /*0.25f Q15*/, mult_r( 8192 /*0.25f Q15*/, *voice_fac ) ); } - ELSE IF( flag_tilt == 1 ) + ELSE IF( EQ_16( flag_tilt, 1 ) ) { /*Between 0.25 (=unvoiced) and 0.5 (=voiced)*/ move16(); diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index a03edf290..350391c26 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -967,9 +967,10 @@ void SynthesisSTFT_flt( *-------------------------------------------------------------------*/ void SynthesisSTFT_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // Q15 Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Qin const Word16 *olapWin, const Word16 tcx_transition, HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ @@ -988,7 +989,7 @@ void SynthesisSTFT_fx( test(); IF( ( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) && EQ_16( nchan_out, 2 ) ) { - Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); + Copy32( olapBuffer + sub( i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ), ( M + 1 ) ), buf_fx, add( hFdCngCom->frameSize, M + 1 ) ); // Qin set32_fx( olapBuffer, 0, hFdCngCom->fftlen ); } ELSE @@ -999,28 +1000,28 @@ void SynthesisSTFT_fx( IF( tcx_transition ) { - FOR( i = 0; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = 0; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = fftBuffer[i]; + olapBuffer[i] = fftBuffer[i]; // Q15 move32(); } } ELSE { - FOR( i = hFdCngCom->frameSize / 4; i < i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( i = hFdCngCom->frameSize / 4; i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } @@ -1054,7 +1055,7 @@ void SynthesisSTFT_fx( { FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[add( i, shr( hFdCngCom->frameSize, 2 ) )] ); + buf_fx[i + ( M + 1 )] = L_add( buf_fx[i + ( M + 1 )], olapBuffer[( i + ( hFdCngCom->frameSize >> 2 ) )] ); move32(); } // v_multc(buf, (float)(hFdCngCom->fftlen / 2), buf, M + 1 + hFdCngCom->frameSize); @@ -1072,13 +1073,8 @@ void SynthesisSTFT_fx( preemph_ivas_fx( buf_fx + 1, PREEMPH_FAC, add( 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 ); 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++ ) - //{ - // hFdCngCom->exc_cng_flt[i] = fix_to_float( hFdCngCom->exc_cng_32fx[i], Q_in - 9 ); - // } return; } @@ -1152,9 +1148,10 @@ void SynthesisSTFT_dirac_flt( #endif #ifdef IVAS_FLOAT_FIXED void SynthesisSTFT_dirac_fx( - Word32 *fftBuffer, /* i : FFT bins */ + Word32 *fftBuffer, + /* i : FFT bins */ // hFdCngCom->fftBuffer_exp Word32 *timeDomainOutput, - Word32 *olapBuffer, + Word32 *olapBuffer, // Q_in const Word16 *olapWin, const Word16 samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ @@ -1170,18 +1167,18 @@ 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 = ( hFdCngCom->frameSize >> 2 ); i < ( 3 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[sub( i, shr( hFdCngCom->frameSize, 2 ) )] ) ); + olapBuffer[i] = L_add( olapBuffer[i], Mpy_32_16_1( fftBuffer[i], olapWin[( i - ( hFdCngCom->frameSize >> 2 ) )] ) ); move32(); } - FOR( ; i < i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); } - FOR( ; i < i_mult( 7, shr( hFdCngCom->frameSize, 2 ) ); i++ ) + FOR( ; i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { olapBuffer[i] = fftBuffer[i]; move32(); @@ -1225,9 +1222,9 @@ void SynthesisSTFT_dirac_fx( { 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 = ( 5 * ( hFdCngCom->frameSize >> 2 ) ); i < ( 7 * ( hFdCngCom->frameSize >> 2 ) ); i++ ) { - olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[sub( i, i_mult( 3, shr( hFdCngCom->frameSize, 2 ) ) )] ); + olapBuffer[i] = Mpy_32_16_1( olapBuffer[i], olapWin[( i - ( 3 * ( hFdCngCom->frameSize >> 2 ) ) )] ); move32(); } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index e11d67d69..69228a482 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -364,7 +364,7 @@ void initPartitions( * Apply some dynamic range compression based on the log *-------------------------------------------------------------------*/ void compress_range( - Word32 *in, + Word32 *in, // Q(31 - in_exp) Word16 in_exp, Word16 *out, const Word16 len ) @@ -379,11 +379,11 @@ void compress_range( /* out = log2( 1 + in ) */ IF( in_exp >= 0 ) { - one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, in_exp ); // Q(31 - 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 ); + in_s = L_add( L_shr( in[i], 1 ), one_s ); // Q(31 - in_exp) L_tmp = L_add( BASOP_Util_Log2( in_s ), in_exp32 ); if ( in_s == 0 ) { @@ -434,8 +434,8 @@ void compress_range( * Apply some dynamic range expansion to undo the compression *-------------------------------------------------------------------*/ void expand_range( - Word16 *in, - Word32 *out, + Word16 *in, // Q15 + Word32 *out, // Q(31 - out_exp) Word16 *out_exp, const Word16 len ) { @@ -451,7 +451,7 @@ void expand_range( move16(); FOR( i = 0; i < len; i++ ) { - maxVal = s_max( maxVal, in[i] ); + maxVal = s_max( maxVal, in[i] ); // Q15 } maxVal2 = maxVal; @@ -460,12 +460,12 @@ void expand_range( move16(); WHILE( maxVal >= 0 ) { - maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); + maxVal = sub( maxVal, 512 /*0.015625 Q15*/ ); // Q15 s = add( s, 1 ); } tmp = sub( maxVal2, maxVal ); - one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); + one_s = L_shr( 1073741824l /*0.5 Q31*/, sub( s, 1 ) ); // Q(31 - sub( s, 1 )) tmp32 = L_shr( 726941l /*0.0003385080526823181 Q31*/, s ); /* out = (2^(in) - 1) */ FOR( i = 0; i < len; i++ ) @@ -1766,7 +1766,7 @@ void minimum_statistics_fx( move16(); } } - if ( enc_dec == DEC && element_mode == IVAS_CPE_TD ) + IF( EQ_16( enc_dec, DEC ) && EQ_16( element_mode, IVAS_CPE_TD ) ) { // v_multc(msNoiseEst, 1.4125f, msNoiseEst, NPART_SHAPING); v_multc_att( msNoiseEst, 23142, msNoiseEst, NPART_SHAPING ); @@ -1812,7 +1812,7 @@ 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 SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize /* i : Size of scale table */ ) { @@ -1874,7 +1874,7 @@ 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 SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ const Word16 scaleTableSize, /* i : Size of scale table */ Word16 *index ) { @@ -1922,7 +1922,7 @@ void bandcombinepow( IF( EQ_16( nband, npart ) ) { - Copy32( bandpow, partpow, nband ); + Copy32( bandpow, partpow, nband ); // Q(31 - exp_bandpow) smin = 0; move16(); } @@ -1973,13 +1973,13 @@ void bandcombinepow( * Scale partitions (with smoothing) *-------------------------------------------------------------------*/ void scalebands( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ 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 */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2008,7 +2008,7 @@ void scalebands( stopPart = nFFTpart; move16(); - WHILE( LT_16( startBand, nband ) ) + WHILE( startBand < nband ) { stopPartM1 = sub( stopPart, 1 ); test(); @@ -2026,15 +2026,15 @@ void scalebands( j = add( j, 1 ); /* inner partitions */ - IF( j < stopPart ) + IF( LT_16( j, stopPart ) ) { partpowLD64M1 = BASOP_Util_Log2( partpow[j - 1] ); } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2057,7 +2057,7 @@ void scalebands( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2067,7 +2067,7 @@ void scalebands( 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 ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2088,19 +2088,19 @@ void scalebands( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { val = L_shl( Mpy_32_16_1( val, delta ), s1 ); - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2115,13 +2115,13 @@ void scalebands( #ifdef IVAS_FLOAT_FIXED void scalebands_fx( - const Word32 *partpow, /* i : Power for each partition */ + const Word32 *partpow, /* i : Power for each partition Qx*/ 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 */ + Word32 *bandpow, /* o : Power for each band Qx*/ const Word16 flag_fft_en ) { Word16 i, j, s, s1, nint, delta, delta_cmp, delta_s; @@ -2162,7 +2162,7 @@ void scalebands_fx( FOR( i = startBand; i <= midband[j]; i++ ) { - bandpow[i] = partpow[j]; + bandpow[i] = partpow[j]; // Qx move32(); } j = add( j, 1 ); @@ -2174,9 +2174,9 @@ void scalebands_fx( } /* Debug values to check this variable is set. */ - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); - delta_cmp = 0x4000; + delta_cmp = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); @@ -2206,7 +2206,7 @@ void scalebands_fx( WHILE( tmp > 0 ) { - tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); + tmp = L_sub( tmp, 33554432l /*0.015625 Q31*/ ); // Q31 delta_s = add( delta_s, 1 ); } delta_cmp = shl( 1, s_max( -15, sub( WORD16_BITS - 1, delta_s ) ) ); @@ -2216,7 +2216,7 @@ void scalebands_fx( 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 ) ); // Q(14+s) #else delta = round_fx( L_shl( tmp, s ) ); #endif @@ -2229,7 +2229,7 @@ void scalebands_fx( bandpow[i] = L_shr( val, delta_s ); move32(); } - bandpow[i++] = partpow[j]; + bandpow[i++] = partpow[j]; // Qx move32(); partpowLD64M1 = partpowLD64; move32(); @@ -2237,14 +2237,14 @@ void scalebands_fx( IF( GT_16( shr( delta, s ), delta_cmp ) ) { - delta = 0x4000; + delta = 0x4000; // 1.Q14 move16(); s1 = 1; move16(); } /* last half partition */ - val = partpow[stopPartM1]; + val = partpow[stopPartM1]; // Qx move32(); FOR( ; i <= part[stopPartM1]; i++ ) { @@ -2263,7 +2263,7 @@ void scalebands_fx( val = 0; move32(); } - bandpow[i] = val; + bandpow[i] = val; // Qx move32(); } } @@ -2331,8 +2331,8 @@ static void getmidbands( FOR( j = 0; j < npart; j++ ) { #ifdef BASOP_NOGLOB - psize_norm[j] = shl_o( psize[j], shift, &Overflow ); -#else /* BASOP_NOGLOB */ + psize_norm[j] = shl_o( psize[j], shift, &Overflow ); // Q(15 - psize_norm_exp) +#else /* BASOP_NOGLOB */ psize_norm[j] = shl( psize[j], shift ); #endif move16(); @@ -2348,7 +2348,7 @@ static void getmidbands( *-------------------------------------------------------------------*/ void AnalysisSTFT( - const Word16 *timeDomainInput, /* i : pointer to time signal */ + const Word16 *timeDomainInput, /* i : pointer to time signal Q(Q)*/ Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2418,7 +2418,7 @@ void AnalysisSTFT( * STFT analysis filterbank *-------------------------------------------------------------------*/ void AnalysisSTFT_fx( - const Word16 *timeDomainInput, + const Word16 *timeDomainInput, // Q(Q) Word16 Q, Word32 *fftBuffer, /* o : FFT bins */ Word16 *fftBuffer_exp, /* i : exponent of FFT bins */ @@ -2528,7 +2528,7 @@ void SynthesisSTFT_enc_ivas_fx( { FOR( i = 0; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2543,7 +2543,7 @@ void SynthesisSTFT_enc_ivas_fx( } FOR( i = len3; i < len; i++ ) { - olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); + olapBuffer[i] = round_fx_sat( L_shl_sat( fftBuffer[i], sub( fftBufferExp, 15 ) ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2620,7 +2620,7 @@ void SynthesisSTFT_enc_ivas_fx( 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 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2666,7 +2666,7 @@ void SynthesisSTFT( { FOR( i = 0; 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 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -2744,7 +2744,7 @@ void SynthesisSTFT( void SynthesisSTFT_ivas_fx( Word32 *fftBuffer, /* i : pointer to FFT bins */ Word16 fftBufferExp, /* i : exponent of FFT bins */ - Word16 *timeDomainOutput, /* o : pointer to time domain signal */ + Word16 *timeDomainOutput, /* o : pointer to time domain signal Qx*/ Word16 *olapBuffer, /* i/o : pointer to overlap buffer */ const PWord16 *olapWin, /* i : pointer to overlap window */ Word16 tcx_transition, @@ -2772,6 +2772,8 @@ void SynthesisSTFT_ivas_fx( /* Perform overlap-add */ /* Handle overlap in P/S domain for stereo */ + test(); + test(); 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 ); @@ -2790,7 +2792,7 @@ void SynthesisSTFT_ivas_fx( { FOR( i = 0; 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 ) ); // Q(15 - fftBufferExp) move16(); } } @@ -3290,12 +3292,12 @@ void FdCng_exc( Word16 *lsp_old, Word16 first_CNG, Word16 *lspCNG, - 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 */ + Word16 *Aq, /* o: LPC coeffs Q12*/ + Word16 *lsp_new, /* o: lsp Q15 */ + Word16 *lsf_new, /* o: lsf Qlog2(2.56) */ + Word16 *exc, /* o: LP excitation Q12 */ + Word16 *exc2, /* o: LP excitation Q12 */ + Word16 *bwe_exc /* o: LP excitation for BWE Q12*/ ) { Word16 i; diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 3123d4475..fea7eca61 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -299,17 +299,17 @@ void sns_compute_scf_fx( Word16 q ); void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping */ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ - Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ + Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ); void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ); @@ -323,10 +323,10 @@ void stereo_tca_enc_fx( ); void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ); + Word32 *output /*qx*/ ); void ECSQ_init_instance_fx( ECSQ_instance *ecsq_inst, @@ -682,12 +682,12 @@ Word16 masa_sq_fx( ); void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -698,18 +698,18 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -720,7 +720,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ); @@ -1681,7 +1681,7 @@ void ivas_fine_gain_pred_fx( 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 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ); @@ -2006,10 +2006,10 @@ Word16 set_ACELP_flag_IVAS( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -2020,10 +2020,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -4951,7 +4951,7 @@ void computeDiffuseness_fixed( void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ); @@ -5308,11 +5308,11 @@ ivas_error ivas_spar_md_enc_open_fx( ); 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], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -5325,7 +5325,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 3aebb59f5..424a95b5a 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -176,9 +176,11 @@ void ivas_sba_config_fx( *nSCE = 0; move16(); *nCPE = shr( *nchan_transport, 1 ); + move16(); IF( NE_16( i_mult( 2, ( *nCPE ) ), *nchan_transport ) ) { *nCPE = add( *nCPE, 1 ); + move16(); } *element_mode = IVAS_CPE_MDCT; move16(); @@ -302,7 +304,7 @@ Word16 ivas_sba_get_analysis_order_fx( sba_analysis_order = sba_order; move16(); - 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; @@ -321,6 +323,7 @@ Word16 ivas_sba_get_analysis_order_fx( *-------------------------------------------------------------------*/ /*! r: number of Ambisonic channels */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_nchan( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int16_t sba_planar /* i : SBA planar flag */ @@ -339,7 +342,7 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } -#ifdef IVAS_FLOAT_FIXED +#else Word16 ivas_sba_get_nchan_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word16 sba_planar /* i : SBA planar flag */ @@ -398,7 +401,7 @@ Word16 ivas_sba_get_nchan_metadata_fx( return ( nb_channels ); } -#endif +#else int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -426,7 +429,7 @@ int16_t ivas_sba_get_nchan_metadata( return ( nb_channels ); } - +#endif /*-------------------------------------------------------------------* * ivas_sba_get_spar_hoa_ch_ind() @@ -565,7 +568,7 @@ void ivas_sba_get_spar_hoa_md_flag_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_sba_zero_vert_comp_fx( - Word32 *sba_data[], /* i : SBA signals */ + Word32 *sba_data[], /* i : SBA signals q_data */ const Word16 sba_order, /* i : SBA order */ const Word16 sba_planar, /* i : SBA planar flag */ const Word16 input_frame /* i : frame length */ diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index ff8fcd8aa..9a7a092b3 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -50,11 +50,11 @@ *-------------------------------------------------------------------*/ void sns_compute_scf_fx( - Word32 spectrum[], /* i : Spectrum (Q_in) */ + Word32 spectrum[], /* i : Spectrum Q_in */ const PsychoacousticParameters *pPsychParams, const Word16 L_frame, Word32 *scf, /* o : Scalefactors (Q16)*/ - Word16 q ) + Word16 Q_in ) { Word16 i, n, k; Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS]; @@ -75,11 +75,11 @@ void sns_compute_scf_fx( move16(); const Word16 w_2 = 8192; // 0.25f ( 3.0f / 12.0f ) in Q15 move16(); - const Word16 w_3 = w_2; + const Word16 w_3 = w_2; // q15 move16(); - const Word16 w_4 = w_1; + const Word16 w_4 = w_1; // q15 move16(); - const Word16 w_5 = w_0; + const Word16 w_5 = w_0; // q15 move16(); assert( nBands == FDNS_NPTS ); @@ -138,7 +138,7 @@ void sns_compute_scf_fx( Word16 inv_bw; bw = (Word8) shr( L_frame, 6 ); move16(); - inv_bw = div_l( ONE_IN_Q16, bw ); // Q15 + inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bw ); // Q15 FOR( i = 0; i < nBands; ++i ) { x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) @@ -149,8 +149,8 @@ void sns_compute_scf_fx( { FOR( i = 0; i < nBands; ++i ) { - Word16 inv_bw = div_l( ONE_IN_Q16, bandLengths[i] ); // Q15 - x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) + Word16 inv_bw = div_l( ONE_IN_Q16 /*1 Q16*/, bandLengths[i] ); // Q15 + x[i] = Mpy_32_16_1( x[i], inv_bw ); // Q_in + (q_shift - 32) move32(); } } @@ -196,7 +196,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < FDNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xs[ind] ); // Q_in + (q_shift - 32) + sum = W_add( sum, W_deposit32_l( xs[ind] ) ); // Q_in + (q_shift - 32) } mean = W_extract_l( W_shr( sum, 6 ) ); // Q_in + (q_shift - 32) @@ -216,8 +216,8 @@ void sns_compute_scf_fx( FOR( i = 0; i < FDNS_NPTS; i++ ) { Word16 e_tmp = norm_l( xs[i] ); - Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); - e_tmp = sub( sub( 34, e_tmp ), q ); + Word16 f_tmp = Log2_norm_lc( L_shl( xs[i], e_tmp ) ); /*Q16*/ + e_tmp = sub( sub( 34, e_tmp ), Q_in ); /* Note: Mpy_32_16 is used temporarily for this computation, It needs to be replaced with appropriate BASOP. */ xl[i] = Mpy_32_16( e_tmp, f_tmp, 16384 ); /* Q16 */ move32(); @@ -264,7 +264,7 @@ void sns_compute_scf_fx( move64(); FOR( Word16 ind = 0; ind < SNS_NPTS; ind++ ) { - sum = W_add( sum, (Word64) xl4[ind] ); // Q16 + sum = W_add( sum, W_deposit32_l( xl4[ind] ) ); // Q16 } mean = W_extract_l( W_shr( sum, 4 ) ); // Q16 @@ -284,8 +284,8 @@ void sns_compute_scf_fx( *-------------------------------------------------------------------*/ void sns_interpolate_scalefactors_fx( - Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping*/ - const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream */ + Word32 *scf_int, /* o : interpolated scalefactors for spectrum shaping q16*/ + const Word32 *scf, /* i : sns scalefactors as derived from the signal or read from the bitstream Q16*/ Word16 encoder_side /* i : flag, if scalefactors have to be inverted */ ) { @@ -294,34 +294,34 @@ void sns_interpolate_scalefactors_fx( Word16 exp; /* Interpolation */ - scf_int[0] = scf[0]; - scf_int[1] = scf[0]; + scf_int[0] = scf[0]; // q16 + scf_int[1] = scf[0]; // q16 move32(); move32(); FOR( n = 0; n <= M - 2; n++ ) { - scf_int[add( n * 4, 2 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 ); /* 4096 -> 1/8 in Q15 */ - scf_int[add( n * 4, 3 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 ); /* 12288 -> 3/8 in Q15 */ - scf_int[add( n * 4, 4 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 ); /* 20480 -> 5/8 in Q15 */ - scf_int[add( n * 4, 5 )] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 ); /* 28672 -> 7/8 in Q15 */ + scf_int[n * 4 + 2] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[n * 4 + 3] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 + scf_int[n * 4 + 4] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 20480 /* 20480 -> 5/8 in Q15 */ ); // q16 + scf_int[n * 4 + 5] = Madd_32_16( scf[n], L_sub( scf[n + 1], scf[n] ), 28672 /* 28672 -> 7/8 in Q15 */ ); // q16 move32(); move32(); move32(); move32(); } - scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 ); - scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 ); + scf_int[FDNS_NPTS - 2] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 4096 /* 4096 -> 1/8 in Q15 */ ); // q16 + scf_int[FDNS_NPTS - 1] = Madd_32_16( scf[M - 1], L_sub( scf[M - 1], scf[M - 2] ), 12288 /* 12288 -> 3/8 in Q15 */ ); // q16 move32(); move32(); /* Inversion at encoder-side */ - IF( encoder_side == ENC ) + IF( encoder_side == ENC /*0*/ ) { FOR( n = 0; n < FDNS_NPTS; n++ ) { - scf_int[n] = L_negate( scf_int[n] ); + scf_int[n] = L_negate( scf_int[n] ); // q16 move32(); } } @@ -329,9 +329,9 @@ void sns_interpolate_scalefactors_fx( /* Linear domain */ FOR( n = 0; n < FDNS_NPTS; n++ ) { - L_tmp = BASOP_util_Pow2( scf_int[n], Q15, &exp ); + L_tmp = BASOP_util_Pow2( scf_int[n], 15 /*31-Q16*/, &exp ); // Q=31-exp exp = sub( 15, exp ); - scf_int[n] = L_shr( L_tmp, exp ); + scf_int[n] = L_shr( L_tmp, exp ); // q16 move32(); } @@ -346,11 +346,11 @@ void sns_interpolate_scalefactors_fx( *-------------------------------------------------------------------*/ void sns_shape_spectrum_fx( - Word32 spectrum[], /* i/o: spectrum to be shaped */ + Word32 spectrum[], /* i/o: spectrum to be shaped Input Q is q_spectrum and ouput Q is (q_spectrum-1)*/ Word16 *q_spectrum, /* i/o: Q of spectrum */ const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ - const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ + const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors q_scf_int*/ const Word16 L_frame, /* i : frame length */ Word16 *length ) { @@ -364,7 +364,7 @@ void sns_shape_spectrum_fx( IF( bandLengths == NULL ) { - bw = divide3216( shl( L_frame, 1 ), nBands ); + bw = divide3216( shl( L_frame, 1 ), nBands ); // q0 /* Shape spectrum */ k = 0; @@ -376,7 +376,7 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) ) + if ( LT_16( shift, min_shift ) ) { min_shift = shift; move16(); @@ -398,9 +398,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // Q = q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; @@ -418,7 +418,8 @@ void sns_shape_spectrum_fx( L64_tmp[k] = W_mult_32_32( spectrum[k], scf_int[i] ); // Q = q_spectrum + q_scf_int + 1 move64(); shift = W_norm( L64_tmp[k] ); - IF( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) + test(); + if ( LT_16( shift, min_shift ) && NE_64( L64_tmp[k], 0 ) ) { min_shift = shift; move16(); @@ -440,9 +441,9 @@ void sns_shape_spectrum_fx( } FOR( k = 0; k < tmp_k; k++ ) { - L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); + L64_tmp[k] = W_shr( L64_tmp[k], sub( add( *q_spectrum, q_scf_int ), q_tmp ) ); // q_tmp+1 move64(); - spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp + spectrum[k] = W_sat_l( L64_tmp[k] ); // Q = q_tmp+1 move64(); } *q_spectrum = q_tmp; diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index f70a74d6e..74d3c01d3 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -64,18 +64,18 @@ #define IVAS_REMIX_MULT_FAC ( 0.5f ) #define IVAS_ACTIVEW_DM_F ( 1.0f ) -#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) +#define IVAS_ACTIVEW_DM_F_Q30 ( ONE_IN_Q30 ) /*1 Q30*/ #define IVAS_ACTIVEW_DM_F_DTX ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_DTX_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_ACTIVEW_DM_F_VLBR ( 0.25f ) -#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) +#define IVAS_ACTIVEW_DM_F_VLBR_Q30 ( 268435456 ) /*0.25 Q30*/ #define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH ( 3.0f ) -#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) +#define IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29 ( 1610612736 ) /*3 Q29*/ #define IVAS_P_NORM_SCALING ( 1.0f ) -#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // Q31 +#define IVAS_P_NORM_SCALING_FX ( ONE_IN_Q31 ) // 1 Q31 #define IVAS_P_NORM_SCALING_DTX ( 0.75f ) -#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // Q31 +#define IVAS_P_NORM_SCALING_DTX_FX ( 1610612736 ) // 0.75 Q31 #define IVAS_MAT_DIM_3 ( 3 ) #define IVAS_MAT_DIM_2 ( 2 ) @@ -88,11 +88,11 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -105,11 +105,11 @@ static void ivas_get_pred_coeffs_enc_fx( const Word16 res_ind ); static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - 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], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -119,24 +119,24 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ); static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_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], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -148,11 +148,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] /*qx*/, const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], Word32 ***mixer_mat /*qx*/, 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] /*q_cov_real*/, Word16 q_cov_real, Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS] /*q_pred_coeffs_re*/, Word16 q_pred_coeffs_re, Word32 ***mixer_mat /*q_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 /*q_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] /*q_cov_real*/, Word16 q_cov_real, Word32 ***mixer_mat /*q_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] /*q_postpred_cov_re*/, Word16 *q_postpred_cov_re ); +static Word16 ivas_is_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim ); +static void ivas_calc_mat_inv_fx( Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_in_re*/, Word16 q_in_re, const Word16 dim, Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM] /*q_out_re*/, Word16 *q_out_re ); #endif /*-----------------------------------------------------------------------------------------* @@ -323,13 +323,13 @@ void ivas_spar_config_fx( move16(); } - *nSCE = max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); + *nSCE = s_max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); move16(); IF( EQ_16( *nchan_transport, 1 ) ) { /* map SPAR SID bitrate to SPAR active bitrate */ - IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { ivas_total_brate = IVAS_32k; move32(); @@ -439,7 +439,7 @@ Word16 ivas_get_spar_table_idx_fx( ( EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) ) { ind1[j] = i; - j = add( j, 1 ); + j++; move16(); } } @@ -459,7 +459,7 @@ Word16 ivas_get_spar_table_idx_fx( table_idx = ind1[ind2]; move16(); - IF( ind != NULL ) + if ( ind != NULL ) { *ind = ind2; move16(); @@ -525,11 +525,11 @@ Word16 ivas_get_sba_num_TCs_fx( *-----------------------------------------------------------------------------------------*/ static void ivas_get_pred_coeffs_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ Word16 *q_pred_coeffs, - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, @@ -573,7 +573,7 @@ static void ivas_get_pred_coeffs_enc_fx( set16_fx( q_pPred_temp, 31, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 in q31*/, L_max( 1, cov_real[0][0][k] ), &s_div ); /*Q=15-(s_div-(31-q_cov_real))*/ move16(); div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); @@ -584,7 +584,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); /*q_cov_real+15-div_factor_e[k]+1*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -607,11 +607,11 @@ static void ivas_get_pred_coeffs_enc_fx( IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); // q_tmp -> q_pPred_temp[k] } ELSE { - pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); // q_pPred_temp[k]->q_tmp move64(); q_pPred_temp[k] = q_tmp; move16(); @@ -626,13 +626,13 @@ static void ivas_get_pred_coeffs_enc_fx( { tmp_shift = W_norm( pPred_temp[k] ); e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); - L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); + L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); // 1 in Q(31-e_tmp) IF( LT_32( one_in_q, L_tmp ) ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); // Q=15-s_div move16(); div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 move16(); @@ -641,7 +641,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - div_factor[k] = ONE_IN_Q15 - 1; + div_factor[k] = ONE_IN_Q15 - 1; /*1 in Q15*/ move16(); div_factor_e[k] = 0; move16(); @@ -654,7 +654,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 /*1 in Q15*/ ) ) { ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] move32(); @@ -672,7 +672,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); // Q=tmp_shift move32(); } } @@ -702,12 +702,12 @@ static void ivas_get_pred_coeffs_enc_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; /*1 in Q29*/ move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; /*3.0f Q29*/ move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -734,7 +734,7 @@ static void ivas_get_pred_coeffs_enc_fx( } IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) { - dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); // Q=q_tmp move64(); dm_alpha64_q[k] = q_tmp; move16(); @@ -744,7 +744,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); IF( LT_16( tmp_shift, 63 ) ) { - dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); // Q=dm_alpha64_q[k] move64(); } } @@ -763,12 +763,12 @@ static void ivas_get_pred_coeffs_enc_fx( e_tmp = 0; move16(); } - dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp move32(); dm_alpha64_q[k] = sub( 31, e_tmp ); move16(); - div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 Q31*/, L_max( dm_alpha[k], 1 ), &s_div ); // Q=15-(dm_alpha64_q[k]+ s_div-31) move16(); div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); @@ -779,7 +779,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( k = start_band; k < end_band; k++ ) { - tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); + tmp64 = W_mult_32_16( cov_real[i + 1][0][k], div_factor[k] ); // Q=(15-div_factor_e[k]+q_cov_real[i+1][0][k])+1 tmp_shift = W_norm( tmp64 ); IF( tmp64 != 0 ) { @@ -800,19 +800,19 @@ static void ivas_get_pred_coeffs_enc_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -827,7 +827,7 @@ static void ivas_get_pred_coeffs_enc_fx( FOR( k = 1; k < in_chans; k++ ) { // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); + re = W_mult0_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q=q_cov_real[j+1][k][b]+dm_v_re_q[k-1][b] tmp_shift = W_norm( re ); IF( re != 0 ) { @@ -841,7 +841,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, real64_q[j] ) ) { - real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp move64(); real64_q[j] = q_tmp; move16(); @@ -851,7 +851,7 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); IF( LT_16( tmp_shift, 63 ) ) { - real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); // Q=real64_q[j] move64(); } } @@ -866,7 +866,7 @@ static void ivas_get_pred_coeffs_enc_fx( { // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); tmp_shift = W_norm( real64[k] ); - re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); // Q=(real64[k]+tmp_shift-32)+dm_v_re_q q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); tmp_shift = W_norm( re ); IF( re != 0 ) @@ -881,7 +881,7 @@ static void ivas_get_pred_coeffs_enc_fx( IF( LT_16( q_tmp, dm_beta_re_q ) ) { - tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); // Q=q_tmp dm_beta_re_q = q_tmp; move16(); } @@ -890,12 +890,12 @@ static void ivas_get_pred_coeffs_enc_fx( tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); IF( LT_16( tmp_shift, 63 ) ) { - tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); // Q=dm_beta_re_q } } } tmp_shift = W_norm( tmp64 ); - dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); // Q=dm_beta_re_q+tmp_shift-32 IF( tmp64 != 0 ) { dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); @@ -908,7 +908,7 @@ static void ivas_get_pred_coeffs_enc_fx( dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); - den_f = L_max( dm_w, 1 ); + den_f = L_max( dm_w, 1 ); // q_cov_real[0][0][b] passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); @@ -929,16 +929,16 @@ static void ivas_get_pred_coeffs_enc_fx( dm_v_re_q[i][b] = 31; move16(); } - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; /*1 Q31*/ move32(); dm_v_re_q[i][b] = 31; move16(); - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } - IF( LT_32( passive_g, activew_quad_thresh ) ) + IF( LT_32( passive_g, activew_quad_thresh ) ) // q29 { /*linear activeW*/ dm_y = 0; @@ -950,30 +950,30 @@ static void ivas_get_pred_coeffs_enc_fx( { IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) { - dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); // q_cov_real[k][k][b] q_tmp = q_cov_real[k][k][b]; move16(); } ELSE { - dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); // q_tmp } } - tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); // Q=q_tmp IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) { - tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); // Q=q_tmp } ELSE { q_tmp = q_cov_real[0][0][b]; move16(); - dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); // Q=q_cov_real[0][0][b] } if ( GT_64( tmp64, dm_y ) ) { - dm_y = tmp64; + dm_y = tmp64; // Q=q_tmp move16(); } @@ -989,7 +989,7 @@ static void ivas_get_pred_coeffs_enc_fx( den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // q_tmp + tmp_shift - 32 DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div move32(); @@ -997,15 +997,15 @@ static void ivas_get_pred_coeffs_enc_fx( DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); move16(); - IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) // q30 { - DM_F[b] = ONE_IN_Q31; + DM_F[b] = ONE_IN_Q31; /*1 Q31*/ move32(); DM_F_q[b] = Q31; move16(); } - tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); /*Q=(2*DM_F_q[b])*/ tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1014,7 +1014,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); /*Q=(2*DM_F_q[b]+tmp_shift)*/ } tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); @@ -1026,12 +1026,12 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=q_tmp+tmp_shift } - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q=q_tmp+tmp_shift-32 L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); // Q=dm_alpha64_q[b]+DM_F_q[b] tmp_shift = sub( W_norm( tmp64 ), 2 ); IF( tmp64 == 0 ) { @@ -1040,40 +1040,40 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q[b]+DM_F_q[b]+tmp_shift } L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { - L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } tmp_shift = sub( norm_l( dm_w ), 1 ); - L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2 = L_shl( dm_w, tmp_shift ); // Q=q_cov_real[0][0][b]+ tmp_shift L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); IF( LT_16( L_tmp2_q, L_tmp1_q ) ) { - den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp2_q ); } ELSE { - den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp2_q den_f_e = sub( 31, L_tmp1_q ); } - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e - tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); // Q= DM_F_q[b]+dm_beta_re_q tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1082,23 +1082,23 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift } L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); - L_tmp2 = W_extract_h( tmp64 ); + L_tmp2 = W_extract_h( tmp64 ); // Q= DM_F_q[b]+dm_beta_re_q+tmp_shift-32 tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) { - L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); // Q=L_tmp2_q L_tmp1_q = L_tmp2_q; move16(); } ELSE { L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); - L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); // Q=L_tmp1_q } dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) @@ -1113,7 +1113,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 num_f_e; /* quadratic activeW */ - tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); // Q=dm_alpha64_q[b]+29 tmp_shift = sub( W_norm( tmp64 ), 1 ); IF( tmp64 == 0 ) { @@ -1122,31 +1122,31 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q=dm_alpha64_q+29+tmp_shift } - L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 - L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); + L_tmp1 = W_extract_h( tmp64 ); // Q29 + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( Q29, dm_alpha64_q[b] ), tmp_shift ), 32 ); // Q=dm_alpha64_q+29+1+tmp_shift-32 - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ), &val_e ); // reducing the Q by 2 instead of multiplication by 4 + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // q=31-val_e - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); // q=31-num_f_e - den_f = Mpy_32_32( dm_beta_re, g_th_sq ); + den_f = Mpy_32_32( dm_beta_re, g_th_sq ); // Q=dm_beta_re_q+27-31-1 den_f_e = add( add( sub( 31, dm_beta_re_q ), 4 ), 1 ); // adding the exp with 1 instead of multiplication by 2 - den_f = L_max( den_f, 1 ); - dm_g[b] = activew_quad_thresh; // Q29 + den_f = L_max( den_f, 1 ); // q=31-den_f_e + dm_g[b] = activew_quad_thresh; // Q29 move32(); dm_g_q[b] = Q29; move16(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // Q=(31-(s_dm_f+2+num_f_e-den_f_e)) move32(); DM_F_q[b] = sub( 31, add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ) ); move16(); @@ -1162,7 +1162,7 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); // dm_v_re_q[i][b]+dm_g_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1171,14 +1171,14 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // dm_v_re_q[i][b]+dm_g_q[b]+tmp_shift } ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); move16(); - tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); // Q = dm_v_re_q[i][b] + DM_F_q[b] tmp_shift = W_norm( tmp64 ); IF( tmp64 == 0 ) { @@ -1187,7 +1187,7 @@ static void ivas_get_pred_coeffs_enc_fx( } ELSE { - tmp64 = W_shl( tmp64, tmp_shift ); + tmp64 = W_shl( tmp64, tmp_shift ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift } ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 move32(); @@ -1204,9 +1204,9 @@ static void ivas_get_pred_coeffs_enc_fx( { FOR( b = start_band; b < end_band; b++ ) { - ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); // Q=*q_pred_coeffs move32(); - ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); // Q=*q_dm_fv_re move32(); } } @@ -1216,9 +1216,9 @@ static void ivas_get_pred_coeffs_enc_fx( } static void ivas_get_pred_coeffs_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], - Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q30*/ + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_pred_coeffs*/ + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -1241,12 +1241,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = ONE_IN_Q29; /*1 q29*/ move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3 * ONE_IN_Q29; /* 3 q29*/ move32(); } tmp_shift = Q30; @@ -1261,13 +1261,13 @@ static void ivas_get_pred_coeffs_fx( set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_max( 1, cov_real[0][0][k] ); + div_factor[k] = L_max( 1, cov_real[0][0][k] ); // q30 move32(); tmp_shift = Q30; move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) // q30 { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31 /*1 q31*/, div_factor[k], &s_div ) ); // Q=15-(s_div-(31-30)) move32(); IF( s_div < 0 ) { @@ -1288,7 +1288,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1296,7 +1296,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1324,7 +1324,7 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); // q=31-q_pred_temp move32(); IF( LT_16( q_pred_temp, 1 ) ) @@ -1342,14 +1342,14 @@ static void ivas_get_pred_coeffs_fx( move16(); } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); /*Q=q_pred_temp*/ IF( LT_32( one_in_q, pPred_temp[k] ) ) { - div_factor[k] = pPred_temp[k]; + div_factor[k] = pPred_temp[k]; /*Q=q_pred_temp*/ move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); // q=15-s_div move32(); IF( s_div < 0 ) { @@ -1368,7 +1368,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE { - div_factor[k] = one_in_q; + div_factor[k] = one_in_q; // q=31-q_pred_temp move32(); tmp_shift = sub( 31, q_pred_temp ); } @@ -1377,7 +1377,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1385,7 +1385,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1427,12 +1427,12 @@ static void ivas_get_pred_coeffs_fx( IF( EQ_16( dyn_active_w_flag, 1 ) ) { - activew_quad_thresh = ONE_IN_Q29; + activew_quad_thresh = ONE_IN_Q29; // 1 q29 move32(); } ELSE { - activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; // 3 q29 move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -1453,13 +1453,13 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_max( dm_alpha[k], 1 ); + div_factor[k] = L_max( dm_alpha[k], 1 ); // q=31-dm_alpha_e move32(); - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); + div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); // q=15-(s_div+(0-dm_alpha_e)) move32(); IF( s_div < 0 ) { @@ -1480,7 +1480,7 @@ static void ivas_get_pred_coeffs_fx( { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); // q=tmp_shift move32(); } prev_tmp_shift = tmp_shift; @@ -1488,7 +1488,7 @@ static void ivas_get_pred_coeffs_fx( } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); // q=prev_tmp_shift move32(); tmp_shift = prev_tmp_shift; move16(); @@ -1506,19 +1506,19 @@ static void ivas_get_pred_coeffs_fx( IF( dtx_vad == 0 ) { - dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; // q30 move32(); } ELSE { IF( active_w_vlbr ) { - dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; // q30 move32(); } ELSE { - dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; // q30 move32(); } } @@ -1552,8 +1552,8 @@ static void ivas_get_pred_coeffs_fx( dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); dm_w = cov_real[0][0][b]; // Q30 move32(); - den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + den_f = L_max( dm_w, 1 ); // Q30 + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // Q=15-(s_div+dm_alpha_e-1) div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); passive_g = L_shl( passive_g, div_shift ); // Q = 29 @@ -1571,15 +1571,15 @@ static void ivas_get_pred_coeffs_fx( } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); // Q=tmp_shift-1 move32(); } ELSE { - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[res_ind - 1][b] = MAX_32; // Q=tmp_shift-1 move32(); } - passive_g = activew_quad_thresh; + passive_g = activew_quad_thresh; // q29 move32(); } @@ -1604,24 +1604,24 @@ static void ivas_get_pred_coeffs_fx( DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 move32(); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); // q30 move32(); L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ - L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); + L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); // Q=(Q29-dm_beta_re_e) + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); // Q29 den_f = L_add( L_tmp1, L_tmp2 ); // Q29 - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q29 den_f_e = 31 - 29; move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); // Q=30-dm_beta_re_e L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); // Q=29 + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); // Q=29 + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div move32(); @@ -1637,34 +1637,34 @@ static void ivas_get_pred_coeffs_fx( /* quadratic activeW */ - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); // Q=31-num_f_e sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ val_e = 4; move16(); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); - sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); // Q=31-val_e + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); // Q=31-val_e // val_e = norm_l( sqrt_val ); - sqrt_val = Sqrt32( sqrt_val, &val_e ); + sqrt_val = Sqrt32( sqrt_val, &val_e ); // Q=31-val_e IF( val_e < 0 ) { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); // Q31 } ELSE IF( val_e > 0 ) { - sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); + sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); // Q31 val_e = 0; move16(); } - num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); // Q=31-num_f_e - den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); // Q=31-dm_beta_re_e+27-31=>-dm_beta_re_e+27 den_f_e = add( dm_beta_re_e, 4 ); - den_f = L_max( den_f, 1 ); + den_f = L_max( den_f, 1 ); // Q=31-den_f_e dm_g[b] = activew_quad_thresh; // Q29 move32(); - DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); // s_dm_f+2+num_f_e-den_f_e move32(); s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ div_shift = sub( s_dm_f, 1 ); @@ -1679,7 +1679,7 @@ static void ivas_get_pred_coeffs_fx( { ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); // Q = tmp_shift - 1 + 30 -31 move32(); } } @@ -1703,11 +1703,11 @@ static void ivas_get_pred_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_Wscaling_factor_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - 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], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1717,7 +1717,7 @@ static void ivas_get_Wscaling_factor_enc_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1770,41 +1770,41 @@ static void ivas_get_Wscaling_factor_enc_fx( ivas_calc_post_pred_per_band_enc_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 ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); // 15-(tmp_exp-(q_cov_real[0][0][b]- q_postpred_cov_re)) q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( 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 ); // q=2*q_pred_coeffs_re-guard_bits-31 + g_sq = L_add( g_sq, abs_val ); // q=2*q_pred_coeffs_re-guard_bits-31 } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); // q_g_sq+28-31 q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // Q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // Q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = 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 ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1815,11 +1815,11 @@ static void ivas_get_Wscaling_factor_enc_fx( } static void ivas_get_Wscaling_factor_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - 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], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -1829,7 +1829,7 @@ static void ivas_get_Wscaling_factor_fx( const Word16 bands_bw, const Word16 active_w, const Word16 active_w_vlbr, - Word32 *pWscale, + Word32 *pWscale, /*q_pWscale*/ Word16 *q_pWscale, const Word16 dyn_active_w_flag ) { @@ -1882,41 +1882,41 @@ static void ivas_get_Wscaling_factor_fx( 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 ); + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); /*15-(tmp_exp-(q_cov_real-q_postpred_cov_re))*/ q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real, q_postpred_cov_re ) ); guard_bits = find_guarded_bits_fx( num_ch ); FOR( ch = 0; ch < sub( 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 ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ + g_sq = L_add( g_sq, abs_val ); /*q=2*q_pred_coeffs_re-guard_bits-31*/ } q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); - tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); /*q=q_g_sq-3*/ q_tmp = sub( q_g_sq, 3 ); q_min = s_min( q_Gw_sq, q_tmp ); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); - tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); // q=q_min tmp_exp = sub( 31, q_min ); - tmp = Sqrt32( tmp, &tmp_exp ); + tmp = Sqrt32( tmp, &tmp_exp ); // q=31-tmp_exp q_tmp = sub( 31, tmp_exp ); tmp_exp = sub( 31, q_Gw_sq ); - Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); // q=31-tmp_exp q_Gw_sq = 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 ) ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); // q=q_min q_Gw_sq = q_min; move16(); - tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); // q=q_min - pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); + pWscale[b] = L_add( L_shr( Gw_sq, 1 /* Gw_sq * 0.5 */ ), L_shr( tmp, 1 /* tmp * 0.5 */ ) ); // q=q_Gw_sq move32(); q_pWscale[b] = q_Gw_sq; move16(); @@ -1938,11 +1938,11 @@ static void ivas_get_Wscaling_factor_fx( #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], /*q_pred_coeffs_re*/ Word16 q_pred_coeffs_re, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 q_dm_fv_re, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 in_chans, const Word16 start_band, @@ -1983,9 +1983,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); // q=q_pred_coeffs_re } } @@ -1993,9 +1993,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[j - 1][b] ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); + max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); // q=q_pred_coeffs_re } } @@ -2011,9 +2011,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); + tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); // q=q_dm_fv_re } } @@ -2021,9 +2021,9 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); + max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); // q=q_dm_fv_re } } @@ -2038,8 +2038,8 @@ void ivas_create_fullr_dmx_mat_fx( { 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 ); + tmp_re = L_shr( Mpy_32_32( tmp_p2_re[i][k][b], tmp_p1_re[k][j][b] ), guard_bits ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits + down_mix_mat1_re[i][j][b] = L_add( down_mix_mat1_re[i][j][b], tmp_re ); // q= q_dm_fv_re+ q_pred_coeffs_re-31-guard_bits move32(); } } @@ -2056,7 +2056,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; + down_mix_mat1_re[j][k][b] = tmp_p2_re[j][k][b]; // q=q_pred_coeffs_re move32(); } } @@ -2084,10 +2084,10 @@ void ivas_create_fullr_dmx_mat_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_reorder_array_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS], /*qx*/ const Word16 in_chans, const Word16 order[IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*qx*/ const Word16 start_band, const Word16 end_band ) { @@ -2102,7 +2102,7 @@ static void ivas_reorder_array_fx( { FOR( b = start_band; b < end_band; b++ ) { - mixer_mat[i][j][b] = in_re[idx][j][b]; + mixer_mat[i][j][b] = in_re[idx][j][b]; /*qx*/ move32(); } } @@ -2121,13 +2121,13 @@ static void ivas_reorder_array_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_post_pred_per_band_enc_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_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], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; @@ -2141,7 +2141,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2165,16 +2165,16 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); /*q_cov_real[i][k][band_idx]*/ IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); /*q_cov_real[i][k][band_idx]*/ q_tmp_re = q_cov_real[i][k][band_idx]; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); /*q_tmp_re*/ } } IF( tmp_re == 0 ) @@ -2189,7 +2189,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_temp_mat[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /*q_temp_mat[i][j]+ q_tmp_re -32*/ move32(); q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); move16(); @@ -2224,17 +2224,17 @@ static void ivas_calc_post_pred_per_band_enc_fx( move16(); FOR( k = 0; k < num_ch; k++ ) { - W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); // q_temp_mat[k][j]+ q_mixer_mat-guard_bits q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); IF( LT_16( q_W_tmp, q_tmp_re ) ) { - tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); // q_W_tmp q_tmp_re = q_W_tmp; move16(); } ELSE { - tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); // q_tmp_re } } @@ -2247,7 +2247,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( q_postpred_cov_re_per_value[i][j] = q_tmp_re; move16(); q_tmp_re = W_norm( tmp_re ); - postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); /* q_tmp_re+ q_postpred_cov_re_per_value[i][j] -32*/ move32(); q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); move16(); @@ -2262,12 +2262,12 @@ static void ivas_calc_post_pred_per_band_enc_fx( { IF( postpred_cov_re[i][j] >= 0 ) { - postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); //*q_postpred_cov_re move32(); } ELSE { - postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); //*q_postpred_cov_re move32(); } } @@ -2277,7 +2277,7 @@ static void ivas_calc_post_pred_per_band_enc_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; //*q_postpred_cov_re move32(); } } @@ -2286,13 +2286,13 @@ static void ivas_calc_post_pred_per_band_enc_fx( } static void ivas_calc_post_pred_per_band_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_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], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 *q_postpred_cov_re ) { Word16 i, j, k, guard_bits, tmp, q_temp_mat; @@ -2305,7 +2305,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < num_ch; j++ ) { - dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; /*q_mixer_mat*/ move32(); } } @@ -2329,7 +2329,7 @@ static void ivas_calc_post_pred_per_band_fx( move64(); 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 ) ); + 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 ) ); /*q_cov_real+q_mixer_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { @@ -2338,7 +2338,7 @@ static void ivas_calc_post_pred_per_band_fx( } 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 = (q_cov_real - guard_bits) } } q_temp_mat = sub( q_cov_real, guard_bits ); @@ -2365,7 +2365,7 @@ static void ivas_calc_post_pred_per_band_fx( 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 ) ); /*q_mixer_mat+q_temp_mat-guard_bits*/ } if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) @@ -2374,7 +2374,7 @@ static void ivas_calc_post_pred_per_band_fx( 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 ) ); /*q_temp_mat-guard_bits*/ move32(); } } @@ -2386,7 +2386,7 @@ static void ivas_calc_post_pred_per_band_fx( { FOR( j = 0; j < i; j++ ) { - postpred_cov_re[i][j] = postpred_cov_re[j][i]; + postpred_cov_re[i][j] = postpred_cov_re[j][i]; /* *q_postpred_cov_re */ move32(); } } @@ -2407,7 +2407,7 @@ static void ivas_calc_post_pred_per_band_fx( static void ivas_calc_p_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_postpred_cov_re*/ Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2445,7 +2445,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2458,7 +2458,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_postpred_cov_re move32(); } } @@ -2472,18 +2472,18 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { Word32 re1, re2; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ pSparMd->band_coeffs[b_ts_idx].q_C_re_fx*/ q_tmp1 = W_norm( W_tmp ); - re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); /*q_cov_dd_re+ q_C_re+q_tmp1-32*/ q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { q_tmp1 = 31; move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); /*q_cov_dd_re+ q_C_re*/ q_tmp = W_norm( W_tmp ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); /*q_cov_dd_re+ q_C_re+q_tmp-32*/ q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2491,10 +2491,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); // q_tmp1+q_C_re q_recon_uu_re[0][0] = W_norm( W_tmp ); move16(); - recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); // q_tmp1+q_C_re+q_recon_uu_re[0][0]-32 move32(); q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); move16(); @@ -2504,10 +2504,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); // q_C_re+q_tmp1 q_recon_uu_re[0][1] = W_norm( W_tmp ); move16(); - recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); // q_C_re+q_tmp1+q_recon_uu_re[0][1]-32 move32(); q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); move16(); @@ -2517,10 +2517,10 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][0] = W_norm( W_tmp ); move16(); - recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][0]-32 move32(); q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); move16(); @@ -2530,12 +2530,12 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( move16(); } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); // q_C_re+q_tmp q_recon_uu_re[1][1] = W_norm( W_tmp ); move16(); - recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); // q_C_re+q_tmp+q_recon_uu_re[1][1]-32 move32(); - q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp ), 32 ); move16(); if ( W_tmp == 0 ) { @@ -2558,7 +2558,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2577,9 +2577,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( k = 0; k < 2; k++ ) { Word32 re; - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 1 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2589,35 +2589,35 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[j] ) ) { - re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); // q_tmp move32(); q_re1[j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); // q_re1[j] } - re1[j] = L_add( re1[j], re ); + re1[j] = L_add( re1[j], re ); // q_re1[j] move32(); } } - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); // q_C_re+q_re1[0] q_tmp = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[0]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); if ( W_tmp == 0 ) { q_tmp = 31; move16(); } - recon_uu_re[0][0] = re2; + recon_uu_re[0][0] = re2; // q_C_re+q_re1[0]+q_tmp-32 move32(); - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); // q_C_re+q_re1[1] q_tmp1 = sub( W_norm( W_tmp ), 1 ); - re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); // q_C_re+q_re1[1]+q_tmp1-32 q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); if ( W_tmp == 0 ) { @@ -2627,22 +2627,22 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_tmp1 ) ) { - re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); // q_tmp } ELSE { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); // q_tmp1 move32(); q_tmp = q_tmp1; move16(); } - recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_tmp move32(); IF( LT_16( q_cov_uu_re, q_tmp ) ) { - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); // q_cov_uu_re move32(); } ELSE @@ -2651,7 +2651,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re, q_tmp ) ); // q_tmp move32(); } } @@ -2668,17 +2668,17 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); + cov_uu_re[i - num_dmx][j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], 1 ); // q_cov_uu_re-1 move32(); } } q_cov_uu_re = sub( q_cov_uu_re, 1 ); - recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); // q_cov_uu_re move32(); } } - 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] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -2696,9 +2696,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( k = 0; k < num_dmx - 1; k++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); // q_C_re+q_cov_dd_re q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_cov_dd_re+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); if ( W_tmp == 0 ) { @@ -2708,29 +2708,29 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_re1[m] ) ) { - re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); // q_tmp move32(); q_re1[m] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); // q_re1[m] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_re1[m]-1 move32(); q_re1[m] = sub( q_re1[m], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_re1[m] } } - re1[m] = L_add( re1[m], re ); + re1[m] = L_add( re1[m], re ); // q_re1[m] move32(); } } @@ -2738,9 +2738,9 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( m = 0; m < num_dmx - 1; m++ ) { - W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); // q_C_re+q_re1[m] q_tmp = sub( W_norm( W_tmp ), 2 ); - re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); // q_C_re+q_re1[m]+q_tmp-32 q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); if ( W_tmp == 0 ) { @@ -2750,28 +2750,28 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) { - recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); // q_tmp move32(); q_recon_uu_re[i][j] = q_tmp; move16(); } ELSE { - re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); // q_recon_uu_re[i][j] } IF( re != 0 ) { test(); IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) { - re1[m] = L_shr( re1[m], 1 ); + re1[m] = L_shr( re1[m], 1 ); // q_recon_uu_re[i][j]-1 move32(); q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); move16(); - re = L_shr( re, 1 ); + re = L_shr( re, 1 ); // q_recon_uu_re[i][j] } } - recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_recon_uu_re[i][j] move32(); } } @@ -2793,7 +2793,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); // q_tmp move32(); } } @@ -2802,13 +2802,13 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; // q31 move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; // q31 move32(); } @@ -2817,33 +2817,33 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); IF( trace != 0 ) { q_factor = W_norm( trace ); - tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); - q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); // q_cov_uu_re+q_factor-32 + q_factor = sub( add( q_cov_uu_re, q_factor ), 32 ); IF( GT_16( q_factor, q_postpred_cov_re ) ) { - tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); // q_postpred_cov_re q_factor = q_postpred_cov_re; move16(); } ELSE { - factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); // q_factor } - factor = L_max( factor, tmp ); + factor = L_max( factor, tmp ); // q_factor } Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); // q=15-(factor_exp+31-(31-q_factor)) factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -2854,14 +2854,14 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); + W_tmp = W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ); /*q_cov_uu_re+15-factor_exp*/ q_tmp = 32; move16(); if ( W_tmp != 0 ) { q_tmp = W_norm( W_tmp ); } - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); + cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), q_tmp ) ); /*q_cov_uu_re+15-factor_exp+q_tmp-32*/ move32(); q_cov_uu_re_per_value[i - num_dmx][j - num_dmx] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); move16(); @@ -2884,7 +2884,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] ); - 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] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); // q=31-cov_uu_re_exp move32(); q_cov_uu_re_per_value[i - num_dmx][i - num_dmx] = sub( 31, cov_uu_re_exp ); move16(); @@ -2898,7 +2898,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = L_shr( cov_uu_re[i - num_dmx][j - num_dmx], sub( q_cov_uu_re_per_value[i - num_dmx][j - num_dmx], Q28 ) ); // Q28 move32(); } } @@ -2913,7 +2913,7 @@ static void ivas_calc_p_coeffs_per_band_enc_fx( static void ivas_calc_p_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], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_postpred_cov_re Word16 q_postpred_cov_re, const Word16 num_ch, const Word16 dtx_vad, @@ -2948,7 +2948,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2961,7 +2961,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q=q_postpred_cov_re move32(); } } @@ -2973,13 +2973,13 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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 ) ); // q_cov_uu_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 ) ); // q_cov_uu_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 ) ); // q_cov_uu_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 ) ); // q_cov_uu_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 ) ); // q_cov_uu_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 ) ); // q_cov_uu_re move32(); move32(); move32(); @@ -2989,7 +2989,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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] ); // q_cov_uu_re move32(); } } @@ -3004,20 +3004,20 @@ static void ivas_calc_p_coeffs_per_band_fx( 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 ) ); // q_cov_uu_re + re1[j] = L_add( re1[j], re ); // q_cov_uu_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; + 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 ) ); // q_cov_uu_re + recon_uu_re[0][0] = re2; // q_cov_uu_re 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][1], re1[1] ), q_C_re ) ); // q_cov_uu_re + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); // q_cov_uu_re move32(); - 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] ); // q_cov_uu_re move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) @@ -3032,8 +3032,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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 ) ); // q_cov_uu_re + re1[m] = L_add( re1[m], re ); // q_cov_uu_re move32(); } } @@ -3041,8 +3041,8 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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 ) ); // q_cov_uu_re + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); // q_cov_uu_re move32(); } } @@ -3053,20 +3053,20 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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] ); // q_cov_uu_re move32(); } } } } - p_norm_scaling = IVAS_P_NORM_SCALING_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; /*q31*/ move32(); test(); if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; /*q31*/ move32(); } @@ -3075,15 +3075,15 @@ static void ivas_calc_p_coeffs_per_band_fx( 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] ) ); // q_cov_uu_re } - factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); - factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); // q=q_postpred_cov_re + factor = L_max( factor, Mpy_32_32( p_norm_scaling, trace ) ); // q=q_postpred_cov_re Word16 factor_exp = 0; move16(); - factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); + factor = BASOP_Util_Divide3232_Scale( L_shl( 1, q_postpred_cov_re ), factor, &factor_exp ); // q=15-factor_exp tmp = sub( 15, factor_exp ); /* normalise Hermitian (except for rounding) cov_uu */ @@ -3094,7 +3094,7 @@ static void ivas_calc_p_coeffs_per_band_fx( 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 ), tmp ) ); + 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 ), tmp ) ); // q_cov_uu_re move32(); } ELSE @@ -3111,8 +3111,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { 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 ) ) ); + 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 ); // q=31-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 ) ) ); // q_cov_uu_re move32(); move32(); } @@ -3124,7 +3124,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { 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]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; // q_cov_uu_re move32(); } } @@ -3149,7 +3149,7 @@ static void ivas_calc_p_coeffs_per_band_fx( static void ivas_calc_c_coeffs_per_band_enc_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], // q_post_pred_cov_re Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3182,7 +3182,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3196,9 +3196,9 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { IF( EQ_16( i, j ) ) { - max_val = L_max( max_val, postpred_cov_re[i][j] ); + max_val = L_max( max_val, postpred_cov_re[i][j] ); // q_post_pred_cov_re } - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3208,10 +3208,10 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); // q_post_pred_cov_re } - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3224,12 +3224,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { q_tmp = 1; move16(); - IF( norm_l( max_val ) > 0 ) + if ( norm_l( max_val ) > 0 ) { q_tmp = 0; move16(); } - trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); // q_post_pred_cov_re - q_tmp FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) @@ -3241,7 +3241,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re - q_tmp move32(); } test(); @@ -3268,12 +3268,12 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( move64(); FOR( k = 0; k < sub( 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] ) ); + 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] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) { - W_max_val = W_abs( C_re_fx[i][j] ); + W_max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3284,7 +3284,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( { FOR( j = 0; j < sub( 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 ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3299,7 +3299,7 @@ static void ivas_calc_c_coeffs_per_band_enc_fx( 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], + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_post_pred_cov_re*/ Word16 q_post_pred_cov_re, const Word16 num_ch, const Word16 num_dmx, @@ -3331,7 +3331,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3340,7 +3340,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; // q_post_pred_cov_re move32(); } } @@ -3350,11 +3350,11 @@ static void ivas_calc_c_coeffs_per_band_fx( 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 = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re } - trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); + trace_cov_dd_re = Mpy_32_32( trace_cov_dd_re, 10737418 /* 0.005f in Q31*/ ); // q_post_pred_cov_re - abs_trace = L_abs( trace_cov_dd_re ); + abs_trace = L_abs( trace_cov_dd_re ); // q_post_pred_cov_re IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { @@ -3367,7 +3367,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { - cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); + cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); // q_post_pred_cov_re move32(); } test(); @@ -3394,12 +3394,12 @@ static void ivas_calc_c_coeffs_per_band_fx( move64(); FOR( k = 0; k < sub( 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] ) ); + 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] ) ); // q_post_pred_cov_re+q_cov_dd_re_inv move64(); } - IF( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) + if ( LT_64( max_val, W_abs( C_re_fx[i][j] ) ) ) { - max_val = W_abs( C_re_fx[i][j] ); + max_val = W_abs( C_re_fx[i][j] ); // q_post_pred_cov_re+q_cov_dd_re_inv } } } @@ -3410,7 +3410,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 0; j < sub( 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 ) ); + pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); // q_post_pred_cov_re+q_cov_dd_re_inv-tmp move32(); } } @@ -3435,10 +3435,10 @@ static void ivas_calc_c_coeffs_per_band_fx( void ivas_calc_c_p_coeffs_enc_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3448,8 +3448,12 @@ void ivas_calc_c_p_coeffs_enc_fx( const Word16 dyn_active_w_flag ) { Word16 i, j, q_postpred_cov_re; - Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) + { + set_zero_fx( postpred_cov_re[i], IVAS_SPAR_MAX_CH ); + } IF( NE_16( num_dmx, num_ch ) ) { ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); @@ -3494,10 +3498,10 @@ void ivas_calc_c_p_coeffs_enc_fx( void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, const Word16 i_ts, - Word32 ***mixer_mat, + Word32 ***mixer_mat, /*q_mixer_mat*/ Word16 q_mixer_mat, const Word16 num_ch, const Word16 num_dmx, @@ -3556,40 +3560,40 @@ void ivas_calc_c_p_coeffs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_det_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word64 *det_re, + Word64 *det_re, /*q_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 ); + re1 = W_mult0_32_32( in_re[1][1], in_re[2][2] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][1] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - 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 ) ); /* 3*q_in_re - 32 */ - *det_re = re1; + *det_re = re1; /* 3*q_in_re - 32 */ 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] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][2], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - 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 ) ); /* 3*q_in_re - 32 */ - *det_re = W_sub_nosat( *det_re, re1 ); + *det_re = W_sub_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); - 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] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); /* 2*q_in_re */ + re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ - 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 ) ); /* 3*q_in_re - 32 */ - *det_re = W_add_nosat( *det_re, re1 ); + *det_re = W_add_nosat( *det_re, re1 ); /* 3*q_in_re - 32 */ move64(); *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); @@ -3598,16 +3602,16 @@ static void ivas_calc_mat_det_fx( 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 ); + re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); /* 2*q_in_re */ + re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); /* 2*q_in_re */ + *det_re = W_sub_nosat( re1, re2 ); /* 2*q_in_re */ move64(); *q_det_re = add( q_in_re, q_in_re ); move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - *det_re = in_re[0][0]; + *det_re = in_re[0][0]; /*q_in_re*/ move32(); *q_det_re = q_in_re; move16(); @@ -3632,8 +3636,8 @@ static void ivas_calc_mat_det_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_get_mat_cofactor_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*qx*/ const Word16 row, const Word16 col ) { @@ -3649,7 +3653,7 @@ static void ivas_get_mat_cofactor_fx( test(); IF( NE_16( i, row ) && NE_16( j, col ) ) { - out_re[r][c] = in_re[i][j]; + out_re[r][c] = in_re[i][j]; /*qx*/ move64(); c = add( c, 1 ); } @@ -3677,10 +3681,10 @@ static void ivas_get_mat_cofactor_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_calc_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim, - Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 out_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_out_re*/ Word16 *q_out_re ) { Word64 det; @@ -3689,7 +3693,7 @@ static void ivas_calc_mat_inv_fx( IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { - det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); + det = W_mult0_32_32( in_re[0][0], in_re[0][0] ); /* 2*q_in_re */ /* assert to catch cases when input is singular matrix*/ assert( det > 0 ); @@ -3698,10 +3702,10 @@ static void ivas_calc_mat_inv_fx( // 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 ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, in_re[0][0], &q_tmp ); /*q=15-(q_tmp-(0-q_in_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_in_re ) ); - out_re[0][0] = one_by_det; + out_re[0][0] = one_by_det; /*q=q_one_by_det*/ move32(); *q_out_re = q_one_by_det; move16(); @@ -3715,22 +3719,22 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_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 ) ); + det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); /* 2*q_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][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); /*q_in_re+(15 - (q_tmp + q_det_re)) -15=>q_in_re-(q_tmp + q_det_re)*/ - out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); + out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); + out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); /*q_in_re-(q_tmp + q_det_re)*/ - out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); /*q_in_re-(q_tmp + q_det_re)*/ move32(); move32(); move32(); @@ -3752,7 +3756,7 @@ static void ivas_calc_mat_inv_fx( q_tmp = W_norm( det_re ); q_tmp = s_max( sub( 32, q_tmp ), 0 ); - det_re = W_shr( det_re, q_tmp ); + det_re = W_shr( det_re, q_tmp ); /*q_det_re-q_tmp*/ q_det_re = sub( q_det_re, q_tmp ); if ( det_re == 0 ) @@ -3761,7 +3765,7 @@ static void ivas_calc_mat_inv_fx( move64(); } - one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); + one_by_det = BASOP_Util_Divide3232_Scale( 1, W_extract_l( det_re ), &q_tmp ); /*15-(q_tmp-(0-q_det_re))*/ q_one_by_det = sub( 15, add( q_tmp, q_det_re ) ); FOR( i = 0; i < dim; i++ ) @@ -3771,9 +3775,9 @@ static void ivas_calc_mat_inv_fx( 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 ); + out_re[j][i] = Mpy_32_16_1( W_extract_h( W_tmp ), one_by_det ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); - out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); + out_re[j][i] = W_extract_l( W_mult0_32_32( out_re[j][i], sign ) ); /*q_W_tmp-32+q_one_by_det-15*/ move32(); IF( s_and( add( i, j ), 1 ) == 0 ) @@ -3811,7 +3815,7 @@ static void ivas_calc_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_is_mat_inv_fx( - Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], + Word32 in_re[MAX_MAT_DIM][MAX_MAT_DIM], /*q_in_re*/ Word16 q_in_re, const Word16 dim ) { @@ -3825,10 +3829,10 @@ static Word16 ivas_is_mat_inv_fx( tmp = W_norm( det_re ); tmp = s_max( sub( 32, tmp ), 0 ); - det_re = W_shr( det_re, tmp ); + det_re = W_shr( det_re, tmp ); /*q_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 ) ); /*2*q_det_re*/ if ( LE_64( det, IVAS_FIX_EPS ) ) { @@ -3850,12 +3854,12 @@ static Word16 ivas_is_mat_inv_fx( #ifdef IVAS_FLOAT_FIXED void ivas_compute_spar_params_enc_fx( - Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3866,7 +3870,7 @@ void ivas_compute_spar_params_enc_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale, + Word32 *pWscale, /*q_Wscale*/ Word16 *q_Wscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3892,22 +3896,22 @@ void ivas_compute_spar_params_enc_fx( move16(); } - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); /*q=15-(tmp_exp+(15-(15-q_Wscale)))=>15-(tmp_exp+q_Wscale)*/ q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].pred_re_fx[i] = L_shl( Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ), sub( Q28, tmp ) ); // Q28 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 = Q28; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_pred_re_fx = Q28; 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[b] ), q_Wscale[b] ) ); + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); /*q_mixer_mat*/ move32(); } } @@ -3928,12 +3932,12 @@ void ivas_compute_spar_params_enc_fx( void ivas_compute_spar_params_fx( - Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*q_cov_real*/ Word16 q_cov_real, - Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], /*q_dm_fv_re*/ Word16 *q_dm_fv_re, const Word16 i_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat*/ Word16 *q_mixer_mat, const Word16 start_band, const Word16 end_band, @@ -3944,7 +3948,7 @@ void ivas_compute_spar_params_fx( const Word16 active_w_vlbr, ivas_spar_md_com_cfg *hSparCfg, ivas_spar_md_t *hSparMd, - Word32 *pWscale_fx, + Word32 *pWscale_fx, /*q_pWscale*/ Word16 *q_pWscale, const Word16 from_dirac, const Word16 dyn_active_w_flag ) @@ -3963,23 +3967,23 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { Word16 tmp_exp, q_tmp, tmp; - Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale_fx[b], &tmp_exp ); /*15-(tmp_exp+q_pWscale[b])*/ q_tmp = sub( sub( 15, tmp_exp ), q_pWscale[b] ); tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); FOR( i = 0; i < sub( 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 ); + 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 ); // q=tmp move32(); IF( tmp < 0 ) { tmp = negate( tmp ); - 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 ) ); + 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 ) ); // q22 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 ) ); + 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 ) ); // q22 move32(); } } @@ -3989,7 +3993,7 @@ void ivas_compute_spar_params_fx( 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] ) ); + 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] ) ); /*q_mixer_mat*/ move32(); } } @@ -4007,11 +4011,11 @@ void ivas_compute_spar_params_fx( IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX - FOR( i = 0; i < sub( num_ch, ndm ); i++ ) + FOR( i = 0; i < ( num_ch - ndm ); i++ ) { FOR( Word16 j = 0; j < sub( ndm, 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 ) ); // q22 move32(); } } @@ -4033,10 +4037,10 @@ void ivas_compute_spar_params_fx( FOR( Word16 j = 0; j < sub( 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 ) ); // q22 move32(); } - hSparMd->band_coeffs[b + imult1616( i_ts, IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; + hSparMd->band_coeffs[b + ( i_ts * IVAS_MAX_NUM_BANDS )].q_P_re_fx = Q22; move16(); } } @@ -4052,9 +4056,9 @@ void ivas_compute_spar_params_fx( * *-----------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -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 }; +Word32 diff_norm_order1_table[4] = { 0, 805306368, 402653184, 268435456 }; // q28 +Word32 diff_norm_order2_table[6] = { 0, 1342177280, 671088640, 447392416, 335544320, 268435456 }; // q28 +Word32 diff_norm_order3_table[8] = { 0, 1879048192, 939524096, 626349376, 469762048, 375809632, 313174688, 268435456 }; // q28 #define EPSILON_FX_THR 70 #define ONE_BY_THREE_Q31 715827882 #define ONE_BY_FIVE_Q31 429496729 @@ -4064,7 +4068,7 @@ void ivas_get_spar_md_from_dirac_fx( Word32 ele_dirac_fx[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], // Q22 Word32 diffuseness_fx[IVAS_MAX_NUM_BANDS], // Q30 const Word16 n_ts, - Word32 ***mixer_mat_fx, + Word32 ***mixer_mat_fx, /*q_mixer_mat_fx*/ Word16 *q_mixer_mat_fx, ivas_spar_md_t *hSpar_md, ivas_spar_md_com_cfg *hSpar_md_cfg, @@ -4147,36 +4151,36 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - P_norm_fx[0] = L_add( 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_fx[0] = L_add( 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] ) ); // q25 move32(); } - 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, sub( 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, sub( foa_ch, ndm ) ) )] ); // q25 move32(); P_norm_fx[1] = 0; move32(); - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { - P_norm_fx[1] = L_add( 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_fx[1] = L_add( 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] ) ); // q25 move32(); } - 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, sub( 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 ) ) )] ); // q25 move32(); P_norm_fx[2] = 0; move32(); - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { - P_norm_fx[2] = L_add( 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_fx[2] = L_add( 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] ) ); // q25 move32(); } - 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, sub( 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 ) ) )] ); // q25 move32(); - FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) + FOR( i = 0; i < max( 0, ( foa_ch - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - 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_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] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4185,16 +4189,16 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[0], IVAS_FIX_EPS ) ); + P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[0], IVAS_FIX_EPS ) ); // q15 move32(); - 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 ); // q30 move32(); } } - FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) + FOR( ; i < max( 0, ( min( num_ch, hoa2_ch ) - ndm ) ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - 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_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] ); // q25 IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; @@ -4202,16 +4206,16 @@ 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] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[1], IVAS_FIX_EPS ) ); // q15 move32(); - 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 ); // q30 move32(); } } - FOR( ; i < sub( num_ch, ndm ); i++ ) + FOR( ; i < ( num_ch - ndm ); i++ ) { idx = sub( remix_order[i + ndm], ndm ); - 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_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] ); // q25 move32(); IF( P_dir_fact_fx[idx] == 0 ) { @@ -4220,9 +4224,9 @@ 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] = divide3232( P_dir_fact_fx[idx], L_max( P_norm_fx[2], IVAS_FIX_EPS ) ); // q15 move32(); - 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 ); // q30 move32(); } } @@ -4242,19 +4246,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][i_ts] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ); // q0 } IF( azi_dirac_fx[band][i_ts] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][i_ts] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4262,19 +4266,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][0] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ); // q0 } IF( azi_dirac_fx[band][0] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][0] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, response_avg_fx, order, Q30 ); } @@ -4284,19 +4288,19 @@ void ivas_get_spar_md_from_dirac_fx( { IF( ele_dirac_fx[band][block] < 0 ) { - elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); + elevation = negate( extract_l( L_shr( L_negate( ele_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); + elevation = extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ); // q0 } IF( azi_dirac_fx[band][block] < 0 ) { - azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); + azimuth = negate( extract_l( L_shr( L_negate( azi_dirac_fx[band][block] ), Q22 ) ) ); // q0 } ELSE { - azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); + azimuth = extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ); // q0 } ivas_dirac_dec_get_response_fx( azimuth, elevation, &( response_fx[block][0] ), order, Q30 ); } @@ -4316,9 +4320,9 @@ void ivas_get_spar_md_from_dirac_fx( move64(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); // q30 } - response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); + response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); // q30 move32(); } @@ -4329,13 +4333,13 @@ void ivas_get_spar_md_from_dirac_fx( move16(); FOR( ch = 1; ch < foa_ch; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4344,33 +4348,33 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q <= 0 ) { - norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); // q=31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = 1; ch < foa_ch; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { IF( response_avg_fx[ch] != 0 ) { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 move32(); } - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4380,12 +4384,12 @@ void ivas_get_spar_md_from_dirac_fx( move32(); FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4394,45 +4398,46 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); } } /*normalize 3rd order*/ + norm_fx = 0; FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); // q29 } norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); IF( norm_fx ) { - norm_fx = Sqrt32( norm_fx, &norm_q ); + norm_fx = Sqrt32( norm_fx, &norm_q ); // q=31-norm_q } ELSE { @@ -4441,32 +4446,32 @@ void ivas_get_spar_md_from_dirac_fx( } IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, negate( norm_q ) ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); // q31 norm_q = 0; move16(); } - norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); // q30 FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - response_avg_fx[ch] = response_avg_fx[ch]; - response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = response_avg_fx[ch]; // q30 + response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); // q15 + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); move32(); move32(); } ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { - response_avg_fx[ch] = ONE_IN_Q30; + response_avg_fx[ch] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { - response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); // q15 move32(); - response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); // q30 move32(); } } @@ -4475,13 +4480,13 @@ void ivas_get_spar_md_from_dirac_fx( FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) { - response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; + response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; // q30 move32(); } - en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30 - en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); + en_ratio_fac_fx = L_shl( L_sub( ONE_IN_Q30 - EPSILON_FX /* Guard to prevent overflow if diffuseness_fx is 0 */, diffuseness_fx[band] ), 1 ); // assuming q of dissusion 30=>q31 + en_ratio_fac_fx = L_max( en_ratio_fac_fx, 0 ); // q31 FOR( i = 0; i < num_ch; i++ ) { @@ -4491,48 +4496,48 @@ void ivas_get_spar_md_from_dirac_fx( { IF( i == 0 ) { - cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; + cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; // 1 q30 move32(); } ELSE { Word32 en_ratio_fac_sq = 0; move32(); - 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_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] ); // q30 move32(); IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) { - cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); + cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); // q30 move32(); test(); IF( ( GE_16( i, ndm ) ) && ( EQ_16( 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] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ) ); // q30 move32(); } ELSE { IF( LT_16( i, foa_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31 /*1 q31*/, en_ratio_fac_sq ), ONE_BY_THREE_Q31 /*1/3 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } ELSE { - en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); // q31 + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ); // q31 + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); // q30 move32(); } } @@ -4541,17 +4546,17 @@ void ivas_get_spar_md_from_dirac_fx( { IF( LT_16( i, foa_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 /*1/3 q31*/ ), 1 ) ); // q30 move32(); } ELSE IF( LT_16( i, hoa2_ch ) ) { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 /*1/5 q31*/ ), 1 ) ); // q30 move32(); } ELSE { - cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ) ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 /*1/7 q31*/ ), 1 ) ); // q30 move32(); } } @@ -4559,7 +4564,7 @@ void ivas_get_spar_md_from_dirac_fx( } ELSE { - cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + cov_real_dirac_fx[i][j][band] = L_shl( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); // q30 move32(); } } @@ -4570,7 +4575,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; + pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; // q30 move32(); } } @@ -4595,7 +4600,7 @@ void ivas_get_spar_md_from_dirac_fx( { FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); + mixer_mat_fx[i][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = L_shl( ppMixer_mat_fx[i][j][band], sub( *q_mixer_mat_fx, q_ppMixer_mat ) ); // q_mixer_mat_fx move32(); } } @@ -4614,7 +4619,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( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); + mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )] = Mpy_32_32( L_shl( mixer_mat_fx[0][j][band + ( i_ts * IVAS_MAX_NUM_BANDS )], 2 ), Wscale_d[band] ); // q_mixer_mat_fx move32(); } } @@ -4750,7 +4755,7 @@ void ivas_dirac_dec_get_response( * Input azimuth and elevation are expected in Q0 *------------------------------------------------------------------------*/ -Word32 local_result_table[91][9] = { +Word32 local_result_table[91][9] /*q30*/ = { { -1518500224, 0, @@ -5754,7 +5759,7 @@ Word32 local_result_table[91][9] = { } }; -Word32 local_result_table_2[91][9] = { +Word32 local_result_table_2[91][9] /*q30*/ = { { -1073741824, 0, @@ -6760,7 +6765,7 @@ Word32 local_result_table_2[91][9] = { void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, - Word32 *response_fx, + Word32 *response_fx, /*Q_out*/ const Word16 ambisonics_order, Word16 Q_out ) { @@ -6819,31 +6824,31 @@ void ivas_dirac_dec_get_response_fx( f_fx = 1; move16(); } - cos_1_fx = dirac_gains_trg_term_fx[az][0]; + cos_1_fx = dirac_gains_trg_term_fx[az][0]; // q31 move32(); - cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - sin_1_fx = dirac_gains_trg_term_fx[az][1]; + cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); // q31 + sin_1_fx = dirac_gains_trg_term_fx[az][1]; // q31 move32(); if ( EQ_32( f_fx, -1 ) ) { - sin_1_fx = L_negate( sin_1_fx ); + sin_1_fx = L_negate( sin_1_fx ); // q31 move32(); } - cos_az_fx[0] = cos_1_fx; + cos_az_fx[0] = cos_1_fx; // q31 move32(); - cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 ), 1 ); + cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 /*0.5 q31*/ ), 1 ); /*q31*/ move32(); - cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) ), 1 ); + cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) /* cos_az_fx[0]/2 q31*/ ), 1 ); /*q31*/ move32(); - sin_az_fx[0] = sin_1_fx; + sin_az_fx[0] = sin_1_fx; /*q31*/ move32(); - sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); + sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); /*q31*/ move32(); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 ) ), 2 ); + sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 /*1/4 q31*/ ) ), 2 ); /*q31*/ move32(); - response_fx[0] = L_shl_sat( 1, Q_out ); + response_fx[0] = L_shl_sat( 1, Q_out ); // Q_out move32(); FOR( l = 1; l <= ambisonics_order; l++ ) @@ -6855,7 +6860,7 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6870,11 +6875,11 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, m ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table[el][a]; + c_fx_better = local_result_table[el][a]; // q30 move32(); if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 } response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out move32(); @@ -6886,13 +6891,13 @@ void ivas_dirac_dec_get_response_fx( b = add( b_2, l ); a = dirac_gains_P_idx[b]; move16(); - c_fx_better = local_result_table_2[el][a]; + c_fx_better = local_result_table_2[el][a]; // q30 move32(); IF( EQ_16( ( l % 2 ), 1 ) ) { if ( EQ_16( e, -1 ) ) { - c_fx_better = L_negate( c_fx_better ); + c_fx_better = L_negate( c_fx_better ); // q30 move32(); } } @@ -7043,7 +7048,11 @@ void ivas_spar_set_bitrate_config( num_PR_bits_dirac_bands = max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands *= DIRAC_TO_SPAR_HBR_PRED_CHS; +#ifdef IVAS_FLOAT_FIXED + n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); +#else n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); +#endif n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; n_dec = n_input - n_dmx; bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx].q_lvls[quant_strat][0] ) ); @@ -7162,7 +7171,7 @@ void ivas_spar_set_bitrate_config_fx( } /* (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) */ - div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 /*1/FRAMES_PER_SEC Q31*/ ) ); /*31-31=>0*/ pSpar_md_cfg->tgt_bits_per_blk = sub( div1, 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( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); move16(); @@ -7186,8 +7195,8 @@ void ivas_spar_set_bitrate_config_fx( move16(); } - pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); - pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); + pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ + pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); /*Q0*/ 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 ); @@ -7220,8 +7229,8 @@ void ivas_spar_set_bitrate_config_fx( num_PR_bits_dirac_bands = 0; move16(); } - div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); - num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); + div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); /*15-temp*/ + num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); /*q0*/ 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 ); @@ -7238,12 +7247,12 @@ void ivas_spar_set_bitrate_config_fx( 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 ) ); + div1 = BASOP_Util_Divide3232_Scale( wc_coarse_strat, bands_bw, &temp ); // q=15-temp + wc_coarse_strat = shr( div1, sub( 15, temp ) ); // q0 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 ) ) + if ( LT_16( pSpar_md_cfg->max_bits_per_blk, wc_coarse_strat ) ) { assert( 0 ); } @@ -7402,7 +7411,7 @@ void ivas_spar_bitrate_dist_fx( move16(); FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 ) ); + core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); sum_core_act_bits = add( sum_core_act_bits, core_bits_act[i] ); @@ -7415,13 +7424,13 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); - core_bits_act[i] = add( core_bits_act[i], min( residual_bits, core_range_bits[i] ) ); + core_bits_act[i] = add( core_bits_act[i], s_min( residual_bits, core_range_bits[i] ) ); move16(); residual_bits = sub( residual_bits, core_range_bits[i] ); - IF( residual_bits <= 0 ) + if ( residual_bits <= 0 ) { BREAK; } @@ -7431,7 +7440,7 @@ void ivas_spar_bitrate_dist_fx( { FOR( i = 0; i < nchan_transport; i++ ) { - core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 ) ); + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 /*1/FRAMES_PER_SEC Q15*/ ) ); /*q0*/ move16(); } @@ -7439,11 +7448,11 @@ void ivas_spar_bitrate_dist_fx( FOR( i = 0; i < nchan_transport; i++ ) { - core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); + core_bits_act[nchan_transport - 1 - i] = sub( core_bits_act[nchan_transport - 1 - i], s_min( overflow_bits, core_range_bits[nchan_transport - 1 - i] ) ); move16(); overflow_bits = sub( overflow_bits, core_range_bits[nchan_transport - 1 - i] ); - IF( overflow_bits <= 0 ) + if ( overflow_bits <= 0 ) { BREAK; } @@ -7461,7 +7470,7 @@ void ivas_spar_bitrate_dist_fx( overflow_bits = sub( overflow_bits, overflow_bits_ch ); } - core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], max( 0, overflow_bits ) ); + core_bits_act[nchan_transport - 1] = sub( core_bits_act[nchan_transport - 1], s_max( 0, overflow_bits ) ); move16(); } } diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 0207e3e19..8b0bf766f 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -162,12 +162,12 @@ void ivas_quantise_real_values_enc_fx_varq( #ifdef IVAS_FLOAT_FIXED void ivas_quantise_real_values_fx( - const Word32 *values_fx, + const Word32 *values_fx, /*q28*/ const Word16 q_levels, - const Word32 min_value_fx, - const Word32 max_value_fx, + const Word32 min_value_fx, /*q28*/ + const Word32 max_value_fx, /*q28*/ Word16 *index, - Word32 *quant_fx, + Word32 *quant_fx, /*q28*/ const Word16 dim ) { Word16 i; @@ -186,18 +186,18 @@ void ivas_quantise_real_values_fx( ELSE IF( q_levels && NE_32( max_value_fx, min_value_fx ) ) { Word16 nor_q_level = norm_l( sub( q_levels, 1 ) ); - Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); - one_by_q_levels = L_shl( one_by_q_levels, 16 ); - q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); - Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); - one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); + Word32 one_by_q_levels = divide3232( L_shl( 1, ( nor_q_level ) ), L_shl( sub( q_levels, 1 ), ( nor_q_level ) ) ); // q15 + one_by_q_levels = L_shl( one_by_q_levels, 16 ); // q31 + q_step_fx = Mpy_32_32( L_sub( max_value_fx, min_value_fx ), one_by_q_levels ); // q28 + Word16 one_by_max_min = divide3232( ONE_IN_Q28, L_sub( max_value_fx, min_value_fx ) ); // q15 + one_by_q_step_fx = L_mult0( sub( q_levels, 1 ), one_by_max_min ); // q15 Word32 val_fx; FOR( i = 0; i < dim; i++ ) { - val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); - index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); + val_fx = L_max( min_value_fx, L_min( values_fx[i], max_value_fx ) ); // q28 + index[i] = extract_l( L_shr( Mpy_32_32( one_by_q_step_fx, val_fx ), 12 ) ); // q15+q28-q31-q12=>q0 move16(); - quant_fx[i] = imult3216( q_step_fx, index[i] ); + quant_fx[i] = imult3216( q_step_fx, index[i] ); // q28 move16(); } } @@ -205,7 +205,7 @@ void ivas_quantise_real_values_fx( { FOR( i = 0; i < dim; i++ ) { - quant_fx[i] = values_fx[i]; + quant_fx[i] = values_fx[i]; // q28 move32(); } } @@ -418,25 +418,25 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // 1 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; //-1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // 2 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; // Q28 + pSpar_md_com_cfg->quant_strat[i].C.min_fx = -ONE_IN_Q29; //-2 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; move16(); pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // 1 Q28 move32(); pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; // Q28 move32(); @@ -445,9 +445,9 @@ void ivas_spar_get_uniform_quant_strat_fx( move16(); pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; move16(); - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // 0.5 Q28 move32(); - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; // Q28 + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27; //-0.5 Q28 move32(); } } @@ -475,33 +475,33 @@ 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]; - Word32 one_by_q_lvl_PR_fx = one_by_q_level[s_max( sub( 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 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_C_fx = one_by_q_level[s_max( sub( 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 )]; /*q31*/ move32(); - Word32 one_by_q_lvl_P_r_fx = one_by_q_level[s_max( sub( 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 )]; /*q31*/ move32(); FOR( i = 0; i < nB; i++ ) { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); - trial1 = L_shl( 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] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.PR.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_PR_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); - Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); - trial2 = L_shl( 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] = extract_l( trial2 ); + Word32 trial2 = L_mult0( sub( qs.P_r.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] ); /*q0*/ + trial2 = L_shl( trial2, 16 ); /*q16*/ + trial2 = round_fx( Mpy_32_32( trial2, one_by_q_lvl_P_r_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = extract_l( trial2 ); /*q0*/ move16(); } FOR( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ ) { - Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); - trial1 = L_shl( 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] = extract_l( trial1 ); + Word32 trial1 = L_mult0( sub( qs.C.q_levels[0], 1 ), pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] ); /*q0*/ + trial1 = L_shl( trial1, 16 ); /*q16*/ + trial1 = round_fx( Mpy_32_32( trial1, one_by_q_lvl_C_fx ) ); /*q16+q31-31-16->0*/ + pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = extract_l( trial1 ); /*q0*/ move16(); } } @@ -593,11 +593,11 @@ void ivas_spar_quant_dtx_init( void ivas_spar_quant_dtx_init_fx( ivas_spar_md_t *spar_md, - Word32 *min_max ) + Word32 *min_max /*q28*/ ) { - spar_md->min_max_fx[0] = min_max[0]; + spar_md->min_max_fx[0] = min_max[0]; // q28 move32(); - spar_md->min_max_fx[1] = min_max[1]; + spar_md->min_max_fx[1] = min_max[1]; // q28 move32(); return; diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index bfe312557..fc0f2159d 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -216,7 +216,7 @@ typedef struct ivas_spar_md_t ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; int16_t num_bands; float min_max[2]; - Word32 min_max_fx[2]; + Word32 min_max_fx[2]; /*q28*/ int16_t dtx_vad; float en_ratio_slow[IVAS_MAX_NUM_BANDS]; Word32 en_ratio_slow_fx[IVAS_MAX_NUM_BANDS]; diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index b315083d8..34a4573c9 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,7 +43,6 @@ #include "ivas_prot_fx.h" #endif -#define INV_FPS 655 // Q15 /*------------------------------------------------------------------------- * stereo_dft_config() * @@ -331,23 +330,23 @@ Word16 stereo_dft_band_config_fx( move16(); nbands = 0; move16(); - WHILE( LT_16( band_limits[nbands], shr( NFFT, 1 ) ) ) + WHILE( LT_16( band_limits[nbands], NFFT / 2 ) ) { - nbands = add( nbands, 1 ); + nbands++; IF( band_res == 0 ) { assert( 0 && "stereo DFT: band config failed!\n" ); } ELSE IF( EQ_16( band_res, 1 ) ) { - IF( enc_dec == ENC ) + IF( enc_dec == ENC /*0*/ ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -357,12 +356,12 @@ Word16 stereo_dft_band_config_fx( { IF( enc_dec == ENC ) { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); // Q0 move16(); } ELSE { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); // Q0 move16(); } @@ -370,7 +369,7 @@ Word16 stereo_dft_band_config_fx( } } - band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ + band_limits[nbands] = NFFT / 2; /*Nyquist Freq*/ move16(); return ( nbands ); diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index deebbe7b8..aebde1530 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -81,12 +81,12 @@ Word32 ECSQ_dequantize_gain_fx( /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ - L_tmp = Mpy_32_16_1( L_prod, 27213 ); /* Q17 + Q13 >> 15 => Q15 */ + L_tmp = Mpy_32_16_1( L_prod, 27213 /*3.321928 q13*/ ); /* Q17 + Q13 >> 15 => Q15 */ - global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); + global_gain = BASOP_util_Pow2( L_tmp, tmp_e, &gg_e ); // 31-gg_e gg_e = sub( 16, gg_e ); - global_gain = L_shr( global_gain, gg_e ); + global_gain = L_shr( global_gain, gg_e ); // q15 return global_gain; } @@ -98,16 +98,17 @@ Word32 ECSQ_dequantize_gain_fx( * ---------------------------------------------------------------*/ void ECSQ_dequantize_vector_fx( - const Word16 *input, - const Word32 global_gain, + const Word16 *input, /*qx*/ + const Word32 global_gain, /*q15*/ const Word16 N, - Word32 *output ) + Word32 *output /*qx*/ +) { Word16 i; FOR( i = 0; i < N; ++i ) { - output[i] = Mpy_32_16_1( global_gain, input[i] ); + output[i] = Mpy_32_16_1( global_gain, input[i] ); /*qx+q15-15->qx*/ move32(); } diff --git a/lib_com/log2.c b/lib_com/log2.c index 9e1cb14ae..1fef489e9 100644 --- a/lib_com/log2.c +++ b/lib_com/log2.c @@ -51,8 +51,8 @@ * 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) Q15*/ + Word32 L_x /* (i) : input value (normalized) Qx*/ ) { Word16 i, a; @@ -72,7 +72,7 @@ Word16 Log2_norm_lc( /* (o) : Fractional part of Log2. (range: 0<=val return y; } -Word32 log10_fx( Word32 Linput ) +Word32 log10_fx( Word32 Linput ) /*o : Q23, i: 2Q13*/ { Word16 n1, frac, p1, p2, q1; Word32 Ltemp1, Ltemp2; @@ -119,7 +119,7 @@ Word32 log10_fx( Word32 Linput ) return ( L_shr( Ltemp1, 1 ) ); } -Word32 pow_10( Word32 x, Word16 *Q ) +Word32 pow_10( Word32 x, Word16 *Q ) /*o : Q15, i: Q26*/ { Word16 xl, xh, t1, t2, n; Word32 Ltemp1; @@ -209,7 +209,7 @@ Word32 pow_10( Word32 x, Word16 *Q ) return ( L_shl( Lacc, sub( n, count ) ) ); } -Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) */ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent*/ Word32 L_x, /* (i) : input value */ Word16 *exponent /* (o) : Integer part of Log2. (range: 0<=val<=30) */ ) diff --git a/lib_com/log2.h b/lib_com/log2.h index 9dc2b01ab..d87f677b5 100644 --- a/lib_com/log2.h +++ b/lib_com/log2.h @@ -26,14 +26,14 @@ * 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) Q15 */ + Word32 L_x /* (i) : input value (normalized) Qx */ ); -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 ); /*o : Q23, i: 2Q13*/ +Word32 pow_10( Word32 x, Word16 *Q ); /*o : Q15, i: Q26*/ +Word16 Log2_lc( /* (o) : Fractional part of Log2. (range: 0<=val<1) Q15 - exponent */ + 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 4505c749d..cef2a6fa3 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -49,12 +49,12 @@ *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ) { Word16 i, j, j1, j2; @@ -82,10 +82,10 @@ void logqnorm_ivas_fx( thren0_sqr = W_mult0_32_32( thre_fxn[0], thre_fxn[0] ); // Q28 threnL2_sqr = W_mult0_32_32( thre_fxn[L - 2], thre_fxn[L - 2] ); // Q28 l_shift = W_norm( thren0_sqr ); - thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); + thren0_sqr32 = W_extract_h( W_shl( thren0_sqr, l_shift ) ); // Q28 + l_shift - 32 thren0_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); l_shift = W_norm( threnL2_sqr ); - threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); + threnL2_sqr32 = W_extract_h( W_shl( threnL2_sqr, l_shift ) ); // Q28 + l_shift - 32 threnL2_sqr32_e = sub( 31, sub( add( Q28, l_shift ), 32 ) ); result1 = BASOP_Util_Add_Mant32Exp( thren0_sqr32, thren0_sqr32_e, L_negate( temp32_fx ), temp_e, &result1_e ); result2 = BASOP_Util_Add_Mant32Exp( threnL2_sqr32, threnL2_sqr32_e, L_negate( temp32_fx ), temp_e, &result2_e ); @@ -97,7 +97,7 @@ void logqnorm_ivas_fx( } ELSE IF( result2 > 0 ) { - *k_fx = L - 1; + *k_fx = sub( L, 1 ); move16(); } ELSE @@ -105,11 +105,11 @@ void logqnorm_ivas_fx( Word16 e = 0; move16(); power_fx = Sqrt32( ONE_IN_Q31, &e ); - power_fx = Sqrt32( temp32_fx, &temp_e ); + power_fx = Sqrt32( temp32_fx, &temp_e ); // Q31-temp_e // power_fx = L_shr( power_fx , Q14-(31-temp_e)); j1 = 0; move16(); - j2 = L - 1; + j2 = sub( L, 1 ); move16(); WHILE( GT_16( sub( j2, j1 ), 1 ) ) { @@ -164,21 +164,21 @@ void logqnorm_fx( FOR( i = 0; i < N; i++ ) { - coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); + coefs16[i] = extract_h( L_shl( L_x[i], coefs_shift ) ); // Qx + coefs_shift - 16 move16(); - L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); + L_temp = L_mac0( L_temp, coefs16[i], coefs16[i] ); // 2*(Qx + coefs_shift - 16) } - if ( GT_16( N, 1 ) ) + IF( GT_16( N, 1 ) ) { - Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); + Mpy_32_16_ss( L_temp, inv_tbl_fx[N], &L_temp, &lsb ); // 2*(Qx + coefs_shift - 16) } 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 ), L_shr( lsb, sub( 16, temp_shift ) ) ); + L_temp1 = L_add( L_shl( L_temp, temp_shift ), L_shr( lsb, sub( 16, temp_shift ) ) ); // 2*(Qx + coefs_shift - 16)+ temp_shift m = add( offset, m ); test(); @@ -219,8 +219,8 @@ void logqnorm_2_fx( 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 */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ const Word32 *thren /* i, Q10 : quantization thresholds */ ) { @@ -306,7 +306,7 @@ void calc_norm_ivas_fx( logqnorm_ivas_fx( &x_fx[band_start[band]], 12, &nrm, 40, band_len[band], thren_HQ_fx ); norm[band] = nrm; move16(); - normlg[band] = dicnlg2[nrm]; + normlg[band] = dicnlg2[nrm]; // Q0 move16(); } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 5efed0d03..ef47fa18d 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -27,7 +27,7 @@ void ivas_fine_gain_pred_fx( 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 *y, /* i/o: Quantized vector (int) Q0*/ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 core /* i : Core */ ) @@ -263,8 +263,8 @@ void get_max_pulses_fx( 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 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ) { Word16 i, k; @@ -309,7 +309,7 @@ void fine_gain_dec_fx( 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 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ) { Word16 band; diff --git a/lib_com/lpc_tools.c b/lib_com/lpc_tools.c index d3635d286..0c13ef7b1 100644 --- a/lib_com/lpc_tools.c +++ b/lib_com/lpc_tools.c @@ -195,10 +195,10 @@ 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 */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ) { @@ -232,10 +232,10 @@ Word16 lev_dur_fx( move32(); 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] ) ); // Q(q_a + q_r - 31) } - 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 ) ) ); // Q15 move16(); if ( GT_16( abs_s( rc_fx[i - 1] ), 32749 ) ) // 32749 = 0.99945 in Q15 @@ -248,14 +248,14 @@ Word16 lev_dur_fx( FOR( j = 1; j <= tmp16; 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] ) ); + 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] ) ); // Q(q_a) move32(); 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 ) ); // Q(q_a) move32(); err = L_add( err, L_shl( Mpy_32_16_1( s, rc_fx[i - 1] ), sub( 31, q_a ) ) ); // q_err - q_s diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index bfb5d8ed1..bec794e31 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -61,8 +61,8 @@ 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 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ @@ -165,12 +165,12 @@ void autocorr_fx( } #ifdef IVAS_FLOAT_FIXED void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ) @@ -185,7 +185,7 @@ void autocorr_fx_32( /* Windowing of signal */ FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -195,12 +195,12 @@ void autocorr_fx_32( tmp16 = shr( len, 1 ); FOR( i = 0; i < tmp16; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } FOR( ; i < len; i++ ) { - y[i] = mult_r( x[i], wind[sub( sub( len, i ), 1 )] ); + y[i] = mult_r( x[i], wind[len - i - 1] ); // Q(x) move16(); } } @@ -208,7 +208,7 @@ void autocorr_fx_32( { FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( x[i], wind[i] ); + y[i] = mult_r( x[i], wind[i] ); // Q(x) move16(); } } @@ -218,9 +218,9 @@ void autocorr_fx_32( L_sum = L_deposit_h( 16 ); /* sqrt(256), avoid overflow after rounding */ FOR( i = 0; i < len; i += 2 ) { - L_tmp = L_mult0( y[i], y[i] ); + L_tmp = L_mult0( y[i], y[i] ); // 2*Q(x) L_tmp = L_and( L_tmp, ~( 128 - 1 ) ); - L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); + L_tmp = L_mac0( L_tmp, y[i + 1], y[i + 1] ); // 2*Q(x) L_tmp = L_shr( L_tmp, 7 ); L_sum = L_add( L_sum, L_tmp ); } @@ -234,7 +234,7 @@ void autocorr_fx_32( fact = lshr( -32768, shift ); FOR( i = 0; i < len; i++ ) { - y[i] = mult_r( y[i], fact ); + y[i] = mult_r( y[i], fact ); // Q(x) move16(); } } @@ -245,10 +245,10 @@ void autocorr_fx_32( } /* Compute and normalize r[0] */ - L_sum = L_mac( 1, y[0], y[0] ); + L_sum = L_mac( 1, y[0], y[0] ); // 2*Q(x) 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] ); // 2*Q(x) } norm = norm_l( L_sum ); L_sum = L_shl( L_sum, norm ); @@ -258,14 +258,14 @@ void autocorr_fx_32( /* Compute r[1] to r[m] */ FOR( i = 1; i <= m; i++ ) { - L_sum = L_mult( y[0], y[i] ); + L_sum = L_mult( y[0], y[i] ); // 2*Q(x)+1 tmp16 = sub( len, i ); FOR( j = 1; j < tmp16; j++ ) { - L_sum = L_mac( L_sum, y[j], y[j + i] ); + L_sum = L_mac( L_sum, y[j], y[j + i] ); // 2*Q(x)+1 } - L_sum = L_shl( L_sum, norm ); + L_sum = L_shl( L_sum, norm ); // 2*Q(x)+1+norm r[i] = L_sum; move32(); } @@ -316,7 +316,7 @@ 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 /*Q31*/, Word16 denom_hi /*Qx -16*/, Word16 denom_lo /*Qx -1*/ ) { Word16 approx /*, hi, lo, n_hi , n_lo*/; Word32 L_32; @@ -364,12 +364,12 @@ static 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[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/ ) { 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[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word16 A[] /*Qx*/, Word32 epsP[] /*QR*/, const Word16 order, Word16 *mem /*Qx*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -794,12 +794,12 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 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[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/ ) { 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[] /*QR -16*/, const Word16 Rl[] /*QR -1*/, Word32 A[] /*QA*/, Word32 epsP[] /*QR*/, const Word16 order, Word32 *mem /*QA*/, Word16 k_max /*Q15*/ ) { Word16 i, j, k; Word16 hi, lo; @@ -1026,7 +1026,7 @@ 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 /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, Word16 m ) { Word16 i; Word32 Amax, Atmp[M + 2]; @@ -1204,7 +1204,7 @@ Word16 E_LPC_lsp_unweight( * Returns: * void */ -Word32 E_LPC_schur( Word32 r[], Word16 reflCoeff[], Word32 epsP[], const Word16 m ) +Word32 E_LPC_schur( Word32 r[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ) { Word16 i, j, temp16, mM1, mMi, s; Word32 g0[M], *g1, tmp32; @@ -1286,8 +1286,8 @@ extern const PWord16 w19N[127]; extern const PWord16 w18N[127]; extern void BASOP_getTables( const PWord16 **ptwiddle, const PWord16 **sin_twiddle, Word16 *psin_step, Word16 length ); static void spec2isf( - Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)*/ - Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)*/ + Word16 /*double*/ spec_r[], /* input spectrum real part (only left half + one zero)Q_spec*/ + Word16 /*double*/ spec_i[], /* input spectrum imag part (only left half+right halt with zeros)Q_spec*/ Word16 /*short*/ speclen, /* length of spectrum (only left half)*/ Word16 /*double*/ lsf[], /* locations of LSFs (buffer must be sufficiently long) */ /*15Q16*/ @@ -1354,7 +1354,7 @@ static 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 /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ) { Word32 RealFFT[128]; Word32 ImagFFT[128]; diff --git a/lib_com/lsf_dec_bfi_fx.c b/lib_com/lsf_dec_bfi_fx.c index b41fa9de9..6292630af 100644 --- a/lib_com/lsf_dec_bfi_fx.c +++ b/lib_com/lsf_dec_bfi_fx.c @@ -24,15 +24,15 @@ void lsf_dec_bfi( 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) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ 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 */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -140,11 +140,13 @@ void lsf_dec_bfi( ELSE { alpha = _ALPHA_VT_FX; /* rapid convergence to the CNG spectrum (long erasure, ONSETS) */ + move16(); } } ELSE { Word16 exp = 15; + move16(); alpha = Inv16( nbLostCmpt, &exp ); /*1.f/bfi_cnt;*/ alpha = shl( alpha, exp ); } @@ -254,7 +256,7 @@ return; } Word16 const *PlcGetLsfBase( - Word16 const lpcQuantization, + Word16 const lpcQuantization /*Q0*/, Word16 const narrowBand, Word32 const sr_core ) { diff --git a/lib_com/lsf_msvq_ma_fx.c b/lib_com/lsf_msvq_ma_fx.c index 409566ddc..6f8ea44c2 100644 --- a/lib_com/lsf_msvq_ma_fx.c +++ b/lib_com/lsf_msvq_ma_fx.c @@ -29,7 +29,7 @@ void midlsf_dec( const Word16 idx, /* i: codebook index */ Word16 qlsf[], /* o: decoded lsf coefficients (3Q12) */ const Word16 coder_type, - Word16 *mid_lsf_int, + Word16 *mid_lsf_int, /*Q0*/ const Word16 prev_bfi, const Word16 safety_net ) { @@ -138,8 +138,8 @@ void midlsf_dec( return; } Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ) { diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index 4d063b5b0..d051a54c7 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2088,12 +2088,12 @@ void dec_FDCNG_MSVQ_stage1( #ifdef IVAS_FLOAT_FIXED void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ) { Word16 col, segm_ind, j, i; @@ -2120,12 +2120,12 @@ void dec_FDCNG_MSVQ_stage1_fx( /* 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 */ + cbpW8 += imult1616( 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] = shl( cbpW8[col], dct_col_shift_tab[col] ); + dct_vec[col] = shl( cbpW8[col], dct_col_shift_tab[col] ); // Q0 move32(); /* LOGIC( 1 ) , SHIFT( 1 ); in BASOP: s_and(for W8->W16), shl() @@ -2138,7 +2138,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < cdk1_ivas_cols_per_segment[segm_ind]; i++ ) { - dct_vec_fx[i] = L_shl( dct_vec[i], norm ); + dct_vec_fx[i] = L_shl( dct_vec[i], norm ); // Q20 move32(); } @@ -2151,6 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2251,18 +2252,18 @@ void msvq_dec_float( #ifdef IVAS_FLOAT_FIXED void msvq_dec_fx( - const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) */ - 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 */ - const Word16 applyIDCT_flag, /* i : applyIDCT flag */ - const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis */ - Word32 *uq, /* o : quantized vector */ - Word16 *uq_ind, /* o : quantized vector (fixed point) */ - Word16 exp ) + const Word16 *const *cb, /* i : Codebook (indexed cb[*stages][levels][p]) Q: (Q_cb) */ + 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 */ + const Word16 applyIDCT_flag, /* i : applyIDCT flag */ + const Word32 *invTrfMatrix, /* i : matrix for IDCT synthesis Q31 */ + Word32 *uq, /* o : quantized vector */ + Word16 *uq_ind, /* o : quantized vector (fixed point) Q0 */ + Word16 Q_cb ) { Word16 i, n, maxn, start, k; Word16 j, max_size = 0; @@ -2327,7 +2328,7 @@ void msvq_dec_fx( { FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2339,7 +2340,7 @@ void msvq_dec_fx( dec_FDCNG_MSVQ_stage1_fx( Idx[0], N, invTrfMatrix, IDCT_T2_XX_24, uq, uq_ind ); /* IDCT_T2 N=24 used for all synthesis */ FOR( k = 0; k < N; k++ ) { - uq[k] = L_shr( uq[k], guard_bits ); + uq[k] = L_shr( uq[k], guard_bits ); // 20 - guard_bits move32(); } } @@ -2349,7 +2350,7 @@ void msvq_dec_fx( FOR( k = 0; k < n; k++ ) { - uq[add( start, k )] = L_add( uq[add( start, k )], L_lshl( cb[i][add( imult1616( Idx[i], maxn ), k )], sub( sub( 20, exp ), guard_bits ) ) ); + uq[start + k] = L_add( uq[start + k], L_lshl( cb[i][Idx[i] * maxn + k], sub( sub( 20, Q_cb ), guard_bits ) ) ); // 20 - guard_bits move32(); } } @@ -2359,7 +2360,8 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[add( start, j )] = add( uq_ind[add( start, j )], (Word16) ( mult( cb[i][add( imult1616( Idx[i], maxn ), j )], 20971 ), sub( add( 13, exp ), 15 ) ) ); + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + // 2 * 1.28 in Q13 -> 20971 move16(); } } @@ -2711,11 +2713,11 @@ void dctT2_N_apply_matrix( #ifdef IVAS_FLOAT_FIXED void dctT2_N_apply_matrix_fx( - const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain */ - Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain */ + const Word32 *input, /* i : input in fdcng or DCT(fdcng) domain Q20 */ + Word32 *output, /* o : output in DCT(fdcng) or fdcng ordomain Q20 */ const Word16 dct_dim, /* i : dct processing dim possibly truncated */ const Word16 fdcngvq_dim, /* i : fdcng domain length */ - const Word32 *matrix, /* i : IDCT matrix */ + const Word32 *matrix, /* i : IDCT matrix Q31 */ const Word16 matrix_row_dim, /* i : */ const DCTTYPE dcttype /* i : matrix operation type */ ) @@ -2773,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[imult1616( i, add( mat_step_row, mat_step_col_flag ) )] ); /* ptr indexing */ + 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++ ) @@ -2848,14 +2850,14 @@ void extend_dctN_input( #ifdef IVAS_FLOAT_FIXED void extend_dctN_input_fx( - const Word32 *input, /* i : input in fdcng domain Q */ - const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ - const Word16 in_dim, /* i : in_dim == N */ - Word32 *ext_sig, /* o : extended output in fdcng domain Q */ - const Word16 out_dim, /* i : output total dim */ - Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ - const Word16 n_cols, /* i : number of columns == DCT truncation length */ - const DCTTYPE dcttype /* i : matrix operation type */ + const Word32 *input, /* i : input in fdcng domain Q */ + const Word32 *dct_input, /* i : input in dctN(fdcng) domain Q */ + const Word16 in_dim, /* i : in_dim == N */ + Word32 *ext_sig, /* o : extended output in fdcng domain Q */ + const Word16 out_dim, /* i : output total dim */ + Word32 *matrix, /* i : idct synthesis matrix N rows, n_cols columns 31 */ + const Word16 n_cols, /* i : number of columns == DCT truncation length */ + const DCTTYPE dcttype /* i : matrix operation type */ ) { Word16 i, j, i_rev; @@ -2868,7 +2870,7 @@ void extend_dctN_input_fx( 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 */ - Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended */ + Copy32( input, ext_sig, in_dim ); /* copy initial part, i.e. only last/tail parts are extended q: Q */ set32_fx( &( ext_sig[in_dim] ), 0, sub( out_dim, in_dim ) ); i_rev = in_dim; /*ptr init*/ @@ -2980,10 +2982,10 @@ 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 */ + Word32 *inv_matrixFloatQ, /* i/o: RAM buffer Q31 */ + 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, tmp16; @@ -2994,14 +2996,14 @@ void create_IDCT_N_Matrix_fx( Word16 idx; Word32( *ptr )[FDCNG_VQ_DCT_MAXTRUNC] = (void *) inv_matrixFloatQ; /* fixed number of columns pointers, to simplifies adressing in ANSIC */ - absval_ptr = unique_idctT2_24coeffsQ16; + absval_ptr = unique_idctT2_24coeffsQ16; // Q16 idx_ptr = idctT2_24_compressed_idx; len = FDCNG_VQ_MAX_LEN; move16(); IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { - absval_ptr = unique_idctT2_21coeffsQ16; + absval_ptr = unique_idctT2_21coeffsQ16; // Q16 idx_ptr = idctT2_21_compressed_idx; len = N; move16(); @@ -3021,7 +3023,7 @@ void create_IDCT_N_Matrix_fx( FOR( c = 0; c < mat_cpy_size; c++ ) { idx = (Word16) ( idx_ptr[c] ); - W16_val = absval_ptr[abs( idx )]; + W16_val = absval_ptr[abs( idx )]; // Q16 move16(); IF( idx < 0 ) @@ -3048,8 +3050,8 @@ void create_IDCT_N_Matrix_fx( FOR( r = 0; r < tmp16; r_flip-- ) { #define WMC_TOOL_SKIP - ptr[r_flip][c] = ptr[r][c]; /* flipped */ - ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped */ + ptr[r_flip][c] = ptr[r][c]; /* flipped: Q31*/ + ptr[r_flip][c1] = L_negate( ptr[r][c1] ); /* flipped and sign swapped: Q31 */ MOVE( 2 ); MULT( 1 ); /* for negate */ #undef WMC_TOOL_SKIP diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index a28f58851..d0dcc289e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -1964,6 +1964,7 @@ ivas_error lsf_allocate_fx( bits1[n_stages] = bits_lvq; move16(); *stages1 = add( n_stages, 1 ); + move16(); } } ELSE @@ -2195,7 +2196,7 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(1+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( 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 */ @@ -2296,7 +2297,7 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, e ); /*Q(0+e)*/ - IF( L_frame == L_FRAME16k ) + IF( EQ_16( 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 */ @@ -2815,28 +2816,29 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* 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, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx,/* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ +) { Word16 i; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; @@ -2902,24 +2904,24 @@ void lsf_syn_mem_backup_fx( #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - 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 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - 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, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ) { Word16 i; @@ -2930,47 +2932,47 @@ void lsf_syn_mem_backup_ivas_fx( FOR( i = 0; i < M; i++ ) { - mem_AR[i] = st_fx->mem_AR_fx[i]; + mem_AR[i] = st_fx->mem_AR_fx[i]; // Q2.56 move16(); - mem_MA[i] = st_fx->mem_MA_fx[i]; + mem_MA[i] = st_fx->mem_MA_fx[i]; // Q2.56 move16(); - lsp_new_bck[i] = lsp_new[i]; + lsp_new_bck[i] = lsp_new[i]; // Q15 move16(); - lsp_mid_bck[i] = lsp_mid[i]; + lsp_mid_bck[i] = lsp_mid[i]; // Q15 move16(); } - *streaklimit = st_fx->streaklimit_fx; + *streaklimit = st_fx->streaklimit_fx; // Q15 move16(); *pstreaklen = st_fx->pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - Bin_E[i] = st_fx->Bin_E_fx[i]; + Bin_E[i] = st_fx->Bin_E_fx[i]; // Q_new + Q_SCALE - 2 move32(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; + Bin_E_old[i] = st_fx->Bin_E_old_fx[i]; // Q_new + Q_SCALE - 2 move32(); } /* back-up memories */ FOR( i = 0; i < M; i++ ) { - mem_syn_bck[i] = hLPDmem->mem_syn[i]; + mem_syn_bck[i] = hLPDmem->mem_syn[i]; // Q: ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } - *mem_w0_bck = hLPDmem->mem_w0; + *mem_w0_bck = hLPDmem->mem_w0; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); - *btilt_code_fx = hLPDmem->tilt_code; + *btilt_code_fx = hLPDmem->tilt_code; // Q15 move16(); - *gc_threshold_fx = hLPDmem->gc_threshold; + *gc_threshold_fx = hLPDmem->gc_threshold; // Q16 move16(); Copy( st_fx->clip_var_fx, clip_var_bck_fx, 6 ); *next_force_sf_bck_fx = st_fx->next_force_safety_net; @@ -3034,28 +3036,28 @@ 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: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3067,78 +3069,81 @@ void lsf_syn_mem_restore_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsf_new[i] = lsf_new_bck[i]; + lsf_new[i] = lsf_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } st_fx->mCb1_fx = mCb1; move16(); - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // ( 15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 + move16(); + move32(); Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; + move16(); return; } #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_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 *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 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - 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: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3150,47 +3155,47 @@ void lsf_syn_mem_restore_ivas_fx( FOR( i = 0; i < M; i++ ) { - st_fx->mem_AR_fx[i] = mem_AR[i]; + st_fx->mem_AR_fx[i] = mem_AR[i]; // 2.56 move16(); - st_fx->mem_MA_fx[i] = mem_MA[i]; + st_fx->mem_MA_fx[i] = mem_MA[i]; // 2.56 move16(); - lsp_new[i] = lsp_new_bck[i]; + lsp_new[i] = lsp_new_bck[i]; // Q15 move16(); - lsp_mid[i] = lsp_mid_bck[i]; + lsp_mid[i] = lsp_mid_bck[i]; // Q15 move16(); } - st_fx->streaklimit_fx = streaklimit; + st_fx->streaklimit_fx = streaklimit; // Q15 move16(); st_fx->pstreaklen = pstreaklen; move16(); FOR( i = 0; i < L_FFT; i++ ) { - st_fx->Bin_E_fx[i] = Bin_E[i]; + st_fx->Bin_E_fx[i] = Bin_E[i]; // Q_new + Q_SCALE - 2 move16(); } FOR( i = 0; i < ( L_FFT / 2 ); i++ ) { - st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; + st_fx->Bin_E_old_fx[i] = Bin_E_old[i]; // Q_new + Q_SCALE - 2 move32(); } /* restoring memories */ - hLPDmem->mem_w0 = mem_w0_bck; + hLPDmem->mem_w0 = mem_w0_bck; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); FOR( i = 0; i < M; i++ ) { - hLPDmem->mem_syn[i] = mem_syn_bck[i]; + hLPDmem->mem_syn[i] = mem_syn_bck[i]; // Q(15 - st_fx->hLPDmem->e_mem_syn ) move16(); } move16(); - hLPDmem->tilt_code = btilt_code_fx; + hLPDmem->tilt_code = btilt_code_fx; // Q15 move32(); - hLPDmem->gc_threshold = gc_threshold_fx; + hLPDmem->gc_threshold = gc_threshold_fx; // Q16 Copy( clip_var_bck_fx, st_fx->clip_var_fx, 6 ); st_fx->next_force_safety_net = next_force_sf_bck_fx; move16(); diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 70b919002..762dea2bd 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -535,7 +535,7 @@ static void spectautocorr_fx( * Here m = 51. *---------------------------------------------------------------------*/ - imid = ( N - 1 ) / 2; + imid = shr( sub( N, 1 ), 1 ); move16(); /*---------------------------------------------------------------------* @@ -569,7 +569,7 @@ static void spectautocorr_fx( FOR( i = 3; i < M; i += 2 ) { r[i] = L_deposit_l( 0 ); - r[i + 1] = -r[i - 1]; + r[i + 1] = L_negate( r[i - 1] ); move32(); move32(); } diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 4b8d785b4..42241bce1 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -534,7 +534,7 @@ void Interpolate_allpass_steep( void Interpolate_allpass_steep_32( const Word32 *in_fx, /* i : input array of size N Qx */ Word32 *mem_fx, /* i/o: memory Qx */ - const int16_t N, /* i : number of input samples */ + const int16_t N, /* i : number of input samples */ Word32 *out_fx /* o : output array of size 2*N Qx */ ) { @@ -545,46 +545,46 @@ void Interpolate_allpass_steep_32( /* upper allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[0], in_fx[k], AP2_STEEP_FX[0] ); // Qx move32(); - mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); + mem_fx[0] = Msub_32_16( in_fx[k], temp_fx[0], AP2_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[n], temp_fx[n - 1], AP2_STEEP_FX[n] ); // Qx move32(); - mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); + mem_fx[n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP2_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k + 1] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k + 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } /* lower allpass filter chain */ FOR( k = 0; k < N; k++ ) { - temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); + temp_fx[0] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP], in_fx[k], AP1_STEEP_FX[0] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); + mem_fx[ALLPASSSECTIONS_STEEP] = Msub_32_16( in_fx[k], temp_fx[0], AP1_STEEP_FX[0] ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); + temp_fx[n] = Madd_32_16( mem_fx[ALLPASSSECTIONS_STEEP + n], temp_fx[n - 1], AP1_STEEP_FX[n] ); // Qx move32(); - mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); + mem_fx[ALLPASSSECTIONS_STEEP + n] = Msub_32_16( temp_fx[n - 1], temp_fx[n], AP1_STEEP_FX[n] ); // Qx move32(); } - out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + out_fx[2 * k] = Madd_32_16( mem_fx[2 * ALLPASSSECTIONS_STEEP - 1], temp_fx[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); - mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); + mem_fx[2 * ALLPASSSECTIONS_STEEP - 1] = Msub_32_16( temp_fx[ALLPASSSECTIONS_STEEP - 2], out_fx[2 * k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ); // Qx move32(); } #else @@ -728,9 +728,9 @@ void Decimate_allpass_steep( #ifdef IVAS_FLOAT_FIXED void Decimate_allpass_steep_fx32( const Word32 *in, /* i : input array of size N Qx */ - Word32 *mem, /* i/o: memory Qx*/ - const Word16 N, /* i : number of input samples */ - Word32 *out /* o : output array of size N/2 Qx*/ + Word32 *mem, /* i/o: memory Qx */ + const Word16 N, /* i : number of input samples */ + Word32 *out /* o : output array of size N/2 Qx */ ) { Word16 n, k; @@ -739,74 +739,74 @@ void Decimate_allpass_steep_fx32( /* upper allpass filter chain */ FOR( k = 0; k < N / 2; k++ ) { - temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); + temp[0] = L_add( mem[0], Mpy_32_16_1( in[2 * k], AP1_STEEP_FX[0] ) ); // Qx move32(); - mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); + mem[0] = L_sub( in[2 * k], Mpy_32_16_1( temp[0], AP1_STEEP_FX[0] ) ); // Qx move32(); - temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); + temp[1] = L_add( mem[1], Mpy_32_16_1( temp[0], AP1_STEEP_FX[1] ) ); // Qx move32(); - mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); + mem[1] = L_sub( temp[0], Mpy_32_16_1( temp[1], AP1_STEEP_FX[1] ) ); // Qx move32(); - out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + out[k] = L_add( mem[ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( out[k], AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); } /* lower allpass filter chain */ - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( mem[2 * ALLPASSSECTIONS_STEEP], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( mem[2 * ALLPASSSECTIONS_STEEP], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + 1] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[0] = W_round48_L( W_mac_32_16( W_mult_32_16( out[0], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); FOR( k = 1; k < N / 2; k++ ) { - temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); + temp[0] = L_add( mem[ALLPASSSECTIONS_STEEP], Mpy_32_16_1( in[sub( shl( k, 1 ), 1 )], AP2_STEEP_FX[0] ) ); // Qx move32(); - mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); + mem[ALLPASSSECTIONS_STEEP] = L_sub( in[sub( shl( k, 1 ), 1 )], Mpy_32_16_1( temp[0], AP2_STEEP_FX[0] ) ); // Qx move32(); /* for better performance, unroll this loop */ FOR( n = 1; n < ALLPASSSECTIONS_STEEP - 1; n++ ) { - temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); + temp[n] = L_add( mem[ALLPASSSECTIONS_STEEP + n], Mpy_32_16_1( temp[n - 1], AP2_STEEP_FX[n] ) ); // Qx move32(); /*if ( fabs( temp[n] ) < 1e-12 ) { temp[n] = sign( temp[n] ) * 1e-12f; }*/ - mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); + mem[ALLPASSSECTIONS_STEEP + n] = L_sub( temp[n - 1], Mpy_32_16_1( temp[n], AP2_STEEP_FX[n] ) ); // Qx move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); - out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); + out[k] = W_round48_L( W_mac_32_16( W_mult_32_16( out[k], 16384 /*0.5 in Q15*/ ), temp[ALLPASSSECTIONS_STEEP - 1], 16384 /*0.5 in Q15*/ ) ); // Qx move32(); } @@ -900,57 +900,57 @@ void interpolate_3_over_2_allpass_32( Word32 out1_buff[L_FRAME32k * 3]; Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Q15 out1 = out1_buff; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vu[1] = L_add( mem[1], Mpy_32_16_1( ( Vu[0] - mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[3] = L_add( mem[2], Mpy_32_16_1( ( Vu[1] - mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vm[1] = L_add( mem[4], Mpy_32_16_1( ( Vm[0] - mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[6] = L_add( mem[5], Mpy_32_16_1( ( Vm[1] - mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add( mem[0], Mpy_32_16_1( ( input[i] - mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx + Q15 - Q15 -> Qx move32(); - Vl[1] = L_add( mem[7], Mpy_32_16_1( ( Vl[0] - mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[9] = L_add( mem[8], Mpy_32_16_1( ( Vl[1] - mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx + Q15 - Q15 -> Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -961,17 +961,19 @@ void interpolate_3_over_2_allpass_32( { mem_temp = out1_buff[2 * i]; move32(); - out[i] = L_add( Mpy_32_16_1( ( mem_temp + mem[10] ), 1550 ), Mpy_32_16_1( ( mem[11] + mem[14] ), -4965 ) ); - out[i] = L_add( out[i], Mpy_32_16_1( ( mem[12] + mem[13] ), 20125 ) ); - mem[10] = mem[11]; + out[i] = L_add( Mpy_32_16_1( L_add( mem_temp, mem[10] ), 1550 ), Mpy_32_16_1( L_add( mem[11], mem[14] ), -4965 ) ); // Qx + Q15 - Q15 -> Qx + // 0.0473147f in Q15 -> 1550, -0.151521f in Q15 -> -4965 + out[i] = L_add( out[i], Mpy_32_16_1( L_add( mem[12], mem[13] ), 20125 ) ); + // 0.614152f in Q15 -> 20125 + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem[13]; + mem[12] = mem[13]; // Qx move32(); - mem[13] = mem[14]; + mem[13] = mem[14]; // Qx move32(); - mem[14] = mem_temp; + mem[14] = mem_temp; // Qx move32(); } @@ -1127,67 +1129,67 @@ void interpolate_3_over_1_allpass( #ifdef IVAS_FLOAT_FIXED void interpolate_3_over_1_allpass_32( - const Word32 *input, /* i : input signal */ - const Word16 len, /* i : number of input samples */ - Word32 *out, /* o : output signal */ - Word32 *mem /* i/o: memory */ + const Word32 *input, /* i : input signal Qx */ + const Word16 len, /* i : number of input samples */ + Word32 *out, /* o : output signal */ + Word32 *mem /* i/o: memory */ ) { Word16 i, tmp16; Word32 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word32 *out1; Word32 mem_temp; - const Word16 *filt_coeff = allpass_poles_3_ov_2; + const Word16 *filt_coeff = allpass_poles_3_ov_2; // Qx out1 = &out[0]; FOR( i = 0; i < len; i++ ) { /* Upper branch */ - Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); + Vu[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[1] ), filt_coeff[0] ) ); // Qx move32(); - Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); + Vu[1] = L_add_sat( mem[1], Mpy_32_16_1( L_sub( Vu[0], mem[2] ), filt_coeff[1] ) ); // Qx move32(); - mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); + mem[3] = L_add_sat( mem[2], Mpy_32_16_1( L_sub( Vu[1], mem[3] ), filt_coeff[2] ) ); // Qx move32(); - mem[1] = Vu[0]; + mem[1] = Vu[0]; // Qx move32(); - mem[2] = Vu[1]; + mem[2] = Vu[1]; // Qx move32(); - *out1++ = mem[3]; + *out1++ = mem[3]; // Qx move32(); /* Middle branch */ - Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); + Vm[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[4] ), filt_coeff[3] ) ); // Qx move32(); - Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); + Vm[1] = L_add_sat( mem[4], Mpy_32_16_1( L_sub( Vm[0], mem[5] ), filt_coeff[4] ) ); // Qx move32(); - mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); + mem[6] = L_add_sat( mem[5], Mpy_32_16_1( L_sub( Vm[1], mem[6] ), filt_coeff[5] ) ); // Qx move32(); - mem[4] = Vm[0]; + mem[4] = Vm[0]; // Qx move32(); - mem[5] = Vm[1]; + mem[5] = Vm[1]; // Qx move32(); - *out1++ = mem[6]; + *out1++ = mem[6]; // Qx move32(); /* Lower branch */ - Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); + Vl[0] = L_add_sat( mem[0], Mpy_32_16_1( L_sub( input[i], mem[7] ), filt_coeff[6] ) ); // Qx move32(); - Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); + Vl[1] = L_add_sat( mem[7], Mpy_32_16_1( L_sub( Vl[0], mem[8] ), filt_coeff[7] ) ); // Qx move32(); - mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); + mem[9] = L_add_sat( mem[8], Mpy_32_16_1( L_sub( Vl[1], mem[9] ), filt_coeff[8] ) ); // Qx move32(); - mem[0] = input[i]; + mem[0] = input[i]; // Qx move32(); - mem[7] = Vl[0]; + mem[7] = Vl[0]; // Qx move32(); - mem[8] = Vl[1]; + mem[8] = Vl[1]; // Qx move32(); - *out1++ = mem[9]; + *out1++ = mem[9]; // Qx move32(); } @@ -1195,15 +1197,16 @@ void interpolate_3_over_1_allpass_32( tmp16 = imult1616( len, 3 ); FOR( i = 0; i < tmp16; i++ ) { - mem_temp = out[i]; + mem_temp = out[i]; // Qx move32(); - out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); + out[i] = L_sub_sat( Mpy_32_16_1( L_add_sat( mem[12], mem[11] ), 18768 ), Mpy_32_16_1( L_add_sat( mem_temp, mem[10] ), 2424 ) ); // Qx + // 0.572769 in Q15 -> 18768, 0.074005 in Q15 -> 2424 move32(); - mem[10] = mem[11]; + mem[10] = mem[11]; // Qx move32(); - mem[11] = mem[12]; + mem[11] = mem[12]; // Qx move32(); - mem[12] = mem_temp; + mem[12] = mem_temp; // Qx move32(); } diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 3cf2b645d..320682c6b 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -280,7 +280,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q test(); test(); test(); - if ( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) + IF( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { #ifdef BASOP_NOGLOB num_den = shl_o( num_den, 1, &Overflow ); @@ -378,6 +378,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ * Find the resampling configuration *-------------------------------------------------------------------*/ *Q_new_inp = 0; + move16(); /* check if fin and fout are the same */ IF( EQ_32( fin, fout ) ) { @@ -385,6 +386,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Copy( sigIn_fx, sigOut_fx, lg ); *mem_decim_size = 0; *Q_new_inp = 0; + move16(); + move16(); return lg; } ELSE @@ -450,6 +453,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ mem_len = shl( filt_len, 1 ); *mem_decim_size = mem_len; + move16(); 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; @@ -468,7 +472,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ 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 + sub( add( 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 */ @@ -487,11 +491,11 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ 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 + sub( add( 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 + sub( add( 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 */ @@ -505,7 +509,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ FOR( i = 0; i < plus_sample_in; i++ ) { - sigPtr = signal_fx + lg + mem_len + i; + sigPtr = signal_fx + add( add( lg, mem_len ), i ); move16(); /*+i*/ L_tmp = syn_kern_16( 0, A_fx, sigPtr ); #ifdef BASOP_NOGLOB @@ -518,7 +522,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ } mem_preemph_fx = signal_fx[mem_len + lg - LEN_WIN_SSS - 1]; move16(); - deemph_fx( signal_fx + mem_len + lg - LEN_WIN_SSS, mu_preemph_fx, LEN_WIN_SSS + plus_sample_in, &mem_preemph_fx ); + deemph_fx( signal_fx + sub( add( mem_len, lg ), LEN_WIN_SSS ), mu_preemph_fx, add( LEN_WIN_SSS, plus_sample_in ), &mem_preemph_fx ); } /* interpolation */ @@ -543,6 +547,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ #else sigOut_fx[i] = round_fx( Interpol_lc_fx( sigIn_ptr, cfg_ptr_fx->filter_fx, frac, fac_num, filt_len_tmp ) ); #endif + move16(); frac = add( frac, fracstep ); j = sub( fac_num, frac ); @@ -555,7 +560,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ /* rescaling */ test(); - IF( ( GT_16( fac_num, fac_den ) ) == ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) + IF( EQ_32( ( GT_16( fac_num, fac_den ) ), ( ( cfg_ptr_fx->flags_fx & RS_INV_FAC ) != 0 ) ) ) { IF( LT_16( fac_num, fac_den ) ) { @@ -568,6 +573,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_shl( L_mult( sigOut_fx[i], num_den ), 1 ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } ELSE @@ -590,6 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; + move16(); } } ELSE @@ -603,6 +611,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], num_den ); /*Q-1*/ move16(); *Q_new_inp = -2; + move16(); } } ELSE @@ -612,6 +621,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ { sigOut_fx[i] = round_fx( L_mac( L_deposit_h( sigOut_fx[i] ), sigOut_fx[i], num_den ) ); /*Q0*/ *Q_new_inp = -1; + move16(); + move16(); } } } @@ -623,6 +634,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ sigOut_fx[i] = mult_r( sigOut_fx[i], 16384 ); move16(); /*Q-1*/ *Q_new_inp = -2; + move16(); } } /* update the filter memory */ @@ -893,11 +905,11 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( LT_16( ctptr[10], 3 ) ) { - *sigOutptr++ = sigIn[add( i, 1 )]; + *sigOutptr++ = sigIn[i + 1]; move16(); } - FOR( k1 = ctptr[add( k, 1 )]; k1 < fk1; k1 += inc ) + FOR( k1 = ctptr[k + 1]; k1 < fk1; k1 += inc ) { cptr = &( cc[kk][0] ); uptr = &( cu[k1][0] ); @@ -912,7 +924,7 @@ Word16 modify_Fs_intcub3m_sup_fx( /* o : length of output if ( EQ_16( ctptr[10], 1 ) ) { - *sigOutptr = sigIn[add( i, 2 )]; + *sigOutptr = sigIn[i + 2]; move16(); } } @@ -1558,7 +1570,7 @@ void interpolate_3_over_1_allpass_fx( Word16 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */ Word16 *out1; Word16 mem_temp; - const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; + const Word16 *filt_coeff_fx = allpass_poles_3_ov_2; // Q15 out1 = &out_fx[0]; diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index 748f2f564..3ff688d7b 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -151,6 +151,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, MAX_NO_SCALES ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][0] = j; @@ -159,6 +160,7 @@ void init_lvq_fx( move16(); WHILE( ( LT_16( j, shl( MAX_NO_SCALES, 1 ) ) ) && ( no_lead_p_fx[i][j] > 0 ) ) { + test(); j++; } no_scales_p[i][1] = sub( j, MAX_NO_SCALES ); @@ -587,6 +589,7 @@ Word16 deindex_lvq_fx( /* 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 ); + move16(); } } IF( scales_mslvq[1] ) @@ -596,6 +599,7 @@ Word16 deindex_lvq_fx( 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 ); + move16(); } } } @@ -609,6 +613,7 @@ Word16 deindex_lvq_fx( 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 ); + move16(); } } IF( scales_mslvq[1] ) @@ -618,6 +623,7 @@ Word16 deindex_lvq_fx( 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 ); + move16(); } } } @@ -656,6 +662,7 @@ Word16 deindex_lvq_ivas_fx( } ELSE { + test(); IF( ( LT_16( mode, 6 ) ) || ( EQ_16( mode, 12 ) ) ) /* for NB */ { mode_glb = add( offset_lvq_modes_pred[mode], offset_in_lvq_mode_pred[mode][sub( no_bits, min_lat_bits_pred[mode] )] ); @@ -1002,6 +1009,7 @@ static void decode_leaders_fx( case 4: dim_loc = add( dim_loc, no_vals_ind[idx_lead][2] ); n_crt = no_vals_ind[idx_lead][2]; + move16(); 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 ); diff --git a/lib_com/nelp_fx.c b/lib_com/nelp_fx.c index a357b7455..b37d57093 100644 --- a/lib_com/nelp_fx.c +++ b/lib_com/nelp_fx.c @@ -127,7 +127,7 @@ Word16 dequantize_uvg_fx( 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 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB1[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } ELSE IF( EQ_16( i, 1 ) ) @@ -136,7 +136,7 @@ Word16 dequantize_uvg_fx( 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 */ + G[i * 5 + k] = round_fx( L_shl( L_mult( frac, UVG2CB2[iG2[i]][k] ), sub( exp, sc ) ) ); /* Q0 */ move16(); } } diff --git a/lib_com/parameter_bitmaping.c b/lib_com/parameter_bitmaping.c index ff7a9c5bd..50cf4886f 100644 --- a/lib_com/parameter_bitmaping.c +++ b/lib_com/parameter_bitmaping.c @@ -214,6 +214,7 @@ void GetParameters_fx( pSubStruct = param->GetParamValue( pParameter, index, &value ); #undef WMC_TOOL_SKIP /* If a function for encoding/decoding value is defined than it should take care of 0 */ + test(); IF( param->fZeroAllowed || ( param->EncodeValue != NULL ) ) { *( *pStream )++ = value; @@ -236,6 +237,8 @@ void GetParameters_fx( } move16(); #undef WMC_TOOL_SKIP + + test(); IF( ( param->pSubParamBitMap != NULL ) && ( value > 0 ) ) { GetParameters_fx( param->pSubParamBitMap, value, ( pSubStruct != NULL ) ? pSubStruct : pParameter, pStream, pnSize, pnBits ); diff --git a/lib_com/prot.h b/lib_com/prot.h index f895ef5f2..1f54c2b1b 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7818,13 +7818,13 @@ void tcx_arith_scale_envelope_ivas( ); void tcx_arith_render_envelope_ivas( - const Word16 A_ind[], /* i : LPC coefficients of signal envelope */ - const Word16 L_frame, /* i : number of spectral lines */ - const Word16 L_spec, /* i : length of the coded spectrum */ - 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 Q12*/ + const Word16 L_frame, /* i : number of spectral lines Q0*/ + const Word16 L_spec, /* i : length of the coded spectrum Q0*/ + const Word16 preemph_fac, /* i : pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i : A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i : A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o : shaped signal envelope Q16*/ ); int16_t ari_encode_14bits_range( diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index d615e511b..de27c37c2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -449,13 +449,13 @@ void logqnorm_fx( ); void logqnorm_2_fx( - const Word32 *env_fl, /* o : index */ + 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, - Word16 *normqlg2, - const Word32 *thren /* i : quantization thresholds */ + Word16 *ynrm, /* o : norm indices Q0*/ + Word16 *normqlg2, /* o : quantized norm values Q0*/ + const Word32 *thren /* i, Q10 : quantization thresholds */ ); void calc_norm_fx( @@ -470,21 +470,21 @@ void calc_norm_fx( ); #ifdef IVAS_FLOAT_FIXED void calc_norm_ivas_fx( - const Word32 *x_fx, /* i : Input vector. */ - Word16 *norm, /* o : Quantization indices for norms */ - Word16 *normlg, /* o : Quantized norms in log2 */ + const Word32 *x_fx, /* i : Input vector.(Qin) */ + 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 */ const Word16 num_bands, /* i : Number of bands */ const Word16 *band_len, /* i : Length of bands */ const Word16 *band_start /* i : Start of bands */ ); void logqnorm_ivas_fx( - const Word32 *x_fx, /* i : coefficient vector */ + const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ - Word16 *k_fx, /* o : index */ + Word16 *k_fx, /* o : index (Q0)*/ const Word16 L, /* i : codebook length */ const Word16 N, /* i : sub-vector size */ - const Word32 *thre_fxn /* i : quantization thresholds */ + const Word32 *thre_fxn /* i : quantization thresholds Q14*/ ); #endif /*========================================================================================================/ @@ -764,7 +764,8 @@ Word16 xsp_to_xsf( Word16 lsp ); Word16 xsf_to_xsp( - Word16 lsf ); + Word16 lsf /* Q2.56 */ +); void lsp_convolve_fx( Word32 x, Word32 *p1, Word32 *p2, Word16 len ); Word32 poscos_fx( Word16 w ); @@ -849,49 +850,50 @@ Word16 tcxlpc_get_cdk( ); 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: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* o: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model Q15 */ + Word16 *mem_MA, /* i: quantizer memory for MA model Q15 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* i: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 mCb1, /* i: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #ifdef IVAS_FLOAT_FIXED void lsf_syn_mem_restore_ivas_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 *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 *lsp_mid_bck, /* i: mid-frame LSP vector - backup */ - 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: Q15 */ + Word32 gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 next_force_sf_bck_fx, /* i: */ + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 clip_var, /* i: pitch clipping state var Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* i: synthesis filter memory Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 mem_w0_bck, /* i: memory of the weighting filter Q(15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 streaklimit, /* i:LSF quantizer Q15 */ + Word16 pstreaklen /* i:LSF quantizer */ ); #endif @@ -1091,9 +1093,9 @@ 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 */ + Word16 r_h[], /* o : Autocorrelations (msb) Q15(Q_r -16) */ + Word16 r_l[], /* o : Autocorrelations (lsb) Q(r)-1 */ + Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ const Word16 *wind, /* i : Window used */ Word16 rev_flag, @@ -1101,12 +1103,12 @@ void autocorr_fx( ); void autocorr_fx_32( - const Word16 x[], /* i : Input signal */ + const Word16 x[], /* i : Input signal Q(q_x) */ const Word16 m, /* i : LPC order Q0 */ - Word32 r[], /* o : Autocorrelations (msb) */ + Word32 r[], /* o : Autocorrelations Q_r */ Word16 *Q_r, /* o : normalisation shift of r Q0 */ const Word16 len, /* i : Frame lenght */ - const Word16 *wind, /* i : Window used */ + const Word16 *wind, /* i : Window used Q15 */ Word16 rev_flag, const Word16 sym_flag /* i : symmetric window flag */ ); @@ -1121,29 +1123,29 @@ Word16 E_LPC_lev_dur_fx( const Word16 Rh[], const Word16 Rl[], Word32 A[], Word3 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 */ + Word32 *a_fx, /* o : LP coefficients (a[0] = 1.0) Q(q_a)*/ + const Word32 *r_fx, /* i : vector of autocorrelations Q(q_r)*/ const Word16 m, /* i : order of LP filter */ - Word32 epsP[], /* o : prediction error energy */ + Word32 epsP[], /* o : prediction error energy Q(q_r)*/ Word16 q_a, Word16 q_r ); -void E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma, Word16 m ); +void E_LPC_a_add_tilt( const Word16 *a /*Qa*/, Word16 *ap /*Qa*/, Word16 gamma /*Q15*/, 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 lsp_w[], /* (I): weighted xSP Q15 */ + Word16 lsp_uw[], /* (O): unweighted xSP Q15 */ + Word16 lsf_uw[], /* (O): unweighted LSF Q1*1.28 */ + Word16 inv_gamma, /* (I): inverse weighting factor Q14 */ + Word16 lpcorder /* (I): prediction order Q0 */ ); -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[] /*Qr*/, Word16 reflCoeff[] /*Q15*/, Word32 epsP[] /*Qr*/, const Word16 m ); +void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/, const Word16 *old_lsf /*15Q16*/, Word16 lpcOrder, Word8 lpcRep /*Q0*/ ); /*========================================================================================================/ @@ -4852,15 +4854,15 @@ void get_max_pulses_fx( 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 *inp_vector, /* i/o: Encoded shape vectors (int)Q0*/ + Word16 *maxpulse /* o : Maximum pulse height per band Q0*/ ); 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 */ + Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ); // fine_gain_bits_fx.c @@ -4959,15 +4961,15 @@ void lsf_dec_bfi( 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) */ + Word16 stab_fac, /*!< i : ISF stability factor (shifted right by 1) Q15*/ 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 */ + Word16 *lsf_cng, /* Q2.56 */ + Word16 *old_lsf_q_cng, /* o : old quantized ISFs for background noise Q2.56*/ const Word16 Last_GSC_pit_band_idx, const Word16 Opt_AMR_WB, /* i : IO flag */ const Word8 tcxonly, @@ -5736,13 +5738,13 @@ void tcx_arith_scale_envelope( ); 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 Q12*/ + const Word16 L_frame, /* i: number of spectral lines Q0*/ + const Word16 L_spec, /* Q0 */ + const Word16 preemph_fac, /* i: pre-emphasis factor Q15*/ + const Word16 gamma_w, /* i: A_ind -> weighted envelope factor Q15*/ + const Word16 gamma_uw, /* i: A_ind -> non-weighted envelope factor Q14*/ + Word32 env[] /* o: shaped signal envelope Q16*/ ); @@ -8667,8 +8669,8 @@ void midlsf_dec( const Word16 safety_net ); Word16 lsf_ind_is_active( - const Word16 lsf_q_ind[], - const Word16 means[], + const Word16 lsf_q_ind[], /*(14Q1*1.28)*/ + const Word16 means[], /*(14Q1*1.28)*/ const Word16 narrowband, const Word16 cdk ); @@ -9652,10 +9654,10 @@ void generate_masking_noise_dirac_ivas_fx( // 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 Qx */ + 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( @@ -10431,12 +10433,12 @@ void msvq_dec_fx( Word16 exp ); void dec_FDCNG_MSVQ_stage1_fx( - Word16 j_full, /* i : index full range */ - Word16 n, /* i : dimension to generate */ - const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis */ - const DCTTYPE idcttype, /* i : specify which IDCT */ - Word32 *uq, /* o : synthesized stage1 vector */ - Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ + Word16 j_full, /* i : index full range */ + Word16 n, /* i : dimension to generate */ + const Word32 *invTrfMatrix, /* i : IDCT matrix for synthesis Q31 */ + const DCTTYPE idcttype, /* i : specify which IDCT */ + Word32 *uq, /* o : synthesized stage1 vector Q20 */ + Word16 *uq_ind /* o : synthesized stage1 vector in BASOP */ ); void dctT2_N_apply_matrix_fx( @@ -10797,24 +10799,24 @@ Word16 ari_decode_14bits_sign_ivas( Tastat *s ); void lsf_syn_mem_backup_ivas_fx( - Encoder_State *st_fx, /* i: state structure */ - Word16 *btilt_code_fx, /* i: tilt code */ - Word32 *gc_threshold_fx, /* i: */ - Word16 *clip_var_bck_fx, /* o: */ - Word16 *next_force_sf_bck_fx, /* o: */ - - Word16 *lsp_new, /* i: LSP vector to quantize */ - 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 *lsp_mid_bck, /* o: mid-frame LSP vector - backup */ - 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, + Encoder_State *st_fx, /* i: state structure */ + Word16 *btilt_code_fx, /* i: tilt code Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* o: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* o: */ + + Word16 *lsp_new, /* i: LSP vector to quantize Q15 */ + Word16 *lsp_mid, /* i: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* o: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *mem_MA, /* o: quantizer memory for AR model Q(2.56) */ + Word16 *lsp_new_bck, /* o: LSP vector to quantize- backup Q15 */ + Word16 *lsp_mid_bck, /* o: mid-frame LSP vector - backup Q15 */ + Word32 *Bin_E, /* o: FFT Bin energy 128 *2 sets Q_new + Q_SCALE - 2 */ + Word32 *Bin_E_old, /* o: FFT Bin energy 128 sets Q_new + Q_SCALE - 2 */ + Word16 *mem_syn_bck, /* o: synthesis filter memory ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *mem_w0_bck, /* o: memory of the weighting filter ( 15 - st_fx->hLPDmem->e_mem_syn ) */ + Word16 *streaklimit, /* Q15 */ Word16 *pstreaklen ); ivas_error config_acelp1_IVAS( diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 51c2c4643..ae5f0c2b1 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -2800,7 +2800,7 @@ void perform_noise_estimation_dec_ivas_fx( } ELSE { - Word16 tmp = s_max( sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); + Word16 tmp = s_max( sub( hFdCngDec->msPeriodog_exp, getScaleFactor32( msPeriodog, npart ) ), sub( hFdCngDec->msNoiseEst_exp, getScaleFactor32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ) ) ) ); Copy_Scale_sig32( msPeriodog, msNoiseEst, npart, sub( hFdCngDec->msPeriodog_exp, tmp ) ); scale_sig32( &msNoiseEst[npart], sub( NPART_SHAPING, npart ), sub( hFdCngDec->msNoiseEst_exp, tmp ) ); hFdCngDec->msNoiseEst_exp = tmp; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index de8d19e32..c31727f29 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -938,7 +938,7 @@ void ivas_hq_core_dec_fx( // 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 ); /* Q0 */ + mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); mdctWindowLengthFB = extract_l( L_shr( L_mult0( temp, mdctWindowLength ), sub( 15, temp_e ) ) ); /* Q0 */ diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index fc2bef83c..633675002 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -332,7 +332,7 @@ void init_coder_ace_plus( int16_t L_subfr; /* Bitrate */ - st->tcxonly = getTcxonly_ivas( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); + st->tcxonly = getTcxonly_ivas_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); /* Core Sampling Rate */ st->sr_core = getCoreSamplerateMode2_flt( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 89ae59101..46fc42291 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -839,7 +839,7 @@ ivas_error ivas_cpe_enc( { int32_t internal_Fs; - internal_Fs = getTcxonly_ivas( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); + internal_Fs = getTcxonly_ivas_fx( IVAS_CPE_MDCT, sts[0]->bits_frame_nominal * FRAMES_PER_SEC, 0, sts[0]->is_ism_format ) == 0 ? INT_FS_16k : max( INT_FS_16k, sts[0]->sr_core ); /* iDFT at input sampling rate */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 454b2305f..2ad739323 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,7 +104,11 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#ifdef IVAS_FLOAT_FIXED + nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#else nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -1381,7 +1385,7 @@ static ivas_error ivas_spar_enc_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS Word16 mixer_q = 31; Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); for ( i = 0; i < num_channels; i++ ) { for ( j = 0; j < num_channels; j++ ) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 1bfa16eaf..b2413c928 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -164,7 +164,11 @@ ivas_error ivas_spar_md_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } +#ifdef IVAS_FLOAT_FIXED + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); +#else num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); +#endif // IVAS_FLOAT_FIXED if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) { -- GitLab From 0370eaa3a62bf29444a14aeb896f44203cdd3157 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:42:47 +0530 Subject: [PATCH 34/39] Clang formatting changes --- lib_com/lsf_tools.c | 10 ++++----- lib_com/lsf_tools_fx.c | 46 +++++++++++++++++++++--------------------- lib_com/modif_fs.c | 2 +- lib_com/modif_fs_fx.c | 2 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib_com/lsf_tools.c b/lib_com/lsf_tools.c index d051a54c7..b2be1b043 100644 --- a/lib_com/lsf_tools.c +++ b/lib_com/lsf_tools.c @@ -2119,8 +2119,8 @@ void dec_FDCNG_MSVQ_stage1_fx( /* Word8 column variable Qx storage*/ - cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ - cbpW8 += imult1616( j, cdk1_ivas_cols_per_segment[segm_ind] ); /* adaptive ptr init */ + cbpW8 = cdk_37bits_ivas_stage1_W8Qx_dct_sections[segm_ind]; /* Word8 storage fixed ptr_init */ + cbpW8 += imult1616( 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++ ) @@ -2151,7 +2151,7 @@ void dec_FDCNG_MSVQ_stage1_fx( FOR( i = 0; i < n; i++ ) { idct_vec_fx[i] = Mpy_32_32( idct_vec_fx[i], 56410112 ); /* norm + 31 - 31 = norm*/ - // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 + // fdcng_dct_scaleF[1] -> 0.420288085937500f / 16.0f -> in Q31 -> 56410112 move32(); } /* fdcng_dct_scaleF[1] --> 0.0625-->scale down from search Q4 domain to Q0 , @@ -2360,7 +2360,7 @@ void msvq_dec_fx( { FOR( j = 0; j < n; ++j ) { - uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 + uq_ind[start + j] = add( uq_ind[start + j], shl( mult( cb[i][Idx[i] * maxn + j], 20971 ), sub( add( 13, Q_cb ), 15 ) ) ); // Q0 // 2 * 1.28 in Q13 -> 20971 move16(); } @@ -2775,7 +2775,7 @@ void dctT2_N_apply_matrix_fx( /* +i(DCT) or +i*maxTrunc(IDCT) */ #define WMC_TOOL_SKIP - pt_A = &( matrix[i * ( mat_step_row + mat_step_col_flag ) ] ); /* ptr indexing */ + 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++ ) diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index d0dcc289e..d3694637e 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -2816,28 +2816,28 @@ Word16 qlsf_ARSN_tcvq_Dec_16k_fx( /*=======================================================================*/ void lsf_syn_mem_backup_fx( - Encoder_State *st_fx, /* o: state structure */ - Word16 *btilt_code_fx, /* i: Q15 */ - Word32 *gc_threshold_fx, /* i: Q16 */ - Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ - Word16 *next_force_sf_bck_fx,/* i: */ - - Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ - Word16 *lsf_new, /* i: quantized LSF vector Q15 */ - Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ - Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ - Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ - Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ - Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ - Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ - Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ - Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ - Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ - Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ - Word16 *mem_syn_bck, /* i: synthesis filter memory q */ - Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ - Word16 *streaklimit, /* i:LSF quantizer Q15 */ - Word16 *pstreaklen /* i:LSF quantizer */ + Encoder_State *st_fx, /* o: state structure */ + Word16 *btilt_code_fx, /* i: Q15 */ + Word32 *gc_threshold_fx, /* i: Q16 */ + Word16 *clip_var_bck_fx, /* i: Q(2.56), Q14, Q7, Q0, Q14, Q14 */ + Word16 *next_force_sf_bck_fx, /* i: */ + + Word16 *lsp_new, /* o: LSP vector to quantize Q15 */ + Word16 *lsf_new, /* i: quantized LSF vector Q15 */ + Word16 *lsp_mid, /* o: mid-frame LSP vector Q15 */ + Word16 *clip_var, /* i: pitch clipping state var Q(2.56) */ + Word16 *mem_AR, /* i: quantizer memory for AR model 2.56 */ + Word16 *mem_MA, /* i: quantizer memory for MA model 2.56 */ + Word16 *lsp_new_bck, /* i: LSP vector to quantize- backup Q15 */ + Word16 *lsf_new_bck, /* o: quantized LSF vector - backup Q15 */ + Word16 *lsp_mid_bck, /* i: mid-frame LSP vector - backup Q15 */ + Word16 *mCb1, /* o: counter for stationary frame after a transition frame */ + Word32 *Bin_E, /* i: FFT Bin energy 128 *2 sets q_bin */ + Word32 *Bin_E_old, /* i: FFT Bin energy 128 sets q_bin */ + Word16 *mem_syn_bck, /* i: synthesis filter memory q */ + Word16 *mem_w0_bck, /* i: memory of the weighting filter q */ + Word16 *streaklimit, /* i:LSF quantizer Q15 */ + Word16 *pstreaklen /* i:LSF quantizer */ ) { Word16 i; @@ -3113,7 +3113,7 @@ void lsf_syn_mem_restore_fx( move16(); move32(); move16(); - hLPDmem->tilt_code = btilt_code_fx; // Q15 + hLPDmem->tilt_code = btilt_code_fx; // Q15 hLPDmem->gc_threshold = gc_threshold_fx; // Q16 move16(); move32(); diff --git a/lib_com/modif_fs.c b/lib_com/modif_fs.c index 42241bce1..5bc57cc4b 100644 --- a/lib_com/modif_fs.c +++ b/lib_com/modif_fs.c @@ -774,7 +774,7 @@ void Decimate_allpass_steep_fx32( move32(); } - temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); //Qx + temp[ALLPASSSECTIONS_STEEP - 1] = L_add( mem[2 * ALLPASSSECTIONS_STEEP - 1], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 2], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx move32(); mem[2 * ALLPASSSECTIONS_STEEP - 1] = L_sub( temp[ALLPASSSECTIONS_STEEP - 2], Mpy_32_16_1( temp[ALLPASSSECTIONS_STEEP - 1], AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1] ) ); // Qx diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index 320682c6b..b53bb9d1c 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -597,7 +597,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ move16(); } *Q_new_inp = -1; - move16(); + move16(); } } ELSE -- GitLab From a275f8291da0d3dc1602939a803a23b190367b48 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 29 Oct 2024 20:54:30 +0530 Subject: [PATCH 35/39] Fix for 3GPP issue 967: Decoder crash for OMASA ISM3_2TC at 64kbps FER in ivas_mdct_core_invQ_fx() --- lib_com/ivas_omasa_com.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 037364420..5821c474c 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -900,13 +900,13 @@ static Word16 get_bits_ism( res = 0; move16(); } - ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092897 /*4/6 (in Q29)*/ ) ) + ELSE IF( LE_32( val, 447750340 /* 5/6 (in Q29)*/ ) && GT_32( val, 358092870 /*4/6 (in Q29)*/ ) ) { // 5/6 (in Q29) <= val <= 4/6 (in Q29) => res = 1 res = 1; move16(); } - ELSE IF( LE_32( val, 358092897 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) + ELSE IF( LE_32( val, 358092870 /*4/6 (in Q29)*/ ) && GT_32( val, 268972326 /*3/6 (in Q29)*/ ) ) { // 4/6 (in Q29) <= val <= 3/6 (in Q29) => res = 2 res = 2; -- GitLab From 6c7b1e3af3c6b79659e4a8d0b6987843f1978397 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 30 Oct 2024 11:36:47 +0530 Subject: [PATCH 36/39] SBA, MCMASA and OMASA float code cleanup, Q-info updates for lib_com and lib_rend --- lib_com/bitstream.c | 802 ++++++++++---------------- lib_com/bitstream_fx.c | 4 +- lib_com/gs_preech.c | 44 +- lib_com/guided_plc_util_fx.c | 98 ++-- lib_com/hq2_bit_alloc_fx.c | 158 ++--- lib_com/ivas_dirac_com.c | 12 +- lib_com/ivas_fb_mixer.c | 90 +-- lib_com/ivas_prot.h | 49 +- lib_com/ivas_prot_fx.h | 25 +- lib_com/ivas_qmetadata_com.c | 20 - lib_com/ivas_spar_com.c | 12 +- lib_com/ivas_stat_com.h | 4 +- lib_com/ivas_tools.c | 22 - lib_com/ivas_transient_det.c | 39 +- lib_com/prot.h | 15 - lib_com/prot_fx.h | 100 ++-- lib_enc/ivas_corecoder_enc_reconfig.c | 147 ++++- lib_enc/ivas_enc.c | 151 ++--- lib_enc/ivas_init_enc.c | 318 +++++----- lib_enc/ivas_ism_dtx_enc.c | 14 +- lib_enc/ivas_ism_metadata_enc.c | 38 +- lib_enc/ivas_masa_enc.c | 26 +- lib_enc/ivas_mc_paramupmix_enc.c | 4 +- lib_enc/ivas_mcmasa_enc.c | 237 +++++--- lib_enc/ivas_omasa_enc.c | 24 +- lib_enc/ivas_osba_enc.c | 59 -- lib_enc/ivas_sba_enc.c | 99 +--- lib_enc/ivas_sce_enc.c | 50 +- lib_enc/ivas_spar_encoder.c | 166 +----- lib_enc/ivas_spar_md_enc.c | 118 ++-- lib_enc/ivas_stat_enc.h | 4 +- lib_enc/ivas_tcx_core_enc.c | 37 +- lib_enc/lib_enc.c | 588 ++++++++++--------- lib_enc/lib_enc.h | 11 + lib_enc/prot_fx_enc.h | 5 + lib_rend/ivas_td_decorr.c | 4 +- 36 files changed, 1667 insertions(+), 1927 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 584013e2b..3d8a69a3e 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -39,6 +39,7 @@ #include "options.h" #include "cnst.h" #include "prot.h" +#include "prot_fx.h" #include "stat_enc.h" #include "stat_dec.h" #include "rom_com.h" @@ -49,6 +50,7 @@ #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx_enc.h" #endif @@ -422,277 +424,6 @@ ivas_error ind_list_realloc( *-----------------------------------------------------------------------*/ /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1350; - } - else - { - return 1650; - } - } - else if ( ivas_format == ISM_FORMAT || ivas_format == MONO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 450; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 550; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 620; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 670; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 780; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 880; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1100; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1300; - } - else - { - return 1650; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1020; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1160; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1220; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1300; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1720; - } - else - { - return 2000; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 950; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1450; - } - else - { - return 1650; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 1250; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1400; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1650; - } - else - { - return 1850; - } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 250; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 350; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 400; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 650; - } - else if ( ivas_total_brate <= IVAS_64k ) - { - return 750; - } - else if ( ivas_total_brate <= IVAS_80k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 1150; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 1420; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 2120; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2250; - } - else - { - return 2450; - } - } - - return 2450; -} - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -908,273 +639,93 @@ Word16 get_ivas_max_num_indices_fx( } 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; -} -/*-----------------------------------------------------------------------* - * get_BWE_max_num_indices() - * - * Get the maximum number of indices in the BWE - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_BWE_max_num_indices( - const int32_t extl_brate /* i : extensiona layer bitrate */ -) -{ - /* set the maximum number of indices in the BWE */ - if ( extl_brate < SWB_BWE_16k ) - { - return 30; - } - else - { - return 150; - } -} - - -/*-----------------------------------------------------------------------* - * get_ivas_max_num_indices_metadata() - * - * Set the maximum allowed number of metadata indices in the list - *-----------------------------------------------------------------------*/ - -/*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - /* set the maximum required number of metadata indices */ - if ( ivas_format == MONO_FORMAT ) - { - return 0; - } - else if ( ivas_format == STEREO_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 60; - } - else - { - return 80; - } - } - else if ( ivas_format == ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 20; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 65; - } - else - { - return 80; - } - } - else if ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 100; - } - else if ( ivas_total_brate <= IVAS_24k4 ) - { - return 200; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 300; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 500; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 1050; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 2000; - } - else - { - return 2500; - } - } - else if ( ivas_format == MASA_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205; - } - else if ( ivas_total_brate <= IVAS_96k ) - { - return 240; - } - else if ( ivas_total_brate <= IVAS_128k ) - { - return 305; - } - else if ( ivas_total_brate <= IVAS_160k ) - { - return 425; - } - else if ( ivas_total_brate <= IVAS_192k ) - { - return 630; - } - else if ( ivas_total_brate <= IVAS_256k ) - { - return 850; - } - else if ( ivas_total_brate <= IVAS_384k ) - { - return 1000; - } - else - { - return 1750; - } - } - else if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( ivas_total_brate <= IVAS_16k4 ) - { - return 80; - } - else if ( ivas_total_brate <= IVAS_32k ) - { - return 125 + 100; - } - else if ( ivas_total_brate <= IVAS_48k ) - { - return 205 + 100; + return 1650; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE { - return 240 + 150; + return 1850; } - else if ( ivas_total_brate <= IVAS_128k ) + } + ELSE IF( EQ_16( ivas_format, MC_FORMAT ) ) + { + IF( LE_32( ivas_total_brate, IVAS_16k4 ) ) { - return 305 + 30; + return 250; } - else if ( ivas_total_brate <= IVAS_160k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_24k4 ) ) { - return 425 + 30; + return 350; } - else if ( ivas_total_brate <= IVAS_192k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_32k ) ) { - return 630 + 30; + return 400; } - else if ( ivas_total_brate <= IVAS_256k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_48k ) ) { - return 850 + 30; + return 650; } - else if ( ivas_total_brate <= IVAS_384k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_64k ) ) { - return 1000 + 30; + return 750; } - else + ELSE IF( LE_32( ivas_total_brate, IVAS_80k ) ) { - return 1750 + 30; + return 850; } - } - else if ( ivas_format == MC_FORMAT ) - { - if ( ivas_total_brate <= IVAS_13k2 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_128k ) ) { - return 80; + return 1150; } - else if ( ivas_total_brate <= IVAS_24k4 ) + ELSE IF( LE_32( ivas_total_brate, IVAS_160k ) ) { - return 100; + return 1420; } - else if ( ivas_total_brate <= IVAS_64k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_256k ) ) { - return 210; + return 2120; } - else if ( ivas_total_brate <= IVAS_96k ) + ELSE IF( LE_32( ivas_total_brate, IVAS_384k ) ) { - return 220; + return 2250; } - else + ELSE { - return 300; + return 2450; } } - return 50; + return 2450; +} +/*-----------------------------------------------------------------------* + * get_BWE_max_num_indices() + * + * Get the maximum number of indices in the BWE + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ +int16_t get_BWE_max_num_indices( + const int32_t extl_brate /* i : extensiona layer bitrate */ +) +{ + /* set the maximum number of indices in the BWE */ + if ( extl_brate < SWB_BWE_16k ) + { + return 30; + } + else + { + return 150; + } } + +/*-----------------------------------------------------------------------* + * get_ivas_max_num_indices_metadata() + * + * Set the maximum allowed number of metadata indices in the list + *-----------------------------------------------------------------------*/ + +/*! r: maximum number of indices */ 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 */ @@ -2244,7 +1795,52 @@ void reset_indices_dec( * * writing forward or backward to a serial stream *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 write_indices_to_stream_fx( + Indice *ind_list, + UWord16 **pt_stream, + const Word16 inc, + const Word16 num_indices ) +{ + Word16 i, k; + Word16 value, nb_bits; + UWord16 mask; + + FOR( i = 0; i < num_indices; i++ ) + { + value = ind_list[i].value; + nb_bits = ind_list[i].nb_bits; + move16(); + move16(); + + IF( nb_bits > 0 ) + { + /* mask from MSB to LSB */ + mask = (UWord16) L_shl( 1, sub( nb_bits, 1 ) ); + + /* write bit by bit */ + FOR( k = 0; k < nb_bits; k++ ) + { + IF( L_and( value, mask ) ) + { + **pt_stream = 1; + move16(); + *pt_stream += inc; + } + ELSE + { + **pt_stream = 0; + move16(); + *pt_stream += inc; + } + mask = (UWord16) L_shr( mask, 1 ); + } + } + } + return 0; +} +#else static int16_t write_indices_to_stream( Indice *ind_list, uint16_t **pt_stream, @@ -2285,13 +1881,158 @@ static int16_t write_indices_to_stream( } return 0; } +#endif /*-------------------------------------------------------------------* * write_indices_element() * * Bitstream writing function of one element (one SCE or one CPE) *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error write_indices_element_fx( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + UWord16 **pt_stream, /* i : pointer to bitstream buffer */ + const Word16 is_SCE, /* i : flag to distingusih SCE and CPE */ + const Word16 element_id /* i : id of the SCE or CPE */ +) +{ + Word16 ch; + Encoder_State **sts = NULL; + UWord16 *pt_stream_loc; + UWord16 *pt_stream_backup; + UWord16 *pt_stream_end; + Word16 nb_bits_tot_metadata; + Word16 nb_ind_tot_metadata; + + Indice *ind_list_metadata; + Word16 n, n_channels; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + ind_list_metadata = NULL; + nb_ind_tot_metadata = 0; + move16(); + + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + sts = st_ivas->hSCE[0]->hCoreCoder; + nb_bits_tot_metadata = 0; + move16(); + } + ELSE + { + nb_bits_tot_metadata = 0; + move16(); + test(); + test(); + IF( is_SCE && st_ivas->hSCE[element_id] != NULL ) + { + sts = st_ivas->hSCE[element_id]->hCoreCoder; + + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hSCE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + ELSE IF( !is_SCE && st_ivas->hCPE[element_id] != NULL ) + { + sts = st_ivas->hCPE[element_id]->hCoreCoder; + + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + nb_bits_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_bits_tot; + ind_list_metadata = st_ivas->hCPE[element_id]->hMetaData->ind_list; + nb_ind_tot_metadata = st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot; + move16(); + move16(); + } + } + } + + n_channels = 1; + move16(); + if ( GT_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + { + n_channels = CPE_CHANNELS; + move16(); + } + + /*----------------------------------------------------------------* + * Bitstream packing (conversion of individual indices into a serial stream) + *----------------------------------------------------------------*/ + + pt_stream_loc = *pt_stream; + pt_stream_end = pt_stream_loc; + + FOR( n = 0; n < n_channels; n++ ) + { + /* write the metadata buffer */ + test(); + IF( n == 0 && nb_bits_tot_metadata != 0 ) + { + pt_stream_backup = pt_stream_loc; + + FOR( ch = 0; ch < n_channels; ch++ ) + { + pt_stream_loc += sts[ch]->hBstr->nb_bits_tot; + } + pt_stream_loc += nb_bits_tot_metadata - 1; + pt_stream_end = pt_stream_loc + 1; + + write_indices_to_stream_fx( 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_fx( sts[n]->hBstr->ind_list, &pt_stream_loc, 1, + sts[n]->hBstr->nb_ind_tot ); + + if ( pt_stream_loc > pt_stream_end ) + { + pt_stream_end = pt_stream_loc; + } + } + + /*----------------------------------------------------------------* + * Clearing of indices + * Reset index pointers + *----------------------------------------------------------------*/ + + IF( is_SCE ) /* EVS and SCE */ + { + IF( st_ivas->hSCE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hSCE[element_id]->hMetaData, st_ivas->hSCE[element_id]->hMetaData->nb_ind_tot ); + } + + reset_indices_enc( sts[0]->hBstr, sts[0]->hBstr->nb_ind_tot ); + } + ELSE + { + IF( st_ivas->hCPE[element_id]->hMetaData != NULL ) + { + reset_indices_enc( st_ivas->hCPE[element_id]->hMetaData, st_ivas->hCPE[element_id]->hMetaData->nb_ind_tot ); + } + + FOR( n = 0; n < n_channels; n++ ) + { + reset_indices_enc( sts[n]->hBstr, sts[n]->hBstr->nb_ind_tot ); + } + } + /* update pointer */ + *pt_stream = pt_stream_end; + + return error; +} +#else static ivas_error write_indices_element( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ uint16_t **pt_stream, /* i : pointer to bitstream buffer */ @@ -2422,6 +2163,7 @@ static ivas_error write_indices_element( return error; } +#endif /*-------------------------------------------------------------------* * write_indices_ivas() @@ -2429,7 +2171,48 @@ static ivas_error write_indices_element( * Write the buffer of indices to a serial bitstream buffer, * each bit represented as a uint16_t of value 0 or 1 *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +) +{ + Word16 i, n; + UWord16 *pt_stream; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + pt_stream = bit_stream; + FOR( i = 0; i < MAX_BITS_PER_FRAME; ++i ) + { + bit_stream[i] = 0; + move16(); + } + + + /*-----------------------------------------------------------------* + * Encode Payload + *-----------------------------------------------------------------*/ + + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 1, n ); + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + write_indices_element_fx( st_ivas, &pt_stream, 0, n ); + } + + *num_bits = (UWord16) ( pt_stream - bit_stream ); + move16(); + return error; +} +#else ivas_error write_indices_ivas( Encoder_Struct *st_ivas, /* i/o: encoder state structure */ uint16_t *bit_stream, /* i/o: output bitstream */ @@ -2467,6 +2250,7 @@ ivas_error write_indices_ivas( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c index 7d7fa3fdd..753bc19cf 100644 --- a/lib_com/bitstream_fx.c +++ b/lib_com/bitstream_fx.c @@ -1088,7 +1088,7 @@ static void decoder_selectCodec( } -void dec_prm_core( Decoder_State *st ) +static void dec_prm_core( Decoder_State *st ) { Word16 n, frame_size_index, num_bits; UWord16 lsb; @@ -1178,7 +1178,7 @@ void dec_prm_core( Decoder_State *st ) * Set st->core, and st->bwidth if signalled together with the core. *-----------------------------------------------------------------*/ -void decision_matrix_core_dec( +static void decision_matrix_core_dec( Decoder_State *st /* i/o: decoder state structure */ ) { diff --git a/lib_com/gs_preech.c b/lib_com/gs_preech.c index 3d1b6f550..1fc23300e 100644 --- a/lib_com/gs_preech.c +++ b/lib_com/gs_preech.c @@ -144,10 +144,10 @@ 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 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -168,18 +168,18 @@ void pre_echo_att_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } 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 */ + L_tmp = sum2_fx( &exc_fx[i * 4], 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 */ } @@ -231,10 +231,10 @@ void pre_echo_att_fx( L_tmp = L_shr( L_tmp, exp ); /* add exponent */ L_tmp = Isqrt( L_tmp ); - ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); + ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */ /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -242,7 +242,7 @@ void pre_echo_att_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /*2*Q_new+1*/ move32(); } ELSE @@ -270,10 +270,10 @@ void pre_echo_att_fx( void pre_echo_att_ivas_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 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ) { Word32 etmp_fx; @@ -294,18 +294,18 @@ void pre_echo_att_ivas_fx( * The inverse weighting aims to favor the first maxima in case of * gradual onset *-------------------------------------------------------------------------*/ - att_len = ATT_LENGHT; + att_len = ATT_LENGHT; /* Q0 */ move16(); if ( EQ_16( L_frame, L_FRAME16k ) ) { - att_len = ATT_LENGHT16k; + att_len = ATT_LENGHT16k; /* Q0 */ move16(); } 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 */ + L_tmp = sum2_fx( &exc_fx[i * 4], 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 */ } @@ -360,7 +360,7 @@ void pre_echo_att_ivas_fx( ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Pre-echo atttenuation should never increase the energy */ - ratio_fx = s_min( ratio_fx, 8192 ); + ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */ FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ ) { /*exc_fx[i] *= ratio_fx;*/ @@ -368,7 +368,7 @@ void pre_echo_att_ivas_fx( move16(); } } - *Last_frame_ener_fx = etmp1_fx; + *Last_frame_ener_fx = etmp1_fx; /* 2 * Q_new + 1 */ move32(); } ELSE @@ -383,7 +383,7 @@ void pre_echo_att_ivas_fx( if ( EQ_16( L_frame, L_FRAME16k ) ) { - etmp_fx = Mpy_32_16_1( etmp_fx, 26214 ); + etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*2*Q_new+1*/ } *Last_frame_ener_fx = etmp_fx; move32(); /*2*Q_new+1*/ diff --git a/lib_com/guided_plc_util_fx.c b/lib_com/guided_plc_util_fx.c index b7eba5d7e..f556fff05 100644 --- a/lib_com/guided_plc_util_fx.c +++ b/lib_com/guided_plc_util_fx.c @@ -22,11 +22,12 @@ static void reorder_lsfs( Word16 *lsf, const Word16 min_dist, const Word16 n, co * *-------------------------------------------------------------------*/ void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ) + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +) { Word16 *p_A; Word16 i_subfr; @@ -40,12 +41,12 @@ void getLookAheadResSig( move16(); /* 0.75 * L_SUBFR(64) */ } - p_A = A_3Q12; + p_A = A_3Q12; /* Q12 */ FOR( i_subfr = 0; i_subfr < numSubFrame * L_SUBFR; i_subfr += L_SUBFR ) { /* calculate residual signal */ Residu3_fx( p_A, &speechLookAhead[i_subfr], &res[i_subfr], - subfr_len[shr( i_subfr, 6 )], 0 ); + subfr_len[i_subfr / 64], 0 ); /* pointer initialization */ p_A += ( M + 1 ); @@ -62,21 +63,22 @@ void getLookAheadResSig( void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ) + Word16 *lsf_14Q1 /* 14Q1 */ +) { Word16 i; Word32 L_tmp = 0; - const Word16 divide_by_3_Q15 = 10923; + const Word16 divide_by_3_Q15 = 10923; /* 1/3 in Q15 */ FOR( i = 0; i < M; i++ ) { - L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); - L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); - decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); + L_tmp = L_mult( divide_by_3_Q15, decState->lsfoldbfi1_14Q1[i] ); /* Q17 */ + L_tmp = L_mac( L_tmp, divide_by_3_Q15, decState->lsfoldbfi0_14Q1[i] ); /* Q17 */ + decState->lsf_adaptive_mean_14Q1[i] = mac_r( L_tmp, divide_by_3_Q15, lsf_14Q1[i] ); /* 14Q1 */ move16(); - decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; + decState->lsfoldbfi1_14Q1[i] = decState->lsfoldbfi0_14Q1[i]; /* 14Q1 */ move16(); - decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; + decState->lsfoldbfi0_14Q1[i] = lsf_14Q1[i]; /* 14Q1 */ move16(); } @@ -90,10 +92,11 @@ void updateLSFForConcealment( void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf; Word16 lsp[( NB_DIV + 1 ) * M]; @@ -106,7 +109,7 @@ void getConcealedLP( 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 ); + Copy( memDecState->lspold_Q15, lsp, M ); /* Q15 */ int_fs = INT_FS_FX; move32(); @@ -128,9 +131,10 @@ void getConcealedLP( *-------------------------------------------------------------------*/ void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ) + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +) { Word16 *lsf = memDecState->lsf_con; @@ -149,11 +153,12 @@ void getConcealedLSF( *-------------------------------------------------------------------*/ void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ) + const Word16 reset_q /* Q0 */ +) { const Word16 *means; Word16 lsf_old[M]; @@ -163,7 +168,7 @@ void RecLpcSpecPowDiffuseLc( st->narrowBand, st->sr_core ); - Copy( st->lsf_old_fx, lsf_old, M ); + Copy( st->lsf_old_fx, lsf_old, M ); /* Q2.56 */ modify_lsf( lsf_old, M, st->sr_core, reset_q ); @@ -173,7 +178,7 @@ void RecLpcSpecPowDiffuseLc( { FOR( i = 0; i < M; i++ ) { - lsfq[i] = add( st->mem_MA_fx[i], means[i] ); + lsfq[i] = add( st->mem_MA_fx[i], means[i] ); /* Q2.56 */ move16(); } sort_fx( lsfq, 0, sub( M, 1 ) ); @@ -195,10 +200,11 @@ void RecLpcSpecPowDiffuseLc( * *-------------------------------------------------------------------*/ void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ) + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +) { Word16 i, k, th_x1p28_Q14; Word16 gap, gap_sum; @@ -231,25 +237,25 @@ void modify_lsf( } } - gap = mult_r( lsf[i - 1], InvIntTable[i] ); + gap = mult_r( lsf[i - 1], InvIntTable[i] ); /* Q14 */ move16(); gap_sum = gap; - i = sub( i, 1 ); + i--; FOR( k = 0; k < i; k++ ) { move16(); - lsf[k] = gap_sum; + lsf[k] = gap_sum; /* Q14 */ gap_sum = add( gap_sum, gap ); } } static void reorder_lsfs( - Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5)*/ - const Word16 min_dist0, /* i : minimum required distance */ - const Word16 n, /* i : LPC order */ - const Word32 sr_core /* i : input sampling frequency */ + Word16 *lsf, /* i/o: vector of lsfs in the frequency domain (0..0.5) 1.28 Q1*/ + const Word16 min_dist0, /* i : minimum required distance 1.28 Q1*/ + const Word16 n, /* i : LPC order Q0*/ + const Word32 sr_core /* i : input sampling frequency Q0*/ ) { Word16 i; @@ -277,17 +283,17 @@ static void reorder_lsfs( *-----------------------------------------------------------------*/ IF( EQ_32( sr_core, INT_FS_16k ) ) { - th1 = 3200; + th1 = 3200; /*1000.0 * 1.25 * 1.28 Q1*/ move16(); - th2 = 6080; + th2 = 6080; /*1900.0 * 1.25 * 1.28 Q1*/ move16(); min_dist = add( min_dist0, shr( min_dist0, 2 ) ); } ELSE { - th1 = 2560; + th1 = 2560; /* 1000.0 * 1.28 Q1 */ move16(); - th2 = 4864; + th2 = 4864; /* 1900.0 * 1.28 Q1 */ move16(); min_dist = min_dist0; move16(); @@ -322,7 +328,7 @@ static void reorder_lsfs( move16(); } - lsf_min = add( lsf[i], curr_min_dist ); + lsf_min = add( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } /*------------------------------------------------------------------------------------------* @@ -333,7 +339,7 @@ static void reorder_lsfs( IF( GT_16( lsf[n - 1], lsf_max ) ) /* If danger of unstable filter in case of resonance in HF */ { - FOR( i = sub( n, 1 ); i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ + FOR( i = n - 1; i >= 0; i-- ) /* Reverify the minimum ISF gap in the reverse direction */ { IF( LE_16( lsf[i], th2 ) ) { @@ -354,7 +360,7 @@ static void reorder_lsfs( lsf[i] = lsf_max; move16(); } - lsf_max = sub( lsf[i], curr_min_dist ); + lsf_max = sub( lsf[i], curr_min_dist ); /* 1.28 Q1 */ } } diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 486de81de..395854d5f 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -92,14 +92,14 @@ void Bits2indvsb_fx( 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; + band_num_fx = sub( end_band, start_band ); /* Q0 */ + L_y_ptr = L_be + start_band; /* Qbe */ + L_R_ptr = L_Rsubband + start_band; /* QRk */ + p2aflags_fx_ptr = p2aflags_fx + start_band; /* Q0 */ 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 ) ) ); + y_index_fx[i] = extract_h( L_shr( L_y_ptr[i], sub( SWB_BWE_LR_Qbe, 16 ) ) ); /* Q16 */ move16(); index_fx[i] = i; move16(); @@ -125,9 +125,9 @@ void Bits2indvsb_fx( } ELSE { - L_R_temp[j] = C1_QRk; - move32(); /* filled not zero value */ - be_cnt_fx = add( be_cnt_fx, 1 ); + L_R_temp[j] = C1_QRk; /* QRk */ + move32(); /* filled not zero value */ + be_cnt_fx = add( be_cnt_fx, 1 ); /* Q0 */ } } @@ -187,7 +187,7 @@ void Bits2indvsb_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 */ + Ravg_fx = shr( Ravg_fx, 2 ); /* safe shift exp_normn - exp_normd + 13*/ QRavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); if ( be_sum_fx <= 0 ) @@ -207,7 +207,7 @@ void Bits2indvsb_fx( 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 */ + Bits_avg_fx = shr( Bits_avg_fx, 2 ); /* safe_shift exp_normn - exp_normd + 13*/ QBavg = add( sub( exp_normn, exp_normd ), 15 - 2 ); } FOR( k = 0; k <= i; k++ ) @@ -244,7 +244,7 @@ void Bits2indvsb_fx( { j = index_fx[k]; move16(); - L_R_ptr[j] = L_R_temp[k]; + L_R_ptr[j] = L_R_temp[k]; /* SWB_BWE_LR_QRk */ move32(); } @@ -262,7 +262,7 @@ void hq2_bit_alloc_har_fx( 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 */ + 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 */ @@ -280,7 +280,7 @@ void hq2_bit_alloc_har_fx( 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 bits_fact_fx, bits_fact1_fx; 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; @@ -336,9 +336,9 @@ void hq2_bit_alloc_har_fx( } final_gr_fact_pos_fx = 2; move16(); - bits_fact_fx = C1_Qbf; + bits_fact_fx = C1_Qbf; /* Qbf */ move16(); - bits_fact1_fx = C1_Qbf; + bits_fact1_fx = C1_Qbf; /* Qbf */ move16(); gmax_range_fx[0] = G1_RANGE; @@ -378,27 +378,27 @@ void hq2_bit_alloc_har_fx( { FOR( temp_fx = 2; temp_fx <= k_fx; ) { - IF( LT_32( L_temp_band_energy[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_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[sub( add( gmax_range_fx[i], temp_fx ), 1 )], L_temp_band_energy[add( gmax_range_fx[i], temp_fx )] ) ) + 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 ); + temp_fx++; IF( GT_16( temp_fx, k_fx ) ) { - temp_fx = sub( temp_fx, 1 ); + temp_fx--; /* Q0 */ BREAK; } } } - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } ELSE { - gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); + gmax_range_fx[i] = add( gmax_range_fx[i], temp_fx ); /* Q0 */ move16(); } } @@ -407,12 +407,12 @@ void hq2_bit_alloc_har_fx( move16(); FOR( i = 1; i < GRP_SB - 1; i++ ) { - grp_bound_fx[i] = gmax_range_fx[i - 1]; + grp_bound_fx[i] = gmax_range_fx[i - 1]; /* Q0 */ move16(); } - grp_bound_fx[i] = harmonic_band_fx; + grp_bound_fx[i] = harmonic_band_fx; /* Q0 */ move16(); - grp_bound_fx[add( i, 1 )] = N_fx; + grp_bound_fx[i + 1] = N_fx; /* Q0 */ move16(); @@ -423,7 +423,7 @@ void hq2_bit_alloc_har_fx( { IF( L_temp_band_energy[j] > 0x0L ) { - L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); + L_Ravg_sub[i] = L_add( L_Ravg_sub[i], L_temp_band_energy[j] ); /* Qbe */ move32(); } } @@ -433,7 +433,7 @@ void hq2_bit_alloc_har_fx( 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] ) ); + L_temp_band_energydiff[j] = L_abs( L_sub( L_temp_band_energy[j], L_temp_band_energy[j - 1] ) ); /* Qbe */ move32(); } @@ -447,7 +447,7 @@ void hq2_bit_alloc_har_fx( { G1_BE_DIFF_POS_fx = j; move16(); - L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; + L_G1_BE_DIFF_VAL = L_temp_band_energydiff[j]; /* Qbe */ move32(); } } @@ -506,47 +506,47 @@ void hq2_bit_alloc_har_fx( } } - j = sub( N_fx, harmonic_band_fx ); + j = sub( N_fx, harmonic_band_fx ); /* Q0 */ 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 ) ) ); + y_index_fx[i] = extract_h( L_shl( L_temp_band_energy[harmonic_band_fx + i], sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - index_fx[i] = add( harmonic_band_fx, i ); + index_fx[i] = add( harmonic_band_fx, i ); /* Q0 */ 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]] ); + L_temp = L_deposit_l( band_width_fx[index_fx[0]] ); /* Q0 */ exp = norm_l( L_temp ); frac = Log2_norm_lc( L_shl( L_temp, exp ) ); exp = sub( 30, exp ); - L_temp = L_Comp( exp, frac ); + L_temp = L_Comp( exp, frac ); /* Q16 */ /* ceil */ if ( L_and( 0x0000ffff, L_temp ) > 0 ) { - L_temp = L_add( L_temp, 0x00010000 ); + L_temp = L_add( L_temp, 0x00010000 ); /* Q16 */ } esthf_bits_fx = extract_h( L_temp ); - L_grp_thr[0] = L_THR1; + L_grp_thr[0] = L_THR1; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[1] = L_THR2; + L_grp_thr[1] = L_THR2; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[2] = L_THR3; + L_grp_thr[2] = L_THR3; /* SWB_BWE_LR_QRk */ move32(); - L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); + L_grp_thr[3] = L_shl( L_deposit_l( esthf_bits_fx ), SWB_BWE_LR_QRk ); /* 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] ); + L_norm_sum = L_add( L_norm_sum, L_Ravg_sub[i] ); /* Qbe */ } /*reserve bits for HF coding */ - L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); + L_temp = L_add( L_norm_sum, L_Ravg_sub[GRP_SB - 1] ); /* Qbe */ exp_normn = norm_l( L_temp ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( N_fx ); @@ -558,7 +558,7 @@ void hq2_bit_alloc_har_fx( 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 ); + Inv_norm_sum_fx = div_s( 0x4000 /* 0.5 in 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 */ @@ -567,8 +567,8 @@ void hq2_bit_alloc_har_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 = L_shl( Mult_32_16( L_Ravg_sub[GRP_SB - 1], Inv_p2a_bands_fx ), sub( SWB_BWE_LR_Qbe, sub( QIpb, 1 ) ) ); /* Qbe */ + 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 */ @@ -604,11 +604,11 @@ void hq2_bit_alloc_har_fx( 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 ); + L_temp = L_add( L_shl( L_temp, SWB_BWE_LR_Qbe ), L_temp2 ); /* Qbe+Q15-15 */ - Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); + Bits_grp_fx[GRP_SB - 1] = extract_h( L_shl( L_temp, sub( 16, SWB_BWE_LR_Qbe ) ) ); /* Q0 */ move16(); - Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); + Bits_grp_fx[GRP_SB - 1] = s_min( Bits_grp_fx[GRP_SB - 1], 10 ); /* Q0 */ move16(); if ( LT_16( Bits_grp_fx[GRP_SB - 1], esthf_bits_fx ) ) @@ -616,7 +616,7 @@ void hq2_bit_alloc_har_fx( Bits_grp_fx[GRP_SB - 1] = 0; move16(); } - B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); + B_fx = sub( B_fx, Bits_grp_fx[GRP_SB - 1] ); /* Q0 */ } exp_shift = sub( add( SWB_BWE_LR_Qbe, QIns ), 47 ); /* (SWB_BWE_LR_Qbe+14+1+QIns-15-16) */ @@ -627,37 +627,37 @@ void hq2_bit_alloc_har_fx( 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_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[1] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); 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 ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); + Bits_grp_fx[0] = sub( sub( B_fx, Bits_grp_fx[1] ), Bits_grp_fx[2] ); /* Q0 */ 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_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[0] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); 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 ) ); + L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Q16 + exp_shift */ + Bits_grp_fx[2] = extract_h( L_shr( L_temp, exp_shift ) ); /* Q0 */ move16(); - Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); + Bits_grp_fx[1] = sub( sub( B_fx, Bits_grp_fx[0] ), Bits_grp_fx[2] ); /* Q0 */ move16(); } IF( LT_16( Bits_grp_fx[2], THR2 ) ) { - Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); + Bits_grp_fx[1] = add( Bits_grp_fx[1], Bits_grp_fx[2] ); /* Q0 */ move16(); Bits_grp_fx[2] = 0; move16(); @@ -690,16 +690,16 @@ 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 Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ) { Word16 j, k; @@ -728,9 +728,9 @@ Word32 hq2_bit_alloc_fx( 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 ); + L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ + L_THR3 = L_shl( L_deposit_l( THR3 ), SWB_BWE_LR_QRk ); /* SWB_BWE_LR_QRk */ /* Init Rk to non-zero values for bands to be allocated bits */ IF( LE_16( num_bits, HQ_16k40_BIT ) ) @@ -763,7 +763,7 @@ Word32 hq2_bit_alloc_fx( /*mvs2r( p2a_flags, Rk, bands ); */ FOR( k = 0; k < bands; k++ ) { - L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); + L_Rk[k] = L_shl( L_deposit_l( p2a_flags[k] ), SWB_BWE_LR_QRk ); /* QRk */ move32(); } } @@ -807,11 +807,11 @@ Word32 hq2_bit_alloc_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 ) ); + L_Ravg = L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ); /* QRk */ exp_normd = norm_s( *bit_budget_fx ); exp_normd = sub( exp_normd, 1 ); - bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); + bit_budget_norm_fx = shl( *bit_budget_fx, exp_normd ); /* exp_normd */ div_fx = 0; move16(); @@ -830,7 +830,7 @@ Word32 hq2_bit_alloc_fx( 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 ); + L_Rk[k] = L_add( L_shr( L_deposit_l( div_fx ), sub( Qdiv, SWB_BWE_LR_QRk ) ), L_tmp ); /* SWB_BWE_LR_QRk */ move32(); } } @@ -860,9 +860,9 @@ Word32 hq2_bit_alloc_fx( L_Rcalc = L_deposit_l( 0 ); /* find worst under-allocation */ - FOR( k = sub( bands, 1 ); k >= 0; k-- ) + FOR( k = bands - 1; k >= 0; k-- ) { - tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); + tmp_fx = s_min( band_width[k], s_max( 12, shr( band_width[k], 2 ) ) ); /* Q0 */ L_dummy = L_sub( L_shl( L_deposit_l( tmp_fx ), SWB_BWE_LR_QRk ), L_Rk[k] ); /*SWB_BWE_LR_QRk */ test(); test(); @@ -927,14 +927,14 @@ Word32 hq2_bit_alloc_fx( test(); IF( EQ_16( hqswb_clas, HQ_NORMAL ) && LT_16( num_bits, HQ_16k40_BIT ) ) { - bit_budget_temp_fx = *bit_budget_fx; + bit_budget_temp_fx = *bit_budget_fx; /* Q0 */ move16(); FOR( k = 0; k < NB_SWB_SUBBANDS; k++ ) { test(); - IF( EQ_16( p2a_flags[add( sub( bands, NB_SWB_SUBBANDS ), k )], 1 ) && L_Rk[add( sub( bands, NB_SWB_SUBBANDS ), k )] == 0 ) + IF( EQ_16( p2a_flags[( bands - NB_SWB_SUBBANDS ) + k], 1 ) && L_Rk[( bands - NB_SWB_SUBBANDS ) + k] == 0 ) { - p2a_flags[add( sub( 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] ); } diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 2b696a4b1..f07dcd4be 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -1029,8 +1029,8 @@ void computeDirectionVectors_fixed( e_x = sub( i_e, norm_x ); e_y = sub( i_e, norm_y ); e_z = sub( 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 ), shl( e_x, 1 ), Mult_32_32( scaled_y, scaled_y ), shl( e_y, 1 ), &exp1 ); + intensityNorm = BASOP_Util_Add_Mant32Exp( temp1, exp1, Mult_32_32( scaled_z, scaled_z ), shl( e_z, 1 ), &intensityNorm_e ); IF( LE_32( intensityNorm, EPSILON_FX ) ) { @@ -1048,12 +1048,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 ), sub( add( 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 ), sub( add( 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 ), sub( add( e_z, intensityNorm_e ), 1 ) ); /*Q30*/ intensity_real_z++; move32(); diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 5da92e987..86e9e9e47 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -343,13 +343,18 @@ ivas_error ivas_FB_mixer_open( { if ( fb_cfg->num_out_chans == 0 ) { +#ifndef IVAS_FLOAT_FIXED hFbMixer->ppFilterbank_inFR_re[i] = NULL; hFbMixer->ppFilterbank_inFR_im[i] = NULL; +#else + hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; + hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; +#endif } else { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED 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" ); @@ -359,8 +364,7 @@ ivas_error ivas_FB_mixer_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } - -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -412,21 +416,6 @@ ivas_error ivas_FB_mixer_open( if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) { - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * 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 ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } - 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 ) { @@ -441,6 +430,8 @@ ivas_error ivas_FB_mixer_open( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } if ( !spar_reconfig_flag ) @@ -600,6 +591,7 @@ ivas_error ivas_FB_mixer_open_fx( ELSE { j = fb_cfg->remix_order[i]; + move16(); IF( ( hFbMixer->ppFilterbank_inFR_re_fx[j] = (Word32 *) malloc( sizeof( Word32 ) * frame_len ) ) == NULL ) { @@ -611,27 +603,6 @@ ivas_error ivas_FB_mixer_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } -#if 1 // TODO: To be removed later - 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_im[j] = (float *) malloc( sizeof( float ) * frame_len ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); - } - } -#endif } IF( EQ_16( fb_cfg->active_w_mixing, -1 ) ) @@ -677,22 +648,8 @@ ivas_error ivas_FB_mixer_open_fx( set32_fx( hFbMixer->prior_mixer_fx[i][j], 0, IVAS_MAX_NUM_BANDS ); } } -#if 1 // TODO: To be removed later - float *pTemp_mem; - if ( ( pTemp_mem = (float *) malloc( sizeof( float ) * 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 ( j = 0; j < fb_cfg->num_in_chans; j++ ) - { - hFbMixer->prior_mixer[i][j] = pTemp_mem; - pTemp_mem += IVAS_MAX_NUM_BANDS; - set_f( hFbMixer->prior_mixer[i][j], 0, IVAS_MAX_NUM_BANDS ); - } - } -#endif + hFbMixer->q_prior_mixer_fx = Q31; + move16(); } IF( !spar_reconfig_flag ) @@ -816,13 +773,13 @@ void ivas_FB_mixer_close( if ( fb_cfg->num_out_chans > 0 ) { j = fb_cfg->remix_order[i]; - +#ifndef IVAS_FLOAT_FIXED free( hFbMixer->ppFilterbank_inFR_re[j] ); hFbMixer->ppFilterbank_inFR_re[j] = NULL; free( hFbMixer->ppFilterbank_inFR_im[j] ); hFbMixer->ppFilterbank_inFR_im[j] = NULL; -#ifdef IVAS_FLOAT_FIXED +#else free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; @@ -853,12 +810,6 @@ void ivas_FB_mixer_close( hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; } #endif - if ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) - { - free( hFbMixer->prior_mixer[0][0] ); - hFbMixer->prior_mixer[0][0] = NULL; - } - if ( !spar_reconfig_flag ) { if ( fb_cfg->num_out_chans > 0 ) @@ -1056,7 +1007,7 @@ void ivas_FB_mixer_close_fx( * * PCM ingest block *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_pcm_ingest( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1090,7 +1041,7 @@ void ivas_fb_mixer_pcm_ingest( return; } -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_pcm_ingest_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in[], /* i : input audio channels Qq_data_fix[] */ @@ -1167,7 +1118,7 @@ void ivas_fb_mixer_pcm_ingest_fx( * * *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_fb_mixer_update_prior_input( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ float *pcm_in[], /* i : input audio channels */ @@ -1185,8 +1136,7 @@ void ivas_fb_mixer_update_prior_input( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_fb_mixer_update_prior_input_fx( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ Word32 *pcm_in_fx[], /* i : input audio channels */ @@ -1266,7 +1216,7 @@ void ivas_fb_mixer_get_windowed_fr_fx( return; } -#endif +#else void ivas_fb_mixer_get_windowed_fr( IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ @@ -1311,7 +1261,7 @@ void ivas_fb_mixer_get_windowed_fr( return; } - +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_cross_fading() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b63a975d3..6dc3b8f55 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -829,8 +829,8 @@ void smooth_dft2td_transition( /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ +Word16 is_IVAS_bitrate_fx( + const Word32 ivas_total_brate /* i : IVAS total bitrate */ ); int16_t is_DTXrate( @@ -4648,22 +4648,6 @@ void ivas_spar_md_enc_close( ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ ); -#ifndef IVAS_FLOAT_FIXED -ivas_error ivas_spar_md_enc_process( - ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - const int16_t dtx_vad, - const int16_t nchan_inp, - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const int16_t dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const int16_t dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); -#endif - void ivas_compute_spar_params( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], @@ -4887,6 +4871,16 @@ void ivas_cov_smooth_process( #endif /* Transient detector module */ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +); +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet, /* i/o: Transient detector handle */ const int32_t sampling_rate /* i : sampling rate */ @@ -4895,6 +4889,7 @@ ivas_error ivas_transient_det_open( void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ); +#endif void ivas_transient_det_process( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ @@ -5704,6 +5699,15 @@ void ivas_mcmasa_param_est_enc( const int16_t nchan_inp /* i : Number of input channels */ ); +#endif + +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA(48000, IVAS_FB_ENC_DELAY_NS)], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0*/ + const Word16 n_chnls_dmx_new /* i : number of downmix channels in the target format Q0*/ +); #endif void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ @@ -6232,15 +6236,6 @@ void ivas_fb_mixer_get_windowed_fr( const int16_t nchan_fb_in /* i : number of analysis channels */ ); -#ifndef IVAS_FLOAT_FIXED -void ivas_fb_mixer_process( - IVAS_FB_MIXER_HANDLE hFbMixer, /* i/o: FB mixer handle */ - float ***mixer_mat, /* i : mixer matrix */ - float **ppOut_pcm, /* o : output audio channels */ - const int16_t frame_len, /* i : frame length in samples */ - int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ -); -#endif void ivas_fb_mixer_get_in_out_mapping( const IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i/o: mixing mapping */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fea7eca61..7c0458fa2 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -3224,10 +3224,10 @@ void computeDirectionVectors_fixed( UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ); /*----------------------------------------------------------------------------------* @@ -3406,9 +3406,9 @@ void ivas_param_mc_enc_fx( const Word16 input_frame /* i : input frame length */ ); void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ); @@ -5348,11 +5348,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -); + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ); Word16 ivas_get_spar_dec_md_num_subframes( const Word16 sba_order, /* i : Ambisonic (SBA) order */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 88821d0b3..25815afe3 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -69,24 +69,6 @@ static void ivas_qmetadata_free_memory( IVAS_QMETADATA_HANDLE hQMetaData ); * Allocate Q Metadata handle *-----------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_qmetadata_open( - IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ -) -{ - /* allocate MetaData handle */ - IF( ( *hQMetaData = (IVAS_QMETADATA_HANDLE) malloc( sizeof( IVAS_QMETADATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Q MetaData" ); - } - - ( *hQMetaData )->q_direction = NULL; - ( *hQMetaData )->surcoh_band_data = NULL; - ( *hQMetaData )->bandMap = NULL; - - return IVAS_ERR_OK; -} -#else ivas_error ivas_qmetadata_open( IVAS_QMETADATA_HANDLE *hQMetaData /* i/o: q_metadata handle */ ) @@ -103,8 +85,6 @@ ivas_error ivas_qmetadata_open( return IVAS_ERR_OK; } -#endif - /*-----------------------------------------------------------------------* * ivas_qmetadata_allocate_memory() diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 74d3c01d3..bae0da15f 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -1129,9 +1129,8 @@ static void ivas_get_pred_coeffs_enc_fx( num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); // Q=31-num_f_e - sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 - val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 - move16(); + sqrt_val = Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ); //((2*dm_alpha64_q[b]-31)+27-31)-2 ,reducing the Q by 2 instead of multiplication by 4 + val_e = sub( 31, sub( sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ), 2 ) ); // reducing the Q by 2 instead of multiplication by 4 sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, sub( shl( dm_beta_re_q, 1 ), 31 ) ), &val_e ); // q=31-val_e sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ) ), sub( 31, sub( sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ), 2 ) ) /* reducing the Q by 2 instead of multiplication by 4*/, &val_e ); // q=31-val_e // val_e = norm_l( sqrt_val ); @@ -1193,6 +1192,11 @@ static void ivas_get_pred_coeffs_enc_fx( move32(); dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); move16(); + if ( ppDM_Fv_re[i][b] == 0 ) + { + dm_v_re_q[i][b] = Q31; + move16(); + } *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); move16(); @@ -3892,7 +3896,7 @@ void ivas_compute_spar_params_enc_fx( { pWscale[b] = 1; move32(); - q_Wscale[b] = 15; + q_Wscale[b] = Q31; move16(); } diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index fc0f2159d..d6dd690fb 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -853,11 +853,11 @@ typedef struct ivas_fb_mixer_state_structure int16_t num_diff_bands; ivas_filterbank_t *pFb; - +#ifndef IVAS_FLOAT_FIXED float *ppFilterbank_inFR_re[IVAS_MAX_FB_MIXER_IN_CH]; float *ppFilterbank_inFR_im[IVAS_MAX_FB_MIXER_IN_CH]; +#endif float *ppFilterbank_prior_input[IVAS_MAX_FB_MIXER_IN_CH]; - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; #ifdef IVAS_FLOAT_FIXED Word32 *ppFilterbank_inFR_re_fx[IVAS_MAX_FB_MIXER_IN_CH]; diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 20cce673c..88a0200eb 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -3197,27 +3197,6 @@ void v_sort_ind_fixed( *-------------------------------------------------------------------*/ /*! r: flag indicating a valid bitrate */ -int16_t is_IVAS_bitrate( - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -) -{ - int16_t j; - - j = SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES; /* skip NO_DATA and SID bitrates */ - while ( j < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[j] ) - { - j++; - } - - if ( j >= SIZE_IVAS_BRATE_TBL ) - { - return 0; - } - - return 1; -} - -#ifdef IVAS_FLOAT_FIXED Word16 is_IVAS_bitrate_fx( const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) @@ -3241,7 +3220,6 @@ Word16 is_IVAS_bitrate_fx( return 1; } -#endif /*-------------------------------------------------------------------* * is_DTXrate() diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index 65bb7f72b..019874fc9 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -350,7 +350,26 @@ static void ivas_transient_det_init( * * Allocate and initialize SPAR TD handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_transient_det_open_fx( + ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ + const Word32 sampling_rate /* i : sampling rate */ +) +{ + ivas_trans_det_state_t *hTranDet; + + IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); + } + ivas_transient_det_init( hTranDet, sampling_rate ); + + *hTranDet_in = hTranDet; + + return IVAS_ERR_OK; +} +#else ivas_error ivas_transient_det_open( ivas_trans_det_state_t **hTranDet_in, /* i/o: Transient detector handle */ const Word32 sampling_rate /* i : sampling rate */ @@ -358,7 +377,7 @@ ivas_error ivas_transient_det_open( { ivas_trans_det_state_t *hTranDet; - IF( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) + if ( ( hTranDet = (ivas_trans_det_state_t *) malloc( sizeof( ivas_trans_det_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR TD\n" ); } @@ -369,6 +388,7 @@ ivas_error ivas_transient_det_open( return IVAS_ERR_OK; } +#endif /*------------------------------------------------------------------------- @@ -376,7 +396,23 @@ ivas_error ivas_transient_det_open( * * Deallocate and initialize Transient detector handle *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_transient_det_close_fx( + ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ +) +{ + test(); + IF( hTranDet == NULL || *hTranDet == NULL ) + { + return; + } + + free( *hTranDet ); + *hTranDet = NULL; + return; +} +#else void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ) @@ -392,6 +428,7 @@ void ivas_transient_det_close( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* diff --git a/lib_com/prot.h b/lib_com/prot.h index 1f54c2b1b..d15bb767d 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -522,11 +522,6 @@ ivas_error push_next_bits( #endif // IVAS_FLOAT_FIXED /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - Word16 get_ivas_max_num_indices_fx( const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ @@ -538,11 +533,6 @@ int16_t get_BWE_max_num_indices( ); /*! r: maximum number of indices */ -int16_t get_ivas_max_num_indices_metadata( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : IVAS total bitrate */ -); - 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 */ @@ -9940,11 +9930,6 @@ int16_t is_EVS_bitrate( int16_t *Opt_AMR_WB /* i : AMR-WB IO flag */ ); -/*! r: codec mode */ -int16_t get_codec_mode( - const int32_t total_brate /* i : total bitrate */ -); - int16_t getTcxonly_ivas( const int16_t element_mode, /* i : IVAS element mode */ const int32_t total_brate, /* i : total bitrate */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index de27c37c2..3239613af 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1262,13 +1262,6 @@ void indices_to_serial_generic( Word16 *pFrame_size /* i/o: number of bits in the binary encoded access unit [bits] */ ); -void dec_prm_core( - Decoder_State *st ); - -void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -); - Word16 BRATE2IDX_fx( Word32 brate ); Word16 BRATE2IDX16k_fx( Word32 brate ); @@ -1743,20 +1736,20 @@ void Comp_and_apply_gain_ivas_fx( 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 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); void pre_echo_att_ivas_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 gsc_attack_flag_fx, /* i : flag signalling attack encoded by AC mode (GSC) Q0*/ const Word16 Q_new, - const Word16 last_coder_type, /* i : Last coding mode */ - const Word16 L_frame /* i : Frame length*/ + const Word16 last_coder_type, /* i : Last coding mode Q0*/ + const Word16 L_frame /* i : Frame length Q0*/ ); // wtda_fx.c void tcx_get_windows_mode1( @@ -2163,21 +2156,21 @@ hq2_bit_alloc_fx.c /========================================================================================================*/ void Bits2indvsb_fx( - const Word32 *L_be, /* i : Q14 Band Energy of sub-band */ + const Word32 *L_be, /* i : Qbe 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 */ + const Word32 L_Bits_needed, /* i : QRk smallest bit number for allocation in group */ + Word32 *L_Rsubband, /* o : QRk 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 */ + 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 : Q18 sub-band bit-allocation vector */ - Word16 p2a_bands_fx, /* i : Q0 highfreq bands */ + Word32 *L_Rsubband, /* o : QRk 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 */ @@ -2185,16 +2178,16 @@ 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 : i bandwidth */ - const Word16 is_transient /* i : indicator HQ_TRANSIENT or not */ + const Word16 bands, /* i : total number of subbands in a frame Q0*/ + Word32 L_Rk[], /* i/o: Bit allocation/Adjusted bit alloc. QRk*/ + Word16 *bit_budget_fx, /* i/o: bit bugdet Q0*/ + Word16 *p2a_flags, /* i : HF tonal indicator Q0*/ + const Word16 weight_fx, /* i : weight Q13*/ + const Word16 band_width[], /* i : Sub band bandwidth Q0*/ + const Word16 num_bits, /* i : available bits Q0*/ + const Word16 hqswb_clas, /* i : HQ2 class information Q0*/ + const Word16 bwidth, /* i : input bandwidth Q0*/ + const Word16 is_transient /* i : indicator HQ_TRANSIENT or not Q0*/ ); void reordvct_fx( @@ -3919,6 +3912,7 @@ int16_t get_cng_mode( ); // core_com_config.c +/*! r: codec mode */ Word16 get_codec_mode( const Word32 total_brate /* i : total bitrate */ ); @@ -9192,38 +9186,44 @@ void dlpc_bfi( // guided_plc_util_fx.c void getLookAheadResSig( - Word16 *speechLookAhead, - Word16 *A_3Q12, - Word16 *res, - const Word16 L_frame, - const Word16 numSubFrame ); + Word16 *speechLookAhead, /* Qx */ + Word16 *A_3Q12, /* 3Q12 */ + Word16 *res, /* Qx */ + const Word16 L_frame, /* Q0 */ + const Word16 numSubFrame /* Q0 */ +); void updateLSFForConcealment( PLC_ENC_EVS_HANDLE decState, - Word16 *lsf_14Q1 ); + Word16 *lsf_14Q1 /* 14Q1 */ +); void getConcealedLP( PLC_ENC_EVS_HANDLE memDecState, - Word16 *AqCon, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + Word16 *AqCon, /* 14Q1 */ + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void getConcealedLSF( PLC_ENC_EVS_HANDLE memDecState, - const Word16 lsfBase[], - const Word16 last_good, - const Word16 L_frame ); + const Word16 lsfBase[], /* Q1 * 1.28 */ + const Word16 last_good, /* Q0 */ + const Word16 L_frame /* Q0 */ +); void RecLpcSpecPowDiffuseLc( - Word16 *lspq, - Word16 *lsp_old, - Word16 *lsfq, + Word16 *lspq, /* Q15 */ + Word16 *lsp_old, /* Q15 */ + Word16 *lsfq, /* Q2.56 */ Decoder_State *st, - const Word16 reset_q ); + const Word16 reset_q /* Q0 */ +); void modify_lsf( - Word16 *lsf, - const Word16 n, - const Word32 sr_core, - const Word16 reset_q ); + Word16 *lsf, /* Q14 */ + const Word16 n, /* Q0 */ + const Word32 sr_core, /* Q0 */ + const Word16 reset_q /* Q0 */ +); // er_dec_tcx_fx.c void con_tcx_fx( diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 9fb4736f1..c36c6eabd 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -39,6 +39,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "math.h" /*-------------------------------------------------------------------* * ivas_corecoder_enc_reconfig() * @@ -504,7 +505,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { Word16 n, sce_id, cpe_id; Word16 len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing; - float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + + Word32 input_buff_fx[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )]; + FOR( int i = 0; i < MCT_MAX_BLOCKS; i++ ) + { + set32_fx( input_buff_fx[i], 0, L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS ) ); + } BSTR_ENC_HANDLE hBstr; Word16 i, nb_bits; Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST]; @@ -531,7 +537,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nchan_transport_real = st_ivas->nchan_transport; move16(); - if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { nchan_transport_real = add( nchan_transport_real, st_ivas->hEncoderConfig->nchan_ism ); } @@ -571,7 +577,6 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, tmp ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - // st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ move32(); } } @@ -621,9 +626,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( nb_bits = 0; move16(); - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( hBstr->ind_list[i].nb_bits > 0 ) { temp_ind_list[i].id = hBstr->ind_list[i].id; @@ -653,28 +658,95 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + Word16 q_com_sce = 0; + Word16 q_com_cpe = 0; + + Word16 gb = find_guarded_bits_fx( len_inp_memory ); + IF( nSCE_old > 0 ) + { + float max_val = 0.0f; + for ( int k = 0; k < nSCE_old; k++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff[i] ) ); + } + } + q_com_sce = L_get_q1( max_val ) - gb; + } + + IF( nCPE_old > 0 ) + { + float max_val = 0.0f; + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + for ( i = 0; i < len_inp_memory; i++ ) + { + max_val = max( max_val, (float) fabs( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff[i] ) ); + } + } + } + q_com_cpe = L_get_q1( max_val ) - gb; + } + + Word16 q_com = min( q_com_sce, q_com_cpe ); + IF( nSCE_old > 0 ) + { + for ( int k = 0; k < nSCE_old; k++ ) + { + st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32 = q_com; + } + for ( int k = 0; k < nSCE_old; k++ ) + { + floatToFixed_arrL( st_ivas->hSCE[k]->hCoreCoder[0]->input_buff, st_ivas->hSCE[k]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[k]->hCoreCoder[0]->q_inp32, len_inp_memory ); + } + } + + IF( nCPE_old > 0 ) + { + + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32 = q_com; + } + } + FOR( cpe_id = 0; cpe_id < nCPE_old; cpe_id++ ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + floatToFixed_arrL( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->q_inp32, len_inp_memory ); + } + } + } +#endif test(); test(); IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* within McMASA we can modify the transport signals when switching */ /* copy earlier dmx buffers */ + IF( nSCE_old > 0 ) { - set_zero( input_buff[0], len_inp_memory ); - mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory ); + set32_fx( input_buff_fx[0], 0, len_inp_memory ); + Copy32( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[0], len_inp_memory ); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set_zero( input_buff[n + 1], len_inp_memory ); + set32_fx( input_buff_fx[n + 1], 0, len_inp_memory ); IF( nCPE_old > 0 ) { - mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory ); + Copy32( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[n + 1], len_inp_memory ); } } - ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); + ivas_mcmasa_dmx_modify_fx( len_inp_memory, input_buff_fx, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE ); n_CoreCoder_existing = 0; move16(); @@ -690,9 +762,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* save input audio buffers */ IF( GT_16( n_CoreCoder_existing, sce_id ) ) { - mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory ); + Copy32( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, input_buff_fx[sce_id], len_inp_memory ); } - destroy_sce_enc( st_ivas->hSCE[sce_id], ( EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) && !st_ivas->hEncoderConfig->stereo_dmx_evs ) ); st_ivas->hSCE[sce_id] = NULL; } @@ -704,14 +775,12 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { IF( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n ) { - mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); + Copy32( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, input_buff_fx[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory ); } } - destroy_cpe_enc( st_ivas->hCPE[cpe_id] ); st_ivas->hCPE[cpe_id] = NULL; } - test(); IF( LE_16( st_ivas->nCPE, 1 ) && st_ivas->hMCT != NULL ) { @@ -752,9 +821,8 @@ ivas_error ivas_corecoder_enc_reconfig_fx( test(); IF( GT_16( n_CoreCoder_existing, sce_id ) && NE_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } - test(); /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ IF( sce_id > 0 || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) @@ -785,7 +853,14 @@ ivas_error ivas_corecoder_enc_reconfig_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { copy_encoder_config_fx( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); // CPE_CHANNELS + } move32(); test(); @@ -818,9 +893,10 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* propagate input audio buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { + IF( GT_16( n_CoreCoder_existing, add( i_mult( cpe_id, CPE_CHANNELS ), n ) ) ) { - mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } @@ -829,7 +905,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ test(); test(); - IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) + IF( add( i_mult( cpe_id, CPE_CHANNELS ), n ) > 0 || ( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->nSCE > 0 ) ) { reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot ); } @@ -850,9 +926,9 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); IF( st_ivas->nSCE > 0 ) { - test(); WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -876,6 +952,7 @@ ivas_error ivas_corecoder_enc_reconfig_fx( { WHILE( LT_16( nb_bits, nb_bits_tot ) && LT_16( i, MAX_NUM_IND_TEMP_LIST ) ) { + test(); IF( temp_ind_list[i].nb_bits > 0 ) { st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id; @@ -895,26 +972,42 @@ ivas_error ivas_corecoder_enc_reconfig_fx( move16(); } - + test(); IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* restore modified transport signal */ IF( st_ivas->nSCE ) { - mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, len_inp_memory ); } IF( st_ivas->nCPE ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory ); + Copy32( input_buff_fx[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, len_inp_memory ); } } } test(); test(); + +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + IF( st_ivas->nSCE ) + { + fixedToFloat_arrL( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff32_fx, st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, q_com, len_inp_memory ); + } + + IF( st_ivas->nCPE ) + { + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + fixedToFloat_arrL( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff32_fx, st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, q_com, len_inp_memory ); + } + } +#endif + IF( GT_16( st_ivas->nCPE, 1 ) && LE_16( nCPE_old, 1 ) ) { IF( EQ_16( nCPE_old, 1 ) ) @@ -986,17 +1079,11 @@ ivas_error ivas_corecoder_enc_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[0]->element_brate, 42949673 ) ) /* 1/50 in Q31*/; // ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC ); -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, - L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), - st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, - st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); -#else + st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent_fx( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, L_mult0( st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal, FRAMES_PER_SEC ), st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ); -#endif move16(); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 1a5a95af5..bb6a9dc84 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -773,8 +773,8 @@ ivas_error ivas_enc( /*----------------------------------------------------------------* * Encoding *----------------------------------------------------------------*/ - - if ( ivas_format == STEREO_FORMAT ) + test(); + IF( EQ_32( ivas_format, STEREO_FORMAT ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK ) @@ -782,7 +782,7 @@ ivas_error ivas_enc( return error; } } - else if ( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { /* select ISM format mode; reconfigure the ISM format encoder */ if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK ) @@ -968,9 +968,7 @@ ivas_error ivas_enc( v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } -#endif -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < st_ivas->nchan_transport; i++ ) { floatToFixed_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); @@ -985,65 +983,53 @@ ivas_error ivas_enc( fixedToFloat_arrL( st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state, Q11, st_ivas->hMasa->data.cldfbAnaEnc[i]->cldfb_state_length ); } #endif -#else - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#endif -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_omasa_enc_config_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; + move16(); data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS]; data_separated_object_fx = data_fx[hEncoderConfig->nchan_ism + CPE_CHANNELS]; /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - /* Estimate MASA parameters for the objects */ -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; - int16_t j; - int16_t nchan_transport = st_ivas->nchan_transport; - int16_t nchan_ism = hEncoderConfig->nchan_ism; - int16_t norm_data_in = MAX16B; - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) + /* Scaling data_fx */ { - for ( int k = 0; k < input_frame; k++ ) + Word16 norm_data_in = MAX16B; + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { - data_fx[j][k] = float_to_fix( data_f[j][k], st_ivas->q_data_fx ); + norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) ); } - norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[j], input_frame ) ); - } - norm_data_in -= 6; /*guard bit is 3->to handle overflow in cldfbAnalysis*/ - for ( j = 0; j < nchan_ism + nchan_transport; j++ ) - { - Scale_sig32( data_fx[j], input_frame, norm_data_in ); + norm_data_in = sub( norm_data_in, 6 ); /*guard bit is 3->to handle overflow in cldfbAnalysis*/ + FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) + { + scale_sig32( data_fx[i], input_frame, norm_data_in ); + } + st_ivas->q_data_fx = add( st_ivas->q_data_fx, norm_data_in ); + move16(); } - st_ivas->q_data_fx = st_ivas->q_data_fx + norm_data_in; - for ( i = 0; i < nchan_ism; i++ ) +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + OMASA_ENC_HANDLE hOMasa = st_ivas->hOMasa; + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { floatToFixed_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state, hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } #endif + + /* Estimate MASA parameters for the objects */ ivas_omasa_enc_fx( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_fx, st_ivas->q_data_fx, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object_fx, &idx_separated_object ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < nchan_ism; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism; i++ ) { fixedToFloat_arrL( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state, st_ivas->q_data_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length ); } - for ( i = 0; i < nchan_ism + nchan_transport; i++ ) + for ( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } @@ -1053,39 +1039,37 @@ ivas_error ivas_enc( /* Encode ISMs transport channels */ n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + IF( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { -#ifdef IVAS_FLOAT_FIXED flag_omasa_ener_brate = ivas_omasa_ener_brate_fx( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#else - flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_fx, input_frame, sub( 31, st_ivas->q_data_fx ) ); -#endif // IVAS_FLOAT_FIXED /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } n = st_ivas->hEncoderConfig->nchan_ism; + move16(); } hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; - if ( st_ivas->nSCE > 0 ) + IF( st_ivas->nSCE > 0 ) { /* update pointer to the buffer of indices (ISM indices were alredy written) */ hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; @@ -1108,14 +1092,14 @@ ivas_error ivas_enc( ); /* Encode MASA transport channels */ - if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { - int16_t planar_sba_orig; + Word16 planar_sba_orig; planar_sba_orig = hEncoderConfig->sba_planar; #ifdef IVAS_FLOAT_FIXED /* Analyze objects and determine needed audio signals */ @@ -1200,10 +1184,10 @@ ivas_error ivas_enc( } } } - else if ( EQ_32( ivas_format, MC_FORMAT ) ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1239,14 +1223,14 @@ ivas_error ivas_enc( fixedToFloat_arrL( data_fx[LFE_CHANNEL], data_f[LFE_CHANNEL], st_ivas->q_data_fx, input_frame ); #endif - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { /* encode MC ParamUpmix parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1292,7 +1276,7 @@ ivas_error ivas_enc( return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { /* encode Parametric MC parameters and write bitstream */ #ifdef IVAS_FLOAT_FIXED @@ -1334,72 +1318,65 @@ ivas_error ivas_enc( } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { if ( st_ivas->hMcMasa->separateChannelEnabled ) { hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */ } -#ifdef IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 q_data = Q8; - for ( i = 0; i < nchan_inp; i++ ) + + FOR( i = 0; i < nchan_inp; i++ ) { - floatToFixed_arrL32( data_f[i], data_fx[i], q_data, input_frame ); + scale_sig32( data_fx[i], input_frame, Q8 - Q11 ); // Q11 -> Q8 } -#endif - ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, q_data ); + st_ivas->q_data_fx = Q8; + move16(); + + ivas_mcmasa_enc_fx( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_fx, input_frame, st_ivas->nchan_transport, nchan_inp, st_ivas->q_data_fx ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( i = 0; i < nchan_inp; i++ ) { - fixedToFloat_arrL( data_fx[i], data_f[i], q_data, input_frame ); + fixedToFloat_arrL( data_fx[i], data_f[i], st_ivas->q_data_fx, input_frame ); } - Word32 ii, jj; - Word16 nBands = st_ivas->hMcMasa->nbands; - Word16 nBlocks = MAX_PARAM_SPATIAL_SUBFRAMES; - FOR( ii = 0; ii < nBands; ii++ ) +#endif + /* Scaling down the Q-factor of energy_ratio_fx from Q31 to Q30 */ + FOR( i = 0; i < st_ivas->hMcMasa->nbands; i++ ) { - FOR( jj = 0; jj < nBlocks; jj++ ) - { - st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj] = L_shr( st_ivas->hQMetaData->q_direction[0].band_data[ii].energy_ratio_fx[jj], 1 ); // Q31 -> Q30 - } + scale_sig32( st_ivas->hQMetaData->q_direction[0].band_data[i].energy_ratio_fx, MAX_PARAM_SPATIAL_SUBFRAMES, -1 ); // Q31 -> Q30 } -#endif -#else - ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); -#endif + IF( ( error = ivas_masa_encode_fx( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1, ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hMcMasa->separateChannelEnabled ) + IF( st_ivas->hMcMasa->separateChannelEnabled ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) { return error; } st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else + ELSE { - if ( st_ivas->nSCE == 1 ) + IF( EQ_16( st_ivas->nSCE, 1 ) ) { - if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } } - else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 3114ae478..e0fd58802 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -567,7 +567,11 @@ void ivas_initialize_handles_enc( st_ivas->hCPE[i] = NULL; } +#ifdef IVAS_FLOAT_FIXED + st_ivas->mem_hp20_in_fx = NULL; +#else st_ivas->mem_hp20_in = NULL; +#endif /* ISM metadata handles */ FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -711,7 +715,7 @@ ivas_error ivas_init_encoder( *-----------------------------------------------------------------*/ /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( ivas_format, ivas_total_brate ); + 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 ) @@ -726,7 +730,7 @@ ivas_error ivas_init_encoder( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); + 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 ) @@ -765,7 +769,7 @@ ivas_error ivas_init_encoder( test(); IF( NE_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) ) { - IF( NE_32( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } @@ -817,7 +821,7 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + if ( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1260,6 +1264,7 @@ ivas_error ivas_init_encoder( n = getNumChanAnalysis_fx( st_ivas ); #endif +#ifndef IVAS_FLOAT_FIXED if ( n > 0 ) { if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL ) @@ -1281,7 +1286,7 @@ ivas_error ivas_init_encoder( set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -1321,41 +1326,52 @@ ivas_error ivas_init_encoder_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); hEncoderConfig = st_ivas->hEncoderConfig; ivas_format = hEncoderConfig->ivas_format; + move32(); input_Fs = hEncoderConfig->input_Fs; + move32(); ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); hEncoderConfig->last_ivas_total_brate = ivas_total_brate; + move32(); 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 ) ); + move16(); } st_ivas->ism_mode = ISM_MODE_NONE; + move32(); st_ivas->mc_mode = MC_MODE_NONE; + move32(); st_ivas->nchan_transport = -1; + move16(); /*-----------------------------------------------------------------* * Allocate floating-point input audio buffers *-----------------------------------------------------------------*/ nchan_inp_buff = hEncoderConfig->nchan_inp; + move16(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { nchan_inp_buff = 0; + move16(); } 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 = add( nchan_inp_buff, 1 ); } - nchan_inp_buff++; /* for *data_separated_object */ + nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object */ } #if 1 /* To be removed */ FOR( n = 0; n < nchan_inp_buff; n++ ) @@ -1391,6 +1407,7 @@ ivas_error ivas_init_encoder_fx( /* 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 ); + move16(); /* allocate buffer of indices */ IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1402,11 +1419,12 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ ) { st_ivas->ind_list[i].nb_bits = -1; + move16(); } /* 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 ); - + move16(); /* allocate buffer of metadata indices */ IF( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1419,6 +1437,7 @@ ivas_error ivas_init_encoder_fx( FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ ) { st_ivas->ind_list_metadata[i].nb_bits = -1; + move16(); } } ELSE @@ -1429,7 +1448,7 @@ ivas_error ivas_init_encoder_fx( /*-----------------------------------------------------------------* * Allocate and initialize SCE/CPE and other handles *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( ivas_format, MONO_FORMAT ) ) { st_ivas->nSCE = 1; /* in mono, there is always only one SCE */ @@ -1469,35 +1488,40 @@ ivas_error ivas_init_encoder_fx( ELSE IF( ivas_format == STEREO_FORMAT ) { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */ + move16(); st_ivas->nchan_transport = CPE_CHANNELS; + move16(); cpe_id = 0; + move16(); - IF( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) ) { st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); + move32(); - IF( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ), 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, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ), IVAS_ERR_OK ) ) { return error; } } - IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - IF( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_ism_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1505,48 +1529,39 @@ ivas_error ivas_init_encoder_fx( IF( st_ivas->hEncoderConfig->Opt_DTX_ON ) { - IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_dtx_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) ) { - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - IF( ivas_format == SBA_FORMAT ) + IF( EQ_32( ivas_format, SBA_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif + move16(); - IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - IF( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } ELSE { st_ivas->nchan_transport = hEncoderConfig->nchan_inp; + move16(); - IF( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1554,20 +1569,25 @@ ivas_error ivas_init_encoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } - + test(); IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON ) { st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1; + move16(); } } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1577,297 +1597,283 @@ ivas_error ivas_init_encoder_fx( IF( hEncoderConfig->Opt_DTX_ON ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); } } } - if ( st_ivas->nCPE > 1 ) + IF( st_ivas->nCPE > 1 ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { - int32_t ism_total_brate; - int16_t k; + Word32 ism_total_brate; + Word16 k; -#ifndef IVAS_FLOAT_FIXED - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); -#else st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); move32(); -#endif st_ivas->nchan_transport = 2; + move16(); - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + move16(); + test(); + WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) ) { - k++; + k = add( k, 1 ); } ism_total_brate = 0; - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + move32(); + 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 ) + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + IF( NE_32( ( 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_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - if ( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_omasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); } - else + ELSE { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + move16(); } - if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->ism_mode = ISM_MODE_NONE; + move32(); - if ( ivas_total_brate >= IVAS_256k ) + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move32(); } - if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ), IVAS_ERR_OK ) ) { return error; } /* allocate and initialize SBA handles */ - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#else st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); -#endif - if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - if ( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* allocate and initialize SBA core-coders */ - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { - if ( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ), IVAS_ERR_OK ) ) { return error; } } - 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_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else + ELSE { /* allocate and initialize MCT core coder */ - st_ivas->nCPE += ( st_ivas->hEncoderConfig->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); - 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_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_osba_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } - else if ( ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( ivas_format, MC_FORMAT ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#else st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); -#endif + move32(); - if ( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ), IVAS_ERR_OK ) ) { return error; } - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( NE_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; + move16(); + st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); + 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_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( 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 ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } -#ifndef IVAS_FLOAT_FIXED - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); -#else st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); -#endif + move16(); } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; - st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); + st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); - if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - 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_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 res_dec, res_frac; + iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) { return error; } } - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( 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 ) + IF( NE_32( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) { -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - 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_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->nCPE > 1 ) + IF( GT_16( st_ivas->nCPE, 1 ) ) { - if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_enc( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - int32_t brate_sce, brate_cpe; + Word32 brate_sce, brate_cpe; -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); -#endif - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_masa_enc_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1878,31 +1884,27 @@ ivas_error ivas_init_encoder_fx( return error; } #else - if ( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } #endif - -#ifndef IVAS_FLOAT_FIXED - ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#else ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); -#endif - 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_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) + IF( NE_32( ( 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++ ) + FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + move16(); - if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ), IVAS_ERR_OK ) ) { return error; } @@ -1916,30 +1918,6 @@ ivas_error ivas_init_encoder_fx( /* set number of input channels used for analysis/coding */ n = getNumChanAnalysis_fx( st_ivas ); -#if 1 // To be removed - if ( n > 0 ) - { - 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 ) - { - 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 ); - } -#endif - /*Fixed point init*/ IF( n > 0 ) { IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL ) @@ -2156,7 +2134,7 @@ void ivas_destroy_enc( } /* HP20 filter handles */ - if ( st_ivas->mem_hp20_in != NULL ) + if ( st_ivas->mem_hp20_in_fx != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2168,6 +2146,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in_fx ); st_ivas->mem_hp20_in_fx = NULL; } +#ifndef IVAS_FLOAT_FIXED if ( st_ivas->mem_hp20_in != NULL ) { n = getNumChanAnalysis_fx( st_ivas ); @@ -2180,6 +2159,7 @@ void ivas_destroy_enc( free( st_ivas->mem_hp20_in ); st_ivas->mem_hp20_in = NULL; } +#endif /* ISM metadata handles */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); diff --git a/lib_enc/ivas_ism_dtx_enc.c b/lib_enc/ivas_ism_dtx_enc.c index c1947034d..5b90cb9f8 100644 --- a/lib_enc/ivas_ism_dtx_enc.c +++ b/lib_enc/ivas_ism_dtx_enc.c @@ -69,26 +69,30 @@ ivas_error ivas_ism_dtx_open( { ivas_error error; ISM_DTX_HANDLE hISMDTX; - int16_t i; + Word16 i; error = IVAS_ERR_OK; + move32(); /* Assign memory to DirAC handle */ - if ( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) + IF( ( hISMDTX = (ISM_DTX_HANDLE) malloc( sizeof( ISM_DTX_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM DTX Handle \n" ) ); } hISMDTX->dtx_flag = 0; + move16(); hISMDTX->sce_id_dtx = 0; + move16(); hISMDTX->cnt_SID_ISM = -1; + move16(); - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + FOR( i = 0; i < MAX_NUM_OBJECTS; i++ ) { - set_f( hISMDTX->long_term_energy_stereo_dmx_enc[i], 0.0f, PARAM_ISM_HYS_BUF_SIZE ); + set32_fx( hISMDTX->long_term_energy_stereo_dmx_enc_fx[i], 0, PARAM_ISM_HYS_BUF_SIZE ); } - set_f( hISMDTX->coh, 0.0f, MAX_NUM_OBJECTS ); + set16_fx( hISMDTX->coh_fx, 0, MAX_NUM_OBJECTS ); st_ivas->hISMDTX = hISMDTX; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 982b35550..64f64b721 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -1518,7 +1518,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_ism_metadata_enc_create( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const int16_t n_ISms, /* i : number of objects */ + const Word16 n_ISms, /* i : number of objects */ Word32 element_brate_tmp[] /* o : element bitrate per object */ ) { @@ -1527,27 +1527,25 @@ ivas_error ivas_ism_metadata_enc_create( nchan_transport = st_ivas->nchan_transport; move16(); - IF( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { nchan_transport = MAX_PARAM_ISM_WAVE; -#ifndef IVAS_FLOAT_FIXED - ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#else + move16(); ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#endif } - ELSE IF( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) { nchan_transport = n_ISms; + move16(); } ELSE { - IF( st_ivas->ism_mode == ISM_MODE_NONE ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { nchan_transport = st_ivas->nchan_transport; move16(); - IF( nchan_transport == 1 ) + IF( EQ_16( nchan_transport, 1 ) ) { st_ivas->nSCE = 1; move16(); @@ -1562,7 +1560,7 @@ ivas_error ivas_ism_metadata_enc_create( move16(); } } - ELSE IF( st_ivas->ism_mode == ISM_MODE_PARAM ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { nchan_transport = 2; move16(); @@ -1623,37 +1621,39 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->hIsmMetaData[ch]->q_elevation_old_fx = 0; move16(); -#ifdef IVAS_FLOAT_FIXED ivas_ism_reset_metadata_enc( st_ivas->hIsmMetaData[ch] ); -#else - ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); -#endif - st_ivas->hIsmMetaData[ch]->last_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_azimuth_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->last_true_elevation_fx = 0; + move32(); st_ivas->hIsmMetaData[ch]->ism_md_fec_cnt_enc = 0; + move16(); st_ivas->hIsmMetaData[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; + move16(); st_ivas->hIsmMetaData[ch]->last_true_radius_fx = ONE_IN_Q9; + move16(); } IF( EQ_16( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { test(); - IF( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1661,7 +1661,7 @@ ivas_error ivas_ism_metadata_enc_create( } ELSE { - IF( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_config_fx( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 9b975d935..63354efd4 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2254,10 +2254,10 @@ ivas_error ivas_masa_enc_config( * Determine if surrounding coherence is significant in this frame and should be encoded *-----------------------------------------------------------------------*/ UWord8 ivas_masa_surrcoh_signicant_fx( - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence */ - Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio */ - const Word16 nSubFrames, /* i : Number of sub frames */ - const Word16 nBands /* i : Number of frequency bands */ /* i : dynamic (min q for surroundingCoherence and diffuse_to_total_ratio) */ + Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ + Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ + const Word16 nSubFrames, /* i : Number of sub frames */ + const Word16 nBands /* i : Number of frequency bands */ ) { Word32 significanceMeasure1, significanceMeasure2, significanceMeasure; @@ -2287,17 +2287,17 @@ UWord8 ivas_masa_surrcoh_signicant_fx( FOR( band = 0; band < nBands; band++ ) { - surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // 2Q -> Q + surrCohToTotal = Mpy_32_32( diffuse_to_total_ratio[sf][band], surroundingCoherence[sf][band] ); // Q31 surrCohToTotalSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalSum, surrCohToTotalSum_e, surrCohToTotal, 0, &surrCohToTotalSum_e ); - surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); // Q2 -> Q - diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); // Q + surrCohToTotalTimesDiffSum = BASOP_Util_Add_Mant32Exp( surrCohToTotalTimesDiffSum, surrCohToTotalTimesDiffSum_e, Mpy_32_32( (Word32) diffuse_to_total_ratio[sf][band], surrCohToTotal ), 0, &surrCohToTotalTimesDiffSum_e ); + diffSum = BASOP_Util_Add_Mant32Exp( diffSum, diffSum_e, diffuse_to_total_ratio[sf][band], 0, &diffSum_e ); } Word16 significanceMeasure1_e, significanceMeasure2_e; Word16 significanceMeasure_e; - significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); // e1 exponent + significanceMeasure1 = L_deposit_h( BASOP_Util_Divide3216_Scale( surrCohToTotalSum, nBands, &significanceMeasure1_e ) ); significanceMeasure1_e = add( significanceMeasure1_e, sub( surrCohToTotalSum_e, 15 ) ); - significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); // e2 exponent + significanceMeasure2 = L_deposit_h( BASOP_Util_Divide3232_Scale( Mpy_32_32( surrCohSignificanceCoef, surrCohToTotalTimesDiffSum ), L_add( diffSum, EPSILON_FX ), &significanceMeasure2_e ) ); significanceMeasure2_e = add( significanceMeasure2_e, sub( surrCohToTotalTimesDiffSum_e, diffSum_e ) ); IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure1, significanceMeasure1_e, significanceMeasure2, significanceMeasure2_e ) > 0 ) @@ -2314,7 +2314,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( significanceMeasure_e = significanceMeasure2_e; move16(); } - IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) // Q31 Comparision + IF( BASOP_Util_Cmp_Mant32Exp( significanceMeasure, significanceMeasure_e, threshold, 0 ) > 0 ) { return 1; } @@ -8903,9 +8903,9 @@ static void ivas_encode_masaism_metadata_fx( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_merge_masa_transports_fx( - Word32 data_in_f1_fx[][L_FRAME48k], - Word32 *data_in_f2_fx[], - Word32 *data_out_f_fx[], + Word32 data_in_f1_fx[][L_FRAME48k], // Qx + Word32 *data_in_f2_fx[], // Qx + Word32 *data_out_f_fx[], // Qx const Word16 input_frame, const Word16 num_transport_channels ) { diff --git a/lib_enc/ivas_mc_paramupmix_enc.c b/lib_enc/ivas_mc_paramupmix_enc.c index 7e4902855..d26e6bee4 100644 --- a/lib_enc/ivas_mc_paramupmix_enc.c +++ b/lib_enc/ivas_mc_paramupmix_enc.c @@ -258,7 +258,7 @@ ivas_error ivas_mc_paramupmix_enc_open( /* Transient Detector handle */ FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - IF( ( error = ivas_transient_det_open( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hMCParamUpmix->hTranDet[i] ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -600,7 +600,7 @@ void ivas_mc_paramupmix_enc_close( FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS * MC_PARAMUPMIX_NCH; i++ ) { - ivas_transient_det_close( &( *hMCParamUpmix )->hTranDet[i] ); + ivas_transient_det_close_fx( &( *hMCParamUpmix )->hTranDet[i] ); } IF( ( *hMCParamUpmix )->hFbMixer != NULL ) diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 57de41384..c38bd5ec6 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -190,7 +190,6 @@ ivas_error ivas_mcmasa_enc_open_fx( Word16 maxBin, input_frame; Word16 nchan_inp; Word32 input_Fs; - Word32 dirac_slot_ns; IVAS_FB_CFG *fb_cfg, *fb_cfgLfe; ivas_error error; @@ -370,8 +369,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } - dirac_slot_ns = DIRAC_SLOT_ENC_NS; - move32(); + /*dirac_slot_ns = DIRAC_SLOT_ENC_NS;*/ /* intensity 3-dim */ FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -406,7 +404,7 @@ ivas_error ivas_mcmasa_enc_open_fx( } } - hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hMcMasa->no_col_avg_diff = (Word8) ( DIRAC_NO_COL_AVG_DIFF_NS / DIRAC_SLOT_ENC_NS ); /* dirac_slot_ns = DIRAC_SLOT_ENC_NS */ move16(); FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) @@ -445,41 +443,41 @@ ivas_error ivas_mcmasa_enc_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for McMasa\n" ) ); } - set_zero_fx( hMcMasa->buffer_energy_fx, hMcMasa->nbands * hMcMasa->no_col_avg_diff ); + set_zero_fx( hMcMasa->buffer_energy_fx, imult1616( hMcMasa->nbands, hMcMasa->no_col_avg_diff ) ); set16_fx( hMcMasa->buffer_intensity_real_vert_q, 31, DIRAC_NO_COL_AVG_DIFF ); set16_fx( hMcMasa->buffer_energy_q, 31, DIRAC_NO_COL_AVG_DIFF ); - IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 ) + IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1 ) ) { - Copy32( ls_azimuth_CICP6_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP6_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP6_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP6_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_7_1 ) ) { - Copy32( ls_azimuth_CICP12_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP12_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP12_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP12_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 1; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_2 ) ) { - Copy32( ls_azimuth_CICP14_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP14_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP14_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP14_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; move16(); } - ELSE IF( st_ivas->hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 ) + ELSE IF( EQ_32( st_ivas->hEncoderConfig->mc_input_setup, MC_LS_SETUP_5_1_4 ) ) { - Copy32( ls_azimuth_CICP16_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP16_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP16_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP16_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 5; move16(); hMcMasa->isHorizontalSetup = 0; @@ -487,8 +485,8 @@ ivas_error ivas_mcmasa_enc_open_fx( } ELSE { - Copy32( ls_azimuth_CICP19_fx, ls_azimuth, nchan_inp - 1 ); - Copy32( ls_elevation_CICP19_fx, ls_elevation, nchan_inp - 1 ); + Copy32( ls_azimuth_CICP19_fx, ls_azimuth, sub( nchan_inp, 1 ) ); + Copy32( ls_elevation_CICP19_fx, ls_elevation, sub( nchan_inp, 1 ) ); hMcMasa->numHorizontalChannels = 7; move16(); hMcMasa->isHorizontalSetup = 0; @@ -506,23 +504,23 @@ ivas_error ivas_mcmasa_enc_open_fx( computeEvenLayout_fx( ls_azimuth, ls_azimuth_even, hMcMasa->numHorizontalChannels ); IF( !hMcMasa->isHorizontalSetup ) { - computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], numAnalysisChannels - hMcMasa->numHorizontalChannels ); + computeEvenLayout_fx( &ls_azimuth[hMcMasa->numHorizontalChannels], &ls_azimuth_even[hMcMasa->numHorizontalChannels], sub( numAnalysisChannels, hMcMasa->numHorizontalChannels ) ); } FOR( i = 0; i < numAnalysisChannels; i++ ) { hMcMasa->chnlToFoaMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[1][i] = L_mult( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 /*32767/360*/ ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaMtx_fx[2][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); - hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); + hMcMasa->chnlToFoaMtx_fx[3][i] = L_mult( getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth[i], 91 ), 7 ) ) ), getCosWord16R2( extract_l( L_shr( Mult_32_16( ls_elevation[i], 91 ), 7 ) ) ) ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[0][i] = ONE_IN_Q31; move32(); - hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); + hMcMasa->chnlToFoaEvenMtx_fx[1][i] = L_shl( getSineWord16R2( extract_l( L_shr( Mult_32_16( ls_azimuth_even[i], 91 ), 7 ) ) ), 16 ); // Q31 move32(); hMcMasa->chnlToFoaEvenMtx_fx[2][i] = 0; move32(); @@ -1215,11 +1213,11 @@ void ivas_mcmasa_enc_fx( MCMASA_ENC_HANDLE hMcMasa, /* i/o: Encoder McMASA handle */ IVAS_QMETADATA_HANDLE hQMeta, /* o : Qmetadata handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: Encoder MASA handle */ - Word32 *data_fx[], /* i : Input frame of audio */ + Word32 *data_fx[], /* i : Input frame of audio Q(q_inp) */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Input data q-format */ + const Word16 q_inp /* i : Input data q-format */ ) { Word16 i, j, k; @@ -1270,6 +1268,8 @@ void ivas_mcmasa_enc_fx( { hMasa->data.lfeToTotalEnergyRatio_fx[i] = BASOP_Util_Divide3232_Scale( hMcMasa->lfeLfEne[i], L_add( EPSILON_FX, hMcMasa->totalLfEne[i] ), &hMasa->data.lfeToTotalEnergyRatio_e[i] ); hMasa->data.lfeToTotalEnergyRatio_e[i] = add( sub( hMcMasa->lfeLfEne_e[i], hMcMasa->totalLfEne_e[i] ), hMasa->data.lfeToTotalEnergyRatio_e[i] ); + move32(); + move16(); } /* Set analyzed values to the MASA struct */ @@ -1299,8 +1299,10 @@ void ivas_mcmasa_enc_fx( IF( hQMeta->surcoh_band_data != NULL ) { - hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (uint8_t) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); - hQMeta->surcoh_band_data[i].surround_coherence[j] = (uint8_t) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); + hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (UWord8) round_fx( Mpy_32_32( spreadCoherence_fx[j][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + hQMeta->surcoh_band_data[i].surround_coherence[j] = (UWord8) round_fx( Mpy_32_32( surroundingCoherence_fx[k][i], L_shl( UINT8_MAX, Q16 ) ) ); // Q0 + move16(); + move16(); } } } @@ -1333,7 +1335,7 @@ void ivas_mcmasa_enc_fx( } /* Downmix */ - ivas_mcmasa_dmx_fx( hMcMasa, data_fx, 31 - q_inp, input_frame, nchan_transport, nchan_inp ); + ivas_mcmasa_dmx_fx( hMcMasa, data_fx, sub( 31, q_inp ), input_frame, nchan_transport, nchan_inp ); IF( hMcMasa->separateChannelEnabled ) { @@ -1344,11 +1346,13 @@ void ivas_mcmasa_enc_fx( /* Update mcMASA-relevant coding parameters */ /* These are reset to default values as they may be modified during later processing. */ hMasa->config.joinedSubframes = FALSE; + move16(); hQMeta->q_direction[0].cfg.nbands = hMcMasa->nbands; move16(); hQMeta->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); hQMeta->all_coherence_zero = 1; + move16(); /* Check spread coherence */ i = 0; @@ -1356,11 +1360,13 @@ void ivas_mcmasa_enc_fx( test(); WHILE( LT_16( i, nBlocks ) && hQMeta->all_coherence_zero ) { + test(); j = 0; move16(); test(); WHILE( LT_16( j, nBands ) && hQMeta->all_coherence_zero ) { + test(); IF( GT_32( spreadCoherence_fx[i][j], MASA_COHERENCE_THRESHOLD_FX ) ) { hQMeta->all_coherence_zero = 0; @@ -1393,7 +1399,7 @@ void ivas_mcmasa_enc_fx( { FOR( j = 0; j < nBands; j++ ) { - diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); + diffuse_to_total_ratio_fx[i][j] = L_max( 0, L_sub( ONE_IN_Q31, energyRatio_fx[i][j] ) ); // Q31 move32(); } } @@ -1588,17 +1594,17 @@ void ivas_mcmasa_enc( #ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_enc_fx( - MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ - MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ - Word32 *data_f[], /* 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 */ - const Word16 input_frame, /* i : Input frame size */ - const Word16 nchan_inp, /* i : Number of input channels */ - const Word16 q_inp /* i : Number of input channels */ + MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ + Word32 *data_f[], /* i : Audio frame in MC-format */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation Q22 */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth Q22 */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio Q31 */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence Q31 */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence Q31 */ + const Word16 input_frame, /* i : Input frame size */ + const Word16 nchan_inp, /* i : Number of input channels */ + const Word16 q_inp /* i : Q factor of the data_f */ ) { Word32 reference_power_fx[MDFT_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; @@ -1902,6 +1908,7 @@ void ivas_mcmasa_param_est_enc_fx( num_freq_bands, intensity_even_real_fx ); Word16 ref_e = 0; + move16(); computeReferencePower_enc_fx( hMcMasa->band_grouping, FoaEven_RealBuffer_fx, FoaEven_ImagBuffer_fx, @@ -1913,7 +1920,7 @@ void ivas_mcmasa_param_est_enc_fx( FOA_CHANNELS, inp_q, &ref_e ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ - hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ + hMcMasa->index_buffer_intensity = add( ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ), 1 ); /* averaging_length = 32 */ move16(); index = hMcMasa->index_buffer_intensity; move16(); @@ -1959,8 +1966,9 @@ void ivas_mcmasa_param_est_enc_fx( ELSE { diffuseness_m_fx[block_m_idx][band_m_idx] = diffuseness_vector_fx[band_m_idx]; - diffuseness_e[block_m_idx][band_m_idx] = Q31; + diffuseness_e[block_m_idx][band_m_idx] = 0; // Q31 move32(); + move16(); } } } @@ -2075,7 +2083,7 @@ void ivas_mcmasa_param_est_enc_fx( /* 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 */ { - minAngleDist_fx = 754974720; /*Q22*/ + minAngleDist_fx = 754974720; /*180.0f Q.22*/ move32(); i1 = 0; move16(); @@ -2086,7 +2094,7 @@ void ivas_mcmasa_param_est_enc_fx( 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 /*360.0f Q.22*/ ) ); } IF( LT_32( angleDist_fx, minAngleDist_fx ) ) { @@ -2278,14 +2286,14 @@ void ivas_mcmasa_param_est_enc_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_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + stereoRatio_fx = L_sub( Mult_32_32( L_shl_sat( stereoCoh_fx, stereoCoh_e ), lsEnergyRelation_fx ), surrCoh_fx ); // Q31 temp2 = L_sub( temp2, EPSILLON_FX ); lsEnergyRelation_fx = BASOP_Util_Divide3232_Scale( temp2, lsEnergySum_fx, &lsEnergyRelation_e ); lsEnergyRelation_e = add( lsEnergyRelation_e, sub( temp2_e, lsEnergySum_e ) ); - lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); - cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); + lsEnergyRelation_fx = L_shl_sat( lsEnergyRelation_fx, add( 16, lsEnergyRelation_e ) ); // Q31 + cohPanRatio_fx = L_sub( Mult_32_32( cohPanCoh_fx, lsEnergyRelation_fx ), surrCoh_fx ); // Q31 IF( GT_32( stereoRatio_fx, cohPanRatio_fx ) ) { cohRatio_fx = stereoRatio_fx; @@ -2338,9 +2346,9 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; + surroundingCoherence_fx[block_m_idx][band_m_idx] = surrCoh_fx; // Q31 move32(); - coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; + coherentEnergyRatio_fx[block_m_idx][band_m_idx] = cohRatio_fx; // Q31 move32(); } } @@ -2356,7 +2364,7 @@ void ivas_mcmasa_param_est_enc_fx( diffuseness_m_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( diffuseness_m_fx[0][band_m_idx], renormalization_factor_diff_fx[band_m_idx], &diffuseness_m_e ); move32(); diffuseness_m_e = add( diffuseness_m_e, sub( diffuseness_e[0][band_m_idx], renormalization_factor_diff_e[band_m_idx] ) ); - diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); + diffuseness_m_fx[0][band_m_idx] = L_shl_sat( diffuseness_m_fx[0][band_m_idx], add( 16, diffuseness_m_e ) ); // Q(31 - diffuseness_m_e) -> Q31 move32(); } ELSE @@ -2372,12 +2380,12 @@ void ivas_mcmasa_param_est_enc_fx( surroundingCoherence_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( surroundingCoherence_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &sc_e ); move32(); sc_e = add( sc_e, sub( surroundingCoherence_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); + surroundingCoherence_fx[0][band_m_idx] = L_shl_sat( surroundingCoherence_fx[0][band_m_idx], add( 16, sc_e ) ); // Q(31 - sc_e) -> Q31 move32(); coherentEnergyRatio_fx[0][band_m_idx] = BASOP_Util_Divide3232_Scale( coherentEnergyRatio_fx[0][band_m_idx], renormalization_factor_coh_fx[band_m_idx], &cer_e ); move32(); cer_e = add( cer_e, sub( coherentEnergyRatio_e[0][band_m_idx], renormalization_factor_coh_e[band_m_idx] ) ); - coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); + coherentEnergyRatio_fx[0][band_m_idx] = L_shl_sat( coherentEnergyRatio_fx[0][band_m_idx], add( 16, cer_e ) ); // Q(31 - cer_e) -> Q31 move32(); } ELSE @@ -2406,7 +2414,7 @@ void ivas_mcmasa_param_est_enc_fx( { FOR( j = 0; j < hMcMasa->nbands; j++ ) { - energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); + energyRatio_fx[i][j] = L_sub( ONE_IN_Q31, diffuseness_m_fx[i][j] ); // Q31 move32(); IF( GT_32( energyRatio_fx[i][j], coherentEnergyRatio_fx[i][j] ) ) { @@ -2415,7 +2423,7 @@ void ivas_mcmasa_param_est_enc_fx( } ELSE { - energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; + energyRatio_fx[i][j] = coherentEnergyRatio_fx[i][j]; // Q31 move32(); } } @@ -2945,6 +2953,92 @@ void ivas_mcmasa_param_est_enc( * *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_mcmasa_dmx_modify_fx( + const Word16 n_samples, /* i : input frame length in samples */ + Word32 dmx_fx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format Qx*/ + const Word16 n_chnls_dmx_old, /* i : number of downmix channels in the old format Q0 */ + const Word16 n_chnls_dmx_new ) /* i : number of downmix channels in the target format Q0*/ +{ + /* assumed data ordering in **dmx: [sce][cpe_chnl0][cpe_chnl1], i.e., [c][l][r] */ + Word16 i; + + assert( ( n_chnls_dmx_old == 1 || n_chnls_dmx_old == 2 || n_chnls_dmx_old == 3 ) && "Input downmix may contain only 1-3 channels." ); + assert( ( n_chnls_dmx_new == 1 || n_chnls_dmx_new == 2 || n_chnls_dmx_new == 3 ) && "Output downmix may contain only 1-3 channels." ); + + IF( EQ_16( n_chnls_dmx_old, n_chnls_dmx_new ) ) + { + /* same dmx layout -> nothing to do */ + return; + } + + IF( EQ_16( n_chnls_dmx_old, 1 ) ) + { + /* split mono energy into identical channels */ + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + dmx_fx[1][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); // dmx_q + Q15 - 15 + dmx_fx[2][i] = dmx_fx[1][i]; + move32(); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT3_FX ); // dmx_q + Q15 - 15 + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 2 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum l and r */ + dmx_fx[0][i] = L_add( dmx_fx[1][i], dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 3 ) ) + { + dmx_fx[0][i] = L_shr( L_add( dmx_fx[1][i], dmx_fx[2][i] ), 1 ); + dmx_fx[1][i] = L_sub( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_sub( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + ELSE IF( EQ_16( n_chnls_dmx_old, 3 ) ) + { + FOR( i = 0; i < n_samples; i++ ) + { + IF( EQ_16( n_chnls_dmx_new, 1 ) ) + { + /* sum all channels */ + dmx_fx[0][i] = L_add( L_add( dmx_fx[0][i], dmx_fx[1][i] ), dmx_fx[2][i] ); + move32(); + } + ELSE IF( EQ_16( n_chnls_dmx_new, 2 ) ) + { + /* mix center into sides */ + dmx_fx[0][i] = Mpy_32_16_1( dmx_fx[0][i], INV_SQRT2_FX_Q15 ); + dmx_fx[1][i] = L_add( dmx_fx[1][i], dmx_fx[0][i] ); + dmx_fx[2][i] = L_add( dmx_fx[2][i], dmx_fx[0][i] ); + move32(); + move32(); + move32(); + } + } + } + + return; +} +#endif + void ivas_mcmasa_dmx_modify( const int16_t n_samples, /* i : input frame length in samples */ float dmx[][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )], /* i/o: downmix signal to be transformed into another format */ @@ -3127,16 +3221,16 @@ static void ivas_mcmasa_dmx_fx( } } - alpha_fx = 214748364; // Q31 + alpha_fx = 214748364; // 0.1 in Q31 move32(); L_tmp = Mpy_32_32( alpha_fx, multiChEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevMultiChEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevMultiChEne_fx ); hMcMasa->prevMultiChEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, multiChEne_e, L_tmp1, hMcMasa->prevMultiChEne_e, &hMcMasa->prevMultiChEne_e ); move32(); L_tmp = Mpy_32_32( alpha_fx, downmixEne_fx ); - L_tmp1 = Mpy_32_32( 1932735284, hMcMasa->prevDownmixEne_fx ); + L_tmp1 = Mpy_32_32( 1932735284 /* 0.9f in Q31 */, hMcMasa->prevDownmixEne_fx ); hMcMasa->prevDownmixEne_fx = BASOP_Util_Add_Mant32Exp( L_tmp, downmixEne_e, L_tmp1, hMcMasa->prevDownmixEne_e, &hMcMasa->prevDownmixEne_e ); move32(); @@ -3157,7 +3251,7 @@ static void ivas_mcmasa_dmx_fx( 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_tmp1 = L_sub( 1073741824 /* 1 in Q30 */, 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, add( prevEQ_e, 1 ), &instEQ_e ); @@ -3282,8 +3376,8 @@ static void ivas_mcmasa_dmx( #ifdef IVAS_FLOAT_FIXED /* Compute covariance matrix, i.e., xT * conj(x), and accumulate to the output */ static void compute_cov_mtx_fx( - Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] */ - Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] */ + Word32 sr[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, real, s[ch][freq] (inp_exp) */ + Word32 si[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX], /* i : Input matrix, imag, s[ch][freq] (inp_exp) */ 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 */ @@ -3445,11 +3539,11 @@ static void computeIntensityVector_enc_fx( #endif #ifdef IVAS_FLOAT_FIXED static void computeVerticalDiffuseness_fx( - Word32 **buffer_intensity, /* i : Intensity vectors */ - const Word32 *buffer_energy, /* i : Energy */ - const int16_t averaging_length, /* i : Averaging length */ - const Word16 num_freq_bands, /* i : Number of frequency bands */ - Word32 *diffuseness, /* o : Estimated diffuseness */ + Word32 **buffer_intensity, /* i : Intensity vectors */ + const Word32 *buffer_energy, /* i : Energy */ + const Word16 averaging_length, /* i : Averaging length */ + const Word16 num_freq_bands, /* i : Number of frequency bands */ + Word32 *diffuseness, /* o : Estimated diffuseness Q31 */ Word16 *buffer_intensity_q, Word16 *buffer_energy_q ) { @@ -3518,7 +3612,7 @@ static void computeVerticalDiffuseness_fx( { tmp = L_shl( tmp, add( 16, tmp_e2 ) ); } - diffuseness[i] = tmp; + diffuseness[i] = tmp; // Q31 move32(); } @@ -3906,7 +4000,8 @@ static void computeLfeEnergy_fx( move32(); } - hMcMasa->ringBufferPointer--; + hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferPointer, 1 ); + move16(); IF( hMcMasa->ringBufferPointer < 0 ) { hMcMasa->ringBufferPointer = sub( hMcMasa->ringBufferSize, 1 ); @@ -3973,8 +4068,8 @@ static void computeLfeEnergy_fx( IF( hMcMasa->separateChannelEnabled ) { - Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); - Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), ( hMcMasa->num_samples_delay_comp - hMcMasa->offset_comp ) ); + Copy32( data_fx[lfeChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[0][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); + Copy32( data_fx[separateChannelIndex] + ( input_frame - hMcMasa->num_samples_delay_comp + hMcMasa->offset_comp ), &( hMcMasa->delay_buffer_lfe[1][0] ), sub( hMcMasa->num_samples_delay_comp, hMcMasa->offset_comp ) ); } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 0265b1339..48592f1b3 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -75,9 +75,6 @@ static void ivas_omasa_energy_and_ratio_est_fx( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, Word32 *data_fx[], -#if 0 - float *data_f[], -#endif const Word16 input_frame, const Word16 nchan_ism, const Word16 q_data ); @@ -873,7 +870,7 @@ void ivas_omasa_enc_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ Word32 *data_in[], /* i/o: Input / transport audio signals */ - Word16 q_data, /* i:Q0 Stores the q for data_in_f */ + Word16 q_data, /* i : Q0 Stores the q for data_in */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 nchan_ism, /* i : Number of objects for parameter analysis */ @@ -939,7 +936,7 @@ void ivas_omasa_enc_fx( // alpha = 26214;/*0.8 Q15*/ FOR( i = 0; i < nchan_all_inp; i++ ) { - hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 ) ); + hOMasa->broadband_energy_sm_fx[i] = L_add( Mpy_32_16_1( broadband_energy_fx[i], 6554 /*0.2 Q15*/ ), Mpy_32_16_1( hOMasa->broadband_energy_sm_fx[i], 26214 /*0.8 Q15*/ ) ); move32(); } @@ -1405,6 +1402,7 @@ void ivas_set_ism_importance_interformat_fx( IF( active_flag == 0 ) { + test(); if ( GT_16( st->lp_noise_fx, 3840 /* 15 in Q8 */ ) || LT_16( sub( lp_noise_CPE_fx, st->lp_noise_fx ), 7680 /* 30 in Q8 */ ) ) { active_flag = 1; @@ -1425,6 +1423,8 @@ void ivas_set_ism_importance_interformat_fx( ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; st->low_rate_mode = 0; + move16(); + test(); IF( active_flag == 0 ) { ism_imp[ch] = ISM_INACTIVE_IMP; @@ -1533,12 +1533,8 @@ void ivas_set_surplus_brate_enc( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#ifndef IVAS_FLOAT_FIXED - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); -#else st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) ); move32(); -#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) @@ -1777,7 +1773,7 @@ static void ivas_omasa_param_est_enc_fx( dir_v_e = MIN_16; num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; num_freq_bands = hOMasa->nbands; - l_ts = input_frame / CLDFB_NO_COL_MAX; /*division by power of 2 so basop not used*/ + l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); move16(); move16(); move16(); @@ -2011,8 +2007,8 @@ static void ivas_omasa_param_est_enc_fx( move16(); } move32(); - diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], 15 + temp_e ); - energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); + diffuseness_m_fx[band_m_idx] = L_shl( diffuseness_m_fx[band_m_idx], add( 15, temp_e ) ); // Scaling to Q30 + energyRatio_fx[band_m_idx] = L_sub( ONE_IN_Q30, diffuseness_m_fx[band_m_idx] ); // Q30 move32(); move32(); } @@ -2672,9 +2668,7 @@ static void computeReferencePower_omasa_ivas_fx( /* abs()^2 */ FOR( j = brange[0]; j < brange[1]; j++ ) { - // reference_power[i] += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); - // Q13 (Q6+Q6+1) - reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); + reference_power_tmp[i] = W_add( reference_power_tmp[i], W_mac_32_32( W_mult_32_32( Cldfb_RealBuffer[ch_idx][j], Cldfb_RealBuffer[ch_idx][j] ), Cldfb_ImagBuffer[ch_idx][j], Cldfb_ImagBuffer[ch_idx][j] ) ); // Q13 (Q6+Q6+1) move64(); } } diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 4da8169fb..ec1e0f9fa 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -345,66 +345,7 @@ ivas_error ivas_osba_enc_reconfig( n_old = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ) ); n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - 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" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; 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 ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - 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" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 549b7ccdc..501c6796a 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -140,66 +140,6 @@ ivas_error ivas_sba_enc_reconfigure( n_old = imult1616( add( analysis_order_old, 1 ), add( analysis_order_old, 1 ) ); n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); -#if 1 // To be removed - float **old_mem_hp20_in; - - if ( n > n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - 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" ) ); - } - - for ( i = 0; i < n_old; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* create additional hp20 memories */ - for ( ; 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 ); - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } - else if ( n < n_old ) - { - /* save old mem_hp_20 pointer */ - old_mem_hp20_in = st_ivas->mem_hp20_in; - st_ivas->mem_hp20_in = NULL; - - 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" ) ); - } - - for ( i = 0; i < n; i++ ) - { - st_ivas->mem_hp20_in[i] = old_mem_hp20_in[i]; - old_mem_hp20_in[i] = NULL; - } - /* remove superfluous hp20 memories */ - for ( ; i < n_old; i++ ) - { - free( old_mem_hp20_in[i] ); - old_mem_hp20_in[i] = NULL; - } - - free( old_mem_hp20_in ); - old_mem_hp20_in = NULL; - } -#endif IF( GT_16( n, n_old ) ) { /* save old mem_hp_20 pointer */ @@ -258,70 +198,77 @@ ivas_error ivas_sba_enc_reconfigure( } } -#ifdef IVAS_FLOAT_FIXED ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#else - ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); -#endif hSpar = st_ivas->hSpar; - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { hEncoderConfig->element_mode_init = IVAS_SCE; } - else + ELSE { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } + move16(); - if ( nchan_transport_old != st_ivas->nchan_transport || ( ivas_total_brate < IVAS_512k && hEncoderConfig->last_ivas_total_brate >= IVAS_512k ) || ( ivas_total_brate >= IVAS_512k && hEncoderConfig->last_ivas_total_brate < IVAS_512k ) ) + test(); + test(); + test(); + test(); + IF( NE_16( nchan_transport_old, st_ivas->nchan_transport ) || ( LT_32( ivas_total_brate, IVAS_512k ) && GE_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) || ( GE_32( ivas_total_brate, IVAS_512k ) && LT_32( hEncoderConfig->last_ivas_total_brate, IVAS_512k ) ) ) { /* FB mixer handle */ - if ( hDirAC->hFbMixer != NULL ) + IF( hDirAC->hFbMixer != NULL ) { ivas_FB_mixer_close( &( hDirAC->hFbMixer ), hEncoderConfig->input_Fs, 0 ); hDirAC->hFbMixer = NULL; } spar_reconfig_flag = 1; + move16(); ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); - if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { return error; } } st_ivas->hSpar->spar_reconfig_flag = spar_reconfig_flag; + move16(); - if ( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_dirac_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->hQMetaData->q_direction->cfg.nbands != nbands_old || st_ivas->hQMetaData->no_directions != ndir_old ) + test(); + IF( NE_16( st_ivas->hQMetaData->q_direction->cfg.nbands, nbands_old ) || NE_16( st_ivas->hQMetaData->no_directions, ndir_old ) ) { - int16_t dir, j, i; + Word16 dir, j, i; IVAS_QDIRECTION *q_direction = st_ivas->hQMetaData->q_direction; - for ( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) + FOR( dir = 0; dir < st_ivas->hQMetaData->no_directions; dir++ ) { - for ( j = 0; j < q_direction[dir].cfg.nbands; j++ ) + FOR( j = 0; j < q_direction[dir].cfg.nbands; j++ ) { - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { q_direction[dir].band_data[j].energy_ratio_index[i] = 0; q_direction[dir].band_data[j].energy_ratio_index_mod[i] = 0; + move16(); + move16(); } } } } hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + move16(); /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, ivas_total_brate / st_ivas->nchan_transport, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS, MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index b6e5fbaf6..6637128dd 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -428,7 +428,7 @@ ivas_error create_sce_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } - copy_encoder_config( st_ivas, st, 1 ); + copy_encoder_config_fx( st_ivas, st, 1 ); if ( st_ivas->hEncoderConfig->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 || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { @@ -544,12 +544,13 @@ ivas_error create_evs_sce_enc( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * 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" ) ); } @@ -559,21 +560,23 @@ ivas_error create_evs_sce_enc( *-----------------------------------------------------------------*/ hSCE->sce_id = sce_id; + move16(); hSCE->element_brate = element_brate; + move32(); hSCE->last_element_brate = hSCE->element_brate; - + move32(); /*-----------------------------------------------------------------* * Metadata: allocate and initialize *-----------------------------------------------------------------*/ - - if ( st_ivas->hEncoderConfig->ivas_format != MONO_FORMAT && sce_id == ( st_ivas->nSCE - 1 ) ) + test(); + IF( NE_32( 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( NE_32( ( error = ivas_initialize_MD_bstr_enc( &( hSCE->hMetaData ), st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { hSCE->hMetaData = NULL; } @@ -581,45 +584,72 @@ ivas_error create_evs_sce_enc( /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize *-----------------------------------------------------------------*/ - if ( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) + IF( ( st_fx = (ENC_CORE_HANDLE) malloc( sizeof( Encoder_State ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) ); } memset( st_fx, 0, sizeof( Encoder_State ) ); st_fx->input_Fs = 16000; + move32(); st_fx->total_brate = ACELP_12k65; - + move32(); st_fx->Opt_AMR_WB = 0; + move16(); st_fx->Opt_RF_ON = 0; + move16(); st_fx->rf_fec_offset = 0; + move16(); st_fx->rf_fec_indicator = 1; + move16(); st_fx->max_bwidth = SWB; + move16(); st_fx->interval_SID_fx = FIXED_SID_RATE; + move16(); st_fx->var_SID_rate_flag_fx = 1; + move16(); st_fx->Opt_HE_SAD_ON_fx = 0; + move16(); st_fx->Opt_SC_VBR = 0; + move16(); st_fx->last_Opt_SC_VBR = 0; + move16(); st_fx->bitstreamformat = G192; + move16(); // copy_encoder_config_fx( st_ivas, st_fx, 1 ); st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; + move16(); st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; + move16(); st_fx->var_SID_rate_flag_fx = st_ivas->hEncoderConfig->var_SID_rate_flag; + move16(); st_fx->interval_SID_fx = st_ivas->hEncoderConfig->interval_SID; + move16(); st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; + move16(); st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; + move16(); st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; + move16(); // st_fx->bitstreamformat = st->bitstreamformat; st_fx->total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + move32(); st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; + move16(); st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; + move16(); st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; + move16(); st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; + move32(); st_fx->codec_mode = st_ivas->codec_mode; + move16(); st_fx->last_codec_mode = st_ivas->last_codec_mode; + move16(); st_fx->input_frame_fx = extract_l( Mult_32_16( st_fx->input_Fs, 0x0290 ) ); - if ( ( error = init_encoder_fx( st_fx ) ) != IVAS_ERR_OK ) + move16(); + IF( NE_32( ( error = init_encoder_fx( st_fx ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2ad739323..9ffd91825 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -104,11 +104,7 @@ ivas_error ivas_spar_enc_open( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); -#ifdef IVAS_FLOAT_FIXED nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#else - nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); -#endif // IVAS_FLOAT_FIXED assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -130,9 +126,9 @@ ivas_error ivas_spar_enc_open( assert( 0 && "sba_order must be 1,2, or 3!" ); } - nchan_transport = ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal ); + nchan_transport = ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, sba_order_internal ); - table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + 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( &( hSpar->hMdEnc ), hEncoderConfig, sba_order_internal ) ) != IVAS_ERR_OK ) @@ -170,10 +166,17 @@ ivas_error ivas_spar_enc_open( if ( !spar_reconfig_flag ) { /* Transient Detector handle */ +#ifdef IVAS_FLOAT_FIXED + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* initialization */ @@ -262,7 +265,7 @@ ivas_error ivas_spar_enc_open( 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( 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 ) + 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; } @@ -375,7 +378,7 @@ ivas_error ivas_spar_enc_open_fx( IF( !spar_reconfig_flag ) { /* Transient Detector handle */ - IF( ( error = ivas_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_transient_det_open_fx( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -546,7 +549,11 @@ void ivas_spar_enc_close( if ( !spar_reconfig_flag ) { /* Trans Det handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_transient_det_close_fx( &( *hSpar )->hTranDet ); +#else ivas_transient_det_close( &( *hSpar )->hTranDet ); +#endif free( ( *hSpar ) ); ( *hSpar ) = NULL; } @@ -661,10 +668,6 @@ static ivas_error ivas_spar_cov_md_process( Word16 i, j, i_ts, b, table_idx; Word16 active_w_vlbr; /* note: the actual dimensions of matrixes correspond to num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); */ - float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - float cov_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - float cov_dtx_real_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; #ifdef IVAS_FLOAT_FIXED Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; @@ -716,29 +719,13 @@ static ivas_error ivas_spar_cov_md_process( num_bands = IVAS_MAX_NUM_BANDS; move16(); } - ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); + ivas_spar_set_bitrate_config_fx( &hSpar->hMdEnc->spar_md_cfg, table_idx, num_bands, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable ); } } /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ - - for ( i = 0; i < nchan_inp; i++ ) - { - for ( j = 0; j < nchan_inp; j++ ) - { - cov_real[i][j] = cov_real_buf[i][j]; - cov_dtx_real[i][j] = cov_dtx_real_buf[i][j]; - for ( b = hSpar->hFbMixer->pFb->filterbank_num_bands; b < IVAS_MAX_NUM_BANDS; b++ ) - { - cov_real[i][j][b] = 0.0f; - cov_dtx_real[i][j][b] = 0.0f; - } - } - } - -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < nchan_inp; i++ ) { FOR( j = 0; j < nchan_inp; j++ ) @@ -757,14 +744,13 @@ static ivas_error ivas_spar_cov_md_process( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_real[i], Q31, nchan_inp ); + set16_fx( q_cov_real[i], Q31, nchan_inp ); IF( ( q_cov_dtx_real[i] = (Word16 *) malloc( sizeof( Word16 ) * nchan_inp ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); } - set_s( q_cov_dtx_real[i], Q31, nchan_inp ); + set16_fx( q_cov_dtx_real[i], Q31, nchan_inp ); } -#endif ivas_enc_cov_handler_process_fx( hSpar->hCovEnc, ppIn_FR_real_fx, ppIn_FR_imag_fx, q_ppIn_FR, cov_real_fx, q_cov_real, cov_dtx_real_fx, q_cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind, &hSpar->hMdEnc->spar_md.res_ind, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], dyn_active_w_flag, nchan_transport, 1 ); @@ -772,15 +758,6 @@ static ivas_error ivas_spar_cov_md_process( #ifdef IVAS_FLOAT_FIXED_CONVERSIONS FOR( i = 0; i < nchan_inp; i++ ) { - FOR( j = 0; j < nchan_inp; j++ ) - { - Word16 k; - FOR( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) - { - cov_real[i][j][k] = me2f( cov_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_state->q_cov_real_per_band[i][j][k] ) ); - cov_dtx_real[i][j][k] = me2f( cov_dtx_real_fx[i][j][k], sub( Q31, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band[i][j][k] ) ); - } - } free( q_cov_real[i] ); q_cov_real[i] = NULL; free( q_cov_dtx_real[i] ); @@ -821,7 +798,7 @@ static ivas_error ivas_spar_cov_md_process( IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ) ), IVAS_ERR_OK ) ) { return error; } @@ -892,35 +869,21 @@ static ivas_error ivas_spar_cov_md_process( move32(); } -#ifdef IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shr( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q22; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q22; + move16(); } - Word16 num_ch = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - Word16 q_mixer_mat = 26; - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - q_mixer_mat = min( q_mixer_mat, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - floatToFixed_arr32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], q_mixer_mat, IVAS_MAX_NUM_BANDS ); - } - } - hSpar->hMdEnc->q_mixer_mat_fx = q_mixer_mat; #endif IF( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { @@ -934,35 +897,26 @@ static ivas_error ivas_spar_cov_md_process( } ivas_get_spar_md_from_dirac_fx( azi_dirac_fx, ele_dirac_fx, diffuseness_fx, 1, hSpar->hMdEnc->mixer_mat_fx, &hSpar->hMdEnc->q_mixer_mat_fx, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, order, dtx_vad, Wscale_d_fx, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) { - for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) + FOR( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q6 ); + move32(); hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i] = L_shl( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q6 ); + move32(); } hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx = Q28; + move16(); hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx = Q28; + move16(); } - for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) - { - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - hSpar->hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hSpar->hMdEnc->mixer_mat_fx[i][j][b], hSpar->hMdEnc->q_mixer_mat_fx ); - } - } - } -#endif -#else - ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d, hQMetaData->useLowerRes, active_w_vlbr, *dyn_active_w_flag ); #endif } IF( hSpar->hMdEnc->spar_hoa_md_flag ) { - error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer, *dyn_active_w_flag, hQMetaData->dirac_mono_flag ); + error = ivas_spar_md_enc_process_fx( hSpar->hMdEnc, hEncoderConfig, cov_real_fx, hSpar->hCovEnc->pCov_state->q_cov_real_per_band, cov_dtx_real_fx, hSpar->hCovEnc->pCov_dtx_state->q_cov_real_per_band, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer_fx, &hSpar->hFbMixer->q_prior_mixer_fx, *dyn_active_w_flag, hQMetaData->dirac_mono_flag, hSpar->hFbMixer->fb_cfg->num_out_chans ); } return error; @@ -1161,12 +1115,6 @@ static ivas_error ivas_spar_enc_process( hSpar->hFbMixer->q_ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; hSpar->hFbMixer->q_ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]] = q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]]; - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_re_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_re[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); - - me2f_buf( hSpar->hFbMixer->ppFilterbank_inFR_im_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], 31 - q_p_pcm_tmp_fx[hSpar->hFbMixer->fb_cfg->remix_order[x]], - hSpar->hFbMixer->ppFilterbank_inFR_im[hSpar->hFbMixer->fb_cfg->remix_order[x]], input_frame ); } /* Need to remove fix to flt conversions */ #endif @@ -1383,45 +1331,6 @@ static ivas_error ivas_spar_enc_process( } #endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS - Word16 mixer_q = 31; - Word16 prior_mixer_q = 31; - Word32 num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - mixer_q = s_min( mixer_q, Q_factor_arrL( hSpar->hMdEnc->mixer_mat[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - prior_mixer_q = s_min( prior_mixer_q, Q_factor_arrL( hSpar->hFbMixer->prior_mixer[i][j], IVAS_MAX_NUM_BANDS ) ); - } - } - - mixer_q = s_min( mixer_q, prior_mixer_q ); - // both should have a common q as there are values being copied inside function - // or need to do loop for updating values for unused values - - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - floatToFixed_arrL32( hSpar->hMdEnc->mixer_mat[i][j], hSpar->hMdEnc->mixer_mat_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - floatToFixed_arrL32( hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->prior_mixer_fx[i][j], mixer_q, IVAS_MAX_NUM_BANDS ); - } - } - - hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; Word16 q_p_pcm_tmp_loc_fx[DIRAC_MAX_ANA_CHANS]; #endif @@ -1437,17 +1346,6 @@ static ivas_error ivas_spar_enc_process( p_pcm_tmp[ch][k] = (float) fixedToFloat( p_pcm_tmp_fx[ch][k], q_p_pcm_tmp_loc_fx[ch] ); } } - - // hSpar->hMdEnc->q_mixer_mat_fx = mixer_q; - // hSpar->hFbMixer->q_prior_mixer_fx = mixer_q; - // should be same - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) - { - fixedToFloat_arrL32( hSpar->hFbMixer->prior_mixer_fx[i][j], hSpar->hFbMixer->prior_mixer[i][j], hSpar->hFbMixer->q_prior_mixer_fx, IVAS_MAX_NUM_BANDS ); - } - } #endif if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index b2413c928..1b07f61a6 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -174,24 +174,6 @@ ivas_error ivas_spar_md_enc_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); } - if ( ( hMdEnc->mixer_mat = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == 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[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 ( ( hMdEnc->mixer_mat[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( ( 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" ); @@ -323,18 +305,6 @@ void ivas_spar_md_enc_close( free( hMdEnc->spar_md.band_coeffs ); hMdEnc->spar_md.band_coeffs = NULL; } - if ( hMdEnc->mixer_mat != NULL ) - { - for ( i = 0; i < num_channels; i++ ) - { - for ( j = 0; j < num_channels; j++ ) - { - free( hMdEnc->mixer_mat[i][j] ); - } - free( hMdEnc->mixer_mat[i] ); - } - free( hMdEnc->mixer_mat ); - } #ifdef IVAS_FLOAT_FIXED IF( hMdEnc->mixer_mat_fx != NULL ) { @@ -475,18 +445,6 @@ ivas_error ivas_spar_md_enc_init( 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 ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0; - } - } - } - #ifdef MSAN_FIX FOR( i = 0; i < num_channels; i++ ) { @@ -499,6 +457,8 @@ ivas_error ivas_spar_md_enc_init( } } } + hMdEnc->q_mixer_mat_fx = Q31; + move16(); #endif ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -581,19 +541,6 @@ ivas_error ivas_spar_md_enc_init_fx( } } } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - FOR( i = 0; i < num_channels; i++ ) - { - FOR( j = 0; j < num_channels; j++ ) - { - FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) - { - hMdEnc->mixer_mat[i][j][k] = 0.0f; - move32(); - } - } - } -#endif hMdEnc->q_mixer_mat_fx = 0; move16(); ivas_clear_band_coeffs_fx( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS ); @@ -826,11 +773,12 @@ ivas_error ivas_spar_md_enc_process_fx( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const Word16 dtx_vad, const Word16 nchan_inp, - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ - const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ - const Word16 dirac_mono_flag /* i : flag to indicate mono only mode in SBA */ -) + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word32 *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH], /* i : prior mixer_matrix */ + Word16 *q_prior_mixer, /* i/o : q for prior mixer_matrix */ + const Word16 dyn_active_w_flag, /* i : flag to indicate dynamic active W */ + const Word16 dirac_mono_flag, /* i : flag to indicate mono only mode in SBA */ + const Word16 nchan_out ) { Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -1197,15 +1145,6 @@ ivas_error ivas_spar_md_enc_process_fx( { ivas_band_mixing_fx( hMdEnc, num_ch, num_bands, nchan_transport, num_bands_full ); } -#ifdef IVAS_FLOAT_FIXED_CONVERSIONS - for ( i = 0; i < num_ch; i++ ) - { - for ( j = 0; j < num_ch; j++ ) - { - fixedToFloat_arrL32( hMdEnc->mixer_mat_fx[i][j], hMdEnc->mixer_mat[i][j], hMdEnc->q_mixer_mat_fx, IVAS_MAX_NUM_BANDS ); - } - } -#endif IF( dtx_vad == 0 ) { @@ -1285,8 +1224,38 @@ ivas_error ivas_spar_md_enc_process_fx( } } } - - + IF( GT_16( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ) + { + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hMdEnc->mixer_mat_fx[i][j][b] = L_shr( hMdEnc->mixer_mat_fx[i][j][b], sub( hMdEnc->q_mixer_mat_fx, *q_prior_mixer ) ); + move32(); + } + } + } + hMdEnc->q_mixer_mat_fx = *q_prior_mixer; + move16(); + } + ELSE + { + FOR( i = 0; i < nchan_out; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + FOR( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + prior_mixer[i][j][b] = L_shr( prior_mixer[i][j][b], sub( *q_prior_mixer, hMdEnc->q_mixer_mat_fx ) ); + move32(); + } + } + } + *q_prior_mixer = hMdEnc->q_mixer_mat_fx; + move16(); + } /* Reuse mixer matrix values for unsent bands */ test(); IF( ( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) ) && GT_16( code_strat, 3 ) ) @@ -1302,9 +1271,10 @@ ivas_error ivas_spar_md_enc_process_fx( { FOR( j = 0; j < 4; j++ ) { - // TODO once fb-mixer changes are final - hMdEnc->mixer_mat[i][j][b] = prior_mixer[i][j][b]; - hMdEnc->mixer_mat[i][j][b + 1] = prior_mixer[i][j][b + 1]; + hMdEnc->mixer_mat_fx[i][j][b] = prior_mixer[i][j][b]; + move32(); + hMdEnc->mixer_mat_fx[i][j][b + 1] = prior_mixer[i][j][b + 1]; + move32(); } } } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0286115d7..eae425507 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1059,7 +1059,6 @@ typedef struct ivas_spar_md_enc_state_t Word16 num_umx_ch; Word16 num_decorr; - float ***mixer_mat; ivas_spar_md_com_cfg spar_md_cfg; ivas_arith_coeffs_t arith_coeffs; ivas_huff_coeffs_t huff_coeffs; @@ -1822,9 +1821,10 @@ typedef struct Word16 sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ Word16 codec_mode; /* Mode1 or Mode2 of core codec */ Word16 last_codec_mode; /* previous frame Mode 1 or 2 */ - float **mem_hp20_in; /* input signals HP filter memories */ #ifdef IVAS_FLOAT_FIXED Word32 **mem_hp20_in_fx; /* input signals HP filter memories */ +#else + float **mem_hp20_in; /* input signals HP filter memories */ #endif /* core-encoder modules */ diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index b2dd2863f..2ba28fcf6 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -1738,7 +1738,14 @@ Word16 ivas_acelp_tcx20_switching_fx( basop_weight_a( A_q_tcx_fx, Ap_fx, 30147 /*0.92 in Q15*/ ); basop_lpc2mdct( Ap_fx, M, gainlpc_fx, gainlpc_e, gainlpc_noinv, gainlpc_noinv_e ); - + Word16 com_gainlpc_e = 0; + move16(); + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + com_gainlpc_e = s_max( com_gainlpc_e, gainlpc_e[i] ); + } + Copy_Scale_sig32( x_fx, x_fx, L_frame, -com_gainlpc_e ); + e_x = add( e_x, com_gainlpc_e ); mdct_shaping( x_fx, L_frame, gainlpc_fx, gainlpc_e ); FOR( i = 0; i < L_frame_4; i++ ) @@ -1748,20 +1755,20 @@ Word16 ivas_acelp_tcx20_switching_fx( move16(); tmp16 = norm_l( x_fx[0] ); - if ( x_fx[0] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[0] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[1] ); - if ( x_fx[1] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[1] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[2] ); - if ( x_fx[2] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[2] != 0 ) + s = s_min( s, tmp16 ); tmp16 = norm_l( x_fx[3] ); - if ( x_fx[3] != 0 ) - s = s_min( s, tmp16 ); + IF( x_fx[3] != 0 ) + s = s_min( s, tmp16 ); s = sub( s, 2 ); /* 2 bits headroom */ @@ -1803,28 +1810,28 @@ Word16 ivas_acelp_tcx20_switching_fx( { 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 ); } 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 ); } 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 ); } 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 ); } @@ -1837,7 +1844,7 @@ Word16 ivas_acelp_tcx20_switching_fx( } } - 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; */ } @@ -1875,6 +1882,7 @@ Word16 ivas_acelp_tcx20_switching_fx( Word32 nrg_s, nrg_n; Word16 temp_e, e_num, e_den, temp_ene_e; temp_ene_e = ener_e; + move16(); tmp32 = Sqrt32( ener, &temp_ene_e ); /*Approximate SNR of TCX*/ set32_fx( x_fx, tmp32, L_frame ); /* ener_e */ @@ -2037,6 +2045,7 @@ Word16 ivas_acelp_tcx20_switching_fx( tmp32 = Mpy_32_16_1( temp_energy, tmp16 ); /*ener_e*/ tmp32 = L_shr( Mpy_32_16_1( tmp32, 0x6054 /* 0x6054 -> 10/log2(10) (2Q13) */ ), sub( 13, ener_e ) ); /* Q16*/ snr_acelp = tmp32; + move32(); /*--------------------------------------------------------------* * Switching Decision diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index ac29e728e..ce072891d 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -71,16 +71,14 @@ static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BAND static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); +static Word16 getInputBufferSize_fx( const Encoder_Struct *st_ivas ); +#else +static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); #endif // IVAS_FLOAT_FIXED static ivas_error configureEncoder( IVAS_ENC_HANDLE hIvasEnc, const int32_t inputFs, const int32_t initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -static ivas_error setBandwidth( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ); static ivas_error setBitrate( IVAS_ENC_HANDLE hIvasEnc, const int32_t totalBitrate ); -static ivas_error setChannelAwareConfig( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ); -static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); -static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); -static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi ); static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); @@ -650,11 +648,11 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics_fx( ivas_error IVAS_ENC_ConfigureForSBAObjects( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ - const int32_t inputFs, /* i : input sampling frequency */ - const int32_t bitrate, /* i : requested bitrate of the ouput bitstream */ + const Word32 inputFs, /* i : input sampling frequency */ + const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */ 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 uint16_t numObjects, /* i : number of objects to be encoded */ + const UWord16 numObjects, /* i : number of objects to be encoded */ 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 */ @@ -663,35 +661,38 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( Encoder_Struct *st_ivas; ivas_error error; - if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + IF( NE_16( ( error = doCommonConfigureChecks( hIvasEnc ) ), IVAS_ERR_OK ) ) { return error; } - if ( numObjects > MAX_NUM_OBJECTS ) + IF( GT_32( numObjects, MAX_NUM_OBJECTS ) ) { return IVAS_ERR_TOO_MANY_INPUTS; } st_ivas = hIvasEnc->st_ivas; st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */ + move16(); st_ivas->hEncoderConfig->sba_planar = isPlanar; + move16(); st_ivas->hEncoderConfig->sba_order = order; + move16(); /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ -#ifndef IVAS_FLOAT_FIXED - st_ivas->hEncoderConfig->nchan_inp = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, 0 ) + numObjects; -#else - st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), (Word16) numObjects ); -#endif - - st_ivas->hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; + st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), numObjects ); + move16(); + st_ivas->hEncoderConfig->Opt_PCA_ON = extract_l( Opt_PCA_ON ); + move16(); /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ - st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp - numObjects; + st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects ); + move16(); st_ivas->hEncoderConfig->ivas_format = SBA_ISM_FORMAT; + move16(); st_ivas->hEncoderConfig->nchan_ism = numObjects; + move16(); return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } @@ -919,7 +920,7 @@ static ivas_error configureEncoder( * Bandwidth limitation *-----------------------------------------------------------------*/ - if ( ( error = setBandwidth( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) + if ( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK ) { return error; } @@ -978,7 +979,7 @@ static ivas_error configureEncoder( /* check if the entered bitrate is supported */ if ( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) /* IVAS */ { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { if ( hEncoderConfig->Opt_SC_VBR ) { @@ -1017,7 +1018,7 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -1099,7 +1100,7 @@ static ivas_error configureEncoder( * Channel-aware mode *-----------------------------------------------------------------*/ - if ( ( error = setChannelAwareConfig( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) + if ( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK ) { return error; } @@ -1153,7 +1154,7 @@ static ivas_error configureEncoder( return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." ); } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1545,13 +1546,21 @@ ivas_error IVAS_ENC_GetDelay( * * *---------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED +static Word16 getInputBufferSize_fx( + const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ +) +{ + return extract_l( Mpy_32_32( imult3216( st_ivas->hEncoderConfig->input_Fs, st_ivas->hEncoderConfig->nchan_inp ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); +} +#else static int16_t getInputBufferSize( const Encoder_Struct *st_ivas /* i : IVAS encoder handle */ ) { return (int16_t) ( st_ivas->hEncoderConfig->input_Fs * st_ivas->hEncoderConfig->nchan_inp / FRAMES_PER_SEC ); } +#endif /*---------------------------------------------------------------------* * IVAS_ENC_GetNumInChannels() @@ -1584,7 +1593,28 @@ ivas_error IVAS_ENC_GetNumInChannels( * * *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_GetInputBufferSize( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ +) +{ + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + IF( inputBufferSize == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *inputBufferSize = getInputBufferSize_fx( hIvasEnc->st_ivas ); + move16(); + + return IVAS_ERR_OK; +} +#else ivas_error IVAS_ENC_GetInputBufferSize( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ int16_t *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */ @@ -1604,6 +1634,7 @@ ivas_error IVAS_ENC_GetInputBufferSize( return IVAS_ERR_OK; } +#endif /*---------------------------------------------------------------------* @@ -1611,7 +1642,269 @@ ivas_error IVAS_ENC_GetInputBufferSize( * * Main function to encode one frame to a serial bitstream *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +) +{ + Encoder_Struct *st_ivas; + ENCODER_CONFIG_HANDLE hEncoderConfig; + Word16 i; + Word16 n, ch; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + st_ivas = hIvasEnc->st_ivas; + hEncoderConfig = st_ivas->hEncoderConfig; + ENC_CORE_HANDLE hCoreCoder = hIvasEnc->hCoreCoder; + + IF( NE_16( inputBufferSize, getInputBufferSize_fx( st_ivas ) ) ) + { + return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; + } + + IF( NE_32( ( error = sanitizeBandwidth_fx( hIvasEnc ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF( EQ_32( hEncoderConfig->ivas_format, ISM_FORMAT ) ) + { + FOR( i = 0; i < hEncoderConfig->nchan_inp; ++i ) + { + IF( !hIvasEnc->ismMetadataProvided[i] ) + { + ivas_ism_reset_metadata_API( hIvasEnc->st_ivas->hIsmMetaData[i] ); + } + } + resetIsmMetadataProvidedFlags( hIvasEnc ); + } + + test(); + test(); + test(); + test(); + IF( ( hEncoderConfig->Opt_RF_ON && ( NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 ) + { + test(); + IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + st_ivas->codec_mode = MODE1; + move16(); + + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 0; + move16(); + hEncoderConfig->rf_fec_offset = 0; + move16(); + hIvasEnc->switchingActive = true; + move16(); + } + + test(); + test(); + test(); + test(); + IF( hIvasEnc->Opt_RF_ON_loc && hIvasEnc->rf_fec_offset_loc != 0 && L_sub( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) == 0 && L_sub( hEncoderConfig->input_Fs, 8000 ) != 0 && hEncoderConfig->max_bwidth != NB ) + { + st_ivas->codec_mode = MODE2; + move16(); + test(); + IF( hEncoderConfig->Opt_RF_ON == 0 && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + reset_rf_indices_fx( hCoreCoder ); + } + hEncoderConfig->Opt_RF_ON = 1; + hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc; + hIvasEnc->switchingActive = true; + move16(); + move16(); + move16(); + } + + /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */ + test(); + test(); + IF( ( EQ_32( hEncoderConfig->input_Fs, 8000 ) || ( hEncoderConfig->max_bwidth == NB ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) ) + { + hEncoderConfig->ivas_total_brate = ACELP_24k40; + st_ivas->codec_mode = MODE2; + hIvasEnc->switchingActive = true; + move32(); + move16(); + move16(); + } + + /*-----------------------------------------------------------------* + * Re-allocate and re-initialize buffer of indices if IVAS total bitrate has changed + *-----------------------------------------------------------------*/ + + IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) ) + { + /* de-allocate old buffer of indices */ + free( st_ivas->ind_list ); + + /* set the maximum allowed number of indices in the list */ + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + /* allocate new 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; + move16(); + } + + /* de-allocate old buffer of metadata indices */ + IF( st_ivas->ind_list_metadata != NULL ) + { + free( st_ivas->ind_list_metadata ); + } + + /* 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( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + move16(); + + IF( st_ivas->ivas_max_num_indices_metadata > 0 ) + { + /* allocate new buffer of metadata indices */ + 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; + move16(); + } + } + ELSE + { + st_ivas->ind_list_metadata = NULL; + } + + /* set pointers to the new buffers of indices in each element */ + FOR( n = 0; n < st_ivas->nSCE; n++ ) + { + test(); + IF( !( hIvasEnc->hCoreCoder == NULL && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) ) + { + if ( ( hEncoderConfig->element_mode_init != EVS_MONO ) ) + { + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list; + } + st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + + IF( st_ivas->hSCE[n]->hMetaData != NULL ) + { + st_ivas->hSCE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hSCE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + + FOR( n = 0; n < st_ivas->nCPE; n++ ) + { + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ind_list = st_ivas->ind_list; + st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list; + } + IF( st_ivas->hCPE[n]->hMetaData != NULL ) + { + st_ivas->hCPE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata; + st_ivas->hCPE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata; + } + } + } + + test(); + IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) + { + copy_encoder_config_fx( st_ivas, hCoreCoder, 0 ); + hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate; + move32(); + } + + /* run the main encoding routine */ + IF( EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* EVS mono */ + { + hCoreCoder->total_brate = hEncoderConfig->ivas_total_brate; /* needed in case of bitrate switching */ + move32(); + + IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) ) + { + inputBufferSize = shr( inputBufferSize, 1 ); + stereo_dmx_evs_enc_fx( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural ); + } + + IF( hEncoderConfig->Opt_AMR_WB ) + { + amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize ); + } + ELSE + { + hCoreCoder->input_frame_fx = inputBufferSize; + move32(); + IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + } + ELSE /* IVAS */ + { + IF( NE_32( ( error = ivas_enc( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + /* write indices into bitstream buffer */ + IF( EQ_16( hEncoderConfig->element_mode_init, EVS_MONO ) ) + { + test(); + IF( EQ_16( 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; + move16(); + write_indices_buf_fx( hCoreCoder, hCoreCoder->hBstr, outputBitStream, pFrame, pFrame_size, numOutBits ); + } + } + ELSE + { + write_indices_ivas_fx( st_ivas, outputBitStream, numOutBits ); + } + /* Reset switching flag before next call - can be set to "true" by some setters */ + hIvasEnc->switchingActive = false; + move16(); + + return error; +} +#else ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ int16_t *inputBuffer, /* i : PCM input */ @@ -1642,7 +1935,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE; } - if ( ( error = sanitizeBandwidth( hIvasEnc ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK ) { return error; } @@ -1716,7 +2009,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( free( st_ivas->ind_list ); /* set the maximum allowed number of indices in the list */ - st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); /* allocate new buffer of indices */ if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL ) @@ -1737,7 +2030,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } /* set the maximum allowed number of metadata indices in the list */ - st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); + st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate ); if ( st_ivas->ivas_max_num_indices_metadata > 0 ) { @@ -1885,6 +2178,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( return error; } +#endif #ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* @@ -1935,7 +2229,7 @@ ivas_error IVAS_ENC_SetBandwidth( } /* Use internal function to set bandiwdth */ - return setBandwidth( hIvasEnc, maxBandwidth ); + return setBandwidth_fx( hIvasEnc, maxBandwidth ); } @@ -1984,7 +2278,7 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( } /* Use internal function to set CA config */ - return setChannelAwareConfig( hIvasEnc, rfConfig ); + return setChannelAwareConfig_fx( hIvasEnc, rfConfig ); } @@ -2034,8 +2328,11 @@ IVAS_ENC_CHANNEL_AWARE_CONFIG IVAS_ENC_GetDefaultChannelAwareConfig( void ) { IVAS_ENC_CHANNEL_AWARE_CONFIG defaultCaConfig; defaultCaConfig.channelAwareModeEnabled = 0; + move16(); defaultCaConfig.fec_indicator = IVAS_ENC_FEC_HI; + move16(); defaultCaConfig.fec_offset = 0; + move16(); return defaultCaConfig; } @@ -2308,7 +2605,7 @@ static ivas_error setBitrate( /* check if the entered bitrate is supported */ if ( hEncoderConfig->element_mode_init > EVS_MONO ) { - if ( !is_IVAS_bitrate( hEncoderConfig->ivas_total_brate ) ) + if ( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS: %d", hEncoderConfig->ivas_total_brate ); } @@ -2329,7 +2626,7 @@ static ivas_error setBitrate( if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { - if ( ( error = sanitizeBitrateISM( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) + if ( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK ) { return error; } @@ -2359,64 +2656,6 @@ static ivas_error setBitrate( * *---------------------------------------------------------------------*/ -static ivas_error setChannelAwareConfig( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig ) -{ - int16_t 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 && st_ivas->hEncoderConfig->ivas_total_brate != ACELP_13k20 ) || ( hEncoderConfig->Opt_RF_ON && hEncoderConfig->input_Fs == 8000 ) ) - { - hEncoderConfig->Opt_RF_ON = 0; - hEncoderConfig->rf_fec_offset = 0; - return IVAS_ERR_OK; - } - - if ( caConfig.channelAwareModeEnabled ) - { - hEncoderConfig->Opt_RF_ON = 1; - - /* Convert FEC indicator from API type */ - if ( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* Set new values only if they differ from current values */ - if ( ( newFecIndicator != hEncoderConfig->rf_fec_indicator || caConfig.fec_offset != hEncoderConfig->rf_fec_offset ) ) - { - hEncoderConfig->rf_fec_indicator = newFecIndicator; - - /* Check if new FEC offset has a valid value */ - if ( caConfig.fec_offset == 0 || caConfig.fec_offset == 2 || caConfig.fec_offset == 3 || caConfig.fec_offset == 5 || caConfig.fec_offset == 7 ) - { - hEncoderConfig->rf_fec_offset = caConfig.fec_offset; - } - else - { - return IVAS_ERR_INVALID_FEC_OFFSET; - } - - 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; -} #ifdef IVAS_FLOAT_FIXED static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, @@ -2531,94 +2770,6 @@ static ivas_error doCommonSetterChecks( * *---------------------------------------------------------------------*/ -static ivas_error sanitizeBandwidth( - const IVAS_ENC_HANDLE hIvasEnc ) -{ - ENCODER_CONFIG_HANDLE hEncoderConfig; - int16_t 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 ( hEncoderConfig->input_Fs == 8000 && max_bwidth_tmp > NB ) - { - max_bwidth_tmp = NB; - } - else if ( hEncoderConfig->input_Fs == 16000 && max_bwidth_tmp > WB ) - { - max_bwidth_tmp = WB; - } - else if ( hEncoderConfig->input_Fs == 32000 && max_bwidth_tmp > SWB ) - { - max_bwidth_tmp = SWB; - } - - /* NB coding not supported in IVAS. Switching to WB. */ - if ( max_bwidth_tmp == NB && hEncoderConfig->ivas_format != UNDEFINED_FORMAT && hEncoderConfig->ivas_format != MONO_FORMAT ) - { - if ( hEncoderConfig->input_Fs >= 16000 ) - { - max_bwidth_tmp = WB; - } - else - { - return IVAS_ERR_INVALID_BITRATE; - } - } - - if ( 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 ) - { - if ( hEncoderConfig->ivas_total_brate < ACELP_9k60 ) - { - max_bwidth_tmp = WB; - } - else - { - max_bwidth_tmp = SWB; - } - } - - if ( max_bwidth_tmp == SWB && hEncoderConfig->ivas_total_brate < ACELP_9k60 ) - { - max_bwidth_tmp = WB; - } - - /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */ - if ( ( max_bwidth_tmp == NB || hEncoderConfig->input_Fs == 8000 ) && hEncoderConfig->ivas_total_brate > ACELP_24k40 ) - { - if ( hEncoderConfig->input_Fs >= 16000 ) - { - max_bwidth_tmp = WB; - } - else - { - return IVAS_ERR_INVALID_BITRATE; - } - } -#endif - } - else - { - if ( max_bwidth_tmp == FB && ( ( hEncoderConfig->ivas_format != ISM_FORMAT && hEncoderConfig->ivas_total_brate < MIN_BRATE_FB_STEREO ) || - ( hEncoderConfig->ivas_format == ISM_FORMAT && hEncoderConfig->ivas_total_brate / hEncoderConfig->nchan_ism < MIN_BRATE_FB_ISM ) ) ) - { - max_bwidth_tmp = SWB; - } - } - - if ( hEncoderConfig->max_bwidth != max_bwidth_tmp ) - { - hEncoderConfig->max_bwidth = max_bwidth_tmp; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc ) @@ -2710,56 +2861,11 @@ static ivas_error sanitizeBandwidth_fx( } #endif /*---------------------------------------------------------------------* - * sanitizeBitrateISM() + * sanitizeBitrateISM_fx() * * *---------------------------------------------------------------------*/ -static ivas_error sanitizeBitrateISM( - const ENCODER_CONFIG_HANDLE hEncoderConfig, - const bool extMetadataApi ) -{ - if ( hEncoderConfig->ivas_total_brate > IVAS_128k && 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 ( hEncoderConfig->ivas_total_brate > IVAS_256k && 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 ( hEncoderConfig->ivas_total_brate > IVAS_384k && 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 ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && 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 ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && 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 ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && 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 = ( hEncoderConfig->ivas_total_brate >= ISM_EXTENDED_METADATA_BRATE ); - } - else - { - hEncoderConfig->ism_extended_metadata_flag = 0; - } - - return IVAS_ERR_OK; -} #ifdef IVAS_FLOAT_FIXED static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, @@ -2808,44 +2914,11 @@ static ivas_error sanitizeBitrateISM_fx( } #endif /*---------------------------------------------------------------------* - * setBandwidth() + * setBandwidth_fx() * * *---------------------------------------------------------------------*/ -static ivas_error setBandwidth( - IVAS_ENC_HANDLE hIvasEnc, - const IVAS_ENC_BANDWIDTH maxBandwidth ) -{ - ivas_error error; - int16_t newBandwidth; - ENCODER_CONFIG_HANDLE hEncoderConfig; - - hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; - - /* Convert bandwidth from API type */ - if ( ( error = bandwidthApiToInternal( maxBandwidth, &newBandwidth ) ) != IVAS_ERR_OK ) - { - return error; - } - - 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; - } - - if ( hEncoderConfig->max_bwidth != newBandwidth ) - { - hEncoderConfig->max_bwidth = newBandwidth; - hIvasEnc->switchingActive = true; - } - - return IVAS_ERR_OK; -} -#ifdef IVAS_FLOAT_FIXED static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth ) @@ -2878,7 +2951,6 @@ static ivas_error setBandwidth_fx( return IVAS_ERR_OK; } -#endif /*---------------------------------------------------------------------* * resetIsmMetadataProvidedFlags() diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index c50055f33..67e747393 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -257,6 +257,16 @@ ivas_error IVAS_ENC_FeedMasaMetadata( IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */ ); +#ifdef IVAS_FLOAT_FIXED +/*! r: error code */ +ivas_error IVAS_ENC_EncodeFrameToSerial( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + Word16 *inputBuffer, /* i : PCM input, Q0 */ + Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() */ + UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ + UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ +); +#else /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToSerial( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ @@ -265,6 +275,7 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( uint16_t *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME */ uint16_t *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value */ ); +#endif /*! r: error code */ ivas_error IVAS_ENC_EncodeFrameToCompact( diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index d113f7c4c..d41b70076 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4393,4 +4393,9 @@ void SynthesisSTFT_enc_ivas_fx( const Word16 nchan_out /* i : number of output channels */ ); +ivas_error write_indices_ivas_fx( + Encoder_Struct *st_ivas, /* i/o: encoder state structure */ + UWord16 *bit_stream, /* i/o: output bitstream */ + UWord16 *num_bits /* i : number of indices written to output */ +); #endif diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index ab172f972..8e1f4d043 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -391,7 +391,7 @@ ivas_error ivas_td_decorr_dec_open_fx( IF( ducking_flag ) { - IF( NE_32( ( error = ivas_transient_det_open( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_transient_det_open_fx( &hTdDecorr_loc->pTrans_det, output_Fs ) ), IVAS_ERR_OK ) ) { return error; } @@ -508,7 +508,7 @@ void ivas_td_decorr_dec_close( IF( ( *hTdDecorr )->pTrans_det != NULL ) { - ivas_transient_det_close( &( *hTdDecorr )->pTrans_det ); + ivas_transient_det_close_fx( &( *hTdDecorr )->pTrans_det ); } free( ( *hTdDecorr ) ); -- GitLab From f8712cf567d035c33476c7da393a41d93eb27ce2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:26:14 +0530 Subject: [PATCH 37/39] Encoder float structure elements cleanup and lib_com Q-info updates --- lib_com/cb_shape_fx.c | 19 +- lib_com/cldfb.c | 444 ++++++++++++++--------------- lib_com/cldfb_evs.c | 233 +++++++-------- lib_com/fft_cldfb_fx.c | 12 +- lib_com/fft_rel.c | 84 +++--- lib_com/fft_rel_fx.c | 18 +- lib_com/fill_spectrum.c | 10 +- lib_com/findpulse.c | 24 +- lib_com/frame_ener.c | 24 +- lib_com/get_gain.c | 8 +- lib_com/gs_bitallocation_ivas_fx.c | 122 ++++---- lib_com/gs_gains.c | 49 ++-- lib_com/gs_gains_fx.c | 102 +++---- lib_com/gs_inact_switching_fx.c | 19 +- lib_com/gs_noisefill_fx.c | 59 ++-- lib_com/hq2_core_com.c | 40 +-- lib_com/hq2_core_com_fx.c | 300 +++++++++---------- lib_com/hq2_noise_inject_fx.c | 257 ++++++++--------- lib_com/hq_bit_allocation_fx.c | 14 +- lib_com/hq_conf.c | 114 +++----- lib_com/hq_conf_fx.c | 236 ++++++--------- lib_com/hvq_pvq_bitalloc_fx.c | 30 +- lib_com/interleave_spectrum.c | 103 ++++--- lib_com/ivas_prot_fx.h | 2 +- lib_com/prot.h | 2 + lib_com/prot_fx.h | 193 +++++++------ lib_com/rom_com.c | 10 +- lib_com/rom_com.h | 10 +- lib_com/stat_noise_uv_mod.c | 2 + lib_com/swb_bwe_com_lr.c | 2 + lib_enc/acelp_core_enc.c | 38 +-- lib_enc/acelp_core_switch_enc.c | 2 + lib_enc/core_enc_init.c | 9 + lib_enc/core_enc_switch.c | 6 - lib_enc/core_switching_enc.c | 17 ++ lib_enc/hq_core_enc.c | 3 +- lib_enc/igf_enc.c | 22 +- lib_enc/init_enc.c | 63 ++-- lib_enc/ivas_core_enc.c | 10 - lib_enc/ivas_core_pre_proc_front.c | 5 - lib_enc/ivas_cpe_enc.c | 3 - lib_enc/ivas_dirac_enc.c | 21 +- lib_enc/ivas_masa_enc.c | 105 +++---- lib_enc/ivas_mct_enc.c | 6 - lib_enc/ivas_qmetadata_enc.c | 58 ++-- lib_enc/ivas_tcx_core_enc.c | 3 - lib_enc/rst_enc.c | 12 + lib_enc/stat_enc.h | 143 ++++++---- lib_enc/swb_tbe_enc.c | 12 +- 49 files changed, 1541 insertions(+), 1539 deletions(-) diff --git a/lib_com/cb_shape_fx.c b/lib_com/cb_shape_fx.c index fcd9e06e4..56d645ce0 100644 --- a/lib_com/cb_shape_fx.c +++ b/lib_com/cb_shape_fx.c @@ -28,7 +28,7 @@ static void E_GAIN_f_pitch_sharpening( Word16 *x, Word16 pit_lag, Word16 L_subfr FOR( i = pit_lag; i < L_subfr; i++ ) { /*x[i] += x[i - pit_lag] * F_PIT_SHARP;*/ - tmp = mult_r( x[sub( i, pit_lag )], 27853 /*F_PIT_SHARP Q15*/ ); + tmp = mult_r( x[i - pit_lag], 27853 /*F_PIT_SHARP Q15*/ ); x[i] = add( x[i], tmp ); move16(); } @@ -47,12 +47,12 @@ void cb_shape_fx( 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 g1, /* i : formant sharpening numerator weighting Q15 */ + const Word16 g2, /* i : formant sharpening denominator weighting Q15 */ + const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ + Word16 *code, /* i/o: signal to shape Q9 */ + const Word16 tilt_code, /* i : tilt of code Q15 */ + const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6 */ const Word16 shift, const Word16 L_subfr /* i : subframe lenght */ ) @@ -88,8 +88,8 @@ void cb_shape_fx( 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] ); + L_tmp = L_mult( 22938 /*.7f in Q15*/, buff[i] ); // Q15+Q9+1 + tmp = mac_r( L_tmp, -22938 /*-.7f in Q15*/, code[i - 1] ); // Q9 code[i] = add( tmp, buff[i - 1] ); move16(); } @@ -121,7 +121,6 @@ void cb_shape_fx( { Copy( code, buff, L_subfr ); - move16(); Residu3_lc_fx( A_num, M, buff, code, L_subfr, shift ); { syn_filt_s_lc_fx( shift, A_den, code, code, L_subfr ); diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 4eae5458f..5b6e77394 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -307,7 +307,7 @@ void cldfbAnalysis_ivas_fx( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, div_l( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), shr( h_cldfb->no_channels, 1 ) ) ); + no_col = s_min( no_col, div_l( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), shr( h_cldfb->no_channels, 1 ) ) ); } M1 = h_cldfb->no_channels; @@ -333,29 +333,29 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -368,7 +368,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &rBuffer_fx[2 * k], &rBuffer_fx[2 * k + 1], rr12_fx, ri12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ @@ -377,36 +377,36 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &iBuffer_fx[2 * k], &iBuffer_fx[2 * k + 1], ir12_fx, ii12_fx, rot_vctr_re_fx[k], rot_vctr_im_fx[k] ); iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // Qx - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // Qx + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // Qx + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // Qx + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // Qx + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // Qx r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // Qx - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // Qx - 1 @@ -419,7 +419,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &rBuffer_fx[2 * k], &rBuffer[2 * k + 1], rr12, ri12, rot_vctr_re[k], rot_vctr_im[k] ); rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + rBuffer_fx[( 2 * k ) + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); /* folding + pre modulation of DCT IV */ @@ -428,7 +428,7 @@ void cldfbAnalysis_ivas_fx( // cplxMult( &iBuffer[2 * k], &iBuffer[2 * k + 1], ir12, ii12, rot_vctr_re[k], rot_vctr_im[k] ); iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // Qx - 3 move32(); - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 + iBuffer_fx[( 2 * k ) + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // Qx - 3 move32(); } @@ -440,9 +440,9 @@ void cldfbAnalysis_ivas_fx( FOR( k = 0; k < M2; k++ ) { // cplxMult( &realBuffer[i][M1 - 1 - ( 2 * k )], &realBuffer[i][2 * k], rBuffer[2 * k], rBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - realBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // Qx - 5 + realBuffer_fx[i][( M1 - 1 ) - ( k * 2 )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // Qx - 5 move32(); - realBuffer_fx[i][2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 + realBuffer_fx[i][2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } @@ -455,9 +455,9 @@ void cldfbAnalysis_ivas_fx( { /* do it inplace */ // cplxMult( &imagBuffer[i][2 * k], &imagBuffer[i][M1 - 1 - ( 2 * k )], iBuffer[2 * k], iBuffer[2 * k + 1], rot_vctr_re[k], rot_vctr_im[k] ); - imagBuffer_fx[i][2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // QX - 5 + imagBuffer_fx[i][2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[( 2 * k + 1 )], rot_vctr_im_fx[k] ); // QX - 5 move32(); - imagBuffer_fx[i][sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // Qx - 5 + imagBuffer_fx[i][( ( M1 - 1 ) - ( k * 2 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // Qx - 5 move32(); } @@ -743,20 +743,17 @@ void cldfbAnalysis_ts_fx( move16(); /* only process needed cols */ - IF( samplesToProcess > -1 ) + IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } M1 = h_cldfb->no_channels; move16(); M2 = shr( M1, 1 ); - move16(); M4 = shr( M1, 2 ); - move16(); L2 = shl( M1, 1 ); - move16(); if ( s_and( M2, 1 ) ) { @@ -777,29 +774,29 @@ void cldfbAnalysis_ts_fx( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[L2 - M2 - 1 - ( 2 * k ) + 0 * L2] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, 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 @@ -810,8 +807,8 @@ void cldfbAnalysis_ts_fx( 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[add( 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 move32(); move32(); @@ -819,8 +816,8 @@ void cldfbAnalysis_ts_fx( 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[add( 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 move32(); move32(); } @@ -828,29 +825,29 @@ void cldfbAnalysis_ts_fx( FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + 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 @@ -861,8 +858,8 @@ void cldfbAnalysis_ts_fx( 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[add( 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 move32(); move32(); @@ -870,8 +867,8 @@ void cldfbAnalysis_ts_fx( 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[add( 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 move32(); move32(); } @@ -884,12 +881,12 @@ void cldfbAnalysis_ts_fx( q_shift = sub( s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ), find_guarded_bits_fx( M2 ) ); *q_cldfb = add( *q_cldfb, q_shift ); move16(); - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); move32(); } - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); move32(); @@ -900,8 +897,8 @@ 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[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_sub( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), Mpy_32_32( rBuffer_fx[add( 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[add( 2 * k, 1 )], rot_vctr_re_fx[k] ) ); // q - 5 + realBuffer_fx[( ( M1 - 1 ) - ( k * 2 ) )] = 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 move32(); move32(); } @@ -914,12 +911,12 @@ void cldfbAnalysis_ts_fx( q_shift = s_min( getScaleFactor32( rBuffer_fx, shl( M2, 1 ) ), getScaleFactor32( iBuffer_fx, shl( M2, 1 ) ) ); *q_cldfb = add( *q_cldfb, q_shift ); move16(); - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { rBuffer_fx[ind] = L_shl( rBuffer_fx[ind], q_shift ); move32(); } - FOR( Word16 ind = 0; ind < shl( M2, 1 ); ind++ ) + FOR( Word16 ind = 0; ind < M2 * 2; ind++ ) { iBuffer_fx[ind] = L_shl( iBuffer_fx[ind], q_shift ); move32(); @@ -930,8 +927,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[add( 2 * k, 1 )], rot_vctr_im_fx[k] ) ); // q - 5 - imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = L_add( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), Mpy_32_32( iBuffer_fx[add( 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 ) - ( k * 2 )] = 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 move32(); move32(); } @@ -1028,7 +1025,7 @@ void cldfbAnalysis_ts_fx_fixed_q( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); assert( no_col == 1 ); } @@ -1037,9 +1034,6 @@ void cldfbAnalysis_ts_fx_fixed_q( M4 = shr( M1, 2 ); L2 = shl( M1, 1 ); move16(); - move16(); - move16(); - move16(); if ( s_and( M2, 1 ) ) { @@ -1060,29 +1054,29 @@ void cldfbAnalysis_ts_fx_fixed_q( FOR( k = 0; k < M4; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, M2 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, i_mult( 3, M2 ) ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, 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 @@ -1093,8 +1087,8 @@ void cldfbAnalysis_ts_fx_fixed_q( 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] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); @@ -1102,8 +1096,8 @@ void cldfbAnalysis_ts_fx_fixed_q( 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] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); } @@ -1111,29 +1105,29 @@ void cldfbAnalysis_ts_fx_fixed_q( FOR( k = M4; k < M2; k++ ) { /* prototype filter */ - r1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( sub( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - r2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 5, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i1_fx = Msub_32_16( 0, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( sub( sub( add( L2, M2 ), 1 ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q - - i2_fx = Msub_32_16( 0, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 0, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 1, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 2, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 3, L2 ) ) )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) )], ptr_pf_fx[( add( add( sub( L2, i_mult( 3, M2 ) ), shl( k, 1 ) ), i_mult( 4, L2 ) ) )] ); // q + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, 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 @@ -1144,8 +1138,8 @@ void cldfbAnalysis_ts_fx_fixed_q( 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] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 - rBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); @@ -1153,8 +1147,8 @@ void cldfbAnalysis_ts_fx_fixed_q( 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] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 - iBuffer_fx[add( 2 * k, 1 )] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 move32(); move32(); } @@ -1169,8 +1163,8 @@ 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[sub( sub( M1, 1 ), shl( k, 1 ) )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 - realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + realBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 move32(); move32(); } @@ -1185,8 +1179,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] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_im_fx[k] ); // q - 5 - imagBuffer_fx[sub( sub( M1, 1 ), shl( k, 1 ) )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[add( 2 * k, 1 )], rot_vctr_re_fx[k] ); // q - 5 + imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 move32(); move32(); } @@ -1459,6 +1453,7 @@ void cldfbSynthesis_ivas_fx( move16(); M1 = h_cldfb->no_channels; + move16(); L2 = shl( M1, 1 ); M2 = shr( M1, 1 ); M41 = shr( M2, 1 ); @@ -1468,7 +1463,7 @@ void cldfbSynthesis_ivas_fx( /* only process needed cols */ IF( GT_16( samplesToProcess, -1 ) ) { - no_col = min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); move16(); } @@ -1491,7 +1486,7 @@ void cldfbSynthesis_ivas_fx( FOR( k = 0; k < no_col; k++ ) { - IF( EQ_16( (Word16) h_cldfb->prototype, (Word16) CLDFB_PROTOTYPE_5_00MS ) ) + IF( EQ_16( h_cldfb->prototype, CLDFB_PROTOTYPE_5_00MS ) ) { /* rotation due to delay*/ /*if(h_cldfb->ds != M1)*/ @@ -1527,16 +1522,16 @@ void cldfbSynthesis_ivas_fx( { /* pre modulation of DST IV */ /*cplxMult(&rBuffer[2*i], &rBuffer[2*i+1], realBuffer[k][2*i], realBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - rBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx + rBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_re_fx[i] ), realBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[i] ); // Qx move32(); - rBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), realBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx + rBuffer_fx[2 * i + 1] = Madd_32_32( Mpy_32_32( realBuffer_fx[k][2 * i], rot_vctr_im_fx[i] ), realBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[i] ); // Qx move32(); /* pre modulation of DCT IV */ /*cplxMult(&iBuffer[2*i], &iBuffer[2*i+1],-imagBuffer[k][2*i], imagBuffer[k][M1-1-2*i], rot_vctr_re[i], rot_vctr_im[i]);*/ - iBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[i] ); // Qx + iBuffer_fx[2 * i] = Msub_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_re_fx[i] ), imagBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[i] ); // Qx move32(); - iBuffer_fx[add( 2 * i, 1 )] = Madd_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), imagBuffer_fx[k][sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[i] ); // Qx + iBuffer_fx[2 * i + 1] = Madd_32_32( Mpy_32_32( ( L_negate( imagBuffer_fx[k][2 * i] ) ), rot_vctr_im_fx[i] ), imagBuffer_fx[k][( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[i] ); // Qx move32(); } @@ -1550,69 +1545,69 @@ void cldfbSynthesis_ivas_fx( FOR( i = 0; i < M41; i++ ) { /* post modulation of DST IV */ - rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx - ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), rBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ), rBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ), rBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ); // Qx /* post modulation of DCT IV */ - ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ); // Qx - ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[sub( sub( M1, 2 ), shl( i, 1 ) )], rot_vctr_im_fx[sub( sub( M2, 1 ), i )] ), iBuffer_fx[sub( sub( M1, 1 ), shl( i, 1 ) )], rot_vctr_re_fx[sub( sub( M2, 1 ), i )] ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ), iBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[( M1 - 2 ) - ( i * 2 )], rot_vctr_im_fx[( M2 - 1 ) - i] ), iBuffer_fx[( M1 - 1 ) - ( i * 2 )], rot_vctr_re_fx[( M2 - 1 ) - i] ); // Qx - new_samples_fx[add( add( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx + new_samples_fx[M1 + M2 + 1 + 2 * i] = L_negate( L_add( rr12_fx, ii12_fx ) ); // Qx move32(); - new_samples_fx[sub( sub( M2, 2 ), shl( i, 1 ) )] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx + new_samples_fx[M2 - 2 - 2 * i] = L_negate( L_add( ri12_fx, ir12_fx ) ); // Qx move32(); - new_samples_fx[sub( sub( add( M1, M2 ), 2 ), shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M1 + M2 - 2 - 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[add( add( M2, 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[M2 + 1 + 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); } FOR( i = 0; i < M42; i++ ) { /* post modulation of DST IV */ - rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx - ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), rBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx + rr12_fx = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_re_fx[i] ), rBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ); // Qx + ri12_fx = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * i], rot_vctr_im_fx[i] ), rBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ); // Qx /* post modulation of DCT IV */ - ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_im_fx[i] ); // Qx - ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), iBuffer_fx[add( 2 * i, 1 )], rot_vctr_re_fx[i] ); // Qx + ir12_fx = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_re_fx[i] ), iBuffer_fx[2 * i + 1], rot_vctr_im_fx[i] ); // Qx + ii12_fx = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * i], rot_vctr_im_fx[i] ), iBuffer_fx[2 * i + 1], rot_vctr_re_fx[i] ); // Qx - new_samples_fx[add( add( M1, M2 ), shl( i, 1 ) )] = L_add( ri12_fx, ir12_fx ); // Qx + new_samples_fx[M1 + M2 + 2 * i] = L_add( ri12_fx, ir12_fx ); // Qx move32(); - new_samples_fx[sub( sub( M2, 1 ), shl( i, 1 ) )] = L_add( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M2 - 1 - 2 * i] = L_add( rr12_fx, ii12_fx ); // Qx move32(); - new_samples_fx[sub( sub( add( M1, M2 ), 1 ), shl( i, 1 ) )] = L_sub( ir12_fx, ri12_fx ); // Qx + new_samples_fx[M1 + M2 - 1 - 2 * i] = L_sub( ir12_fx, ri12_fx ); // Qx move32(); - new_samples_fx[add( M2, shl( i, 1 ) )] = L_sub( rr12_fx, ii12_fx ); // Qx + new_samples_fx[M2 + 2 * i] = L_sub( rr12_fx, ii12_fx ); // Qx move32(); } /* synthesis prototype filter */ FOR( i = 0; i < L2; i++ ) { - accu0 = Madd_32_16( synthesisBuffer_fx[i], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[i] ), p_filter_sf ); // Qx - 1 - accu1 = Madd_32_16( synthesisBuffer_fx[add( L2, i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( L2, i )] ), p_filter_sf ); // Qx - 1 - accu2 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 2, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 2, L2 ), i )] ), p_filter_sf ); // Qx - 1 - accu3 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 3, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 3, L2 ), i )] ), p_filter_sf ); // Qx - 1 - accu4 = Madd_32_16( synthesisBuffer_fx[add( i_mult( 4, L2 ), i )], Mpy_32_16_1( new_samples_fx[sub( sub( L2, 1 ), i )], p_filter[add( i_mult( 4, L2 ), i )] ), p_filter_sf ); // Qx - 1 + accu0 = Madd_32_16( synthesisBuffer_fx[i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[i] ), p_filter_sf ); // Qx - 1 + accu1 = Madd_32_16( synthesisBuffer_fx[1 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 1 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu2 = Madd_32_16( synthesisBuffer_fx[2 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 2 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu3 = Madd_32_16( synthesisBuffer_fx[3 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 3 * L2 + i )] ), p_filter_sf ); // Qx - 1 + accu4 = Madd_32_16( synthesisBuffer_fx[4 * L2 + i], Mpy_32_16_1( new_samples_fx[L2 - 1 - i], p_filter[( 4 * L2 + i )] ), p_filter_sf ); // Qx - 1 synthesisBuffer_fx[i] = accu0; move32(); - synthesisBuffer_fx[add( L2, i )] = accu1; + synthesisBuffer_fx[1 * L2 + i] = accu1; move32(); - synthesisBuffer_fx[add( i_mult( 2, L2 ), i )] = accu2; + synthesisBuffer_fx[2 * L2 + i] = accu2; move32(); - synthesisBuffer_fx[add( i_mult( 3, L2 ), i )] = accu3; + synthesisBuffer_fx[3 * L2 + i] = accu3; move32(); - synthesisBuffer_fx[add( i_mult( 4, L2 ), i )] = accu4; + synthesisBuffer_fx[4 * L2 + i] = accu4; move32(); } FOR( i = 0; i < M1; i++ ) { - ptr_time_out_fx[sub( sub( M1, 1 ), i )] = synthesisBuffer_fx[add( i_mult( 4, L2 ), add( M1, i ) )]; + ptr_time_out_fx[( M1 - 1 ) - i] = synthesisBuffer_fx[4 * L2 + M1 + i]; move32(); } @@ -1728,9 +1723,9 @@ ivas_error openCldfb_ivas_fx( } hs->type = type; - move16(); + move32(); hs->prototype = prototype; - move16(); + move32(); configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory32 = NULL; hs->FilterStates = NULL; @@ -1958,11 +1953,11 @@ void analysisCldfbEncoder_ivas_fx( Word32 *timeIn, /*q11*/ Word16 timeInq, Word16 samplesToProcess, - 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 *ppBuf_Ener, + Word32 realBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(scale.lb_scale) + Word32 imagBuffer[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(scale.lb_scale) + Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q15 + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q15 + Word32 *ppBuf_Ener, // Q(31-enerBuffSum_exp) Word16 *enerBuffSum_exp, CLDFB_SCALE_FACTOR *scale ) { @@ -2135,6 +2130,7 @@ void deleteCldfb_ivas_fx( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; + test(); IF( h_cldfb == NULL || *h_cldfb == NULL ) { return; @@ -3239,7 +3235,7 @@ ivas_error cldfb_save_memory_ivas_fx( ) { UWord16 offset = sub( hs->p_filter_length, hs->no_channels ); - + test(); IF( hs->memory32 != NULL || ( hs->memory_length != 0 ) ) { /* memory already stored; Free memory first */ diff --git a/lib_com/cldfb_evs.c b/lib_com/cldfb_evs.c index 1186c82fa..c22e583be 100644 --- a/lib_com/cldfb_evs.c +++ b/lib_com/cldfb_evs.c @@ -241,9 +241,9 @@ static void calcModulation( Word32 *rYR, C_c = C_form( *cr, *ci ); CL_z = CL_mult_32x16( CL_x, C_c ); *rYR = CL_Extract_real( CL_z ); - move64(); + move32(); *rYI = CL_Extract_imag( CL_z ); - move64(); + move32(); rYR += srYR; rYI += srYI; rXR += srXR; @@ -252,9 +252,9 @@ static void calcModulation( Word32 *rYR, CL_x = CL_form( *iXR, *iXI ); CL_z = CL_mult_32x16( CL_x, C_c ); *iYR = CL_Extract_real( CL_z ); - move64(); + move32(); *iYI = CL_Extract_imag( CL_z ); - move64(); + move32(); iYR += siYR; iYI += siYI; iXR += siXR; @@ -301,14 +301,14 @@ static void calcModulationAndFolding( Word16 *rY, const Word16 *r11, *r12, *r21, *r22; - y11 = &rY[add( add( m, m2 ), 1 )]; - y12 = &rY[sub( m2, 2 )]; - y13 = &rY[sub( add( m, m2 ), 2 )]; + y11 = &rY[( m + m2 ) + 1]; + y12 = &rY[m2 - 2]; + y13 = &rY[( m + m2 ) - 2]; y14 = &rY[m2 + 1]; - y21 = &rY[add( m, m2 )]; + y21 = &rY[m + m2]; y22 = &rY[m2 - 1]; - y23 = &rY[sub( add( m, m2 ), 1 )]; + y23 = &rY[( m + m2 ) - 1]; y24 = &rY[m2]; x11 = &rX[m - 2]; @@ -376,10 +376,11 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Word32 **rAnalysis, Word32 **iAnalysis, CLDFB_SCALE_FACTOR *scaleFactor, - const Word16 *timeIn, + const Word16 *timeIn, // Q(15-timeIn_e) const Word16 timeIn_e, const Word16 nTimeSlots, - Word32 *pWorkBuffer ) + Word32 *pWorkBuffer // Qx +) { Word16 i, k; @@ -450,13 +451,14 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, pStates6 = &pStates[M0M2]; p_stride = CLDFB_NO_POLY; + move16(); pFilter = &cldfbBank->p_filter[p_stride - CLDFB_NO_POLY]; - pFilter1 = &pFilter[i_mult( p_stride, L3M1 )]; - pFilter2 = &pFilter[i_mult( p_stride, L3 )]; - pFilter3 = &pFilter[i_mult( p_stride, m2 )]; - pFilter4 = &pFilter[i_mult( p_stride, M2M1 )]; - pFilter5 = &pFilter[i_mult( p_stride, L4M1 )]; - pFilter6 = &pFilter[i_mult( p_stride, M0M2 )]; + 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 ); @@ -469,7 +471,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, move16(); FOR( i = 0; i < offset; i += cldfbBank->no_channels ) { - cldfbBank->FilterStates_e[k] = cldfbBank->FilterStates_e[add( 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] ); @@ -496,7 +498,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < offset; i++ ) { #ifdef BASOP_NOGLOB - pStates[i] = shl_sat( pStates[i + nSamplesUpd], scale ); + pStates[i] = shl_sat( pStates[i + nSamplesUpd], scale ); // Q(15-(timeIn_e-FilterStates_eg)) #else pStates[i] = shl( pStates[i + nSamplesUpd], scale ); #endif @@ -508,7 +510,7 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < nSamples; i++ ) { #ifdef BASOP_NOGLOB - pStates[offset + i] = shl_sat( *timeIn, scale ); + pStates[offset + i] = shl_sat( *timeIn, scale ); // Q(15-scale) #else pStates[offset + i] = shl( *timeIn, scale ); #endif @@ -521,80 +523,80 @@ void cldfbAnalysisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < M4; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - r2 = L_msu0( 0, pFilter2[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter2[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates2[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i1 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i2 = L_msu0( 0, pFilter4[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter4[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates4[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( 0, pFilter1[0 - ( p_stride * ( i * 2 ) )], pStates1[( 0 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[1 - ( p_stride * ( i * 2 ) )], pStates1[( 1 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[2 - ( p_stride * ( i * 2 ) )], pStates1[( 2 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[3 - ( p_stride * ( i * 2 ) )], pStates1[( 3 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[4 - ( p_stride * ( i * 2 ) )], pStates1[( 4 * L2 ) - ( i * 2 )] ); + + r2 = L_msu0( 0, pFilter2[0 + ( p_stride * ( i * 2 ) )], pStates2[( 0 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[1 + ( p_stride * ( i * 2 ) )], pStates2[( 1 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[2 + ( p_stride * ( i * 2 ) )], pStates2[( 2 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[3 + ( p_stride * ( i * 2 ) )], pStates2[( 3 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter2[4 + ( p_stride * ( i * 2 ) )], pStates2[( 4 * L2 ) + ( i * 2 )] ); + + i1 = L_msu0( 0, pFilter3[0 + ( p_stride * ( i * 2 ) )], pStates3[( 0 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[1 + ( p_stride * ( i * 2 ) )], pStates3[( 1 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[2 + ( p_stride * ( i * 2 ) )], pStates3[( 2 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[3 + ( p_stride * ( i * 2 ) )], pStates3[( 3 * L2 ) + ( i * 2 )] ); + i1 = L_msu0( i1, pFilter3[4 + ( p_stride * ( i * 2 ) )], pStates3[( 4 * L2 ) + ( i * 2 )] ); + + i2 = L_msu0( 0, pFilter4[0 - ( p_stride * ( i * 2 ) )], pStates4[( 0 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[1 - ( p_stride * ( i * 2 ) )], pStates4[( 1 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[2 - ( p_stride * ( i * 2 ) )], pStates4[( 2 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[3 - ( p_stride * ( i * 2 ) )], pStates4[( 3 * L2 ) - ( i * 2 )] ); + i2 = L_msu0( i2, pFilter4[4 - ( p_stride * ( i * 2 ) )], pStates4[( 4 * L2 ) - ( i * 2 )] ); /* folding */ rBuffer[2 * i] = L_sub( r1, r2 ); move32(); - rBuffer[add( shl( i, 1 ), 1 )] = L_negate( L_add( i1, i2 ) ); + rBuffer[( ( i * 2 ) + 1 )] = L_negate( L_add( i1, i2 ) ); move32(); /* folding */ iBuffer[2 * i] = L_add( r1, r2 ); move32(); - iBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); + iBuffer[( ( i * 2 ) + 1 )] = L_sub( i1, i2 ); move32(); } FOR( i = M4; i < m2; i++ ) { /* prototype filter */ - r1 = L_msu0( 0, pFilter1[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r1 = L_msu0( r1, pFilter1[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates1[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - r2 = L_msu0( 0, pFilter6[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - r2 = L_msu0( r2, pFilter6[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates6[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i1 = L_msu0( 0, pFilter5[sub( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i1 = L_msu0( i1, pFilter5[sub( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates5[sub( i_mult( 4, L2 ), shl( i, 1 ) )] ); - - i2 = L_msu0( 0, pFilter3[add( 0, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 0, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 1, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 1, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 2, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 2, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 3, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 3, L2 ), shl( i, 1 ) )] ); - i2 = L_msu0( i2, pFilter3[add( 4, i_mult( p_stride, shl( i, 1 ) ) )], pStates3[add( i_mult( 4, L2 ), shl( i, 1 ) )] ); + r1 = L_msu0( 0, pFilter1[0 - ( p_stride * ( i * 2 ) )], pStates1[( 0 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[1 - ( p_stride * ( i * 2 ) )], pStates1[( 1 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[2 - ( p_stride * ( i * 2 ) )], pStates1[( 2 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[3 - ( p_stride * ( i * 2 ) )], pStates1[( 3 * L2 ) - ( i * 2 )] ); + r1 = L_msu0( r1, pFilter1[4 - ( p_stride * ( i * 2 ) )], pStates1[( 4 * L2 ) - ( i * 2 )] ); + + r2 = L_msu0( 0, pFilter6[0 + ( p_stride * ( i * 2 ) )], pStates6[( 0 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[1 + ( p_stride * ( i * 2 ) )], pStates6[( 1 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[2 + ( p_stride * ( i * 2 ) )], pStates6[( 2 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[3 + ( p_stride * ( i * 2 ) )], pStates6[( 3 * L2 ) + ( i * 2 )] ); + r2 = L_msu0( r2, pFilter6[4 + ( p_stride * ( i * 2 ) )], pStates6[( 4 * L2 ) + ( i * 2 )] ); + + i1 = L_msu0( 0, pFilter5[0 - ( p_stride * ( i * 2 ) )], pStates5[( 0 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[1 - ( p_stride * ( i * 2 ) )], pStates5[( 1 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[2 - ( p_stride * ( i * 2 ) )], pStates5[( 2 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[3 - ( p_stride * ( i * 2 ) )], pStates5[( 3 * L2 ) - ( i * 2 )] ); + i1 = L_msu0( i1, pFilter5[4 - ( p_stride * ( i * 2 ) )], pStates5[( 4 * L2 ) - ( i * 2 )] ); + + i2 = L_msu0( 0, pFilter3[0 + ( p_stride * ( i * 2 ) )], pStates3[( 0 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[1 + ( p_stride * ( i * 2 ) )], pStates3[( 1 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[2 + ( p_stride * ( i * 2 ) )], pStates3[( 2 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[3 + ( p_stride * ( i * 2 ) )], pStates3[( 3 * L2 ) + ( i * 2 )] ); + i2 = L_msu0( i2, pFilter3[4 + ( p_stride * ( i * 2 ) )], pStates3[( 4 * L2 ) + ( i * 2 )] ); /* folding */ rBuffer[2 * i] = L_add( r1, r2 ); move32(); - rBuffer[add( shl( i, 1 ), 1 )] = L_sub( i1, i2 ); + rBuffer[( ( i * 2 ) + 1 )] = L_sub( i1, i2 ); move32(); /* folding */ iBuffer[2 * i] = L_sub( r1, r2 ); move32(); - iBuffer[add( shl( i, 1 ), 1 )] = L_add( i1, i2 ); + iBuffer[( ( i * 2 ) + 1 )] = L_add( i1, i2 ); move32(); } @@ -655,10 +657,11 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Word32 **rAnalysis, Word32 **iAnalysis, const CLDFB_SCALE_FACTOR *scaleFactor, - Word16 *timeOut, + Word16 *timeOut, // Q(15-timeOut_e) const Word16 timeOut_e, const Word16 nTimeSlots, - Word32 *pWorkBuffer ) + Word32 *pWorkBuffer // Qx +) { Word16 i; Word16 k; @@ -709,7 +712,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, Lz = s_min( cldfbBank->lsb, sub( m, cldfbBank->bandsToZero ) ); Mz = s_min( cldfbBank->usb, sub( m, cldfbBank->bandsToZero ) ); stride = 1; /* constant */ - + move16(); channels0 = sub( m, cldfbBank->zeros ); channels1 = sub( m, 1 ); channels2 = shl( m, 1 ); @@ -726,7 +729,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, iBuffer = &pWorkBuffer[m]; nBuffer = (Word16 *) ( &pWorkBuffer[L2] ); - rAnalysisS = &pWorkBuffer[i_mult( 3, m )]; + rAnalysisS = &pWorkBuffer[3 * m]; iAnalysisS = &pWorkBuffer[4 * m]; rRotVctr = cldfbBank->rRotVctr; @@ -756,7 +759,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, 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 ) ); // Q(15-scale) cldfbBank->FilterStates_eg = scale; move16(); } @@ -787,9 +790,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, { FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l( 0 ); + rAnalysisS[i] = 0; move32(); - iAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = 0; move32(); } } @@ -817,9 +820,9 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, { FOR( ; i < m; i += 2 ) { - rAnalysisS[i] = L_deposit_l( 0 ); + rAnalysisS[i] = 0; move32(); - iAnalysisS[i] = L_deposit_l( 0 ); + iAnalysisS[i] = 0; move32(); } } @@ -845,7 +848,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, calcModulationAndFolding( nBuffer, rBuffer, iBuffer, rRotVctr, iRotVctr, cldfbBank->synGain, scale, m, m2 ); /* prototype filter */ - pStates = &cldfbBank->FilterStates[i_mult( k, L2 )]; + pStates = &cldfbBank->FilterStates[( k * L2 )]; pFilterS = &cldfbBank->p_filter[0]; pFilterM = &cldfbBank->p_filter[shr( cldfbBank->p_filter_length, 1 )]; @@ -878,7 +881,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[i_mult( sub( 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 ) ); #endif @@ -888,8 +891,8 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( ; i < cldfbBank->no_channels; i++ ) { - pStatesI = &pStates[add( i, channels2 )]; - pStatesR = &pStates[add( add( i, channels2 ), channels3 )]; + pStatesI = &pStates[i + channels2]; + pStatesR = &pStates[( i + channels2 ) + channels3]; acc = L_mult( *pStatesI, *pFilterS++ ); acc = L_mac( acc, *pStatesR, *pFilterM++ ); @@ -914,7 +917,7 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - timeOut[i_mult( sub( 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 ) ); #endif @@ -924,17 +927,17 @@ void cldfbSynthesisFiltering( HANDLE_CLDFB_FILTER_BANK cldfbBank, FOR( i = 0; i < cldfbBank->no_channels; i++ ) { - pStates[add( statesSizeM1, i )] = nBuffer[sub( channels1, i )]; + pStates[statesSizeM1 + i] = nBuffer[channels1 - i]; move16(); - pStates[add( statesSizeM2, i )] = nBuffer[sub( add( channels1, m ), i )]; + pStates[statesSizeM2 + i] = nBuffer[( channels1 + m ) - i]; move16(); } - timeOut = &timeOut[i_mult( m, stride )]; + timeOut = &timeOut[m * stride]; } /* move filter states */ - Copy( &cldfbBank->FilterStates[i_mult( nTimeSlots, L2 )], cldfbBank->FilterStates, statesSizeM2 ); + Copy( &cldfbBank->FilterStates[nTimeSlots * L2], cldfbBank->FilterStates, statesSizeM2 ); set16_fx( &cldfbBank->FilterStates[statesSizeM2], 0, L2 ); } @@ -1040,8 +1043,8 @@ ivas_error openCldfb( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for CLDFB" ); } - hs->flags &= ~CLDFB_FLAG_KEEP_STATES; - + hs->flags = s_and( hs->flags, ~CLDFB_FLAG_KEEP_STATES ); + move16(); configureCldfb( hs, maxCldfbBands, frameSize ); hs->memory = NULL; @@ -1140,10 +1143,10 @@ void resampleCldfb( HANDLE_CLDFB_FILTER_BANK hs, */ 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 */ + Word32 **rSubband32, /*!< Real bands Q(cldfbSacle)*/ + Word32 **iSubband32, /*!< Imaginary bands Q(cldfbSacle)*/ + Word16 **rSubband16, /*!< Real bands Q(cldfbSacle)*/ + Word16 **iSubband16, /*!< Imaginary bands Q(cldfbScale)*/ Word16 *cldfbScale /*!< CLDFB lowband scalefactor */ ) { @@ -1165,14 +1168,14 @@ AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle 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 ) ); + rSubband16[i][j] = round_fx_sat( L_shl_sat( rSubband32[i][j], headRoom ) ); // Q(cldfbSacle_headRoom) + iSubband16[i][j] = round_fx_sat( L_shl_sat( iSubband32[i][j], headRoom ) ); // Q(cldfbSacle+headRoom) #else rSubband16[i][j] = round_fx( L_shl( rSubband32[i][j], headRoom ) ); iSubband16[i][j] = round_fx( L_shl( iSubband32[i][j], headRoom ) ); #endif - move32(); - move32(); + move16(); + move16(); } } @@ -1192,12 +1195,12 @@ AnalysisPostSpectrumScaling_Fx( HANDLE_CLDFB_FILTER_BANK cldfbBank, /*!< Handle void analysisCldfbEncoder_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *timeIn, + const Word16 *timeIn, // Q15 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 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(enerScale.lb_scale16) + Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], // Q(enerScale.lb_scale16) + Word32 enerBuffSum[CLDFB_NO_CHANNELS_MAX], // Q(31-enerBuffSum_exp) Word16 *enerBuffSum_exp, CLDFB_SCALE_FACTOR *scale ) { @@ -1232,7 +1235,8 @@ void analysisCldfbEncoder_fx( enerScale.lb_scale = negate( scale->lb_scale ); enerScale.lb_scale16 = negate( scale->lb_scale ); - + move16(); + move16(); /* get 16bit respresentation */ AnalysisPostSpectrumScaling_Fx( st_fx->cldfbAnaEnc, @@ -1294,8 +1298,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) { FOR( j = 0; j < numberBands; j++ ) { - nrg = L_mult0( realValues[k][j], realValues[k][j] ); - nrg = L_mac0( nrg, imagValues[k][j], imagValues[k][j] ); + nrg = L_mult0( realValues[k][j], realValues[k][j] ); // Q(2*sf_Values) + nrg = L_mac0( nrg, imagValues[k][j], imagValues[k][j] ); // Q(2*sf_Values) energyValues[k][j] = nrg; move32(); @@ -1325,13 +1329,13 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) FOR( j = 0; j < numberBands; j++ ) { - energyValuesSum[j] = L_deposit_l( 0 ); + energyValuesSum[j] = 0; move32(); energyValuesSumE[j] = 31; move16(); FOR( k = 0; k < CLDFB_NO_COL_MAX; k++ ) { - nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); + nrg = L_shr_r( energyValues[k][j], sub( energyValuesSumE[j], 31 ) ); // Q(2*sf_Values - (energyValuesSumE[j]-31)) IF( LT_32( L_sub( maxWord32, nrg ), energyValuesSum[j] ) ) { energyValuesSumE[j] = add( energyValuesSumE[j], 1 ); @@ -1352,7 +1356,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) } FOR( j = 0; j < numberBands; j++ ) { - energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); + energyValuesSum[j] = L_shr_r( energyValuesSum[j], sub( *energyValuesSum_Exp, energyValuesSumE[j] ) ); // Q(energyValuesSum_Exp - (2*sf_Values)) move32(); } *energyValuesSum_Exp = sub( *energyValuesSum_Exp, shl( sf_Values, 1 ) ); @@ -1368,8 +1372,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) /* sum up CLDFB energy above 8 kHz */ s = BASOP_util_norm_s_bands2shift( i_mult( numberColsL, numberBandsM20 ) ); s = sub( s, 4 ); - nrg = L_deposit_l( 0 ); - + nrg = 0; + move32(); FOR( k = 0; k < numberColsL; k++ ) { FOR( j = 20; j < numberBandsM; j++ ) @@ -1386,7 +1390,7 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) sm = sub( s_min( s, *sf_energyLookahead ), 1 ); *energyHF = L_add( L_shr( nrg, limitScale32( sub( s, sm ) ) ), - L_shr( *energyLookahead, sub( *sf_energyLookahead, sm ) ) ); + L_shr( *energyLookahead, sub( *sf_energyLookahead, sm ) ) ); // Q(31-(-nm)) move32(); *energyHF_Exp = negate( sm ); @@ -1395,8 +1399,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) /* process look-ahead region */ s = BASOP_util_norm_s_bands2shift( i_mult( numLookahead, numberBandsM20 ) ); s = sub( s, 2 ); - nrg = L_deposit_l( 0 ); - + nrg = 0; + move32(); FOR( k = numberColsL; k < numberCols; k++ ) { FOR( j = 20; j < numberBandsM; j++ ) @@ -1642,13 +1646,14 @@ cldfb_init_proto_and_twiddles( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle ivas_error cldfb_save_memory( HANDLE_CLDFB_FILTER_BANK hs ) /* i: cldfb handle */ { - + test(); 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 ); + move16(); hs->memory = (Word16 *) calloc( hs->memory_length + CLDFB_MEM_EXPONENTS + 1, sizeof( Word16 ) ); /* save the memory */ diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c index ba5ca4e1e..b4dbcc095 100644 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -124,7 +124,7 @@ 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 /*Qx*/ ) { cmplx x0, x1, x2, x3, x4, x5, x6, x7; cmplx s0, s1, s2, s3, s4, s5, s6, s7; @@ -204,7 +204,7 @@ 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 /*Qx*/ ) { cmplx x0, x1, x2, x3, x4; cmplx y1, y2, y3, y4; @@ -262,7 +262,7 @@ 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 /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4, t; @@ -369,7 +369,7 @@ 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 /*Qx*/ ) { cmplx r1, r2, r3, r4; cmplx x0, x1, x2, x3, x4; @@ -617,7 +617,7 @@ 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 /*Qx*/ ) { cmplx *l = &inp[0]; cmplx *h = &inp[15]; @@ -1023,7 +1023,7 @@ 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 Qx*/ const Word16 size /* size of fft operation */ ) { diff --git a/lib_com/fft_rel.c b/lib_com/fft_rel.c index bad84753f..88f80e798 100644 --- a/lib_com/fft_rel.c +++ b/lib_com/fft_rel.c @@ -303,7 +303,7 @@ void fft_rel( void fft_rel_fx( - Word16 x[], /* i/o: input/output vector */ + Word16 x[], /* i/o: input/output vector Qx */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ) @@ -326,22 +326,22 @@ void fft_rel_fx( j = 0; move16(); - x0 = &x[0]; + x0 = &x[0]; // Qx move16(); FOR( i = 0; i < n - 1; i++ ) { IF( LT_16( i, j ) ) { - xt = x[j]; + xt = x[j]; // Qx move16(); - x[j] = *x0; + x[j] = *x0; // Qx move16(); - *x0 = xt; + *x0 = xt; // Qx move16(); } x0++; k = shr( n, 1 ); - WHILE( LE_16( k, j ) ) + WHILE( ( k <= j ) ) { j = sub( j, k ); k = shr( k, 1 ); @@ -357,7 +357,7 @@ void fft_rel_fx( move16(); x1 = &x[1]; move16(); - FOR( i = 0; i < shr( n, 1 ); i++ ) + FOR( i = 0; i < ( n >> 1 ); i++ ) { xt = *x0; move16(); @@ -425,8 +425,8 @@ void fft_rel_fx( move16(); /* x[i+n2+n4] = -x[i+n2+n4]; */ - s = sincos_t_fx + step; - c = s + 64; + s = sincos_t_fx + step; // Q15 + c = s + 64; // Q15 xi1 = x + add( i, 1 ); xi3 = xi1 + n2; xi2 = xi3 - 2; @@ -435,8 +435,8 @@ void fft_rel_fx( 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); */ + t1 = add_o( mult_r( *xi3, *c ), mult_r( *xi4, *s ), &Overflow ); /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind); Qx */ + t2 = sub_o( mult_r( *xi3, *s ), mult_r( *xi4, *c ), &Overflow ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); Qx */ *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); */ @@ -482,7 +482,7 @@ void fft_rel_fx( } void fft_rel_fx32( - Word32 x[], /* i/o: input/output vector */ + Word32 x[], /* i/o: input/output vector Qx */ const Word16 n, /* i : vector length */ const Word16 m /* i : log2 of vector length */ ) @@ -517,9 +517,9 @@ void fft_rel_fx32( k = *idx++; move16(); - *x2++ = L_add( x[shr( j, 1 )], x[shr( k, 1 )] ); + *x2++ = L_add( x[( j >> 1 )], x[( k >> 1 )] ); // Qx move16(); - *x2++ = L_sub( x[shr( j, 1 )], x[shr( k, 1 )] ); + *x2++ = L_sub( x[( j >> 1 )], x[( k >> 1 )] ); // Qx move16(); } } @@ -533,9 +533,9 @@ void fft_rel_fx32( k = *idx++; move16(); - *x2++ = L_add( x[j], x[k] ); + *x2++ = L_add( x[j], x[k] ); // Qx move16(); - *x2++ = L_sub( x[j], x[k] ); + *x2++ = L_sub( x[j], x[k] ); // Qx move16(); } } @@ -551,15 +551,15 @@ void fft_rel_fx32( k = shl( *idx, 1 ); idx++; - *x2even++ = L_add( x[j], x[k] ); + *x2even++ = L_add( x[j], x[k] ); // Qx move16(); - *x2even++ = L_sub( x[j], x[k] ); + *x2even++ = L_sub( x[j], x[k] ); // Qx move16(); j = add( j, 1 ); k = add( k, 1 ); - *x2odd++ = L_add( x[j], x[k] ); + *x2odd++ = L_add( x[j], x[k] ); // Qx move16(); - *x2odd++ = L_sub( x[j], x[k] ); + *x2odd++ = L_sub( x[j], x[k] ); // Qx move16(); } } @@ -576,7 +576,7 @@ void fft_rel_fx32( { x0 = temp; x1 = x0 + 2; - x2 = x; + x2 = x; // Qx FOR( i = 0; i < n; i += 4 ) { @@ -604,12 +604,12 @@ void fft_rel_fx32( j = 0; move16(); - x0 = &x[0]; - FOR( i = 0; i < sub( n, 1 ); i++ ) + x0 = &x[0]; // Qx + FOR( i = 0; i < ( n - 1 ); i++ ) { IF( LT_16( i, j ) ) { - xt = x[j]; + xt = x[j]; // Qx move32(); x[j] = *x0; move32(); @@ -618,7 +618,7 @@ void fft_rel_fx32( } x0++; k = shr( n, 1 ); - WHILE( LE_16( k, j ) ) + WHILE( ( k <= j ) ) { j = sub( j, k ); k = shr( k, 1 ); @@ -630,13 +630,13 @@ void fft_rel_fx32( * Length two butterflies *-----------------------------------------------------------------*/ - x0 = &x[0]; - x1 = &x[1]; - FOR( i = 0; i < shr( n, 1 ); i++ ) + x0 = &x[0]; // Qx + x1 = &x[1]; // Qx + FOR( i = 0; i < ( n >> 1 ); i++ ) { - *x1 = L_sub( *x0, *x1 ); + *x1 = L_sub( *x0, *x1 ); // Qx move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); //*x0 * 2 - *x1 (Qx) move32(); x0++; @@ -653,16 +653,16 @@ void fft_rel_fx32( /* for_ (k = 2; k < 3; k++) */ { - x0 = x; + x0 = x; // Qx x1 = x0 + 2; FOR( i = 0; i < n; i += 4 ) { - *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ + *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; Qx*/ move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1++ ); /* x[i] = xt + x[i+n2]; */ /**x0 * 2 - *x1 (Qx)*/ move32(); - *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x1 = L_negate( *x1 ); /* x[i+n2+n4] = -x[i+n2+n4]; Qx*/ move32(); x0 += 4; @@ -707,13 +707,13 @@ void fft_rel_fx32( { *x1 = L_sub( *x0, *x1 ); /* x[i+n2] = xt - x[i+n2]; */ move32(); - *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ + *x0 = L_sub( L_shl( *x0, 1 ), *x1 ); /* x[i] = xt + x[i+n2]; */ /**x0 * 2 - *x1 (Qx)*/ move32(); - *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; */ + *x2 = L_negate( *x2 ); /* x[i+n2+n4] = -x[i+n2+n4]; Qx */ move32(); - s = sincos_t_ext_fx; - c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 */ + s = sincos_t_ext_fx; // Q15 + c = s + N_MAX_FFT / 4; /* 1024/4 = 256, 256/4=64 Q15*/ xi1 = x0; xi3 = xi1 + n2; xi2 = xi3; @@ -729,16 +729,16 @@ 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); Qx*/ + t2 = L_sub( Mpy_32_16_1( *xi3, *s ), Mpy_32_16_1( *xi4, *c ) ); /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind); Qx*/ *xi4 = L_sub( *xi2, t2 ); move32(); *xi2 = L_sub( *xi1, t1 ); move32(); - *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); + *xi1 = L_sub( L_shl( *xi1, 1 ), *xi2 ); // Qx move32(); - *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); + *xi3 = L_negate( L_add( L_shl( t2, 1 ), *xi4 ) ); // Qx move32(); } diff --git a/lib_com/fft_rel_fx.c b/lib_com/fft_rel_fx.c index 85a5a3224..1285049bc 100644 --- a/lib_com/fft_rel_fx.c +++ b/lib_com/fft_rel_fx.c @@ -72,8 +72,8 @@ 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 *in_ptr, /* i : coefficients in the order re[0], re[n/2], re[1], im[1], ..., re[n/2-1], im[n/2-1] Qx*/ + 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] Q(x - 1)*/ /* in_ptr & out_ptr must not overlap! */ const Word16 isign ) /* i : 1=fft, otherwise it is ifft*/ { @@ -129,7 +129,7 @@ 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 ); // Qx L_tmp1 = L_mult( *input_ptr1++, 16384 ); L_tmp2 = L_mult( *input_ptr1, 16384 ); @@ -379,8 +379,8 @@ void r_fft_fx_lc( 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 *in_ptr, /* i : coefficients in the order re[0], re[1], ... re[n/2], im[n/2-1], im[n/2-2], ..., im[1] Qx*/ + 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] Q(x - 1)*/ const Word16 isign /* i : 1=fft, otherwize it's ifft */ ) { @@ -478,10 +478,10 @@ void r_fft_fx_lc( /* 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]; - ptRealUp = &in_ptr[1]; - ptImaUp = &in_ptr[SIZE2 + 1]; - ptRealDn = &in_ptr[SIZE2 - 1]; + ptImaDn = &in_ptr[SIZE - 1]; // Qx + ptRealUp = &in_ptr[1]; // Qx + ptImaUp = &in_ptr[SIZE2 + 1]; // Qx + ptRealDn = &in_ptr[SIZE2 - 1]; // Qx /* Now, handle the remaining positive frequencies */ FOR( i = 2; i <= SIZE2; i += 2 ) diff --git a/lib_com/fill_spectrum.c b/lib_com/fill_spectrum.c index 5fe270c3c..d9f24d8d5 100644 --- a/lib_com/fill_spectrum.c +++ b/lib_com/fill_spectrum.c @@ -394,7 +394,7 @@ void ivas_fill_spectrum_fx( test(); test(); test(); - if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) + if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) { flag_32K_env_hangover = 1; move16(); @@ -437,7 +437,7 @@ void ivas_fill_spectrum_fx( * Normal mode BWE *----------------------------------------------------------------*/ - IF( EQ_16( HQ_mode, HQ_NORMAL ) ) + IF( HQ_mode == HQ_NORMAL ) { hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); } @@ -625,7 +625,7 @@ void fill_spectrum_fx( move16(); } } - ELSE if ( EQ_16( HQ_mode, HQ_HVQ ) ) + ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) { bin_th = sfm_end[last_sfm]; move16(); @@ -654,7 +654,7 @@ void fill_spectrum_fx( test(); test(); test(); - if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) + if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) { flag_32K_env_hangover = 1; move16(); @@ -697,7 +697,7 @@ void fill_spectrum_fx( * Normal mode BWE *----------------------------------------------------------------*/ - IF( EQ_16( HQ_mode, HQ_NORMAL ) ) + IF( HQ_mode == HQ_NORMAL ) { hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); } diff --git a/lib_com/findpulse.c b/lib_com/findpulse.c index 72f1b3990..3596b20b8 100644 --- a/lib_com/findpulse.c +++ b/lib_com/findpulse.c @@ -48,6 +48,7 @@ * Find first pitch pulse in a frame *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED /*! r: pulse position */ int16_t findpulse( const int16_t L_frame, /* i : length of the frame */ @@ -139,11 +140,12 @@ int16_t findpulse( return ( maxi ); } +#endif #ifdef IVAS_FLOAT_FIXED -Word16 findpulse_fx( /* o : pulse position */ +Word16 findpulse_fx( /* o : pulse position Q0 */ const Word16 L_frame, /* i : length of the frame */ - const Word16 res[], /* i : Residual signal <12 bits */ + const Word16 res[], /* i : Residual signal <12 bits Qx */ 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 */ @@ -162,21 +164,21 @@ Word16 findpulse_fx( /* o : pulse position *------------------------------------------------------------------------*/ /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */ - Ltmp = L_mult( res[0], 16384 ); - resf[0] = mac_r( Ltmp, res[1], 8192 ); + Ltmp = L_mult( res[0], 16384 /*0.5 (Q15)*/ ); /*Q(x + 15 + 1) => Q(x + 16)*/ + resf[0] = mac_r( Ltmp, res[1], 8192 /*0.25( Q15 )*/ ); /*Q(x + 16)*/ 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] ); + Ltmp = L_mult( 8192 /*0.25 (Q15)*/, res[i - 1] ); /*Q(x + 16)*/ + Ltmp = L_mac( Ltmp, 16384 /*0.5 (Q15)*/, res[i] ); /*Q(x + 16)*/ + resf[i] = mac_r( Ltmp, 8192 /*0.25 (Q15)*/, res[i + 1] ); /*Q(x*/ move16(); } /* 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] ); + Ltmp = L_mult( res[L_frame - 2], 8192 /*0.25 (Q15)*/ ); /*Q(x + 16)*/ + resf[L_frame - 1] = mac_r( Ltmp, 16384 /*0.5 (Q15)*/, res[L_frame - 1] ); /*Q(x)*/ move16(); /*------------------------------------------------------------------------* @@ -189,14 +191,14 @@ Word16 findpulse_fx( /* o : pulse position FOR( i = 1; i < T0; i++ ) { - Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); + Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); /*Q( 2 * x )*/ if ( L_msu0( Ltmp, ptr[-i], ptr[-i] ) < 0 ) { maxi = i; move16(); } } - *sign = negate( shr( ptr[-maxi], 15 ) ); + *sign = negate( shr( ptr[-maxi], 15 ) ); /*extracting sign : Q0*/ move16(); } ELSE diff --git a/lib_com/frame_ener.c b/lib_com/frame_ener.c index ece0418c6..cd2eb4418 100644 --- a/lib_com/frame_ener.c +++ b/lib_com/frame_ener.c @@ -87,13 +87,13 @@ void fer_energy( #ifdef IVAS_FLOAT_FIXED void fer_energy_fx( - const Word16 L_frame, /* i : frame length */ - const Word16 clas, /* i : frame classification */ - const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz */ - const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ - const Word16 pitch, /* i : pitch period */ - Word32 *enr, /* o : pitch-synchronous or half_frame energy */ - const Word16 offset /* i : speech pointer offset (0 or L_frame) */ + const Word16 L_frame, /* i : frame length */ + const Word16 clas, /* i : frame classification */ + const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q(q_synth) */ + const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ + const Word16 pitch, /* i : pitch period Q0 */ + Word32 *enr, /* o : pitch-synchronous or half_frame energy Q0 */ + const Word16 offset /* i : speech pointer offset (0 or L_frame) */ ) { Word16 len, shift, exp; @@ -136,7 +136,7 @@ void fer_energy_fx( move32(); enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); - *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); + *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); /*Q0*/ move32(); } return; @@ -222,13 +222,11 @@ Word16 frame_ener_fx( 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 ); @@ -251,15 +249,15 @@ Word16 frame_ener_fx( 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] ); /*2 * Qnew + 1*/ #else Ltmp = L_mult( synth[pos], synth[pos] ); #endif FOR( i = 1; i < L_frame2; i++ ) { #ifdef BASOP_NOGLOB - Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); -#else /* BASOP_NOGLOB */ + Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); /*2 * Qnew + 1*/ +#else /* BASOP_NOGLOB */ Ltmp = L_mac( Ltmp, synth[pos + i], synth[pos + i] ); #endif } diff --git a/lib_com/get_gain.c b/lib_com/get_gain.c index 33739f0cd..8cfa02160 100644 --- a/lib_com/get_gain.c +++ b/lib_com/get_gain.c @@ -73,9 +73,9 @@ float get_gain_flt( #ifdef IVAS_FLOAT_FIXED 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 */ + const Word16 x[], /* input : target signal Qx */ + const Word16 y[], /* input : filtered codebook excitation Qx */ + const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; @@ -155,7 +155,7 @@ Word32 get_gain2( /* output: codebook gain (adaptive or fixed) move16(); m_corr = 0x7FFF; } - if ( m_ener != 0 ) + IF( m_ener != 0 ) { m_corr = div_s( m_corr, m_ener ); } diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index f8a45b4f8..077463885 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -69,7 +69,7 @@ static Word32 Find_bit_frac( const Word16 nb_band, const Word16 remaining_bits ) /*----------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ /* _ (Word16*) bit :Number of bit allowed for frequency quantization */ -/* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q13 */ +/* _ (Word16*) Ener_per_bd_iQ : Quantized energy vector Q12 */ /* _ (Word32*) bits_per_bands : Number of bit allowed per allowed subband Q18 */ /*----------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -82,7 +82,7 @@ void bands_and_bit_alloc_ivas_fx( 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 */ + const Word16 *Ener_per_bd_iQ, /* i/o: Quantized energy vector Q12 */ 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 */ @@ -103,7 +103,7 @@ void bands_and_bit_alloc_ivas_fx( 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 /*Q0*/, bit_fracf /*Q18*/; Word16 etmp; Word16 tmp; Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; // Q13 @@ -143,10 +143,10 @@ void bands_and_bit_alloc_ivas_fx( move16(); 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[18] = Ener_per_bd_iQ[17]; - ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 ); + ener_vec[16] = Ener_per_bd_iQ[16]; /*Q12*/ + ener_vec[17] = mac_r( L_mult( Ener_per_bd_iQ[16], 16384 /*0.5 in Q15*/ ), Ener_per_bd_iQ[17], 16384 /*0.5 in Q15*/ ); /*Q12*/ + ener_vec[18] = Ener_per_bd_iQ[17]; /*Q12*/ + ener_vec[19] = mult_r( Ener_per_bd_iQ[17], 26214 /*0.8 in Q15*/ ); /*Q12*/ move16(); move16(); move16(); @@ -210,16 +210,16 @@ void bands_and_bit_alloc_ivas_fx( 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 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); - *bit = sub( sub( tmp, bits_used ), 25 ); + *bit = sub( sub( tmp, bits_used ), 25 ); /*Q0*/ move16(); } ELSE { - L_tmp = Mult_32_16( core_brate, 20971 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); - *bit = sub( sub( tmp, bits_used ), 21 ); + *bit = sub( sub( tmp, bits_used ), 21 ); /*Q0*/ move16(); } nb_tot_bands = 10; @@ -229,7 +229,7 @@ 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 ); + L_tmp = Mult_32_16( core_brate, 20971 /*1/50 in Q20*/ ); tmp = extract_l( L_shr_r( L_tmp, 5 ) ); *bit = sub( sub( tmp, bits_used ), GSC_freq_bits[bit_index] ); move16(); @@ -493,7 +493,7 @@ void bands_and_bit_alloc_ivas_fx( #endif IF( EQ_16( GSC_noisy_speech, 1 ) ) { - SWB_bit_budget = *bit; + SWB_bit_budget = *bit; /*Q0*/ move32(); nb_bands = 5; move16(); @@ -536,7 +536,7 @@ void bands_and_bit_alloc_ivas_fx( set32_fx( bits_per_bands, 0, MBANDS_GN ); /*bit_fracf = (1.0f/nb_bands)*(SWB_bit_budget); */ #ifdef FIX_802__NON_BE_DECODING - bit_fracf = Find_bit_frac( nb_bands, extract_l( SWB_bit_budget ) ); + bit_fracf = Find_bit_frac( nb_bands, extract_l( SWB_bit_budget ) ); /*Q18*/ #else bit_fracf = L_mult( div_s( 1, nb_bands ), shl( (Word16) SWB_bit_budget, 2 ) ); /* Q18 */ #endif @@ -734,7 +734,7 @@ void bands_and_bit_alloc_ivas_fx( #endif { #ifdef FIX_802__NON_BE_DECODING - bit_fracf = Find_bit_frac( st_band, bit_tmp ); + bit_fracf = Find_bit_frac( st_band, bit_tmp ); /*Q18*/ #else bit_fracf = L_mult( div_s( 1, st_band ), shl( bit_tmp, 2 ) ); /* Q18 */ #endif @@ -752,8 +752,8 @@ void bands_and_bit_alloc_ivas_fx( } FOR( i = 0; i < imax; i++ ) { - bits_per_bands[i] = L_add( GSC_freq_bits_fx_Q18[bit_index], bit_fracf ); - move32(); /* Q18 */ + bits_per_bands[i] = L_add( GSC_freq_bits_fx_Q18[bit_index], bit_fracf ); /*Q18*/ + move32(); /* Q18 */ bit_index = add( bit_index, 1 ); } #if 1 // def ADD_LRTD @@ -763,14 +763,15 @@ void bands_and_bit_alloc_ivas_fx( move16(); i = sub( imax, 1 ); // 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 ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( Compl_GSC_freq_bits[bit_index], Q18 ) ); /*Q18*/ + move32(); i = add( i, 1 ); bit_index = add( bit_index, 1 ); FOR( ; i < 10; i++ ) { // 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 ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_add( L_shl( Compl_GSC_freq_bits[bit_index], Q18 ), bit_fracf ) ); /*Q18*/ move32(); bit_index = add( bit_index, 1 ); } @@ -781,8 +782,8 @@ void bands_and_bit_alloc_ivas_fx( 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 */ + bits_per_bands[i] = L_add( bits_per_bands[i], GSC_freq_bits_fx_Q18[bit_index] ); /*Q18*/ + move32(); /*chk Q18 */ bit_index = add( bit_index, 1 ); } } @@ -801,6 +802,7 @@ void bands_and_bit_alloc_ivas_fx( * Complete the bit allocation per frequency band for 16kHz high brate mode *--------------------------------------------------------------------------*/ #if 1 // def ADD_LRTD + test(); IF( EQ_16( L_frame, L_FRAME16k ) && GT_32( core_brate, ACELP_32k ) ) { FOR( j = st_band; j < nb_bands; j++ ) @@ -811,19 +813,19 @@ void bands_and_bit_alloc_ivas_fx( } // bit_fracf = (1.0f / nb_bands) * (bit_tmp); - bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); + bit_fracf = L_shl( L_mult0( idiv1616( 16384, nb_bands ), bit_tmp ), 4 ); /*Q18*/ // etmp = 2.0f * bit_fracf / (nb_bands + 1); etmp = divide3216( L_shr( bit_fracf, Q2 ), add( nb_bands, 1 ) ); // Q15 // bit_fracf = etmp; bit_fracf = L_shl( etmp, Q3 ); // Q18 - FOR( j = sub( nb_bands, 1 ); j >= 0; j-- ) + 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 move32(); - etmp = (Word16) L_add( etmp, L_shr( bit_fracf, Q3 ) ); + etmp = extract_l( L_add( etmp, L_shr( bit_fracf, Q3 ) ) ); } } ELSE @@ -852,7 +854,7 @@ void bands_and_bit_alloc_ivas_fx( { bandoffset = sub( bandoffset, 1 ); } - ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) ) || + ELSE IF( ( LE_32( core_brate, ACELP_13k20 ) && ( ( 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 ); @@ -899,12 +901,12 @@ void bands_and_bit_alloc_ivas_fx( 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; + max_ener_band[nb_bands + j] = i; move16(); ener_vec[i] = -10; move16(); - bits_per_bands[add( nb_bands, j )] = 1310720; - move32(); /*Q18 */ + bits_per_bands[nb_bands + j] = 1310720; /*5 in Q18*/ + move32(); /*Q18 */ } nb_bands = add( nb_bands, band ); @@ -912,7 +914,7 @@ void bands_and_bit_alloc_ivas_fx( IF( LE_16( band, 2 ) ) { - FOR( j = sub( st_band, 1 ); j < nb_bands; j++ ) + FOR( j = st_band - 1; j < nb_bands; j++ ) { bits_per_bands[j] = L_add( bits_per_bands[j], 262144 ); /*Q18 */ move32(); @@ -926,7 +928,7 @@ void bands_and_bit_alloc_ivas_fx( move16(); FOR( ; bit_tmp > 0; bit_tmp-- ) { - bits_per_bands[j] = L_sub( bits_per_bands[j], 262144 ); /*Q18 */ + bits_per_bands[j] = L_sub( bits_per_bands[j], ONE_IN_Q18 ); /*Q18 */ j = add( j, 1 ); IF( EQ_16( j, sub( st_band, i ) ) ) { @@ -934,7 +936,7 @@ void bands_and_bit_alloc_ivas_fx( 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 ); } @@ -952,12 +954,12 @@ void bands_and_bit_alloc_ivas_fx( move16(); FOR( i = 0; i < nb_bands; i++ ) { - L_tmp = Mult_32_16( sum_bit, 10923 ); + L_tmp = Mult_32_16( sum_bit, 10923 /*1/3 in Q15*/ ); 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 */ - bits_per_bands[i] = 29360128; + sum_bit = L_add( sum_bit, L_sub( bits_per_bands[i], 29360128 /* 112 in Q18 */ ) ); /* Q18 */ + bits_per_bands[i] = 29360128 /* 112 in Q18 */; move32(); j = add( i, 1 ); } @@ -982,12 +984,13 @@ void bands_and_bit_alloc_ivas_fx( *--------------------------------------------------------------------------*/ #if 1 // def ADD_LRTD sum_bit = 0; + move32(); FOR( i = 0; i < nb_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 ); move32(); - sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); + sum_bit = L_add( sum_bit, L_shr( bits_per_bands[i], Q18 ) ); /*Q0*/ } test(); IF( GSC_IVAS_mode != 0 && LT_32( sum_bit, *bit ) ) /* If we need to add bits, we are doing it on the LF */ @@ -1030,6 +1033,7 @@ void bands_and_bit_alloc_ivas_fx( *nb_subbands = nb_bands; move16(); *pvq_len = shl( *nb_subbands, 4 ); + move16(); /*-------------------------------------------------------------------------- * Concatenate bands (encoder only) @@ -1062,11 +1066,11 @@ void bands_and_bit_alloc_ivas_fx( *-------------------------------------------------------------------*/ static void reajust_bits_fx( - Word32 *bits_per_bands, + Word32 *bits_per_bands, /*i : Q18*/ const Word16 st_band, const Word16 end_band, - const Word16 sum_bit_in, - const Word16 bit_bdgt_in ) + const Word16 sum_bit_in, /*i : Q0*/ + const Word16 bit_bdgt_in /*i : Q0*/ ) { Word16 i, amount_to_add, incr; Word16 bit_bdgt, sum_bit; @@ -1105,10 +1109,10 @@ static void reajust_bits_fx( /* if (amount_to_add > 0 || (amount_to_add < 0 && bits_per_bands[i] > 1))*/ test(); test(); - IF( amount_to_add > 0 || ( amount_to_add < 0 && GT_32( bits_per_bands[i], 262144 ) ) ) + IF( amount_to_add > 0 || ( amount_to_add < 0 && GT_32( bits_per_bands[i], ONE_IN_Q18 ) ) ) { /* bits_per_bands[i] += amount_to_add;*/ - bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( amount_to_add, Q18 ) ); + bits_per_bands[i] = L_add( bits_per_bands[i], L_shl( amount_to_add, Q18 ) ); /*Q18*/ move32(); sum_bit = add( sum_bit, abs_s( amount_to_add ) ); } @@ -1135,34 +1139,34 @@ static Word32 Find_bit_frac( const Word16 nb_band, const Word16 remaining_bits ) { - int16_t inv_bandQ15; - int32_t L_out; + Word16 inv_bandQ15; + Word32 L_out; - inv_bandQ15 = 6553; + inv_bandQ15 = 6553; /*Q15*/ move16(); - IF( nb_band == 7 ) + IF( EQ_16( nb_band, 7 ) ) { - inv_bandQ15 = 4681; + inv_bandQ15 = 4681; /*Q15*/ move16(); } - ELSE IF( nb_band == 3 ) + ELSE IF( EQ_16( nb_band, 3 ) ) { - inv_bandQ15 = 10922; + inv_bandQ15 = 10922; /*Q15*/ move16(); } - ELSE IF( nb_band == 4 ) + ELSE IF( EQ_16( nb_band, 4 ) ) { - inv_bandQ15 = 8192; + inv_bandQ15 = 8192; /*Q15*/ move16(); } - ELSE IF( nb_band == 5 ) + ELSE IF( EQ_16( nb_band, 5 ) ) { - inv_bandQ15 = 6536; + inv_bandQ15 = 6536; /*Q15*/ move16(); } - ELSE IF( nb_band == 10 ) + ELSE IF( EQ_16( nb_band, 10 ) ) { - inv_bandQ15 = 3277; + inv_bandQ15 = 3277; /*Q15*/ move16(); } ELSE @@ -1171,7 +1175,7 @@ static Word32 Find_bit_frac( printf( "1/%d NOT DEFINED in Find_bit_frac\n", nb_band ); #endif } - L_out = L_mult( inv_bandQ15, shl( remaining_bits, 2 ) ); + L_out = L_mult( inv_bandQ15, shl( remaining_bits, 2 ) ); /*Q18*/ return ( L_out ); } @@ -1185,7 +1189,7 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of Word16 *bit, /* i/o: Number of bit allowed for frequency quantization */ Word16 *max_ener_band, /* i/o: Energy based sorted order */ Word16 *ener_vec, /* i/o: Energy per band order */ - Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q3 */ + Word32 *bits_per_bands /* o : Number of bit allowed per allowed subband Q18 */ ) { Word32 mp, mb, nb_bands_adj, bit_adj; @@ -1241,6 +1245,8 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of /* nb_bands_adj = 1.0f; */ nb_bands_adj = Q18_1_0; move32(); + test(); + test(); IF( EQ_16( GSC_IVAS_mode, 1 ) && LT_32( core_brate, GSC_L_RATE_STG ) ) { /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ @@ -1393,11 +1399,11 @@ static Word16 Find_bit_alloc_IVAS( /*o: Number of WHILE( SWB_bit_budget > 0 ) { /* bits_per_bands[i]++; */ - bits_per_bands[i] = L_add( bits_per_bands[i], Q18_1_0 ); + bits_per_bands[i] = L_add( bits_per_bands[i], Q18_1_0 ); /*Q18*/ move32(); /* SWB_bit_budget--; */ - SWB_bit_budget = L_sub( SWB_bit_budget, Q18_1_0 ); - i--; + SWB_bit_budget = L_sub( SWB_bit_budget, Q18_1_0 ); /*Q18*/ + i = sub( i, 1 ); if ( EQ_16( i, -1 ) ) { i = sub( st_band, 1 ); diff --git a/lib_com/gs_gains.c b/lib_com/gs_gains.c index b9a6f5875..31aca67b6 100644 --- a/lib_com/gs_gains.c +++ b/lib_com/gs_gains.c @@ -588,19 +588,19 @@ float gsc_gainQ( } Word16 gsc_gainQ_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const int16_t element_mode, /* i : element mode */ - const int16_t idchan, /* i : channel ID */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 element_mode, /* i : element mode */ + const Word16 idchan, /* i : channel ID */ const Word16 y_gain4[], /* i : Energy per band */ // Q12 Word16 y_gainQ[], /* o : quantized energy per band */ // Q12 - const int32_t core_brate, /* i : Core rate */ - const int16_t coder_type, /* i : coding type */ - const int16_t bwidth, /* i : input signal bandwidth */ - const int16_t L_frame, /* i : frame length */ - const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const int32_t core_brate_inp /* i : true core bitrate */ + const Word32 core_brate, /* i : Core rate */ + const Word16 coder_type, /* i : coding type */ + const Word16 bwidth, /* i : input signal bandwidth */ + const Word16 L_frame, /* i : frame length */ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word32 core_brate_inp /* i : true core bitrate */ ) { Word16 y_gain_tmp[MBANDS_GN16k]; @@ -609,10 +609,11 @@ Word16 gsc_gainQ_ivas_fx( move16(); Word16 mean_4g_fx[1], ftmp1_fx; Word16 Mbands_gn = MBANDS_GN; + move16(); Word16 y_gain_tmp3[MBANDS_GN]; Word32 L_tmp; - IF( EQ_16( L_frame, L_FRAME16k ) ) + if ( EQ_16( L_frame, L_FRAME16k ) ) { Mbands_gn = MBANDS_GN16k; move16(); @@ -637,11 +638,11 @@ Word16 gsc_gainQ_ivas_fx( { IF( LT_16( y_gain4[i], ftmp1_fx ) ) { - y_gain_tmp2[i] = ftmp1_fx; + y_gain_tmp2[i] = ftmp1_fx; /*Q12*/ } ELSE { - y_gain_tmp2[i] = y_gain4[i]; + y_gain_tmp2[i] = y_gain4[i]; /*Q12*/ } move16(); } @@ -665,7 +666,7 @@ Word16 gsc_gainQ_ivas_fx( move16(); } - IF( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) ) + if ( LT_16( y_gain_tmp[9], -1229 /* -0.3f in Q12 */ ) ) { y_gain_tmp[9] = -1229; /* -0.3f in Q12 */ move16(); @@ -696,17 +697,17 @@ Word16 gsc_gainQ_ivas_fx( IF( LE_32( core_brate, ACELP_9k60 ) && 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] = mean_fx( y_gain_tmp + 6, 3 ); + y_gain_tmp[10] = mean_fx( y_gain_tmp + 6, 3 ); /*Q12*/ move16(); - y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); + y_gain_tmp[11] = mean_fx( y_gain_tmp + 7, 3 ); /*Q12*/ move16(); - y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); + y_gain_tmp[12] = mean_fx( y_gain_tmp + 8, 3 ); /*Q12*/ move16(); - y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); + y_gain_tmp[13] = mean_fx( y_gain_tmp + 9, 3 ); /*Q12*/ move16(); - y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); + y_gain_tmp[14] = mean_fx( y_gain_tmp + 10, 3 ); /*Q12*/ move16(); - y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); + y_gain_tmp[15] = mean_fx( y_gain_tmp + 11, 3 ); /*Q12*/ move16(); } ELSE @@ -726,13 +727,13 @@ Word16 gsc_gainQ_ivas_fx( ftmp1_fx = extract_l( L_tmp ); FOR( i = 0; i < Mbands_gn; i++ ) { - IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 ) ) ) + IF( LT_16( y_gain4[i], sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) { - y_gain_tmp2[i] = sub( ftmp1_fx, 2457 ); + y_gain_tmp2[i] = sub( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); } - ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 ) ) ) + ELSE IF( GT_16( y_gain4[i], add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ) ) ) { - y_gain_tmp2[i] = add( ftmp1_fx, 2457 ); + y_gain_tmp2[i] = add( ftmp1_fx, 2457 /* 0.6 in Q12*/ ); } ELSE { @@ -817,7 +818,7 @@ Word16 gsc_gainQ_ivas_fx( FOR( i = 8; i < 16; i++ ) { - y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 ), 1 ); + y_gain_tmp[i] = shl( mult( y_gain_tmp[i], 23101 /* 1.41 in Q14 */ ), 1 ); /*Q12*/ move16(); } diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 703f0e4ef..8b3719e98 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -82,6 +82,7 @@ void Comp_and_apply_gain_fx( Word32 L32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Recreate excitation for local synthesis and decoder */ @@ -139,7 +140,8 @@ void Comp_and_apply_gain_fx( 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 */ + move16(); +#else /* BASOP_NOGLOB */ exc_diffQ[i] = round_fx( L_shl( L32, tmp_exp ) ); /*Q_exc */ #endif } @@ -183,7 +185,7 @@ void Comp_and_apply_gain_ivas_fx( move16(); IF( EQ_16( ReUseGain, 1 ) ) { - y_gain = Ener_per_bd_yQ[i_band]; + y_gain = Ener_per_bd_yQ[i_band]; /*Q13*/ move16(); FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) @@ -221,11 +223,11 @@ void Comp_and_apply_gain_ivas_fx( /* 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_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/ +#else /* BASOP_NOGLOB */ Ener_per_bd_yQ[i_band] = shl( y_gain, sub( exp1, 13 ) ); -#endif /* BASOP_NOGLOB */ - move16(); /*Q1 */ +#endif /* BASOP_NOGLOB */ + move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) ); FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) @@ -257,7 +259,7 @@ void Comp_and_apply_gain_ivas_fx( } FOR( i = 0; i < StartBin + NB_Qbins; i++ ) { - exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); + exc_diffQ[i] = shl( exc_diffQ[i], sub( *Q_exc, Q_exc_diffQ[i] ) ); /*Q_exc*/ move16(); } @@ -320,21 +322,21 @@ void Ener_per_band_comp_fx( pt_fx = exc_diff_fx; FOR( j = 0; j < 2; j++ ) { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); + y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ move16(); pt_fx += 8; } FOR( j = 1; j < Mband - 2; j++ ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ move16(); pt_fx += 16; } IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 32; } @@ -357,30 +359,30 @@ void Ener_per_band_comp_ivas_fx( pt_fx = exc_diff_fx; FOR( j = 0; j < 2; j++ ) { - y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); + y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/ move16(); pt_fx += 8; } FOR( j = 1; j < Mband - 2; j++ ) { - y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/ move16(); pt_fx += 16; } IF( EQ_16( Eflag, 1 ) ) { - y_gain4_fx[add( j, 1 )] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 32; } IF( EQ_16( L_frame, L_FRAME16k ) ) { - y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); + y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/ move16(); - y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); + y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/ move16(); pt_fx += 64; } @@ -566,7 +568,7 @@ static void GSC_gain_adj( 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 /* 20/MBANDS_GN in Q15 */ ) ) ) ); move16(); } } @@ -594,7 +596,7 @@ static void GSC_gain_adj_ivas_fx( Word16 Gain_off, i; test(); - IF( NE_16( coder_type, INACTIVE ) && NE_16( coder_type, UNVOICED ) ) + IF( ( coder_type != INACTIVE ) && NE_16( coder_type, UNVOICED ) ) { FOR( i = 0; i < Mbands_gn; i++ ) { @@ -646,7 +648,7 @@ static void GSC_gain_adj_ivas_fx( { old_y_gain[i] = y_gain_tmp[i]; move16(); - 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, 205 /* 20/MBANDS_GN in Q16 */ ) ) ) ); move16(); } } @@ -690,33 +692,32 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) ( get_next_indice_fx( 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_fx( st_fx, 6 ); - move16(); + idx_g_fx = (Word16) ( get_next_indice_fx( st_fx, 6 ) ); 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 ) ) { - idx_g_fx = (Word16) get_next_indice_fx( st_fx, 5 ); + idx_g_fx = (Word16) ( get_next_indice_fx( 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_fx( st_fx, 4 ); + idx_g_fx = (Word16) ( get_next_indice_fx( 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_fx( st_fx, 6 ); + idx_g_fx = (Word16) ( get_next_indice_fx( 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_fx( st_fx, 7 ); + idx_g_fx = (Word16) ( get_next_indice_fx( 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 ) && ( coder_type == INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ @@ -777,6 +778,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai FOR( i = 8; i < 16; i++ ) { y_gainQ_fx[i] = round_fx( L_shl( L_mult( y_gainQ_fx[i], 23101 ), 1 ) ); /*Q12 */ + move16(); } /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands @@ -835,7 +837,7 @@ Word16 gsc_gaindec_fx( /* o : average frequency gai /*==========================================================================*/ 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 */ + Word16 y_gainQ_fx[], /* o : quantized gain per band Q12 */ 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 */ @@ -847,7 +849,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc Word16 Mbands_gn = MBANDS_GN; move16(); 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; move16(); @@ -855,7 +857,7 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc test(); test(); - IF( ( EQ_16( coder_type, AUDIO ) || EQ_16( coder_type, INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) + IF( ( EQ_16( coder_type, AUDIO ) || ( coder_type == INACTIVE ) ) && EQ_16( bwidth_fx, NB ) ) { idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( &mean_4g_fx, Gain_meanNB_fx, Gain_mean_dicNB_fx, idx_g_fx, 1 ); @@ -880,21 +882,21 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc 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 ) && ( 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 ); /*Q12*/ move16(); - y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); + y_gainQ_fx[11] = mean_fx( y_gainQ_fx + 7, 3 ); /*Q12*/ move16(); - y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); + y_gainQ_fx[12] = mean_fx( y_gainQ_fx + 8, 3 ); /*Q12*/ move16(); - y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); + y_gainQ_fx[13] = mean_fx( y_gainQ_fx + 9, 3 ); /*Q12*/ move16(); - y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); + y_gainQ_fx[14] = mean_fx( y_gainQ_fx + 10, 3 ); /*Q12*/ move16(); - y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); + y_gainQ_fx[15] = mean_fx( y_gainQ_fx + 11, 3 ); /*Q12*/ move16(); } ELSE @@ -946,13 +948,13 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc /*----------------------------------------------------------------------* * Copy the true Q values in the specific bands *----------------------------------------------------------------------*/ - y_gainQ_fx[8] = y_gain_tmp3_fx[0]; + y_gainQ_fx[8] = y_gain_tmp3_fx[0]; /*Q12*/ move16(); - y_gainQ_fx[10] = y_gain_tmp3_fx[1]; + y_gainQ_fx[10] = y_gain_tmp3_fx[1]; /*Q12*/ move16(); - y_gainQ_fx[12] = y_gain_tmp3_fx[2]; + y_gainQ_fx[12] = y_gain_tmp3_fx[2]; /*Q12*/ move16(); - y_gainQ_fx[14] = y_gain_tmp3_fx[3]; + y_gainQ_fx[14] = y_gain_tmp3_fx[3]; /*Q12*/ move16(); } ELSE @@ -973,19 +975,19 @@ Word16 gsc_gaindec_ivas_fx( /* o : average frequenc } ELSE { - idx_g_fx = get_next_indice_fx( st_fx, 7 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 7 ); VDQ_vec_fx( y_gainQ_fx, YG_mean16HR_fx, YG_dicHR_1_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 4, YG_mean16HR_fx + 4, YG_dicHR_2_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 8, YG_mean16HR_fx + 8, YG_dicHR_3_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 6 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 6 ); VDQ_vec_fx( y_gainQ_fx + 12, YG_mean16HR_16kHz_fx, YG_dicHR_4_16kHz_fx, idx_g_fx, 4 ); - idx_g_fx = get_next_indice_fx( st_fx, 3 ); + idx_g_fx = (Word16) get_next_indice_fx( st_fx, 3 ); VDQ_vec_fx( y_gainQ_fx + 16, YG_meanL2G_16kHz_fx, YG_dicL2G_16kHz_fx, idx_g_fx, 2 ); } } @@ -1033,7 +1035,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ 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 /*0.1 in Q15*/ ); } tmp16 = sub( round_fx( L_tmp ), 4915 ); @@ -1049,7 +1051,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ 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 /*0.1 in Q15*/ ); } /* Quantized mean gain without clipping */ @@ -1064,7 +1066,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ 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 /*0.3 in Q12*/ ); 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 ); @@ -1086,7 +1088,7 @@ Word16 gsc_gainQ_fx( /*Q12*/ } /*add end */ test(); - IF( LE_32( core_brate, ACELP_9k60 ) && EQ_16( coder_type, INACTIVE ) ) + IF( LE_32( core_brate, ACELP_9k60 ) && ( coder_type == INACTIVE ) ) { /* Some energy is needed in high band for stat_noise_uv_enc to be functional in inactive speech */ diff --git a/lib_com/gs_inact_switching_fx.c b/lib_com/gs_inact_switching_fx.c index aa7b647bd..7fc4ca16d 100644 --- a/lib_com/gs_inact_switching_fx.c +++ b/lib_com/gs_inact_switching_fx.c @@ -13,8 +13,8 @@ *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -#define ALPHA0_FX 13107 -#define BETA0_FX ( 32768 - ALPHA0_FX ) +#define ALPHA0_FX 13107 /*Q15*/ +#define BETA0_FX ( 32768 - ALPHA0_FX ) /*Q15*/ /*========================================================================*/ /* FUNCTION : Inac_swtch_ematch_fx() */ @@ -83,7 +83,7 @@ void Inac_swtch_ematch_fx( 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 ) || ( 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 ); @@ -97,7 +97,7 @@ void Inac_swtch_ematch_fx( move16(); } } - ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( core_brate, ACELP_24k40 ) ) + ELSE IF( ( 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 ); @@ -112,6 +112,7 @@ void Inac_swtch_ematch_fx( 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 */ + move16(); ftmp = sub( lt_ener_per_band[i], Ener_per_bd[i] ); /*Q12 */ @@ -205,6 +206,8 @@ void Inac_switch_ematch_ivas_fx( test(); test(); test(); + test(); + test(); 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 ); @@ -212,11 +215,11 @@ void Inac_switch_ematch_ivas_fx( /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) { - lt_ener_per_band[i] = Ener_per_bd[i]; + lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/ 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 ) || ( last_core != ACELP_CORE ) || NE_16( last_codec_mode, MODE1 ) || ( ( 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 ); @@ -226,11 +229,11 @@ void Inac_switch_ematch_ivas_fx( /* reset long-term energy per band */ FOR( i = 0; i < MBANDS_GN; i++ ) { - lt_ener_per_band[i] = Ener_per_bd[i]; + lt_ener_per_band[i] = Ener_per_bd[i]; /*Q12*/ move16(); } } - ELSE IF( EQ_16( coder_type, INACTIVE ) && LE_32( total_brate, MAX_GSC_INACTIVE_BRATE ) ) + ELSE IF( ( 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 ); diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 93b7bb3f8..d0f72936d 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -17,8 +17,8 @@ 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 */ + const Word16 *y_norm, /* i : Quantized pulses Q(qNoise_fac) */ + Word16 *exc_diffQ, /* o : Quantized pulses with noise added Q(qNoise_fac) */ Word16 *seed_tcx, /* i : Random generator seed */ const Word16 coder_type, /* i : coder type */ Word16 qNoise_fac ) @@ -32,8 +32,8 @@ static void gs_noisf_fx( 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 ) ); /*2*Q(qNoise_fac)*/ + if ( ( coder_type == INACTIVE ) ) { NB_zer = 2; move16(); @@ -51,7 +51,7 @@ static void gs_noisf_fx( { exc_diffQ[i] = y_norm[i]; move16(); - ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); + ftmp = L_mac0( ftmp, exc_diffQ[i], exc_diffQ[i] ); /*2*Q(qNoise_fac)*/ } IF( LT_32( L_shl( ftmp, 1 ), const_1 ) ) @@ -118,11 +118,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 ) ); /*Q15*/ FOR( i = i_band; i < 5; i++ ) { - noisepb[i] = s_min( noisepb[i], 6554 ); + noisepb[i] = s_min( noisepb[i], 6554 /*0.2(Q15)*/ ); move16(); } @@ -196,7 +196,7 @@ static void EstimateNoiseLevel_fx( } test(); test(); - IF( ( EQ_16( coder_type, INACTIVE ) || GE_16( noise_lev, NOISE_LEVEL_SP3 ) ) && EQ_16( L_frame, L_FRAME ) ) + IF( ( ( 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++ ) { @@ -211,7 +211,7 @@ static void EstimateNoiseLevel_fx( set16_fx( noisepb, 14746 /*0.45*/, Mbands_gn ); } - IF( EQ_16( coder_type, INACTIVE ) ) + IF( ( coder_type == INACTIVE ) ) { FOR( ; i_band < Mbands_gn; i_band++ ) { @@ -320,7 +320,7 @@ void freq_dnw_scaling_fx( 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 fy_norm[], /* i/o: Frequency quantized parameter Qx */ Word16 Qx, /* Q format of fy_norm*/ const Word16 L_frame /* i : frame length */ @@ -340,7 +340,7 @@ void freq_dnw_scaling_fx( start_sc = 64; move16(); } - ELSE IF( EQ_16( coder_type, INACTIVE ) ) + ELSE IF( ( coder_type == INACTIVE ) ) { sc_dyn = mult_r( sc_dyn, 8192 ); /*Q15 (0.25 in Q15) */ start_sc = 80; @@ -377,9 +377,9 @@ void freq_dnw_scaling_fx( { 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 ) ); /*Qx*/ move16(); - fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); + fy_norm[i] = s_max( fy_norm[i], shl( -1, Qx ) ); /*Qx*/ move16(); } } @@ -387,9 +387,9 @@ void freq_dnw_scaling_fx( { 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 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*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 /*1.5 in Q10*/, sub( 10, Qx ) ) ); /*Qx*/ move16(); } } @@ -398,7 +398,7 @@ void freq_dnw_scaling_fx( } static void Decreas_freqPeak_fx( - const Word16 *lsf_new, /* i : ISFs at the end of the frame */ + const Word16 *lsf_new, /* i : ISFs at the end of the frame Qx2.56 */ Word16 *exc_diffQ, /* i/o: frequency coefficients of per band */ Word16 rat /* i : threshold of ratio between consecutive lsf_new_diff */ ) @@ -406,6 +406,7 @@ static void Decreas_freqPeak_fx( Word16 i, j, k; Word16 last_bin = 0; Word16 pos = 0; + move16(); Word16 *src, max_val, avrg; Word32 L_avrg, L_tmp; Word16 lsf_new_diff[M]; @@ -446,7 +447,7 @@ static void Decreas_freqPeak_fx( 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 /*4000 in Qx2.56*/ ) ) { last_bin = i; move16(); @@ -459,7 +460,7 @@ static void Decreas_freqPeak_fx( 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[( i - 1 ) << 4]; move16(); FOR( j = 0; j < 2; j++ ) { @@ -505,7 +506,7 @@ static void Decreas_freqPeak_fx( { FOR( i = pos - 1; i < pos + 2; i++ ) { - exc_diffQ[pos] = mult_r( 16384, exc_diffQ[pos] ); + exc_diffQ[pos] = mult_r( 16384 /*0.5 in Q15*/, exc_diffQ[pos] ); move16(); } } @@ -553,8 +554,7 @@ static void envelop_modify_fx( exp1 = norm_l( Ener_fx ); Ener_fx = L_shl( Ener_fx, exp1 ); - exp1 = 31 - exp1 - sub( shl( Q_exc, 1 ), 7 ); - move16(); + exp1 = sub( sub( 31, exp1 ), sub( shl( Q_exc, 1 ), 7 ) ); Ener_fx = Isqrt_lc( Ener_fx, &exp1 ); /*Q(31-exp1) */ weight_fx = 16384; /*Q15 */ @@ -586,7 +586,7 @@ static void envelop_modify_fx( L_tmp = L_mult0( sub( 32767, weight_fx ), Random( seed_tcx ) ); /*Q30 */ tmp1 = round_fx( L_shr( L_tmp, 2 ) ); - L_exc_diffQ_fx[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -617,7 +617,7 @@ static void envelop_modify_fx( 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[add( i_mult( 16, i ), j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ + L_exc_diffQ_fx[( ( 16 * i ) + j )] = L_mult0( Ener1_fx, add( tmp, tmp1 ) ); /*Q12 */ move32(); src_fx++; } @@ -647,6 +647,7 @@ static void envelop_modify_fx( { Q_tmp = sub( 16, exp ); *Q_hb_exc = sub( 12, Q_tmp ); + move16(); FOR( i = start_band; i < L_FRAME; i++ ) { exc_diffQ_fx[i] = extract_l( L_shr( L_exc_diffQ_fx[i], Q_tmp ) ); @@ -988,11 +989,11 @@ void highband_exc_dct_in_fx( 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 )]; + src = &exc_diffQ[L_FRAME - 1]; move16(); - dst = &exc_dct_in[sub( tmp, 1 )]; + dst = &exc_dct_in[( tmp - 1 )]; move16(); - end = &exc_diffQ[sub( tmp1, 1 )]; + end = &exc_diffQ[( tmp1 - 1 )]; move16(); WHILE( src > end ) @@ -1492,11 +1493,11 @@ void highband_exc_dct_in_ivas_fx( 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 )]; + src = &exc_diffQ[( L_FRAME - 1 )]; move16(); - dst = &exc_dct_in[sub( tmp, 1 )]; + dst = &exc_dct_in[( tmp - 1 )]; move16(); - end = &exc_diffQ[sub( tmp1, 1 )]; + end = &exc_diffQ[( tmp1 - 1 )]; move16(); WHILE( src > end ) diff --git a/lib_com/hq2_core_com.c b/lib_com/hq2_core_com.c index 59ad832f7..e238ac724 100644 --- a/lib_com/hq2_core_com.c +++ b/lib_com/hq2_core_com.c @@ -305,16 +305,17 @@ void reverse_transient_frame_energies( #define WMC_TOOL_SKIP void bit_allocation_second_fx2( - 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, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +) { Word16 k, k2 = 0; Word16 ever_bits[BANDS_MAX], ever_sort[BANDS_MAX]; /*Q12 */ @@ -323,13 +324,18 @@ void bit_allocation_second_fx2( Word16 exp; Word16 tmp; Word32 L_tmp; + move16(); + move16(); + move16(); + move16(); + FOR( k = 0; k < BANDS; k++ ) { test(); test(); IF( ( ( sub( k_sort[k], sub( BANDS, p2a_bands ) ) >= 0 ) && ( sub( p2a_flags[k_sort[k]], 1 ) == 0 ) ) || - ( ( sub( k_sort[k], sub( BANDS, 2 ) ) >= 0 ) && ( sub( last_bitalloc[sub( k_sort[k], sub( BANDS, 2 ) )], 1 ) == 0 ) ) ) + ( ( sub( k_sort[k], ( BANDS - 2 ) ) >= 0 ) && ( sub( last_bitalloc[k_sort[k] - ( BANDS - 2 )], 1 ) == 0 ) ) ) { exp = norm_s( band_width[k_sort[k]] ); tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ @@ -339,7 +345,7 @@ void bit_allocation_second_fx2( ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ if ( sub( ever_bits[k], rk_temp ) < 0 ) { - rk_temp = ever_bits[k]; + rk_temp = ever_bits[k]; /* Q12 */ k2 = k; move16(); move16(); @@ -364,7 +370,7 @@ void bit_allocation_second_fx2( move16(); IF( sub( ever_sort[k], ever_temp ) < 0 ) { - ever_temp = ever_sort[k]; + ever_temp = ever_sort[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -381,7 +387,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -392,7 +398,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -405,7 +411,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], sub( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -416,7 +422,7 @@ void bit_allocation_second_fx2( { IF( sub( k_sort[k], add( k_sort[k2], 1 ) ) == 0 ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index d24bb0d96..a05519387 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -122,7 +122,7 @@ void mdct_spectrum_denorm_fx( /*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 ) ); + L_temp = L_shr( L_band_energy[k], sub( SWB_BWE_LR_Qbe, 16 ) ); /* 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 */ @@ -145,14 +145,14 @@ void mdct_spectrum_denorm_fx( 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 ); + gamma_fx = round_fx( L_temp ); /* Qgamma */ } 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 ); + gamma_fx = round_fx( L_temp ); /* Qgamma */ } /* Adjust gamma based on pulse density (0 bit MSE gain estimator) */ @@ -160,12 +160,12 @@ void mdct_spectrum_denorm_fx( 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 ) ); + pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_norm - 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*/ ); -#else /* BASOP_NOGLOB */ + cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#else /* BASOP_NOGLOB */ cond_fx = sub( shl( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); #endif Overflow = 0; @@ -190,7 +190,7 @@ void mdct_spectrum_denorm_fx( L_tmp = L_Comp( exp, frac ); /* Q16 */ /* Mult part */ - L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); + L_tmp = Mpy_32_16_1( L_tmp, ld_slope_fx ); /* Q16 */ /* Pow part */ temp_lo_fx = L_Extract_lc( L_tmp, &temp_hi_fx ); @@ -213,7 +213,7 @@ void mdct_spectrum_denorm_fx( { /*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 ); + L_y2[i] = L_shl( L_tmp, exp_shift ); /* SWB_BWE_LR_Qs */ move32(); } } @@ -312,11 +312,11 @@ void mdct_spectrum_denorm_ivas_fx( 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 ) ) ); + temp_fx = div_s( shl( pow_fx, exp_normn ), extract_h( L_shl( L_Eyy, exp_normd ) ) ); /* ((Qpow + exp_norm) - (QEyy + exp_normd)) + 31 */ 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 ); + temp_fx = shl( temp_fx, exp_norm ); /* Qdiv + exp_norm */ Qdiv = add( Qdiv, exp_norm ); /* Sqrt part sqrt(pow (2.0f, band_energy[i])/Eyy) */ @@ -341,12 +341,12 @@ void mdct_spectrum_denorm_ivas_fx( 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 ) ); + pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_normn + 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*/ ); -#else /* BASOP_NOGLOB */ + cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#else /* BASOP_NOGLOB */ cond_fx = sub( shl( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); #endif Overflow = 0; @@ -363,7 +363,7 @@ void mdct_spectrum_denorm_ivas_fx( /* Log2 part */ exp_norm = norm_s( div_pd_fx ); - L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); + L_div_pd = L_deposit_h( shl( div_pd_fx, exp_norm ) ); /* Qdivpd + exp_norm + 16 */ Qdivpd = add( add( Qdivpd, exp_norm ), 16 ); frac = Log2_norm_lc( L_div_pd ); @@ -394,7 +394,7 @@ void mdct_spectrum_denorm_ivas_fx( { /*y2[i] = gamma * inp_vector[i]; */ L_tmp = L_mult( gamma_fx, extract_l( inp_vector[i] ) ); /* Qgamma+0+1=Qgamma+1 */ - L_y2[i] = L_shl( L_tmp, exp_shift ); + L_y2[i] = L_shl( L_tmp, exp_shift ); /* SWB_BWE_LR_Qs */ move32(); } } @@ -429,25 +429,26 @@ void mdct_spectrum_denorm_ivas_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, /* Q0 */ + const Word16 num_bits, /* Q0 */ + const Word16 is_transient, /* Q0 */ + Word16 *bands, /* Q0 */ + Word16 *length, /* Q0 */ + Word16 band_width[], /* Q0 */ + Word16 band_start[], /* Q0 */ + Word16 band_end[], /* Q0 */ + Word32 *L_qint, /* Q13 */ + Word16 *eref, /* Q10 */ + Word16 *bit_alloc_weight, /* Q13 */ + Word16 *gqlevs, /* Q0 */ + Word16 *Ngq, /* Q0 */ + Word16 *p2a_bands, /* Q0 */ + Word16 *p2a_th, /* Q11 */ + Word16 *pd_thresh, /* Q15 */ + Word16 *ld_slope, /* Q15 */ + Word16 *ni_coef, /* Q14 */ + Word32 L_bwe_br /* Q0 */ +) { const Xcore_Config *xcore_config_fx; @@ -554,67 +555,67 @@ ELSE } } -*bands = xcore_config_fx->bands; +*bands = xcore_config_fx->bands; /* Q0 */ move16(); -*length = xcore_config_fx->bw; +*length = xcore_config_fx->bw; /* Q0 */ move16(); -*L_qint = xcore_config_fx->L_qint; +*L_qint = xcore_config_fx->L_qint; /* Q13 */ move32(); -*eref = xcore_config_fx->eref; +*eref = xcore_config_fx->eref; /* Q10 */ move16(); -*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; +*bit_alloc_weight = xcore_config_fx->bit_alloc_weight; /* Q13 */ move16(); -*gqlevs = xcore_config_fx->gqlevs; +*gqlevs = xcore_config_fx->gqlevs; /* Q0 */ move16(); -*Ngq = xcore_config_fx->Ngq; +*Ngq = xcore_config_fx->Ngq; /* Q0 */ move16(); -*p2a_bands = xcore_config_fx->p2a_bands; +*p2a_bands = xcore_config_fx->p2a_bands; /* Q0 */ move16(); -*p2a_th = xcore_config_fx->p2a_th; +*p2a_th = xcore_config_fx->p2a_th; /* Q11 */ move16(); -*pd_thresh = xcore_config_fx->pd_thresh; +*pd_thresh = xcore_config_fx->pd_thresh; /* Q15 */ move16(); -*ld_slope = xcore_config_fx->ld_slope; +*ld_slope = xcore_config_fx->ld_slope; /* Q14 */ move16(); -*ni_coef = xcore_config_fx->ni_coef; +*ni_coef = xcore_config_fx->ni_coef; /* Q14 */ move16(); /*mvs2s_fx (xcore_config_fx->band_width, band_width, *bands); */ -Copy( xcore_config_fx->band_width, band_width, *bands ); +Copy( xcore_config_fx->band_width, band_width, *bands ); /* Q0 */ /* Expand band_width[] table for short windows */ IF( is_transient ) { - bands_sh = *bands; + bands_sh = *bands; /* Q0 */ move16(); - *bands = shl( bands_sh, 2 ); + *bands = shl( bands_sh, 2 ); /* Q0 */ move16(); - *length = shl( *length, 2 ); + *length = shl( *length, 2 ); /* Q0 */ move16(); FOR( i = 1; i <= 3; i++ ) { FOR( k = 0; k < bands_sh; k++ ) { - band_width[i * bands_sh + k] = band_width[k]; + band_width[i * bands_sh + k] = band_width[k]; /* Q0 */ move16(); } } } /* Formulate band_start and band_end tables from band_width table */ -band_start[0] = 0; +band_start[0] = 0; /* Q0 */ move16(); -band_end[0] = sub( band_width[0], 1 ); +band_end[0] = sub( band_width[0], 1 ); /* Q0 */ move16(); FOR( k = 1; k < *bands; k++ ) { - band_start[k] = add( band_start[k - 1], band_width[k - 1] ); + band_start[k] = add( band_start[k - 1], band_width[k - 1] ); /* Q0 */ move16(); - band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); + band_end[k] = sub( add( band_start[k], band_width[k] ), 1 ); /* Q0 */ move16(); } @@ -638,37 +639,37 @@ void reverse_transient_frame_energies_fx( 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 ); + bands_2 = shr( bands, 1 ); /* Q0 */ + bands_4 = shr( bands, 2 ); /* Q0 */ + bands_8 = shr( bands, 3 ); /* Q0 */ - k1 = bands_4; - k2 = sub( bands_2, 1 ); - p_be1 = &L_band_energy[k1]; - p_be2 = &L_band_energy[k2]; + k1 = bands_4; /* Q0 */ + k2 = sub( bands_2, 1 ); /* Q0 */ + p_be1 = &L_band_energy[k1]; /* Q14 */ + p_be2 = &L_band_energy[k2]; /* Q14 */ FOR( k = 0; k < bands_8; k++ ) { - L_be = *p_be1; + L_be = *p_be1; /* Q14 */ move32(); - *p_be1 = *p_be2; + *p_be1 = *p_be2; /* Q14 */ move32(); - *p_be2 = L_be; + *p_be2 = L_be; /* Q14 */ 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]; + k1 = sub( bands, bands_4 ); /* 3*bands/4 Q0 */ + k2 = sub( bands, 1 ); /* Q0 */ + p_be1 = &L_band_energy[k1]; /* Q14 */ + p_be2 = &L_band_energy[k2]; /* Q14 */ FOR( k = 0; k < bands_8; k++ ) { - L_be = *p_be1; + L_be = *p_be1; /* Q14 */ move32(); - *p_be1 = *p_be2; + *p_be1 = *p_be2; /* Q14 */ move32(); - *p_be2 = L_be; + *p_be2 = L_be; /* Q14 */ move32(); p_be1++; p_be2--; @@ -685,14 +686,14 @@ 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 Q0*/ + const Word16 band_end[], /* i: End position of sub band Q0*/ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak Q0*/ + const Word16 BANDS, /* i: total number of bands Q0*/ + const Word32 L_bwe_br, /* i: bitrate information Q0*/ + Word16 new_band_start[], /* o: Starting position of new shorten sub band Q0*/ + Word16 new_band_end[], /* o: End position of new shorten sub band Q0*/ + Word16 new_band_width[] /* o: new sub band bandwidth Q0*/ ) { Word16 j; @@ -702,60 +703,60 @@ void spt_shorten_domain_pre_fx( Word16 new_band_width_half; const Word16 *p_bw_SPT_tbl; /* pointer of bw_SPT_tbl */ - p_bw_SPT_tbl = bw_SPT_tbl[0]; + p_bw_SPT_tbl = bw_SPT_tbl[0]; /* Q0 */ if ( EQ_32( L_bwe_br, HQ_16k40 ) ) { - p_bw_SPT_tbl = bw_SPT_tbl[1]; + p_bw_SPT_tbl = bw_SPT_tbl[1]; /* Q0 */ } kpos = 0; move16(); j = 0; move16(); - FOR( k = sub( BANDS, SPT_SHORTEN_SBNUM ); k < BANDS; k++ ) + FOR( k = BANDS - SPT_SHORTEN_SBNUM; k < BANDS; k++ ) { IF( prev_SWB_peak_pos[kpos] != 0 ) { - new_band_width[j] = p_bw_SPT_tbl[j]; + new_band_width[j] = p_bw_SPT_tbl[j]; /* Q0 */ /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr( new_band_width[j], 1 ); + new_band_width_half = shr( new_band_width[j], 1 ); /* Q0 */ move16(); - new_band_start[j] = sub( prev_SWB_peak_pos[kpos], new_band_width_half ); + new_band_start[j] = sub( prev_SWB_peak_pos[kpos], new_band_width_half ); /* Q0 */ move16(); - new_band_end[j] = add( prev_SWB_peak_pos[kpos], new_band_width_half ); + new_band_end[j] = add( prev_SWB_peak_pos[kpos], new_band_width_half ); /* Q0 */ move16(); IF( LT_16( new_band_start[j], band_start[k] ) ) { - new_band_start[j] = band_start[k]; + new_band_start[j] = band_start[k]; /* Q0 */ move16(); - new_band_end[j] = add( new_band_start[j], sub( new_band_width[j], 1 ) ); + new_band_end[j] = add( new_band_start[j], sub( new_band_width[j], 1 ) ); /* Q0 */ move16(); } ELSE IF( GT_16( new_band_end[j], band_end[k] ) ) { - new_band_end[j] = band_end[k]; + new_band_end[j] = band_end[k]; /* Q0 */ move16(); - new_band_start[j] = sub( new_band_end[j], sub( new_band_width[j], 1 ) ); + new_band_start[j] = sub( new_band_end[j], sub( new_band_width[j], 1 ) ); /* Q0 */ move16(); } } ELSE { - new_band_width[j] = p_bw_SPT_tbl[j]; + new_band_width[j] = p_bw_SPT_tbl[j]; /* Q0 */ /*shorten the bandwidth for pulse resolution*/ - new_band_width_half = shr( new_band_width[j], 1 ); + new_band_width_half = shr( new_band_width[j], 1 ); /* Q0 */ move16(); - new_band_start[j] = sub( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + new_band_start[j] = sub( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); /* Q0 */ move16(); - new_band_end[j] = add( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); + new_band_end[j] = add( shr( add( band_start[k], band_end[k] ), 1 ), new_band_width_half ); /* Q0 */ move16(); } - kpos = add( kpos, 1 ); - j = add( j, 1 ); + kpos++; + j++; } return; @@ -768,13 +769,13 @@ 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 Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -782,15 +783,15 @@ void spt_shorten_domain_band_save_fx( kpos = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { - org_band_start[kpos] = band_start[k]; + org_band_start[kpos] = band_start[k]; /* Q0 */ move16(); - org_band_end[kpos] = band_end[k]; + org_band_end[kpos] = band_end[k]; /* Q0 */ move16(); - org_band_width[kpos] = band_width[k]; + org_band_width[kpos] = band_width[k]; /* Q0 */ move16(); - kpos = add( kpos, 1 ); + kpos++; } return; @@ -803,13 +804,13 @@ 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 Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ) { Word16 k; @@ -817,15 +818,15 @@ void spt_shorten_domain_band_restore_fx( kpos = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { - band_start[k] = org_band_start[kpos]; + band_start[k] = org_band_start[kpos]; /* Q0 */ move16(); - band_end[k] = org_band_end[kpos]; + band_end[k] = org_band_end[kpos]; /* Q0 */ move16(); - band_width[k] = org_band_width[kpos]; + band_width[k] = org_band_width[kpos]; /* Q0 */ move16(); - kpos = add( kpos, 1 ); + kpos++; } return; @@ -838,11 +839,11 @@ 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 Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ) { @@ -852,7 +853,7 @@ void spt_swb_peakpos_tmp_save_fx( j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = bands - SPT_SHORTEN_SBNUM; k < bands; k++ ) { L_peak_max = L_deposit_l( 0 ); prev_SWB_peak_pos_tmp[j] = 0; @@ -863,13 +864,13 @@ void spt_swb_peakpos_tmp_save_fx( move32(); IF( LT_32( L_peak_max, L_abs_y2 ) ) { - L_peak_max = L_abs_y2; + L_peak_max = L_abs_y2; /* Qx */ move32(); - prev_SWB_peak_pos_tmp[j] = i; + prev_SWB_peak_pos_tmp[j] = i; /* Q0 */ move16(); } } - j = add( j, 1 ); + j++; } return; } @@ -877,16 +878,17 @@ void spt_swb_peakpos_tmp_save_fx( // 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, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +) { Word16 k, k2 = 0; move16(); @@ -906,7 +908,7 @@ void bit_allocation_second_fx( 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 ) ) ) ) + ( ( GE_16( k_sort[k], ( BANDS - 2 ) ) ) && ( EQ_16( last_bitalloc[k_sort[k] - ( BANDS - 2 )], 1 ) ) ) ) { exp = norm_s( band_width[k_sort[k]] ); tmp = shl( band_width[k_sort[k]], exp ); /*Q(exp) */ @@ -916,7 +918,7 @@ void bit_allocation_second_fx( ever_bits[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ IF( LT_16( ever_bits[k], rk_temp ) ) { - rk_temp = ever_bits[k]; + rk_temp = ever_bits[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -941,7 +943,7 @@ void bit_allocation_second_fx( ever_sort[k] = extract_l( L_shr( L_tmp, tmp ) ); /*Q12 */ IF( LT_16( ever_sort[k], ever_temp ) ) { - ever_temp = ever_sort[k]; + ever_temp = ever_sort[k]; /* Q12 */ move16(); k2 = k; move16(); @@ -950,7 +952,7 @@ void bit_allocation_second_fx( } } - k_num[0] = k2; + k_num[0] = k2; /* Q0 */ move16(); IF( EQ_16( k_sort[k2], sub( BANDS, 1 ) ) ) { @@ -958,7 +960,7 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], sub( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } @@ -969,20 +971,20 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } } ELSE { - IF( LT_32( Rk[sub( k_sort[k2], 1 )], Rk[add( k_sort[k2], 1 )] ) ) + IF( LT_32( Rk[k_sort[k2] - 1], Rk[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; + k_num[1] = k; /* Q0 */ move16(); } } @@ -993,7 +995,7 @@ void bit_allocation_second_fx( { if ( EQ_16( k_sort[k], add( k_sort[k2], 1 ) ) ) { - k_num[1] = k; + k_num[1] = k; /* Q0 */ move16(); } } diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index 223462df4..12bedd1fb 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -43,28 +43,29 @@ * 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[], /* Q12 */ + const Word16 band_start[], /* Q0 */ + const Word16 band_end[], /* Q0 */ + const Word16 band_width[], /* Q0 */ + Word32 Ep_fx[], /* Q-6 */ + Word32 Rk_fx[], /* QRk (Q16) */ + const Word16 npulses[], /* Q0 */ + Word16 ni_seed, /* Q0 */ + const Word16 bands, /* Q0 */ + const Word16 ni_start_band, /* Q0 */ + const Word16 bw_low, /* Q0 */ + const Word16 bw_high, /* Q0 */ + const Word32 enerL_fx, /* Q0 */ + const Word32 enerH_fx, /* Q0 */ + Word32 last_ni_gain_fx[], /* Q17 */ + Word16 last_env_fx[], /* Q1 */ + Word16 *last_max_pos_pulse, /* Q0 */ + Word16 *p2a_flags, /* Q0 */ + Word16 p2a_bands, /* Q0 */ + const Word16 hqswb_clas, /* Q0 */ + const Word16 bwidth, /* Q0 */ + const Word32 bwe_br /* Q0 */ +) { Word32 L_tmp, L_tmp2, L_tmp2x, L_tmp3, L_tmp1; Word16 exp, exp2, Q_speech; @@ -136,7 +137,7 @@ void hq2_noise_inject_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); - L_tmp3 = (Word32) band_width[k]; + L_tmp3 = (Word32) band_width[k]; /* Q0 */ move32(); exp2 = norm_l( L_tmp3 ); tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); @@ -152,8 +153,8 @@ void hq2_noise_inject_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp2 ); env_fx[k] = L_tmp; move32(); /*Q(31-exp2) move32(); */ @@ -174,35 +175,35 @@ void hq2_noise_inject_fx( { FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /*0 */ + L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /* Q0 */ #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 */ + move32(); /* Q0 */ IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) ) { peak_fx[k] = abs_s( y2hat_fx[i] ); - move16(); /*0 */ + move16(); /* Q0 */ } IF( y2hat_fx[i] != 0 ) { - count[k] = add( count[k], 1 ); + count[k] = add( count[k], 1 ); /* Q0 */ move16(); } } - max_pos_pulse = k; + max_pos_pulse = k; /* Q0 */ move16(); - L_tmp2 = Ep_fx[k]; + 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]; + L_tmp3 = (Word32) band_width[k]; /* Q0 */ exp2 = norm_l( L_tmp3 ); tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); @@ -217,8 +218,8 @@ void hq2_noise_inject_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); + tmp = div_s( tmp2, tmp ); /* Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ L_tmp = Isqrt_lc( L_tmp, &exp2 ); Ep_fx[k] = L_tmp; move32(); /*Q(31-exp2) */ @@ -239,9 +240,9 @@ void hq2_noise_inject_fx( /* calculate the noise gain */ satur = 0; move16(); - if ( GE_16( pd_fx[k], 819 ) ) + if ( GE_16( pd_fx[k], 819 /* 0.8 in Q10 */ ) ) { - satur = 1; + satur = 1; /* Q0 */ move16(); } @@ -262,7 +263,7 @@ void hq2_noise_inject_fx( } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -274,10 +275,10 @@ void hq2_noise_inject_fx( 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) */ + tmp = sub( 1536 /* 1.5 in Q10 */, 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 /* 6.0f in Q10 */ ); /*Q(Q_env_fx[k]-1+10-15 = Q_env_fx[k]-6) */ IF( peak_fx[k] != 0 ) { @@ -287,7 +288,7 @@ void hq2_noise_inject_fx( } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -307,48 +308,48 @@ void hq2_noise_inject_fx( move16(); /*Q12 */ if ( GT_16( k, sb ) ) { - fac_fx = mult( 24576, tmp2 ); /*//Q(14+13-15=12) */ + fac_fx = mult( 24576 /* 1.5 in Q14 */, tmp2 ); /*//Q(14+13-15=12) */ } } ELSE { IF( LE_16( k, sb ) ) { - tmp = sub( 1536, pd_fx[k] ); /*Q10 */ + tmp = sub( 1536 /* 1.5 in Q10 */, 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) */ + L_tmp = Mult_32_16( L_tmp, 20480 /* 5 in Q12 */ ); /*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) */ + fac_fx = shl( mult( 32767 /* 4.0f in Q13 */, tmp2 ), 1 ); /*//Q(13+13-15+1=12) */ } } } ELSE { fac_fx = 4505; - move16(); /*Q12 */ + move16(); /* 1.1 in 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) */ + tmp = sub( 1536 /* 1.5 in Q10 */, pd_fx[k] ); /*Q10 */ + tmp2 = s_min( 1024 /* 1 in Q10 */, 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 /* 20 in Q10 */ ); /*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) */ + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384 /* 0.5f in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1 in Q15 */ move16(); Q_speech = 0; move16(); @@ -371,35 +372,35 @@ void hq2_noise_inject_fx( 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) */ + tmp = shl( env_fx2[k], Q_speech ); /*Q(Q_speech+1) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech-1=28-Q_speech) */ Q_speech = sub( 28, Q_speech ); } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1/0 in Q15 */ move16(); Q_speech = 0; move16(); } - tmp1 = mult( env_fx2[add( k, 1 )], 16384 ); /*Q(1+15-15=1) Q1 */ + tmp1 = mult( env_fx2[k + 1], 16384 /* 0.5 in Q15 */ ); /*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 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, env_fx2[k - 1] ); + tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*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 ) + IF( count[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) */ + L_tmp = L_mult( env_fx2[k + 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = Mult_32_16( L_tmp, 24576 /* 1.5 in Q14 */ ); /*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 ) + ELSE IF( count[k - 1] == 0 && tmp4 > 0 ) { - L_tmp = L_mult( env_fx2[sub( k, 1 )], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = L_mult( env_fx2[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 */ #else @@ -414,7 +415,7 @@ void hq2_noise_inject_fx( 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 */ + tmp1 = mult( peak_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(0+15-15=0) Q0 */ tmp4 = sub( tmp1, shr( env_fx2[k], 1 ) ); test(); IF( L_tmp > 0 && tmp4 < 0 ) @@ -422,12 +423,12 @@ void hq2_noise_inject_fx( 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) */ + tmp = shl( peak_fx[k], Q_speech ); /*Q(Q_speech) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { - tmp = 0x7fff; + tmp = 0x7fff; /* 1.0f in Q15 */ move16(); Q_speech = 0; move16(); @@ -436,7 +437,7 @@ void hq2_noise_inject_fx( 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 */ + tmp = sub( 16384 /* 2 in Q13 */, tmp ); /*Q13 */ fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 2 ) ); /*Q12*/ } @@ -447,9 +448,9 @@ void hq2_noise_inject_fx( 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 = div_s( 16384 /* 0.5 in Q15 */, 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 /* 1.25 in Q14 */ ); /*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 ); @@ -458,22 +459,22 @@ void hq2_noise_inject_fx( #else L_tmp = L_shr( L_tmp2, tmp ); /*Q7 */ #endif - tmp = extract_l( L_min( L_tmp, 192 ) ); /* */ + tmp = extract_l( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ); /* */ 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 = 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 /* 1.25 in Q14 */ ); /*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 */ #else 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 */ + tmp = extract_l( ( L_min( L_tmp, 192 /* 1.5 in Q7 */ ) ) ); /* Q7 */ + fac_fx = extract_h( L_shl( L_mult( fac_fx, tmp ), 8 ) ); /*Q12 */ } } } @@ -481,12 +482,12 @@ void hq2_noise_inject_fx( } ELSE { - fac_fx = 4505; + fac_fx = 4505; /* 1.1 in Q12 */ move16(); test(); if ( EQ_16( hqswb_clas, HQ_HARMONIC ) && EQ_16( bwidth, SWB ) ) { - fac_fx = 3277; + fac_fx = 3277; /* 0.8 in Q12 */ move16(); } } @@ -505,11 +506,11 @@ void hq2_noise_inject_fx( } /* smooth the noise gain between the current frame and the previous frame */ - pos = s_max( max_pos_pulse, *last_max_pos_pulse ); + pos = s_max( max_pos_pulse, *last_max_pos_pulse ); /* Q0 */ move16(); if ( EQ_16( bwidth, SWB ) ) { - pos = sub( ni_end_band, 1 ); + pos = sub( ni_end_band, 1 ); /* Q0 */ move16(); } @@ -518,18 +519,18 @@ void hq2_noise_inject_fx( 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 */ + tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /* Q1 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /* Q1 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /* Q1 */ + L_tmp = L_add( L_tmp, (Word32) env_fx2[k + 1] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /* Q1 */ + L_tmp1 = L_add( L_tmp1, (Word32) last_env_fx[k + 1] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */ test(); test(); test(); @@ -537,32 +538,32 @@ void hq2_noise_inject_fx( { 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 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ 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 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ 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 */ + tmp1 = mult( last_env_fx[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp2 = sub( env_fx2[k], tmp1 ); /*Q1 */ + tmp1 = mult( env_fx2[k], 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15=1) Q1 */ + tmp3 = sub( tmp1, last_env_fx[k] ); /*Q1 */ + L_tmp = L_add( (Word32) env_fx2[k], (Word32) env_fx2[k - 1] ); /*Q1 */ + L_tmp1 = L_add( (Word32) last_env_fx[k], (Word32) last_env_fx[k - 1] ); /*Q1 */ + L_tmp2 = Mult_32_16( L_tmp1, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp2 = L_sub( L_tmp, L_tmp2 ); /*Q1 */ + L_tmp3 = Mult_32_16( L_tmp, 16384 /* 0.5 in Q15 */ ); /*Q(1+15-15) Q1 */ + L_tmp3 = L_sub( L_tmp3, L_tmp1 ); /*Q1 */ test(); test(); @@ -571,16 +572,16 @@ void hq2_noise_inject_fx( { 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 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 6554 /* 0.2 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 26214 /* 0.8 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ 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 ); + L_tmp = Mult_32_16( ni_gain_fx[k], 19661 /* 0.6 in Q15 */ ); /*Q(17+15-15 = 17) */ + L_tmp1 = Mult_32_16( last_ni_gain_fx[k], 13107 /* 0.4 in Q15 */ ); /*Q17 */ + ni_gain_fx[k] = L_add( L_tmp, L_tmp1 ); /* Q17 */ move32(); } } @@ -596,7 +597,7 @@ void hq2_noise_inject_fx( { IF( L_y2[i] != 0 ) { - L_y2[i] = Mult_32_16( L_y2[i], 26215 ); + L_y2[i] = Mult_32_16( L_y2[i], 26215 /* 0.8 in Q15 */ ); move32(); /*Q(12+15-15=12) */ } } @@ -614,8 +615,8 @@ void hq2_noise_inject_fx( 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 = div_s( 16384 /* 0.5 in Q15 */, 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 @@ -635,7 +636,7 @@ void hq2_noise_inject_fx( tmp = extract_h( L_shl( L_tmp, tmp ) ); /*Q12 */ #endif } - fac_fx = s_max( tmp, 4096 ); /*Q12 */ + fac_fx = s_max( tmp, 4096 /* 1 in Q12 */ ); /*Q12 */ FOR( i = band_start[k]; i <= band_end[k]; i++ ) { @@ -650,7 +651,7 @@ void hq2_noise_inject_fx( #else tmp = shl( band_width[k], Q_speech ); /*Q(Q_speech) */ #endif - tmp = div_s( 16384, tmp ); /*Q(15+14-Q_speech) */ + tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } ELSE { @@ -659,9 +660,9 @@ void hq2_noise_inject_fx( move16(); move16(); } - 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) */ + tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*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 */ #else @@ -691,7 +692,7 @@ void hq2_noise_inject_fx( } Copy( env_fx2, last_env_fx, ni_end_band ); - Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); + Copy32( ni_gain_fx, last_ni_gain_fx, ni_end_band ); /* Q17 */ *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 e03fec40b..c3fc6a3a5 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -22,7 +22,7 @@ void ivas_hq_bit_allocation_fx( 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 *noise_level, /* o : HVQ noise level Q15 */ 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 */ @@ -56,7 +56,7 @@ void ivas_hq_bit_allocation_fx( IF( NE_16( hqswb_clas, HQ_TRANSIENT ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( core_brate, HQ_32k ) ) ) { /* 'nf_idx' 2-bits index written later */ - *num_bits = sub( *num_bits, 2 ); + *num_bits = sub( *num_bits, 2 ); /*Q0*/ move16(); } @@ -65,17 +65,17 @@ void ivas_hq_bit_allocation_fx( { IF( GE_32( core_brate, HQ_32k ) ) { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); /*Q0*/ } ELSE { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); /*Q0*/ } move16(); IF( EQ_16( length, L_SPEC48k ) ) { - *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); + *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); /*Q0*/ move16(); } } @@ -235,7 +235,7 @@ void hq_bit_allocation_fx( 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 *noise_level, /* o : HVQ noise level Q15 */ 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 */ @@ -293,6 +293,8 @@ void hq_bit_allocation_fx( } } + test(); + test(); IF( ( EQ_16( length, L_FRAME48k ) ) && ( NE_16( hqswb_clas, HQ_HARMONIC ) ) && ( NE_16( hqswb_clas, HQ_HVQ ) ) ) { tmp = 0; diff --git a/lib_com/hq_conf.c b/lib_com/hq_conf.c index 6c2b60c99..e99e89ba7 100644 --- a/lib_com/hq_conf.c +++ b/lib_com/hq_conf.c @@ -287,14 +287,10 @@ void hq_configure_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -323,12 +319,9 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -354,28 +347,22 @@ void hq_configure_fx( *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -390,12 +377,9 @@ void hq_configure_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -405,7 +389,7 @@ void hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; @@ -417,29 +401,23 @@ void hq_configure_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 ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } p_sfmsize = band_len_harm; - move16(); p_sfm_start = band_start_harm; - move16(); p_sfm_end = band_end_harm; - move16(); } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -469,70 +447,58 @@ void hq_configure_fx( *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } 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; + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ *num_sfm = NB_SFM; - move16(); - move16(); - move16(); - move16(); } 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(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE { *num_sfm = SFM_N_WB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { 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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); } - *nb_sfm = *num_sfm; - *num_env_bands = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ + *num_env_bands = *num_sfm; /* Q0 */ move16(); move16(); } diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index 7dd8a2371..ae3fc58b0 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -50,14 +50,10 @@ void ivas_hq_configure_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -86,12 +82,9 @@ void ivas_hq_configure_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -101,7 +94,7 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -112,33 +105,27 @@ void ivas_hq_configure_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 ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -153,12 +140,9 @@ void ivas_hq_configure_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -168,7 +152,7 @@ void ivas_hq_configure_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; @@ -180,29 +164,23 @@ void ivas_hq_configure_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 ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } p_sfmsize = band_len_harm; - move16(); p_sfm_start = band_start_harm; - move16(); p_sfm_end = band_end_harm; - move16(); } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -227,75 +205,65 @@ void ivas_hq_configure_fx( /* HQ_NORMAL and HQ_TRANSIENT */ *num_sfm = SFM_N_SWB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } 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(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ + *num_sfm = NB_SFM; move16(); } 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(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE { *num_sfm = SFM_N_WB; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { 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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); /*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 /* 1.25 in Q14 */ ); /* Q0 */ move16(); } - *nb_sfm = *num_sfm; - *num_env_bands = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ + *num_env_bands = *num_sfm; /* Q0 */ move16(); move16(); } @@ -349,14 +317,10 @@ void hq_configure_evs_fx( { *num_sfm = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ - test(); IF( GE_32( core_brate, HQ_32k ) ) { *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; @@ -371,7 +335,7 @@ void hq_configure_evs_fx( move16(); move16(); } - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); } ELSE @@ -385,12 +349,9 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_HARM_FB; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -400,7 +361,7 @@ void hq_configure_evs_fx( move16(); *nb_sfm = HVQ_THRES_SFM_24k; move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); + *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_24k; move16(); @@ -411,33 +372,27 @@ 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 ); /* Q0 */ move16(); *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - move16(); - move16(); - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE { *num_sfm = NB_SFM; move16(); - *nb_sfm = *num_sfm; + *nb_sfm = *num_sfm; /* Q0 */ move16(); *num_env_bands = NB_SFM; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } } @@ -452,12 +407,9 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_HARM; move16(); - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { @@ -485,23 +437,17 @@ void hq_configure_evs_fx( *start_norm = HVQ_THRES_SFM_32k; move16(); } - p_sfmsize = band_len_harm; - move16(); - p_sfm_start = band_start_harm; - move16(); - p_sfm_end = band_end_harm; - move16(); + p_sfmsize = band_len_harm; /* Q0 */ + p_sfm_start = band_start_harm; /* Q0 */ + p_sfm_end = band_end_harm; /* Q0 */ } ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) { *num_sfm = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ IF( GE_32( core_brate, HQ_32k ) ) { @@ -531,36 +477,29 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_SWB; move16(); - p_sfmsize = band_len_HQ; - move16(); - p_sfm_start = band_start_HQ; - move16(); - p_sfm_end = band_end_HQ; - move16(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ } } 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(); + p_sfmsize = band_len_HQ; /* Q0 */ + p_sfm_start = band_start_HQ; /* Q0 */ + p_sfm_end = band_end_HQ; /* Q0 */ + *num_sfm = NB_SFM; move16(); } 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(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ + *num_sfm = SFM_N_WB; move16(); } ELSE @@ -572,25 +511,22 @@ void hq_configure_evs_fx( *num_env_bands = SFM_N_WB; move16(); - p_sfmsize = band_len_wb; - move16(); - p_sfm_start = band_start_wb; - move16(); - p_sfm_end = band_end_wb; - move16(); + p_sfmsize = band_len_wb; /* Q0 */ + p_sfm_start = band_start_wb; /* Q0 */ + p_sfm_end = band_end_wb; /* Q0 */ } IF( bw_ext ) { 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 /* 1.25 in Q14 */ ); move16(); /*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 /* 1.25 in Q14 */ ); move16(); /*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 /* 1.25 in Q14 */ ); move16(); } *nb_sfm = *num_sfm; diff --git a/lib_com/hvq_pvq_bitalloc_fx.c b/lib_com/hvq_pvq_bitalloc_fx.c index 298547b53..bc15fe266 100644 --- a/lib_com/hvq_pvq_bitalloc_fx.c +++ b/lib_com/hvq_pvq_bitalloc_fx.c @@ -22,10 +22,10 @@ Word16 hvq_pvq_bitalloc_fx( 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 *Rk, /* Q3 o : bit allocation for concatenated vector */ + Word16 *R, /* Q0 i/o: Global bit allocation */ + Word16 *sel_bands, /* Q0 o : Selected bands for encoding */ + Word16 *n_sel_bands /* Q0 o : No. of selected bands for encoding */ ) { Word16 num_bands, band_max_bits; @@ -52,11 +52,11 @@ Word16 hvq_pvq_bitalloc_fx( IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) { - band_max_bits = HVQ_BAND_MAX_BITS_24k; + band_max_bits = HVQ_BAND_MAX_BITS_24k; /*Q0*/ move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX; + one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_24k_FX; /*Q15*/ move16(); - k_start = HVQ_THRES_SFM_24k; + k_start = HVQ_THRES_SFM_24k; /*Q0*/ move16(); IF( EQ_16( bwidth_fx, FB ) ) { @@ -71,11 +71,11 @@ Word16 hvq_pvq_bitalloc_fx( } ELSE { - band_max_bits = HVQ_BAND_MAX_BITS_32k; + band_max_bits = HVQ_BAND_MAX_BITS_32k; /*Q0*/ move16(); - one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX; + one_over_band_max_bits = ONE_OVER_HVQ_BAND_MAX_BITS_32k_FX; /*Q15*/ move16(); - k_start = HVQ_THRES_SFM_32k; + k_start = HVQ_THRES_SFM_32k; /*Q0*/ move16(); IF( EQ_16( bwidth_fx, FB ) ) { @@ -164,14 +164,14 @@ Word16 hvq_pvq_bitalloc_fx( { QuantaPerDsDirac_fx( band_len_harm[k_max], 1, hBitsN, &n ); } - m = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); + m = shl( sub( num_bits, HVQ_PVQ_GAIN_BITS ), 3 ); /*Q3*/ IF( GE_16( m, n ) ) { IF( GT_16( num_bands, 1 ) ) /* condition: num_bands > 1 */ { - sel_bands[*n_sel_bands] = k_max; + sel_bands[*n_sel_bands] = k_max; /*Q0*/ move16(); - *n_sel_bands = add( *n_sel_bands, 1 ); + *n_sel_bands = add( *n_sel_bands, 1 ); /*Q0*/ move16(); R[k_max] = 1; /* Mark that the band has been encoded for fill_spectrum */ move16(); @@ -184,11 +184,11 @@ Word16 hvq_pvq_bitalloc_fx( 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 ); /*Q3*/ 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 ); /*Q3*/ move16(); return num_bands; diff --git a/lib_com/interleave_spectrum.c b/lib_com/interleave_spectrum.c index 65b42e575..1cf7d5ce6 100644 --- a/lib_com/interleave_spectrum.c +++ b/lib_com/interleave_spectrum.c @@ -142,8 +142,11 @@ void interleave_spectrum_fx( const Word16 *bw; const Word16 *cnt; + move16(); + move16(); + move16(); /* Common inits */ - p1 = coefs; + p1 = coefs; /*Q12*/ p_out = coefs_out; #ifdef SOLVED_COMP_ENC_DEC IF( EQ_16( length, L_SPEC48k ) ) @@ -151,8 +154,8 @@ void interleave_spectrum_fx( IF( EQ_16( length, L_FRAME48k ) ) #endif { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); p2 = p1 + sublen[0]; @@ -161,8 +164,8 @@ void interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); p2 = p1 + sublen[1]; @@ -171,8 +174,8 @@ void interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); p2 = p1 + sublen[2]; @@ -186,22 +189,22 @@ void interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p1++; + *p_out++ = *p1++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p2++; + *p_out++ = *p2++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p3++; + *p_out++ = *p3++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p4++; + *p_out++ = *p4++; /*Q12*/ move32(); } } @@ -231,13 +234,13 @@ void interleave_spectrum_ivas_fx( const Word16 *cnt; /* Common inits */ - p1 = coefs; + p1 = coefs; /*Q12*/ p_out = coefs_out; IF( EQ_16( length, L_SPEC48k ) ) { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); p2 = p1 + sublen[0]; @@ -246,8 +249,8 @@ void interleave_spectrum_ivas_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); p2 = p1 + sublen[1]; @@ -256,8 +259,8 @@ void interleave_spectrum_ivas_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); p2 = p1 + sublen[2]; @@ -271,22 +274,22 @@ void interleave_spectrum_ivas_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p1++; + *p_out++ = *p1++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p2++; + *p_out++ = *p2++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p3++; + *p_out++ = *p3++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p_out++ = *p4++; + *p_out++ = *p4++; /*Q12*/ move32(); } } @@ -389,6 +392,12 @@ void ivas_de_interleave_spectrum_fx( Word32 *p_in; Word32 coefs_out[L_FRAME48k]; Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 grps; Word16 l_frame; const Word16 *bw; @@ -400,8 +409,8 @@ void ivas_de_interleave_spectrum_fx( move16(); IF( EQ_16( length, L_SPEC48k ) ) { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); l_frame = L_FRAME48k; @@ -412,8 +421,8 @@ void ivas_de_interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_FRAME32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); @@ -423,8 +432,8 @@ void ivas_de_interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); @@ -434,7 +443,7 @@ void ivas_de_interleave_spectrum_fx( } set32_fx( coefs_out, 0, L_FRAME48k ); - p_in = coefs; + p_in = coefs; /*Q12*/ FOR( i = 0; i < grps; i++ ) { @@ -442,22 +451,22 @@ void ivas_de_interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p1++ = *p_in++; + *p1++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p2++ = *p_in++; + *p2++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p3++ = *p_in++; + *p3++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p4++ = *p_in++; + *p4++ = *p_in++; /*Q12*/ move32(); } } @@ -478,6 +487,12 @@ void de_interleave_spectrum_fx( Word32 *p_in; Word32 coefs_out[L_FRAME48k]; Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); Word16 grps; Word16 l_frame; const Word16 *bw; @@ -493,8 +508,8 @@ void de_interleave_spectrum_fx( IF( EQ_16( length, L_FRAME48k ) ) #endif { - bw = intl_bw_48; - cnt = intl_cnt_48; + bw = intl_bw_48; /*Q0*/ + cnt = intl_cnt_48; /*Q0*/ grps = N_INTL_GRP_48; move16(); #ifdef SOLVED_COMP_ENC_DEC @@ -507,8 +522,8 @@ void de_interleave_spectrum_fx( } ELSE IF( EQ_16( length, L_SPEC32k ) ) { - bw = intl_bw_32; - cnt = intl_cnt_32; + bw = intl_bw_32; /*Q0*/ + cnt = intl_cnt_32; /*Q0*/ grps = N_INTL_GRP_32; move16(); @@ -518,8 +533,8 @@ void de_interleave_spectrum_fx( } ELSE /* length == L_SPEC16k */ { - bw = intl_bw_16; - cnt = intl_cnt_16; + bw = intl_bw_16; /*Q0*/ + cnt = intl_cnt_16; /*Q0*/ grps = N_INTL_GRP_16; move16(); @@ -529,7 +544,7 @@ void de_interleave_spectrum_fx( } set32_fx( coefs_out, 0, L_FRAME48k ); - p_in = coefs; + p_in = coefs; /*Q12*/ FOR( i = 0; i < grps; i++ ) { @@ -537,22 +552,22 @@ void de_interleave_spectrum_fx( { FOR( k = 0; k < bw[i]; k++ ) { - *p1++ = *p_in++; + *p1++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p2++ = *p_in++; + *p2++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p3++ = *p_in++; + *p3++ = *p_in++; /*Q12*/ move32(); } FOR( k = 0; k < bw[i]; k++ ) { - *p4++ = *p_in++; + *p4++ = *p_in++; /*Q12*/ move32(); } } diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 7c0458fa2..348fc2ebe 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1654,7 +1654,7 @@ void ivas_hq_bit_allocation_fx( 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 *noise_level, /* o : HVQ noise level Q15 */ 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 */ diff --git a/lib_com/prot.h b/lib_com/prot.h index d15bb767d..803a0a757 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -827,6 +827,7 @@ int16_t lsp_convert_poly( const int16_t Opt_AMRWB /* i : flag for the AMR-WB IO mode */ ); /*! r: pulse position */ +#ifndef IVAS_FLOAT_FIXED int16_t findpulse( const int16_t L_frame, /* i : length of the frame */ const float res[], /* i : residual signal */ @@ -834,6 +835,7 @@ int16_t findpulse( const int16_t enc_dec, /* i : flag enc/dec, 0 - enc, 1 - dec */ int16_t *sign /* i/o: sign of the maximum */ ); +#endif void fft_rel( float x[], /* i/o: input/output vector */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3239613af..07e2aa779 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2128,28 +2128,29 @@ 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[], /* Q12 */ + const Word16 band_start[], /* Q0 */ + const Word16 band_end[], /* Q0 */ + const Word16 band_width[], /* Q0 */ + Word32 Ep_fx[], /* Q-6 */ + Word32 Rk_fx[], /* QRk (Q16) */ + const Word16 npulses[], /* Q0 */ + Word16 ni_seed, /* Q0 */ + const Word16 bands, /* Q0 */ + const Word16 ni_start_band, /* Q0 */ + const Word16 bw_low, /* Q0 */ + const Word16 bw_high, /* Q0 */ + const Word32 enerL_fx, /* Q0 */ + const Word32 enerH_fx, /* Q0 */ + Word32 last_ni_gain_fx[], /* Q17 */ + Word16 last_env_fx[], /* Q1 */ + Word16 *last_max_pos_pulse, /* Q0 */ + Word16 *p2a_flags, /* Q0 */ + Word16 p2a_bands, /* Q0 */ + const Word16 hqswb_clas, /* Q0 */ + const Word16 bwidth, /* Q0 */ + const Word32 bwe_br /* Q0 */ +); /*========================================================================================================/ hq2_bit_alloc_fx.c @@ -2262,25 +2263,26 @@ void mdct_spectrum_denorm_ivas_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, /* Q0 */ + const Word16 num_bits, /* Q0 */ + const Word16 is_transient, /* Q0 */ + Word16 *bands, /* Q0 */ + Word16 *length, /* Q0 */ + Word16 band_width[], /* Q0 */ + Word16 band_start[], /* Q0 */ + Word16 band_end[], /* Q0 */ + Word32 *L_qint, /* Q13 */ + Word16 *eref, /* Q10 */ + Word16 *bit_alloc_weight, /* Q13 */ + Word16 *gqlevs, /* Q0 */ + Word16 *Ngq, /* Q0 */ + Word16 *p2a_bands, /* Q0 */ + Word16 *p2a_th, /* Q11 */ + Word16 *pd_thresh, /* Q15 */ + Word16 *ld_slope, /* Q15 */ + Word16 *ni_coef, /* Q14 */ + Word32 L_bwe_br /* Q0 */ +); void reverse_transient_frame_energies_fx( Word32 L_band_energy[], /* o : Q14 : band energies */ @@ -2288,55 +2290,56 @@ 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 Q0*/ + const Word16 band_end[], /* i: End position of sub band Q0*/ + const Word16 prev_SWB_peak_pos[], /* i: Spectral peak Q0*/ + const Word16 BANDS, /* i: total number of bands Q0*/ + const Word32 L_bwe_br, /* i: bitrate information Q0*/ + Word16 new_band_start[], /* o: Starting position of new shorten sub band Q0*/ + Word16 new_band_end[], /* o: End position of new shorten sub band Q0*/ + Word16 new_band_width[] /* o: new sub band bandwidth Q0*/ ); 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 Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + const Word16 band_width[], /* i: band width of subband Q0*/ + Word16 org_band_start[], /* o: starting position of subband Q0*/ + Word16 org_band_end[], /* o: end position of subband Q0*/ + Word16 org_band_width[] /* o: band width of subband Q0*/ ); 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 Q0*/ + Word16 band_start[], /* i/o: starting position of subband Q0*/ + Word16 band_end[], /* i/o: end position of subband Q0*/ + Word16 band_width[], /* i/o: band width of subband Q0*/ + const Word16 org_band_start[], /* o: starting position of subband Q0*/ + const Word16 org_band_end[], /* o: end position of subband Q0*/ + const Word16 org_band_width[] /* o: band width of subband Q0*/ ); 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 Qx*/ + const Word16 bands, /* i: total number of bands Q0*/ + const Word16 band_start[], /* i: starting position of subband Q0*/ + const Word16 band_end[], /* i: end position of subband Q0*/ + Word16 prev_SWB_peak_pos_tmp[] /* o: spectral peaks Q0*/ ); 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, /* Q16 */ + Word32 *Rk_sort, /* Q16 */ + Word16 BANDS, /* Q0 */ + const Word16 *band_width, /* Q0 */ + Word16 *k_sort, /* Q0 */ + Word16 *k_num, /* Q0 */ + const Word16 *p2a_flags, /* Q0 */ + const Word16 p2a_bands, /* Q0 */ + const Word16 *last_bitalloc, /* Q0 */ + const Word16 input_frame /* Q0 */ +); // synth_filt_fix.c Word32 syn_kern_16( @@ -5372,19 +5375,19 @@ void fill_spectrum_fx( // 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 */ + 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 Q15 */ + 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_SWB_BWE Q0 */ ); // weight_fx.c @@ -7800,10 +7803,10 @@ Word16 hvq_pvq_bitalloc_fx( 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 *Rk, /* Q3 o : bit allocation for concatenated vector */ + Word16 *R, /* Q0 i/o: Global bit allocation */ + Word16 *sel_bands, /* Q0 o : Selected bands for encoding */ + Word16 *n_sel_bands /* Q0 o : No. of selected bands for encoding */ ); // hq_conf_fec_fx.c diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 9047d8338..648280d1e 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -8328,7 +8328,7 @@ const Word16 mean_isf_noise_amr_wb_fx[M] = { 478, 1100, 2213, 3267, 4219, 5222, 6198, 7240, 8229, 9153,10098, 11108, 12144, 13184,14165, 3803 -}; +};/*14Q1*1.28*/ /* ISF codebook - common 1st stage, 1st split (only in AMR-WB IO mode) */ /*------------------------------------------------------* @@ -17816,7 +17816,7 @@ const Word16 dico5_ns_28b_fx[] = 1109, 918, 1101, 503, 1039, 1286, 1220, 317, 1351, 1207, 1010, 326 -}; +}; /*1.28f Q1*/ const Word16 means_nb_31bits_ma_lsf[16] = { 861 /*336.3281f*1.28f Q1*/, 1360 /*531.2500f*1.28f Q1*/, 2270 /*886.7188f*1.28f Q1*/, 3243 /*1266.7969f*1.28f Q1*/, 4171 /*1629.2969f*1.28f Q1*/, 5052 /*1973.4375f*1.28f Q1*/, 6012 /*2348.4375f*1.28f Q1*/, 6776 /*2646.8750f*1.28f Q1*/, 7676 /*2998.4375f*1.28f Q1*/, 8428 /*3292.1875f*1.28f Q1*/, 9194 /*3591.4062f*1.28f Q1*/, 9744 /*3806.2500f*1.28f Q1*/, 10580 /*4132.8125f*1.28f Q1*/, 11911 /*4652.7344f*1.28f Q1*/, 13440 /*5250.0000f*1.28f Q1*/, 15061 /*5883.2031f*1.28f Q1*/ }; const Word16 means_wb_31bits_ma_lsf[16] = { 818 /*319.5312f*1.28f Q1*/, 1403 /*548.0469f*1.28f Q1*/, 2392 /*934.3750f*1.28f Q1*/, 3465 /*1353.5156f*1.28f Q1*/, 4429 /*1730.0781f*1.28f Q1*/, 5428 /*2120.3125f*1.28f Q1*/, 6414 /*2505.4688f*1.28f Q1*/, 7323 /*2860.5469f*1.28f Q1*/, 8304 /*3243.7500f*1.28f Q1*/, 9221 /*3601.9531f*1.28f Q1*/, 10162 /*3969.5312f*1.28f Q1*/, 11091 /*4332.4219f*1.28f Q1*/, 12125 /*4736.3281f*1.28f Q1*/, 13153 /*5137.8906f*1.28f Q1*/, 14241 /*5562.8906f*1.28f Q1*/, 15266 /*5963.2812f*1.28f Q1*/ }; @@ -28071,7 +28071,7 @@ const int16_t intl_cnt_16[N_INTL_GRP_16] = {4, 1}; const int16_t intl_cnt_32[N_INTL_GRP_32] = {4, 4}; const int16_t intl_cnt_48[N_INTL_GRP_48] = {4, 3, 2}; -const int16_t band_start_HQ[44] = +const Word16 band_start_HQ[44] = { 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, @@ -28079,7 +28079,7 @@ const int16_t band_start_HQ[44] = 544, 576, 608, 640, 672, 704, 736, 768 }; -const int16_t band_end_HQ[44] = +const Word16 band_end_HQ[44] = { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 144, 160, 176, 192, 208, 224, 240, 256, @@ -28087,7 +28087,7 @@ const int16_t band_end_HQ[44] = 576, 608, 640, 672, 704, 736, 768, 800 }; -const int16_t band_len_HQ[44] = +const Word16 band_len_HQ[44] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 993e213b3..ce044a4e6 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1066,15 +1066,15 @@ extern const Word16 wscw16q15_16_fx[]; extern const Word16 wscw16q15_32_fx[]; /* Band structure */ -extern const int16_t band_len_HQ[]; -extern const int16_t band_start_HQ[]; -extern const int16_t band_end_HQ[]; +extern const Word16 band_len_HQ[]; +extern const Word16 band_start_HQ[]; +extern const Word16 band_end_HQ[]; extern const int16_t band_len_wb[]; extern const int16_t band_start_wb[]; extern const int16_t band_end_wb[]; extern const int16_t band_len_harm_float[]; -extern const int16_t band_start_harm[]; -extern const int16_t band_end_harm[]; +extern const Word16 band_start_harm[]; +extern const Word16 band_end_harm[]; extern const float rat_flt[SFM_N_WB]; extern const Word16 rat_fx[SFM_N_WB]; extern const int16_t intl_bw_16[N_INTL_GRP_16]; diff --git a/lib_com/stat_noise_uv_mod.c b/lib_com/stat_noise_uv_mod.c index f9b10f501..2899052f3 100644 --- a/lib_com/stat_noise_uv_mod.c +++ b/lib_com/stat_noise_uv_mod.c @@ -40,6 +40,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local constants *---------------------------------------------------------------------*/ @@ -236,3 +237,4 @@ static float calc_tilt( return r1 / r0; } +#endif diff --git a/lib_com/swb_bwe_com_lr.c b/lib_com/swb_bwe_com_lr.c index 638e78db5..22d79f157 100644 --- a/lib_com/swb_bwe_com_lr.c +++ b/lib_com/swb_bwe_com_lr.c @@ -42,6 +42,7 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * hf_parinitiz() * @@ -2108,3 +2109,4 @@ void updat_prev_frm( return; } +#endif diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index a814ff029..d2a43ac55 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -217,8 +217,6 @@ ivas_error acelp_core_enc( } for ( int ii = 0; ii < M; ii++ ) { - st->mem_MA_fx[ii] = (Word16) ( ( st->mem_MA[ii] ) * 2.56f ); - st->mem_AR_fx[ii] = (Word16) ( ( st->mem_AR[ii] ) * 2.56f ); st->lsf_old_fx[ii] = (Word16) ( ( st->lsf_old[ii] ) * 2.56f ); } Word16 inp_buff[L_FRAME16k + M + 1]; @@ -448,8 +446,6 @@ ivas_error acelp_core_enc( for ( i = 0; i < M; i++ ) { st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; } fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); IF( st->hLPDmem ) @@ -508,7 +504,6 @@ ivas_error acelp_core_enc( floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ, st->hTdCngEnc->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arr( st->hTdCngEnc->ho_lsp_circ2, st->hTdCngEnc->ho_lsp_circ2_fx, Q15, HO_HIST_SIZE * M ); floatToFixed_arrL( st->hTdCngEnc->ho_ener_circ, st->hTdCngEnc->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); floatToFixed_arr( st->hTdCngEnc->exc_mem2, st->hTdCngEnc->exc_mem2_fx, q_inp, 30 ); for ( i = 0; i < M; i++ ) @@ -525,7 +520,6 @@ ivas_error acelp_core_enc( fixedToFloat_arrL32( q_env_fx, q_env, Q6, NUM_ENV_CNG ); fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, Q15, HO_HIST_SIZE * M ); fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, 160 ); fixedToFloat_arrL( st->hTdCngEnc->ho_ener_circ_fx, st->hTdCngEnc->ho_ener_circ, Q6, HO_HIST_SIZE ); fixedToFloat_arr( st->hTdCngEnc->exc_mem2_fx, st->hTdCngEnc->exc_mem2, q_inp, 30 ); @@ -767,7 +761,6 @@ ivas_error acelp_core_enc( IF( st->hLPDmem ) { st->hLPDmem->tilt_code = float_to_fix16( st->hLPDmem->tilt_code_flt, Q15 ); - st->hLPDmem->gc_threshold = float_to_fix16( st->hLPDmem->gc_threshold_flt, Q16 ); f2me_buf_16( &st->hLPDmem->mem_syn_flt[-1], &st->hLPDmem->mem_syn[-1], &st->hLPDmem->e_mem_syn, M + 1 ); // -1 to sync the exponent of mem_syn with mem_w0 } floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); @@ -780,11 +773,8 @@ ivas_error acelp_core_enc( st->clip_var_fx[5] = float_to_fix16( st->clip_var[5], Q14 ); FOR( Word16 idx = 0; idx < M; idx++ ) { - st->lsf_adaptive_mean_fx[idx] = (Word16) ( st->lsf_adaptive_mean[idx] * 2.56f ); IF( tdm_lsfQ_PCh ) tdm_lsfQ_PCh_fx[idx] = (Word16) ( tdm_lsfQ_PCh[idx] * 2.56f ); - st->lsfoldbfi1_fx[idx] = (Word16) ( st->lsfoldbfi1[idx] * 2.56f ); - st->lsfoldbfi0_fx[idx] = (Word16) ( st->lsfoldbfi0[idx] * 2.56f ); } Q_old_bwe_exc = Q_factor_arr( old_bwe_exc, 1380 ); floatToFixed_arr( old_bwe_exc, old_bwe_exc_fx, Q_old_bwe_exc, 1380 ); @@ -1016,11 +1006,6 @@ ivas_error acelp_core_enc( lsf_new[i] = lsf_new_fx[i] / 2.56f; st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f; - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; } fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, 128 ); fixedToFloat_arrL( st->Bin_E_fx, st->Bin_E, q_comm_Bin, 256 ); @@ -1128,7 +1113,6 @@ ivas_error acelp_core_enc( lsf_syn_mem_restore_ivas_fx( st, tilt_code_bck_fx, gc_threshold_bck_fx, clip_var_bck_fx, next_force_sf_bck, lsp_new_fx, lsp_mid_fx, clip_var_fx, mem_AR_fx, mem_MA_fx, lsp_new_bck_fx, lsp_mid_bck_fx, Bin_E_fx, Bin_E_old_fx, mem_syn_bck_fx, mem_w0_bck_fx, streaklimit_fx, pstreaklen ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS st->hLPDmem->tilt_code_flt = fix16_to_float( st->hLPDmem->tilt_code, Q15 ); - st->hLPDmem->gc_threshold_flt = fix_to_float( st->hLPDmem->gc_threshold, Q16 ); st->clip_var[0] = st->clip_var_fx[0] / 2.56f; st->clip_var[1] = fix16_to_float( st->clip_var_fx[1], Q14 ); st->clip_var[2] = fix16_to_float( st->clip_var_fx[2], Q7 ); @@ -1141,11 +1125,6 @@ ivas_error acelp_core_enc( fixedToFloat_arrL( st->Bin_E_old_fx, st->Bin_E_old, q_comm_Bin, L_FFT / 2 ); fixedToFloat_arr( st->hLPDmem->mem_syn, st->hLPDmem->mem_syn_flt, mem_syn, M ); st->hLPDmem->mem_w0_flt = me2f( st->hLPDmem->mem_w0, st->hLPDmem->e_mem_syn ); - for ( i = 0; i < M; i++ ) - { - st->mem_AR[i] = (float) st->mem_AR_fx[i] / 2.56f; - st->mem_MA[i] = (float) st->mem_MA_fx[i] / 2.56f; - } #endif #else lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); @@ -1268,13 +1247,10 @@ ivas_error acelp_core_enc( floatToFixed_arr( exc2, exc2_fx, Q_exc2, L_FRAME ); #endif floatToFixed_arr( Aq, Aq_fx, 12, NB_SUBFR16k * ( M + 1 ) ); - floatToFixed_arr( st->lspold_s, st->lspold_s_fx, 15, 16 ); - st->min_alpha_fx = float_to_fix16( st->min_alpha, 15 ); Word32 LepsP[2]; Word32 epsP_fx[M + 1]; Word16 e_epsP; f2me_buf( epsP, epsP_fx, &e_epsP, M + 1 ); - st->ge_sm_fx = float_to_fix( st->ge_sm, 6 ); st->exc_pe_fx = float_to_fix16( st->exc_pe, st->Q_stat_noise ); floatToFixed_arr( lsp_new, lsp_new_fx, 15, 16 ); floatToFixed_arr( lsp_mid, lsp_mid_fx, 15, 16 ); @@ -1289,9 +1265,6 @@ ivas_error acelp_core_enc( // conv params from fix to float fixedToFloat_arr( exc2_fx, exc2, Q_exc2, L_FRAME16k ); fixedToFloat_arr( Aq_fx, Aq, 12, NB_SUBFR16k * ( M + 1 ) ); - fixedToFloat_arr( st->lspold_s_fx, st->lspold_s, 15, 16 ); - st->min_alpha = fix16_to_float( st->min_alpha_fx, 15 ); - st->ge_sm = fix_to_float( st->ge_sm_fx, 6 ); st->exc_pe = fix16_to_float( st->exc_pe_fx, st->Q_stat_noise ); #endif #endif @@ -1498,11 +1471,22 @@ ivas_error acelp_core_enc( cng_params_upd( lsp_new, exc, st->L_frame, &st->hTdCngEnc->ho_circ_ptr, st->hTdCngEnc->ho_ener_circ, &st->hTdCngEnc->ho_circ_size, st->hTdCngEnc->ho_lsp_circ, ENC, st->hTdCngEnc->ho_env_circ, &st->hTdCngEnc->cng_buf_cnt, st->hTdCngEnc->cng_exc2_buf_flt, st->hTdCngEnc->cng_brate_buf, st->hDtxEnc->last_active_brate, st->element_mode, st->hFdCngEnc->hFdCngCom->CngBandwidth ); +#ifndef IVAS_FLOAT_FIXED if ( st->L_frame == L_FRAME ) { /* store LSPs@16k, potentially to be used in CNG@16k */ mvr2r( st->lsp_old16k, &( st->hTdCngEnc->ho_lsp_circ2[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); } +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old16k, st->lsp_old16k_fx, Q15, M ); +#endif + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + /* store LSPs@16k, potentially to be used in CNG@16k */ + Copy( st->lsp_old16k_fx, &( st->hTdCngEnc->ho_lsp_circ2_fx[( st->hTdCngEnc->ho_circ_ptr ) * M] ), M ); + } +#endif /* set LSP@16k flag for the first buffer */ st->hTdCngEnc->ho_16k_lsp[st->hTdCngEnc->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c index 768ccf004..465df84a2 100644 --- a/lib_enc/acelp_core_switch_enc.c +++ b/lib_enc/acelp_core_switch_enc.c @@ -43,6 +43,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -460,3 +461,4 @@ static void bwe_switch_enc( return; } +#endif diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index 633675002..add6c9675 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -424,8 +424,13 @@ void init_coder_ace_plus( st->next_force_safety_net = 0; if ( ( st->last_L_frame != st->L_frame ) || ( st->last_core == AMR_WB_CORE ) || ( st->last_core == HQ_CORE ) ) { +#ifndef IVAS_FLOAT_FIXED set_f( st->mem_MA, 0.0f, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); +#else + set16_fx( st->mem_MA_fx, 0, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); +#endif } /* Initialize IGF */ @@ -1372,7 +1377,11 @@ static void init_acelp( if ( hLPDmem != NULL ) { set_zero( hLPDmem->dispMem_flt, 8 ); +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif } /* Pulse Search configuration */ diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index f6c196b42..6397c2d4c 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -220,12 +220,6 @@ void core_coder_mode_switch_ivas_fx( st->currEnergyHF = 0; - 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 ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - /* Initialize TCX */ IF( hTcxEnc != NULL ) { diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index fe6837e7a..029bdb8bb 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -213,13 +213,22 @@ void core_switching_pre_enc( set_f( hLPDmem->mem_syn1_flt, 0.0f, M ); hLPDmem->mem_w0_flt = 0.0f; hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); } st->Nb_ACELP_frames = 0; +#ifndef IVAS_FLOAT_FIXED set_zero( st->mem_MA, M ); mvr2r( GEWB_Ave, st->mem_AR, M ); +#else + set16_fx( st->mem_MA_fx, 0, M ); + Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); +#endif init_gp_clip( st->clip_var ); st->last_coder_type = GENERIC; @@ -261,7 +270,11 @@ void core_switching_pre_enc( hLPDmem->mem_w0_flt = 0.0f; hLPDmem->tilt_code_flt = 0.0f; init_gp_clip( st->clip_var ); +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); } @@ -898,7 +911,11 @@ void core_switching_post_enc( if ( ( st->extl == SWB_TBE || st->extl == FB_TBE ) && ( st->last_core == HQ_CORE || 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 ) ) ) { +#ifdef IVAS_FLOAT_FIXED + set16_fx( st->hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#else set_f( st->hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif #ifdef IVAS_FLOAT_FIXED InitSWBencBufferStates_fx( st->hBWE_TD, NULL ); swb_tbe_reset_fx( st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->state_syn_shbexc_fx, &( st->hBWE_TD->tbe_demph_fx ), &( st->hBWE_TD->tbe_premph_fx ), st->hBWE_TD->mem_stp_swb_fx, &( st->hBWE_TD->gain_prec_swb_fx ) ); diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 317f59eae..6345a1c63 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -678,10 +678,11 @@ void HQ_core_enc_init( hHQ_core->prev_stab_hfe2 = 0; #ifndef IVAS_FLOAT_FIXED hHQ_core->prev_ni_ratio = 0.5f; + set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); #else hHQ_core->prev_ni_ratio_fx = 16384; + set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); #endif - set_f( hHQ_core->prev_En_sb, 0.0f, NB_SWB_SUBBANDS ); set_s( hHQ_core->last_bitalloc_max_band, 0, 2 ); #ifndef IVAS_FLOAT_FIXED set_f( hHQ_core->last_ni_gain, 0, BANDS_MAX ); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index a2ec04bba..bc926b32d 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -209,7 +209,7 @@ static Word16 IGF_getCrest_new_fx( move16(); return crest; } -#endif +#else static float IGF_getCrest_new( const int16_t *logSpec, /* i : power spectrum */ const int16_t start, /* i : start subband index */ @@ -242,6 +242,7 @@ static float IGF_getCrest_new( return crest; } +#endif /*-------------------------------------------------------------------* @@ -305,7 +306,7 @@ static Word16 IGF_getSFM_new_fx( return sfm; } -#endif +#else static float IGF_getSFM_new( const float *powerSpectrum, /* i : power spectrum */ const int16_t *logSpec, /* i : log of power spectrum */ @@ -343,6 +344,7 @@ static float IGF_getSFM_new( return sfm; } +#endif /*-------------------------------------------------------------------* @@ -546,7 +548,7 @@ static Word32 IGF_getTNR_fx( return tonalToNoise; } -#endif // IVAS_FLOAT_FIXED +#else static float IGF_getTNR( const float *powerSpectrum, /* i : energies */ const int16_t start, /* i : start subband index */ @@ -589,8 +591,10 @@ static float IGF_getTNR( return tonalToNoise; } +#endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_getCrest() * @@ -675,6 +679,7 @@ static float IGF_getSFM_ivas( return sfm; } +#endif /*-------------------------------------------------------------------* @@ -1991,6 +1996,7 @@ static void IGF_CalculateStereoEnvelope_fx( return; } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_CalculateStereoEnvelope() * @@ -2232,6 +2238,7 @@ static void IGF_CalculateStereoEnvelope( return; } +#endif /*-------------------------------------------------------------------* @@ -2384,6 +2391,7 @@ static int16_t IGF_WriteEnvelope( #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * IGF_ErodeSpectrum() * @@ -2513,6 +2521,7 @@ static float IGF_ErodeSpectrum_ivas( return highPassEner; } +#endif /*-------------------------------------------------------------------* @@ -2968,6 +2977,7 @@ static void IGF_Whitening_ivas_fx( } #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED static void IGF_Whitening( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : | instance handle of IGF Encoder */ float *powerSpectrum, /* i : Q31 | MDCT/MDST power spectrum */ @@ -3310,6 +3320,7 @@ static void IGF_Whitening( return; } +#endif /*-------------------------------------------------------------------* @@ -4282,6 +4293,7 @@ void IGFEncApplyMono( * * apply the IGF encoder, main encoder interface *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED void IGFEncApplyStereo_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ @@ -4372,8 +4384,7 @@ void IGFEncApplyStereo_fx( } return; } -#endif // IVAS_FLOAT_FIXED - +#else void IGFEncApplyStereo( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ int16_t ms_mask[2][MAX_SFB], /* i : bandwise MS mask */ @@ -4450,6 +4461,7 @@ void IGFEncApplyStereo( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 6e051302f..98f4a3df5 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -143,20 +143,28 @@ ivas_error init_encoder( * Pre-processing and ACELP core parameters *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED mvr2r( GEWB_Ave, st->mem_AR, M ); mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); +#else + 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 ); +#endif st->next_force_safety_net = 0; st->pstreaklen = 0; #ifndef IVAS_FLOAT_FIXED st->streaklimit = 1.0f; + set_f( st->mem_MA, 0, M ); #else st->streaklimit_fx = 32767; + set16_fx( st->mem_MA_fx, 0, M ); #endif - set_f( st->mem_MA, 0, M ); init_gp_clip( st->clip_var ); pitch_ol_init( @@ -195,9 +203,10 @@ ivas_error init_encoder( set_f( st->mem_decim2, 0, 3 ); set_f( st->Bin_E, 0, L_FFT ); +#ifndef IVAS_FLOAT_FIXED st->ee_old = 10.0f; -#ifdef IVAS_FLOAT_FIXED - st->ee_old_fx = 10 << 6; // 10 in Q6 +#else + st->ee_old_fx = 640; #endif st->Nb_ACELP_frames = 0; st->audio_frame_cnt = AUDIO_COUNTER_INI; /* Initialization of the audio frame counter mildly into the audio mode */ @@ -250,12 +259,17 @@ ivas_error init_encoder( st->tc_cnt = 0; /* find_uv() parameters */ +#ifndef IVAS_FLOAT_FIXED st->old_dE1 = 0.0f; -#ifdef IVAS_FLOAT_FIXED +#else st->old_dE1_fx = 0; #endif st->old_ind_deltaMax = 0; +#ifndef IVAS_FLOAT_FIXED set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); +#else + set32_fx( st->old_enr_ssf_fx, 0, 2 * NB_SSF ); +#endif st->spike_hyst = -1; /* stereo switching memories */ @@ -271,12 +285,27 @@ ivas_error init_encoder( st->sharpFlag = 0; #endif /* Stationary noise UV modification */ +#ifndef IVAS_FLOAT_FIXED st->ge_sm = 10; +#else + st->ge_sm_fx = L_deposit_l( 640 ); +#endif st->uv_count = 0; st->act_count = 3; +#ifndef IVAS_FLOAT_FIXED mvr2r( st->lsp_old, st->lspold_s, M ); +#else +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); +#endif + Copy( st->lsp_old_fx, st->lspold_s_fx, M ); +#endif st->noimix_seed = RANDOM_INITSEED; +#ifndef IVAS_FLOAT_FIXED st->min_alpha = 1; +#else + st->min_alpha_fx = 32767; +#endif st->exc_pe = 0; #ifdef IVAS_FLOAT_FIXED st->exc_pe_fx = 0; @@ -1230,12 +1259,7 @@ ivas_error init_encoder_ivas_fx( Copy( GEWB_Ave_fx, st->lsfoldbfi1_fx, M ); Copy( GEWB_Ave_fx, st->lsf_adaptive_mean_fx, M ); #if 1 // TODO: Float Initializations. To be removed later - mvr2r( GEWB_Ave, st->mem_AR, M ); - mvr2r( GEWB_Ave, st->lsfoldbfi0, M ); - mvr2r( GEWB_Ave, st->lsfoldbfi1, M ); - mvr2r( GEWB_Ave, st->lsf_adaptive_mean, M ); init_gp_clip( st->clip_var ); - set_zero( st->mem_MA, M ); pitch_ol_init( #ifndef IVAS_FLOAT_FIXED &st->old_thres, @@ -1278,8 +1302,6 @@ ivas_error init_encoder_ivas_fx( st->mem_wsp = 0.0f; set_f( st->mem_decim2, 0, 3 ); set_f( st->Bin_E, 0, L_FFT ); - st->ee_old = 10.0f; - st->old_dE1 = 0.0f; if ( st->Opt_AMR_WB ) { mvr2r( mean_isf_amr_wb, st->lsf_old, M ); @@ -1294,12 +1316,10 @@ ivas_error init_encoder_ivas_fx( mvr2r( st->lsp_old1, st->lsp_old, M ); mvr2r( st->lsp_old, st->lsp_old16k, M ); mvr2r( st->lsp_old, st->lspold_enc, M ); - set_f( st->old_enr_ssf, 0.0f, 2 * NB_SSF ); st->mem_preemph_DFT = 0.0f; set_f( st->inp_12k8_mem_stereo_sw, 0, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); st->mem_preemph16k_DFT = 0.0f; set_f( st->inp_16k_mem_stereo_sw, 0, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - mvr2r( st->lsp_old, st->lspold_s, M ); set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 4096; st->voicing0_sm = 0; @@ -1317,7 +1337,6 @@ ivas_error init_encoder_ivas_fx( st->EnergyLT = 0.0f; st->Energy_Old = 0; #endif - st->min_alpha = 1; #ifndef IVAS_FLOAT_FIXED st->prev_fmerit_flt = 0; st->fmerit_dt_flt = 0; @@ -1350,7 +1369,7 @@ ivas_error init_encoder_ivas_fx( 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->ee_old_fx = 640; /* 10.0f in Q6 */ move16(); st->Nb_ACELP_frames = 0; move16(); @@ -1430,9 +1449,7 @@ ivas_error init_encoder_ivas_fx( st->sharpFlag = 0; /* Stationary noise UV modification */ - st->ge_sm_fx = 10; /*chk //10 in Q6 */ - move16(); - st->ge_sm = 10; /*chk //10 in Q6 */ + st->ge_sm_fx = L_deposit_l( 640 ); /*Q(GE_SHIFT)*/ move16(); st->uv_count = 0; move16(); @@ -2248,12 +2265,6 @@ ivas_error init_encoder_ivas_fx( st->currEnergyHF = 0; - 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 ) ) ) - { - set_f( st->mem_MA, 0.0f, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - /* Initialize TCX */ IF( hTcxEnc != NULL ) { @@ -2416,7 +2427,11 @@ void LPDmem_enc_init( set_f( hLPDmem->mem_syn3_flt, 0, M ); hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED hLPDmem->gc_threshold_flt = 0.0f; +#else + hLPDmem->gc_threshold = 0; +#endif set_f( hLPDmem->dispMem_flt, 0, 8 ); return; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 20ac14fb6..32ea92422 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -489,7 +489,6 @@ ivas_error ivas_core_enc( fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ_fx, st->hTdCngEnc->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); fixedToFloat_arrL( st->hTdCngEnc->ho_env_circ_fx, st->hTdCngEnc->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); // fixedToFloat_arr( st->hTdCngEnc->cng_exc2_buf, st->hTdCngEnc->cng_exc2_buf_flt, Q_exc, HO_HIST_SIZE * L_FFT ); - fixedToFloat_arr( st->hTdCngEnc->ho_lsp_circ2_fx, st->hTdCngEnc->ho_lsp_circ2, M, Q15 ); } st->hTcxEnc->measuredBwRatio_flt = fix16_to_float( st->hTcxEnc->measuredBwRatio, Q14 ); @@ -507,9 +506,6 @@ ivas_error ivas_core_enc( for ( int j = 0; j < M; j++ ) { st->lsf_old[j] = (float) st->lsf_old_fx[j] / 2.56f; - st->lsf_adaptive_mean[j] = (float) st->lsf_adaptive_mean_fx[j] / 2.56f; - st->mem_AR[j] = (float) st->mem_AR_fx[j] / 2.56f; - st->mem_MA[j] = (float) st->mem_MA_fx[j] / 2.56f; } for ( int k = 0; k < 2; k++ ) { @@ -1423,12 +1419,6 @@ ivas_error ivas_core_enc( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - 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 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) - { - set_zero( st->mem_MA, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index b84e82262..1a6970133 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -2383,9 +2383,6 @@ ivas_error pre_proc_front_ivas_fx( } st->hNoiseEst->Etot_last_fx = float_to_fix16( st->hNoiseEst->Etot_last, Q8 ); - - floatToFixed_arr32( st->old_enr_ssf, st->old_enr_ssf_fx, 0, 2 * NB_SSF ); - #endif // IVAS_FLOAT_FIXED_CONVERSIONS /* Detection of very short stable pitch period */ @@ -2473,8 +2470,6 @@ ivas_error pre_proc_front_ivas_fx( fixedToFloat_arrL32( ee_fx, ee, Q6, 2 ); fixedToFloat_arrL32( hp_E_fx, hp_E, q_fr_bands, 2 ); - fixedToFloat_arrL32( st->old_enr_ssf_fx, st->old_enr_ssf, 0, 2 * NB_SSF ); - non_staX = fixedToFloat_16( non_staX16_fx, Q8 ); sp_div = fixedToFloat_16( sp_div16_fx, q_sp_div ); *cor_map_sum = fixedToFloat_16( cor_map_sum16_fx, Q8 ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 46fc42291..2b8930a55 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -733,9 +733,6 @@ ivas_error ivas_cpe_enc( sts[0]->old_corr_fx = float_to_fix16( sts[0]->old_corr, Q15 ); sts[1]->old_corr_fx = float_to_fix16( sts[1]->old_corr, Q15 ); - sts[0]->ee_old_fx = floatToFixed( sts[0]->ee_old, Q6 ); - sts[1]->ee_old_fx = floatToFixed( sts[1]->ee_old, Q6 ); - IF( hCPE->hStereoTD->tdm_last_SM_flag ) { floatToFixed_arr16( sts[0]->input, sts[0]->input_fx, 0, input_frame ); diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 45a008543..5dc8c4f61 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -1842,6 +1842,8 @@ void ivas_dirac_param_est_enc( /* Sectors */ IF( hodirac_flag ) { + Word32 L_tmp, L_tmp1; + Word16 e_tmp, e_tmp1, exp_diff; FOR( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) { q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx] = L_shr( azi_secs_fx[band_m_idx], 1 ); // Q23 -> Q22 @@ -1854,20 +1856,21 @@ void ivas_dirac_param_est_enc( q_direction[1].band_data[band_m_idx].elevation_fx[block_m_idx] = L_shr( ele_secs_fx[num_freq_bands + band_m_idx], 1 ); // Q23 -> Q22 move32(); - Word32 x = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[band_m_idx], sub( 1, diff_secs_exp[band_m_idx] ) ) ); - Word32 y = L_sub( ONE_IN_Q30, L_shr( diff_secs_fx[num_freq_bands + band_m_idx], sub( 1, diff_secs_exp[num_freq_bands + band_m_idx] ) ) ); - - Word16 tmp16 = extract_h( L_add( x, y ) ); - Word32 tmp32; - IF( tmp16 == 0 ) + L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[band_m_idx] ), diff_secs_exp[band_m_idx], &e_tmp ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, Q1, L_negate( diff_secs_fx[num_freq_bands + band_m_idx] ), diff_secs_exp[num_freq_bands + band_m_idx], &e_tmp1 ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp, e_tmp, L_tmp1, e_tmp1, &e_tmp1 ); + IF( L_tmp1 == 0 ) { - tmp32 = L_deposit_h( div_l( x, EPSILON_FX ) ); + q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( div_l( L_tmp, EPSILON_FX ), Q30 - Q15 ); // Q30 + move32(); } ELSE { - tmp32 = L_deposit_h( div_l( x, tmp16 ) ); + L_tmp = L_deposit_h( BASOP_Util_Divide3232_Scale( L_tmp, L_add( L_tmp1, EPSILON_FX ), &exp_diff ) ); + exp_diff = add( exp_diff, sub( e_tmp, e_tmp1 ) ); + q_direction[1].band_data[band_m_idx].energy_ratio_fx[block_m_idx] = L_shl( L_tmp, sub( exp_diff, Q1 ) ); // Q30 + move32(); } - tmp32 = L_shr( tmp32, 1 ); // Q31 -> Q30 } } } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 63354efd4..4c27158a0 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -551,7 +551,7 @@ ivas_error ivas_masa_encode_fx( ivas_error error; Word16 guard_bits, tmp; - guard_bits = find_guarded_bits_fx( 24 ); + guard_bits = find_guarded_bits_fx( 9 ); masa_sid_descriptor = -1; h_orig_metadata = NULL; @@ -2381,6 +2381,9 @@ static void combine_freqbands_and_subframes_fx( Word32 x[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 y[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 z[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 x_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 y_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 z_e[MASA_MAXIMUM_DIRECTIONS][MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 vecLen; Word16 vecLen_e; Word32 xSum, ySum, zSum; @@ -2468,12 +2471,27 @@ static void combine_freqbands_and_subframes_fx( eleRad = extract_l( L_shl( Mpy_32_32( hMeta->directional_meta[i].elevation_fx[j][k], PI_OVER_180_FX ), Q13 - Q22 ) ); // ((Q22, Q31) -> Q22) >> Q9 -> Q13 vecLen = Mpy_32_32( hMeta->directional_meta[i].energy_ratio_fx[j][k], hMasa->data.energy_fx[j][k] ); // (Q30, 31-hMasa->data.energy_e[j][k]) -> (31-hMasa->data.energy_e[j][k]) - Q1 - x[i][j][k] = Mpy_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + /* Need more precision for some DTX cases with low energy frames */ + W_tmp = W_mult0_32_32( L_mult( getCosWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + x[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); - y[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + x_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); + + W_tmp = W_mult0_32_32( L_mult0( getSinWord16( aziRad ), getCosWord16( eleRad ) ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + y[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); - z[i][j][k] = Mpy_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (31-hMasa->data.energy_e[j][k]) - Q3 + y_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); + + W_tmp = W_mult0_32_32( L_mult0( getSinWord16( eleRad ), ONE_IN_Q14 ), vecLen ); // (Q29, (31-hMasa->data.energy_e[j][k]) - Q1) -> (Q59 - hMasa->data.energy_e[j][k]) + q_shift = W_norm( W_tmp ); + z[i][j][k] = W_extract_h( W_shl( W_tmp, q_shift ) ); move32(); + z_e[i][j][k] = sub( Q31, add( sub( 59, hMasa->data.energy_e[j][k] ), sub( q_shift, 32 ) ) ); + move16(); } } } @@ -2512,9 +2530,9 @@ static void combine_freqbands_and_subframes_fx( FOR( m = brange[0]; m < brange[1]; m++ ) { - xSum = BASOP_Util_Add_Mant32Exp( xSum, xSum_e, x[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &xSum_e ); // xSum_e - ySum = BASOP_Util_Add_Mant32Exp( ySum, ySum_e, y[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &ySum_e ); // ySum_e - zSum = BASOP_Util_Add_Mant32Exp( zSum, zSum_e, z[i][j][m], add( hMasa->data.energy_e[j][m], 3 ), &zSum_e ); // zSum_e + xSum = BASOP_Util_Add_Mant32Exp( xSum, xSum_e, x[i][j][m], x_e[i][j][m], &xSum_e ); // xSum_e + ySum = BASOP_Util_Add_Mant32Exp( ySum, ySum_e, y[i][j][m], y_e[i][j][m], &ySum_e ); // ySum_e + zSum = BASOP_Util_Add_Mant32Exp( zSum, zSum_e, z[i][j][m], z_e[i][j][m], &zSum_e ); // zSum_e energySum = BASOP_Util_Add_Mant32Exp( energySum, energySum_e, hMasa->data.energy_fx[j][m], hMasa->data.energy_e[j][m], &energySum_e ); // energySum_e } common_e = add( s_max( xSum_e, s_max( ySum_e, zSum_e ) ), 2 ); /*2 is guard bit for addition operations*/ @@ -2563,7 +2581,8 @@ static void combine_freqbands_and_subframes_fx( hMeta->directional_meta[i].spread_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( spreadCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+spreadCohSum_e-energySum_e*/ exp_diff = add( exp_diff, sub( spreadCohSum_e, energySum_e ) ); move16(); - hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 + /* Saturation - LTV fix for values close to 1.0f+ */ + hMeta->directional_meta[i].spread_coherence_fx[j][k] = shl_sat( hMeta->directional_meta[i].spread_coherence_fx[j][k], exp_diff ); // Q15 move16(); IF( i == 0 ) @@ -2579,7 +2598,8 @@ static void combine_freqbands_and_subframes_fx( hMeta->common_meta.surround_coherence_fx[j][k] = BASOP_Util_Divide3232_Scale( surrCohSum, L_add( energySum, EPSILON_FX ), &exp_diff ); /*exp_diff+surrCohSum_e-energySum_e*/ move16(); exp_diff = add( exp_diff, sub( surrCohSum_e, energySum_e ) ); - hMeta->common_meta.surround_coherence_fx[j][k] = shl( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 + /* Saturation - LTV fix for values close to 1.0f+ */ + hMeta->common_meta.surround_coherence_fx[j][k] = shl_sat( hMeta->common_meta.surround_coherence_fx[j][k], exp_diff ); // Q15 move16(); } } @@ -2882,11 +2902,8 @@ void ivas_masa_combine_directions_fx( Word16 exp_sumVecLen_buff[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], exp_sumVecLen = MIN16B_FLT_FX; move16(); Word32 tempImportance_fx; - Word16 exp_tmp_importance = 0; - move16(); Word32 importance_fx[MASA_FREQUENCY_BANDS]; - Word16 exp_importance_buff[MASA_FREQUENCY_BANDS], exp_importance = MIN16B_FLT_FX; - move16(); + Word16 exp_importance; Word16 indicesOfLargest[MASA_FREQUENCY_BANDS]; Word32 ratioSum_fx; @@ -3004,41 +3021,29 @@ void ivas_masa_combine_directions_fx( } /* Estimate the importance of having two directions instead of one */ + /* Reduced precision of importance_fx intentionally to Q13 to maintatin 0.0001f resolution */ FOR( i = 0; i < numCodingBands; i++ ) { importance_fx[i] = 0; move32(); FOR( j = 0; j < numSf; j++ ) { - tempImportance_fx = L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ); - exp_tmp_importance = 0; - move16(); - tempImportance_fx = BASOP_Util_Add_Mant32Exp( tempImportance_fx, 31 - Q30, L_negate( sumVecLen_fx[j][i] ), exp_sumVecLen, &exp_tmp_importance ); - importance_fx[i] = BASOP_Util_Add_Mant32Exp( importance_fx[i], exp_importance_buff[i], tempImportance_fx, exp_tmp_importance, &exp_importance_buff[i] ); + tempImportance_fx = L_shr( L_add( hMeta->directional_meta[0].energy_ratio_fx[j][i], hMeta->directional_meta[1].energy_ratio_fx[j][i] ), Q30 - Q13 ); // Q13 + tempImportance_fx = L_sub( tempImportance_fx, L_shr( sumVecLen_fx[j][i], sub( sub( Q31, exp_sumVecLen ), Q13 ) ) ); // Q13 + importance_fx[i] = L_add( importance_fx[i], tempImportance_fx ); // Q13 move32(); } IF( NE_16( numSf, 1 ) ) { - importance_fx[i] = L_shr( importance_fx[i], 2 ); + importance_fx[i] = L_shr( importance_fx[i], 2 ); // Q13 move32(); } - importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); - move32(); - exp_importance_buff[i] = add( exp_importance_buff[i], 1 ); - move16(); - } - - /*make commen exp for importance_fx buffer*/ - FOR( i = 0; i < numCodingBands; i++ ) - { - exp_importance = s_max( exp_importance_buff[i], exp_importance ); - } - FOR( i = 0; i < numCodingBands; i++ ) - { - importance_fx[i] = L_shr( importance_fx[i], sub( exp_importance, exp_importance_buff[i] ) ); + importance_fx[i] = Mpy_32_32( importance_fx[i], hMasa->data.importanceWeight_fx[i] ); //(Q13, Q30) -> Q12 move32(); } + exp_importance = Q31 - Q12; + move16(); /* Determine bands where to use two directions */ find_n_largest_fx( importance_fx, exp_importance, indicesOfLargest, numCodingBands, hMasa->config.numTwoDirBands ); @@ -5996,8 +6001,8 @@ static void masa_metadata_direction_alignment_fx( FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ ) { UWord8 sf; - Word16 diff_swap_fx; - Word16 diff_no_swap_fx; + Word32 diff_swap_fx; + Word32 diff_no_swap_fx; /* trade 2*(cos+sin) against storing the values between frames */ Word16 prev_ele_dir1_sin_fx, prev_ele_dir2_sin_fx; @@ -6041,7 +6046,9 @@ static void masa_metadata_direction_alignment_fx( LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir2_fx[band] ) ), EPSILON_FX ) ) { diff_swap_fx = ONE_IN_Q13; /*1 q13*/ + move32(); diff_no_swap_fx = 0; + move32(); /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ sin_ele1_fx = prev_ele_dir1_sin_fx; /*q15*/ sin_ele2_fx = prev_ele_dir2_sin_fx; /*q15*/ @@ -6051,8 +6058,6 @@ static void masa_metadata_direction_alignment_fx( move16(); move16(); move16(); - move16(); - move16(); } ELSE IF( LT_32( L_abs( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ) ), EPSILON_FX ) && LT_32( L_abs( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ) ), EPSILON_FX ) && @@ -6060,7 +6065,9 @@ static void masa_metadata_direction_alignment_fx( LT_32( L_abs( L_sub( ele_rad2_fx, hAlignState->previous_ele_dir1_fx[band] ) ), EPSILON_FX ) ) { diff_swap_fx = 0; + move32(); diff_no_swap_fx = ONE_IN_Q13; /*1.0 q13*/ + move32(); /* cached values that will be used for the short-cuts and over-written by the real computations, if done */ sin_ele1_fx = prev_ele_dir2_sin_fx; /*q15*/ sin_ele2_fx = prev_ele_dir1_sin_fx; /*q15*/ @@ -6070,8 +6077,6 @@ static void masa_metadata_direction_alignment_fx( move16(); move16(); move16(); - move16(); - move16(); } ELSE { @@ -6089,8 +6094,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = temp1; /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = L_deposit_l( temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ @@ -6098,8 +6103,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_no_swap_fx = add( diff_no_swap_fx, temp1 ); /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_no_swap_fx = L_add( diff_no_swap_fx, temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad1_fx, hAlignState->previous_azi_dir2_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele1_fx ) /*q31*/, prev_ele_dir2_cos_fx /*q15*/ ); /*q15*/ @@ -6107,8 +6112,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = temp1; /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = L_deposit_l( temp1 ); /*q13*/ temp1 = getCosWord16R2( extract_l( Mpy_32_32( L_sub( azi_rad2_fx, hAlignState->previous_azi_dir1_fx[band] ), 2670177 /*2^24/(2*pi)*/ ) ) ); /*q15*/ temp1 = mult( mult( temp1, cos_ele2_fx ) /*q31*/, prev_ele_dir1_cos_fx /*q15*/ ); /*q15*/ @@ -6116,8 +6121,8 @@ static void masa_metadata_direction_alignment_fx( temp1_e = 1; /*stores expoenent for square root operation*/ move16(); temp2 = Sqrt32( L_sub( ONE_IN_Q30, L_mult0( temp1, temp1 ) ), &temp1_e ); /*31-temp1_e*/ - temp1 = BASOP_util_atan2( temp2, abs_s( temp1 ), sub( temp1_e, 16 ) ); /*q13*/ - diff_swap_fx = add( diff_swap_fx, temp1 ); /*q13*/ + temp1 = BASOP_util_atan2( temp2, temp1, sub( temp1_e, 16 ) ); /*q13*/ + diff_swap_fx = L_add( diff_swap_fx, temp1 ); /*q13*/ } } ELSE @@ -6138,12 +6143,12 @@ static void masa_metadata_direction_alignment_fx( diff_swap_fx = ONE_IN_Q13; /*1.0 in Q13*/ diff_no_swap_fx = 0; - move16(); - move16(); + move32(); + move32(); } test(); - IF( GT_16( n_dirs, 1 ) && GT_16( diff_no_swap_fx, diff_swap_fx ) ) + IF( GT_16( n_dirs, 1 ) && GT_32( diff_no_swap_fx, diff_swap_fx ) ) { /* swap the metadata of the two directions in this TF-tile */ Word32 tmp_val; diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 472043f02..07379e99c 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -779,12 +779,6 @@ ivas_error ivas_mct_enc( me2f_buf_16( st->hTcxEnc->buf_speech_ltp, st->hTcxEnc->exp_buf_speech_ltp, st->hTcxEnc->buf_speech_ltp_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k ); } - 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 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) - { - set_zero( st->mem_MA, M ); - mvr2r( GEWB_Ave, st->mem_AR, M ); - } - IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL ) { st->hTcxEnc->tcxltp_norm_corr_mem_flt = fixedToFloat( st->hTcxEnc->tcxltp_norm_corr_mem, 15 ); diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index f34ae9ef0..f77bce2a8 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -1621,7 +1621,7 @@ void ivas_qmetadata_enc_sid_encode_fx( const Word16 ivas_format /* i : IVAS format */ ) { - Word16 b, m, i; + Word16 b, m; Word16 bit_pos_start; IVAS_QDIRECTION *q_direction; Word16 nbands, nblocks, start_band; @@ -1823,14 +1823,11 @@ void ivas_qmetadata_enc_sid_encode_fx( { /*compute the average direction */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - FOR( i = 0; i < 3; i++ ) - { - avg_direction_vector_fx[i] = L_add( avg_direction_vector_fx[i], L_shr( direction_vector_fx[i], 1 ) ); - move32(); - } + scale_sig32( direction_vector_fx, 3, Q22 - Q30 ); // Q30 -> Q22 + v_add_fixed( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3, 0 ); // Q22 } - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q22, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); /* Quantize the average direction */ IF( q_direction->not_in_2D == 0 ) @@ -2549,7 +2546,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { test(); - IF( EQ_16( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) + IF( EQ_32( hQMetaData->no_directions, 2 ) && EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { Word32 diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; /* Q30 */ Word32 dirRatio1, dirRatio2, sumRatio; /* Q30 */ @@ -2562,27 +2559,28 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { /* already encoded as total and ratios in HO-DirAC */ - diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); - dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; - move32(); + diffRatio = L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ); // Q30 + dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; // Q30 move32(); } ELSE { - dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; - dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; + dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0]; // Q30 move32(); + dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0]; // Q30 move32(); - sumRatio = L_add( dirRatio1, dirRatio2 ); - diffRatio = L_sub( ONE_IN_Q30, sumRatio ); + sumRatio = L_add( dirRatio1, dirRatio2 ); // Q30 + diffRatio = L_sub( ONE_IN_Q30, sumRatio ); // Q30 IF( LT_32( sumRatio, EPSILON_FIX ) ) { - dfRatio = ONE_IN_Q30 / 2; // 0.5 in Q30 + dfRatio = ONE_IN_Q29 /* 0.5f in Q30*/; // Q30 move32(); } ELSE { - dfRatio = L_shl( L_deposit_l( div_l( dirRatio1, extract_h( sumRatio ) ) ), 15 ); // Q30 + Word16 exp_diff; + dfRatio = L_deposit_h( BASOP_Util_Divide3232_Scale( dirRatio1, sumRatio, &exp_diff ) ); + dfRatio = L_shl( dfRatio, sub( exp_diff, Q1 ) ); // Q30 } } @@ -2607,16 +2605,16 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ) /* Q13 */, dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16 /* Q14 */, 0, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 2 ), dfRatio_qsteps ); dfRatioQ = L_deposit_h( dfRatioQ16 ); // Q30 dirRatio1Q = L_sub( ONE_IN_Q30, diffRatioQ ); // Q30 - dirRatio2Q = dfRatioQ; + dirRatio2Q = dfRatioQ; // Q30 move32(); } ELSE { Word16 dfRatioQ16; /* Q14 */ - dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16, ONE_IN_Q13, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ) /* Q12 */, dfRatio_qsteps ); + dfRatio_index = usquant_fx( extract_h( dfRatio ), &dfRatioQ16 /* Q14 */, ONE_IN_Q13 /* 0.5f in Q14 */, shr( div_s( 1, sub( dfRatio_qsteps, 1 ) ), 3 ), dfRatio_qsteps ); /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ dirRatio1Q = L_shl( Mpy_32_16_1( L_sub( ONE_IN_Q30, diffRatioQ ), dfRatioQ16 ), 1 ); // Q30 @@ -2630,9 +2628,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( * then later retrieved for further use in encoding. */ FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; // Q0 move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = dirRatio1Q; // Q30 move32(); } nbits_diff[0] = add( nbits_diff[0], MASA_BITS_ER ); @@ -2641,7 +2639,7 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( IF( hodirac_flag ) { Word16 tmp; /* Q14 */ - index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp, 0, shr( div_s( 1, ( DIRAC_DIFFUSE_LEVELS - 1 ) ), 2 ) /* Q13 */, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = usquant_fx( extract_h( dirRatio2Q ), &tmp /* Q14 */, 0, shr( div_s( 1, sub( DIRAC_DIFFUSE_LEVELS, 1 ) ), 2 ), DIRAC_DIFFUSE_LEVELS ); } ELSE { @@ -2650,9 +2648,9 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; // Q0 move16(); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[k] = dirRatio2Q; // Q30 move32(); } nbits_diff[1] = add( nbits_diff[1], dfRatio_bits ); @@ -2667,8 +2665,8 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; move16(); + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; move16(); } needed_bits[0] = add( needed_bits[0], imult1616( hQMetaData->q_direction[0].cfg.nblocks, bits_direction_masa[index_dirRatio1Inv_mod] ) ); @@ -2677,8 +2675,8 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) { hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; move16(); + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; move16(); } needed_bits[1] = add( needed_bits[1], imult1616( hQMetaData->q_direction[1].cfg.nblocks, bits_direction_masa[index_dirRatio2Inv_mod] ) ); @@ -2693,12 +2691,12 @@ static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_fx( FOR( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; move16(); + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[index_dirRatio1Inv] ); // Q30 move32(); + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; move16(); } diff --git a/lib_enc/ivas_tcx_core_enc.c b/lib_enc/ivas_tcx_core_enc.c index 2ba28fcf6..40223d1bd 100644 --- a/lib_enc/ivas_tcx_core_enc.c +++ b/lib_enc/ivas_tcx_core_enc.c @@ -474,9 +474,6 @@ void stereo_tcx_core_enc( for ( int j = 0; j < M; j++ ) { st->lsf_old_fx[j] = (Word16) ( st->lsf_old[j] * 2.56f ); - st->lsf_adaptive_mean_fx[j] = (Word16) ( st->lsf_adaptive_mean[j] * 2.56f ); - st->mem_MA_fx[j] = (Word16) ( st->mem_MA[j] * 2.56f ); - st->mem_AR_fx[j] = (Word16) ( st->mem_AR[j] * 2.56f ); } floatToFixed_arr( st->lspold_enc, st->lspold_enc_fx, Q15, M ); diff --git a/lib_enc/rst_enc.c b/lib_enc/rst_enc.c index 0e8ec0a3e..66ea72cc9 100644 --- a/lib_enc/rst_enc.c +++ b/lib_enc/rst_enc.c @@ -40,6 +40,9 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#endif /*-------------------------------------------------------------------* * CNG_reset_enc() @@ -54,11 +57,20 @@ void CNG_reset_enc( int16_t VBR_cng_reset_flag ) { init_gp_clip( st->clip_var ); +#ifndef IVAS_FLOAT_FIXED mvr2r( UVWB_Ave, st->mem_AR, M ); set_f( st->mem_MA, 0, M ); +#else + Copy( UVWB_Ave_fx, st->mem_AR_fx, M ); + set16_fx( st->mem_MA_fx, 0, M ); +#endif st->hLPDmem->mem_w0_flt = 0.0f; st->hLPDmem->tilt_code_flt = 0.0f; +#ifndef IVAS_FLOAT_FIXED st->hLPDmem->gc_threshold_flt = 0.0f; +#else + st->hLPDmem->gc_threshold = 0; +#endif if ( VBR_cng_reset_flag ) { diff --git a/lib_enc/stat_enc.h b/lib_enc/stat_enc.h index 500dd1307..87076409e 100644 --- a/lib_enc/stat_enc.h +++ b/lib_enc/stat_enc.h @@ -457,11 +457,14 @@ typedef struct td_cng_enc_structure #else Word16 CNG_att_fx; /* CNG and DTX - attenuation factor for CNG, in dB Q7 */ #endif - 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 */ + 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 */ +#ifndef IVAS_FLOAT_FIXED + float ho_lsp_circ2[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs */ +#else + Word16 ho_lsp_circ2_fx[HO_HIST_SIZE * M]; /* CNG and DTX - second buffer of LSPs Q15 */ +#endif + int16_t num_ho; /* CNG and DTX - number of selected hangover frames */ #ifndef IVAS_FLOAT_FIXED float old_env[NUM_ENV_CNG]; float lp_env[NUM_ENV_CNG]; @@ -1151,11 +1154,14 @@ typedef struct lpd_state_structure Word16 e_mem_syn; float tilt_code_flt; - float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ + Word16 tilt_code; /* Q15 */ +#ifndef IVAS_FLOAT_FIXED + float gc_threshold_flt; /* Noise enhancer - threshold for gain_code */ +#else + Word32 gc_threshold; /* Noise enhancer - threshold for gain_code. exponent = 15, 15Q16 */ +#endif float dispMem_flt[8]; /* Noise enhancer - phase dispersion algorithm memory */ Word32 dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ - Word16 tilt_code; /* Q15 */ - Word32 gc_threshold; /* exponent = 15, 15Q16 */ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ } LPD_state, *LPD_state_HANDLE; @@ -1246,11 +1252,11 @@ typedef struct hq_enc_structure int16_t prev_stab_hfe2; #ifndef IVAS_FLOAT_FIXED float prev_ni_ratio; + float prev_En_sb[NB_SWB_SUBBANDS]; #else Word16 prev_ni_ratio_fx; /* Q15 */ + Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ #endif - float prev_En_sb[NB_SWB_SUBBANDS]; - Word16 prev_En_sb_fx[NB_SWB_SUBBANDS]; /* QsEn(4) */ int16_t last_bitalloc_max_band[2]; #ifndef IVAS_FLOAT_FIXED @@ -1463,15 +1469,12 @@ typedef struct td_bwe_enc_structure #ifndef IVAS_FLOAT_FIXED float prev_lsp_shb[LPC_SHB_ORDER]; -#else - Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ -#endif float state_ana_filt_shb[2 * ALLPASSSECTIONS_STEEP + 1]; /* states for the analysis filters */ - Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; -#ifndef IVAS_FLOAT_FIXED float cldfbHBLT_flt; #else - Word16 cldfbHBLT; /* Q13 */ + Word16 prev_lsp_shb_fx[LPC_SHB_ORDER]; /* Q15 */ + Word16 state_ana_filt_shb_fx[( 2 * ALLPASSSECTIONS_STEEP + 1 )]; /* states for the analysis filters */ + Word16 cldfbHBLT; /* Q13 */ #endif /* states for the filters used in generating SHB excitation from WB excitation*/ float mem_csfilt[2]; @@ -1486,8 +1489,8 @@ typedef struct td_bwe_enc_structure float prev_enr_EnvSHBres; /* energy of the residual SHB envelope from the previous frame */ float prev_shb_env_tilt; /* tilt of the residual SHB envelope from the previous frame */ #else - Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ - Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ + Word16 old_mean_EnvSHBres_fx; /* energy of the last subframe of the SHB residual signal from previous frame Q15 */ + Word32 prev_enr_EnvSHBres_fx; /* energy of the residual SHB envelope from the previous frame Q(31 - prev_enr_EnvSHBres_e) */ Word16 prev_enr_EnvSHBres_e; Word16 prev_shb_env_tilt_fx; /* tilt of the residual SHB envelope from the previous frame Q(prev_shb_env_tilt_q) */ Word16 prev_shb_env_tilt_q; @@ -2105,8 +2108,13 @@ 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) */ +#ifndef IVAS_FLOAT_FIXED + 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) */ +#else + Word16 mem_AR_fx[M]; /* AR memory of LSF quantizer (past quantized LSFs without mean) Qlog2(2.56) */ + Word16 mem_MA_fx[M]; /* MA memory of LSF quantizer (past quantized residual) (used also in AMR-WB IO mode) Qlog2(2.56) */ +#endif // Word16 pstreaklen_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*/ @@ -2128,34 +2136,41 @@ typedef struct enc_core_structure Word16 clip_var_fx[6]; Word16 mem_deemph_fx; /* deemphasis filter memory */ Word32 mem_hp20_in_fx[5]; /* HP filter memory for AMR-WB IO */ - 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 */ + int16_t Last_pulse_pos; /* FEC - last position of the first glottal pulse in the frame */ +#ifndef IVAS_FLOAT_FIXED + 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 */ +#else + Word16 lsfoldbfi0_fx[M]; /* FEC - LSF vector of the previous frame Qlog2(2.56) */ + Word16 lsfoldbfi1_fx[M]; /* FEC - LSF vector of the past previous frame Qlog2(2.56) */ + Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC Qlog2(2.56) */ +#endif + 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 uv_count; /* Stationary noise UV modification - unvoiced counter */ + int16_t act_count; /* Stationary noise UV modification - activation counter */ +#ifndef IVAS_FLOAT_FIXED + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ +#else + 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 */ +#endif + int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ +#ifndef IVAS_FLOAT_FIXED + float min_alpha; /* Stationary noise UV modification - minimum alpha */ +#else + Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15 */ +#endif + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ + 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) */ @@ -2169,25 +2184,33 @@ typedef struct enc_core_structure 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 */ +#ifndef IVAS_FLOAT_FIXED + float ee_old; /* previous frame low/high frequency energy ratio */ +#else + Word32 ee_old_fx; /* previous frame low/high frequency energy ratio Q6 */ +#endif + 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 */ +#ifndef IVAS_FLOAT_FIXED + float old_dE1; /* Maximum energy increase in previous frame */ +#else + Word32 old_dE1_fx; /* Maximum energy increase in previous frame Q13 */ +#endif + int16_t old_ind_deltaMax; /* Index of the sub-subframe of maximum energy in previous frame */ +#ifndef IVAS_FLOAT_FIXED + float old_enr_ssf[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ +#else + Word32 old_enr_ssf_fx[2 * NB_SSF]; /* Maxima of energies per sub-subframes of previous frame */ +#endif + 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 */ diff --git a/lib_enc/swb_tbe_enc.c b/lib_enc/swb_tbe_enc.c index 37c799639..dad834fcf 100644 --- a/lib_enc/swb_tbe_enc.c +++ b/lib_enc/swb_tbe_enc.c @@ -99,19 +99,19 @@ void InitSWBencBuffer( set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); #ifndef IVAS_FLOAT_FIXED hBWE_TD->bwe_non_lin_prev_scale = 0; -#else - hBWE_TD->bwe_non_lin_prev_scale_fx = 0; -#endif set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); -#ifndef IVAS_FLOAT_FIXED set_f( hBWE_TD->elliptic_bpf_2_48k_mem[0], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[1], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[2], 0.0f, 4 ); set_f( hBWE_TD->elliptic_bpf_2_48k_mem[3], 0.0f, 4 ); hBWE_TD->prev_fb_energy = 0.0f; #else + hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + + 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 ); @@ -2976,7 +2976,11 @@ void TBEreset_enc( } else if ( bwidth == SWB || bwidth == FB ) { +#ifdef IVAS_FLOAT_FIXED + set16_fx( hBWE_TD->state_ana_filt_shb_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#else set_f( hBWE_TD->state_ana_filt_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) ); +#endif swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) ); -- GitLab From 9b06a6d0b33339f02fff37c5b4f5db1a0b07ad5e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:31:15 +0530 Subject: [PATCH 38/39] Fix for 3gpp issue 974: OSBA 160 kbps (pre-rendering): Discrepancy for SPAR part for several components --- lib_rend/ivas_dirac_output_synthesis_dec.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index f30bb1237..0fa4511fd 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -1537,7 +1537,15 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( } 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 ); /*Q(15-b_exp)*/ + IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) + { + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], 232831 /* EPSILON in exp 63 */, &b_exp ); + b_exp = add( b_exp, sub( sub( 31, q_reference_power ), 63 ) ); + } + ELSE + { + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], reference_power[k + ( ch_idx + 1 ) * num_freq_bands], &b_exp ); /*Q(15-b_exp)*/ + } } c = L_add( ONE_IN_Q29 /*1 Q29*/, Mpy_32_16_1( L_sub( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr_fx, ONE_IN_Q29 /*1 Q29*/ ), 5461 /*1.0 / 6.0 Q15*/ ) ); /*Diffuseness modellling nrg compensation*/ /*Q29*/ @@ -1611,10 +1619,8 @@ void ivas_dirac_dec_output_synthesis_process_slot_fx( { IF( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] == 0 ) { - b = MAXVAL_WORD16; /*Q(-9)*/ - move16(); - b_exp = 40; - move16(); + b = BASOP_Util_Divide3232_Scale( reference_power[k + num_freq_bands], 232831 /* EPSILON in exp 63 */, &b_exp ); + b_exp = add( b_exp, sub( sub( 31, q_reference_power ), 63 ) ); } ELSE { -- GitLab From 2f9f657253c2634d5ab290ea89608cb345dc278f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 4 Nov 2024 10:34:22 +0530 Subject: [PATCH 39/39] Fix for 3gpp issue 971: Waveform discrepency when transitioning from concealing a lost frame to decoding a received frame with SBA bitstream [x] Changed guard bits logic to avoid saturation --- lib_dec/FEC_scale_syn_fx.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib_dec/FEC_scale_syn_fx.c b/lib_dec/FEC_scale_syn_fx.c index 1de166612..21a589c56 100644 --- a/lib_dec/FEC_scale_syn_fx.c +++ b/lib_dec/FEC_scale_syn_fx.c @@ -790,15 +790,16 @@ void FEC_scale_syn_ivas_fx( /*-----------------------------------------------------------------* * Find the energy/gain at the end of the frame *-----------------------------------------------------------------*/ - IF( LT_16( getScaleFactor16( synth, L_frame ), 2 ) ) + tmp = sub( 3, getScaleFactor16( synth, L_frame ) ); + IF( tmp > 0 ) { - Scale_sig( synth, L_frame, -1 ); - frame_ener_fx( L_frame, clas, synth, pitch[sub( shr( L_frame, 6 ), 1 )], &L_enr2 /*Q0*/, 1, sub( Q_syn, 1 ), 3, 0 ); - Scale_sig( synth, L_frame, 1 ); + Word16 synth_tmp[L_FRAME16k]; + Copy_Scale_sig( synth, synth_tmp, L_frame, -tmp ); // Q_synth - tmp + frame_ener_fx( L_frame, clas, synth_tmp, pitch[L_frame / L_SUBFR - 1], &L_enr2 /*Q0*/, 1, sub( Q_syn, tmp ), 3, 0 ); } ELSE { - 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[L_frame / L_SUBFR - 1], &L_enr2 /*Q0*/, 1, Q_syn, 3, 0 ); } test(); -- GitLab