From e1b2b4fbc510bf71ce02aa9f5d309fc4449071f6 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 3 Feb 2026 08:29:09 -0500 Subject: [PATCH 1/3] cleanup in pitch_ol --- lib_com/options.h | 1 + lib_enc/pitch_ol_fx.c | 347 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 342 insertions(+), 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0ea316a82..7b7766a8d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -109,6 +109,7 @@ #define FIX_2391_INIT_HQ_GENERIC_OFFSET /* FhG/Eri: basop issue 2391: make sure hq_generic_offset is initialized inside hq_hr_dec_fx() */ #define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ +#define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index ab58b31bf..789da2bbd 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -57,8 +57,10 @@ static Word16 pitch_coherence_fx( Word16 pitch0, Word16 pitch1, Word16 fac_max, static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); - -/*-----------------------------------------------------------------* +#ifdef FIX_2403_COMBINE_PITCH_OL +static void pitch_ol_resolve_fx( Word16 pitch[3], Word16 voicing[3], Word16 *old_pitch, Word16 *old_corr, Word16 *old_thres, Word16 *delta_pit, const Word16 element_mode, const Word16 corr_shift, const Word16 relE, const Word16 Opt_SC_VBR, Word16 pitchX[NHFR][2 * NSECT], Word16 corX[NHFR][2 * NSECT], Word16 scaledX[NHFR][2 * NSECT], const Word16 sect0, const Word16 *pit_max, const Word16 pit_min_coding ); +#endif + /*-----------------------------------------------------------------* * pitch_ol_init() * * Open loop pitch variable initialization @@ -79,7 +81,303 @@ void pitch_ol_init_fx( *old_corr = 0; move16(); } +#ifdef FIX_2403_COMBINE_PITCH_OL +static void pitch_ol_resolve_fx( + Word16 pitch[3], /* o : open loop pitch lag for each half-frame Q0 */ + Word16 voicing[3], /* o : maximum normalized correlation for each half-frame Q15 */ + Word16 *old_pitch, /* i/o: pitch of the 2nd half-frame of previous frame Q0 */ + Word16 *old_corr, /* i/o: correlation of old_pitch Q15 */ + Word16 *old_thres, /* i/o: maximum correlation weighting with respect to past Q15 or Q14) */ + Word16 *delta_pit, /* i/o: old pitch extrapolation correction Q0 */ + const Word16 element_mode, /* i : if element_mode != EVS old_thres is in Q14 */ + const Word16 corr_shift, /* i : normalized correlation correction Q15 */ + const Word16 relE, /* i : relative frame energy Q8 */ + const Word16 Opt_SC_VBR, /* i : SC-VBR flag */ + Word16 pitchX[NHFR][2 * NSECT], /* i : pitch candidates Q0 */ + Word16 corX[NHFR][2 * NSECT], /* i : correlation candidates Q15 */ + Word16 scaledX[NHFR][2 * NSECT], /* i/o: scaled correlation candidates Q12 */ + const Word16 sect0, /* i : section offset */ + const Word16 *pit_max, /* i : maximum pitch delays (array) */ + const Word16 pit_min_coding /* i : minimum pitch delay for coding */ +) +{ + Word16 i, ind, ind1, ind_corX, ind1_corX; + Word16 fac, ftmp, k, tmp16, diff, cnt; + Word16 add_sect0, sub_sect0; + Word16 coh_flag, coh_flag1; + Word16 cor_mean; + Word32 Ltmp; + + Word16 pitch_tmp[2 * NHFR]; + Word16 ind_tmp[2 * NHFR]; + Word16 cor_tmp[2 * NHFR]; + Word16 thres1[2 * NHFR]; + Word16 tmp_buf[NHFR + 1]; + /*-----------------------------------------------------------------* + * Favor a smaller delay if it happens that it has its multiple + * in the longer-delay sections (harmonics check) + *-----------------------------------------------------------------*/ + + FOR( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */ + { + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + } + + fac = THRES0; + move16(); /* the look-ahead */ + find_mult_fx( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + } + fac = THRES0; + move16(); + find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ + find_mult_fx( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ + test(); + IF( ( sect0 == 0 ) && GE_16( shl( pitchX[i][NSECT + 0], 1 ), pit_min_coding ) ) + { + find_mult_fx( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ /* Multiples in 2nd section */ + } + + /*-----------------------------------------------------------------* + * Do 1st estimate for pitch values + * Adjust the normalized correlation using estimated noise level + * Compute the maximum scaling for the neighbour correlation + * reinforcement + *-----------------------------------------------------------------*/ + add_sect0 = add( NSECT, sect0 ); + sub_sect0 = sub( NSECT, sect0 ); + FOR( i = 0; i < NHFR; i++ ) + { + /* 1st set of pitch candidates */ + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_tmp[i] = ind; + move16(); + pitch_tmp[i] = pitchX[i][ind]; + move16(); + cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); + move16(); + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i] = mult( THRES1, cor_tmp[i] ); + move16(); + + /* 2nd set of pitch candidates */ + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind_tmp[i + NHFR] = ind1; + move16(); + pitch_tmp[i + NHFR] = pitchX[i][ind1]; + move16(); + cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); + move16(); + + /* Higher is the neighbour's correlation, higher is the weighting */ + /* operands are Q15, result is Q15 */ + thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); + move16(); + } + /*-----------------------------------------------------------------* + * Take into account previous and next pitch values of the present + * frame and look-ahead. Choose the pitch lags and normalize + * correlations for each half-frame & look-ahead + *-----------------------------------------------------------------*/ + + pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); + FOR( i = 0; i < NHFR; i++ ) + { + ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + ind_corX = add( maximum_fx( corX[i] + sect0, sub_sect0, &ftmp ), sect0 ); + + ind1 = add( maximum_fx( scaledX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + ind1_corX = add( maximum_fx( corX[i] + add_sect0, sub_sect0, &ftmp ), add_sect0 ); + + if ( GT_16( scaledX[i][ind1], scaledX[i][ind] ) ) + { + ind = ind1; + move16(); + } + test(); + if ( Opt_SC_VBR && GT_16( corX[i][ind1_corX], corX[i][ind_corX] ) ) + { + ind_corX = ind1_corX; + move16(); + } + test(); + test(); + test(); + IF( Opt_SC_VBR && ( LT_16( mult( pitchX[i][ind], 13107 /*0.4 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GT_16( mult( pitchX[i][ind], 19661 /*0.6 in Q15*/ ), pitchX[i][ind_corX] ) ) && + ( GE_16( corX[i][ind_corX], 29491 /*0.9 in Q15*/ ) ) ) + { + pitch[i] = pitchX[i][ind_corX]; + move16(); + voicing[i] = corX[i][ind_corX]; + move16(); + } + ELSE + { + pitch[i] = pitchX[i][ind]; + move16(); + voicing[i] = corX[i][ind]; + move16(); + } + } + + /*-----------------------------------------------------------------* + * Increase the threshold for correlation reinforcement with + * the past if correlation high and pitch stable + *-----------------------------------------------------------------*/ + + /* all Q15 here */ + /* cor_mean = 0.5f * (voicing[0] + voicing[1]) + corr_shift; */ + Ltmp = L_mult( voicing[0], 16384 /*.5 Q15*/ ); + Ltmp = L_mac( Ltmp, voicing[1], 16384 /*.5 Q15*/ ); + cor_mean = round_fx( L_add( Ltmp, corr_shift ) ); + + /* pitch unstable in present frame or from previous frame or normalized correlation too low */ + coh_flag = pitch_coherence_fx( pitch[0], pitch[1], COH_FAC, DELTA_COH ); + move16(); + coh_flag1 = pitch_coherence_fx( pitch[0], *old_pitch, COH_FAC, DELTA_COH ); + move16(); + + test(); + test(); + test(); + IF( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( LT_16( cor_mean, CORR_TH0 ) ) || ( LT_16( relE, THR_relE ) ) ) + { + /* Reset the threshold */ + *old_thres = 0; + move16(); + } + ELSE + { + /* The threshold increase is directly dependent on normalized correlation */ + /* *old_thres += (0.16f * cor_mean); */ + IF( element_mode != EVS_MONO ) + { + *old_thres = round_fx( L_mac0( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q14 + } + ELSE + { + *old_thres = round_fx( L_mac( L_deposit_h( *old_thres ), 5243 /* 0.16f in Q15 */, cor_mean ) ); // Q15 + } + move16(); + } + IF( element_mode != EVS_MONO ) + { + *old_thres = s_min( *old_thres, 11469 /* 0.7f in Q14 */ ); // Q14 + } + ELSE + { + *old_thres = s_min( *old_thres, THRES3 /* 0.7f in Q14 */ ); // Q15 + } + move16(); + + IF( GT_16( voicing[1], voicing[0] ) ) + { + *old_corr = voicing[1]; + move16(); + } + ELSE + { + *old_corr = cor_mean; + move16(); + } + + /*-----------------------------------------------------------------* + * Extrapolate the pitch value for the next frame by estimating + * the pitch evolution. This value is added to the old_pitch + * in the next frame and is then used when the normalized + * correlation is reinforced by the past estimate + *-----------------------------------------------------------------*/ + tmp_buf[0] = *old_pitch; + move16(); + FOR( i = 0; i < NHFR; i++ ) + { + tmp_buf[i + 1] = pitch[i]; + move16(); + } + + *delta_pit = 0; + move16(); + cnt = 0; + move16(); + + FOR( i = 0; i < NHFR; i++ ) + { + diff = sub( tmp_buf[i + 1], tmp_buf[i] ); + move16(); + coh_flag = pitch_coherence_fx( tmp_buf[i], tmp_buf[i + 1], COH_FAC, DELTA_COH ); + + if ( coh_flag != 0 ) + { + *delta_pit = add( *delta_pit, diff ); + move16(); + } + cnt = add( cnt, coh_flag ); + } + if ( EQ_16( cnt, 2 ) ) + { + /* *delta_pit /= 2; */ + *delta_pit = shr( *delta_pit, 1 ); + move16(); + } + IF( EQ_16( cnt, 3 ) ) + { + k = *delta_pit; + move16(); + /* *delta_pit /= 3; */ + if ( k < 0 ) + { + *delta_pit = mult( *delta_pit, -32768 /*-1 Q15*/ ); + move16(); + } + tmp16 = mult( *delta_pit, 10923 /*1/3 Q15*/ ); + if ( k < 0 ) + { + tmp16 = mult( tmp16, -32768 /*-1 Q15*/ ); + } + *delta_pit = tmp16; + move16(); + } + + /*--------------------------------------------------------------* + * Update old pitch, upsample pitch, + *--------------------------------------------------------------*/ + + *old_pitch = pitch[1]; + move16(); + + FOR( i = 0; i < NHFR; i++ ) + { + /* compensate decimation */ + pitch[i] = i_mult2( pitch[i], OPL_DECIM ); + move16(); + } +} +#endif /*==================================================================================*/ /* FUNCTION : pitch_ol_fx() */ @@ -166,12 +464,18 @@ void pitch_ol_fx( Word16 *pt_exp1, *pt_exp2, *pt_exp3, *pt_exp4; Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4, *pt_cor5, *pt_cor6; +#ifndef FIX_2403_COMBINE_PITCH_OL Word16 thres1[6]; Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; Word16 ind_corX, ind1_corX; Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, add_sect0, sub_sect0, old_tmp, old_tmp1, len_x, len_x1; +#else + Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; + Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; +#endif Word16 len_temp; +#ifndef FIX_2403_COMBINE_PITCH_OL Word16 pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1]; Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; @@ -179,6 +483,14 @@ void pitch_ol_fx( Word16 fac, tmp16, tmp16_2; Word16 qCorX, qScaledX; Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; +#else + Word16 pitchX[NHFR][2 * NSECT]; + Word16 enr0[NSECT], enr0_exp[NSECT], enr0_1[NSECT], enr0_1_exp[NSECT], enr1, enr1_exp, enr2_exp; + Word32 enr, enr2, Ltmp; + Word16 tmp16, tmp16_2; + Word16 qCorX, qScaledX; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; +#endif const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; @@ -801,7 +1113,9 @@ void pitch_ol_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ - +#ifdef FIX_2403_COMBINE_PITCH_OL + pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); +#else /*-----------------------------------------------------------------* * Favor a smaller delay if it happens that it has its multiple * in the longer-delay sections (harmonics check) @@ -1050,7 +1364,7 @@ void pitch_ol_fx( pitch[i] = i_mult2( pitch[i], OPL_DECIM ); move16(); } - +#endif return; } @@ -1072,7 +1386,11 @@ void pitch_ol_ivas_fx( Word16 qwsp /* i : Q factor for wsp Q0 */ ) { +#ifndef FIX_2403_COMBINE_PITCH_OL Word16 ftmp, old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; +#else + Word16 old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2; +#endif Word16 tmp_mem[3]; Word16 scale1[2 * DELTA_COH - 1]; @@ -1082,6 +1400,7 @@ void pitch_ol_ivas_fx( Word16 *pt1, *pt2, *pt3, *pt4, *pt5, *pt6; Word16 *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4; Word16 *pt_cor0_exp, *pt_cor1_exp, *pt_cor2_exp, *pt_cor3_exp, *pt_cor4_exp; +#ifndef FIX_2403_COMBINE_PITCH_OL Word16 thres1[6]; Word16 diff, cnt, ind, ind1, offset, offset1, offset_la, offset_la1, coh_flag, coh_flag1; Word16 ind_corX, ind1_corX; @@ -1096,6 +1415,20 @@ void pitch_ol_ivas_fx( Word32 Ltmp; Word16 fac, tmp16, tmp16_2; Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean; +#else + Word16 cnt, ind, ind1, offset, offset1, offset_la, offset_la1; + Word16 i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1; + Word16 len_temp; + Word16 pitchX[NHFR][2 * NSECT]; + + Word16 enr0_exp[NSECT], enr0_1_exp[NSECT], enr1_exp; + Word32 enr0[NSECT], enr0_1[NSECT], enr1; + Word64 temp, temp1; + Word32 Ltmp; + Word16 tmp16, tmp16_2; + Word16 scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT]; +#endif + const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; @@ -1757,7 +2090,9 @@ void pitch_ol_ivas_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ - +#ifdef FIX_2403_COMBINE_PITCH_OL + pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ +#else /*-----------------------------------------------------------------* * Favor a smaller delay if it happens that it has its multiple * in the longer-delay sections (harmonics check) @@ -2007,7 +2342,7 @@ void pitch_ol_ivas_fx( pitch[i] = i_mult2( pitch[i], OPL_DECIM ); move16(); } - +#endif return; } -- GitLab From aaf24683d04d9a0346dd5ebe23686ffa907d0d2c Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 3 Feb 2026 08:33:26 -0500 Subject: [PATCH 2/3] fix clang format --- lib_enc/pitch_ol_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 789da2bbd..973a2fcb2 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -60,7 +60,7 @@ static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word1 #ifdef FIX_2403_COMBINE_PITCH_OL static void pitch_ol_resolve_fx( Word16 pitch[3], Word16 voicing[3], Word16 *old_pitch, Word16 *old_corr, Word16 *old_thres, Word16 *delta_pit, const Word16 element_mode, const Word16 corr_shift, const Word16 relE, const Word16 Opt_SC_VBR, Word16 pitchX[NHFR][2 * NSECT], Word16 corX[NHFR][2 * NSECT], Word16 scaledX[NHFR][2 * NSECT], const Word16 sect0, const Word16 *pit_max, const Word16 pit_min_coding ); #endif - /*-----------------------------------------------------------------* +/*-----------------------------------------------------------------* * pitch_ol_init() * * Open loop pitch variable initialization -- GitLab From aff4167321776d3ee6239940620ca8eeca40c783 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 3 Feb 2026 16:33:14 +0100 Subject: [PATCH 3/3] editorial improvements --- lib_com/options.h | 2 +- lib_enc/pitch_ol_fx.c | 103 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 21 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7b7766a8d..041b64e24 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -109,7 +109,7 @@ #define FIX_2391_INIT_HQ_GENERIC_OFFSET /* FhG/Eri: basop issue 2391: make sure hq_generic_offset is initialized inside hq_hr_dec_fx() */ #define FIX_2397_COPY_AQ_MDCT_CORE_BFI /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */ #define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ -#define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ +#define FIX_2403_COMBINE_PITCH_OL /* VA : basop 2403, reusing common code between EVS and IVAS in pitch_ol */ /* #################### End BE switches ################################## */ diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 973a2fcb2..b7f79eeea 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -15,6 +15,7 @@ /*-----------------------------------------------------------------* * Local Constants *-----------------------------------------------------------------*/ + #define PIT_MIN2 20 /* pit_min for pitch tracking */ #define PIT_MIN_1 44 /* for second pitch track */ #define PIT_MIN2_1 24 @@ -57,14 +58,18 @@ static Word16 pitch_coherence_fx( Word16 pitch0, Word16 pitch1, Word16 fac_max, static Word32 Dot_product12_OL( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); static Word32 Dot_product12_OL_back( Word16 *sum1, const Word16 x[], const Word16 y[], const Word16 lg, const Word16 lg2, Word16 *exp, Word16 *exp2 ); + #ifdef FIX_2403_COMBINE_PITCH_OL static void pitch_ol_resolve_fx( Word16 pitch[3], Word16 voicing[3], Word16 *old_pitch, Word16 *old_corr, Word16 *old_thres, Word16 *delta_pit, const Word16 element_mode, const Word16 corr_shift, const Word16 relE, const Word16 Opt_SC_VBR, Word16 pitchX[NHFR][2 * NSECT], Word16 corX[NHFR][2 * NSECT], Word16 scaledX[NHFR][2 * NSECT], const Word16 sect0, const Word16 *pit_max, const Word16 pit_min_coding ); #endif + + /*-----------------------------------------------------------------* * pitch_ol_init() * * Open loop pitch variable initialization *-----------------------------------------------------------------*/ + void pitch_ol_init_fx( Word16 *old_thres, /* o : threshold for reinforcement of past pitch influence */ Word16 *old_pitch, /* o : pitch of the 2nd half-frame of previous frame */ @@ -80,8 +85,17 @@ void pitch_ol_init_fx( move16(); *old_corr = 0; move16(); + + return; } + #ifdef FIX_2403_COMBINE_PITCH_OL +/*-----------------------------------------------------------------* + * pitch_ol_resolve_fx() + * + * + *-----------------------------------------------------------------*/ + static void pitch_ol_resolve_fx( Word16 pitch[3], /* o : open loop pitch lag for each half-frame Q0 */ Word16 voicing[3], /* o : maximum normalized correlation for each half-frame Q15 */ @@ -113,6 +127,7 @@ static void pitch_ol_resolve_fx( Word16 cor_tmp[2 * NHFR]; Word16 thres1[2 * NHFR]; Word16 tmp_buf[NHFR + 1]; + /*-----------------------------------------------------------------* * Favor a smaller delay if it happens that it has its multiple * in the longer-delay sections (harmonics check) @@ -149,6 +164,7 @@ static void pitch_ol_resolve_fx( { find_mult_fx( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */ } + fac = THRES0; move16(); find_mult_fx( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2, 2 ); /* Multiples in 3rd section */ @@ -165,6 +181,7 @@ static void pitch_ol_resolve_fx( * Compute the maximum scaling for the neighbour correlation * reinforcement *-----------------------------------------------------------------*/ + add_sect0 = add( NSECT, sect0 ); sub_sect0 = sub( NSECT, sect0 ); FOR( i = 0; i < NHFR; i++ ) @@ -197,13 +214,15 @@ static void pitch_ol_resolve_fx( thres1[i + NHFR] = mult( THRES1, cor_tmp[i + NHFR] ); move16(); } - /*-----------------------------------------------------------------* + /*---- + -------------------------------------------------------------* * Take into account previous and next pitch values of the present * frame and look-ahead. Choose the pitch lags and normalize * correlations for each half-frame & look-ahead *-----------------------------------------------------------------*/ pitch_neighbour_fx( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp ); + FOR( i = 0; i < NHFR; i++ ) { ind = add( maximum_fx( scaledX[i] + sect0, sub_sect0, &ftmp ), sect0 ); @@ -311,6 +330,7 @@ static void pitch_ol_resolve_fx( * in the next frame and is then used when the normalized * correlation is reinforced by the past estimate *-----------------------------------------------------------------*/ + tmp_buf[0] = *old_pitch; move16(); FOR( i = 0; i < NHFR; i++ ) @@ -375,6 +395,8 @@ static void pitch_ol_resolve_fx( pitch[i] = i_mult2( pitch[i], OPL_DECIM ); move16(); } + + return; } #endif @@ -610,6 +632,7 @@ void pitch_ol_fx( /*-----------------------------------------------------------------------------* * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames *-----------------------------------------------------------------------------*/ + old_tmp = add( *old_pitch, *delta_pit ); old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); old_tmp = s_max( old_tmp, pit_min ); @@ -620,6 +643,7 @@ void pitch_ol_fx( /*-----------------------------------------------------------------* * Loop for all three half-frames (current frame + look-ahead) *-----------------------------------------------------------------*/ + pt_cor0 = scaled_buf + DELTA_COH - 1; pt_cor2 = pt_cor0 - pit_min + old_tmp; @@ -690,6 +714,7 @@ void pitch_ol_fx( /*----------------------------------------------------------* * Find correlation for the non-overlapping pitch lag values *----------------------------------------------------------*/ + exp_sect[subsect0] = 0; move16(); pt_cor5 = pt_cor1; @@ -725,6 +750,7 @@ void pitch_ol_fx( /*----------------------------------------------------------* * For each subsection, find the correlation *----------------------------------------------------------*/ + FOR( j = subsect0; j < NSUBSECT; j++ ) { len_temp = sublen[j]; @@ -837,6 +863,7 @@ void pitch_ol_fx( /*-----------------------------------------------------------------* * Find correlation for the non-overlapping pitch lag values *-----------------------------------------------------------------*/ + exp_sect[subsect0] = 0; move16(); pt_cor5 = pt_cor1; @@ -985,6 +1012,7 @@ void pitch_ol_fx( * Scale correlation function in the neighbourhood of * the extrapolated pitch *-----------------------------------------------------------------*/ + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); pt2 = scale1; @@ -1113,6 +1141,7 @@ void pitch_ol_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ + #ifdef FIX_2403_COMBINE_PITCH_OL pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); #else @@ -1365,9 +1394,11 @@ void pitch_ol_fx( move16(); } #endif + return; } + void pitch_ol_ivas_fx( Word16 pitch[3], /* o : open loop pitch lag for each half-frame in range [29,231] Q0 */ Word16 voicing[3], /* o : maximum normalized correlation for each half-frame in [0,1.0[ Q15 */ @@ -1496,6 +1527,7 @@ void pitch_ol_ivas_fx( * Extend the decimation of wsp to the end of the speech buffer * Update wsp memory *--------------------------------------------------------------*/ + Copy( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM ); @@ -1545,6 +1577,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------------------* * Estimate the new pitch by extrapolating the old pitch value for 2 half-frames *-----------------------------------------------------------------------------*/ + old_tmp = add( *old_pitch, *delta_pit ); old_tmp = s_min( old_tmp, PIT_MAX / OPL_DECIM ); old_tmp = s_max( old_tmp, pit_min ); @@ -1555,6 +1588,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------* * Loop for all three half-frames (current frame + look-ahead) *-----------------------------------------------------------------*/ + pt_cor0 = scaled_buf + DELTA_COH - 1; pt_cor0_exp = scaled_buf_exp + DELTA_COH - 1; @@ -1674,6 +1708,7 @@ void pitch_ol_ivas_fx( /*----------------------------------------------------------* * For each subsection, find the correlation *----------------------------------------------------------*/ + FOR( j = subsect0; j < NSUBSECT; j++ ) { len_temp = sublen[j]; @@ -1759,6 +1794,7 @@ void pitch_ol_ivas_fx( /*-----------------------------------------------------------------* * For each section in both sets, find fixed vector energy *-----------------------------------------------------------------*/ + FOR( j = sect0; j < NSECT; j++ ) /* loop for each section */ { /* 1st set */ @@ -1939,6 +1975,7 @@ void pitch_ol_ivas_fx( * Scale correlation function in the neighbourhood of * the extrapolated pitch *-----------------------------------------------------------------*/ + pt_cor1 = pt_cor2 - ( DELTA_COH - 1 ); pt_cor1_exp = pt_cor2_exp - ( DELTA_COH - 1 ); pt_cor3 = pt_cor4 - ( DELTA_COH - 1 ); @@ -2090,6 +2127,7 @@ void pitch_ol_ivas_fx( } /* FOR j < NSECT */ } /* FOR i < NHFR */ + #ifdef FIX_2403_COMBINE_PITCH_OL pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ #else @@ -2353,6 +2391,7 @@ void pitch_ol_ivas_fx( * Verifies whether max pitch delays in higher sections have multiples * in lower sections *-----------------------------------------------------------------*/ + static void find_mult_fx( Word16 *fac, /* i/o: correlation scaling factor Q12 */ Word16 pitch0, /* i : pitch of max correlation in the c section */ @@ -2389,6 +2428,8 @@ static void find_mult_fx( pit_min = add( pit_min, pitch0 ); /* next multiple */ delta = add( delta, step ); /* the incertitude to the allowed range */ } + + return; } /*---------------------------------------------------------------------------* @@ -2397,6 +2438,7 @@ static void find_mult_fx( * Verifies if the maximum correlation pitch lag is coherent with neighbour * values *---------------------------------------------------------------------------*/ + static void pitch_neighbour_fx( Word16 sect0, /* i : indicates whether section 0 (below PIT_MIN) is used */ Word16 pitch_tmp[], /* i : estimated pitch values for each half-frame & look-ahead */ @@ -2510,13 +2552,17 @@ static void pitch_neighbour_fx( } } } + + return; } + /*-----------------------------------------------------------------* * pitch_coherence_fx * * Verify if pitch evolution is smooth *-----------------------------------------------------------------*/ + static Word16 pitch_coherence_fx( Word16 pitch0, /* i : first pitch to compare */ Word16 pitch1, /* i : 2nd pitch to compare */ @@ -2543,11 +2589,13 @@ static Word16 pitch_coherence_fx( return pc; } + /*-----------------------------------------------------------------* * LP_Decim2_Copy: * * Decimate a vector by 2 with 2nd order fir filter. *-----------------------------------------------------------------*/ + static void LP_Decim2_Copy( const Word16 x[], /* i: signal to process */ Word16 y[], /* o: signal to process */ @@ -2597,20 +2645,26 @@ static void LP_Decim2_Copy( y[j++] = round_fx( L_tmp ); move16(); } + + return; } + + /*---------------------------------------------------------------------* * Dot_product12_OL * * two different length dot products of x and y *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL( /* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ + +/* o : Q31: normalized result (1 < val <= -1) */ +static Word32 Dot_product12_OL( + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; @@ -2662,19 +2716,22 @@ static Word32 Dot_product12_OL( /* o : Q31: normalized result return L_sum; } + /*---------------------------------------------------------------------* * Dot_product12_OL_back() * * two different length dot products of x and y, computed backward *---------------------------------------------------------------------*/ -static Word32 Dot_product12_OL_back( /* o : Q31: normalized result (1 < val <= -1) */ - Word16 *sum1, /* o : Q31: normalized result 2 */ - const Word16 x[], /* i : 12bits: x vector */ - const Word16 y[], /* i : 12bits: y vector */ - const Word16 lg, /* i : vector length */ - const Word16 lg2, /* i : vector length 2 */ - Word16 *exp, /* o : exponent of result (0..+30) */ - Word16 *exp2 /* o : exponent of result 2 (0..+30) */ + +/* o : Q31: normalized result (1 < val <= -1) */ +static Word32 Dot_product12_OL_back( + Word16 *sum1, /* o : Q31: normalized result 2 */ + const Word16 x[], /* i : 12bits: x vector */ + const Word16 y[], /* i : 12bits: y vector */ + const Word16 lg, /* i : vector length */ + const Word16 lg2, /* i : vector length 2 */ + Word16 *exp, /* o : exponent of result (0..+30) */ + Word16 *exp2 /* o : exponent of result 2 (0..+30) */ ) { Word16 i, sft; @@ -2726,6 +2783,13 @@ static Word32 Dot_product12_OL_back( /* o : Q31: normalized r return L_sum; } + +/*---------------------------------------------------------------------* + * pitchDoubling_det_fx() + * + * + *---------------------------------------------------------------------*/ + void pitchDoubling_det_fx( Word16 *wspeech, Word16 *pitch_ol, @@ -2737,7 +2801,6 @@ void pitchDoubling_det_fx( Word16 new_Top[2]; Word16 m, T; - /*save initial values*/ new_Top[0] = pitch_ol[0]; @@ -2747,7 +2810,6 @@ void pitchDoubling_det_fx( FOR( m = 2; m < 5; m++ ) { - /* T= pitch_ol[0]/m; */ T = mult( pitch_ol[0], One_div_fx[m - 1] ); @@ -2800,4 +2862,5 @@ void pitchDoubling_det_fx( pitch_ol[1] = new_Top[1]; move16(); -} /*end of pitch doubling detection*/ + return; +} -- GitLab