Loading lib_com/options.h +0 −1 Original line number Diff line number Diff line Loading @@ -92,7 +92,6 @@ #define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */ #define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #define FIX_2489_HARMONIZE_FdCng_encodeSID /* FhG: harmonize FdCng_encodeSID_fx() and FdCng_encodeSID_ivas_fx() */ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ #define HARMONIZE_2494_FdCng_decodeSID_fx /* FhG: harmonize FdCng_decodeSID_fx with _ivas_ version */ #define FIX_BASOP_2509_EVS_CONCEAL_UNINIT_MEM /* FhG: BASOP 2509: st->hTcxCfg->psychParamsCurrent is not initialized */ Loading lib_enc/acelp_core_enc_fx.c +0 −8 Original line number Diff line number Diff line Loading @@ -362,11 +362,7 @@ ivas_error acelp_core_enc_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); #endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); } Loading Loading @@ -401,11 +397,7 @@ ivas_error acelp_core_enc_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_ivas_fx( st ); #endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); } Loading lib_enc/enc_acelp_tcx_main_fx.c +0 −4 Original line number Diff line number Diff line Loading @@ -88,11 +88,7 @@ void enc_acelp_tcx_main_fx( /* Run SID Coder */ IF( st->core_brate == SID_2k40 ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); #endif } /* Generate Comfort Noise */ Loading lib_enc/fd_cng_enc_fx.c +0 −454 Original line number Diff line number Diff line Loading @@ -763,230 +763,6 @@ static void msvq_encoder( return; } #ifndef FIX_2489_HARMONIZE_FdCng_encodeSID /* FdCng_encodeSID_fx Parameters: stenc i/o: pointer to FD_CNG structure containing all buffers and variables bitstream o : pointer to bitstream total_nbbits o : pointer to total number of encoded bits bitrate i : bitrate amrwb_io i : amr wideband mode preemph_fac i : preemphase factor Function: Generate a bitstream out of the partition levels Returns: void */ void FdCng_encodeSID_fx( HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ Encoder_State *corest, Word16 preemph_fac /* i : preemphase factor */ ) { Word16 i, index, N; Word16 E_Exp, normFacN, normShiftN; Word16 normFacGain, normShiftGain, sidNoiseEst_Exp; Word32 tmp, gain, e, maxVal; Word32 *E, E_ExpLd64; Word32 v[32]; Word16 indices[32]; Word16 v16[32]; BSTR_ENC_HANDLE hBstr = corest->hBstr; HANDLE_FD_CNG_COM st; Word16 maxC_37bits = FD_CNG_maxC_37bits, stages_37bits = FD_CNG_stages_37bits, maxN_37bits = FD_CNG_maxN_37bits; /* Init */ st = stenc->hFdCngCom; E_Exp = stenc->msNoiseEst_fx_exp; move16(); E_ExpLd64 = L_shl( E_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); E = stenc->msNoiseEst_fx; N = stenc->npartDec; move16(); normFacN = getNormReciprocalWord16( N ); normShiftN = BASOP_util_norm_s_bands2shift( N ); normFacGain = getNormReciprocalWord16( N_GAIN_MAX - N_GAIN_MIN ); normShiftGain = BASOP_util_norm_s_bands2shift( N_GAIN_MAX - N_GAIN_MIN ); /* Convert to LOG */ /* e: Q14.23 format, v: Q9.23 format */ e = L_deposit_l( 0 ); tmp = Mpy_32_32_r( L_shl( 1, sub( 31, E_Exp ) ), 214748 ); /* 1e-4f, Q31-E_Exp */ FOR( i = 0; i < N; i++ ) { /* assert( E[i] != 0 ); */ /* constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0) * 0.25 */ v[i] = Mpy_32_16_1( L_add( BASOP_Util_Log2( L_add( E[i], L_max( 1, tmp ) ) ), E_ExpLd64 ), 24660 /*0.75257498916 Q15*/ ); move32(); e = L_add( e, L_shr( v[i], normShiftN ) ); } e = L_shl( Mpy_32_16_1( e, shl( normFacN, sub( normShiftN, 1 ) ) ), 1 ); /* Normalize MSVQ input */ /* gain: Q9.23 format */ gain = L_deposit_l( 0 ); FOR( i = N_GAIN_MIN; i < N_GAIN_MAX; i++ ) { gain = L_add( gain, L_shr( v[i], normShiftGain ) ); } gain = L_shl( Mpy_32_16_1( gain, shl( normFacGain, sub( normShiftGain, 1 ) ) ), 1 ); FOR( i = 0; i < N; i++ ) { v16[i] = extract_h( L_sub( v[i], gain ) ); } /* MSVQ encoder */ msvq_encoder( cdk_37bits, v16, levels_37bits, maxC_37bits, stages_37bits, N, maxN_37bits, indices ); /* MSVQ decoder */ msvq_decoder( cdk_37bits, stages_37bits, N, maxN_37bits, indices, v16 ); FOR( i = 0; i < N; i++ ) { v[i] = L_deposit_h( v16[i] ); } /* Compute gain, Q9.23 format */ gain = 0; FOR( i = 0; i < N; i++ ) { gain = L_add( gain, L_shr( v[i], normShiftN ) ); } gain = L_sub( e, L_shl( Mpy_32_16_1( gain, shl( normFacN, sub( normShiftN, 1 ) ) ), 1 ) ); /* Apply bitrate-dependant scale */ { apply_scale( &gain, st->CngBandwidth, st->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO ); } /* Quantize gain, Q14.23 format */ gain = L_add( gain, L_shr( gain, 1 ) ); gain = L_add( gain, 507510784l /*60.5 Q23*/ ); index = extract_l( L_shr( gain, WORD32_BITS - 1 - 8 ) ); if ( index < 0 ) { index = 0; move16(); } if ( GT_16( index, 127 ) ) { index = 127; move16(); } /* gain Q14.23 format */ gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /* Apply gain and undo log */ /* sidNoiseEst: format Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ /* calculate worst case for scaling */ maxVal = 0x80000000 /*-1.0 Q31*/; move32(); FOR( i = 0; i < N; i++ ) { maxVal = L_max( maxVal, v[i] ); } maxVal = L_add( maxVal, gain ); maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); sidNoiseEst_Exp = 0; move16(); WHILE( maxVal >= 0 ) { maxVal = L_sub( maxVal, 33554432l /*0.015625 Q31*/ ); sidNoiseEst_Exp = add( sidNoiseEst_Exp, 1 ); } st->sidNoiseEstExp = sidNoiseEst_Exp; move16(); E_ExpLd64 = L_shl( sidNoiseEst_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); FOR( i = 0; i < N; i++ ) { tmp = L_add( v[i], gain ); tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); tmp = L_sub( tmp, E_ExpLd64 ); assert( tmp < 0 ); st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); move32(); } /* NB last band energy compensation */ IF( EQ_16( st->CngBandwidth, NB ) ) { st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); move32(); } test(); if ( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); move32(); } /* Write bitstream */ IF( EQ_16( corest->codec_mode, MODE2 ) ) { FOR( i = 0; i < stages_37bits; i++ ) { push_next_indice( hBstr, indices[i], bits_37bits[i] ); } push_next_indice( hBstr, index, 7 ); } ELSE { push_indice( hBstr, IND_SID_TYPE, 1, 1 ); push_indice( hBstr, IND_ACELP_16KHZ, corest->bwidth, 2 ); IF( EQ_16( corest->L_frame, L_FRAME16k ) ) { push_indice( hBstr, IND_ACELP_16KHZ, 1, 1 ); } ELSE { push_indice( hBstr, IND_ACELP_16KHZ, 0, 1 ); } FOR( i = 0; i < stages_37bits; i++ ) { push_indice( hBstr, IND_LSF, indices[i], bits_37bits[i] ); } push_indice( hBstr, IND_ENERGY, index, 7 ); } /* Interpolate the bin/band-wise levels from the partition levels */ /* sidNoiseEst: Q6.26 format => cngNoiseLevel: Q6.26 format */ scalebands( st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, sub( stenc->stopBandDec, stenc->startBandDec ), st->cngNoiseLevel, 1 ); st->cngNoiseLevelExp = st->sidNoiseEstExp; move16(); lpc_from_spectrum( st, stenc->startBandDec, stenc->stopFFTbinDec, preemph_fac ); return; } #endif /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ void generate_comfort_noise_enc_fx( Loading Loading @@ -1806,7 +1582,6 @@ void perform_noise_estimation_enc_fx( * * Generate a bitstream out of the partition levels *-------------------------------------------------------------------*/ #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_fx( Encoder_State *st /* i/o: encoder state structure */ ) Loading Loading @@ -2145,235 +1920,6 @@ void FdCng_encodeSID_fx( return; } #else /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ void FdCng_encodeSID_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ ) { Word16 N; HANDLE_FD_CNG_ENC hFdCngEnc = st->hFdCngEnc; HANDLE_FD_CNG_COM hFdCngCom = hFdCngEnc->hFdCngCom; BSTR_ENC_HANDLE hBstr = st->hBstr; Word32 *invTrfMatrix_fx, *E_fx; Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; Word32 v_fx[32], gain_fx, e_fx, temp; Word16 w_fx[32], indices[32], exp[32]; Word32 dct_target_fx[FDCNG_VQ_DCT_MAXTRUNC]; Word32 tot_sig_ext_fx[FDCNG_VQ_MAX_LEN]; Word16 v_e, gain_q_offset, preemph_fac; Word16 i, index; gain_q_offset = GAIN_Q_OFFSET_IVAS_FX_Q0; move16(); if ( st->element_mode == EVS_MONO ) { gain_q_offset = GAIN_Q_OFFSET_EVS_FX_Q0; move16(); } preemph_fac = st->preemph_fac; // Q15 move16(); /* Init */ N = hFdCngEnc->npartDec; move16(); E_fx = hFdCngEnc->msNoiseEst_fx; invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */ set_zero_fx( v_fx, FDCNG_VQ_MAX_LEN ); /* Convert to LOG */ e_fx = 0; move32(); FOR( i = 0; i < N; i++ ) { IF( E_fx[i] == 0 ) { /* 10 * log(1e-4) = 10 * (-4) = -40 */ v_fx[i] = -41943040; // -40.0 in Q20 move32(); } ELSE { v_fx[i] = Mpy_32_32( 671088640 /*10 in Q26*/, BASOP_Util_Log10( E_fx[i], hFdCngEnc->msNoiseEst_fx_exp ) ); // Q20 = 26+25-31 move32(); } e_fx = L_add( e_fx, L_shr( v_fx[i], 1 ) ); // Q19, add one bit headroom } /* Normalize MSVQ input */ gain_fx = 0; move32(); FOR( i = N_GAIN_MIN; i < N_GAIN_MAX; i++ ) { gain_fx = L_add( gain_fx, v_fx[i] ); // Q20 } /*gain /= (float) ( N_GAIN_MAX - N_GAIN_MIN );*/ gain_fx = Mpy_32_32( gain_fx, 165191050 /* 1/13 in Q31*/ ); // Q20 FOR( i = 0; i < N; i++ ) { v_fx[i] = L_sub( v_fx[i], gain_fx ); // Q20 move32(); } v_e = 11; // Q20 move16(); /* MSVQ encoder */ set_val_Word16( w_fx, ONE_IN_Q8, N ); IF( st->element_mode != EVS_MONO ) { /* DCT domain compressed/truncated indices used for first stage */ /* quantization with stage1 stored in DCT24 domain, stages 2 through 6 directly dearched in FDCNG band domain */ IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { /* truncated DCT21 analysis */ create_IDCT_N_Matrix_fx( invTrfMatrix_fx, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 dctT2_N_apply_matrix_fx( v_fx /*Q20*/, dct_target_fx, FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX ); // Q20 /* truncated IDCT21 extension to 24 bands */ extend_dctN_input_fx( v_fx, dct_target_fx, N, tot_sig_ext_fx, FDCNG_VQ_MAX_LEN, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); // Q20 Copy32( tot_sig_ext_fx, v_fx, FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 */ // Q20 } create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, v_fx, v_e, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w_fx, N, FD_CNG_maxN_37bits, 1, invTrfMatrix_fx, indices ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v_fx, NULL, 7 ); v_e = sub( 31, sub( 20, find_guarded_bits_fx( N ) ) ); } ELSE { /* EVS_MONO tables */ msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, v_fx, v_e, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w_fx, N, FD_CNG_maxN_37bits, 0, NULL, indices ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v_fx, NULL, 7 ); v_e = sub( 31, sub( 20, find_guarded_bits_fx( N ) ) ); } /* Compute gain */ gain_fx = 0; move32(); FOR( i = 0; i < N; i++ ) { gain_fx = L_add( gain_fx, v_fx[i] ); // Q = 31 - v_e } e_fx = L_shl( e_fx, sub( 12, v_e ) ); // Q = 31 - v_e gain_fx = Mpy_32_16_1( L_sub( e_fx, gain_fx ), div_s( 1, N ) ); // Q = 31 - v_e gain_fx = L_shl( gain_fx, sub( v_e, 8 ) ); // Q23 /* Apply bitrate-dependant scale */ IF( st->element_mode > EVS_MONO ) { apply_scale( &gain_fx, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); } ELSE { apply_scale( &gain_fx, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO ); } /* Quantize gain */ temp = Madd_32_32( L_shl( gain_q_offset, 22 ), gain_fx, 1610612736 /*1.5 in Q30*/ ); // Q22 index = extract_l( L_shr( L_add( temp, ONE_IN_Q21 ), 22 ) ); // Q0 if ( index < 0 ) { index = 0; move16(); } if ( GT_16( index, 127 ) ) { index = 127; move16(); } gain_fx = L_shl( L_mult0( sub( index, gain_q_offset ), 21845 /*1.5 in Q15*/ ), sub( 16, v_e ) ); // Q = 31-v_e /* Apply gain and undo log */ FOR( i = 0; i < N; i++ ) { temp = Mpy_32_32( L_add( v_fx[i], gain_fx ), 214748365 /* 0.1 in Q31*/ ); // Q = 31-v_e hFdCngCom->sidNoiseEst[i] = BASOP_Util_fPow( 10, 31, temp, v_e, &exp[i] ); move32(); } maximum_s( exp, N, &hFdCngCom->sidNoiseEstExp ); FOR( i = 0; i < N; i++ ) { hFdCngCom->sidNoiseEst[i] = L_shr( hFdCngCom->sidNoiseEst[i], sub( hFdCngCom->sidNoiseEstExp, exp[i] ) ); // exp = hFdCngCom->sidNoiseEstExp move32(); } /* NB last band energy compensation */ IF( hFdCngCom->CngBandwidth == NB ) { hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } test(); IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } /* Write bitstream */ IF( EQ_16( st->codec_mode, MODE2 ) ) { FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { push_next_indice( hBstr, indices[i], bits_37bits[i] ); } push_next_indice( hBstr, index, 7 ); } ELSE { Word16 is_frame_len_16k = 0; move16(); if ( EQ_16( st->L_frame, L_FRAME16k ) ) { is_frame_len_16k = 1; move16(); } push_indice( hBstr, IND_SID_TYPE, 1, 1 ); push_indice( hBstr, IND_BWIDTH, st->bwidth, 2 ); push_indice( hBstr, IND_ACELP_16KHZ, is_frame_len_16k, 1 ); FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { push_indice( hBstr, IND_LSF, indices[i], bits_37bits[i] ); } push_indice( hBstr, IND_ENERGY, index, 7 ); } /* Interpolate the bin/band-wise levels from the partition levels */ scalebands( hFdCngCom->sidNoiseEst, hFdCngEnc->partDec, hFdCngEnc->npartDec, hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, sub( hFdCngEnc->stopBandDec, hFdCngEnc->startBandDec ), hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; move16(); lpc_from_spectrum( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, preemph_fac ); return; } #endif /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ /*-------------------------------------------------------------------* Loading lib_enc/prot_fx_enc.h +0 −13 Original line number Diff line number Diff line Loading @@ -1502,16 +1502,8 @@ void CNG_enc_fx( Word16 *sid_bw ); /* Generate a bitstream out of the partition levels */ #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_fx( Encoder_State *corest ); #else void FdCng_encodeSID_fx( HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ Encoder_State *corest, Word16 preemph_fac /* i : preemphase factor */ ); #endif /* Generate the comfort noise based on the target noise level */ void generate_comfort_noise_enc_fx( Loading Loading @@ -1658,11 +1650,6 @@ Word16 AdjustFirstSID_fx( Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ ); #ifndef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ ); #endif void resetFdCngEnc_fx( Encoder_State *st ); Loading Loading
lib_com/options.h +0 −1 Original line number Diff line number Diff line Loading @@ -92,7 +92,6 @@ #define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */ #define FIX_2452_HQ_CORE_PEAQ_AVR_RATIO_HARM /* Eri: Basop issue 2453: Fix alignment of peak_avrg_ratio_fx */ #define FIX_FLOAT_1539_G192_FORMAT_SWITCH /* VA/Nokia: reintroduce format switching for g192 bitstreams */ #define FIX_2489_HARMONIZE_FdCng_encodeSID /* FhG: harmonize FdCng_encodeSID_fx() and FdCng_encodeSID_ivas_fx() */ #define FIX_1527_CMR_BITRATE_IDX /* Fix for incorrect bitrate idx packed in rtp CMR E-byte */ #define HARMONIZE_2494_FdCng_decodeSID_fx /* FhG: harmonize FdCng_decodeSID_fx with _ivas_ version */ #define FIX_BASOP_2509_EVS_CONCEAL_UNINIT_MEM /* FhG: BASOP 2509: st->hTcxCfg->psychParamsCurrent is not initialized */ Loading
lib_enc/acelp_core_enc_fx.c +0 −8 Original line number Diff line number Diff line Loading @@ -362,11 +362,7 @@ ivas_error acelp_core_enc_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); #endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); } Loading Loading @@ -401,11 +397,7 @@ ivas_error acelp_core_enc_fx( test(); IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_ivas_fx( st ); #endif st->hDtxEnc->last_CNG_L_frame = st->L_frame; move16(); } Loading
lib_enc/enc_acelp_tcx_main_fx.c +0 −4 Original line number Diff line number Diff line Loading @@ -88,11 +88,7 @@ void enc_acelp_tcx_main_fx( /* Run SID Coder */ IF( st->core_brate == SID_2k40 ) { #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID FdCng_encodeSID_fx( st ); #else FdCng_encodeSID_fx( st->hFdCngEnc, st, st->preemph_fac ); #endif } /* Generate Comfort Noise */ Loading
lib_enc/fd_cng_enc_fx.c +0 −454 Original line number Diff line number Diff line Loading @@ -763,230 +763,6 @@ static void msvq_encoder( return; } #ifndef FIX_2489_HARMONIZE_FdCng_encodeSID /* FdCng_encodeSID_fx Parameters: stenc i/o: pointer to FD_CNG structure containing all buffers and variables bitstream o : pointer to bitstream total_nbbits o : pointer to total number of encoded bits bitrate i : bitrate amrwb_io i : amr wideband mode preemph_fac i : preemphase factor Function: Generate a bitstream out of the partition levels Returns: void */ void FdCng_encodeSID_fx( HANDLE_FD_CNG_ENC stenc, /* i/o: pointer to FD_CNG structure containing all buffers and variables */ Encoder_State *corest, Word16 preemph_fac /* i : preemphase factor */ ) { Word16 i, index, N; Word16 E_Exp, normFacN, normShiftN; Word16 normFacGain, normShiftGain, sidNoiseEst_Exp; Word32 tmp, gain, e, maxVal; Word32 *E, E_ExpLd64; Word32 v[32]; Word16 indices[32]; Word16 v16[32]; BSTR_ENC_HANDLE hBstr = corest->hBstr; HANDLE_FD_CNG_COM st; Word16 maxC_37bits = FD_CNG_maxC_37bits, stages_37bits = FD_CNG_stages_37bits, maxN_37bits = FD_CNG_maxN_37bits; /* Init */ st = stenc->hFdCngCom; E_Exp = stenc->msNoiseEst_fx_exp; move16(); E_ExpLd64 = L_shl( E_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); E = stenc->msNoiseEst_fx; N = stenc->npartDec; move16(); normFacN = getNormReciprocalWord16( N ); normShiftN = BASOP_util_norm_s_bands2shift( N ); normFacGain = getNormReciprocalWord16( N_GAIN_MAX - N_GAIN_MIN ); normShiftGain = BASOP_util_norm_s_bands2shift( N_GAIN_MAX - N_GAIN_MIN ); /* Convert to LOG */ /* e: Q14.23 format, v: Q9.23 format */ e = L_deposit_l( 0 ); tmp = Mpy_32_32_r( L_shl( 1, sub( 31, E_Exp ) ), 214748 ); /* 1e-4f, Q31-E_Exp */ FOR( i = 0; i < N; i++ ) { /* assert( E[i] != 0 ); */ /* constant: 0.75257498916 = 10.0 * log10(2.0)/log10(10.0) * 0.25 */ v[i] = Mpy_32_16_1( L_add( BASOP_Util_Log2( L_add( E[i], L_max( 1, tmp ) ) ), E_ExpLd64 ), 24660 /*0.75257498916 Q15*/ ); move32(); e = L_add( e, L_shr( v[i], normShiftN ) ); } e = L_shl( Mpy_32_16_1( e, shl( normFacN, sub( normShiftN, 1 ) ) ), 1 ); /* Normalize MSVQ input */ /* gain: Q9.23 format */ gain = L_deposit_l( 0 ); FOR( i = N_GAIN_MIN; i < N_GAIN_MAX; i++ ) { gain = L_add( gain, L_shr( v[i], normShiftGain ) ); } gain = L_shl( Mpy_32_16_1( gain, shl( normFacGain, sub( normShiftGain, 1 ) ) ), 1 ); FOR( i = 0; i < N; i++ ) { v16[i] = extract_h( L_sub( v[i], gain ) ); } /* MSVQ encoder */ msvq_encoder( cdk_37bits, v16, levels_37bits, maxC_37bits, stages_37bits, N, maxN_37bits, indices ); /* MSVQ decoder */ msvq_decoder( cdk_37bits, stages_37bits, N, maxN_37bits, indices, v16 ); FOR( i = 0; i < N; i++ ) { v[i] = L_deposit_h( v16[i] ); } /* Compute gain, Q9.23 format */ gain = 0; FOR( i = 0; i < N; i++ ) { gain = L_add( gain, L_shr( v[i], normShiftN ) ); } gain = L_sub( e, L_shl( Mpy_32_16_1( gain, shl( normFacN, sub( normShiftN, 1 ) ) ), 1 ) ); /* Apply bitrate-dependant scale */ { apply_scale( &gain, st->CngBandwidth, st->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO ); } /* Quantize gain, Q14.23 format */ gain = L_add( gain, L_shr( gain, 1 ) ); gain = L_add( gain, 507510784l /*60.5 Q23*/ ); index = extract_l( L_shr( gain, WORD32_BITS - 1 - 8 ) ); if ( index < 0 ) { index = 0; move16(); } if ( GT_16( index, 127 ) ) { index = 127; move16(); } /* gain Q14.23 format */ gain = L_shl( L_deposit_l( index ), WORD32_BITS - 1 - 8 ); gain = L_sub( gain, 503316480l /*60.0 Q23*/ ); gain = Mpy_32_16_1( gain, 21845 /*2.0f/3.0f Q15*/ ); /* Apply gain and undo log */ /* sidNoiseEst: format Q6.26, 0.66438561897 = log10(10)/log10(2.0) / 10.0 * 2.0 */ /* calculate worst case for scaling */ maxVal = 0x80000000 /*-1.0 Q31*/; move32(); FOR( i = 0; i < N; i++ ) { maxVal = L_max( maxVal, v[i] ); } maxVal = L_add( maxVal, gain ); maxVal = L_shl( Mpy_32_16_1( maxVal, 21771 /*0.66438561897 Q15*/ ), 1 ); sidNoiseEst_Exp = 0; move16(); WHILE( maxVal >= 0 ) { maxVal = L_sub( maxVal, 33554432l /*0.015625 Q31*/ ); sidNoiseEst_Exp = add( sidNoiseEst_Exp, 1 ); } st->sidNoiseEstExp = sidNoiseEst_Exp; move16(); E_ExpLd64 = L_shl( sidNoiseEst_Exp, WORD32_BITS - 1 - LD_DATA_SCALE ); FOR( i = 0; i < N; i++ ) { tmp = L_add( v[i], gain ); tmp = L_shl( Mpy_32_16_1( tmp, 21771 /*0.66438561897 Q15*/ ), 1 ); tmp = L_sub( tmp, E_ExpLd64 ); assert( tmp < 0 ); st->sidNoiseEst[i] = BASOP_Util_InvLog2( tmp ); move32(); } /* NB last band energy compensation */ IF( EQ_16( st->CngBandwidth, NB ) ) { st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); move32(); } test(); if ( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); move32(); } /* Write bitstream */ IF( EQ_16( corest->codec_mode, MODE2 ) ) { FOR( i = 0; i < stages_37bits; i++ ) { push_next_indice( hBstr, indices[i], bits_37bits[i] ); } push_next_indice( hBstr, index, 7 ); } ELSE { push_indice( hBstr, IND_SID_TYPE, 1, 1 ); push_indice( hBstr, IND_ACELP_16KHZ, corest->bwidth, 2 ); IF( EQ_16( corest->L_frame, L_FRAME16k ) ) { push_indice( hBstr, IND_ACELP_16KHZ, 1, 1 ); } ELSE { push_indice( hBstr, IND_ACELP_16KHZ, 0, 1 ); } FOR( i = 0; i < stages_37bits; i++ ) { push_indice( hBstr, IND_LSF, indices[i], bits_37bits[i] ); } push_indice( hBstr, IND_ENERGY, index, 7 ); } /* Interpolate the bin/band-wise levels from the partition levels */ /* sidNoiseEst: Q6.26 format => cngNoiseLevel: Q6.26 format */ scalebands( st->sidNoiseEst, stenc->partDec, stenc->npartDec, stenc->midbandDec, stenc->nFFTpartDec, sub( stenc->stopBandDec, stenc->startBandDec ), st->cngNoiseLevel, 1 ); st->cngNoiseLevelExp = st->sidNoiseEstExp; move16(); lpc_from_spectrum( st, stenc->startBandDec, stenc->stopFFTbinDec, preemph_fac ); return; } #endif /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ void generate_comfort_noise_enc_fx( Loading Loading @@ -1806,7 +1582,6 @@ void perform_noise_estimation_enc_fx( * * Generate a bitstream out of the partition levels *-------------------------------------------------------------------*/ #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_fx( Encoder_State *st /* i/o: encoder state structure */ ) Loading Loading @@ -2145,235 +1920,6 @@ void FdCng_encodeSID_fx( return; } #else /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ void FdCng_encodeSID_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ ) { Word16 N; HANDLE_FD_CNG_ENC hFdCngEnc = st->hFdCngEnc; HANDLE_FD_CNG_COM hFdCngCom = hFdCngEnc->hFdCngCom; BSTR_ENC_HANDLE hBstr = st->hBstr; Word32 *invTrfMatrix_fx, *E_fx; Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; Word32 v_fx[32], gain_fx, e_fx, temp; Word16 w_fx[32], indices[32], exp[32]; Word32 dct_target_fx[FDCNG_VQ_DCT_MAXTRUNC]; Word32 tot_sig_ext_fx[FDCNG_VQ_MAX_LEN]; Word16 v_e, gain_q_offset, preemph_fac; Word16 i, index; gain_q_offset = GAIN_Q_OFFSET_IVAS_FX_Q0; move16(); if ( st->element_mode == EVS_MONO ) { gain_q_offset = GAIN_Q_OFFSET_EVS_FX_Q0; move16(); } preemph_fac = st->preemph_fac; // Q15 move16(); /* Init */ N = hFdCngEnc->npartDec; move16(); E_fx = hFdCngEnc->msNoiseEst_fx; invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */ set_zero_fx( v_fx, FDCNG_VQ_MAX_LEN ); /* Convert to LOG */ e_fx = 0; move32(); FOR( i = 0; i < N; i++ ) { IF( E_fx[i] == 0 ) { /* 10 * log(1e-4) = 10 * (-4) = -40 */ v_fx[i] = -41943040; // -40.0 in Q20 move32(); } ELSE { v_fx[i] = Mpy_32_32( 671088640 /*10 in Q26*/, BASOP_Util_Log10( E_fx[i], hFdCngEnc->msNoiseEst_fx_exp ) ); // Q20 = 26+25-31 move32(); } e_fx = L_add( e_fx, L_shr( v_fx[i], 1 ) ); // Q19, add one bit headroom } /* Normalize MSVQ input */ gain_fx = 0; move32(); FOR( i = N_GAIN_MIN; i < N_GAIN_MAX; i++ ) { gain_fx = L_add( gain_fx, v_fx[i] ); // Q20 } /*gain /= (float) ( N_GAIN_MAX - N_GAIN_MIN );*/ gain_fx = Mpy_32_32( gain_fx, 165191050 /* 1/13 in Q31*/ ); // Q20 FOR( i = 0; i < N; i++ ) { v_fx[i] = L_sub( v_fx[i], gain_fx ); // Q20 move32(); } v_e = 11; // Q20 move16(); /* MSVQ encoder */ set_val_Word16( w_fx, ONE_IN_Q8, N ); IF( st->element_mode != EVS_MONO ) { /* DCT domain compressed/truncated indices used for first stage */ /* quantization with stage1 stored in DCT24 domain, stages 2 through 6 directly dearched in FDCNG band domain */ IF( EQ_16( N, FDCNG_VQ_MAX_LEN_WB ) ) { /* truncated DCT21 analysis */ create_IDCT_N_Matrix_fx( invTrfMatrix_fx, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 dctT2_N_apply_matrix_fx( v_fx /*Q20*/, dct_target_fx, FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX ); // Q20 /* truncated IDCT21 extension to 24 bands */ extend_dctN_input_fx( v_fx, dct_target_fx, N, tot_sig_ext_fx, FDCNG_VQ_MAX_LEN, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); // Q20 Copy32( tot_sig_ext_fx, v_fx, FDCNG_VQ_MAX_LEN ); /* write extended result as input to VQ stage #1 */ // Q20 } create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, v_fx, v_e, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w_fx, N, FD_CNG_maxN_37bits, 1, invTrfMatrix_fx, indices ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v_fx, NULL, 7 ); v_e = sub( 31, sub( 20, find_guarded_bits_fx( N ) ) ); } ELSE { /* EVS_MONO tables */ msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, v_fx, v_e, levels_37bits, FD_CNG_maxC_37bits, FD_CNG_stages_37bits, w_fx, N, FD_CNG_maxN_37bits, 0, NULL, indices ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v_fx, NULL, 7 ); v_e = sub( 31, sub( 20, find_guarded_bits_fx( N ) ) ); } /* Compute gain */ gain_fx = 0; move32(); FOR( i = 0; i < N; i++ ) { gain_fx = L_add( gain_fx, v_fx[i] ); // Q = 31 - v_e } e_fx = L_shl( e_fx, sub( 12, v_e ) ); // Q = 31 - v_e gain_fx = Mpy_32_16_1( L_sub( e_fx, gain_fx ), div_s( 1, N ) ); // Q = 31 - v_e gain_fx = L_shl( gain_fx, sub( v_e, 8 ) ); // Q23 /* Apply bitrate-dependant scale */ IF( st->element_mode > EVS_MONO ) { apply_scale( &gain_fx, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); } ELSE { apply_scale( &gain_fx, hFdCngCom->CngBandwidth, hFdCngCom->CngBitrate, scaleTableMono, SIZE_SCALE_TABLE_MONO ); } /* Quantize gain */ temp = Madd_32_32( L_shl( gain_q_offset, 22 ), gain_fx, 1610612736 /*1.5 in Q30*/ ); // Q22 index = extract_l( L_shr( L_add( temp, ONE_IN_Q21 ), 22 ) ); // Q0 if ( index < 0 ) { index = 0; move16(); } if ( GT_16( index, 127 ) ) { index = 127; move16(); } gain_fx = L_shl( L_mult0( sub( index, gain_q_offset ), 21845 /*1.5 in Q15*/ ), sub( 16, v_e ) ); // Q = 31-v_e /* Apply gain and undo log */ FOR( i = 0; i < N; i++ ) { temp = Mpy_32_32( L_add( v_fx[i], gain_fx ), 214748365 /* 0.1 in Q31*/ ); // Q = 31-v_e hFdCngCom->sidNoiseEst[i] = BASOP_Util_fPow( 10, 31, temp, v_e, &exp[i] ); move32(); } maximum_s( exp, N, &hFdCngCom->sidNoiseEstExp ); FOR( i = 0; i < N; i++ ) { hFdCngCom->sidNoiseEst[i] = L_shr( hFdCngCom->sidNoiseEst[i], sub( hFdCngCom->sidNoiseEstExp, exp[i] ) ); // exp = hFdCngCom->sidNoiseEstExp move32(); } /* NB last band energy compensation */ IF( hFdCngCom->CngBandwidth == NB ) { hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } test(); IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { hFdCngCom->sidNoiseEst[N - 1] = Mpy_32_16_1( hFdCngCom->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); // exp(hFdCngCom->sidNoiseEstExp) move32(); } /* Write bitstream */ IF( EQ_16( st->codec_mode, MODE2 ) ) { FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { push_next_indice( hBstr, indices[i], bits_37bits[i] ); } push_next_indice( hBstr, index, 7 ); } ELSE { Word16 is_frame_len_16k = 0; move16(); if ( EQ_16( st->L_frame, L_FRAME16k ) ) { is_frame_len_16k = 1; move16(); } push_indice( hBstr, IND_SID_TYPE, 1, 1 ); push_indice( hBstr, IND_BWIDTH, st->bwidth, 2 ); push_indice( hBstr, IND_ACELP_16KHZ, is_frame_len_16k, 1 ); FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { push_indice( hBstr, IND_LSF, indices[i], bits_37bits[i] ); } push_indice( hBstr, IND_ENERGY, index, 7 ); } /* Interpolate the bin/band-wise levels from the partition levels */ scalebands( hFdCngCom->sidNoiseEst, hFdCngEnc->partDec, hFdCngEnc->npartDec, hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, sub( hFdCngEnc->stopBandDec, hFdCngEnc->startBandDec ), hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; move16(); lpc_from_spectrum( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, preemph_fac ); return; } #endif /*FIX_2489_HARMONIZE_FdCng_encodeSID*/ /*-------------------------------------------------------------------* Loading
lib_enc/prot_fx_enc.h +0 −13 Original line number Diff line number Diff line Loading @@ -1502,16 +1502,8 @@ void CNG_enc_fx( Word16 *sid_bw ); /* Generate a bitstream out of the partition levels */ #ifdef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_fx( Encoder_State *corest ); #else void FdCng_encodeSID_fx( HANDLE_FD_CNG_ENC st, /* i/o: FD_CNG structure containing all buffers and variables */ Encoder_State *corest, Word16 preemph_fac /* i : preemphase factor */ ); #endif /* Generate the comfort noise based on the target noise level */ void generate_comfort_noise_enc_fx( Loading Loading @@ -1658,11 +1650,6 @@ Word16 AdjustFirstSID_fx( Encoder_State *stcod /* i : pointer to Coder_State_Plus structure */ ); #ifndef FIX_2489_HARMONIZE_FdCng_encodeSID void FdCng_encodeSID_ivas_fx( Encoder_State *st /* i/o: encoder state structure */ ); #endif void resetFdCngEnc_fx( Encoder_State *st ); Loading