diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 0e528f9f3af42a04ec8a3ad612476421a8a7528d..0080f41257f0537b1303b9d87237a88abd121e76 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7694,10 +7694,10 @@ void fd_bwe_dec_init( void hq_core_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *audio_fx, /* i : input audio signal Q0 */ - const Word16 input_frame, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 input_frame, /* i : frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ ); // hq_core_dec_fx.c diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 2988a8fb847696a49d359953e79c31dd6abdf460..1d330ac49a8a08bbdbad58155b603f78d4caa5c6 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -622,6 +622,16 @@ void gain_enc_mless_ivas_fx( /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ L_tmp = Dot_product12( code, code, L_SUBFR, &exp_code ); exp_inov = sub( exp_code, 18 + 6 ); + + // To avoid crash in case code value is 0 + IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_tmp, exp_inov, 21474836, 0 ), -1 ) ) + { + L_tmp = 21474836; + exp_inov = 0; + move32(); + move16(); + } + exp_code = sub( exp_code, 30 ); /*Ei = 10 * log10((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index b63ebeb3af9c631cb03c53907e5d3824c2a4b17b..0259ef9ffdbe151f2896304f54cfedd2e2dafcff 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -28,10 +28,10 @@ * Local functions *-----------------------------------------------------------------*/ -void hvq_classifier_fx( const Word32 *input, Word16 *prev_Npeaks, Word16 *prev_peaks, Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, const Word16 last_core, Word32 *L_nf_gains, Word16 *hvq_hangover, Word32 *L_pe_gains ); +void hvq_classifier_fx( const Word32 *input /*Q12*/, Word16 *prev_Npeaks, Word16 *prev_peaks, Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, const Word16 last_core, Word32 *L_nf_gains /*Q12*/, Word16 *hvq_hangover, Word32 *L_pe_gains /*Q12*/ ); static Word16 hf_spectrum_sparseness_fx( Encoder_State *st, /* i/o: encoder state structure */ - const Word32 *coefs_fx /* i : MDCT spectrum */ + const Word32 *coefs_fx /* i : MDCT spectrum Q12*/ ); /*--------------------------------------------------------------------------* * hf_spectrum_sparseness() @@ -64,8 +64,8 @@ static Word16 hf_spectrum_sparseness_fx( Word16 inv_rms32_e = 0; move16(); - crest_lp_fx = &st->hHQ_core->crest_lp_fx; - crest_mod_lp_fx = &st->hHQ_core->crest_mod_lp_fx; + crest_lp_fx = &st->hHQ_core->crest_lp_fx; /* &st->hHQ_core->crest_lp_q */ + crest_mod_lp_fx = &st->hHQ_core->crest_mod_lp_fx; /* &st->hHQ_core->crest_mod_lp_q */ result = TRUE; move16(); @@ -74,7 +74,7 @@ static Word16 hf_spectrum_sparseness_fx( FOR( i = 0; i < L_SPEC_HB; i++ ) { - A_fx[i] = L_abs( coefs_fx[i + L_SPEC_HB] ); + A_fx[i] = L_abs( coefs_fx[i + L_SPEC_HB] ); /* Q12 */ move32(); } low_count_fx = 0; @@ -88,24 +88,25 @@ static Word16 hf_spectrum_sparseness_fx( IF( Amax_fx == 0 ) { /* For all-zero input the crest is 1.0 */ - crest_fx = L_shl( 1, st->hHQ_core->crest_lp_q ); - crest_mod_fx = L_shl( 1, st->hHQ_core->crest_mod_lp_q ); + crest_fx = L_shl( 1, st->hHQ_core->crest_lp_q ); /* &st->hHQ_core->crest_lp_q */ + crest_mod_fx = L_shl( 1, st->hHQ_core->crest_mod_lp_q ); /* &st->hHQ_core->crest_mod_lp_q */ low_count_fx = 0; move16(); } ELSE { #endif - thr_fx = Mpy_32_32( Amax_fx, PEAK_THRESHOLD_FX ); - movmean_fx = 0; /* avoid uninitialized warning */ - // p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ - p_num_fx = &inv_tbl_fx[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ + thr_fx = Mpy_32_32( Amax_fx, PEAK_THRESHOLD_FX ); /* Q12 */ + movmean_fx = 0; /* avoid uninitialized warning */ + move32(); + // p_num = &inv_tbl[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) */ + p_num_fx = &inv_tbl_fx[HALF_WIN_LENGTH + 1]; /* Table for division 1./(11:21) Q15*/ FOR( i = 0; i < L_SPEC_HB; i++ ) { // inv_rms += A[i] * A[i]; - inv_rms_fx = W_add( inv_rms_fx, W_shr( W_mult0_32_32( A_fx[i], A_fx[i] ), Q9 ) ); // 2*Q12 -Q9 (Q9 for guard bits + inv_rms_fx = W_add( inv_rms_fx, W_shr( W_mult0_32_32( A_fx[i], A_fx[i] ), Q9 ) ); // 2*Q12 -Q9 (Q9 for guard bits) Q15 - if ( LT_32( A_fx[i], thr_fx ) ) + IF( LT_32( A_fx[i], thr_fx ) ) { low_count_fx = add( low_count_fx, 1 ); } @@ -136,27 +137,27 @@ static Word16 hf_spectrum_sparseness_fx( } } - if ( LT_32( crest_mod_fx, movmean_fx ) ) + IF( LT_32( crest_mod_fx, movmean_fx ) ) { crest_mod_fx = movmean_fx; // Q12 move32(); } } Word16 l_shift = W_norm( inv_rms_fx ); - inv_rms32_fx = W_extract_h( W_shl( inv_rms_fx, l_shift ) ); // Q15+l_shift-32 - Word16 q_rms = sub( add( Q15, l_shift ), 32 ); // q_rms - inv_rms32_div_fx = BASOP_Util_Divide3232_Scale_cadence( inv_rms32_fx, L_SPEC_HB, &inv_rms32_e ); + inv_rms32_fx = W_extract_h( W_shl( inv_rms_fx, l_shift ) ); // Q15+l_shift-32 + Word16 q_rms = sub( add( Q15, l_shift ), 32 ); // q_rms + inv_rms32_div_fx = BASOP_Util_Divide3232_Scale_cadence( inv_rms32_fx, L_SPEC_HB, &inv_rms32_e ); /* Q31-inv_rms32_e */ inv_rms32_e = sub( 31, add( sub( Q31, inv_rms32_e ), q_rms ) ); // inv_rms = 1.0f / (float) sqrtf( inv_rms / L_SPEC_HB ); - inv_rms32_fx = ISqrt32( inv_rms32_div_fx, &inv_rms32_e ); + inv_rms32_fx = ISqrt32( inv_rms32_div_fx, &inv_rms32_e ); /* Q31-inv_rms32_e */ - crest_fx = Mpy_32_32( Amax_fx, inv_rms32_fx ); // Q12 + (Q31-inv_rms32_e) -Q31 = Q12 - inv_rms32_e - crest_mod_fx = Mpy_32_32( crest_mod_fx, inv_rms32_fx ); // Q12 + (Q31-inv_rms32_e) -Q31 = Q12 - inv_rms32_e - *crest_lp_fx = L_shr( *crest_lp_fx, sub( st->hHQ_core->crest_lp_q, sub( Q12, inv_rms32_e ) ) ); + crest_fx = Mpy_32_32( Amax_fx, inv_rms32_fx ); // Q12 + (Q31-inv_rms32_e) -Q31 = Q12 - inv_rms32_e + crest_mod_fx = Mpy_32_32( crest_mod_fx, inv_rms32_fx ); // Q12 + (Q31-inv_rms32_e) -Q31 = Q12 - inv_rms32_e + *crest_lp_fx = L_shr( *crest_lp_fx, sub( st->hHQ_core->crest_lp_q, sub( Q12, inv_rms32_e ) ) ); /* Q12-inv_rms32_e */ move32(); st->hHQ_core->crest_lp_q = sub( Q12, inv_rms32_e ); move16(); - *crest_mod_lp_fx = L_shr( *crest_mod_lp_fx, sub( st->hHQ_core->crest_mod_lp_q, sub( Q12, inv_rms32_e ) ) ); + *crest_mod_lp_fx = L_shr( *crest_mod_lp_fx, sub( st->hHQ_core->crest_mod_lp_q, sub( Q12, inv_rms32_e ) ) ); /* Q12-inv_rms32_e */ move32(); st->hHQ_core->crest_mod_lp_q = sub( Q12, inv_rms32_e ); move16(); @@ -179,7 +180,7 @@ static Word16 hf_spectrum_sparseness_fx( } } - return result; + return result; /* Q0 */ } /*--------------------------------------------------------------------------* * hq_classifier_enc_fx() @@ -216,7 +217,8 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits IF( EQ_16( length, L_FRAME32k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); + *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ + move16(); /* Detect harmonic VQ mode HQ_HVQ */ hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, @@ -229,7 +231,8 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits IF( EQ_16( length, L_FRAME48k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); + *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ + move16(); /* Detect harmonic VQ mode HQ_HVQ */ hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains ); @@ -239,7 +242,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits test(); IF( EQ_16( length, L_FRAME48k ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) { - *hqswb_clas = HQ_GEN_FB; + *hqswb_clas = HQ_GEN_FB; /* Q0 */ move16(); } @@ -276,7 +279,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits test(); IF( EQ_16( *hqswb_clas, HQ_NORMAL ) && EQ_16( length, L_FRAME32k ) && LE_32( st_fx->core_brate, HQ_32k ) ) { - *hqswb_clas = HQ_GEN_SWB; + *hqswb_clas = HQ_GEN_SWB; /* Q0 */ move16(); } #else @@ -289,7 +292,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits max_brate = HQ_32k; move32(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { max_brate = HQ_48k; move32(); @@ -320,6 +323,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits harmonic_decision = hf_spectrum_sparseness( st, coefs ); #else harmonic_decision = 0; + move16(); #endif test(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && !harmonic_decision ) @@ -391,12 +395,12 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi move32(); } - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ bits = 1; move16(); IF( EQ_16( is_transient, 1 ) ) { - *hqswb_clas = HQ_TRANSIENT; + *hqswb_clas = HQ_TRANSIENT; /* Q0 */ move16(); } @@ -410,7 +414,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi IF( !is_transient && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_ivas_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); + *hqswb_clas = peak_avrg_ratio_ivas_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ harmonic_decision = hf_spectrum_sparseness_fx( st_fx, coefs ); @@ -418,7 +422,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi test(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && !harmonic_decision ) { - *hqswb_clas = HQ_NORMAL; + *hqswb_clas = HQ_NORMAL; /* Q0 */ move16(); } ELSE @@ -443,17 +447,17 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi { 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(); } } - return bits; + return bits; /* Q0 */ } /*--------------------------------------------------------------------------* * peak_avrg_ratio() @@ -461,9 +465,9 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi * Classify the input signal and decide if it has a harmonic structure *--------------------------------------------------------------------------*/ Word16 peak_avrg_ratio_ivas_fx( - const Word32 total_brate, /* i : total bitrate */ + const Word32 total_brate, /* i : total bitrate Q0*/ const Word32 *input_hi_fx, /* i : input signal Q_coeff */ - const Word16 length, /* i : number of coefficients */ + const Word16 length, /* i : number of coefficients Q0*/ Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ) @@ -488,6 +492,7 @@ Word16 peak_avrg_ratio_ivas_fx( k1 = 0; move16(); q = 96; /* q used for indexing */ + move16(); FOR( i = 3; i < 17; i++ ) { @@ -500,11 +505,12 @@ Word16 peak_avrg_ratio_ivas_fx( input_abs_fx[q] = L_shr( input_abs_fx[q], 5 ); /*Q_coeff-5 */ move32(); mean_fx = L_add( mean_fx, input_abs_fx[q] ); /*Q_coeff-5 */ - IF( GT_32( input_abs_fx[q], peak_fx ) ) + if ( GT_32( input_abs_fx[q], peak_fx ) ) { peak_fx = input_abs_fx[q]; /*Q_coeff-5 */ + move32(); } - q = add( q, 1 ); + q += 1; } IF( LT_16( i, 8 ) ) @@ -528,26 +534,30 @@ Word16 peak_avrg_ratio_ivas_fx( test(); IF( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) { - if ( LT_16( *mode_count, 8 ) ) + IF( LT_16( *mode_count, 8 ) ) { *mode_count = add( *mode_count, 1 ); + move16(); } - if ( *mode_count1 > 0 ) + IF( *mode_count1 > 0 ) { *mode_count1 = sub( *mode_count1, 1 ); + move16(); } } ELSE { - if ( LT_16( *mode_count1, 8 ) ) + IF( LT_16( *mode_count1, 8 ) ) { *mode_count1 = add( *mode_count1, 1 ); + move16(); } - if ( *mode_count > 0 ) + IF( *mode_count > 0 ) { *mode_count = sub( *mode_count, 1 ); + move16(); } } @@ -558,12 +568,12 @@ Word16 peak_avrg_ratio_ivas_fx( test(); test(); - if ( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && LT_32( total_brate, HQ_BWE_CROSSOVER_BRATE ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) + IF( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && LT_32( total_brate, HQ_BWE_CROSSOVER_BRATE ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) { hqswb_clas = HQ_HARMONIC; move16(); } - return hqswb_clas; + return hqswb_clas; /* Q0 */ } /*--------------------------------------------------------------------------* * peak_avrg_ratio() @@ -571,11 +581,11 @@ Word16 peak_avrg_ratio_ivas_fx( * Classify the input signal and decide if it has a harmonic structure *--------------------------------------------------------------------------*/ Word16 peak_avrg_ratio_fx( - const Word32 total_brate, /* i : total bitrate */ - const Word32 *input_hi_fx, /* i : input signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + const Word32 total_brate, /* i : total bitrate Q0*/ + const Word32 *input_hi_fx, /* i : input signal Q_coeff*/ + const Word16 length, /* i : number of coefficients Q0*/ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ) { Word16 i, j, q, k, k1, hqswb_clas; @@ -585,7 +595,7 @@ Word16 peak_avrg_ratio_fx( FOR( i = 96; i < length; i++ ) { - input_abs_fx[i] = L_abs( input_hi_fx[i] ); + input_abs_fx[i] = L_abs( input_hi_fx[i] ); /* Q_coeff */ } hqswb_clas = HQ_NORMAL; @@ -597,6 +607,7 @@ Word16 peak_avrg_ratio_fx( k1 = 0; move16(); q = 96; /* q used for indexing */ + move16(); FOR( i = 3; i < 17; i++ ) { @@ -607,12 +618,14 @@ Word16 peak_avrg_ratio_fx( FOR( j = 0; j < 32; j++ ) { input_abs_fx[q] = L_shr( input_abs_fx[q], 5 ); /*Q_coeff-5 */ - mean_fx = L_add( mean_fx, input_abs_fx[q] ); /*Q_coeff-5 */ - IF( GT_32( input_abs_fx[q], peak_fx ) ) + move32(); + mean_fx = L_add( mean_fx, input_abs_fx[q] ); /*Q_coeff-5 */ + if ( GT_32( input_abs_fx[q], peak_fx ) ) { peak_fx = input_abs_fx[q]; /*Q_coeff-5 */ + move32(); } - q++; + q += 1; } IF( LT_16( i, 8 ) ) @@ -636,26 +649,30 @@ Word16 peak_avrg_ratio_fx( test(); IF( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) { - if ( LT_16( *mode_count, 8 ) ) + IF( LT_16( *mode_count, 8 ) ) { *mode_count = add( *mode_count, 1 ); + move16(); } - if ( *mode_count1 > 0 ) + IF( *mode_count1 > 0 ) { *mode_count1 = sub( *mode_count1, 1 ); + move16(); } } ELSE { - if ( LT_16( *mode_count1, 8 ) ) + IF( LT_16( *mode_count1, 8 ) ) { *mode_count1 = add( *mode_count1, 1 ); + move16(); } - if ( *mode_count > 0 ) + IF( *mode_count > 0 ) { *mode_count = sub( *mode_count, 1 ); + move16(); } } @@ -666,7 +683,7 @@ Word16 peak_avrg_ratio_fx( test(); test(); #ifndef SOLVED_COMP_ENC_DEC /*This affect BE even if it shouldn't*/ - if ( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && EQ_32( total_brate, HQ_24k40 ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) + IF( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && EQ_32( total_brate, HQ_24k40 ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) #else if ( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && LT_32( total_brate, HQ_BWE_CROSSOVER_BRATE ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) #endif @@ -675,7 +692,7 @@ Word16 peak_avrg_ratio_fx( move16(); } - return hqswb_clas; + return hqswb_clas; /* Q0 */ } /*--------------------------------------------------------------------------* @@ -738,19 +755,19 @@ void hvq_classifier_ivas_fx( { nsub = HVQ_NSUB_24k; move16(); - inv_nsub = 4681; - move16(); /* 1/7 in Q15 */ - inv_gains_nsub = 10923; - move16(); /* 1/3 in Q15 */ + inv_nsub = 4681; /* 1/7 in Q15 */ + move16(); + inv_gains_nsub = 10923; /* 1/3 in Q15 */ + move16(); } ELSE { nsub = HVQ_NSUB_32k; move16(); - inv_nsub = 3277; - move16(); /* 1/10 in Q15 */ - inv_gains_nsub = 6554; - move16(); /* 1/5 in Q15 */ + inv_nsub = 3277; /* 1/10 in Q15 */ + move16(); + inv_gains_nsub = 6554; /* 1/5 in Q15 */ + move16(); } N = shl( nsub, 5 ); /* Mult by 32 (HVQ_BW) */ @@ -761,10 +778,11 @@ void hvq_classifier_ivas_fx( { FOR( i = 0; i < N; i++ ) { - L_input_abs[i] = L_abs( input[i] ); - if ( L_input_abs[i] > L_input_max ) + L_input_abs[i] = L_abs( input[i] ); /* Q12 */ + move16(); + IF( GT_32( L_input_abs[i], L_input_max ) ) { - L_input_max = L_input_abs[i]; + L_input_max = L_input_abs[i]; /* Q12 */ move16(); } } @@ -773,10 +791,10 @@ void hvq_classifier_ivas_fx( *Npeaks = 0; move16(); - L_nf = 3276800; - move32(); /* 800 in Q12 */ - L_pe = 3276800; - move32(); /* 800 in Q12 */ + L_nf = 3276800; /* 800 in Q12 */ + move32(); + L_pe = 3276800; /* 800 in Q12 */ + move32(); num_sharp_bands = 0; move16(); k = 0; @@ -798,7 +816,7 @@ void hvq_classifier_ivas_fx( FOR( j = 0; j < HVQ_BW; j++ ) { - L_d = L_input_abs[q]; + L_d = L_input_abs[q]; /* Q12 */ IF( GT_32( L_d, L_nf ) ) { /*nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; */ @@ -830,8 +848,8 @@ void hvq_classifier_ivas_fx( } #ifdef BASOP_NOGLOB - L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); - L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); + L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); /*Q12 */ + L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); /*Q12 */ #else L_nf_mean[i] = L_add( L_nf_mean[i], L_nf ); L_pe_mean[i] = L_add( L_pe_mean[i], L_pe ); @@ -843,7 +861,7 @@ void hvq_classifier_ivas_fx( L_peak = L_add( L_d, 0 ); } - q = add( q, 1 ); + q += 1; } L_nf_mean[i] = L_shr( L_nf_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ L_pe_mean[i] = L_shr( L_pe_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ @@ -886,7 +904,7 @@ void hvq_classifier_ivas_fx( move16(); /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ #ifdef BASOP_NOGLOB - sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow ); + sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow ); /* Q6 */ #else sharp_dist = add( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); #endif @@ -898,12 +916,12 @@ void hvq_classifier_ivas_fx( /* Estimate noise floor gains */ offset = s_and( nsub, 1 ); - FOR( i = 0; i < s_and( nsub, (Word16) 0xFFFE ); i++ ) + FOR( i = 0; i < ( nsub & (Word16) 0xFFFE ); i++ ) { /*(2*i+1)/nsub */ - idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ - L_nf_gains[idx] = L_add( L_nf_gains[idx], L_nf_mean[i + offset] ); - L_pe_gains[idx] = L_add( L_pe_gains[idx], L_pe_mean[i + offset] ); + idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ + L_nf_gains[idx] = L_add( L_nf_gains[idx], L_nf_mean[i + offset] ); /* Q12 */ + L_pe_gains[idx] = L_add( L_pe_gains[idx], L_pe_mean[i + offset] ); /* Q12 */ move32(); move32(); } @@ -917,7 +935,7 @@ void hvq_classifier_ivas_fx( /* Allocate available peaks */ FOR( i = 0; i < nsub; i++ ) { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; + avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; /* Q0 */ move16(); idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ Mpy_32_16_ss( L_nf_gains[idx], HVQ_PA_FAC_FX, &L_tmp, &lsb ); /* 12+15-15 -> Q12 */ @@ -925,12 +943,12 @@ void hvq_classifier_ivas_fx( { IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES3_FX ) ) { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; + avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; /* Q0 */ move16(); } ELSE IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES2_FX ) ) { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; + avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; /* Q0 */ move16(); } } @@ -940,9 +958,9 @@ void hvq_classifier_ivas_fx( /* Adjust threshold around previous peaks */ FOR( i = 0; i < *prev_Npeaks; i++ ) { - j = sub( prev_peaks[i], 2 ); - k = add( prev_peaks[i], 2 ); - p_adj = hvq_thr_adj_fx; + j = sub( prev_peaks[i], 2 ); /* Q0 */ + k = add( prev_peaks[i], 2 ); /* Q0 */ + p_adj = hvq_thr_adj_fx; /* Q15 */ FOR( q = j; q < k; q++ ) { @@ -973,16 +991,16 @@ void hvq_classifier_ivas_fx( } ELSE { - L_input_abs[num_peak_cands] = L_input_abs[i]; + L_input_abs[num_peak_cands] = L_input_abs[i]; /* Q12 */ move32(); - peak_cand_idx[num_peak_cands] = i; + peak_cand_idx[num_peak_cands] = i; /* Q0 */ move16(); num_peak_cands = add( num_peak_cands, 1 ); } } - peak_th = (Word16) BASOP_Util_Divide3232_Scale( L_add( W_extract_l( W_mult0_32_32( L_core_brate, HVQ_PEAKS_PER_DELTA_THR ) ), HVQ_PEAKS_PER_DELTA_THR_OFFS ), HVQ_PEAKS_BPS_DELTA, &temp_e ); + peak_th = extract_l( BASOP_Util_Divide3232_Scale( L_add( W_extract_l( W_mult0_32_32( L_core_brate, HVQ_PEAKS_PER_DELTA_THR ) ), HVQ_PEAKS_PER_DELTA_THR_OFFS ), HVQ_PEAKS_BPS_DELTA, &temp_e ) ); peak_th = shr( peak_th, sub( 15, temp_e ) ); /* Find peaks */ pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); @@ -994,7 +1012,7 @@ void hvq_classifier_ivas_fx( idx = mult( peak_cand_idx[pindx], INV_HVQ_BW ); /* 0+15-15=0 */ IF( avail_peaks[idx] > 0 ) { - peaks[i++] = peak_cand_idx[pindx]; + peaks[i++] = peak_cand_idx[pindx]; /* Q0 */ avail_peaks[idx]--; } @@ -1055,7 +1073,7 @@ void hvq_classifier_ivas_fx( pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); } - *Npeaks = i; + *Npeaks = i; /* Q0 */ move16(); IF( GT_16( *Npeaks, HVQ_MIN_PEAKS ) ) { @@ -1066,28 +1084,28 @@ void hvq_classifier_ivas_fx( test(); IF( LE_16( sharp_dist, SHARP_DIST_THRES_FX ) && *hvq_hangover < 0 ) { - *hvq_hangover = add( *hvq_hangover, 1 ); + *hvq_hangover = add( *hvq_hangover, 1 ); /* Q0 */ } ELSE { - *hqswb_clas = HQ_HVQ; + *hqswb_clas = HQ_HVQ; /* Q0 */ move16(); - *hvq_hangover = 2; + *hvq_hangover = 2; /* Q0 */ move16(); } /* update memory */ - *prev_Npeaks = *Npeaks; + *prev_Npeaks = *Npeaks; /* Q0 */ move16(); - Copy( peaks, prev_peaks, *Npeaks ); + Copy( peaks, prev_peaks, *Npeaks ); /* Q0 */ } ELSE { IF( *hvq_hangover > 0 ) { - *hqswb_clas = HQ_HVQ; + *hqswb_clas = HQ_HVQ; /* Q0 */ move16(); - *hvq_hangover = sub( *hvq_hangover, 1 ); + *hvq_hangover = sub( *hvq_hangover, 1 ); /* Q0 */ move16(); } ELSE @@ -1110,6 +1128,7 @@ void hvq_classifier_ivas_fx( Word16 Npeaks_temp = *Npeaks; *Npeaks = BASOP_Util_Divide3232_Scale( L_add( W_extract_l( W_mult0_32_32( L_core_brate, HVQ_PEAKS_PER_DELTA ) ), HVQ_PEAKS_PER_DELTA_OFFS ), HVQ_PEAKS_BPS_DELTA, &temp_e ); *Npeaks = s_min( shr( *Npeaks, sub( 15, temp_e ) ), Npeaks_temp ); + move16(); } ELSE { @@ -1167,6 +1186,7 @@ void hvq_classifier_fx( Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_input_max = L_deposit_l( 0 ); set32_fx( L_thr, 0, L_FRAME16k ); @@ -1179,19 +1199,19 @@ void hvq_classifier_fx( { nsub = HVQ_NSUB_24k; move16(); - inv_nsub = 4681; - move16(); /* 1/7 in Q15 */ - inv_gains_nsub = 10923; - move16(); /* 1/3 in Q15 */ + inv_nsub = 4681; /* 1/7 in Q15 */ + move16(); + inv_gains_nsub = 10923; /* 1/3 in Q15 */ + move16(); } ELSE { nsub = HVQ_NSUB_32k; move16(); - inv_nsub = 3277; - move16(); /* 1/10 in Q15 */ - inv_gains_nsub = 6554; - move16(); /* 1/5 in Q15 */ + inv_nsub = 3277; /* 1/10 in Q15 */ + move16(); + inv_gains_nsub = 6554; /* 1/5 in Q15 */ + move16(); } N = shl( nsub, 5 ); /* Mult by 32 (HVQ_BW) */ @@ -1202,10 +1222,10 @@ void hvq_classifier_fx( { FOR( i = 0; i < N; i++ ) { - L_input_abs[i] = L_abs( input[i] ); - if ( L_input_abs[i] > L_input_max ) + L_input_abs[i] = L_abs( input[i] ); /* Q12 */ + IF( GT_32( L_input_abs[i], L_input_max ) ) { - L_input_max = L_input_abs[i]; + L_input_max = L_input_abs[i]; /* Q12 */ move16(); } } @@ -1214,10 +1234,10 @@ void hvq_classifier_fx( *Npeaks = 0; move16(); - L_nf = 3276800; - move32(); /* 800 in Q12 */ - L_pe = 3276800; - move32(); /* 800 in Q12 */ + L_nf = 3276800; /* 800 in Q12 */ + move32(); + L_pe = 3276800; /* 800 in Q12 */ + move32(); num_sharp_bands = 0; move16(); k = 0; @@ -1233,9 +1253,13 @@ void hvq_classifier_fx( L_peak = 0; L_nf_mean[i] = 0; L_pe_mean[i] = 0; + move32(); + move32(); + move32(); FOR( j = 0; j < HVQ_BW; j++ ) { - L_d = L_input_abs[q]; + L_d = L_input_abs[q]; /* Q12 */ + move32(); IF( GT_32( L_d, L_nf ) ) { /*nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; */ @@ -1267,8 +1291,10 @@ void hvq_classifier_fx( } #ifdef BASOP_NOGLOB - L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); - L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); + L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); /*Q12 */ + L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); /*Q12 */ + move32(); + move32(); #else L_nf_mean[i] = L_add( L_nf_mean[i], L_nf ); L_pe_mean[i] = L_add( L_pe_mean[i], L_pe ); @@ -1278,10 +1304,12 @@ void hvq_classifier_fx( L_peak = L_add( L_d, 0 ); } - q = add( q, 1 ); + q += 1; } L_nf_mean[i] = L_shr( L_nf_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ L_pe_mean[i] = L_shr( L_pe_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ + move32(); + move32(); /*thr_tmp = (float)pow( pe_mean[i]/nf_mean[i], HVQ_THR_POW ) * nf_mean[i]; */ exp1 = norm_l( L_nf_mean[i] ); @@ -1317,6 +1345,7 @@ void hvq_classifier_fx( Mpy_32_16_ss( L_peak, inv_nf_mean, &L_tmp, &lsb ); /* 12+33-s-15=30-s */ shift = sub( exp1, 8 ); sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */ + move16(); /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ #ifdef BASOP_NOGLOB @@ -1324,7 +1353,7 @@ void hvq_classifier_fx( #else sharp_dist = add( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); #endif - if ( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) + IF( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) { num_sharp_bands = add( num_sharp_bands, 1 ); } @@ -1332,12 +1361,14 @@ void hvq_classifier_fx( /* Estimate noise floor gains */ offset = s_and( nsub, 1 ); - FOR( i = 0; i < s_and( nsub, (Word16) 0xFFFE ); i++ ) + FOR( i = 0; i < ( nsub & (Word16) 0xFFFE ); i++ ) { /*(2*i+1)/nsub */ idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ L_nf_gains[idx] = L_add( L_nf_gains[idx], L_nf_mean[i + offset] ); L_pe_gains[idx] = L_add( L_pe_gains[idx], L_pe_mean[i + offset] ); + move32(); + move32(); } FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) @@ -1372,9 +1403,10 @@ void hvq_classifier_fx( /* Adjust threshold around previous peaks */ FOR( i = 0; i < *prev_Npeaks; i++ ) { - j = sub( prev_peaks[i], 2 ); - k = add( prev_peaks[i], 2 ); - p_adj = hvq_thr_adj_fx; + j = sub( prev_peaks[i], 2 ); /* Q0 */ + k = add( prev_peaks[i], 2 ); /* Q0 */ + p_adj = hvq_thr_adj_fx; /* Q15 */ + move16(); FOR( q = j; q < k; q++ ) { @@ -1391,17 +1423,22 @@ void hvq_classifier_fx( L_input_abs[1] = L_deposit_l( 0 ); L_input_abs[N - 2] = L_deposit_l( 0 ); L_input_abs[N - 1] = L_deposit_l( 0 ); + move32(); + move32(); + move32(); + move32(); FOR( i = 0; i < N - 2; i++ ) { IF( LT_32( L_input_abs[i], L_thr[i] ) ) { L_input_abs[i] = L_deposit_l( 0 ); + move32(); } ELSE { - L_input_abs[num_peak_cands] = L_input_abs[i]; + L_input_abs[num_peak_cands] = L_input_abs[i]; /* Q12 */ move32(); - peak_cand_idx[num_peak_cands] = i; + peak_cand_idx[num_peak_cands] = i; /* Q0 */ move16(); num_peak_cands = add( num_peak_cands, 1 ); } @@ -1430,7 +1467,8 @@ void hvq_classifier_fx( idx = mult( peak_cand_idx[pindx], INV_HVQ_BW ); /* 0+15-15=0 */ IF( avail_peaks[idx] > 0 ) { - peaks[i++] = peak_cand_idx[pindx]; + peaks[i++] = peak_cand_idx[pindx]; /* Q0 */ + move16(); avail_peaks[idx]--; } @@ -1460,7 +1498,7 @@ void hvq_classifier_fx( } tmp = sub( N, 1 ); - if ( GT_16( high, tmp ) ) + IF( GT_16( high, tmp ) ) { high = tmp; move16(); @@ -1488,7 +1526,7 @@ void hvq_classifier_fx( } } - pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); + pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); /* Q0 */ } *Npeaks = i; @@ -1506,24 +1544,24 @@ void hvq_classifier_fx( } ELSE { - *hqswb_clas = HQ_HVQ; + *hqswb_clas = HQ_HVQ; /* Q0 */ move16(); - *hvq_hangover = 2; + *hvq_hangover = 2; /* Q0 */ move16(); } /* update memory */ - *prev_Npeaks = *Npeaks; + *prev_Npeaks = *Npeaks; /* Q0 */ move16(); - Copy( peaks, prev_peaks, *Npeaks ); + Copy( peaks, prev_peaks, *Npeaks ); /* Q0 */ } ELSE { IF( *hvq_hangover > 0 ) { - *hqswb_clas = HQ_HVQ; + *hqswb_clas = HQ_HVQ; /* Q0 */ move16(); - *hvq_hangover = sub( *hvq_hangover, 1 ); + *hvq_hangover = sub( *hvq_hangover, 1 ); /* Q0 */ move16(); } ELSE @@ -1543,12 +1581,12 @@ void hvq_classifier_fx( #ifndef ADD_IVAS_HQ_CODE IF( EQ_32( L_core_brate, HQ_24k40 ) ) { - *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); + *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); /* Q0 */ move16(); } ELSE { - *Npeaks = s_min( HVQ_MAX_PEAKS_32k, *Npeaks ); + *Npeaks = s_min( HVQ_MAX_PEAKS_32k, *Npeaks ); /* Q0 */ move16(); } #else diff --git a/lib_enc/hq_core_enc.c b/lib_enc/hq_core_enc.c index 148ef885e016235ee72ad9d4f24c367bcb3331df..07928e84dfd0a15b495d02e44f2505086504b9ec 100644 --- a/lib_enc/hq_core_enc.c +++ b/lib_enc/hq_core_enc.c @@ -54,10 +54,10 @@ void hq_core_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *audio_fx, /* i : input audio signal Q0 */ - const Word16 input_frame_orig, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 input_frame_orig, /* i : frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ ) { Word16 i, is_transient, num_bits, extra_unused; @@ -89,18 +89,19 @@ void hq_core_enc_ivas_fx( move16(); set_zero_fx( t_audio_fx, L_FRAME48k_EXT ); /* set input_frame length */ - input_frame = input_frame_orig; + input_frame = input_frame_orig; /* Q0 */ /* Sanity check, it should never happen at the encoder side (no BFI) */ IF( st->hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) { st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + move16(); } ELSE { st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode; + move16(); } - move16(); st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -110,8 +111,8 @@ void hq_core_enc_ivas_fx( * Write signaling information *--------------------------------------------------------------------------*/ - num_bits = BASOP_Util_Divide3232_Scale( st->total_brate, FRAMES_PER_SEC, &exp ); - num_bits = shr( num_bits, sub( 15, exp ) ); + num_bits = BASOP_Util_Divide3232_Scale( st->total_brate, FRAMES_PER_SEC, &exp ); /* Q15-exp */ + num_bits = shr( num_bits, sub( 15, exp ) ); /* Q0 */ extra_unused = 0; move16(); @@ -119,7 +120,7 @@ void hq_core_enc_ivas_fx( * Detect signal transition *--------------------------------------------------------------------------*/ - is_transient = detect_transient_fx( audio_fx, input_frame, 0, st ); + is_transient = detect_transient_fx( audio_fx, input_frame, 0, st ); /* Q0 */ move16(); test(); @@ -144,10 +145,10 @@ void hq_core_enc_ivas_fx( Q_audio = sub( Q16, q ); TCX_MDCT( wtda_audio_fx16, t_audio_fx, &Q_audio, left_overlap, sub( L_spec, shr( add( left_overlap, right_overlap ), 1 ) ), right_overlap, st->element_mode ); Q_audio = sub( Q31, Q_audio ); - Copy_Scale_sig_16_32( wtda_audio_fx16, wtda_audio_fx32, 2 * L_FRAME48k, sub( Q_audio, q ) ); + Copy_Scale_sig_16_32( wtda_audio_fx16, wtda_audio_fx32, 2 * L_FRAME48k, sub( Q_audio, q ) ); /* Q_audio */ - inner_frame = inner_frame_tbl[st->bwidth]; - L_spec = l_spec_ext_tbl[st->bwidth]; + inner_frame = inner_frame_tbl[st->bwidth]; /* Q0 */ + L_spec = l_spec_ext_tbl[st->bwidth]; /* Q0 */ is_transient = 0; move16(); move16(); @@ -161,14 +162,14 @@ void hq_core_enc_ivas_fx( *--------------------------------------------------------------------------*/ Q_audio = 0; move16(); - Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); - Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); /* Q0 */ + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); /* Q0 */ st->q_old_inp = 0; move16(); st->q_inp = 0; move16(); - Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); - Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); + Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); /* Q0 */ + Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); /* Q0 */ wtda_fx( two_frames_buffer + input_frame, &Q_audio, wtda_audio_fx32, NULL, 0, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, input_frame ); @@ -191,7 +192,7 @@ void hq_core_enc_ivas_fx( Word16 tmp_q = Q_audio; move16(); direct_transform_fx( wtda_audio_fx32, t_audio_fx, is_transient, input_frame, &Q_audio, st->element_mode ); - scale_sig32( wtda_audio_fx32, L_FRAME48k_EXT, sub( Q_audio, tmp_q ) ); + scale_sig32( wtda_audio_fx32, L_FRAME48k_EXT, sub( Q_audio, tmp_q ) ); /* Q_audio */ /* scale coefficients to their nominal level (8kHz) */ IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) @@ -199,17 +200,18 @@ void hq_core_enc_ivas_fx( UWord16 lsb; tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ Word16 ener_match_fx = hq_nominal_scaling[tmp]; + move16(); FOR( i = 0; i < input_frame; i++ ) { /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss( t_audio_fx[i], ener_match_fx, &t_audio_fx[i], &lsb ); - move16(); /* Q12 */ + Mpy_32_16_ss( t_audio_fx[i], ener_match_fx, &t_audio_fx[i], &lsb ); /* Q12 */ + move16(); } } /* limit encoded band-width according to the command-line OR BWD limitation */ - inner_frame = inner_frame_tbl[st->bwidth]; - L_spec = l_spec_tbl[st->bwidth]; + inner_frame = inner_frame_tbl[st->bwidth]; /* Q0 */ + L_spec = l_spec_tbl[st->bwidth]; /* Q0 */ move16(); move16(); @@ -222,7 +224,7 @@ void hq_core_enc_ivas_fx( FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { tmp = shr( inner_frame, 2 ); - Copy32( t_audio_fx + i_mult2( i, shr( input_frame, 2 ) ), t_audio_fx + i_mult2( i, tmp ), tmp ); + Copy32( t_audio_fx + i_mult2( i, shr( input_frame, 2 ) ), t_audio_fx + i_mult2( i, tmp ), tmp ); /* Q_audio */ } } @@ -232,7 +234,7 @@ void hq_core_enc_ivas_fx( /* subtract signaling bits */ - num_bits = sub( num_bits, hBstr->nb_bits_tot ); + num_bits = sub( num_bits, hBstr->nb_bits_tot ); /* Q0 */ /*-------------------------------------------------------------------------- * High-band gain control in case of BWS @@ -241,9 +243,9 @@ void hq_core_enc_ivas_fx( IF( st->bwidth_sw_cnt > 0 ) { Word32 L_tmp; - tmp = BASOP_Util_Divide1616_Scale( 3, BWS_TRAN_PERIOD, &exp ); + tmp = BASOP_Util_Divide1616_Scale( 3, BWS_TRAN_PERIOD, &exp ); /* Q15-exp */ shr( tmp, exp ); - L_tmp = L_deposit_h( tmp ); + L_tmp = L_deposit_h( tmp ); /* Q31-exp */ IF( is_transient ) { FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) @@ -315,7 +317,7 @@ void hq_core_enc_ivas_fx( test(); IF( st->element_mode > EVS_MONO && ( st->last_core == ACELP_CORE || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - overlap = st->hTcxCfg->tcx_mdct_window_length; + overlap = st->hTcxCfg->tcx_mdct_window_length; /* Q0 */ move16(); nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); @@ -349,7 +351,7 @@ void hq_core_enc_ivas_fx( /*Compute windowed synthesis in case of switching to ALDO windows in next frame*/ - Copy( wtda_audio_fx16 + sub( L_frame, nz ), st->hTcxEnc->old_out_fx, nz + overlap ); + Copy( wtda_audio_fx16 + sub( L_frame, nz ), st->hTcxEnc->old_out_fx, nz + overlap ); /* Q0 */ set16_fx( st->hTcxEnc->old_out_fx + add( nz, overlap ), 0, nz ); tcx_windowing_synthesis_past_frame( st->hTcxEnc->old_out_fx + nz, st->hTcxCfg->tcx_aldo_window_1_trunc, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, overlap, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, FULL_OVERLAP ); @@ -359,9 +361,11 @@ void hq_core_enc_ivas_fx( // This implementation is diffrent in float code need to revisit to check its correctness. st->hTcxEnc->old_out_fx[nz + overlap + i] = mult( wtda_audio_fx16[L_frame - 1 - i], st->hTcxCfg->tcx_aldo_window_1_trunc[i].v.re ); // Q0 + Q15 - Q15 -> Q0; st->hTcxEnc->old_out_fx[nz / 2 + ( nz + overlap + i )] = mult( wtda_audio_fx16[nz / 2 + ( L_frame - 1 - i )], st->hTcxCfg->tcx_aldo_window_1_trunc[nz / 2 - 1 - i].v.im ); // Q0 + Q15 - Q15 -> Q0; + move16(); + move16(); } - Copy( wtda_audio_fx16 + sub( shr( overlap, 1 ), tcx_offset ), output_fx, st->L_frame ); + Copy( wtda_audio_fx16 + sub( shr( overlap, 1 ), tcx_offset ), output_fx, st->L_frame ); /* Q0 */ } ELSE { @@ -371,12 +375,12 @@ void hq_core_enc_ivas_fx( move32(); FOR( i = 0; i < input_frame; i++ ) { - t_audio_fx[i] = Mpy_32_32( t_audio_fx[i], ener_match_fx ); - move32(); /* Q12 - 1 -> Q11 */ + t_audio_fx[i] = Mpy_32_32( t_audio_fx[i], ener_match_fx ); /* Q12 - 1 -> Q11 */ + move32(); } Q_audio = sub( Q_audio, 1 ); - scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q_audio, tmp_q ) ); + scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q_audio, tmp_q ) ); /* Q_audio */ Inverse_Transform( t_audio_fx, &Q_audio, wtda_audio_fx32, is_transient, L_FRAME16k, inner_frame, st->element_mode ); @@ -384,8 +388,8 @@ void hq_core_enc_ivas_fx( move16(); window_ola_fx( wtda_audio_fx32, output_fx, &out_q, st->hTcxEnc->old_out_fx, &old_q, L_FRAME16k, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, 0, 0, NULL ); - Scale_sig( output_fx, L_FRAME16k, negate( out_q ) ); - Scale_sig( st->hTcxEnc->old_out_fx, L_FRAME32k, negate( old_q ) ); + Scale_sig( output_fx, L_FRAME16k, negate( out_q ) ); /* Q0 */ + Scale_sig( st->hTcxEnc->old_out_fx, L_FRAME32k, negate( old_q ) ); /* Q0 */ st->hTcxEnc->Q_old_out = 0; move16(); } diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index faef4c1e0e99888c1480cef1ffcdd8d4ade86135..6dc7bb5b95f981002a28f310591ca9e2393384cb 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -19,10 +19,10 @@ void hq_core_enc_fx( Encoder_State *st_fx, const Word16 *audio, /* i : input audio signal Q0 */ - const Word16 input_frame_orig, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 input_frame_orig, /* i : frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ ) { Word16 i, is_transient, num_bits, extra_unused; @@ -31,6 +31,7 @@ void hq_core_enc_fx( Word16 Q_audio = 0; Word16 inner_frame, input_frame; Word16 ener_match; /* Q13/Q15 */ + move16(); Word16 tmp; Word32 L_tmp; @@ -52,7 +53,7 @@ void hq_core_enc_fx( move16(); /* set input_frame length */ - input_frame = input_frame_orig; + input_frame = input_frame_orig; /* Q0 */ move16(); /* Sanity check, it should never happen at the encoder side (no BFI) */ IF( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) @@ -85,13 +86,13 @@ void hq_core_enc_fx( * Detect signal transition *--------------------------------------------------------------------------*/ - is_transient = detect_transient_fx( audio, input_frame, 0, st_fx ); + is_transient = detect_transient_fx( audio, input_frame, 0, st_fx ); /* Q0 */ #ifdef ADD_IVAS_HQ_CODE test(); test(); test(); - IF( GT_16( st_fx->element_mode, EVS_MONO ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) + IF( ( st_fx->element_mode > EVS_MONO ) && ( ( st_fx->last_core == ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { /*-------------------------------------------------------------------------- * IVAS switching frame @@ -124,8 +125,8 @@ void hq_core_enc_fx( * DCT transform *--------------------------------------------------------------------------*/ - Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); - Copy( audio, two_frames_buffer + input_frame, input_frame ); + Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); /* st_fx->q_old_inp */ + Copy( audio, two_frames_buffer + input_frame, input_frame ); /* Q0 */ wtda_fx( two_frames_buffer + input_frame, &Q_audio, wtda_audio, NULL, 0, st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, input_frame ); @@ -146,7 +147,7 @@ void hq_core_enc_fx( } #ifndef ADD_IVAS_HQ_CODE /* subtract signalling bits */ - num_bits = sub( num_bits, hBstr->nb_bits_tot ); + num_bits = sub( num_bits, hBstr->nb_bits_tot ); /* Q0 */ #endif direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode ); @@ -161,17 +162,18 @@ void hq_core_enc_fx( { tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ ener_match = hq_nominal_scaling[tmp]; + move16(); FOR( i = 0; i < input_frame; i++ ) { /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss( t_audio[i], ener_match, &t_audio[i], &lsb ); - move16(); /* Q12 */ + Mpy_32_16_ss( t_audio[i], ener_match, &t_audio[i], &lsb ); /* Q12 */ + move16(); } } } /* limit encoded band-width according to the command-line OR BWD limitation */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; + inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ move16(); #ifdef ADD_IVAS_HQ_CODE_L_SPEC L_spec = l_spec_tbl[st_fx->bwidth]; @@ -185,7 +187,7 @@ void hq_core_enc_fx( { tmp = i_mult2( i, shr( input_frame, 2 ) ); tmp = shr( inner_frame, 2 ); - Copy32( t_audio + i_mult2( i, shr( input_frame, 2 ) ), t_audio + i_mult2( i, tmp ), tmp ); + Copy32( t_audio + i_mult2( i, shr( input_frame, 2 ) ), t_audio + i_mult2( i, tmp ), tmp ); /* Q12 */ } } @@ -221,6 +223,8 @@ void hq_core_enc_fx( * Classify whether to put extra bits for FER mitigation *--------------------------------------------------------------------------*/ + test(); + test(); test(); IF( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, HQ_CORE ) ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { @@ -246,6 +250,7 @@ void hq_core_enc_fx( FOR( i = 0; i < inner_frame; i++ ) { t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ + move32(); } hq_lr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); Q_audio = 12; @@ -257,6 +262,7 @@ void hq_core_enc_fx( FOR( i = 0; i < inner_frame; i++ ) { t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ + move32(); } #ifdef ADD_IVAS_HQ_CODE_L_SPEC @@ -360,8 +366,8 @@ void HQ_core_enc_init_fx( move16(); hHQ_core->prev_stab_hfe2 = 0; move16(); - hHQ_core->prev_ni_ratio_fx = 16384; - move16(); /* 0.5 */ + hHQ_core->prev_ni_ratio_fx = 16384; /* Q15 */ + move16(); /* 0.5 */ set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); set16_fx( hHQ_core->last_bitalloc_max_band, 0, 2 ); set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); @@ -370,11 +376,11 @@ void HQ_core_enc_init_fx( move16(); #ifdef MSAN_FIX - hHQ_core->crest_lp_fx = HQ_CREST_THRESHOLD_FX; + hHQ_core->crest_lp_fx = HQ_CREST_THRESHOLD_FX; /* Q28 */ move32(); hHQ_core->crest_lp_q = Q28; move16(); - hHQ_core->crest_mod_lp_fx = HQ_CREST_MOD_THRESHOLD_FX; + hHQ_core->crest_mod_lp_fx = HQ_CREST_MOD_THRESHOLD_FX; /* Q29 */ move32(); hHQ_core->crest_mod_lp_q = Q29; move16(); diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index e04489b18341d3125b69ab673755a46dc39983eb..b0875968e2c2ede803105d6d7fae94bea062f55e 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -19,7 +19,7 @@ *--------------------------------------------------------------------------------------*/ Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ const Word16 num_sfm, /* i : Number of subbands Q0 */ const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ @@ -68,12 +68,12 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { IF( GT_16( difidx[i], index_max ) ) { - index_max = difidx[i]; + index_max = difidx[i]; /* Q0 */ move16(); } IF( LT_16( difidx[i], index_min ) ) { - index_min = difidx[i]; + index_min = difidx[i]; /* Q0 */ move16(); } } @@ -82,7 +82,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); bits = add( bits, huffsizn_tran[j] ); } @@ -95,24 +95,24 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* LC mode 0 = Context based coding */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add( hcode_l, huffsizn_n[31 - j] ); + hcode_l = add( hcode_l, huffsizn_n[31 - j] ); /* Q0 */ } ELSE { IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); + hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ } ELSE { /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); + hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ } } prevj = j; @@ -136,24 +136,24 @@ Word16 encode_envelope_indices_fx( /* o : Number of b prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add( hcode_l, huffsizn_n[sub( 31, j )] ); + hcode_l = add( hcode_l, huffsizn_n[( 31 - j )] ); /* Q0 */ } ELSE { IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); + hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ } ELSE { /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); + hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ } } prevj = j; @@ -171,16 +171,16 @@ Word16 encode_envelope_indices_fx( /* o : Number of b move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - bits = add( bits, huffsizn[j] ); + bits = add( bits, huffsizn[j] ); /* Q0 */ } /*------------------------------------------------------------------------------* * comparing bit expenses of coding mode 2 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if ( GT_16( hcode_l, bits ) ) + IF( GT_16( hcode_l, bits ) ) { *LCmode = 2; move16(); @@ -197,7 +197,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b move16(); FOR( i = 1; i < num_sfm; i++ ) { - difidx_org[i] = difidx[i]; + difidx_org[i] = difidx[i]; /* Q0 */ move16(); } @@ -207,7 +207,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ move16(); IF( GT_16( difidx[i], 31 ) ) { @@ -219,7 +219,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ move16(); IF( difidx[i] < 0 ) { @@ -246,7 +246,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); bits = add( bits, resize_huffsizn[j] ); } @@ -255,7 +255,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b * comparing bit expenses of coding mode 1 with that of coding mode 0 *------------------------------------------------------------------*/ - if ( GT_16( hcode_l, bits ) ) + IF( GT_16( hcode_l, bits ) ) { *LCmode = 1; move16(); @@ -271,7 +271,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b * comparing bit expenses of coding mode 3 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if ( GE_16( hcode_l, numnrmibits ) ) + IF( GE_16( hcode_l, numnrmibits ) ) { *LCmode = 3; move16(); @@ -285,7 +285,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { FOR( i = 2; i < num_sfm; i++ ) { - difidx[i] = difidx_org[i]; + difidx[i] = difidx_org[i]; /* Q0 */ move16(); } } @@ -315,11 +315,11 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* LC mode 0 Transient Huffman Coding */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = huffnorm_tran[j]; + m = huffnorm_tran[j]; /* Q0 */ move16(); - r = huffsizn_tran[j]; + r = huffsizn_tran[j]; /* Q0 */ move16(); v = 0; move16(); @@ -327,9 +327,9 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl( v, 1 ); - v = s_or( v, s_and( m, 1 ) ); - m = lshr( m, 1 ); + v = lshl( v, 1 ); /* Q0 */ + v = s_or( v, s_and( m, 1 ) ); /* Q0 */ + m = lshr( m, 1 ); /* Q0 */ } push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); @@ -341,15 +341,15 @@ Word16 encode_envelope_indices_fx( /* o : Number of b prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub( 31, j )]; + r = huffsizn_n[( 31 - j )]; /* Q0 */ move16(); - m = huffnorm_n[sub( 31, j )]; + m = huffnorm_n[( 31 - j )]; /* Q0 */ move16(); } ELSE @@ -357,17 +357,17 @@ Word16 encode_envelope_indices_fx( /* o : Number of b IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - r = huffsizn_n[j]; + r = huffsizn_n[j]; /* Q0 */ move16(); - m = huffnorm_n[j]; + m = huffnorm_n[j]; /* Q0 */ move16(); } ELSE { /* equal */ - r = huffsizn_e[j]; + r = huffsizn_e[j]; /* Q0 */ move16(); - m = huffnorm_e[j]; + m = huffnorm_e[j]; /* Q0 */ move16(); } } @@ -387,15 +387,15 @@ Word16 encode_envelope_indices_fx( /* o : Number of b prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub( 31, j )]; + r = huffsizn_n[( 31 - j )]; /* Q0 */ move16(); - m = huffnorm_n[sub( 31, j )]; + m = huffnorm_n[( 31 - j )]; /* Q0 */ move16(); } ELSE @@ -403,17 +403,17 @@ Word16 encode_envelope_indices_fx( /* o : Number of b IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - r = huffsizn_n[j]; + r = huffsizn_n[j]; /* Q0 */ move16(); - m = huffnorm_n[j]; + m = huffnorm_n[j]; /* Q0 */ move16(); } ELSE { /* equal */ - r = huffsizn_e[j]; + r = huffsizn_e[j]; /* Q0 */ move16(); - m = huffnorm_e[j]; + m = huffnorm_e[j]; /* Q0 */ move16(); } } @@ -441,7 +441,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b move16(); FOR( i = 1; i < num_sfm; i++ ) { - difidx_org[i] = difidx[i]; + difidx_org[i] = difidx[i]; /* Q0 */ move16(); } @@ -449,7 +449,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ move16(); IF( GT_16( difidx[i], 31 ) ) { @@ -461,7 +461,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ move16(); IF( difidx[i] < 0 ) { @@ -486,7 +486,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); } } @@ -496,12 +496,12 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* LC mode 2 -> LC mode 1 */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = resize_huffnorm[j]; + m = resize_huffnorm[j]; /* Q0 */ move16(); - r = resize_huffsizn[j]; + r = resize_huffsizn[j]; /* Q0 */ move16(); v = 0; move16(); @@ -509,9 +509,9 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl( v, 1 ); - v = s_or( v, s_and( m, 1 ) ); - m = lshr( m, 1 ); + v = lshl( v, 1 ); /* Q0 */ + v = s_or( v, s_and( m, 1 ) ); /* Q0 */ + m = lshr( m, 1 ); /* Q0 */ } IF( flag_HQ2 == 0 ) @@ -529,12 +529,12 @@ Word16 encode_envelope_indices_fx( /* o : Number of b /* LC mode 1 -> LC mode 2 */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = huffnorm[j]; + m = huffnorm[j]; /* Q0 */ move16(); - r = huffsizn[j]; + r = huffsizn[j]; /* Q0 */ move16(); push_indice_fx( hBstr, IND_YNRM, m, r ); @@ -554,7 +554,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b } Word16 encode_envelope_indices_ivas_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ const Word16 num_sfm, /* i : Number of subbands Q0 */ const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ @@ -603,12 +603,12 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { IF( GT_16( difidx[i], index_max ) ) { - index_max = difidx[i]; + index_max = difidx[i]; /* Q0 */ move16(); } IF( LT_16( difidx[i], index_min ) ) { - index_min = difidx[i]; + index_min = difidx[i]; /* Q0 */ move16(); } } @@ -617,7 +617,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); bits = add( bits, huffsizn_tran[j] ); } @@ -630,24 +630,24 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* LC mode 0 = Context based coding */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add( hcode_l, huffsizn_n[31 - j] ); + hcode_l = add( hcode_l, huffsizn_n[31 - j] ); /* Q0 */ } ELSE { IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); + hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ } ELSE { /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); + hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ } } prevj = j; @@ -671,24 +671,24 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - hcode_l = add( hcode_l, huffsizn_n[sub( 31, j )] ); + hcode_l = add( hcode_l, huffsizn_n[( 31 - j )] ); /* Q0 */ } ELSE { IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); + hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ } ELSE { /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); + hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ } } prevj = j; @@ -706,7 +706,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number move16(); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); bits = add( bits, huffsizn[j] ); } @@ -715,7 +715,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number * comparing bit expenses of coding mode 2 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if ( GT_16( hcode_l, bits ) ) + IF( GT_16( hcode_l, bits ) ) { *LCmode = 2; move16(); @@ -732,7 +732,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number move16(); FOR( i = 1; i < num_sfm; i++ ) { - difidx_org[i] = difidx[i]; + difidx_org[i] = difidx[i]; /* Q0 */ move16(); } @@ -742,7 +742,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ move16(); IF( GT_16( difidx[i], 31 ) ) { @@ -754,7 +754,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ move16(); IF( difidx[i] < 0 ) { @@ -781,7 +781,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); bits = add( bits, resize_huffsizn[j] ); } @@ -790,7 +790,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number * comparing bit expenses of coding mode 1 with that of coding mode 0 *------------------------------------------------------------------*/ - if ( GT_16( hcode_l, bits ) ) + IF( GT_16( hcode_l, bits ) ) { *LCmode = 1; move16(); @@ -806,7 +806,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number * comparing bit expenses of coding mode 3 with that of the optimal coding mode *------------------------------------------------------------------------------*/ - if ( GE_16( hcode_l, numnrmibits ) ) + IF( GE_16( hcode_l, numnrmibits ) ) { *LCmode = 3; move16(); @@ -820,7 +820,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { FOR( i = 2; i < num_sfm; i++ ) { - difidx[i] = difidx_org[i]; + difidx[i] = difidx_org[i]; /* Q0 */ move16(); } } @@ -850,11 +850,11 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* LC mode 0 Transient Huffman Coding */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = huffnorm_tran[j]; + m = huffnorm_tran[j]; /* Q0 */ move16(); - r = huffsizn_tran[j]; + r = huffsizn_tran[j]; /* Q0 */ move16(); v = 0; move16(); @@ -862,9 +862,9 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl( v, 1 ); - v = s_or( v, s_and( m, 1 ) ); - m = lshr( m, 1 ); + v = lshl( v, 1 ); /* Q0 */ + v = s_or( v, s_and( m, 1 ) ); /* Q0 */ + m = lshr( m, 1 ); /* Q0 */ } push_indice( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); @@ -876,15 +876,15 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub( 31, j )]; + r = huffsizn_n[( 31 - j )]; /* Q0 */ move16(); - m = huffnorm_n[sub( 31, j )]; + m = huffnorm_n[( 31 - j )]; /* Q0 */ move16(); } ELSE @@ -892,17 +892,17 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - r = huffsizn_n[j]; + r = huffsizn_n[j]; /* Q0 */ move16(); - m = huffnorm_n[j]; + m = huffnorm_n[j]; /* Q0 */ move16(); } ELSE { /* equal */ - r = huffsizn_e[j]; + r = huffsizn_e[j]; /* Q0 */ move16(); - m = huffnorm_e[j]; + m = huffnorm_e[j]; /* Q0 */ move16(); } } @@ -922,15 +922,15 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number prevj = add( difidx[0], OFFSET_NORM ); FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); IF( GT_16( prevj, HTH_NORM ) ) { /* above */ - r = huffsizn_n[sub( 31, j )]; + r = huffsizn_n[( 31 - j )]; /* Q0 */ move16(); - m = huffnorm_n[sub( 31, j )]; + m = huffnorm_n[( 31 - j )]; /* Q0 */ move16(); } ELSE @@ -938,17 +938,17 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number IF( LT_16( prevj, LTH_NORM ) ) { /* less */ - r = huffsizn_n[j]; + r = huffsizn_n[j]; /* Q0 */ move16(); - m = huffnorm_n[j]; + m = huffnorm_n[j]; /* Q0 */ move16(); } ELSE { /* equal */ - r = huffsizn_e[j]; + r = huffsizn_e[j]; /* Q0 */ move16(); - m = huffnorm_e[j]; + m = huffnorm_e[j]; /* Q0 */ move16(); } } @@ -976,7 +976,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number move16(); FOR( i = 1; i < num_sfm; i++ ) { - difidx_org[i] = difidx[i]; + difidx_org[i] = difidx[i]; /* Q0 */ move16(); } @@ -984,7 +984,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { IF( GT_16( difidx_org[i - 1], 17 ) ) { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); + difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ move16(); IF( GT_16( difidx[i], 31 ) ) { @@ -996,7 +996,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number IF( LT_16( difidx_org[i - 1], 13 ) ) { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); + difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ move16(); IF( difidx[i] < 0 ) { @@ -1021,7 +1021,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number { FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); } } @@ -1031,12 +1031,12 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* LC mode 2 -> LC mode 1 */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = resize_huffnorm[j]; + m = resize_huffnorm[j]; /* Q0 */ move16(); - r = resize_huffsizn[j]; + r = resize_huffsizn[j]; /* Q0 */ move16(); v = 0; move16(); @@ -1044,9 +1044,9 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* Bit reverse */ FOR( k = 0; k < r; k++ ) { - v = lshl( v, 1 ); - v = s_or( v, s_and( m, 1 ) ); - m = lshr( m, 1 ); + v = lshl( v, 1 ); /* Q0 */ + v = s_or( v, s_and( m, 1 ) ); /* Q0 */ + m = lshr( m, 1 ); /* Q0 */ } IF( flag_HQ2 == 0 ) @@ -1064,12 +1064,12 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number /* LC mode 1 -> LC mode 2 */ FOR( i = 1; i < num_sfm; i++ ) { - j = difidx[i]; + j = difidx[i]; /* Q0 */ move16(); - m = huffnorm[j]; + m = huffnorm[j]; /* Q0 */ move16(); - r = huffsizn[j]; + r = huffsizn[j]; /* Q0 */ move16(); push_indice( hBstr, IND_YNRM, m, r ); @@ -1113,20 +1113,20 @@ void diff_envelope_coding_fx( /* Reorder quantization indices and quantized norms */ reordernorm_fx( ynrm, normqlg2, idxbuf, normbuf, num_env_bands ); diffcod_fx( num_env_bands, idxbuf, &difidx[1] ); - difidx[0] = idxbuf[0]; + difidx[0] = idxbuf[0]; /* Q0 */ move16(); recovernorm_fx( idxbuf, ynrm, normqlg2, num_env_bands ); } ELSE { diffcod_fx( num_env_bands, &ynrm[start_norm], &difidx[1] ); - difidx[0] = ynrm[start_norm]; + difidx[0] = ynrm[start_norm]; /* Q0 */ move16(); tmp = add( start_norm, num_env_bands ); FOR( i = start_norm; i < tmp; i++ ) { - normqlg2[i] = dicnlg2[ynrm[i]]; + normqlg2[i] = dicnlg2[ynrm[i]]; /* Q0 */ move16(); move16(); } diff --git a/lib_enc/hq_hr_enc.c b/lib_enc/hq_hr_enc.c index c72e682e0e0a75e2190b8f5654bcc390495257ef..f73925978f0f7f80cdad30357bf272f047979f7d 100644 --- a/lib_enc/hq_hr_enc.c +++ b/lib_enc/hq_hr_enc.c @@ -53,11 +53,11 @@ void hq_hr_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ - Word32 *t_audio_fx, /* i/o: transform-domain coefficients */ - const Word16 length, /* i : length of spectrum */ - Word16 *num_bits, /* i/o: number of available bits */ - const Word16 is_transient, /* i : transient flag */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + Word32 *t_audio_fx, /* i/o: transform-domain coefficients Q12*/ + const Word16 length, /* i : length of spectrum Q0*/ + Word16 *num_bits, /* i/o: number of available bits Q0*/ + const Word16 is_transient, /* i : transient flag Q0*/ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ ) { Word16 nb_sfm; @@ -113,7 +113,7 @@ void hq_hr_enc_ivas_fx( /*------------------------------------------------------------------* * Classification *------------------------------------------------------------------*/ - bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); + bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ *num_bits = sub( *num_bits, bits ); move16(); @@ -135,7 +135,7 @@ void hq_hr_enc_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag ); - v_multc_att32( t_audio_fx, att_fx, t_audio_fx, sfm_end[sub( num_sfm, 1 )] ); + v_multc_att32( t_audio_fx, att_fx, t_audio_fx, sfm_end[( num_sfm - 1 )] ); /* Q12 */ } /*------------------------------------------------------------------* @@ -149,7 +149,7 @@ void hq_hr_enc_ivas_fx( diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); /* Find norm coding mode and calculate number of bits */ - hcode_l = encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); + hcode_l = encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); move16(); @@ -187,12 +187,13 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - b_delta_env = calc_nor_delta_hf_ivas_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); + b_delta_env = calc_nor_delta_hf_ivas_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ sum = sub( sum, b_delta_env ); } normalizecoefs_fx( t_audio_fx, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); } Word16 Q_audio = 12, Q_shift; + move16(); /*------------------------------------------------------------------* * Quantize/code spectral fine structure using PVQ or HVQ *------------------------------------------------------------------*/ @@ -204,7 +205,7 @@ void hq_hr_enc_ivas_fx( } ELSE { - shape_bits = pvq_core_enc_ivas_fx( hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); + shape_bits = pvq_core_enc_ivas_fx( hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); /* Q0 */ *num_bits = add( *num_bits, sub( sum, shape_bits ) ); move16(); } @@ -212,9 +213,9 @@ void hq_hr_enc_ivas_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; - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; + subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ + wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ + wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ move16(); move16(); IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) @@ -247,19 +248,19 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); + nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); /* Q0 */ push_indice( hBstr, IND_NF_IDX, nf_idx, 2 ); } ELSE { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); + nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); /* Q0 */ push_indice( hBstr, IND_NF_IDX, nf_idx, 2 ); } } /* updates */ - hHQ_core->prev_hqswb_clas = hqswb_clas; + hHQ_core->prev_hqswb_clas = hqswb_clas; /* Q0 */ move16(); /* Prepare synthesis for LB generation in case of switch to ACELP */ IF( NE_16( hqswb_clas, HQ_HVQ ) ) diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index f1ff0d62f5911f289b84cce3a05e244c8dce6e84..f73a926dc5177ed57cbbcfaeeec3c93b77eb3512 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -20,7 +20,7 @@ void hq_hr_enc_fx( const Word16 length, /* i : length of spectrum Q0 */ Word16 *num_bits, /* i : number of available bits Q0 */ const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0 */ ) { Word16 nb_sfm; /* Q0 */ @@ -47,7 +47,8 @@ void hq_hr_enc_fx( Word16 hq_generic_offset; /* Q0 */ Word16 hq_generic_fenv[HQ_FB_FENV]; /* Q1 */ Word16 hq_generic_exc_clas = 0; /* Q0 */ - Word16 core_sfm; /* Q0 */ + move16(); + Word16 core_sfm; /* Q0 */ Word16 har_freq_est1, har_freq_est2; Word16 flag_dis; const Word16 *subband_search_offset; @@ -68,6 +69,8 @@ void hq_hr_enc_fx( Npeaks = 0; Q_audio = 0; /* to avoid compilation warnings */ + move16(); + move16(); set16_fx( npulses, 0, NB_SFM ); set16_fx( maxpulse, 0, NB_SFM ); @@ -86,9 +89,10 @@ void hq_hr_enc_fx( * Classification *------------------------------------------------------------------*/ - bits = hq_classifier_enc_fx( st_fx, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); + bits = hq_classifier_enc_fx( st_fx, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); /* Q0 */ - *num_bits = sub( *num_bits, bits ); + *num_bits = sub( *num_bits, bits ); /* Q0 */ + move16(); /*------------------------------------------------------------------* * set quantization parameters @@ -111,7 +115,7 @@ void hq_hr_enc_fx( IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag ); - v_multc_att32( t_audio, att, t_audio, sfm_end[sub( num_sfm, 1 )] ); + v_multc_att32( t_audio, att, t_audio, sfm_end[( num_sfm - 1 )] ); /* Q12 */ } /*------------------------------------------------------------------* * Scalar quantization of norms @@ -125,8 +129,9 @@ void hq_hr_enc_fx( diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); /* Find coding mode and calculate bit rate */ - hcode_l = encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); - *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); + hcode_l = encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ + *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ + move16(); /* Encode norm indices */ encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); @@ -141,7 +146,8 @@ void hq_hr_enc_fx( hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { - *num_bits = add( *num_bits, 1 ); /* conditional 1 bit saving for representing FD3 BWE excitation class */ + *num_bits = add( *num_bits, 1 ); /* conditional 1 bit saving for representing FD3 BWE excitation class Q0*/ + move16(); } map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -161,11 +167,12 @@ void hq_hr_enc_fx( test(); IF( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB ) { - b_delta_env = calc_nor_delta_hf_fx( st_fx->hBstr, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); - sum -= b_delta_env; + b_delta_env = calc_nor_delta_hf_fx( st_fx->hBstr, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ + sum = sub( sum, b_delta_env ); } normalizecoefs_fx( t_audio, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); Q_audio = 12; + move16(); } /*------------------------------------------------------------------* @@ -174,22 +181,24 @@ void hq_hr_enc_fx( IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { sum = hvq_enc_fx( st_fx, st_fx->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, noise_level, pe_gains, t_audio, t_audio_q ); - *num_bits = sub( *num_bits, sum ); + *num_bits = sub( *num_bits, sum ); /* Q0 */ + move16(); } ELSE { shape_bits = pvq_core_enc_fx( st_fx->hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); - *num_bits = add( *num_bits, sub( sum, shape_bits ) ); + *num_bits = add( *num_bits, sub( sum, shape_bits ) ); /* Q0 */ + move16(); } 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 ) ) @@ -198,12 +207,13 @@ void hq_hr_enc_fx( FOR( i = 0; i < 300; i++ ) { t_audio_q[i] = L_shl( L_deposit_l( t_audio_q_norm[i] ), Q_shift ); /* Q12 */ + move32(); } } har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); - hHQ_core->prev_frm_hfe2 = har_freq_est2; + hHQ_core->prev_frm_hfe2 = har_freq_est2; /* Q0 */ move16(); } @@ -224,17 +234,17 @@ void hq_hr_enc_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); + nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); /* Q0 */ push_indice_fx( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); } ELSE { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); + nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); /* Q0 */ push_indice_fx( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); } } /* updates */ - hHQ_core->prev_hqswb_clas = hqswb_clas; + hHQ_core->prev_hqswb_clas = hqswb_clas; /* Q0 */ move16(); /* Prepare synthesis for LB generation in case of switch to ACELP */ diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index e602d28b36257214b18b592633dbc60b98ccb8db..3e70bc42ec238369b5561cdc95af18c60f5f8738 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -18,14 +18,14 @@ * Local function prototypes *--------------------------------------------------------------------------*/ -static Word16 band_energy_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[], const Word16 bands_fx, const Word32 L_qint, const Word16 eref_fx, const Word16 is_transient_fx ); +static Word16 band_energy_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio /*Q12*/, const Word16 band_start_fx[], const Word16 band_end_fx[], Word32 L_band_energy[] /*Q14*/, const Word16 bands_fx, const Word32 L_qint /*Q29*/, const Word16 eref_fx /*Q10*/, const Word16 is_transient_fx ); -static Word16 p2a_threshold_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); +static Word16 p2a_threshold_quant_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio /*Q12*/, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th /*Q11*/, Word16 *p2a_flags ); -static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 L_ybuf[], Word32 L_y2[], const Word16 band_start[], const Word16 band_end[], const Word16 k_sort[], const Word16 bands, const Word32 L_qint, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); +static void mdct_spectrum_fine_gain_enc_fx( Encoder_State *st_fx, const Word32 L_ybuf[] /*Q12*/, Word32 L_y2[] /*Q12*/, const Word16 band_start[], const Word16 band_end[], const Word16 k_sort[], const Word16 bands, const Word32 L_qint /*Q29*/, const Word16 Ngq, const Word16 gqlevs, const Word16 gqbits ); -static Word16 p2a_threshold_quant_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th, Word16 *p2a_flags ); +static Word16 p2a_threshold_quant_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word32 *L_t_audio /*Q12*/, const Word16 band_start[], const Word16 band_end[], const Word16 band_width[], const Word16 bands, const Word16 p2a_bands, const Word16 p2a_th /*Q11*/, Word16 *p2a_flags ); static void mdct_spectrum_fine_gain_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 L_ybuf[], /* i : Q12 : input spectrum */ @@ -41,15 +41,15 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( ); static Word16 band_energy_quant_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *L_t_audio, - const Word16 band_start[], - const Word16 band_end[], - Word32 L_band_energy[], - const Word16 bands_fx, - const Word32 L_qint, /* Q29 */ - const Word16 eref_fx, /* Q10 */ - const Word16 is_transient ); + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word32 *L_t_audio, /* Q12 */ + const Word16 band_start[], /* Q0 */ + const Word16 band_end[], /* Q0 */ + Word32 L_band_energy[], /* Q14 */ + const Word16 bands_fx, /* Q0 */ + const Word32 L_qint, /* Q29 */ + const Word16 eref_fx, /* Q10 */ + const Word16 is_transient /* Q0 */ ); /*--------------------------------------------------------------------------* * spt_shorten_domain_set() @@ -59,16 +59,16 @@ static Word16 band_energy_quant_ivas_fx( static void spt_shorten_domain_set_fx( Encoder_State *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* i/o: band start position */ - Word16 band_end[], /* i/o: band end position */ - Word16 band_width[], /* i: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + const Word32 L_t_audio[], /* i: input spectrum Q12*/ + 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[], /* i/o: band start position Q0*/ + Word16 band_end[], /* i/o: band end position Q0*/ + Word16 band_width[], /* i: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 i, j, k; @@ -81,7 +81,8 @@ static void spt_shorten_domain_set_fx( kpos = 0; j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + move16(); + FOR( k = ( bands - SPT_SHORTEN_SBNUM ); k < bands; k++ ) { IF( EQ_16( p2a_flags[k], 1 ) ) { @@ -96,7 +97,8 @@ static void spt_shorten_domain_set_fx( { IF( LT_32( L_max_y2, L_abs( L_t_audio[i] ) ) ) { - L_max_y2 = L_abs( L_t_audio[i] ); + L_max_y2 = L_abs( L_t_audio[i] ); /* Q12 */ + move32(); max_y2_pos = i; move16(); } @@ -104,22 +106,23 @@ static void spt_shorten_domain_set_fx( test(); IF( GE_16( max_y2_pos, new_band_start[j] ) && LE_16( max_y2_pos, new_band_end[j] ) ) { - band_start[k] = new_band_start[j]; + 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(); spt_shorten_flag[j] = 1; move16(); } } push_indice_fx( st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1 ); - *bit_budget = sub( *bit_budget, 1 ); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ + move16(); } - kpos = add( kpos, 1 ); - j = add( j, 1 ); + kpos += 1; + j += 1; } return; @@ -127,16 +130,16 @@ static void spt_shorten_domain_set_fx( static void spt_shorten_domain_set_ivas_fx( Encoder_State *st_fx, /* i: encoder state structure */ - const Word32 L_t_audio[], /* i: input spectrum */ - const Word16 p2a_flags[], /* i: p2a anlysis information */ - const Word16 new_band_start[], /* i: new band start position */ - const Word16 new_band_end[], /* i: new band end position */ - const Word16 new_band_width[], /* i: new subband band width */ - const Word16 bands, /* i: total number of subbands */ - Word16 band_start[], /* i/o: band start position */ - Word16 band_end[], /* i/o: band end position */ - Word16 band_width[], /* i: sub band band width */ - Word16 *bit_budget /* i/o: bit budget */ + const Word32 L_t_audio[], /* i: input spectrum Q12*/ + 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[], /* i/o: band start position Q0*/ + Word16 band_end[], /* i/o: band end position Q0*/ + Word16 band_width[], /* i: sub band band width Q0*/ + Word16 *bit_budget /* i/o: bit budget Q0*/ ) { Word16 i, j, k; @@ -150,7 +153,7 @@ static void spt_shorten_domain_set_ivas_fx( j = 0; move16(); move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = ( bands - SPT_SHORTEN_SBNUM ); k < bands; k++ ) { IF( EQ_16( p2a_flags[k], 1 ) ) { @@ -165,7 +168,8 @@ static void spt_shorten_domain_set_ivas_fx( { IF( LT_32( L_max_y2, L_abs( L_t_audio[i] ) ) ) { - L_max_y2 = L_abs( L_t_audio[i] ); + L_max_y2 = L_abs( L_t_audio[i] ); /* Q12 */ + move32(); max_y2_pos = i; move16(); } @@ -173,22 +177,23 @@ static void spt_shorten_domain_set_ivas_fx( test(); IF( GE_16( max_y2_pos, new_band_start[j] ) && LE_16( max_y2_pos, new_band_end[j] ) ) { - band_start[k] = new_band_start[j]; + 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(); spt_shorten_flag[j] = 1; move16(); } } push_indice( st_fx->hBstr, IND_HQ2_SPT_SHORTEN, spt_shorten_flag[j], 1 ); - *bit_budget = sub( *bit_budget, 1 ); + *bit_budget = sub( *bit_budget, 1 ); /* Q0 */ + move16(); } - kpos = add( kpos, 1 ); - j = add( j, 1 ); + kpos += 1; + j += 1; } return; @@ -270,6 +275,7 @@ void hq_lr_enc_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -288,6 +294,7 @@ void hq_lr_enc_fx( enerH_fx = L_deposit_l( 0 ); tmp2 = 0; /* to avoid compilation warnings */ + move16(); L_bwe_br = L_add( st_fx->core_brate, 0 ); hqswb_clas_fx = HQ_NORMAL; @@ -303,13 +310,14 @@ void hq_lr_enc_fx( } ELSE { - hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); + hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ } /* write the classification information into the bitstream */ push_indice_fx( hBstr, IND_HQ2_SWB_CLAS, hqswb_clas_fx, 2 ); ( *num_bits_fx ) = sub( *num_bits_fx, 2 ); - if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + move16(); + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -321,15 +329,16 @@ void hq_lr_enc_fx( push_indice_fx( st_fx->hBstr, IND_HQ2_SWB_CLAS, is_transient_fx, 1 ); /* subtract one bit for the transient flag */ - ( *num_bits_fx )--; + ( *num_bits_fx ) = sub( ( *num_bits_fx ), 1 ); + move16(); } hq2_core_configure_fx( inner_frame_fx, *num_bits_fx, is_transient_fx, &bands_fx, &length_fx, band_width, band_start, band_end, &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs_fx, &Ngq_fx, &p2a_bands_fx, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, L_bwe_br ); - highlength_fx = band_end[sub( 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(); @@ -342,6 +351,7 @@ void hq_lr_enc_fx( IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) || EQ_16( hqswb_clas_fx, HQ_HARMONIC ) ) { ( *num_bits_fx ) = sub( *num_bits_fx, get_usebit_npswb_fx( hqswb_clas_fx ) ); + move16(); } } @@ -353,7 +363,7 @@ void hq_lr_enc_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[j] = 0; move16(); @@ -368,16 +378,18 @@ void hq_lr_enc_fx( { /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ - k1_step_fx = shr( length_fx, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS */ - k2_step_fx = shr( inner_frame_fx, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - k1_fx = k1_step_fx; - k2_fx = k2_step_fx; + k1_step_fx = shr( length_fx, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS Q0*/ + k2_step_fx = shr( inner_frame_fx, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS Q0*/ + k1_fx = k1_step_fx; /* Q0 */ + k2_fx = k2_step_fx; /* Q0 */ + move16(); + move16(); FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) { /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); + Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); /* Q12 */ k1_fx = add( k1_fx, k1_step_fx ); k2_fx = add( k2_fx, k2_step_fx ); @@ -386,13 +398,13 @@ void hq_lr_enc_fx( /* Spectral energy calculation/quantization */ ebits_fx = band_energy_quant_fx( hBstr, L_t_audio, band_start, band_end, L_band_energy, bands_fx, - L_qint, eref_fx, is_transient_fx ); + L_qint, eref_fx, is_transient_fx ); /* Q0 */ /* First pass bit budget for TCQ of spectral band information */ exp_norm = norm_s( gqlevs_fx ); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ gqbits_fx = sub( 14, exp_norm ); - bit_budget_fx = sub( sub( *num_bits_fx, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget_fx = sub( sub( *num_bits_fx, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits_fx = 0; @@ -409,7 +421,7 @@ void hq_lr_enc_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); /* Q0 */ bit_budget_fx = sub( bit_budget_fx, pbits_fx ); IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) @@ -421,7 +433,7 @@ void hq_lr_enc_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); + pbits_fx = p2a_threshold_quant_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands_fx, p2a_bands_fx, p2a_th_fx, p2a_flags_fx ); /* Q0 */ bit_budget_fx = sub( bit_budget_fx, pbits_fx ); } @@ -434,6 +446,7 @@ void hq_lr_enc_fx( /* Estimate number of bits per band */ Q_band_energy = SWB_BWE_LR_Qbe; + move16(); FOR( i = 0; i < bands_fx; i++ ) { @@ -451,23 +464,23 @@ void hq_lr_enc_fx( FOR( i = 0; i < bands_fx; i++ ) { - L_tmp2 = Ep_fx[i]; - L_tmp = L_max( 1, L_tmp2 ); + L_tmp2 = Ep_fx[i]; /* Q -6 */ + L_tmp = L_max( 1, L_tmp2 ); /* Q -6 */ exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); + tmp = extract_h( L_shl( L_tmp, exp ) ); /* Q -6 + exp - 16 */ - L_tmp3 = (Word32) band_width[i]; + L_tmp3 = L_deposit_l( band_width[i] ); /* Q0 */ exp2 = norm_l( L_tmp3 ); - tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); /* exp2 - 16 */ exp2 = sub( exp, exp2 ); /* Denormalize and substract */ tmp3 = sub( tmp2, tmp ); - if ( tmp3 > 0 ) + IF( tmp3 > 0 ) { tmp2 = shr( tmp2, 1 ); } - if ( tmp3 > 0 ) + IF( tmp3 > 0 ) { exp2 = add( exp2, 1 ); } @@ -475,6 +488,7 @@ void hq_lr_enc_fx( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &exp2 ); /*Q(31-exp2) */ Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ + move32(); } test(); @@ -491,18 +505,19 @@ void hq_lr_enc_fx( move16(); bit_budget_fx = sub( bit_budget_fx, trans_bit ); gama_fx = 27852; /*Q15 0.85f;// */ - beta_fx = 17203; - move16(); /*Q14 1.05f; */ + beta_fx = 17203; /*Q14 1.05f; */ + move16(); + move16(); - set16_fx( &p2a_flags_tmp[sub( bands_fx, trans_bit )], 0, 2 ); + set16_fx( &p2a_flags_tmp[( bands_fx - trans_bit )], 0, 2 ); IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) { - beta_fx = 13107; - move16(); /*14 1.25f; */ - gama_fx = 31130; - move16(); /*0.95f; */ - Copy( &p2a_flags_fx[sub( bands_fx, trans_bit )], &p2a_flags_tmp[sub( bands_fx, trans_bit )], trans_bit ); + beta_fx = 13107; /*14 1.25f; */ + move16(); + gama_fx = 31130; /*0.95f; */ + move16(); + Copy( &p2a_flags_fx[( bands_fx - trans_bit )], &p2a_flags_tmp[( bands_fx - trans_bit )], trans_bit ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ Ep_vari_fx = L_deposit_l( 0 ); @@ -516,6 +531,7 @@ void hq_lr_enc_fx( #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 */ + move32(); #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 */ @@ -573,16 +589,18 @@ void hq_lr_enc_fx( L_tmp2 = L_add( L_tmp, 13107 ); /*15 */ tmp2 = extract_l( L_min( L_max( L_tmp2, 16384 ), gama_fx ) ); /*15 = 15 */ L_band_energy_tmp[i] = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+15-15 = Q_band_energy) */ + move32(); } } } ELSE { j = 0; - FOR( i = sub( bands_fx, trans_bit ); i < bands_fx; i++ ) + move16(); + FOR( i = ( bands_fx - trans_bit ); i < bands_fx; i++ ) { - alpha_fx = 16384; - move16(); /*Q14 */ + alpha_fx = 16384; /*Q14 */ + move16(); IF( EQ_16( p2a_flags_tmp[i], 1 ) ) { L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ @@ -629,15 +647,15 @@ void hq_lr_enc_fx( #else L_tmp2 = L_shl( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ #endif - L_tmp = L_min( L_tmp, L_tmp2 ); /*14 */ - tmp = extract_l( L_min( L_tmp, 13107 ) ); /*14 */ + L_tmp = L_min( L_tmp, L_tmp2 ); /*Q14 */ + tmp = extract_l( L_min( L_tmp, 13107 ) ); /*Q14 */ alpha_fx = add( 16384, tmp ); } IF( EQ_16( hHQ_core->last_bitalloc_max_band[j++], 1 ) ) { L_tmp = Mult_32_16( Ep_tmp_fx[i], sub( bands_fx, lowband ) ); /*Q(13+0-15 = -2) */ #ifdef BASOP_NOGLOB - tmp = extract_h( L_shl_sat( L_tmp, 14 ) ); /*Q-2 */ + tmp = extract_h( L_shl_sat( L_tmp, 14 ) ); /*Q-4 */ #else tmp = extract_h( L_shl( L_tmp, 14 ) ); /*Q-2 */ #endif @@ -660,9 +678,9 @@ void hq_lr_enc_fx( #else L_tmp = L_shl( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ #endif - L_tmp = L_max( L_tmp, 16384 ); /*14 */ - tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ - alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ + L_tmp = L_max( L_tmp, 16384 ); /*Q14 */ + tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*Q14 */ + alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=Q14 */ } ELSE { @@ -687,12 +705,13 @@ void hq_lr_enc_fx( #else L_tmp = L_shl( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ) ); /*Q(13+exp-15 +19-exp +3 = 20) */ #endif - L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =14 */ - L_tmp = L_max( L_tmp, 13926 ); /*14 */ - tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*14 */ - alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =14 */ + L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =Q14 */ + L_tmp = L_max( L_tmp, 13926 ); /*Q14 */ + tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*Q14 */ + alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =Q14 */ } L_band_energy_tmp[i] = L_shl( Mult_32_16( L_band_energy_tmp[i], alpha_fx ), 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + move32(); } } lowband = 3; @@ -753,7 +772,7 @@ void hq_lr_enc_fx( L_tmp = Mult_32_16( L_tmp, lowband ); /*Q(exp+2+0-15 = exp-13) */ L_tmp = Mult_32_16( L_tmp, 18842 ); /*Q(exp-13+16-16 = exp-13) */ L_tmp = L_shl( L_tmp, sub( 27, exp ) ); /*Q14 0.5 */ - tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ + tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*Q14 */ L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp2 ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ } @@ -769,11 +788,12 @@ void hq_lr_enc_fx( } ELSE IF( is_transient_fx == 0 && EQ_16( inner_frame_fx, L_FRAME16k ) ) { - bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ + bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < bands_fx; i++ ) { #ifdef BASOP_NOGLOB - Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); + Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ + move32(); #else /* BASOP_NOGLOB */ Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #endif /* BASOP_NOGLOB */ @@ -784,8 +804,8 @@ void hq_lr_enc_fx( move16(); highband = 15; move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[( bands_fx - 1 )], 1 ), band_start[highband] ); /* Q0 */ } ELSE { @@ -793,8 +813,8 @@ void hq_lr_enc_fx( move16(); highband = 16; move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands_fx, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* 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 ); @@ -807,7 +827,7 @@ void hq_lr_enc_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_sat( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*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 */ #else Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ #endif @@ -845,7 +865,7 @@ void hq_lr_enc_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 ) @@ -885,8 +905,8 @@ void hq_lr_enc_fx( } ELSE { - alpha_fx = 16384; - move16(); /*Q14 */ + alpha_fx = 16384; /*Q14 */ + move16(); } IF( add( sub( i, bands_fx ), p2a_bands_fx ) > 0 ) @@ -954,6 +974,7 @@ void hq_lr_enc_fx( } L_tmp = Mult_32_16( L_band_energy_tmp[i], alpha_fx ); /*Q(Q_band_energy+14-15=Q_band_energy-1) */ L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q Q_band_energy */ + move32(); } lowband = 6; move16(); @@ -1025,6 +1046,7 @@ void hq_lr_enc_fx( tmp = extract_l( L_min( L_tmp, 19661 ) ); /*//Q14 */ L_tmp = Mult_32_16( L_band_energy_tmp[i], tmp ); /*Q(Q_band_energy+14-15 = Q_band_energy-1) */ L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ + move32(); } } @@ -1054,20 +1076,25 @@ void hq_lr_enc_fx( tcq_core_LR_enc_fx( hBstr, /*st_fx->idchan, */ inp_vector_fx, /*t_audio, */ L_t_audio, /*y2, */ L_y2, bit_budget_fx, bands_fx, band_start, band_end, band_width, /*Rk*/ L_Rk, npulses_fx, k_sort_fx, p2a_flags_fx, p2a_bands_fx, hHQ_core->last_bitalloc_max_band, inner_frame_fx, adjustFlag, is_transient_fx ); + test(); + test(); IF( ( EQ_16( inner_frame_fx, L_FRAME8k ) && LE_32( st_fx->core_brate, ACELP_13k20 ) ) || EQ_16( inner_frame_fx, L_FRAME16k ) ) { j = 0; + move16(); FOR( i = 2; i > 0; i-- ) { IF( npulses_fx[bands_fx - i] > 0 ) { - hHQ_core->last_bitalloc_max_band[j] = 1; + hHQ_core->last_bitalloc_max_band[j] = 1; /* Q0 */ + move16(); } ELSE { - hHQ_core->last_bitalloc_max_band[j] = 0; + hHQ_core->last_bitalloc_max_band[j] = 0; /* Q0 */ + move16(); } - j++; + j += 1; } } @@ -1088,7 +1115,7 @@ void hq_lr_enc_fx( /* 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, hqswb_clas_fx, st_fx->bwidth, L_bwe_br ); @@ -1121,11 +1148,11 @@ void hq_lr_enc_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*/ } } @@ -1164,10 +1191,10 @@ void hq_lr_enc_fx( void hq_lr_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ - Word32 L_t_audio[], /* i/o: transform-domain coefs. */ - const Word16 inner_frame, /* i : inner frame length */ - Word16 *num_bits, /* i/o: number of available bits */ - const Word16 is_transient /* i : transient flag */ + Word32 L_t_audio[], /* i/o: transform-domain coefs. Q12*/ + const Word16 inner_frame, /* i : inner frame length Q0*/ + Word16 *num_bits, /* i/o: number of available bits Q0*/ + const Word16 is_transient /* i : transient flag Q0*/ ) { Word16 i; @@ -1240,6 +1267,7 @@ void hq_lr_enc_ivas_fx( Word16 Q_band_energy; #ifdef BASOP_NOGLOB Flag Overflow; + move32(); #endif /* BASOP_NOGLOB */ BSTR_ENC_HANDLE hBstr = st->hBstr; @@ -1271,19 +1299,19 @@ void hq_lr_enc_ivas_fx( { IF( EQ_16( is_transient, 1 ) ) { - hqswb_clas = HQ_TRANSIENT; + hqswb_clas = HQ_TRANSIENT; /* Q0 */ move16(); } ELSE { - hqswb_clas = peak_avrg_ratio_fx( st->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); + hqswb_clas = peak_avrg_ratio_fx( st->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ } /* write the classification information into the bitstream */ push_indice( hBstr, IND_HQ2_SWB_CLAS, hqswb_clas, 2 ); ( *num_bits ) = sub( *num_bits, 2 ); move16(); - if ( EQ_16( hqswb_clas, HQ_NORMAL ) ) + IF( EQ_16( hqswb_clas, HQ_NORMAL ) ) { flag_spt = 1; move16(); @@ -1305,9 +1333,9 @@ void hq_lr_enc_ivas_fx( &L_qint, &eref_fx, &bit_alloc_weight_fx, &gqlevs, &Ngq, &p2a_bands, &p2a_th_fx, &pd_thresh_fx, &ld_slope_fx, &ni_coef_fx, bwe_br ); - highlength = band_end[sub( bands, 1 )]; + highlength = band_end[( bands - 1 )]; /* Q0 */ move16(); - har_bands = bands; + har_bands = bands; /* Q0 */ move16(); @@ -1333,11 +1361,11 @@ void hq_lr_enc_ivas_fx( { j = 0; move16(); - FOR( k = sub( bands, SPT_SHORTEN_SBNUM ); k < bands; k++ ) + FOR( k = ( bands - SPT_SHORTEN_SBNUM ); k < bands; k++ ) { hHQ_core->prev_SWB_peak_pos[j] = 0; move16(); - j = add( j, 1 ); + j += 1; } } } @@ -1347,10 +1375,10 @@ void hq_lr_enc_ivas_fx( { /* If so, collapse transient frame (4 short transforms) to remove uncoded coefficients */ - k1_step_fx = shr( length, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS */ - k2_step_fx = shr( inner_frame, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS */ - k1_fx = k1_step_fx; - k2_fx = k2_step_fx; + k1_step_fx = shr( length, 2 ); /* k1 = length/NUM_TIME_SWITCHING_BLOCKS Q0*/ + k2_step_fx = shr( inner_frame, 2 ); /* k2 = inner_frame/NUM_TIME_SWITCHING_BLOCKS Q0*/ + k1_fx = k1_step_fx; /* Q0 */ + k2_fx = k2_step_fx; /* Q0 */ move16(); move16(); FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) @@ -1358,7 +1386,7 @@ void hq_lr_enc_ivas_fx( /*k1 = i*length/NUM_TIME_SWITCHING_BLOCKS; */ /*k2 = i*inner_frame/NUM_TIME_SWITCHING_BLOCKS; */ - Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); + Copy32( &L_t_audio[k2_fx], &L_t_audio[k1_fx], k1_step_fx ); /* Q12 */ k1_fx = add( k1_fx, k1_step_fx ); k2_fx = add( k2_fx, k2_step_fx ); @@ -1368,13 +1396,13 @@ void hq_lr_enc_ivas_fx( /* Spectral energy calculation/quantization */ ebits_fx = band_energy_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, L_band_energy, bands, - L_qint, eref_fx, is_transient ); + L_qint, eref_fx, is_transient ); /* Q0 */ /* First pass bit budget for TCQ of spectral band information */ exp_norm = norm_s( gqlevs ); /* gqbits_fx = (short int) log2_f ((float) gqlevs_fx); */ gqbits = sub( 14, exp_norm ); - bit_budget = sub( sub( *num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq, gqbits ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; */ + bit_budget = sub( sub( *num_bits, ebits_fx ), round_fx( L_shl( L_mult( Ngq, gqbits ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ pbits = 0; @@ -1391,7 +1419,7 @@ void hq_lr_enc_ivas_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); + pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); /* Q0 */ bit_budget = sub( bit_budget, pbits ); IF( EQ_16( hqswb_clas, HQ_NORMAL ) ) @@ -1403,7 +1431,7 @@ void hq_lr_enc_ivas_fx( ELSE { /* High band tonality detector based on per band peak-to-average ratio */ - pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); + pbits = p2a_threshold_quant_ivas_fx( hBstr, L_t_audio, band_start, band_end, band_width, bands, p2a_bands, p2a_th_fx, p2a_flags ); /* Q0 */ bit_budget = sub( bit_budget, pbits ); } @@ -1427,18 +1455,19 @@ void hq_lr_enc_ivas_fx( L_tmp = Pow2( 30, frac1 ); exp = sub( exp, 30 ); Ep_fx[i] = L_shl( L_tmp, sub( exp, 6 ) ); /* Q -6 */ + move32(); } FOR( i = 0; i < bands; i++ ) { - L_tmp2 = Ep_fx[i]; + L_tmp2 = Ep_fx[i]; /* Q -6 */ L_tmp = L_max( 1, L_tmp2 ); exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); + tmp = extract_h( L_shl( L_tmp, exp ) ); /* Q -6 + exp - 16 */ - L_tmp3 = (Word32) band_width[i]; + L_tmp3 = L_deposit_l( band_width[i] ); /* Q0 */ exp2 = norm_l( L_tmp3 ); - tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); + tmp2 = extract_h( L_shl( L_tmp3, exp2 ) ); /* exp2 - 16 */ exp2 = sub( exp, exp2 ); /* Denormalize and substract */ @@ -1451,11 +1480,12 @@ void hq_lr_enc_ivas_fx( { exp2 = add( exp2, 1 ); } - tmp = div_s( tmp2, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc1( L_tmp, &exp2 ); - move32(); /*Q(31-exp2) */ - Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q13 */ + tmp = div_s( tmp2, tmp ); /* Q15 */ + L_tmp = L_deposit_h( tmp ); /* Q31 */ + L_tmp = Isqrt_lc1( L_tmp, &exp2 ); /*Q(31-exp2) */ + move32(); + Ep_tmp_fx[i] = L_shr( L_tmp, sub( 15, exp2 ) ); /*Q16 */ + move32(); } #undef WMC_TOOL_SKIP @@ -1473,19 +1503,19 @@ void hq_lr_enc_ivas_fx( trans_bit = 2; move16(); bit_budget = sub( bit_budget, trans_bit ); - gama_fx = 27852; /*Q15 0.85f; */ - beta_fx = 17203; + gama_fx = 27852; /*Q15 0.85f */ + beta_fx = 17203; /*Q14 1.05f */ + move16(); move16(); - move16(); /*Q14 1.05f; */ set_s( &p2a_flags_tmp[bands - trans_bit], 0, 2 ); IF( EQ_32( st->core_brate, ACELP_13k20 ) ) { - beta_fx = 13107; - move16(); /*14 1.25f; */ - gama_fx = 31130; - move16(); /*0.95f; */ - mvs2s( &p2a_flags[sub( bands, trans_bit )], &p2a_flags_tmp[sub( bands, trans_bit )], trans_bit ); + beta_fx = 13107; /* Q14 1.25f */ + move16(); + gama_fx = 31130; /* 0.95f Q15 */ + move16(); + mvs2s( &p2a_flags[( bands - trans_bit )], &p2a_flags_tmp[( bands - trans_bit )], trans_bit ); } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ @@ -1501,8 +1531,8 @@ void hq_lr_enc_ivas_fx( { IF( sub( i, lowband ) >= 0 ) { - 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 */ } ELSE { @@ -1513,19 +1543,23 @@ void hq_lr_enc_ivas_fx( #endif IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) { - Ep_peak_fx = Ep_tmp_fx[i]; - move32(); /*Q15 */ + Ep_peak_fx = Ep_tmp_fx[i]; /*Q15 */ + move32(); } } } /* modify the last p2a_bands subbands band_energies */ k = bands; + move16(); mvl2l( L_band_energy, L_band_energy_tmp, k ); /*Q_band_energy */ Mpy_32_16_ss( Ep_peak_fx, 24576, &L_tmp, &lo ); Mpy_32_16_ss( Ep_peak_fx, shl( sub( bands, lowband ), 9 ), &L_tmp2, &lo ); Mpy_32_16_ss( Ep_avrg_fx, 1126, &L_tmp3, &lo ); - IF( ( ( L_sub( L_tmp, L_shr( Ep_avrgL_fx, 1 ) ) < 0 && st->core_brate == ACELP_13k20 ) || st->core_brate < ACELP_13k20 ) && + test(); + test(); + test(); + IF( ( ( L_sub( L_tmp, L_shr( Ep_avrgL_fx, 1 ) ) < 0 && EQ_32( st->core_brate, ACELP_13k20 ) ) || LT_32( st->core_brate, ACELP_13k20 ) ) && L_sub( L_tmp2, L_tmp3 ) < 0 && L_sub( L_tmp2, L_shr( Ep_avrg_fx, 7 ) ) > 0 ) { FOR( i = lowband; i < bands; i++ ) @@ -1562,10 +1596,10 @@ void hq_lr_enc_ivas_fx( { j = 0; move16(); - FOR( i = sub( bands, trans_bit ); i < bands; i++ ) + FOR( i = ( bands - trans_bit ); i < bands; i++ ) { - alpha_fx = 16384; - move16(); /*Q14 */ + alpha_fx = 16384; /*Q14 */ + move16(); IF( sub( p2a_flags_tmp[i], 1 ) == 0 ) { Mpy_32_16_ss( Ep_tmp_fx[i], sub( bands, lowband ), &L_tmp, &lo ); @@ -1609,7 +1643,7 @@ void hq_lr_enc_ivas_fx( L_tmp2 = L_shl( L_tmp2, sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ L_tmp = L_min( L_tmp, L_tmp2 ); /*14 */ tmp = extract_l( L_min( L_tmp, 13107 ) ); /*14 */ - alpha_fx = add( 16384, tmp ); + alpha_fx = add( 16384, tmp ); /* Q14 */ } IF( sub( hHQ_core->last_bitalloc_max_band[j++], 1 ) == 0 ) { @@ -1669,6 +1703,7 @@ void hq_lr_enc_ivas_fx( } Mpy_32_16_ss( L_band_energy_tmp[i], alpha_fx, &L_tmp, &lo ); L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ + move32(); } } lowband = 3; @@ -1694,13 +1729,16 @@ void hq_lr_enc_ivas_fx( Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) { - Ep_peak_fx = Ep_tmp_fx[i]; - move32(); /*Q13 */ + Ep_peak_fx = Ep_tmp_fx[i]; /*Q13 */ + move32(); } } } Mpy_32_16_ss( Ep_peak_fx, 28262, &L_tmp, &lo ); Mpy_32_16_ss( Ep_avrgL_fx, 24576, &L_tmp2, &lo ); + + test(); + test(); IF( L_sub( L_shr( Ep_avrg_fx, 2 ), L_tmp2 ) > 0 && L_sub( L_shr( Ep_avrg_fx, 4 ), L_tmp2 ) < 0 && L_sub( L_tmp, Ep_avrgL_fx ) > 0 ) { adjustFlag = 1; @@ -1735,6 +1773,7 @@ void hq_lr_enc_ivas_fx( #endif /* BASOP_NOGLOB */ Mpy_32_16_ss( L_band_energy_tmp[i], tmp2, &L_tmp, &lo ); L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ + move32(); } } #undef WMC_TOOL_SKIP @@ -1757,7 +1796,7 @@ void hq_lr_enc_ivas_fx( #ifndef BASOP_NOGLOB Ep_tmp_fx[i] = L_shl( Ep_tmp_fx[i], 2 ); #else /* BASOP_NOGLOB */ - Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); + Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ move32(); #endif /* BASOP_NOGLOB */ } @@ -1767,8 +1806,8 @@ void hq_lr_enc_ivas_fx( move16(); highband = 15; move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[( bands - 1 )], 1 ), band_start[highband] ); /* Q0 */ } ELSE { @@ -1776,8 +1815,8 @@ void hq_lr_enc_ivas_fx( move16(); highband = 16; move16(); - bw_low = sub( band_start[highband], band_start[lowband] ); - bw_high = sub( add( band_end[sub( bands, 1 )], 1 ), band_start[highband] ); + bw_low = sub( band_start[highband], band_start[lowband] ); /* Q0 */ + bw_high = sub( add( band_end[( bands - 1 )], 1 ), band_start[highband] ); /* Q0 */ } /* calculate the the low band/high band energy and the variance/avrage of the envelopes */ enerL_fx = 0; @@ -1790,6 +1829,7 @@ void hq_lr_enc_ivas_fx( move32(); FOR( i = 0; i < bands; i++ ) { + test(); IF( sub( i, lowband ) >= 0 && add( sub( i, bands ), p2a_bands ) < 0 ) { Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ @@ -1811,6 +1851,7 @@ void hq_lr_enc_ivas_fx( } /* modify the last p2a_bands subbands band_energies */ k = bands; + move16(); mvl2l( L_band_energy, L_band_energy_tmp, k ); /*Q_band_energy */ L_tmp = L_max( enerH_fx, enerL_fx ); @@ -1821,7 +1862,7 @@ void hq_lr_enc_ivas_fx( Mpy_32_16_ss( L_shl( enerL_fx, i ), shl( bw_high, j ), &L_tmp2, &lo ); L_tmp2 = L_sub( L_tmp, L_tmp2 ); - FOR( i = sub( bands, p2a_bands ); i < bands; i++ ) + FOR( i = ( bands - p2a_bands ); i < bands; i++ ) { test(); IF( sub( p2a_flags[i], 1 ) == 0 || L_tmp2 > 0 ) @@ -1861,14 +1902,14 @@ void hq_lr_enc_ivas_fx( } ELSE { - alpha_fx = 16384; - move16(); /*Q14 */ + alpha_fx = 16384; /* Q14 */ + move16(); } IF( add( sub( i, bands ), p2a_bands ) > 0 ) { tmp = sub( bands, p2a_bands ); - IF( sub( hHQ_core->last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) == 0 ) + IF( sub( hHQ_core->last_bitalloc_max_band[( i - ( tmp + 1 ) )], 1 ) == 0 ) { tmp = sub( tmp, lowband ); Mpy_32_16_ss( Ep_tmp_fx[i], tmp, &L_tmp, &lo ); @@ -1930,6 +1971,7 @@ void hq_lr_enc_ivas_fx( } Mpy_32_16_ss( L_band_energy_tmp[i], alpha_fx, &L_tmp, &lo ); L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q Q_band_energy */ + move32(); } lowband = 6; move16(); @@ -1958,8 +2000,8 @@ void hq_lr_enc_ivas_fx( #endif /* BASOP_NOGLOB */ IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) { - Ep_peak_fx = Ep_tmp_fx[i]; - move32(); /*Q15 */ + Ep_peak_fx = Ep_tmp_fx[i]; /* Q15 */ + move32(); } } } @@ -2005,6 +2047,7 @@ void hq_lr_enc_ivas_fx( tmp = extract_l( L_min( L_tmp, 19661 ) ); /*Q14 */ Mpy_32_16_ss( L_band_energy_tmp[i], tmp, &L_tmp, &lo ); L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ + move32(); } } #undef WMC_TOOL_SKIP @@ -2065,9 +2108,9 @@ void hq_lr_enc_ivas_fx( } /* Inject noise into components having relatively low pulse energy per band */ - ni_seed = add( add( add( npulses[0], npulses[1] ), npulses[2] ), npulses[3] ); + ni_seed = add( add( add( npulses[0], npulses[1] ), npulses[2] ), npulses[3] ); /* Q0 */ - Copy32( L_y2, L_y2_ni, band_end[bands - 1] + 1 ); + Copy32( L_y2, L_y2_ni, band_end[bands - 1] + 1 ); /* Q12 */ test(); test(); IF( EQ_16( st->bwidth, SWB ) && ( EQ_32( bwe_br, HQ_16k40 ) || EQ_32( bwe_br, HQ_13k20 ) ) ) @@ -2096,16 +2139,16 @@ void hq_lr_enc_ivas_fx( } } } - Copy32( L_y2_ni, L_y2, lowlength ); + Copy32( L_y2_ni, L_y2, lowlength ); /* Q12 */ } ELSE { - Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* HQ_TRANSIENT */ + Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* HQ_TRANSIENT Q12*/ } } ELSE { - Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* NB, WB */ + Copy32( L_y2_ni, L_y2, band_end[bands - 1] + 1 ); /* NB, WB Q12*/ } updat_prev_frm_fx( L_y2, L_t_audio, bwe_br, length, inner_frame, bands, st->bwidth, is_transient, hqswb_clas, &hHQ_core->prev_hqswb_clas, hHQ_core->prev_SWB_peak_pos, prev_SWB_peak_pos_tmp, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, bws_cnt ); @@ -2152,18 +2195,18 @@ void hq_lr_enc_ivas_fx( static Word16 small_symbol_enc_tran_fx( /* o : bits */ BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ - const Word16 is_transient ) + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; FOR( i = 0; i < BANDS; i++ ) { - difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); + difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -2181,8 +2224,8 @@ static Word16 small_symbol_enc_tran_fx( /* o : bits IF( flag_pack == 0 ) { /* estimating # of bits */ - bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ } ELSE { @@ -2191,24 +2234,24 @@ static Word16 small_symbol_enc_tran_fx( /* o : bits encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); } - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode */ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } static Word16 small_symbol_enc_tran_ivas_fx( /* o : bits */ BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ - const Word16 is_transient ) + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; FOR( i = 0; i < BANDS; i++ ) { - difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); + difidx[i] = add( qbidx[i], LRMDCT_BE_OFFSET ); /* Q0 */ move16(); } @@ -2226,8 +2269,8 @@ static Word16 small_symbol_enc_tran_ivas_fx( /* o : bit IF( flag_pack == 0 ) { /* estimating # of bits */ - bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ } ELSE { @@ -2236,7 +2279,7 @@ static Word16 small_symbol_enc_tran_ivas_fx( /* o : bit encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE_TRAN, is_transient ); } - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode */ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } @@ -2250,23 +2293,23 @@ static Word16 small_symbol_enc_tran_ivas_fx( /* o : bit static Word16 small_symbol_enc_fx( /* o : bits */ BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack /* i : indicator of packing or estimating bits */ + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack /* i : indicator of packing or estimating bits Q0*/ , - const Word16 is_transient ) + const Word16 is_transient /* Q0 */ ) { Word16 i, bits; Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; /* Preparing lossless coding input */ - difidx[0] = add( qbidx[0], DE_OFFSET0 ); + difidx[0] = add( qbidx[0], DE_OFFSET0 ); /* Q0 */ move16(); FOR( i = 1; i < BANDS; ++i ) { - difidx[i] = add( qbidx[i], DE_OFFSET1 ); + difidx[i] = add( qbidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } @@ -2283,9 +2326,9 @@ static Word16 small_symbol_enc_fx( /* o : bits /* splitting MSB and LSB */ FOR( i = 0; i < BANDS; ++i ) { - LSB[i] = s_and( difidx[i], 1 ); + LSB[i] = s_and( difidx[i], 1 ); /* Q0 */ move16(); - difidx[i] = shr( difidx[i], 1 ); + difidx[i] = shr( difidx[i], 1 ); /* Q0 */ move16(); } @@ -2294,11 +2337,11 @@ static Word16 small_symbol_enc_fx( /* o : bits { /* estimating # of bits */ /* Encoding MSB bits */ - bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + bits = encode_envelope_indices_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ /* Encoding LSB bit packing */ - bits = add( bits, BANDS ); + bits = add( bits, BANDS ); /* Q0 */ } ELSE { @@ -2314,27 +2357,27 @@ static Word16 small_symbol_enc_fx( /* o : bits } } - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode */ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } static Word16 small_symbol_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode, /* i/o: LC mode info */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits */ - const Word16 is_transient ) + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) { Word16 i, bits; Word16 difidx[BANDS_MAX], LSB[BANDS_MAX]; /* Preparing lossless coding input */ - difidx[0] = add( qbidx[0], DE_OFFSET0 ); + difidx[0] = add( qbidx[0], DE_OFFSET0 ); /* Q0 */ move16(); FOR( i = 1; i < BANDS; ++i ) { - difidx[i] = add( qbidx[i], DE_OFFSET1 ); + difidx[i] = add( qbidx[i], DE_OFFSET1 ); /* Q0 */ move16(); } @@ -2351,9 +2394,9 @@ static Word16 small_symbol_enc_ivas_fx( /* splitting MSB and LSB */ FOR( i = 0; i < BANDS; ++i ) { - LSB[i] = s_and( difidx[i], 1 ); + LSB[i] = s_and( difidx[i], 1 ); /* Q0 */ move16(); - difidx[i] = shr( difidx[i], 1 ); + difidx[i] = shr( difidx[i], 1 ); /* Q0 */ move16(); } @@ -2362,11 +2405,11 @@ static Word16 small_symbol_enc_ivas_fx( { /* estimating # of bits */ /* Encoding MSB bits */ - bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); - bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies */ + bits = encode_envelope_indices_ivas_fx( hBstr, BANDS, -1, difidx, hLCmode, flag_pack, LOW_RATE_HQ_CORE, is_transient ); /* Q0 */ + bits = add( bits, BITS_DE_FCOMP ); /* xx bits for diff. energies + BITS_DE_FCOMP bits for first energies Q0*/ /* Encoding LSB bit packing */ - bits = add( bits, BANDS ); + bits = add( bits, BANDS ); /* Q0 */ } ELSE { @@ -2382,16 +2425,16 @@ static Word16 small_symbol_enc_ivas_fx( } } - return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode */ + return add( bits, BITS_DE_HMODE ); /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } -static Word16 large_symbol_enc_fx( /* o : bits */ +static Word16 large_symbol_enc_fx( /* o : bits Q0*/ BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode0, /* i/o: LC mode info */ - const Word16 flag_pack /* i : indicator of packing or estimating bits */ + Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode0, /* i/o: LC mode info Q0*/ + const Word16 flag_pack /* i : indicator of packing or estimating bits Q0*/ ) { Word16 i, bits, tmp; @@ -2404,7 +2447,7 @@ static Word16 large_symbol_enc_fx( /* o : bits Word16 lsbdepth1; Word16 cnt_outlyer, pos_outlyer, cnt_outlyer0; - min_q = 513; + min_q = 513; /* Q0 */ move16(); max_q = -1; move16(); @@ -2453,15 +2496,15 @@ static Word16 large_symbol_enc_fx( /* o : bits test(); IF( GT_16( qbidx[i], 3 ) || LT_16( qbidx[i], -4 ) ) { - cnt_outlyer = add( cnt_outlyer, 1 ); + cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ pos_outlyer = i; move16(); } test(); - if ( GT_16( qbidx[i], sub( ABS_ENG_OFFSET, 1 ) ) || LT_16( qbidx[i], -ABS_ENG_OFFSET ) ) + IF( GT_16( qbidx[i], ( ABS_ENG_OFFSET - 1 ) ) || LT_16( qbidx[i], -ABS_ENG_OFFSET ) ) { - cnt_outlyer = add( cnt_outlyer, 1 ); + cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ } } @@ -2469,37 +2512,39 @@ static Word16 large_symbol_enc_fx( /* o : bits test(); IF( cnt_outlyer0 == 0 && LE_16( cnt_outlyer, 1 ) ) { - bitsmode0 = add( add( BITS_DE_8SMODE, BITS_DE_8SMODE_N0 ), BITS_DE_8SMODE_N1 ); + bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ + move16(); IF( EQ_16( cnt_outlyer, 1 ) ) { /* 01 */ - bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); + bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ } FOR( i = 0; i < pos_outlyer; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE IF( EQ_16( cnt_outlyer0, 1 ) && LE_16( cnt_outlyer, 1 ) ) { - bitsmode0 = add( add( BITS_DE_8SMODE, BITS_DE_8SMODE_N0 ), BITS_DE_8SMODE_N1 ); - tdifidx0[0] = qbidx[0]; + bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ + move16(); + tdifidx0[0] = qbidx[0]; /* Q0 */ move16(); bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); IF( EQ_16( cnt_outlyer, 1 ) ) { /* 11 */ - bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); + bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ } ELSE { @@ -2509,16 +2554,16 @@ static Word16 large_symbol_enc_fx( /* o : bits FOR( i = 1; i < pos_outlyer; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE @@ -2555,9 +2600,9 @@ static Word16 large_symbol_enc_fx( /* o : bits basic_shift = i; move16(); - min_bits = 1000; + min_bits = 1000; /* Q0 */ move16(); - min_bits_pos = basic_shift; + min_bits_pos = basic_shift; /* Q0 */ move16(); tmp = add( basic_shift, 3 ); FOR( offset0 = basic_shift; offset0 < tmp; offset0++ ) @@ -2567,17 +2612,17 @@ static Word16 large_symbol_enc_fx( /* o : bits min_q = MAXIMUM_ENERGY_LOWBRATE; move16(); - bitsmode1 = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); + bitsmode1 = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ FOR( i = 0; i < BANDS; ++i ) { - bitsmode1 = add( bitsmode1, add( hessize[add( shr( qbidx[i], offset0 ), 4 )], offset0 ) ); + bitsmode1 = add( bitsmode1, add( hessize[( ( qbidx[i] >> offset0 ) + 4 )], offset0 ) ); } IF( GT_16( min_bits, bitsmode1 ) ) { - min_bits_pos = offset0; + min_bits_pos = offset0; /* Q0 */ move16(); - min_bits = bitsmode1; + min_bits = bitsmode1; /* Q0 */ move16(); } } @@ -2591,6 +2636,8 @@ static Word16 large_symbol_enc_fx( /* o : bits { LSB1[i] = s_and( qbidx[i], sub( shl( 1, lsbdepth1 ), 1 ) ); tdifidx1[i] = shr( qbidx[i], lsbdepth1 ); + move16(); + move16(); } } @@ -2601,14 +2648,14 @@ static Word16 large_symbol_enc_fx( /* o : bits /* Encoding MSB bits */ IF( LT_16( bitsmode0, bitsmode1 ) ) { - bits = bitsmode0; + bits = bitsmode0; /* Q0 */ move16(); *hLCmode0 = 0; move16(); } ELSE { - bits = bitsmode1; + bits = bitsmode1; /* Q0 */ move16(); *hLCmode0 = 1; move16(); @@ -2630,7 +2677,7 @@ static Word16 large_symbol_enc_fx( /* o : bits { /* 01 */ push_indice_fx( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice_fx( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); bits = add( bits, BITS_DE_8SPOS ); push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); @@ -2640,19 +2687,19 @@ static Word16 large_symbol_enc_fx( /* o : bits { /* 00 */ push_indice_fx( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ } FOR( i = 0; i < pos_outlyer; ++i ) { push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) + FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) { push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE IF( EQ_16( cnt_outlyer0, 1 ) ) @@ -2662,7 +2709,7 @@ static Word16 large_symbol_enc_fx( /* o : bits IF( EQ_16( cnt_outlyer, 1 ) ) { push_indice_fx( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice_fx( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); bits = add( bits, BITS_DE_8SPOS ); push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); @@ -2673,34 +2720,34 @@ static Word16 large_symbol_enc_fx( /* o : bits ELSE { push_indice_fx( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); + bits = add( bits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < BANDS; ++i ) { push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } } ELSE { - bits = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); + bits = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); /* Q0 */ push_indice_fx( hBstr, IND_HQ2_DENG_8SMODE, 1, BITS_DE_8SMODE ); push_indice_fx( hBstr, IND_HQ2_DENG_8SDEPTH, lsbdepth1, BITS_MAX_DEPTH ); FOR( i = 0; i < BANDS; ++i ) { push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx1[i] + 4], hessize[tdifidx1[i] + 4] ); - bits = add( bits, hessize[tdifidx1[i] + 4] ); + bits = add( bits, hessize[tdifidx1[i] + 4] ); /* Q0 */ } IF( lsbdepth1 > 0 ) @@ -2710,21 +2757,21 @@ static Word16 large_symbol_enc_fx( /* o : bits push_indice_fx( hBstr, IND_HQ2_DIFF_ENERGY, LSB1[i], lsbdepth1 ); } /*bits += BANDS * lsbdepth1; */ - bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); + bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); /* Q0 */ } } } - return bits; /* xx bits for diff. energies + 1 bit for LC coding mode */ + return bits; /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } static Word16 large_symbol_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 *qbidx, /* i : input of dequantized differential energy */ - const Word16 BANDS, /* i : number of bands */ - Word16 *hLCmode0, /* i/o: LC mode info */ - const Word16 flag_pack /* i : indicator of packing or estimating bits */ + Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode0, /* i/o: LC mode info Q0*/ + const Word16 flag_pack /* i : indicator of packing or estimating bits Q0*/ ) { Word16 i, bits, tmp; @@ -2737,7 +2784,7 @@ static Word16 large_symbol_enc_ivas_fx( Word16 lsbdepth1; Word16 cnt_outlyer, pos_outlyer, cnt_outlyer0; - min_q = 513; + min_q = 513; /* Q0 */ move16(); max_q = -1; move16(); @@ -2786,15 +2833,15 @@ static Word16 large_symbol_enc_ivas_fx( test(); IF( GT_16( qbidx[i], 3 ) || LT_16( qbidx[i], -4 ) ) { - cnt_outlyer = add( cnt_outlyer, 1 ); + cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ pos_outlyer = i; move16(); } test(); - if ( GT_16( qbidx[i], sub( ABS_ENG_OFFSET, 1 ) ) || LT_16( qbidx[i], -ABS_ENG_OFFSET ) ) + IF( GT_16( qbidx[i], ( ABS_ENG_OFFSET - 1 ) ) || LT_16( qbidx[i], -ABS_ENG_OFFSET ) ) { - cnt_outlyer = add( cnt_outlyer, 1 ); + cnt_outlyer = add( cnt_outlyer, 1 ); /* Q0 */ } } @@ -2802,37 +2849,39 @@ static Word16 large_symbol_enc_ivas_fx( test(); IF( cnt_outlyer0 == 0 && LE_16( cnt_outlyer, 1 ) ) { - bitsmode0 = add( add( BITS_DE_8SMODE, BITS_DE_8SMODE_N0 ), BITS_DE_8SMODE_N1 ); + bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ + move16(); IF( EQ_16( cnt_outlyer, 1 ) ) { /* 01 */ - bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); + bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); /* Q0 */ } FOR( i = 0; i < pos_outlyer; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) + FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE IF( EQ_16( cnt_outlyer0, 1 ) && LE_16( cnt_outlyer, 1 ) ) { - bitsmode0 = add( add( BITS_DE_8SMODE, BITS_DE_8SMODE_N0 ), BITS_DE_8SMODE_N1 ); - tdifidx0[0] = qbidx[0]; + bitsmode0 = ( BITS_DE_8SMODE + BITS_DE_8SMODE_N0 ) + BITS_DE_8SMODE_N1; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); + tdifidx0[0] = qbidx[0]; /* Q0 */ + move16(); + bitsmode0 = add( bitsmode0, BITS_ABS_ENG ); /* Q0 */ IF( EQ_16( cnt_outlyer, 1 ) ) { /* 11 */ - bitsmode0 = add( bitsmode0, add( BITS_DE_8SPOS, BITS_ABS_ENG ) ); + bitsmode0 = add( bitsmode0, ( BITS_DE_8SPOS + BITS_ABS_ENG ) ); /* Q0 */ } ELSE { @@ -2842,27 +2891,27 @@ static Word16 large_symbol_enc_ivas_fx( FOR( i = 1; i < pos_outlyer; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) + FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) { - tdifidx0[i] = qbidx[i]; + tdifidx0[i] = qbidx[i]; /* Q0 */ move16(); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE { - bitsmode0 = 20000; + bitsmode0 = 20000; /* Q0 */ move16(); } } test(); - IF( flag_pack == 0 || *hLCmode0 == 1 ) + IF( flag_pack == 0 || EQ_16( *hLCmode0, 1 ) ) { /* components 0 range : -256~255 */ max_q = MINIMUM_ENERGY_LOWBRATE; @@ -2888,9 +2937,9 @@ static Word16 large_symbol_enc_ivas_fx( basic_shift = i; move16(); - min_bits = 1000; + min_bits = 1000; /* Q0 */ move16(); - min_bits_pos = basic_shift; + min_bits_pos = basic_shift; /* Q0 */ move16(); tmp = add( basic_shift, 3 ); FOR( offset0 = basic_shift; offset0 < tmp; offset0++ ) @@ -2900,30 +2949,33 @@ static Word16 large_symbol_enc_ivas_fx( min_q = MAXIMUM_ENERGY_LOWBRATE; move16(); - bitsmode1 = add( BITS_DE_8SMODE, BITS_MAX_DEPTH ); + bitsmode1 = ( BITS_DE_8SMODE + BITS_MAX_DEPTH ); /* Q0 */ + move16(); FOR( i = 0; i < BANDS; ++i ) { - bitsmode1 = add( bitsmode1, add( hessize[add( shr( qbidx[i], offset0 ), 4 )], offset0 ) ); + bitsmode1 = add( bitsmode1, add( hessize[( ( qbidx[i] >> offset0 ) + 4 )], offset0 ) ); /* Q0 */ } IF( GT_16( min_bits, bitsmode1 ) ) { - min_bits_pos = offset0; + min_bits_pos = offset0; /* Q0 */ move16(); - min_bits = bitsmode1; + min_bits = bitsmode1; /* Q0 */ move16(); } } - bitsmode1 = min_bits; + bitsmode1 = min_bits; /* Q0 */ move16(); - lsbdepth1 = min_bits_pos; + lsbdepth1 = min_bits_pos; /* Q0 */ move16(); FOR( i = 0; i < BANDS; ++i ) { LSB1[i] = s_and( qbidx[i], sub( shl( 1, lsbdepth1 ), 1 ) ); tdifidx1[i] = shr( qbidx[i], lsbdepth1 ); + move16(); + move16(); } } @@ -2934,14 +2986,14 @@ static Word16 large_symbol_enc_ivas_fx( /* Encoding MSB bits */ IF( LT_16( bitsmode0, bitsmode1 ) ) { - bits = bitsmode0; + bits = bitsmode0; /* Q0 */ move16(); *hLCmode0 = 0; move16(); } ELSE { - bits = bitsmode1; + bits = bitsmode1; /* Q0 */ move16(); *hLCmode0 = 1; move16(); @@ -2963,7 +3015,7 @@ static Word16 large_symbol_enc_ivas_fx( { /* 01 */ push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); bits = add( bits, BITS_DE_8SPOS ); push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[pos_outlyer] + ABS_ENG_OFFSET, BITS_ABS_ENG ); @@ -2973,29 +3025,29 @@ static Word16 large_symbol_enc_ivas_fx( { /* 00 */ push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ } FOR( i = 0; i < pos_outlyer; ++i ) { push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } - FOR( i = add( pos_outlyer, 1 ); i < BANDS; ++i ) + FOR( i = ( pos_outlyer + 1 ); i < BANDS; ++i ) { push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); + bitsmode0 = add( bitsmode0, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } ELSE IF( EQ_16( cnt_outlyer0, 1 ) ) { push_indice( hBstr, IND_HQ2_DENG_8SMODE_N0, 1, BITS_DE_8SMODE_N0 ); - bits = add( bits, BITS_DE_8SMODE_N0 ); + bits = add( bits, BITS_DE_8SMODE_N0 ); /* Q0 */ IF( EQ_16( cnt_outlyer, 1 ) ) { push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 1, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice( hBstr, IND_HQ2_DENG_8SPOS, pos_outlyer, BITS_DE_8SPOS ); bits = add( bits, BITS_DE_8SPOS ); push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); @@ -3006,21 +3058,21 @@ static Word16 large_symbol_enc_ivas_fx( ELSE { push_indice( hBstr, IND_HQ2_DENG_8SMODE_N1, 0, BITS_DE_8SMODE_N1 ); - bits = add( bits, BITS_DE_8SMODE_N1 ); + bits = add( bits, BITS_DE_8SMODE_N1 ); /* Q0 */ push_indice( hBstr, IND_HQ2_DIFF_ENERGY, qbidx[0] + ABS_ENG_OFFSET, BITS_ABS_ENG ); - bits = add( bits, BITS_ABS_ENG ); + bits = add( bits, BITS_ABS_ENG ); /* Q0 */ } FOR( i = 1; i < pos_outlyer; ++i ) { push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ } FOR( i = pos_outlyer + 1; i < BANDS; ++i ) { push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx0[i] + 4], hessize[tdifidx0[i] + 4] ); - bits = add( bits, hessize[tdifidx0[i] + 4] ); + bits = add( bits, hessize[tdifidx0[i] + 4] ); /* Q0 */ } } } @@ -3033,7 +3085,7 @@ static Word16 large_symbol_enc_ivas_fx( FOR( i = 0; i < BANDS; ++i ) { push_indice( hBstr, IND_HQ2_DIFF_ENERGY, hescode[tdifidx1[i] + 4], hessize[tdifidx1[i] + 4] ); - bits = add( bits, hessize[tdifidx1[i] + 4] ); + bits = add( bits, hessize[tdifidx1[i] + 4] ); /* Q0 */ } IF( lsbdepth1 > 0 ) @@ -3043,12 +3095,12 @@ static Word16 large_symbol_enc_ivas_fx( push_indice( hBstr, IND_HQ2_DIFF_ENERGY, LSB1[i], lsbdepth1 ); } /*bits += BANDS * lsbdepth1; */ - bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); + bits = add( bits, extract_h( L_shl( L_mult( BANDS, lsbdepth1 ), 15 ) ) ); /* Q0 */ } } } - return bits; /* xx bits for diff. energies + 1 bit for LC coding mode */ + return bits; /* xx bits for diff. energies + 1 bit for LC coding mode Q0*/ } /*-------------------------------------------------------------------* @@ -3074,6 +3126,7 @@ static Word16 band_energy_quant_fx( Word16 hLCmode0, hLCmode1, deng_bits; Word16 deng_cmode = 0; Word16 hbits; + move16(); Word32 L_E; Word16 QE; @@ -3104,7 +3157,7 @@ static Word16 band_energy_quant_fx( L_tmp = L_deposit_l( 1295 ); /* 1295 = sqrt(0.1) (Qs) */ FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); + L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Qs */ } exp_norm = norm_l( L_tmp ); exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ @@ -3114,18 +3167,19 @@ static Word16 band_energy_quant_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { /*E += yos[i] * yos[i]; */ - temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); - L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ + temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Qs+exp_norm-16 */ + L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ } /*band_energy[k] = (float) log2_f (E + 1.0e-1f); */ exp_norm2 = norm_l( L_E ); exp = add( add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ), exp_norm2 ); - L_E = L_shl( L_E, exp_norm2 ); + L_E = L_shl( L_E, exp_norm2 ); /* (Qs+exp_norm-16)*2 + 1 + exp_norm2 */ frac = Log2_norm_lc( L_E ); exp = sub( 30, exp ); L_tmp = L_Comp( exp, frac ); L_band_energy[k] = L_shr( L_tmp, 2 ); /* Q16->Qbe(Q14) */ + move32(); } IF( is_transient_fx ) @@ -3144,53 +3198,55 @@ static Word16 band_energy_quant_fx( { /*bq1[k] = round_f (band_energy[k] / qint); */ L_tmp = Mpy_32_16_1( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ - bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* 16-(14+Qrev_qint-15) */ + bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* Q0 */ + move16(); } IF( is_transient_fx ) { - Copy( bq1_fx, bq1_temp_fx, bands_fx ); + Copy( bq1_fx, bq1_temp_fx, bands_fx ); /* Q0 */ /* Calculate the differential energies */ diffcod_lrmdct_fx( bands_fx, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient_fx ); } /* Calculate the differential energies */ - bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); + bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); /* Q0 */ + move16(); FOR( k = 1; k < bands_fx; k++ ) { - bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); + bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); /* Q0 */ move16(); } /* Modifying qbidx to be located in the range -256~255 */ FOR( i = 0; i < bands_fx; ++i ) { - if ( GT_16( bq2_fx[i], MAXIMUM_ENERGY_LOWBRATE ) ) + IF( GT_16( bq2_fx[i], MAXIMUM_ENERGY_LOWBRATE ) ) { - bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; + bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; /* Q0 */ move16(); } - if ( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) + IF( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) { - bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; + bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; /* Q0 */ move16(); } } /* Get number of bits by Huffman0 coding */ - ebits = large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 0 ); + ebits = large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 0 ); /* Q0 */ IF( is_transient_fx ) { /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_tran_fx( hBstr, bq2_temp_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); + hbits = small_symbol_enc_tran_fx( hBstr, bq2_temp_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ } ELSE { /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); + hbits = small_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 0, is_transient_fx ); /* Q0 */ } /* comparing used bits */ @@ -3201,7 +3257,7 @@ static Word16 band_energy_quant_fx( move16(); push_indice_fx( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); large_symbol_enc_fx( hBstr, bq2_fx, bands_fx, &hLCmode0, 1 ); - deng_bits = add( ebits, BITS_DE_CMODE ); + deng_bits = add( ebits, BITS_DE_CMODE ); /* Q0 */ } ELSE { @@ -3210,12 +3266,12 @@ static Word16 band_energy_quant_fx( move16(); push_indice_fx( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - deng_bits = add( hbits, BITS_DE_CMODE ); + deng_bits = add( hbits, BITS_DE_CMODE ); /* Q0 */ /* packing indice */ IF( is_transient_fx ) { - Copy( bq2_temp_fx, bq2_fx, bands_fx ); + Copy( bq2_temp_fx, bq2_fx, bands_fx ); /* Q0 */ small_symbol_enc_tran_fx( hBstr, bq2_fx, bands_fx, &hLCmode1, 1, is_transient_fx ); } ELSE @@ -3225,17 +3281,18 @@ static Word16 band_energy_quant_fx( } /* Reconstruct quantized spectrum */ - bq1_fx[0] = add( bq2_fx[0], bq0_fx ); + bq1_fx[0] = add( bq2_fx[0], bq0_fx ); /* Q0 */ move16(); FOR( k = 1; k < bands_fx; k++ ) { - bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); + bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); /* Q0 */ move16(); } FOR( k = 0; k < bands_fx; k++ ) { L_band_energy[k] = Mpy_32_16_1( L_qint, bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ + move32(); } IF( is_transient_fx ) @@ -3243,7 +3300,7 @@ static Word16 band_energy_quant_fx( reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } - return ( deng_bits ); + return ( deng_bits ); /* Q0 */ } @@ -3294,7 +3351,7 @@ static Word16 band_energy_quant_ivas_fx( L_tmp = L_deposit_l( 1295 ); /* 1295 = sqrt(0.1) (Qs) */ FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); + L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Qs */ } exp_norm = norm_l( L_tmp ); exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ @@ -3304,18 +3361,19 @@ static Word16 band_energy_quant_ivas_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { /*E += yos[i] * yos[i]; */ - temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); - L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ + temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Qs+exp_norm-16 */ + L_E = L_mac( L_E, temp_fx, temp_fx ); /* (Qs+exp_norm-16)*2+1 */ } /*band_energy[k] = (float) log2_f (E + 1.0e-1f); */ exp_norm2 = norm_l( L_E ); exp = add( add( shl( sub( add( SWB_BWE_LR_Qs, exp_norm ), 16 ), 1 ), 1 ), exp_norm2 ); - L_E = L_shl( L_E, exp_norm2 ); + L_E = L_shl( L_E, exp_norm2 ); /* (Qs+exp_norm-16)*2 + 1 + exp_norm2 */ frac = Log2_norm_lc( L_E ); exp = sub( 30, exp ); L_tmp = L_Comp( exp, frac ); L_band_energy[k] = L_shr( L_tmp, 2 ); /* Q16->Qbe(Q14) */ + move32(); } IF( is_transient ) @@ -3333,24 +3391,26 @@ static Word16 band_energy_quant_ivas_fx( { /*bq1[k] = round_f (band_energy[k] / qint); */ L_tmp = L_mls( L_band_energy[k], rev_qint_fx ); /* Q14+Qrev_qint-15 */ - bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* 16-(14+Qrev_qint-15) */ + bq1_fx[k] = round_fx( L_shl( L_tmp, sub( 17, Qrev_qint ) ) ); /* Q0 */ + move16(); } #undef WMC_TOOL_SKIP IF( is_transient ) { - Copy( bq1_fx, bq1_temp_fx, bands ); + Copy( bq1_fx, bq1_temp_fx, bands ); /* Q0 */ /* Calculate the differential energies */ - diffcod_lrmdct_fx( bands, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient ); + diffcod_lrmdct_fx( bands, bq0_fx, bq1_temp_fx, bq2_temp_fx, is_transient ); /* Q0 */ } /* Calculate the differential energies */ - bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); + bq2_fx[0] = sub( bq1_fx[0], bq0_fx ); /* Q0 */ + move16(); FOR( k = 1; k < bands; k++ ) { - bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); + bq2_fx[k] = sub( bq1_fx[k], bq1_fx[k - 1] ); /* Q0 */ move16(); } @@ -3358,30 +3418,30 @@ static Word16 band_energy_quant_ivas_fx( /* Modifying qbidx to be located in the range -256~255 */ FOR( i = 0; i < bands; ++i ) { - if ( bq2_fx[i] > MAXIMUM_ENERGY_LOWBRATE ) + IF( GT_16( bq2_fx[i], MAXIMUM_ENERGY_LOWBRATE ) ) { - bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; + bq2_fx[i] = MAXIMUM_ENERGY_LOWBRATE; /* Q0 */ move16(); } - if ( bq2_fx[i] < MINIMUM_ENERGY_LOWBRATE ) + IF( LT_16( bq2_fx[i], MINIMUM_ENERGY_LOWBRATE ) ) { - bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; + bq2_fx[i] = MINIMUM_ENERGY_LOWBRATE; /* Q0 */ move16(); } } /* Get number of bits by Huffman0 coding */ - ebits = large_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode0, 0 ); + ebits = large_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode0, 0 ); /* Q0 */ IF( is_transient ) { /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_tran_ivas_fx( hBstr, bq2_temp_fx, bands, &hLCmode1, 0, is_transient ); + hbits = small_symbol_enc_tran_ivas_fx( hBstr, bq2_temp_fx, bands, &hLCmode1, 0, is_transient ); /* Q0 */ } ELSE { /* Get number of bits by Huffman coding */ - hbits = small_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 0, is_transient ); + hbits = small_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 0, is_transient ); /* Q0 */ } test(); @@ -3391,7 +3451,7 @@ static Word16 band_energy_quant_ivas_fx( move16(); push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); large_symbol_enc_ivas_fx( hBstr, bq2_fx, bands, &hLCmode0, 1 ); - deng_bits = add( ebits, BITS_DE_CMODE ); + deng_bits = add( ebits, BITS_DE_CMODE ); /* Q0 */ } ELSE { @@ -3400,12 +3460,12 @@ static Word16 band_energy_quant_ivas_fx( move16(); push_indice( hBstr, IND_HQ2_DENG_MODE, deng_cmode, BITS_DE_CMODE ); - deng_bits = add( hbits, BITS_DE_CMODE ); + deng_bits = add( hbits, BITS_DE_CMODE ); /* Q0 */ /* packing indice */ IF( is_transient ) { - Copy( bq2_temp_fx, bq2_fx, bands ); + Copy( bq2_temp_fx, bq2_fx, bands ); /* Q0 */ small_symbol_enc_tran_ivas_fx( hBstr, bq2_fx, bands, &hLCmode1, 1, is_transient ); } ELSE @@ -3415,17 +3475,19 @@ static Word16 band_energy_quant_ivas_fx( } /* Reconstruct quantized spectrum */ - bq1_fx[0] = add( bq2_fx[0], bq0_fx ); + bq1_fx[0] = add( bq2_fx[0], bq0_fx ); /* Q0 */ + move16(); FOR( k = 1; k < bands; k++ ) { - bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); + bq1_fx[k] = add( bq2_fx[k], bq1_fx[k - 1] ); /* Q0 */ + move16(); } FOR( k = 0; k < bands; k++ ) { #define WMC_TOOL_SKIP - L_band_energy[k] = L_mls( L_qint, (Word16) bq1_fx[k] ); - move32(); /* 29+0-15 -> Qbe(Q14) */ + L_band_energy[k] = L_mls( L_qint, (Word16) bq1_fx[k] ); /* 29+0-15 -> Qbe(Q14) */ + move32(); #undef WMC_TOOL_SKIP } @@ -3434,7 +3496,7 @@ static Word16 band_energy_quant_ivas_fx( reverse_transient_frame_energies_fx( L_band_energy, bands ); } - return ( deng_bits ); + return ( deng_bits ); /* Q0 */ } @@ -3474,16 +3536,18 @@ static Word16 p2a_threshold_quant_fx( Word16 p2a_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif exp_safe = 4; /* never happen overflow. */ + move16(); set16_fx( p2a_flags_fx, 1, bands ); move16(); j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = ( bands - p2a_bands ); k < bands; k++ ) { L_a = L_deposit_l( 0 ); L_p = L_deposit_l( 0 ); @@ -3491,7 +3555,7 @@ static Word16 p2a_threshold_quant_fx( L_tmp = L_deposit_l( 0 ); FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); + L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Q12 */ } exp_norm = norm_l( L_tmp ); exp_norm = sub( exp_norm, exp_safe ); @@ -3499,9 +3563,9 @@ static Word16 p2a_threshold_quant_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult( temp_fx, temp_fx ); + L_e = L_mult( temp_fx, temp_fx ); /* 2*(exp_norm-4)+1 */ - if ( GT_32( L_e, L_p ) ) + IF( GT_32( L_e, L_p ) ) { L_p = L_add( L_e, 0 ); } @@ -3515,8 +3579,8 @@ static Word16 p2a_threshold_quant_fx( exp_normn = norm_l( L_a ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( band_width[k] ); - norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); - Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); /* (Qa+exp_normn)-exp_normd-1); */ + norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); /* (Qa+exp_normn)-exp_normd-1); */ + Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); /*p2a = 10.0f * (float) log10 (p / a); */ p2a_fx = 0; @@ -3526,7 +3590,7 @@ static Word16 p2a_threshold_quant_fx( exp_normn = norm_l( L_p ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( norm_a_fx ); - pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); + pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); /* Qpa + exp_normn + Qnorm_a + exp_normd - 1 */ Qpa = sub( sub( add( Qa, exp_normn ), add( Qnorm_a, exp_normd ) ), 1 ); L_tmp = L_deposit_h( pa_fx ); @@ -3547,7 +3611,7 @@ static Word16 p2a_threshold_quant_fx( #endif } - if ( LE_16( p2a_fx, p2a_th_fx ) ) + IF( LE_16( p2a_fx, p2a_th_fx ) ) { p2a_flags_fx[k] = 0; move16(); @@ -3563,7 +3627,7 @@ static Word16 p2a_threshold_quant_fx( j = add( j, 1 ); } - return ( j ); + return ( j ); /* Q0 */ } static Word16 p2a_threshold_quant_ivas_fx( @@ -3596,6 +3660,7 @@ static Word16 p2a_threshold_quant_ivas_fx( Word16 p2a_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif exp_safe = 4; /* never happen overflow. */ @@ -3605,7 +3670,7 @@ static Word16 p2a_threshold_quant_ivas_fx( j = 0; move16(); - FOR( k = sub( bands, p2a_bands ); k < bands; k++ ) + FOR( k = ( bands - p2a_bands ); k < bands; k++ ) { L_a = L_deposit_l( 0 ); L_p = L_deposit_l( 0 ); @@ -3613,7 +3678,7 @@ static Word16 p2a_threshold_quant_ivas_fx( L_tmp = L_deposit_l( 0 ); FOR( i = band_start[k]; i <= band_end[k]; i++ ) { - L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); + L_tmp = L_or( L_tmp, L_abs( L_t_audio[i] ) ); /* Q12 */ } exp_norm = norm_l( L_tmp ); exp_norm = sub( exp_norm, exp_safe ); @@ -3621,9 +3686,9 @@ static Word16 p2a_threshold_quant_ivas_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { temp_fx = round_fx( L_shl( L_t_audio[i], exp_norm ) ); /* Q12+exp_norm-16 -> exp_norm-4 */ - L_e = L_mult( temp_fx, temp_fx ); + L_e = L_mult( temp_fx, temp_fx ); /* (exp_norm-4)*2 + 1 */ - if ( GT_32( L_e, L_p ) ) + IF( GT_32( L_e, L_p ) ) { L_p = L_add( L_e, 0 ); } @@ -3637,8 +3702,8 @@ static Word16 p2a_threshold_quant_ivas_fx( exp_normn = norm_l( L_a ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( band_width[k] ); - norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); - Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); /* (Qa+exp_normn)-exp_normd-1); */ + norm_a_fx = div_l( L_shl( L_a, exp_normn ), shl( band_width[k], exp_normd ) ); /* (Qa+exp_normn)-exp_normd-1); */ + Qnorm_a = sub( sub( add( Qa, exp_normn ), exp_normd ), 1 ); /*p2a = 10.0f * (float) log10 (p / a); */ p2a_fx = 0; @@ -3648,7 +3713,7 @@ static Word16 p2a_threshold_quant_ivas_fx( exp_normn = norm_l( L_p ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_s( norm_a_fx ); - pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); + pa_fx = div_l( L_shl( L_p, exp_normn ), shl( norm_a_fx, exp_normd ) ); /* Qpa + exp_normn + Qnorm_a + exp_normd - 1 */ Qpa = sub( sub( add( Qa, exp_normn ), add( Qnorm_a, exp_normd ) ), 1 ); L_tmp = L_deposit_h( pa_fx ); @@ -3669,7 +3734,7 @@ static Word16 p2a_threshold_quant_ivas_fx( #endif } - if ( LE_16( p2a_fx, p2a_th_fx ) ) + IF( LE_16( p2a_fx, p2a_th_fx ) ) { p2a_flags_fx[k] = 0; move16(); @@ -3685,7 +3750,7 @@ static Word16 p2a_threshold_quant_ivas_fx( j = add( j, 1 ); } - return ( j ); + return ( j ); /* Q0 */ } @@ -3735,6 +3800,7 @@ static void mdct_spectrum_fine_gain_enc_fx( Word16 imin_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Fine gain quantization on only the most significant energy bands */ @@ -3743,23 +3809,25 @@ static void mdct_spectrum_fine_gain_enc_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 ) ); /* 29+exp_normn-(exp_normd)-1; */ + Qdelta = add( sub( exp_normn, exp_normd ), 28 ); + L_delta = L_shl( L_deposit_h( delta_fx ), sub( 13, Qdelta ) ); /* Q29 */ /*q = (-qint + delta) / 2.0f; */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q29 */ FOR( i = 0; i < gqlevs; i++ ) { /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ - L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); + L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); /* Q16 */ temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); Qgt = sub( 14, temp_hi_fx ); gain_table_fx[i] = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qgt */ + move16(); /*q += delta; */ L_q = L_add( L_q, L_delta ); gain_table_fx[i] = shl( gain_table_fx[i], sub( 14, Qgt ) ); /* Qgt -> Q14 */ + move16(); } FOR( k = sub( bands, Ngq ); k < bands; k++ ) @@ -3776,8 +3844,8 @@ static void mdct_spectrum_fine_gain_enc_fx( L_temp = L_deposit_l( 0 ); FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { - L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); - L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); + L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); /* Q12 */ + L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); /* Q12 */ } exp_norm = norm_l( L_temp ); exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ @@ -3788,12 +3856,12 @@ static void mdct_spectrum_fine_gain_enc_fx( FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { /*Eyy += y2[i] * y2[i]; */ - temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); - L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); + temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ + L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ /*Exy += ybuf[i] * y2[i]; */ - temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); - L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); + temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ + L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ } test(); @@ -3804,7 +3872,7 @@ static void mdct_spectrum_fine_gain_enc_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_l( L_Eyy ); #ifdef BASOP_NOGLOB - gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); + gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); /* Qgamma */ #else gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx( L_shl( L_Eyy, exp_normd ) ) ); #endif @@ -3817,18 +3885,18 @@ static void mdct_spectrum_fine_gain_enc_fx( move16(); FOR( i = 0; i < gqlevs; i++ ) { - d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); + d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); /* Q14 */ IF( LT_16( d_fx, dmin_fx ) ) { - dmin_fx = d_fx; + dmin_fx = d_fx; /* Q14 */ move16(); imin_fx = i; move16(); } } - gamma_fx = gain_table_fx[imin_fx]; - move16(); /* Q14 */ + gamma_fx = gain_table_fx[imin_fx]; /* Q14 */ + move16(); FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { @@ -3836,11 +3904,13 @@ static void mdct_spectrum_fine_gain_enc_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(); } } } @@ -3896,6 +3966,7 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( Word16 imin_fx; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* Fine gain quantization on only the most significant energy bands */ @@ -3905,22 +3976,24 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( 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 ) ); + 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 ) ); /* Q29 */ /*q = (-qint + delta) / 2.0f; */ - L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); + L_q = L_shr( L_sub( L_delta, L_qint ), 1 ); /* Q29 */ FOR( i = 0; i < gqlevs; i++ ) { /*gain_table[i] = (float) pow (2.0f, q * 0.5f); */ - L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); + L_temp = L_shr( L_shr( L_q, 1 ), sub( 29, 16 ) ); /* Q16 */ temp_lo_fx = L_Extract_lc( L_temp, &temp_hi_fx ); Qgt = sub( 14, temp_hi_fx ); gain_table_fx[i] = extract_l( Pow2( 14, temp_lo_fx ) ); /* Qgt */ + move16(); /*q += delta; */ L_q = L_add( L_q, L_delta ); gain_table_fx[i] = shl( gain_table_fx[i], sub( 14, Qgt ) ); /* Qgt -> Q14 */ + move16(); } FOR( k = sub( bands, Ngq ); k < bands; k++ ) @@ -3937,8 +4010,8 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( L_temp = L_deposit_l( 0 ); FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { - L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); - L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); + L_temp = L_or( L_temp, L_abs( L_y2[i] ) ); /* Q12 */ + L_temp = L_or( L_temp, L_abs( L_ybuf[i] ) ); /* Q12 */ } exp_norm = norm_l( L_temp ); exp_norm = sub( exp_norm, exp_safe ); /* safe_shift */ @@ -3949,12 +4022,12 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { /*Eyy += y2[i] * y2[i]; */ - temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); - L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); + temp_fx = round_fx( L_shl( L_y2[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ + L_Eyy = L_mac( L_Eyy, temp_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ /*Exy += ybuf[i] * y2[i]; */ - temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); - L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); + temp2_fx = round_fx( L_shl( L_ybuf[i], exp_norm ) ); /* Q12 + exp_norm - 16 */ + L_Exy = L_mac( L_Exy, temp2_fx, temp_fx ); /* (Q12 + exp_norm - 16)*2 + 1 */ } test(); @@ -3965,7 +4038,7 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( exp_normn = sub( exp_normn, 1 ); exp_normd = norm_l( L_Eyy ); #ifdef BASOP_NOGLOB - gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); + gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); /* Qgamma */ #else gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx( L_shl( L_Eyy, exp_normd ) ) ); #endif @@ -3978,18 +4051,18 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( move16(); FOR( i = 0; i < gqlevs; i++ ) { - d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); + d_fx = abs_s( sub( gamma_fx, gain_table_fx[i] ) ); /* Q14 */ IF( LT_16( d_fx, dmin_fx ) ) { - dmin_fx = d_fx; + dmin_fx = d_fx; /* Q14 */ move16(); - imin_fx = i; + imin_fx = i; /* Q0 */ move16(); } } - gamma_fx = gain_table_fx[imin_fx]; - move16(); /* Q14 */ + gamma_fx = gain_table_fx[imin_fx]; /* Q14 */ + move16(); FOR( i = band_start[k_sort[k]]; i <= band_end[k_sort[k]]; i++ ) { @@ -3997,11 +4070,13 @@ static void mdct_spectrum_fine_gain_enc_ivas_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_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 11dde0745d1362dfcaa0a2272b793b8ebeb71e3e..372afad233e312d4891c6e30483a298916c1dabf 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -273,6 +273,28 @@ ivas_error ivas_cpe_enc_fx( #ifdef MSAN_FIX set32_fx( band_energies_LR_fx, 0, 2 * NB_BANDS ); #endif + + IF( hCPE->hFrontVad[0] != NULL && NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) ) + { + Word16 scale_inp = Q15; + Q_add = 0; + move16(); + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + scale_inp = s_min( sts[n]->q_inp, hCPE->hFrontVad[n]->q_mem_decim ); + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + Scale_sig( sts[n]->input_fx, input_frame, sub( scale_inp, sts[n]->q_inp ) ); + Scale_sig( hCPE->hFrontVad[n]->mem_decim_fx, 2 * L_FILT_MAX, sub( scale_inp, hCPE->hFrontVad[n]->q_mem_decim ) ); + sts[n]->q_inp = scale_inp; + move16(); + hCPE->hFrontVad[n]->q_mem_decim = scale_inp; + } + Q_inp = scale_inp; + move16(); + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) { Q_buffer[n] = 15; @@ -417,7 +439,7 @@ ivas_error ivas_cpe_enc_fx( stereo_tca_enc_fx( hCPE, input_frame ); shift = s_min( 0, sub( add( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); - shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[0]->q_inp32 ), 16 ) ); + shift = s_min( shift, sub( add( L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), sts[1]->q_inp32 ), 16 ) ); Copy_Scale_sig32_16( sts[0]->input_buff32_fx, sts[0]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[0]->q_inp32 ) ); // shift Copy_Scale_sig32_16( sts[1]->input_buff32_fx, sts[1]->input_buff_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( add( Q16, shift ), sts[1]->q_inp32 ) ); // shift diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 023b9fa59b72e7cb023a38f0937677bc526dc58d..5467d7854ab6ee0639860d08cf55b6859a71009a 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -200,12 +200,25 @@ ivas_error front_vad_fx( IF( *front_create_flag ) { + Word16 scale_inp = Q15; + Q_add = 0; + move16(); FOR( n = 0; n < n_chan; n++ ) { scale_sig32( hFrontVads[n]->hNoiseEst->bckr_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ scale_sig32( hFrontVads[n]->hNoiseEst->enrO_fx, 20, sub( add( Q_new_old, QSCALE ), Q11 ) ); /* Q_new_old + QSCALE */ hFrontVads[n]->lp_speech_fx = shr( hFrontVads[n]->lp_speech_fx, 1 ); move16(); + + scale_inp = s_min( sts[n]->q_inp, hCPE->hFrontVad[n]->q_mem_decim ); + Scale_sig( sts[n]->input_fx, input_frame, sub( scale_inp, sts[n]->q_inp ) ); + Scale_sig( hCPE->hFrontVad[n]->mem_decim_fx, 2 * L_FILT_MAX, sub( scale_inp, hCPE->hFrontVad[n]->q_mem_decim ) ); + sts[n]->q_inp = scale_inp; + hCPE->hFrontVad[n]->q_mem_decim = scale_inp; + Q_inp = scale_inp; + move16(); + Q_buffer[n] = hCPE->hFrontVad[n]->q_buffer_12k8; + move16(); } } @@ -415,8 +428,8 @@ ivas_error front_vad_create_fx( move16(); hFrontVad->q_mem_preemph_fx = Q15; move16(); - hFrontVad->q_buffer_12k8 = Q31; - hFrontVad->q_mem_decim = Q31; + hFrontVad->q_buffer_12k8 = Q15; + hFrontVad->q_mem_decim = Q15; hFrontVad->ini_frame = 0; move16(); hFrontVad->hVAD->vad_flag = 1; diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index c2e4f350c3d4900bf43ac04cd45f0b7f3afcea8a..6e8890e4c0c954751e45887c54ac69b6bac57f42 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -906,7 +906,7 @@ void unclr_classifier_td_fx( test(); test(); test(); - if ( ( ( hStereoClassif->unclr_decision == 0 && GT_32( hStereoClassif->unclr_wscore_fx, 214748365 /*0.1f in Q31*/ ) ) || ( EQ_16( hStereoClassif->unclr_decision, 1 ) && LT_32( hStereoClassif->unclr_wscore_fx, 150323855 /*-0.07f in Q31*/ ) ) ) && ( hStereoClassif->unclr_sw_enable_cnt[0] > 0 || hStereoClassif->unclr_sw_enable_cnt[1] > 0 ) ) + if ( ( ( hStereoClassif->unclr_decision == 0 && GT_32( hStereoClassif->unclr_wscore_fx, 214748365 /*0.1f in Q31*/ ) ) || ( EQ_16( hStereoClassif->unclr_decision, 1 ) && LT_32( hStereoClassif->unclr_wscore_fx, -150323855 /*-0.07f in Q31*/ ) ) ) && ( hStereoClassif->unclr_sw_enable_cnt[0] > 0 || hStereoClassif->unclr_sw_enable_cnt[1] > 0 ) ) { /* let's switch the binary decision */ hStereoClassif->unclr_decision = !hStereoClassif->unclr_decision; diff --git a/lib_enc/ivas_stereo_ica_enc.c b/lib_enc/ivas_stereo_ica_enc.c index 6020d83516321a44fe1a58e145ac74e88aee9971..f7cf971efb50e946c9f84a0ad41a0993b4f184f9 100644 --- a/lib_enc/ivas_stereo_ica_enc.c +++ b/lib_enc/ivas_stereo_ica_enc.c @@ -99,7 +99,7 @@ static void tcaTargetCh_LA_fx( ref_exp = sub( 31, *q_com ); target_exp = sub( 31, *q_com ); - set16_fx( target_exp_temp, target_exp, L_FRAME48k + 30 ); + set16_fx( target_exp_temp, target_exp, L_FRAME48k + currentNCShift ); IF( EQ_16( hStereoTCA->refChanIndx, L_CH_INDX ) ) { @@ -187,7 +187,7 @@ static void tcaTargetCh_LA_fx( exp_com = s_max( exp_com, target_exp_temp[i + currentNCShift] ); } - FOR( i = 0; i < input_frame; i++ ) + FOR( i = 0; i < input_frame + currentNCShift; i++ ) { target[i] = L_shl( target[i], sub( target_exp_temp[i], exp_com ) ); /* Q31-exp_com */ move32(); @@ -1942,6 +1942,10 @@ void stereo_tca_enc_fx( ELSE { v_multc_fixed( target_fx - tempS, hStereoTCA->prevTargetGain_fx, &( input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh - tempS - currentNCShift] ), add( currentNCShift, tempS ) ); /* bufChan_q - 2 */ + scale_sig32( input_mem_loc_fx[target_idx], sub( sub( add( lMemRecalc, lMemRecalc_SCh ), tempS ), currentNCShift ), -2 ); + scale_sig32( &input_mem_loc_fx[target_idx][lMemRecalc + lMemRecalc_SCh], sub( NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ), add( lMemRecalc, lMemRecalc_SCh ) ), -2 ); + scale_sig32( input_mem_loc_fx[0], NS2SA( 48000, L_MEM_RECALC_NS + L_MEM_RECALC_SCH_NS ), -2 ); + input_mem_loc_q = sub( bufChan_q, 2 ); } } @@ -2026,16 +2030,14 @@ void stereo_tca_enc_fx( /* Temporal channel adjustment of the LA samples based on the NC shift */ tcaTargetCh_LA_fx( hStereoTCA, ptrChanL_fx, ptrChanR_fx, &q_com, currentNCShift, input_frame ); - Word16 additional_length = NS2SA( L_mult0( input_frame, FRAMES_PER_SEC ), L_SAMPLES_LA_NS ); - move16(); - scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) - scale_sig32( bufChanL_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) - scale_sig32( bufChanL_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanL_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanL_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanL_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) /* Scaling to common Q*/ - scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) - scale_sig32( bufChanR_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) - scale_sig32( bufChanR_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, additional_length ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanR_fx, add( lMemRecalc, lMemRecalc_SCh ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanR_fx + add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ), sub( s_min( q_com, bufChan_q ), q_com ) ); // s_min( q_com, bufChan_q ) + scale_sig32( bufChanR_fx + add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ) ), sub( L_MEM_RECALC_48K + L_MEM_RECALC_48k_SCH + L_FRAME48k + L_NCSHIFTMAX, add( add( lMemRecalc, lMemRecalc_SCh ), add( input_frame, currentNCShift ) ) ), sub( s_min( q_com, bufChan_q ), bufChan_q ) ); // s_min( q_com, bufChan_q ) bufChan_q = s_min( q_com, bufChan_q ); q_com = bufChan_q; } @@ -2053,13 +2055,18 @@ void stereo_tca_enc_fx( sts[1]->q_inp32 = input_mem_loc_q; move16(); - icaMemUpdate_fx( sts, hCPE, input_mem_loc_fx[0], input_mem_loc_fx[1], q_com, lMemRecalc, lMemRecalc_SCh, input_frame ); + icaMemUpdate_fx( sts, hCPE, input_mem_loc_fx[0], input_mem_loc_fx[1], input_mem_loc_q, lMemRecalc, lMemRecalc_SCh, input_frame ); /* populate the st->input target buffer */ test(); IF( hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 || EQ_16( prev_ICA_flag, 1 ) ) { - Copy32( target_fx + currentNCShift, sts[target_idx]->input32_fx, input_frame ); /* bufChan_q */ + Word16 shift = sub( q_com, sts[target_idx]->q_inp32 ); + FOR( Word16 idx = 0; idx < input_frame; idx++ ) + { + sts[target_idx]->input32_fx[idx] = L_shr( target_fx[currentNCShift + idx], shift ); + move32(); + } } IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 8a0c0b82933b1dca2ddb7053b878e1840b1f97b7..7af3830abdbb2a3877d8010aea0d41ede9a837a3 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -313,10 +313,10 @@ void fine_gain_quant_fx( void hq_core_enc_fx( Encoder_State *st_fx, const Word16 *audio, /* i : i audio signal Q0 */ - const Word16 input_frame_orig, /* i : frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 input_frame_orig, /* i : frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ + const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ ); void long_enr_fx( @@ -963,18 +963,18 @@ void norm_corr_ivas_fx( const Word16 L_subfr /* i : subframe size */ ); Word16 peak_avrg_ratio_fx( - const Word32 total_brate, - const Word32 *input_hi_fx, /* i : i signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + const Word32 total_brate, /* Q0 */ + const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ + const Word16 length, /* i : number of coefficients Q0*/ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ); Word16 peak_avrg_ratio_ivas_fx( - const Word32 total_brate, - const Word32 *input_hi_fx, /* i : i signal */ - const Word16 length, /* i : number of coefficients */ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count */ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count */ + const Word32 total_brate, /* Q0 */ + const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ + const Word16 length, /* i : number of coefficients Q0*/ + Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ + Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ); void hvq_classifier_ivas_fx( const Word32 *input, /* i : input signal Q12 */ @@ -4098,7 +4098,7 @@ void hq_hr_enc_fx( const Word16 length, /* i : length of spectrum Q0 */ Word16 *num_bits, /* i : number of available bits Q0 */ const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0 */ ); void hq_hr_enc_ivas_fx( @@ -4107,7 +4107,7 @@ void hq_hr_enc_ivas_fx( const Word16 length, /* i : length of spectrum Q0 */ Word16 *num_bits, /* i : number of available bits Q0 */ const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag */ + const Word16 vad_hover_flag /* i : VAD hangover flag Q0 */ ); void reordernorm_fx( @@ -4156,7 +4156,7 @@ void diff_envelope_coding_fx( ); Word16 encode_envelope_indices_ivas_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ const Word16 num_sfm, /* i : Number of subbands Q0 */ const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ @@ -4279,7 +4279,7 @@ ivas_error tcq_core_LR_enc_ivas_fx( const Word16 is_transient ); Word16 encode_envelope_indices_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ const Word16 num_sfm, /* i : Number of subbands Q0 */ const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ diff --git a/lib_enc/range_enc_fx.c b/lib_enc/range_enc_fx.c index 15e3f398348f70803c7e76c89e3055515cb2ee1c..05916e8013e76d05abec274e198c039c9e23c48e 100644 --- a/lib_enc/range_enc_fx.c +++ b/lib_enc/range_enc_fx.c @@ -163,7 +163,7 @@ void rc_enc_finish_ivas_fx( L_xor( 0, 0 ); /* For bit not */ } - if ( LT_32( val, hPVQ->rc_low ) ) + if ( LT_64( val, hPVQ->rc_low ) ) { hPVQ->rc_carry = 1; move16(); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 3c6876fcb5369b92047669cc908742f4627425fb..3dfb552e6024ad70002462a4a96c5f4f2bc9726d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1290,6 +1290,7 @@ void wb_tbe_enc_ivas_fx( Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; Word16 shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4]; + Word16 shaped_wb_exc_scale[L_SHB_LAHEAD / 4]; Word16 exc4kWhtnd[L_FRAME16k / 4]; /*Word16 ana_align_delay = WBTBE_ANA_ALIGNDELAY; */ /* -L_SHB_LAHEAD/4 - 5 */ Word32 GainFrame; @@ -1309,7 +1310,7 @@ void wb_tbe_enc_ivas_fx( /*Word16 ramp_flag;*/ Word32 p2m_in, p2m_out; /*Word16 cnt, max =0;*/ - Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out; /* Q_hb_frame; */ + Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_pow; /* Q_hb_frame; */ Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; Word16 Q_ns = -1; @@ -1620,26 +1621,50 @@ void wb_tbe_enc_ivas_fx( curr_pow = 0; move32(); + Q_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_pow, 3 ) ) + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i], 3 ); + move16(); + } + Q_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); + move16(); + } + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shaped_wb_excitation[i]; + move16(); + } + Q_pow = shl_r( Q_bwe_exc_ext, 1 ); + move16(); + } IF( st_fx->element_mode > EVS_MONO ) { - tmp = sub( shl( Q_bwe_exc_ext, 1 ), 31 + 16 ); + tmp = sub( Q_pow, 31 + 16 ); #ifdef BASOP_NOGLOB - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(Q_bwe_exc_ext))*/ + curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_pow)*/ #else curr_pow = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc_ext) */ #endif } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_pow) */ } IF( GT_16( voice_factors[0], 24576 ) ) { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + Lscale = root_a_over_b_fx( curr_pow, Q_pow, prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) {