Loading lib_com/bits_alloc_fx.c +67 −0 Original line number Diff line number Diff line Loading @@ -1575,6 +1575,72 @@ static Word16 allocate_unused( *--------------------------------------------------------------------*/ /*! r: ACELP16k flag */ #ifdef IVAS_FLOAT_FIXED Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ const Word32 total_brate, /* i : total bitrate per channel */ const Word16 idchan, /* i : Channel id */ const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const Word16 bwidth, /* i : audio bandwidth */ const Word16 cng_type /* i : CNG type */ ) { // PMT("Not floating point computation, but fixed point operator are still missing ") test(); test(); test(); test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) { return 1; } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { test(); test(); test(); IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) { return 1; } ELSE { return 0; } } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { IF( GE_32( element_brate, IVAS_24k4 ) ) { return 1; } ELSE { return 0; } } ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { IF( GE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) ) { return 1; } ELSE { return 0; } } ELSE IF( GE_32( total_brate, ACELP_16k_LOW_LIMIT ) ) /* EVS_MONO */ { return 1; } ELSE { return 0; } } #else Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ Loading Loading @@ -1633,4 +1699,5 @@ Word16 set_ACELP_flag( return 0; } } #endif /*#endif IVAS_CODE*/ No newline at end of file lib_com/cldfb.c +61 −2 Original line number Diff line number Diff line Loading @@ -1598,7 +1598,7 @@ void configureCldfb_ivas_fx( // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); Word32 n_sampling_rate = sampling_rate * 2; Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 ), 1 ); Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */), 1 ); val = L_shr( val, 1 ); h_cldfb->no_channels = extract_l( val ); Loading Loading @@ -1687,7 +1687,8 @@ ivas_error openCldfb_ivas_fx( hs->prototype = prototype; move16(); configureCldfb_ivas( hs, sampling_rate ); //configureCldfb_ivas( hs, sampling_rate ); configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; move16(); Loading Loading @@ -1914,6 +1915,36 @@ void deleteCldfb_ivas( return; } #ifdef IVAS_FLOAT_FIXED void deleteCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ) { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; IF ( h_cldfb == NULL || *h_cldfb == NULL ) { return; } IF ( hs->cldfb_state_fx ) { free( hs->cldfb_state_fx ); } #ifdef IVAS_FLOAT_FIXED // TODO : Will be removed later IF ( hs->cldfb_state ) { free( hs->cldfb_state ); } #endif free( hs ); *h_cldfb = NULL; return; } #endif /*-------------------------------------------------------------------* * cldfb_init_proto_and_twiddles() Loading Loading @@ -1956,6 +1987,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17036; hs->p_filter = CLDFB80_10_fx; hs->q_scale = norm_s((Word16)CLDFB80_10_SCALE); hs->scale = (Word16)(CLDFB80_10_SCALE*(1<<hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -1975,6 +2008,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_10_fx; hs->q_scale = norm_s((Word16)LDQMF_10_SCALE); hs->scale = (Word16)(LDQMF_10_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2007,6 +2042,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_16_fx; hs->q_scale = norm_s((Word16)CLDFB80_16_SCALE); hs->scale = (Word16)(CLDFB80_16_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2026,6 +2063,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_16_fx; hs->q_scale = norm_s((Word16)LDQMF_16_SCALE); hs->scale = (Word16)(LDQMF_16_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2058,6 +2097,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_20_fx; hs->q_scale = norm_s((Word16)CLDFB80_20_SCALE); hs->scale = (Word16)(CLDFB80_20_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2077,6 +2118,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15390; hs->p_filter = LDQMF_20_fx; hs->q_scale = norm_s((Word16)LDQMF_20_SCALE); hs->scale = (Word16)(LDQMF_20_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2109,6 +2152,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_30_fx; hs->q_scale = norm_s((Word16)CLDFB80_30_SCALE); hs->scale = (Word16)(CLDFB80_30_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2128,6 +2173,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_30_fx; hs->q_scale = norm_s((Word16)LDQMF_30_SCALE); hs->scale = (Word16)(LDQMF_30_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2160,6 +2207,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_32_fx; hs->q_scale = norm_s((Word16)CLDFB80_32_SCALE); hs->scale = (Word16)(CLDFB80_32_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2179,6 +2228,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15392; hs->p_filter = LDQMF_32_fx; hs->q_scale = norm_s((Word16)LDQMF_32_SCALE); hs->scale = (Word16)(LDQMF_32_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2211,6 +2262,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_40_fx; hs->q_scale = norm_s((Word16)CLDFB80_40_SCALE); hs->scale = (Word16)(CLDFB80_40_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2230,6 +2283,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_40_fx; hs->q_scale = norm_s((Word16)LDQMF_40_SCALE); hs->scale = (Word16)(LDQMF_40_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2262,6 +2317,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_60_fx; hs->q_scale = norm_s((Word16)CLDFB80_60_SCALE); hs->scale = (Word16)(CLDFB80_60_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2281,6 +2338,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_60_fx; hs->q_scale = norm_s((Word16)LDQMF_60_SCALE); hs->scale = (Word16)(LDQMF_60_SCALE*(1 << hs->q_scale)); #endif } break; Loading lib_com/cng_exc_fx.c +215 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" #include "ivas_rom_com_fx.h" /*---------------------------------------------------------------------* * Local constants Loading @@ -14,7 +15,7 @@ #define A2 6554 #define OmA2 (32768-A2) #define GAIN_VAR 11811 /* in Q31 divided by 2 (Q30) */ const Word16 att_pow_tbl[SIZE_SCALE_TABLE_STEREO + 1] = { 9234, 10361, 13044, 16422, 22669, 31292, 32767, 26634, 28212, 20674, 16422, 27254, 30934, 32767 }; /*-------------------------------------------------------* * CNG_exc() * Loading Loading @@ -962,6 +963,219 @@ void cng_params_upd_fx( return; } #ifdef IVAS_FLOAT_FIXED void cng_params_upd_ivas_fx( const Word16 lsp_new[], /* i : LSP aprameters Q15 */ const Word16 exc2[], /* i : current enhanced excitation Q_exc */ const Word16 L_frame, /* i : frame length Q0 */ Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ const Word16 Q_exc, /* i : Q value of excitation */ const Word16 enc_dec_flag,/* i : Flag indicating encoder or decoder (ENC,DEC) */ Word32 ho_env_circ[], /* i/o: Envelope buffer */ Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ const Word32 last_active_brate /* i : Last active bit rate Q0 */ , const Word16 element_mode, /* i : Element mode */ const Word16 bwidth /* i : Audio bandwidth */ ) { Word32 L_ener, L_tmp; Word16 i, j; const Word16 *pt_exc2; Word16 tmpv, maxv, scale; Word16 fft_io[L_FRAME16k]; Word32 sp[129]; Word16 *ptR, *ptI; Word32 env[NUM_ENV_CNG]; Word16 exp1; Word16 CNG_mode; Word16 tmp = 0; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /* update the pointer to circular buffer of old LSP vectors */ *ho_circ_ptr = add( *ho_circ_ptr, 1 ); if ( EQ_16( *ho_circ_ptr, HO_HIST_SIZE ) ) { *ho_circ_ptr = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ Copy( lsp_new, &( ho_lsp_circ[( *ho_circ_ptr ) * M] ), M ); /* calculate the residual signal energy */ /*enr = dotp( exc2, exc2, L_frame ) / L_frame; */ maxv = 0; move16(); FOR( i = 0; i < L_frame; i++ ) { maxv = s_max( maxv, abs_s( exc2[i] ) ); } scale = norm_s( maxv ); pt_exc2 = exc2; move16(); L_ener = L_deposit_l( 0 ); IF( EQ_16( L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { tmpv = shl( *pt_exc2, scale ); L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); #else L_tmp = L_mac0( L_tmp, tmpv, tmpv ); #endif pt_exc2++; #ifdef BASOP_NOGLOB L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #else L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #endif } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 160; j++ ) { tmpv = shl( *pt_exc2, scale ); L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); #else L_tmp = L_mac0( L_tmp, tmpv, tmpv ); #endif pt_exc2++; #ifdef BASOP_NOGLOB L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #else L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #endif } } #ifdef BASOP_NOGLOB L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #else /* BASOP_NOGLOB */ L_ener = L_shr( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #endif /* update the circular buffer of old energies */ ho_ener_circ[*ho_circ_ptr] = L_ener; move32(); IF( EQ_16( enc_dec_flag, ENC ) ) { /* Store residual signal for postponed FFT-processing*/ *cng_buf_cnt = add( *cng_buf_cnt, 1 ); if ( GT_16( *cng_buf_cnt, HO_HIST_SIZE ) ) { *cng_buf_cnt = HO_HIST_SIZE; move16(); } Copy( exc2, &( cng_exc2_buf[( *ho_circ_ptr ) * L_FFT] ), L_FFT ); cng_Qexc_buf[*ho_circ_ptr] = Q_exc; move16(); cng_brate_buf[*ho_circ_ptr] = last_active_brate; move16(); } ELSE { /* calculate the spectrum of residual signal */ Copy( exc2, fft_io, L_frame ); fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); ptR = &fft_io[1]; ptI = &fft_io[L_FFT - 1]; FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ #ifdef BASOP_NOGLOB L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ #else L_tmp = L_mult( *ptR, *ptR ); /* 2*Q_exc+1 */ L_tmp = L_add( L_tmp, L_mult( *ptI, *ptI ) ); /* 2*Q_exc+1 */ L_tmp = L_add( L_tmp, L_tmp ); /* 2*Q_exc+1 */ #endif L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ ptR++; ptI--; } Copy32(sp,env,NUM_ENV_CNG); Word16 shift = 0; if (element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT) { Word32 att_fx = 0; Word16 index = 0; apply_scale_ivas_fx(&att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index); att_fx = pow_10_q23[index];//Q23 tmp = extract_h(att_fx);//Q7 shift = 8; } else { CNG_mode = get_cng_mode(last_active_brate); /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ L_tmp = L_shl(L_deposit_l(ENR_ATT_fx[CNG_mode]), 8);/* 16 */ temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); exp_pow = sub(14, temp_hi_fx); L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ L_tmp = L_shl(L_tmp, sub(13, exp_pow)); /* Q13 */ tmp = extract_l(L_tmp);/* Q13 */ exp1 = norm_s(tmp); tmp = shl(tmp, exp1);/*Q(exp1+13) */ tmp = div_s(16384, tmp); /*Q(15+14-exp1-13) */ tmp = shr(tmp, sub(1, exp1));/* Q15 */ } FOR(i = 0; i < NUM_ENV_CNG; i++) { env[i] = Mult_32_16(env[i],tmp); move32(); } /* update the circular buffer of old residual envelope */ /* Copy32( env, &(ho_env_circ[add(shl(*ho_circ_ptr,4),shl(*ho_circ_ptr,2))]), NUM_ENV_CNG ); */ Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); scale_sig32(&(ho_env_circ[(*ho_circ_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG, shift); } *ho_circ_size = add( *ho_circ_size, 1 ); if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) { *ho_circ_size = HO_HIST_SIZE; move16(); } return; } #endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * get_cng_mode() * Loading lib_com/cnst.h +2 −0 Original line number Diff line number Diff line Loading @@ -2995,6 +2995,8 @@ extern const Word16 Idx2Freq_Tbl[]; #define FS_32K_IN_NS_Q31 68719 #define FS_16K_IN_NS_Q31 34360 #define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ typedef enum { MCT_CHAN_MODE_REGULAR, Loading lib_com/fd_cng_com_fx.c +179 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,121 @@ ivas_error createFdCngCom( * *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) { /* Calculate CLDFB scaling factor */ /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); /* Initialize the overlap-add */ set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); hFdCngCom->olapBufferAna = NULL; set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); move16(); set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); hFdCngCom->olapBufferSynth2 = NULL; move16(); /* Initialize the comfort noise generation */ set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 ); /* Initialize quantizer */ set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 ); set16_fx( hFdCngCom->A_cng, 0, M + 1 ); hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */ move16(); /* Set some counters and flags */ hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); hFdCngCom->active_frame_counter = 0; move16(); hFdCngCom->frame_type_previous = ACTIVE_FRAME; move16(); hFdCngCom->flag_noisy_speech = 0; move16(); hFdCngCom->likelihood_noisy_speech = 0; move16(); hFdCngCom->numCoreBands = 0; move16(); hFdCngCom->stopBand = 0; move16(); hFdCngCom->startBand = 0; move16(); hFdCngCom->stopFFTbin = 0; move16(); hFdCngCom->frameSize = 0; move16(); hFdCngCom->fftlen = 0; move16(); hFdCngCom->seed = 0; move16(); hFdCngCom->seed2 = 1; move16(); hFdCngCom->seed3 = 2; move16(); hFdCngCom->CngBitrate = -1; move16(); /* Initialize noise estimation algorithm */ set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) ); mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) ); set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); hFdCngCom->msPeriodogSum_exp[0] = 0; move16(); hFdCngCom->msPeriodogSum_exp[1] = 0; move16(); set32_fx( hFdCngCom->msPsdSum, 0, 2 ); set16_fx( hFdCngCom->msSlope, 0, 2 ); set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); hFdCngCom->msQeqInvAv_exp[0] = 0; move16(); hFdCngCom->msQeqInvAv_exp[1] = 0; move16(); hFdCngCom->msFrCnt_init_counter = 0; move16(); hFdCngCom->msFrCnt_init_thresh = 1; move16(); hFdCngCom->init_old = 0; move16(); hFdCngCom->offsetflag = 0; move16(); hFdCngCom->msFrCnt = MSSUBFRLEN; move16(); hFdCngCom->msMinBufferPtr = 0; move16(); hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/; move16(); hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/; move16(); set16_fx( hFdCngCom->psize, 0, NPART ); /* Initialize exponents */ hFdCngCom->exp_cldfb_periodog = 0; move16(); hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ move16(); set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN ); set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); hFdCngCom->likelihood_noisy_speech_32fx = 0; move32(); return; } #endif void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) { /* Calculate CLDFB scaling factor */ Loading Loading @@ -1699,6 +1814,70 @@ void apply_scale( } #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * apply_scale_ind() * * Apply bitrate-dependent scale * returns index of scaleTable *-------------------------------------------------------------------*/ Word16 apply_scale_ind( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ const SCALE_SETUP *scaleTable, /* i : Scale table */ const Word16 scaleTableSize /* i : Size of scale table */ ) { Word16 i; // PMT("Verifiy if the basop ued are ok for stereo too") FOR(i = 0; i < scaleTableSize; i++) { cast16(); IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, L_sub(bitrate, scaleTable[i].bitrateTo) < 0))) { BREAK; } } { *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); } return i; } void apply_scale_ivas_fx( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ const SCALE_SETUP* scaleTable, /* i : Scale table */ const Word16 scaleTableSize, /* i : Size of scale table */ Word16 *index ) { Word16 i; //PMT("Verifiy if the basop ued are ok for stereo too") FOR(i = 0; i < scaleTableSize; i++) { cast16(); IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, L_sub(bitrate, scaleTable[i].bitrateTo) < 0)) ) { BREAK; } } assert(i < scaleTableSize); *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); *index = i; } #endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * bandcombinepow() * Loading Loading
lib_com/bits_alloc_fx.c +67 −0 Original line number Diff line number Diff line Loading @@ -1575,6 +1575,72 @@ static Word16 allocate_unused( *--------------------------------------------------------------------*/ /*! r: ACELP16k flag */ #ifdef IVAS_FLOAT_FIXED Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ const Word32 total_brate, /* i : total bitrate per channel */ const Word16 idchan, /* i : Channel id */ const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const Word16 bwidth, /* i : audio bandwidth */ const Word16 cng_type /* i : CNG type */ ) { // PMT("Not floating point computation, but fixed point operator are still missing ") test(); test(); test(); test(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) && EQ_16( idchan, 0 ) && LE_32( total_brate, SID_2k40 ) && EQ_16( bwidth, WB ) && EQ_16( cng_type, LP_CNG ) ) { return 1; } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { test(); test(); test(); IF( GE_32( element_brate, IVAS_24k4 ) && EQ_16( idchan, 0 ) && ( EQ_16( tdm_LRTD_flag, 0 ) || GT_32( element_brate, IVAS_24k4 ) ) ) { return 1; } ELSE { return 0; } } ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { IF( GE_32( element_brate, IVAS_24k4 ) ) { return 1; } ELSE { return 0; } } ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) { IF( GE_32( element_brate, SCE_CORE_16k_LOW_LIMIT ) ) { return 1; } ELSE { return 0; } } ELSE IF( GE_32( total_brate, ACELP_16k_LOW_LIMIT ) ) /* EVS_MONO */ { return 1; } ELSE { return 0; } } #else Word16 set_ACELP_flag( const Word16 element_mode, /* i : element mode */ const Word32 element_brate, /* i : element bitrate */ Loading Loading @@ -1633,4 +1699,5 @@ Word16 set_ACELP_flag( return 0; } } #endif /*#endif IVAS_CODE*/ No newline at end of file
lib_com/cldfb.c +61 −2 Original line number Diff line number Diff line Loading @@ -1598,7 +1598,7 @@ void configureCldfb_ivas_fx( // h_cldfb->no_channels = (int16_t) ( sampling_rate * INV_CLDFB_BANDWIDTH + 0.5f ); Word32 n_sampling_rate = sampling_rate * 2; Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 ), 1 ); Word32 val = L_add( Mpy_32_16_1( n_sampling_rate, 41 /* INV_CLDFB_BANDWIDTH in Q15 */), 1 ); val = L_shr( val, 1 ); h_cldfb->no_channels = extract_l( val ); Loading Loading @@ -1687,7 +1687,8 @@ ivas_error openCldfb_ivas_fx( hs->prototype = prototype; move16(); configureCldfb_ivas( hs, sampling_rate ); //configureCldfb_ivas( hs, sampling_rate ); configureCldfb_ivas_fx( hs, sampling_rate ); hs->memory_flt = NULL; hs->memory_length = 0; move16(); Loading Loading @@ -1914,6 +1915,36 @@ void deleteCldfb_ivas( return; } #ifdef IVAS_FLOAT_FIXED void deleteCldfb_ivas_fx( HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ ) { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; IF ( h_cldfb == NULL || *h_cldfb == NULL ) { return; } IF ( hs->cldfb_state_fx ) { free( hs->cldfb_state_fx ); } #ifdef IVAS_FLOAT_FIXED // TODO : Will be removed later IF ( hs->cldfb_state ) { free( hs->cldfb_state ); } #endif free( hs ); *h_cldfb = NULL; return; } #endif /*-------------------------------------------------------------------* * cldfb_init_proto_and_twiddles() Loading Loading @@ -1956,6 +1987,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17036; hs->p_filter = CLDFB80_10_fx; hs->q_scale = norm_s((Word16)CLDFB80_10_SCALE); hs->scale = (Word16)(CLDFB80_10_SCALE*(1<<hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -1975,6 +2008,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_10_fx; hs->q_scale = norm_s((Word16)LDQMF_10_SCALE); hs->scale = (Word16)(LDQMF_10_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2007,6 +2042,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_16_fx; hs->q_scale = norm_s((Word16)CLDFB80_16_SCALE); hs->scale = (Word16)(CLDFB80_16_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2026,6 +2063,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_16_fx; hs->q_scale = norm_s((Word16)LDQMF_16_SCALE); hs->scale = (Word16)(LDQMF_16_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2058,6 +2097,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_20_fx; hs->q_scale = norm_s((Word16)CLDFB80_20_SCALE); hs->scale = (Word16)(CLDFB80_20_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2077,6 +2118,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15390; hs->p_filter = LDQMF_20_fx; hs->q_scale = norm_s((Word16)LDQMF_20_SCALE); hs->scale = (Word16)(LDQMF_20_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2109,6 +2152,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_30_fx; hs->q_scale = norm_s((Word16)CLDFB80_30_SCALE); hs->scale = (Word16)(CLDFB80_30_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2128,6 +2173,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_30_fx; hs->q_scale = norm_s((Word16)LDQMF_30_SCALE); hs->scale = (Word16)(LDQMF_30_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2160,6 +2207,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_32_fx; hs->q_scale = norm_s((Word16)CLDFB80_32_SCALE); hs->scale = (Word16)(CLDFB80_32_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2179,6 +2228,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15392; hs->p_filter = LDQMF_32_fx; hs->q_scale = norm_s((Word16)LDQMF_32_SCALE); hs->scale = (Word16)(LDQMF_32_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2211,6 +2262,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_40_fx; hs->q_scale = norm_s((Word16)CLDFB80_40_SCALE); hs->scale = (Word16)(CLDFB80_40_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2230,6 +2283,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_40_fx; hs->q_scale = norm_s((Word16)LDQMF_40_SCALE); hs->scale = (Word16)(LDQMF_40_SCALE*(1 << hs->q_scale)); #endif } break; Loading Loading @@ -2262,6 +2317,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_60_fx; hs->q_scale = norm_s((Word16)CLDFB80_60_SCALE); hs->scale = (Word16)(CLDFB80_60_SCALE*(1 << hs->q_scale)); #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) Loading @@ -2281,6 +2338,8 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_60_fx; hs->q_scale = norm_s((Word16)LDQMF_60_SCALE); hs->scale = (Word16)(LDQMF_60_SCALE*(1 << hs->q_scale)); #endif } break; Loading
lib_com/cng_exc_fx.c +215 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ #include "rom_com.h" #include "ivas_rom_com_fx.h" /*---------------------------------------------------------------------* * Local constants Loading @@ -14,7 +15,7 @@ #define A2 6554 #define OmA2 (32768-A2) #define GAIN_VAR 11811 /* in Q31 divided by 2 (Q30) */ const Word16 att_pow_tbl[SIZE_SCALE_TABLE_STEREO + 1] = { 9234, 10361, 13044, 16422, 22669, 31292, 32767, 26634, 28212, 20674, 16422, 27254, 30934, 32767 }; /*-------------------------------------------------------* * CNG_exc() * Loading Loading @@ -962,6 +963,219 @@ void cng_params_upd_fx( return; } #ifdef IVAS_FLOAT_FIXED void cng_params_upd_ivas_fx( const Word16 lsp_new[], /* i : LSP aprameters Q15 */ const Word16 exc2[], /* i : current enhanced excitation Q_exc */ const Word16 L_frame, /* i : frame length Q0 */ Word16 *ho_circ_ptr, /* i/o: pointer for CNG averaging buffers Q0 */ Word32 ho_ener_circ[], /* o : energy buffer for CNG averaging Q6 */ Word16 *ho_circ_size, /* i/o: size of DTX hangover history buffer for averaging Q0 */ Word16 ho_lsp_circ[], /* o : old LSP buffer for CNG averaging Q15 */ const Word16 Q_exc, /* i : Q value of excitation */ const Word16 enc_dec_flag,/* i : Flag indicating encoder or decoder (ENC,DEC) */ Word32 ho_env_circ[], /* i/o: Envelope buffer */ Word16 *cng_buf_cnt, /* i/o: Counter of postponed FFT-processing instances */ Word16 cng_exc2_buf[], /* i/o: Excitation buffer Q_exc */ Word16 cng_Qexc_buf[], /* i/o: Q_exc buffer Q0 */ Word32 cng_brate_buf[], /* i/o: last_active_brate buffer Q0 */ const Word32 last_active_brate /* i : Last active bit rate Q0 */ , const Word16 element_mode, /* i : Element mode */ const Word16 bwidth /* i : Audio bandwidth */ ) { Word32 L_ener, L_tmp; Word16 i, j; const Word16 *pt_exc2; Word16 tmpv, maxv, scale; Word16 fft_io[L_FRAME16k]; Word32 sp[129]; Word16 *ptR, *ptI; Word32 env[NUM_ENV_CNG]; Word16 exp1; Word16 CNG_mode; Word16 tmp = 0; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif /* update the pointer to circular buffer of old LSP vectors */ *ho_circ_ptr = add( *ho_circ_ptr, 1 ); if ( EQ_16( *ho_circ_ptr, HO_HIST_SIZE ) ) { *ho_circ_ptr = 0; move16(); } /* update the circular buffer of old LSP vectors with the new LSP vector */ Copy( lsp_new, &( ho_lsp_circ[( *ho_circ_ptr ) * M] ), M ); /* calculate the residual signal energy */ /*enr = dotp( exc2, exc2, L_frame ) / L_frame; */ maxv = 0; move16(); FOR( i = 0; i < L_frame; i++ ) { maxv = s_max( maxv, abs_s( exc2[i] ) ); } scale = norm_s( maxv ); pt_exc2 = exc2; move16(); L_ener = L_deposit_l( 0 ); IF( EQ_16( L_frame, L_FRAME ) ) { FOR( j = 0; j < 128; j++ ) { tmpv = shl( *pt_exc2, scale ); L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); #else L_tmp = L_mac0( L_tmp, tmpv, tmpv ); #endif pt_exc2++; #ifdef BASOP_NOGLOB L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #else L_ener = L_add( L_ener, L_shr( L_tmp, 7 ) ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #endif } } ELSE /* L_FRAME16k */ { FOR( j = 0; j < 160; j++ ) { tmpv = shl( *pt_exc2, scale ); L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); #ifdef BASOP_NOGLOB L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); #else L_tmp = L_mac0( L_tmp, tmpv, tmpv ); #endif pt_exc2++; #ifdef BASOP_NOGLOB L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #else L_ener = L_add( L_ener, L_shr( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #endif } } #ifdef BASOP_NOGLOB L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #else /* BASOP_NOGLOB */ L_ener = L_shr( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #endif /* update the circular buffer of old energies */ ho_ener_circ[*ho_circ_ptr] = L_ener; move32(); IF( EQ_16( enc_dec_flag, ENC ) ) { /* Store residual signal for postponed FFT-processing*/ *cng_buf_cnt = add( *cng_buf_cnt, 1 ); if ( GT_16( *cng_buf_cnt, HO_HIST_SIZE ) ) { *cng_buf_cnt = HO_HIST_SIZE; move16(); } Copy( exc2, &( cng_exc2_buf[( *ho_circ_ptr ) * L_FFT] ), L_FFT ); cng_Qexc_buf[*ho_circ_ptr] = Q_exc; move16(); cng_brate_buf[*ho_circ_ptr] = last_active_brate; move16(); } ELSE { /* calculate the spectrum of residual signal */ Copy( exc2, fft_io, L_frame ); fft_rel_fx( fft_io, L_FFT, LOG2_L_FFT ); ptR = &fft_io[1]; ptI = &fft_io[L_FFT - 1]; FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ #ifdef BASOP_NOGLOB L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ #else L_tmp = L_mult( *ptR, *ptR ); /* 2*Q_exc+1 */ L_tmp = L_add( L_tmp, L_mult( *ptI, *ptI ) ); /* 2*Q_exc+1 */ L_tmp = L_add( L_tmp, L_tmp ); /* 2*Q_exc+1 */ #endif L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ ptR++; ptI--; } Copy32(sp,env,NUM_ENV_CNG); Word16 shift = 0; if (element_mode == IVAS_SCE || element_mode == IVAS_CPE_DFT) { Word32 att_fx = 0; Word16 index = 0; apply_scale_ivas_fx(&att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index); att_fx = pow_10_q23[index];//Q23 tmp = extract_h(att_fx);//Q7 shift = 8; } else { CNG_mode = get_cng_mode(last_active_brate); /* att = 1/pow(2,ENR_ATT_fx[CNG_mode]); */ L_tmp = L_shl(L_deposit_l(ENR_ATT_fx[CNG_mode]), 8);/* 16 */ temp_lo_fx = L_Extract_lc(L_tmp, &temp_hi_fx); exp_pow = sub(14, temp_hi_fx); L_tmp = Pow2(14, temp_lo_fx); /* Qexp_pow */ L_tmp = L_shl(L_tmp, sub(13, exp_pow)); /* Q13 */ tmp = extract_l(L_tmp);/* Q13 */ exp1 = norm_s(tmp); tmp = shl(tmp, exp1);/*Q(exp1+13) */ tmp = div_s(16384, tmp); /*Q(15+14-exp1-13) */ tmp = shr(tmp, sub(1, exp1));/* Q15 */ } FOR(i = 0; i < NUM_ENV_CNG; i++) { env[i] = Mult_32_16(env[i],tmp); move32(); } /* update the circular buffer of old residual envelope */ /* Copy32( env, &(ho_env_circ[add(shl(*ho_circ_ptr,4),shl(*ho_circ_ptr,2))]), NUM_ENV_CNG ); */ Copy32( env, &( ho_env_circ[( *ho_circ_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); scale_sig32(&(ho_env_circ[(*ho_circ_ptr)*NUM_ENV_CNG]), NUM_ENV_CNG, shift); } *ho_circ_size = add( *ho_circ_size, 1 ); if ( GT_16( *ho_circ_size, HO_HIST_SIZE ) ) { *ho_circ_size = HO_HIST_SIZE; move16(); } return; } #endif // IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * get_cng_mode() * Loading
lib_com/cnst.h +2 −0 Original line number Diff line number Diff line Loading @@ -2995,6 +2995,8 @@ extern const Word16 Idx2Freq_Tbl[]; #define FS_32K_IN_NS_Q31 68719 #define FS_16K_IN_NS_Q31 34360 #define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ typedef enum { MCT_CHAN_MODE_REGULAR, Loading
lib_com/fd_cng_com_fx.c +179 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,121 @@ ivas_error createFdCngCom( * *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_initFdCngCom_fx( HANDLE_FD_CNG_COM hFdCngCom, Word16 scale ) { /* Calculate CLDFB scaling factor */ /* shl(i_mult2(scale, scale), 3) does not fit in 16 bit */ /*hFdCngCom->scalingFactor = div_s(1, shl(i_mult2(scale, scale), 3));*/ assert( 2048 /*1.0/(1<<4) Q15*/ < mult( scale, scale ) ); /* Exponent invScalingFactor: -16 = -(2*7 (scale) + 2 (8.0) */ hFdCngCom->invScalingFactor = shl( mult( scale, scale ), 1 ); /* Exponent scalingFactor: -15 = -(2*7 (scale) + 2 (8.0) - 1 (1.0)) */ hFdCngCom->scalingFactor = div_s( 0x4000, hFdCngCom->invScalingFactor ); /* Initialize the overlap-add */ set16_fx( hFdCngCom->timeDomainBuffer, 0, L_FRAME16k ); hFdCngCom->olapBufferAna = NULL; set16_fx( hFdCngCom->olapBufferAna_fx, 0, FFTLEN ); move16(); set16_fx( hFdCngCom->olapBufferSynth, 0, FFTLEN ); hFdCngCom->olapBufferSynth2 = NULL; move16(); /* Initialize the comfort noise generation */ set32_fx( hFdCngCom->fftBuffer, 0, FFTLEN ); set32_fx( hFdCngCom->cngNoiseLevel, 0, FFTCLDFBLEN ); set16_fx( &hFdCngCom->cngNoiseLevelExp, 0, 1 ); /* Initialize quantizer */ set32_fx( hFdCngCom->sidNoiseEst, 0, NPART ); set16_fx( &hFdCngCom->sidNoiseEstExp, 0, 1 ); set16_fx( hFdCngCom->A_cng, 0, M + 1 ); hFdCngCom->A_cng[0] = 4096 /*1.f Q12*/; /* 3Q12 */ move16(); /* Set some counters and flags */ hFdCngCom->inactive_frame_counter = 0; /* Either SID or zero frames */ move16(); hFdCngCom->active_frame_counter = 0; move16(); hFdCngCom->frame_type_previous = ACTIVE_FRAME; move16(); hFdCngCom->flag_noisy_speech = 0; move16(); hFdCngCom->likelihood_noisy_speech = 0; move16(); hFdCngCom->numCoreBands = 0; move16(); hFdCngCom->stopBand = 0; move16(); hFdCngCom->startBand = 0; move16(); hFdCngCom->stopFFTbin = 0; move16(); hFdCngCom->frameSize = 0; move16(); hFdCngCom->fftlen = 0; move16(); hFdCngCom->seed = 0; move16(); hFdCngCom->seed2 = 1; move16(); hFdCngCom->seed3 = 2; move16(); hFdCngCom->CngBitrate = -1; move16(); /* Initialize noise estimation algorithm */ set32_fx( hFdCngCom->periodog, 0, PERIODOGLEN ); mhvals( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win ) ); mhvals( MSSUBFRLEN, &( hFdCngCom->msM_subwin ) ); set32_fx( hFdCngCom->msPeriodogSum, 0, 2 ); hFdCngCom->msPeriodogSum_exp[0] = 0; move16(); hFdCngCom->msPeriodogSum_exp[1] = 0; move16(); set32_fx( hFdCngCom->msPsdSum, 0, 2 ); set16_fx( hFdCngCom->msSlope, 0, 2 ); set32_fx( hFdCngCom->msQeqInvAv, 0, 2 ); hFdCngCom->msQeqInvAv_exp[0] = 0; move16(); hFdCngCom->msQeqInvAv_exp[1] = 0; move16(); hFdCngCom->msFrCnt_init_counter = 0; move16(); hFdCngCom->msFrCnt_init_thresh = 1; move16(); hFdCngCom->init_old = 0; move16(); hFdCngCom->offsetflag = 0; move16(); hFdCngCom->msFrCnt = MSSUBFRLEN; move16(); hFdCngCom->msMinBufferPtr = 0; move16(); hFdCngCom->msAlphaCor[0] = 644245120l /*0.3f Q31*/; move16(); hFdCngCom->msAlphaCor[1] = 644245120l /*0.3f Q31*/; move16(); set16_fx( hFdCngCom->psize, 0, NPART ); /* Initialize exponents */ hFdCngCom->exp_cldfb_periodog = 0; move16(); hFdCngCom->coherence_fx = 16384; /* 0.5 in Q15 */ move16(); set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN ); set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); set32_fx( hFdCngCom->exc_cng_32fx, 0, L_FRAME16k ); hFdCngCom->likelihood_noisy_speech_32fx = 0; move32(); return; } #endif void initFdCngCom(HANDLE_FD_CNG_COM hFdCngCom, Word16 scale) { /* Calculate CLDFB scaling factor */ Loading Loading @@ -1699,6 +1814,70 @@ void apply_scale( } #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * apply_scale_ind() * * Apply bitrate-dependent scale * returns index of scaleTable *-------------------------------------------------------------------*/ Word16 apply_scale_ind( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ const SCALE_SETUP *scaleTable, /* i : Scale table */ const Word16 scaleTableSize /* i : Size of scale table */ ) { Word16 i; // PMT("Verifiy if the basop ued are ok for stereo too") FOR(i = 0; i < scaleTableSize; i++) { cast16(); IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, L_sub(bitrate, scaleTable[i].bitrateTo) < 0))) { BREAK; } } { *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); } return i; } void apply_scale_ivas_fx( Word32 *scale, /* o : scalefactor */ const Word16 bwmode, /* i : audio bandwidth */ const Word32 bitrate, /* i : Bit rate */ const SCALE_SETUP* scaleTable, /* i : Scale table */ const Word16 scaleTableSize, /* i : Size of scale table */ Word16 *index ) { Word16 i; //PMT("Verifiy if the basop ued are ok for stereo too") FOR(i = 0; i < scaleTableSize; i++) { cast16(); IF(s_and((Word16)EQ_16(bwmode, (Word16)scaleTable[i].bwmode), s_and(L_sub(bitrate, scaleTable[i].bitrateFrom) >= 0, L_sub(bitrate, scaleTable[i].bitrateTo) < 0)) ) { BREAK; } } assert(i < scaleTableSize); *scale = L_add(*scale, L_deposit_h(scaleTable[i].scale)); *index = i; } #endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * bandcombinepow() * Loading