diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index 3a3acced08ee10dc5f78cd64ea45069673b28f17..43e7af2af14af672f137859d9dd72b04aace709b 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -239,7 +239,6 @@ - @@ -273,13 +272,7 @@ - - - - - - diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index d88992f20e8474180b3fffc31306a54fdbec3a8c..abc2ccec7162cae15eb0dd94fbadef0a8deabae2 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -52,15 +52,9 @@ enc_evs_c - - enc_evs_c - enc_evs_c - - enc_evs_c - enc_evs_c @@ -103,9 +97,6 @@ enc_evs_c - - enc_all_c - enc_all_c @@ -169,9 +160,6 @@ enc_all_c - - enc_all_c - enc_all_c diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 480f7e5d630c1e797e4645287a6bdf0abbffa316..5a3d2e1a27b1fd60aba746579f8bc5cee346fe1e 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -437,11 +437,11 @@ void cldfbAnalysis_ts_fx( i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q - i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q - i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 @@ -569,6 +569,278 @@ void cldfbAnalysis_ts_fx( return; } +void cldfbAnalysis_ts_fx_var_q( + const Word32 *timeIn_fx, + /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : real value buffer */ // q_cldfb - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : imag value buffer */ // q_cldfb - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16 *q_cldfb ) + +{ + Word16 i, k; + Word16 L2, M1, M2, M4; + Word16 no_col = h_cldfb->no_col; + move16(); + Word32 r1_fx, r2_fx, rr12_fx, ir12_fx; + Word32 i1_fx, i2_fx, ri12_fx, ii12_fx; + Word32 rBuffer_fx[2 * CLDFB_NO_CHANNELS_MAX]; + Word32 iBuffer_fx[2 * CLDFB_NO_CHANNELS_MAX]; + const Word32 *rot_vctr_re_fx; + const Word32 *rot_vctr_im_fx; + const Word32 *rot_vctr_delay_re_fx; + const Word32 *rot_vctr_delay_im_fx; + const Word16 *ptr_pf_fx; + Word16 ptr_pf_sf; + Word32 *timeBuffer_fx, buffer_fx[( CLDFB_NO_CHANNELS_MAX * CLDFB_NO_COL_MAX ) + ( 9 * CLDFB_NO_CHANNELS_MAX )]; + Word16 offset, frameSize; + + offset = sub( h_cldfb->p_filter_length, h_cldfb->no_channels ); + frameSize = i_mult( h_cldfb->no_channels, h_cldfb->no_col ); + + /* prepare input buffer */ + timeBuffer_fx = buffer_fx; + Copy32( h_cldfb->cldfb_state_fx, timeBuffer_fx, offset ); + + IF( GT_16( samplesToProcess, -1 ) ) + { + Copy32( timeIn_fx, timeBuffer_fx + offset, samplesToProcess ); + set32_fx( timeBuffer_fx + add( offset, samplesToProcess ), 0, sub( frameSize, samplesToProcess ) ); + } + ELSE + { + Copy32( timeIn_fx, timeBuffer_fx + offset, frameSize ); + } + + IF( NE_16( h_cldfb->Q_cldfb_state, *q_cldfb ) ) + { + Word16 norm_st = L_norm_arr( timeBuffer_fx, offset ); + IF( GE_16( norm_st, sub( *q_cldfb, h_cldfb->Q_cldfb_state ) ) ) + { + scale_sig32( timeBuffer_fx, offset, sub( *q_cldfb, h_cldfb->Q_cldfb_state ) ); + /* cldfb_state will get updated at end of processing with values whose q is same as + * *q_cldfb. + */ + h_cldfb->Q_cldfb_state = *q_cldfb; + move16(); + } + ELSE + { + scale_sig32( &timeBuffer_fx[offset], frameSize, sub( h_cldfb->Q_cldfb_state, *q_cldfb ) ); + *q_cldfb = h_cldfb->Q_cldfb_state; + move16(); + } + } + + /* only process needed cols */ + IF( GT_16( samplesToProcess, -1 ) ) + { + no_col = s_min( no_col, idiv1616( sub( add( samplesToProcess, h_cldfb->no_channels ), 1 ), h_cldfb->no_channels ) ); + assert( no_col == 1 ); + } + + M1 = h_cldfb->no_channels; + M2 = shr( M1, 1 ); + M4 = shr( M1, 2 ); + L2 = shl( M1, 1 ); + move16(); + + if ( s_and( M2, 1 ) ) + { + M4 = add( M4, 1 ); + } + + rot_vctr_re_fx = h_cldfb->rot_vec_ana_re_fx; // q = 29 + rot_vctr_im_fx = h_cldfb->rot_vec_ana_im_fx; // q = 29 + rot_vctr_delay_re_fx = h_cldfb->rot_vec_ana_delay_re_fx; // q = 31 + rot_vctr_delay_im_fx = h_cldfb->rot_vec_ana_delay_im_fx; // q = 31 + + ptr_pf_fx = h_cldfb->p_filter; + ptr_pf_sf = h_cldfb->p_filter_sf; // Q14 + move16(); + + FOR( i = 0; i < no_col; i++ ) + { + FOR( k = 0; k < M4; k++ ) + { + /* prototype filter */ + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 + + /* folding + pre modulation of DST IV */ + rr12_fx = L_sub( r1_fx, r2_fx ); // q -1 + ri12_fx = L_negate( L_add( i1_fx, i2_fx ) ); // q - 1 + /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); + + ///* folding + pre modulation of DCT IV */ + ir12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_sub( i1_fx, i2_fx ); // q - 1 + /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); + } + + FOR( k = M4; k < M2; k++ ) + { + /* prototype filter */ + r1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + r1_fx = Msub_32_16( r1_fx, timeBuffer_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + r2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + r2_fx = Msub_32_16( r2_fx, timeBuffer_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 5 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + i1_fx = Msub_32_16( 0, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 0 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 1 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 2 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 3 * L2 )] ); // q + i1_fx = Msub_32_16( i1_fx, timeBuffer_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 + M2 - 1 - ( 2 * k ) + 4 * L2 )] ); // q + + i2_fx = Msub_32_16( 0, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 0 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 1 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 2 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 3 * L2 )] ); // q + i2_fx = Msub_32_16( i2_fx, timeBuffer_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )], ptr_pf_fx[( L2 - 3 * M2 + ( 2 * k ) + 4 * L2 )] ); // q + + r1_fx = Mpy_32_16_1( r1_fx, ptr_pf_sf ); // q - 1 + r2_fx = Mpy_32_16_1( r2_fx, ptr_pf_sf ); // q - 1 + i1_fx = Mpy_32_16_1( i1_fx, ptr_pf_sf ); // q - 1 + i2_fx = Mpy_32_16_1( i2_fx, ptr_pf_sf ); // q - 1 + + /* folding + pre modulation of DST IV */ + rr12_fx = L_add( r1_fx, r2_fx ); // q - 1 + ri12_fx = L_sub( i1_fx, i2_fx ); // q - 1 + /*cplxMult(&rBuffer[2*k],&rBuffer[2*k+1],rr12,ri12,rot_vctr_re[k],rot_vctr_im[k]);*/ + rBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( rr12_fx, rot_vctr_re_fx[k] ), ri12_fx, rot_vctr_im_fx[k] ); // q - 3 + rBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( rr12_fx, rot_vctr_im_fx[k] ), ri12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); + + /* folding + pre modulation of DCT IV */ + ir12_fx = L_sub( r1_fx, r2_fx ); // q - 1 + ii12_fx = L_add( i1_fx, i2_fx ); // q - 1 + /*cplxMult(&iBuffer[2*k],&iBuffer[2*k+1],ir12,ii12,rot_vctr_re[k],rot_vctr_im[k]);*/ + iBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( ir12_fx, rot_vctr_re_fx[k] ), ii12_fx, rot_vctr_im_fx[k] ); // q - 3 + iBuffer_fx[2 * k + 1] = Madd_32_32( Mpy_32_32( ir12_fx, rot_vctr_im_fx[k] ), ii12_fx, rot_vctr_re_fx[k] ); // q - 3 + move32(); + move32(); + } + + *q_cldfb = sub( *q_cldfb, 3 ); + move16(); + + /* FFT of DST IV */ + fft_cldfb_fx( rBuffer_fx, M2 ); + + /* post modulation of DST IV */ + FOR( k = 0; k < M2; k++ ) + { + /*cplxMult(&realBuffer[M1-1-(2*k)],&realBuffer[2*k],rBuffer[2*k],rBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ + realBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Msub_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_re_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + realBuffer_fx[2 * k] = Madd_32_32( Mpy_32_32( rBuffer_fx[2 * k], rot_vctr_im_fx[k] ), rBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 + move32(); + move32(); + } + *q_cldfb = sub( *q_cldfb, 2 ); + move16(); + + /* FFT of DCT IV */ + fft_cldfb_fx( iBuffer_fx, M2 ); + + /* post modulation of DCT IV */ + FOR( k = 0; k < M2; k++ ) + { + /* do it inplace */ + /*cplxMult(&imagBuffer[2*k],&imagBuffer[M1-1-(2*k)],iBuffer[2*k],iBuffer[2*k+1],rot_vctr_re[k],rot_vctr_im[k]);*/ + imagBuffer_fx[2 * k] = Msub_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_re_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_im_fx[k] ); // q - 5 + imagBuffer_fx[( M1 - 1 ) - ( k * 2 )] = Madd_32_32( Mpy_32_32( iBuffer_fx[2 * k], rot_vctr_im_fx[k] ), iBuffer_fx[2 * k + 1], rot_vctr_re_fx[k] ); // q - 5 + move32(); + move32(); + } + + IF( EQ_32( h_cldfb->prototype, CLDFB_PROTOTYPE_5_00MS ) ) + { + /* rotation due to delay*/ + /*if(h_cldfb->da != M1)*/ + IF( rot_vctr_delay_re_fx != NULL ) + { + FOR( k = 0; k < M1; k++ ) + { + Word32 cplx_aux_fx; + /* delay */ + /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[i][k], imagBuffer[i][k], cos((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)), + sin((EVS_PI/M1)*(k+0.5)*((h_cldfb->da-M1)*0.5)));*/ + /*cplxMult(&rBuffer[k], &iBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ + /*cplxMult(&realBuffer[k], &imagBuffer[k], realBuffer[k], imagBuffer[k], rot_vctr_delay_re[k], rot_vctr_delay_im[k]);*/ + /*realBuffer[k] = rBuffer[k]; + imagBuffer[k] = iBuffer[k];*/ + cplx_aux_fx = Msub_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_re_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_im_fx[k] ); // q - 5 + imagBuffer_fx[k] = Madd_32_32( Mpy_32_32( realBuffer_fx[k], rot_vctr_delay_im_fx[k] ), imagBuffer_fx[k], rot_vctr_delay_re_fx[k] ); // q - 5 + realBuffer_fx[k] = cplx_aux_fx; + move32(); + move32(); + } + } + } + + timeBuffer_fx += i_mult( L2, 5 ); + timeBuffer_fx += sub( h_cldfb->no_channels, h_cldfb->p_filter_length ); + } + + /* update memory */ + IF( GT_16( samplesToProcess, -1 ) ) + { + Copy32( buffer_fx + samplesToProcess, h_cldfb->cldfb_state_fx, offset ); + } + ELSE + { + Copy32( buffer_fx + frameSize, h_cldfb->cldfb_state_fx, offset ); + } + + return; +} + + void cldfbAnalysis_ts_fx_fixed_q( const Word32 *timeIn_fx, /* i : time buffer */ // q diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index cee2bbaad8941a715a932bf864c0c4ab3cb4fc72..be9ea3a80f5e10808c5b3cc89bc1b051314aab2e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -402,37 +402,37 @@ void ivas_initialize_handles_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -ivas_error ivas_core_enc( +ivas_error ivas_core_enc_fx( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const int16_t n_CoreChannels, /* i : number of core channels to be coded */ - Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ - Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ + const Word16 n_CoreChannels, /* i : number of core channels to be coded Q0*/ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal Q_new-1*/ Word16 Q_new[], - Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6*/ - Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes*/ - Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q */ - Word16 epsP_fx_q[], /* i : LP prediction errors */ - Word16 lsp_new[][M], /* i : LSPs at the end of the frame Q15 */ - Word16 lsp_mid[][M], /* i : LSPs in the middle of the frame Q15 */ - const int16_t vad_hover_flag[], /* i : VAD hanglover flag */ - int16_t attack_flag[], /* i : attack flag (GSC or TC) */ - Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q*/ + Word16 epsP_fx_q[], /* i : LP prediction errors */ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15*/ + const Word16 vad_hover_flag[], /* i : VAD hanglover flag Q0*/ + Word16 attack_flag[], /* i : attack flag (GSC or TC) Q0*/ + Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer q_re_im_buf*/ + Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer q_re_im_buf*/ Word16 *q_re_im_buf, - Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer */ + Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer e_old_wsp*/ Word16 e_old_wsp[], - const int16_t loc_harm[], /* i : harmonicity flag */ - const Word16 cor_map_sum[], /* i : speech/music clasif. parameter Q8 */ - const int16_t vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ - Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - Word16 enerBuffer_fx_exp[], /* o : energy buffer */ - Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer */ - const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ - const int16_t ivas_format, /* i : IVAS format */ - const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 loc_harm[], /* i : harmonicity flag Q0*/ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8*/ + const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 enerBuffer_fx_exp[], /* o : energy buffer */ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag Q0*/ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ ); diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3f06fcf450ee6bf4ee62f1bd2577018c6b7ac16b..7bca00410939f8cf110f6209a55da52efac96156 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9614,6 +9614,17 @@ void cldfbAnalysis_ts_fx( Word16 *q_cldfb ); Word16 floor_log_2( Word32 num ); +void cldfbAnalysis_ts_fx_var_q( + const Word32 *timeIn_fx, + /* i : time buffer */ // q + Word32 realBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : real value buffer */ // q_cldfb - 5 + Word32 imagBuffer_fx[CLDFB_NO_CHANNELS_MAX], + /* o : imag value buffer */ // q_cldfb - 5 + const Word16 samplesToProcess, /* i : samples to process */ + HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ + Word16 *q_cldfb ); + void cldfbAnalysis_ts_fx_fixed_q( const Word32 *timeIn_fx, /* i : time buffer */ // q @@ -10852,19 +10863,24 @@ Word16 IGFSCFEncoderEncode( const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); /*ari_enc.c*/ -Word16 ari_encode_14bits_ext( - Word16 *ptr, - Word16 bp, +Word16 ari_encode_14bits_ext_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ Tastat *s, - Word32 symbol, - const UWord16 *cum_freq ); -Word16 ari_encode_14bits_sign( - Word16 *ptr, - Word16 bp, - Word32 bits, + Word32 symbol, /* Q0 */ + UWord16 const *cum_freq /* Q0 */ +); +Word16 ari_encode_14bits_sign_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word32 bits, /* Q0 */ Tastat *s, - Word16 sign ); -Word16 ari_done_encoding_14bits( Word16 *ptr, Word16 bp, Tastat *s ); + Word16 sign /* Q0 */ +); +Word16 ari_done_encoding_14bits_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Tastat *s ); void pack_bit( const Word16 bit, /* i: bit to be packed */ UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ diff --git a/lib_enc/analy_sp.c b/lib_enc/analy_sp.c deleted file mode 100644 index 0be76e525dda92b012f35a545e02e2cf42a331ce..0000000000000000000000000000000000000000 --- a/lib_enc/analy_sp.c +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "rom_enc.h" -#include "rom_com.h" -#include "prot.h" -#include "wmc_auto.h" -#include -#include "ivas_cnst.h" diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index c07d8ba6d410a1617f5238e0627b1d9b398a6fa8..7244e8300d8040b0a4fc515d92dde5b3cff8f4f3 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -68,44 +68,52 @@ void analy_sp_fx( * find energy per critical frequency band and total energy in dB *-----------------------------------------------------------------*/ - pt_bands = fr_bands; + pt_bands = fr_bands; /* Q_new + QSCALE */ pt_fft = fft_buff; LEtot = L_deposit_l( 0 ); IF( NE_16( element_mode, IVAS_CPE_DFT ) ) { FOR( i_subfr = 0; i_subfr <= 1; i_subfr++ ) { - pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; + pt = speech + 3 * ( L_SUBFR / 2 ) - L_FFT / 2; /* Q_new - preemph_bits */ if ( i_subfr != 0 ) { - pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; + pt = speech + 7 * ( L_SUBFR / 2 ) - L_FFT / 2; /* Q_new - preemph_bits */ } /* Clear 1st value of 1st part, copy 1st value of 2nd part */ fft_temp[0] = 0; move16(); - fft_temp[L_FFT / 2] = pt[L_FFT / 2]; + fft_temp[L_FFT / 2] = pt[L_FFT / 2]; /* Q_new - preemph_bits */ move16(); - Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); - Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); + Max_val = s_max( fft_temp[0], fft_temp[L_FFT / 2] ); /* Q_new - preemph_bits */ + Min_val = s_min( fft_temp[0], fft_temp[L_FFT / 2] ); /* Q_new - preemph_bits */ FOR( i = 1; i < L_FFT / 2; i++ ) { /* 1st windowed part */ - fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); + fft_temp[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); /* Q_new - preemph_bits */ move16(); - if ( fft_temp[i] > 0 ) - Max_val = s_max( Max_val, fft_temp[i] ); - if ( fft_temp[i] < 0 ) - Min_val = s_min( Min_val, fft_temp[i] ); + IF( fft_temp[i] > 0 ) + { + Max_val = s_max( Max_val, fft_temp[i] ); /* Q_new - preemph_bits */ + } + IF( fft_temp[i] < 0 ) + { + Min_val = s_min( Min_val, fft_temp[i] ); /* Q_new - preemph_bits */ + } /* 2nd windowed part */ - fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); + fft_temp[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); /* Q_new - preemph_bits */ move16(); - if ( fft_temp[L_FFT - i] > 0 ) - Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); - if ( fft_temp[L_FFT - i] < 0 ) - Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); + IF( fft_temp[L_FFT - i] > 0 ) + { + Max_val = s_max( Max_val, fft_temp[L_FFT - i] ); /* Q_new - preemph_bits */ + } + IF( fft_temp[L_FFT - i] < 0 ) + { + Min_val = s_min( Min_val, fft_temp[L_FFT - i] ); /* Q_new - preemph_bits */ + } } /* Combine -Min_val and Max_val into one */ @@ -114,7 +122,7 @@ void analy_sp_fx( Scale_fac[i_subfr] = s_min( sub( norm_s( Max_val ), 1 ), 6 ); move16(); Scale_fac2 = shl( Scale_fac[i_subfr], 1 ); - Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); + Scale_sig( fft_temp, L_FRAME_12k8, Scale_fac[i_subfr] ); /* Q_new - preemph_bits + Scale_fac */ r_fft_fx_lc( FFT_W128, SIZE_256, SIZE2_256, NUM_STAGE_256, fft_temp, pt_fft, 1 ); @@ -152,7 +160,7 @@ void analy_sp_fx( Ltmp = Mpy_32( exp_etot, frac_etot, LG10, 0 ); /*Q8 Averaged the total energy over both half-frames in log10 */ - *Etot = extract_l( L_shr( Ltmp, 14 - 8 ) ); + *Etot = extract_l( L_shr( Ltmp, 14 - 8 ) ); /* Q8 */ Bin_E[L_FFT / 2 - 1] = Bin_E[L_FFT / 2 - 2]; move32(); @@ -186,7 +194,7 @@ void analy_sp_fx( /* -56783L is to substract 0.86643 in Q16 */ /* 28391 is 0.86643 in Q15 */ /* 1774 is (0.86643 in Q15) * 8 / 128 (/128 to go in Q7) */ - EspecdB[i] = mac_r( L_shl( L_msu( L_tmp2, exp, 28391 ), 3 + 7 ), exp_frac, 887 ); + EspecdB[i] = mac_r( L_shl( L_msu( L_tmp2, exp, 28391 ), 3 + 7 ), exp_frac, 887 ); /* Q7 */ move16(); } @@ -199,17 +207,19 @@ void analy_sp_fx( * * find input signal energy for each critical band using the DFT buffers *------------------------------------------------------------------------*/ + + static void find_enr_dft_ivas_fx( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 input_Fs, /* i : input sampling rate */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ Word32 DFT_past_DMX_fx[], /* i :input DFT_Dmx (Q_inp_dmx ) */ Word32 band_fx[], /* o : per band energy (*q_band) */ Word16 *q_band, /* o : Q of per band energy */ Word32 *ptE_fx, /* o : per bin energy for low frequencies (*q_ptE) */ Word16 *q_ptE, /* o : Q of per bin energy for low frequencies */ Word64 *Etot_fx, /* i/o: total energy (Q8) */ - const Word16 min_band, /* i : minimum critical band */ - const Word16 max_band, /* i : maximum critical band */ + const Word16 min_band, /* i : minimum critical band Q0*/ + const Word16 max_band, /* i : maximum critical band Q0*/ Word32 *Bin_E_fx, /* o : Per bin energy (Q7) */ Word16 *q_Bin_E, /* o : Q of Per bin energy (*q_band) */ Word32 *band_ener_fx, /* o : per band energy without E_MIN */ @@ -434,9 +444,9 @@ static void find_enr_dft_ivas_fx( * Spectral analysis of 12.8kHz input *-------------------------------------------------------------------*/ void ivas_analy_sp_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode Q0*/ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const Word32 input_Fs, /* i : input sampling rate */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ Word32 *fr_bands, /* o : energy in critical frequency bands q_fr_bands */ @@ -516,17 +526,17 @@ void ivas_analy_sp_fx( /* Clear 1st value of 1st part, copy 1st value of 2nd part */ pt_fft[0] = 0; move16(); - pt_fft[L_FFT / 2] = pt[L_FFT / 2]; + pt_fft[L_FFT / 2] = pt[L_FFT / 2]; // Q_new - preemph_bits move16(); FOR( i = 1; i < L_FFT / 2; i++ ) { /* 1st windowed part */ - pt_fft[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); + pt_fft[i] = mult_r( pt[i], sqrt_han_window_fx[i] ); // Q_new - preemph_bits move16(); /* 2nd windowed part */ - pt_fft[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); + pt_fft[L_FFT - i] = mult_r( pt[L_FFT - i], sqrt_han_window_fx[i] ); // Q_new - preemph_bits move16(); } @@ -580,7 +590,7 @@ void ivas_analy_sp_fx( ELSE { exp = sub( getScaleFactor32( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC ), 1 ); - scale_sig32( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC, exp ); + scale_sig32( hCPE->hStereoDft->DFT_fx[0], STEREO_DFT_N_MAX_ENC, exp ); /* exp(hCPE->hStereoDft->DFT_fx_e[0] - exp) */ hCPE->hStereoDft->DFT_fx_e[0] = sub( hCPE->hStereoDft->DFT_fx_e[0], exp ); move16(); find_enr_dft_ivas_fx( hCPE, input_Fs, hCPE->hStereoDft->DFT_fx[0], pt_bands, q_fr_bands, lf_E, q_lf_E, &LEtot, min_band, max_band, Bin_E, q_Bin_E, band_energies, sub( Q31, hCPE->hStereoDft->DFT_fx_e[0] ) ); @@ -608,12 +618,12 @@ void ivas_analy_sp_fx( move16(); exp = sub( getScaleFactor32( fr_bands, 2 * NB_BANDS ), 1 ); - scale_sig32( fr_bands, 2 * NB_BANDS, exp ); + scale_sig32( fr_bands, 2 * NB_BANDS, exp ); /* q_fr_bands + exp */ *q_fr_bands = add( *q_fr_bands, exp ); move16(); exp = sub( getScaleFactor32( band_energies, 2 * NB_BANDS ), 1 ); - scale_sig32( band_energies, 2 * NB_BANDS, exp ); + scale_sig32( band_energies, 2 * NB_BANDS, exp ); /* q_band_energies + exp */ *q_band_energies = add( *q_band_energies, exp ); move16(); @@ -637,7 +647,7 @@ void ivas_analy_sp_fx( move32(); /* Bin_E[i] = (float) ( 10.0f * log( PS[i] ) ); */ - if ( EspecdB != NULL ) + IF( EspecdB != NULL ) { EspecdB[i] = -14736; /* ln(1e-5) in Q7 */ move16(); @@ -646,7 +656,7 @@ void ivas_analy_sp_fx( Bin_E[i] = -482887093; /* ln(1e-5) in Q22 */ move32(); - IF( PS[i] != 0 ) + IF( GT_32( PS[i], L_shl_sat( 21475, sub( *q_Bin_E, Q31 ) ) ) /*1e - 5 in *q_bin_E */ ) { Ltmp = L_add( BASOP_Util_Log2( PS[i] ), L_shl( sub( Q31, *q_Bin_E ), Q25 ) ); Bin_E[i] = Mpy_32_32( Ltmp, 1860652798 /*10.0*logf(2) in Q28 */ ); // Q22 @@ -688,12 +698,13 @@ void ivas_analy_sp_fx( * find input signal energy for each critical band and first 74 LF bins * The energy is normalized by the number of frequency bins in a channel *------------------------------------------------------------------------*/ + /* Merge with ivas_find_enr function once analy_sp is unified */ static void ivas_find_enr( Word16 data[], /* i : fft result */ Word16 q_data, /* i : Q of fft result */ Word32 band[], /* o : per band energy q_band */ - Word16 *q_band, /* o : Q of per band energy Q0 */ + Word16 *q_band, /* o : Q of per band energy */ Word32 *ptE, /* o : per bin energy for low frequencies q_ptE */ Word16 *q_ptE, /* o : Q of per bin energy for low frequencies Q0 */ Word64 *LEtot, /* o : total energy q_band+1 */ @@ -877,7 +888,7 @@ static void find_enr( const Word16 Q_new2, /* i : scaling factor Q0 */ const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ - Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ + Word16 BIN_FREQ_FX, /* i : Number of frequency bins Q0 */ Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ ) { @@ -892,7 +903,7 @@ static void find_enr( Word32 *tmpptr; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; - move16(); + move32(); #endif @@ -928,7 +939,7 @@ static void find_enr( move16(); FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ { - tmpptr = Bin_E; + tmpptr = Bin_E; /* Q_new + QSCALE - 2 */ move16(); Ltmp1 = L_deposit_l( 0 ); @@ -942,11 +953,11 @@ static void find_enr( /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); -#else /* BASOP_NOGLOB */ + *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); /* Q_new + QSCALE - 2 */ +#else /* BASOP_NOGLOB */ *ptE = L_shl( Ltmp, diff_scaleM2 ); -#endif /* BASOP_NOGLOB */ - move32(); /* scaled by Q_new + QSCALE - 2 */ +#endif /* BASOP_NOGLOB */ + move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; /*band[i] += *ptE++;*/ *Bin_E = *ptE; @@ -965,18 +976,18 @@ static void find_enr( /* band[i] /= cnt */ /* normalization per frequency bin */ cnt = (Word16) ( Bin_E - tmpptr ); shift_to_norm = norm_s( cnt ); - wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); - Ltmp1 = L_deposit_l( wtmp ); + wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); /* Q15 */ + Ltmp1 = L_deposit_l( wtmp ); /* Q15 */ exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); -#else /* BASOP_NOGLOB */ + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); /* Q15 + exp_band */ +#else /* BASOP_NOGLOB */ band[i] = L_shl( Ltmp1, exp_band ); -#endif /* BASOP_NOGLOB */ - move32(); /* band scaled by Q_new + QSCALE */ +#endif /* BASOP_NOGLOB */ + move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); @@ -998,7 +1009,7 @@ static void find_enr( etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); } - band_energies[i] = band[i]; + band_energies[i] = band[i]; /* Q_new + QSCALE */ move32(); band[i] = L_max( band[i], e_min ); @@ -1027,11 +1038,11 @@ static void find_enr( /* normalization - corresponds to FFT normalization by 2/L_FFT */ BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ #ifdef BASOP_NOGLOB - *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); -#else /* BASOP_NOGLOB */ + *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); /* Q_new + QSCALE */ +#else /* BASOP_NOGLOB */ *Bin_E = L_shl( Ltmp, diff_scaleM2 ); -#endif /* BASOP_NOGLOB */ - move32(); /* scaled by Q_new + QSCALE - 2 */ +#endif /* BASOP_NOGLOB */ + move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); @@ -1103,396 +1114,3 @@ static void find_enr( return; } - -#ifdef IVAS_FLOAT_FIXED1 -/*------------------------------------------------------------------------* - * ivas_find_enr() - * - * find input signal energy for each critical band and first 74 LF bins - * The energy is normalized by the number of frequency bins in a channel - *------------------------------------------------------------------------*/ - -static void ivas_find_enr( - Word16 data[], /* i : fft result */ - Word32 band[], /* o : per band energy Q_new + QSCALE */ - Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE */ - const Word16 min_band, /* i : minimum critical band Q0 */ - const Word16 max_band, /* i : maximum critical band Q0 */ - const Word16 Q_new2, /* i : scaling factor Q0 */ - const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ - Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ - Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ - Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ -) -{ - Word16 i, cnt, shift_to_norm; - Word16 freq, wtmp; - Word16 *ptR, *ptI, diff_scaleP1, diff_scaleM2; - Word16 exp_band; - Word32 Ltmp, Ltmp1; - Word16 voic_band; - Word32 etot; - Word16 exp_etot; - Word32 *tmpptr; -#ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; -#endif - - - ptR = &data[1]; /* first real */ - ptI = &data[L_FFT - 1]; /* first imaginary */ - - /*-----------------------------------------------------------------------------------* - * Scaling needed by band and ptE output - * Wants all energies scaled by Q_new + QSCALE to maintain maximum - * precision on bckr noise in clean speech - * First shift left by Q_new + QSCALE than shift right by 2*Q_new-1 - * shift left (Q_new + QSCALE - (2*Q_new -1)) - * shift left (QSCALE - Q_new + 1) == shift left by (QSCALE+1) - Q_new - *-----------------------------------------------------------------------------------*/ - - diff_scaleP1 = sub( QSCALE + 1 + 1, Q_new2 ); - diff_scaleM2 = sub( QSCALE + 1 - 2, Q_new2 ); - - voic_band = VOIC_BAND_8k; - move16(); - assert( VOIC_BAND == VOIC_BAND_8k ); - - etot = L_deposit_l( 0 ); - exp_etot = 0; - move16(); - - /*-----------------------------------------------------------------* - * For low frequency bins, save per bin energy for the use - * in NS and find_tilt() - *-----------------------------------------------------------------*/ - - freq = BIN_FREQ_FX; - move16(); - FOR( i = 0; i < voic_band; i++ ) /* up to maximum allowed voiced critical band */ - { - tmpptr = Bin_E; - move16(); - Ltmp1 = L_deposit_l( 0 ); - - FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) - { - /*ptE = *ptR * *ptR + *ptI * *ptI */ /* energy */ - Ltmp = L_mult( *ptI, *ptI ); - Ltmp = L_mac( Ltmp, *ptR, *ptR ); - - /* *ptE *= 4.0 / (L_FFT*L_FFT) */ - /* normalization - corresponds to FFT normalization by 2/L_FFT */ - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ -#ifdef BASOP_NOGLOB - *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); -#else /* BASOP_NOGLOB */ - *ptE = L_shl( Ltmp, diff_scaleM2 ); -#endif /* BASOP_NOGLOB */ - move32(); /* scaled by Q_new + QSCALE - 2 */ - BASOP_SATURATE_WARNING_ON_EVS; - /*band[i] += *ptE++;*/ - *Bin_E = *ptE; - move32(); - Bin_E++; - Ltmp1 = L_add_sat( Ltmp1, Ltmp ); - - ptE++; - ptR++; - ptI--; - } - - exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ - wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); - - /* band[i] /= cnt */ /* normalization per frequency bin */ - cnt = (Word16) ( Bin_E - tmpptr ); - shift_to_norm = norm_s( cnt ); - wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); - Ltmp1 = L_deposit_l( wtmp ); - - exp_band = sub( exp_band, shift_to_norm ); - exp_band = sub( diff_scaleP1, exp_band ); - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ -#ifdef BASOP_NOGLOB - band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); -#else /* BASOP_NOGLOB */ - band[i] = L_shl( Ltmp1, exp_band ); -#endif /* BASOP_NOGLOB */ - move32(); /* band scaled by Q_new + QSCALE */ - BASOP_SATURATE_WARNING_ON_EVS; - - test(); - IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) - { - IF( LT_32( band[i], e_min ) ) - { - Ltmp1 = L_shl( e_min, 0 ); - exp_band = 0; - move16(); - } - - wtmp = sub( exp_band, exp_etot ); - if ( wtmp > 0 ) - { - etot = L_shr( etot, wtmp ); - } - exp_etot = s_max( exp_etot, exp_band ); - etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); - } - - band_energies[i] = band[i]; - move32(); - - band[i] = L_max( band[i], e_min ); - move32(); - } - - IF( EQ_16( BIN_FREQ_FX, 50 ) ) - { - /*-----------------------------------------------------------------* - * Continue compute the E per critical band for high frequencies - *-----------------------------------------------------------------*/ - - FOR( i = voic_band; i < NB_BANDS; i++ ) - { - tmpptr = Bin_E; - move16(); - Ltmp1 = L_deposit_l( 0 ); - - FOR( ; freq <= crit_bands[i]; freq += BIN_FREQ_FX ) - { - /* *ptE = *ptR * *ptR + *ptI * *ptI */ - Ltmp = L_mult( *ptI, *ptI ); - Ltmp = L_mac_sat( Ltmp, *ptR, *ptR ); - - /* *ptE *= 4.0 / (L_FFT*L_FFT) */ - /* normalization - corresponds to FFT normalization by 2/L_FFT */ - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ -#ifdef BASOP_NOGLOB - *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); -#else /* BASOP_NOGLOB */ - *Bin_E = L_shl( Ltmp, diff_scaleM2 ); -#endif /* BASOP_NOGLOB */ - move32(); /* scaled by Q_new + QSCALE - 2 */ - BASOP_SATURATE_WARNING_ON_EVS; - Bin_E++; - Ltmp1 = L_add_sat( Ltmp1, Ltmp ); - - ptR++; - ptI--; - } - - exp_band = sub( norm_l( Ltmp1 ), 1 ); /* divide by 2 to ensure band < cnt */ - wtmp = round_fx( L_shl( Ltmp1, exp_band ) ); - - /* band[i] /= cnt */ /* normalization per frequency bin */ - cnt = (Word16) ( Bin_E - tmpptr ); - shift_to_norm = norm_s( cnt ); - wtmp = div_s( wtmp, shl( cnt, shift_to_norm ) ); - Ltmp1 = L_deposit_l( wtmp ); - - exp_band = sub( exp_band, shift_to_norm ); - exp_band = sub( diff_scaleP1, exp_band ); - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ -#ifdef BASOP_NOGLOB - band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); -#else /* BASOP_NOGLOB */ - band[i] = L_shl( Ltmp1, exp_band ); -#endif - move32(); /* band scaled by Q_new + QSCALE */ - BASOP_SATURATE_WARNING_ON_EVS; - - test(); - IF( GE_16( i, min_band ) && LE_16( i, max_band ) ) - { - IF( LT_32( band[i], e_min ) ) - { - Ltmp1 = L_shl( e_min, 0 ); - exp_band = 0; - move16(); - } - - wtmp = sub( exp_band, exp_etot ); - if ( wtmp > 0 ) - { - etot = L_shr( etot, wtmp ); - } - exp_etot = s_max( exp_etot, exp_band ); - - etot = L_add( etot, L_shl( Ltmp1, sub( exp_band, exp_etot ) ) ); - } - - band_energies[i] = band[i]; - move32(); - - band[i] = L_max( band[i], e_min ); - move32(); - } - } - - /*-----------------------------------------------------------------* - * Find the total energy over the input bandwidth - *-----------------------------------------------------------------*/ - -#ifdef BASOP_NOGLOB - etot = L_add_sat( *LEtot, L_shl_sat( etot, sub( exp_etot, 4 ) ) ); -#else - etot = L_add( *LEtot, L_shl( etot, sub( exp_etot, 4 ) ) ); -#endif - *LEtot = etot; - move32(); - - - return; -} -#endif -#ifdef IVAS_CODE_CPE -/*------------------------------------------------------------------------* - * find_enr_dft() - * - * find input signal energy for each critical band using the DFT buffers - *------------------------------------------------------------------------*/ - -static void find_enr_dft( - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - const int32_t input_Fs, /* i : input sampling rate */ - float DFT_past_DMX[], - float band[], /* o : per band energy */ - float *ptE, /* o : per bin energy for low frequencies */ - float *Etot, /* i/o: total energy */ - const int16_t min_band, /* i : minimum critical band */ - const int16_t max_band, /* i : maximum critical band */ - float *Bin_E, /* o : Per bin energy */ - float *band_ener /* o : per band energy without E_MIN */ -) -{ - int16_t i, cnt; - float freq, tmp; - const float *ptR, *ptI; - float norm_val; - int16_t bin_cnt = 0; - - float c, s; - /* One window - 40ms*12.8kHz = 512 samples */ - float c_1 = cosf( PI2 / STEREO_DFT_N_12k8_ENC ); - float s_1 = sinf( PI2 / STEREO_DFT_N_12k8_ENC ); - float g_1 = 1.f + 0.68f * 0.68f; - float g_2 = 2 * 0.68f; - float g; - float scaleWin; - - float BinE[STEREO_DFT_N_12k8_ENC / 2]; /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ - float bin_freq = input_Fs / (float) hCPE->hStereoDft->NFFT; /* adaptive frequency bin width */ - - scaleWin = 1 / ( 2 * hCPE->hStereoDft->win_ana_energy ); - scaleWin *= (float) BIN / bin_freq; - norm_val = scaleWin * 4.0f / ( hCPE->hStereoDft->NFFT * hCPE->hStereoDft->NFFT ); - - ptR = &DFT_past_DMX[2]; /* first real */ - ptI = &DFT_past_DMX[3]; /* first imaginary */ - c = c_1; - s = s_1; - - /* for low frequency bins, save per bin energy for the use in find_tilt() */ - freq = bin_freq; - for ( i = 0; i < NB_BANDS - 1; i++ ) /* up to maximum allowed voiced critical band */ - { - band[i] = 0.0f; - cnt = 0; - - /* bins up to crit_band 17 (<= 3700 Hz): - * bin_cnt old (bin_width 50 Hz): 74 (74 * FRAMES_PER_SEC = 3700) - * bin_cnt new (bin_width 40 Hz): 92 (92 * 40 = 3680) - */ - - while ( freq <= crit_bands[i] ) - { - BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; /* energy */ - g = g_1 - g_2 * c; - tmp = c * c_1 - s * s_1; - s = s * c_1 + c * s_1; - c = tmp; - BinE[bin_cnt] *= norm_val * g; /* normalization - corresponds to FFT normalization by 2/L_FFT */ - band[i] += BinE[bin_cnt]; - ptR += 2; - ptI += 2; - - freq += bin_freq; - cnt++; - bin_cnt++; - } - - band[i] *= inv_tbl[cnt]; /* normalization per frequency bin */ - - band_ener[i] = band[i]; /* per band energy without E_MIN */ - - if ( band[i] < E_MIN ) - { - band[i] = E_MIN; - } - } - - /* continue computing the energy per critical band for higher frequencies */ - - /* old version, FFT 256 @ SR12.8 (-> bin_width = 50 Hz): - NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 127 = L_FFT/2-1*/ - - /* new version: DFT (1200/800/400) @ input SR (48/32/16) (-> bin_width = 40 Hz): - * - */ - /* NB_BANDS = 20 (= 6350Hz) = highest band available for SR 12.8 -> bin_cnt = 158 */ - /* NB_BANDS = 21 (= 7700Hz) = highest band available for SR 16 -> bin_cnt = 192 */ - /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 32 -> bin_cnt = 387 */ - /* NB_BANDS = 24 (= 15500Hz) = highest band available for SR 48 -> bin_cnt = 387 */ - - for ( ; i < NB_BANDS; i++ ) - { - band[i] = 0.0f; - cnt = 0; - while ( freq < 6399.0f ) - { - BinE[bin_cnt] = *ptR * *ptR + *ptI * *ptI; - g = g_1 - g_2 * c; - BinE[bin_cnt] *= norm_val * g; - band[i] += BinE[bin_cnt]; - ptR += 2; - ptI += 2; - - freq += bin_freq; - cnt++; - bin_cnt++; - } - - band[i] *= inv_tbl[cnt]; /* normalization per frequency bin */ - - band_ener[i] = band[i]; /* per band energy without E_MIN */ - - if ( band[i] < E_MIN ) - { - band[i] = E_MIN; - } - } - - /* put bin energies from BinE into Bin_E[L_FFT/2-1] (interpolate 40 Hz bin values to fit into 50 Hz bins) */ - /* Last value of Bin_E is handled outside this function*/ - assert( bin_cnt == ( STEREO_DFT_N_12k8_ENC / 2 - 1 ) ); - BinE[STEREO_DFT_N_12k8_ENC / 2 - 1] = BinE[STEREO_DFT_N_12k8_ENC / 2 - 2]; - lerp( BinE, Bin_E, L_FFT / 2, STEREO_DFT_N_12k8_ENC / 2 ); - mvr2r( Bin_E, ptE, VOIC_BINS ); - - - /* find the total log energy */ - tmp = *Etot; - for ( i = min_band; i <= max_band; i++ ) - { - tmp += band[i]; - } - - *Etot = tmp; - - return; -} - -#endif diff --git a/lib_enc/ari_enc.c b/lib_enc/ari_enc.c index 733e3e72a10274c2ce2627330e37b3aa5e46c0cf..cda9d3c8270527bb9da7675dff645599620770bd 100644 --- a/lib_enc/ari_enc.c +++ b/lib_enc/ari_enc.c @@ -80,6 +80,9 @@ void ari_start_encoding_14bits( s->low = 0; s->high = ari_q4new; s->bits_to_follow = 0; + move32(); + move32(); + move32(); return; } @@ -98,18 +101,21 @@ void ari_start_encoding_14bits_ivas_fx( } /*--------------------------------------------------------------- - * ari_done_encoding_14bits() + * ari_done_encoding_14bits_ivas_fx() * * Finish ArCo encoding *-------------------------------------------------------------*/ -Word16 ari_done_encoding_14bits( Word16 *ptr, Word16 bp, Tastat *s ) +Word16 ari_done_encoding_14bits_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Tastat *s ) { Word16 bit; bit = 0; move16(); - if ( GE_32( s->low, ari_q1new ) ) + IF( GE_32( s->low, ari_q1new ) ) { bit = s_xor( bit, 1 ); } @@ -118,17 +124,18 @@ Word16 ari_done_encoding_14bits( Word16 *ptr, Word16 bp, Tastat *s ) /*--------------------------------------------------------------- - * ari_encode_14bits_ext() + * ari_encode_14bits_ext_ivas_fx() * * encode function for extended proba tables: less branches needed for coding * *-------------------------------------------------------------*/ -Word16 ari_encode_14bits_ext( - Word16 *ptr, - Word16 bp, +Word16 ari_encode_14bits_ext_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ Tastat *s, - Word32 symbol, - UWord16 const *cum_freq ) + Word32 symbol, /* Q0 */ + UWord16 const *cum_freq /* Q0 */ +) { Word32 low; Word32 high; @@ -140,7 +147,7 @@ Word16 ari_encode_14bits_ext( high = L_add( s->high, 0 ); low = L_add( s->low, 0 ); - range = L_add( L_sub( high, low ), 1 ); + range = L_add( L_sub( high, low ), 1 ); /* Q0 */ L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ ); Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp ); @@ -148,23 +155,23 @@ Word16 ari_encode_14bits_ext( { Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp ); } - high = L_sub( L_add( low, range ), 1 ); - low = L_add( low, L_temp2 ); + high = L_sub( L_add( low, range ), 1 ); /* Q0 */ + low = L_add( low, L_temp2 ); /* Q0 */ assert( s->bits_to_follow <= MAX_16 ); - bits_to_follow = extract_l( s->bits_to_follow ); + bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */ FOR( i = 0; i < 0x7FFF; i++ ) { IF( LT_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ bits_to_follow = 0; move16(); } ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ bits_to_follow = 0; move16(); low = L_sub( low, ari_q2new ); @@ -177,8 +184,8 @@ Word16 ari_encode_14bits_ext( { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add( bits_to_follow, 1 ); - low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ high = L_sub( high, ari_q1new ); } ELSE @@ -186,15 +193,15 @@ Word16 ari_encode_14bits_ext( BREAK; /* Otherwise exit loop. */ } } - low = L_add( low, low ); - high = L_add( L_add( high, high ), 1 ); /* Scale up code range. */ + low = L_add( low, low ); /* Q0 */ + high = L_add( L_add( high, high ), 1 ); /* Scale up code range. Q0*/ } - s->low = low; + s->low = low; /* Q0 */ move32(); - s->high = high; + s->high = high; /* Q0 */ move32(); - s->bits_to_follow = bits_to_follow; + s->bits_to_follow = bits_to_follow; /* Q0 */ move32(); return bp; @@ -202,39 +209,41 @@ Word16 ari_encode_14bits_ext( /*------------------------------------------------------------------------ - * Function: ari_encode_14bits_range() + * Function: ari_encode_14bits_high_low_fx() * - * Encode an cumulative frequency interval. *-------------------------------------------------------------------------*/ -/*------------------------------------------------------------------------ - * Function: ari_encode_14bits_sign() - * - * Encode a sign with equal probabilities. - *-------------------------------------------------------------------------*/ -static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, Tastat *s, Word32 high, Word32 low ) + +static Word16 ari_encode_14bits_high_low_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + Tastat *s, + Word32 high, /* Q0 */ + Word32 low /* Q0 */ +) { Word16 bits_to_follow, tmp; - bits_to_follow = extract_l( s->bits_to_follow ); + bits_to_follow = extract_l( s->bits_to_follow ); /* Q0 */ move16(); /* while there are more than 16 bits left */ - tmp = sub( 16, bits ); + tmp = sub( 16, bits ); /* Q0 */ WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) { IF( LE_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ bits_to_follow = 0; move16(); } ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ bits_to_follow = 0; move16(); - low = L_sub( low, ari_q2new ); - high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + low = L_sub( low, ari_q2new ); /* Q0 */ + high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/ } ELSE { @@ -243,9 +252,9 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add( bits_to_follow, 1 ); - low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ - high = L_sub( high, ari_q1new ); + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE { @@ -257,35 +266,47 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T high = L_add( high, high ); /* Scale up code range. */ } - s->low = low; + s->low = low; /* Q0 */ move32(); - s->high = L_sub( high, 1 ); + s->high = L_sub( high, 1 ); /* Q0 */ move32(); - s->bits_to_follow = bits_to_follow; + s->bits_to_follow = bits_to_follow; /* Q0 */ move16(); return bp; } -Word16 ari_encode_14bits_sign( Word16 *ptr, Word16 bp, Word32 bits, Tastat *s, Word16 sign ) + +/*------------------------------------------------------------------------ + * Function: ari_encode_14bits_sign_ivas_fx() + * + * Encode a sign with equal probabilities. + *-------------------------------------------------------------------------*/ +Word16 ari_encode_14bits_sign_ivas_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word32 bits, /* Q0 */ + Tastat *s, + Word16 sign /* Q0 */ +) { Word32 low, high, range; Word32 L_tmp; high = L_add( s->high, 1 ); low = L_add( s->low, 0 ); - range = L_sub( high, low ); + range = L_sub( high, low ); /* Q0 */ L_tmp = L_shr( range, 1 ); if ( sign != 0 ) { - high = L_add( low, L_tmp ); + high = L_add( low, L_tmp ); /* Q0 */ } if ( sign == 0 ) { - low = L_add( low, L_tmp ); + low = L_add( low, L_tmp ); /* Q0 */ } - return ari_encode_14bits_high_low( ptr, bp, extract_l( bits ), s, high, low ); + return ari_encode_14bits_high_low_fx( ptr, bp, extract_l( bits ), s, high, low ); } /*------------------------------------------------------------------------ diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 872b6a1f3b6acb78d4db2987de223500ef45b48f..0ef053edd75ef58434abdc6fab944cb0851964de 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -56,19 +56,19 @@ void ari_start_encoding_14bits_fx( TastatEnc *s ) * Returns: new bit-stream position *-------------------------------------------------------------*/ Word16 ari_put_bit_plus_follow( - Word16 ptr[], /* o: bit-stream */ - Word16 bp, /* i: bit-stream position */ - Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' */ - Word16 bit /* i: bit to send */ + Word16 ptr[], /* o: bit-stream Q0*/ + Word16 bp, /* i: bit-stream position Q0*/ + Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' Q0*/ + Word16 bit /* i: bit to send Q0*/ ) { assert( bit == 0 || bit == 1 ); - ptr[bp++] = bit; /* send initially a zero or one */ + ptr[bp++] = bit; /* send initially a zero or one Q0*/ move16(); bit = s_xor( bit, 1 ); /* invert bit to send */ FOR( ; bits_to_follow > 0; bits_to_follow-- ) { - ptr[bp++] = bit; /* send inverted bit */ + ptr[bp++] = bit; /* send inverted bit Q0*/ move16(); } return bp; @@ -84,7 +84,10 @@ Word16 ari_put_bit_plus_follow( * * \return bit consumption * ------------------------------------------------------------ - */ -Word16 ari_done_encoding_14bits_fx( Word16 *ptr, Word16 bp, TastatEnc *s ) +Word16 ari_done_encoding_14bits_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + TastatEnc *s ) { Word16 bit; @@ -113,11 +116,12 @@ Word16 ari_done_encoding_14bits_fx( Word16 *ptr, Word16 bp, TastatEnc *s ) * \return bit consumption * ------------------------------------------------------------ - */ Word16 ari_encode_14bits_ext_fx( - Word16 *ptr, - Word16 bp, + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ TastatEnc *s, - Word32 symbol, - UWord16 const *cum_freq ) + Word32 symbol, /* Q0 */ + UWord16 const *cum_freq /* Q0 */ +) { Word32 low; Word32 high; @@ -129,7 +133,7 @@ Word16 ari_encode_14bits_ext_fx( high = L_add( s->high, 0 ); low = L_add( s->low, 0 ); - range = L_sub( high, low ); + range = L_sub( high, low ); /* Q0 */ L_temp1 = L_shl( range, 15 - stat_bitsnew /*both are constants*/ ); Mpy_32_16_ss( L_temp1, cum_freq[symbol + 1], &L_temp2, &temp ); @@ -137,27 +141,27 @@ Word16 ari_encode_14bits_ext_fx( { Mpy_32_16_ss( L_temp1, cum_freq[symbol], &range, &temp ); } - high = L_add( low, range ); - low = L_add( low, L_temp2 ); + high = L_add( low, range ); /* Q0 */ + low = L_add( low, L_temp2 ); /* Q0 */ - bits_to_follow = s->value; + bits_to_follow = s->value; /* Q0 */ move16(); FOR( i = 0; i < 0x7FFF; i++ ) { IF( LE_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ bits_to_follow = 0; move16(); } ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ bits_to_follow = 0; move16(); - low = L_sub( low, ari_q2new ); - high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + low = L_sub( low, ari_q2new ); /* Q0 */ + high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/ } ELSE { @@ -166,9 +170,9 @@ Word16 ari_encode_14bits_ext_fx( { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add( bits_to_follow, 1 ); - low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ - high = L_sub( high, ari_q1new ); + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE { @@ -176,15 +180,15 @@ Word16 ari_encode_14bits_ext_fx( } } - low = L_add( low, low ); - high = L_add( high, high ); /* Scale up code range. */ + low = L_add( low, low ); /* Q0 */ + high = L_add( high, high ); /* Scale up code range. Q0*/ } - s->low = low; + s->low = low; /* Q0 */ move32(); - s->high = high; + s->high = high; /* Q0 */ move32(); - s->value = bits_to_follow; + s->value = bits_to_follow; /* Q0 */ move16(); return bp; @@ -204,7 +208,14 @@ Word16 ari_encode_overflow_fx( TastatEnc *s ) * * *-------------------------------------------------------------------------*/ -static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word32 high, Word32 low ) +static Word16 ari_encode_14bits_high_low( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s, + Word32 high, /* Q0 */ + Word32 low /* Q0 */ +) { Word16 bits_to_follow, tmp; @@ -212,22 +223,22 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T move16(); /* while there are more than 16 bits left */ - tmp = sub( 16, bits ); + tmp = sub( 16, bits ); /* Q0 */ WHILE( add( add( bp, bits_to_follow ), tmp ) < 0 ) { IF( LE_32( high, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 0 ); /* Q0 */ bits_to_follow = 0; move16(); } ELSE IF( GE_32( low, ari_q2new ) ) { - bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); + bp = ari_put_bit_plus_follow( ptr, bp, bits_to_follow, 1 ); /* Q0 */ bits_to_follow = 0; move16(); - low = L_sub( low, ari_q2new ); - high = L_sub( high, ari_q2new ); /* Subtract offset to top. */ + low = L_sub( low, ari_q2new ); /* Q0 */ + high = L_sub( high, ari_q2new ); /* Subtract offset to top. Q0*/ } ELSE { @@ -236,9 +247,9 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T { /* Output an opposite bit */ /* later if in middle half. */ - bits_to_follow = add( bits_to_follow, 1 ); - low = L_sub( low, ari_q1new ); /* Subtract offset to middle*/ - high = L_sub( high, ari_q1new ); + bits_to_follow = add( bits_to_follow, 1 ); /* Q0 */ + low = L_sub( low, ari_q1new ); /* Subtract offset to middle Q0*/ + high = L_sub( high, ari_q1new ); /* Q0 */ } ELSE { @@ -246,15 +257,15 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T } } - low = L_add( low, low ); - high = L_add( high, high ); /* Scale up code range. */ + low = L_add( low, low ); /* Q0 */ + high = L_add( high, high ); /* Scale up code range. Q0*/ } - s->low = low; + s->low = low; /* Q0 */ move32(); - s->high = high; + s->high = high; /* Q0 */ move32(); - s->value = bits_to_follow; + s->value = bits_to_follow; /* Q0 */ move16(); return bp; @@ -266,14 +277,21 @@ static Word16 ari_encode_14bits_high_low( Word16 *ptr, Word16 bp, Word16 bits, T * Encode an cumulative frequency interval. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_range_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high ) +Word16 ari_encode_14bits_range_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s, + Word16 cum_freq_low, /* Q0 */ + Word16 cum_freq_high /* Q0 */ +) { Word32 low, high, range; - range = L_sub( s->high, s->low ); + range = L_sub( s->high, s->low ); /* Q0 */ - high = L_add( s->low, mul_sbc_14bits( range, cum_freq_high ) ); - low = L_add( s->low, mul_sbc_14bits( range, cum_freq_low ) ); + high = L_add( s->low, mul_sbc_14bits( range, cum_freq_high ) ); /* Q0 */ + low = L_add( s->low, mul_sbc_14bits( range, cum_freq_low ) ); /* Q0 */ return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); } @@ -284,23 +302,29 @@ Word16 ari_encode_14bits_range_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEn * * Encode a sign with equal probabilities. *-------------------------------------------------------------------------*/ -Word16 ari_encode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign ) +Word16 ari_encode_14bits_sign_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s, + Word16 sign /* Q0 */ +) { Word32 low, high, range; Word32 L_tmp; high = L_add( s->high, 0 ); low = L_add( s->low, 0 ); - range = L_sub( high, low ); + range = L_sub( high, low ); /* Q0 */ L_tmp = L_shr( range, 1 ); if ( sign != 0 ) { - high = L_add( low, L_tmp ); + high = L_add( low, L_tmp ); /* Q0 */ } if ( sign == 0 ) { - low = L_add( low, L_tmp ); + low = L_add( low, L_tmp ); /* Q0 */ } return ari_encode_14bits_high_low( ptr, bp, bits, s, high, low ); @@ -311,25 +335,29 @@ Word16 ari_encode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc * * Finish up encoding in CBR mode. *-------------------------------------------------------------------------*/ -Word16 ari_done_cbr_encoding_14bits_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s ) +Word16 ari_done_cbr_encoding_14bits_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s ) { Word16 high, tmp, k; - tmp = sub( bits, 16 ); + tmp = sub( bits, 16 ); /* Q0 */ WHILE( GT_16( sub( tmp, bp ), s->value ) ) { - bp = ari_encode_14bits_sign_fx( ptr, bp, bits, s, 0 ); + bp = ari_encode_14bits_sign_fx( ptr, bp, bits, s, 0 ); /* Q0 */ } - high = extract_l( L_sub( s->high, 1 ) ); + high = extract_l( L_sub( s->high, 1 ) ); /* Q0 */ - bp = ari_put_bit_plus_follow( ptr, bp, s->value, lshr( high, 15 ) ); + bp = ari_put_bit_plus_follow( ptr, bp, s->value, lshr( high, 15 ) ); /* Q0 */ high = lshl( high, 1 ); tmp = s_min( 15, sub( bits, bp ) ); FOR( k = 0; k < tmp; ++k ) { - ptr[bp++] = lshr( high, 15 ); + ptr[bp++] = lshr( high, 15 ); /* Q0 */ move16(); high = lshl( high, 1 ); } diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index ee57efffe3b2735dcd2abba7fb1da5d9d236c078..0826880458f9a802528c4cdb2843932f7fa204a7 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -20,19 +20,19 @@ #define _1_ 0x2000 /*Q12*/ #define _1_Q9 0x200 -static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p ); +static void E_ACELP_codearithp_fx( const Word16 v[] /*Q9*/, UWord32 *n /*Q0*/, UWord32 *ps /*Q0*/, Word16 *p /*Q0*/ ); -void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[], Word16 dn2_pos[], Word16 nb_pulse ); +void E_ACELP_h_vec_corr1_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 track /*Q0*/, Word16 sign[] /*Q15*/, Word16 ( *rrixix )[16] /*Q9*/, Word16 cor[] /*Q9*/, Word16 dn2_pos[] /*Q0*/, Word16 nb_pulse /*Q0*/ ); -void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[] ); +void E_ACELP_h_vec_corr2_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 track /*Q0*/, Word16 sign[] /*Q15*/, Word16 ( *rrixix )[16] /*Q9*/, Word16 cor[] /*Q9*/ ); -Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn ); +Word16 E_ACELP_xy1_corr_fx( Word16 xn[] /*Q15-exp_xn*/, Word16 y1[] /*Q15-exp_xn*/, ACELP_CbkCorr *g_corr, Word16 norm_flag /*Q0*/, Word16 L_subfr /*Q0*/, Word16 exp_xn ); -void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 gain, Word16 L_subfr ); +void E_ACELP_codebook_target_update_fx( Word16 *x /*Q_xn*/, Word16 *x2 /*Q_xn*/, Word16 *y /*Q_xn*/, Word16 gain /*Q14*/, Word16 L_subfr /*Q0*/ ); -void E_ACELP_vec_neg( Word16 h[], Word16 h_inv[], Word16 L_subfr ); +void E_ACELP_vec_neg_fx( Word16 h[] /*Qx*/, Word16 h_inv[] /*Qx*/, Word16 L_subfr /*Q0*/ ); -void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256] ); +void E_ACELP_corrmatrix_fx( Word16 h[] /*Q12*/, Word16 sign[] /*Q0*/, Word16 vec[] /*Q15*/, Word16 rrixix[4][16] /*Q9*/, Word16 rrixiy[4][256] /*Q9*/ ); /* * E_ACELP_h_vec_corrx @@ -51,7 +51,7 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ * Returns: * void */ -void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[], Word16 dn2_pos[], Word16 nb_pulse ) +void E_ACELP_h_vec_corr1_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 track /*Q0*/, Word16 sign[] /*Q15*/, Word16 ( *rrixix )[16] /*Q9*/, Word16 cor[] /*Q9*/, Word16 dn2_pos[] /*Q0*/, Word16 nb_pulse /*Q0*/ ) { Word16 i, j; Word16 dn, corr; @@ -60,22 +60,23 @@ void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word32 L_sum; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - dn2 = &dn2_pos[shl( track, 3 )]; - p0 = rrixix[track]; + dn2 = &dn2_pos[( track * 8 )]; /*Q0*/ + p0 = rrixix[track]; /*Q9*/ FOR( i = 0; i < nb_pulse; i++ ) { - dn = dn2[i]; + dn = dn2[i]; /*Q0*/ move16(); L_sum = L_deposit_l( 0 ); - p1 = h; - p2 = &vec[dn]; + p1 = h; /*Qx*/ + p2 = &vec[dn]; /*Qx*/ FOR( j = dn; j < L_SUBFR - 1; j++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); + L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); /*2*Qx+1*/ #else L_sum = L_mac( L_sum, *p1++, *p2++ ); #endif @@ -92,7 +93,7 @@ void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], if ( sign[dn] > 0 ) { #ifdef BASOP_NOGLOB - corr = add_o( p0[j], corr, &Overflow ); + corr = add_o( p0[j], corr, &Overflow ); /*Q9*/ #else corr = add( p0[j], corr ); #endif @@ -100,40 +101,41 @@ void E_ACELP_h_vec_corr1( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], if ( sign[dn] < 0 ) { #ifdef BASOP_NOGLOB - corr = sub_o( p0[j], corr, &Overflow ); -#else /* BASOP_NOGLOB */ + corr = sub_o( p0[j], corr, &Overflow ); /*Q9*/ +#else /* BASOP_NOGLOB */ corr = sub( p0[j], corr ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ } - cor[j] = corr; + cor[j] = corr; /*Q9*/ move16(); } return; } -void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], Word16 ( *rrixix )[16], Word16 cor[] ) +void E_ACELP_h_vec_corr2_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 track /*Q0*/, Word16 sign[] /*Q15*/, Word16 ( *rrixix )[16] /*Q9*/, Word16 cor[] /*Q9*/ ) { Word16 i, j, pos, corr; Word16 *p0, *p1, *p2; Word32 L_sum; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - p0 = rrixix[track]; + p0 = rrixix[track]; /*Q9*/ - pos = track; + pos = track; /*Q0*/ move16(); FOR( i = 0; i < 16; i++ ) { L_sum = L_deposit_l( 0 ); - p1 = h; - p2 = &vec[pos]; + p1 = h; /*Qx*/ + p2 = &vec[pos]; /*Qx*/ FOR( j = pos; j < L_SUBFR - 1; j++ ) { #ifdef BASOP_NOGLOB - L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); + L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); /* 2*Qx+1 */ #else L_sum = L_mac( L_sum, *p1++, *p2++ ); #endif @@ -149,7 +151,7 @@ void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], if ( sign[pos] > 0 ) { #ifdef BASOP_NOGLOB - corr = add_o( *p0++, corr, &Overflow ); + corr = add_o( *p0++, corr, &Overflow ); /*Q9*/ #else corr = add( *p0++, corr ); #endif @@ -157,12 +159,12 @@ void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], if ( sign[pos] < 0 ) { #ifdef BASOP_NOGLOB - corr = sub_o( *p0++, corr, &Overflow ); + corr = sub_o( *p0++, corr, &Overflow ); /*Q9*/ #else corr = sub( *p0++, corr ); #endif } - cor[i] = corr; + cor[i] = corr; /*Q9*/ move16(); pos = add( pos, 4 ); @@ -194,7 +196,7 @@ void E_ACELP_h_vec_corr2( Word16 h[], Word16 vec[], UWord8 track, Word16 sign[], * Returns: * void */ -static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 track_y, Word16 *ps, Word16 *alp, Word16 *ix, Word16 *iy, Word16 dn[], Word16 *dn2, Word16 cor_x[], Word16 cor_y[], Word16 ( *rrixiy )[256] ) +static void E_ACELP_2pulse_search( Word16 nb_pos_ix /*Q0*/, UWord8 track_x /*Q0*/, UWord8 track_y /*Q0*/, Word16 *ps /*Qdn*/, Word16 *alp /*Qx*/, Word16 *ix /*Q0*/, Word16 *iy /*Q0*/, Word16 dn[] /*Qdn*/, Word16 *dn2 /*Q0*/, Word16 cor_x[] /*Qx*/, Word16 cor_y[] /*Qx*/, Word16 ( *rrixiy )[256] /*Q9*/ ) { Word16 x, x2, y, i, *pos_x; Word16 ps0, ps1, alp2_16, ps2, sq; @@ -203,28 +205,30 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 trac Word16 sqk[2], alpk[2], ik; Word32 xy_save; Word16 check = 0; /* debug code not instrumented */ + #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* eight dn2 max positions per track */ /*pos_x = &dn2[track_x << 3]; SHIFT(1); PTR_INIT(1);*/ - pos_x = &dn2[shl( track_x, 3 )]; + pos_x = &dn2[( track_x * 8 )]; /*Qdn*/ move16(); /* save these to limit memory searches */ - alp0 = L_deposit_h( *alp ); - ps0 = *ps; + alp0 = L_deposit_h( *alp ); /*Qx-16*/ + ps0 = *ps; /*Qdn*/ move16(); alpk[0] = 1; move16(); sqk[0] = -1; move16(); - x2 = shr( pos_x[0], 2 ); + x2 = shr( pos_x[0], 2 ); /*Qdn*/ #ifdef BASOP_NOGLOB - if ( mac_ro( L_mac_o( L_mac_o( alp0, cor_x[x2], _1_, &Overflow ), cor_y[0], _1_, &Overflow ), rrixiy[track_x][shl( x2, 4 )], _1_, &Overflow ) < 0 ) + if ( mac_ro( L_mac_o( L_mac_o( alp0, cor_x[x2], _1_, &Overflow ), cor_y[0], _1_, &Overflow ), rrixiy[track_x][( x2 * 16 )], _1_, &Overflow ) < 0 ) #else /* BASOP_NOGLOB */ if ( mac_r( L_mac( L_mac( alp0, cor_x[x2], _1_ ), cor_y[0], _1_ ), rrixiy[track_x][shl( x2, 4 )], _1_ ) < 0 ) #endif /* BASOP_NOGLOB */ @@ -234,17 +238,17 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 trac } ik = 0; move16(); - xy_save = L_mac0( L_deposit_l( track_y ), track_x, L_SUBFR ); + xy_save = L_mac0( L_deposit_l( track_y ), track_x, L_SUBFR ); /*Q0*/ /* loop track 1 */ FOR( i = 0; i < nb_pos_ix; i++ ) { - x = pos_x[i]; + x = pos_x[i]; /*Qdn*/ move16(); x2 = shr( x, 2 ); /* dn[x] has only nb_pos_ix positions saved */ /*ps1 = ps0 + dn[x];*/ - ps1 = add( ps0, dn[x] ); + ps1 = add( ps0, dn[x] ); /*Qdn*/ /*alp1 = alp0 + cor_x[x2];*/ #ifdef BASOP_NOGLOB @@ -253,28 +257,29 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 trac alp1 = L_mac( alp0, cor_x[x2], _1_ ); /*Q22*/ #endif /* BASOP_NOGLOB */ - p1 = cor_y; - p2 = &rrixiy[track_x][shl( x2, 4 )]; + p1 = cor_y; /*Qx*/ + p2 = &rrixiy[track_x][( x2 * 16 )]; /*Q9*/ FOR( y = track_y; y < L_SUBFR; y += 4 ) { /*ps2 = ps1 + dn[y];*/ - ps2 = add( ps1, dn[y] ); + ps2 = add( ps1, dn[y] ); /*Qdn*/ + move16(); /*alp2 = alp1 + (*p1++) + (*p2++);*/ #ifdef BASOP_NOGLOB - alp2 = L_mac_o( alp1, *p1++, _1_, &Overflow ); + alp2 = L_mac_o( alp1, *p1++, _1_, &Overflow ); /*Qx+12+1*/ alp2_16 = mac_ro( alp2, *p2++, _1_, &Overflow ); /*Q6*/ #else /* BASOP_NOGLOB */ alp2 = L_mac( alp1, *p1++, _1_ ); alp2_16 = mac_r( alp2, *p2++, _1_ ); /*Q6*/ #endif /* BASOP_NOGLOB */ - alpk[1 - ik] = alp2_16; + alpk[1 - ik] = alp2_16; /*Q6*/ move16(); /*sq = ps2 * ps2;*/ - sq = mult( ps2, ps2 ); - sqk[1 - ik] = sq; + sq = mult( ps2, ps2 ); /*2*Qdn+1*/ + sqk[1 - ik] = sq; /*2*Qdn+1*/ move16(); /*s = (alpk[ik] * sq) - (sqk[0] * alp2);*/ @@ -283,28 +288,30 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 trac if ( s > 0 ) { ik = sub( 1, ik ); + move16(); check = 1; /* debug code not instrumented */ + move16(); } if ( s > 0 ) { - xy_save = L_mac0( y, x, L_SUBFR ); + xy_save = L_mac0( y, x, L_SUBFR ); /*Qdn*/ } } } assert( check ); /* debug code not instrumented */ - ps2 = extract_l( xy_save ); - *iy = s_and( ps2, L_SUBFR - 1 ); + ps2 = extract_l( xy_save ); /*Qdn*/ + *iy = s_and( ps2, L_SUBFR - 1 ); /*Q0*/ move16(); - *ix = lshr( ps2, 6 ); + *ix = lshr( ps2, 6 ); /*Q0*/ move16(); /**ps = ps0 + dn[*ix] + dn[*iy];*/ - *ps = add( ps0, add( dn[*ix], dn[*iy] ) ); + *ps = add( ps0, add( dn[*ix], dn[*iy] ) ); /*Qdn*/ move16(); - *alp = alpk[ik]; + *alp = alpk[ik]; /*Q6*/ move16(); return; } @@ -330,12 +337,12 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix, UWord8 track_x, UWord8 trac * void */ static void E_ACELP_1pulse_search( UWord8 tracks[2], - Word16 *ps, - Word16 *alp, - Word16 *ix, - Word16 dn[], - Word16 cor_x[], - Word16 cor_y[] ) + Word16 *ps, /*Qdn*/ + Word16 *alp, /*Qx*/ + Word16 *ix, /*Q0*/ + Word16 dn[], /*Qdn*/ + Word16 cor_x[], /*Q6*/ + Word16 cor_y[] /*Q6*/ ) { Word16 x, x_save = 0; Word16 ps0; @@ -348,14 +355,14 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], /* save these to limit memory searches */ alp0 = L_deposit_h( *alp ); - ps0 = *ps; + ps0 = *ps; /*Qdn*/ move16(); alpk[0] = 1; move16(); sqk[0] = -1; move16(); - if ( mac_r_sat( alp0, cor_x[shr( tracks[0], 2 )], _1_ ) < 0 ) + if ( mac_r_sat( alp0, cor_x[( tracks[0] / 4 )], _1_ ) < 0 ) { sqk[0] = 1; move16(); @@ -364,6 +371,7 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], move16(); ntracks = 1; + move16(); if ( NE_16( tracks[1], tracks[0] ) ) { ntracks = 2; @@ -379,16 +387,16 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], FOR( x = tracks[t]; x < L_SUBFR; x += 4 ) { /*ps1 = ps0 + dn[x]; ADD(1);*/ - ps1 = add( ps0, dn[x] ); + ps1 = add( ps0, dn[x] ); /*Qdn*/ /*alp1 = alp0 + cor_x[x>>2]; SHIFT(1);ADD(1);*/ - alp1 = mac_r_sat( alp0, cor_x[shr( x, 2 )], _1_ ); /*Q6*/ - alpk[1 - ik] = alp1; + alp1 = mac_r_sat( alp0, cor_x[( x / 4 )], _1_ ); /*Q6*/ + alpk[1 - ik] = alp1; /*Q6*/ move16(); /*sq = ps1 * ps1; MULT(1);*/ - sq = mult( ps1, ps1 ); - sqk[1 - ik] = sq; + sq = mult( ps1, ps1 ); /*2*Qdn+1*/ + sqk[1 - ik] = sq; /*2*Qdn+1*/ move16(); /*s = (alpk * sq) - (sqk * alp1); MULT(1);MAC(1); */ @@ -408,11 +416,11 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], assert( check ); /* debug code not instrumented */ } - *ps = add( ps0, dn[x_save] ); + *ps = add( ps0, dn[x_save] ); /*2*Qdn+1*/ move16(); - *alp = alpk[ik]; + *alp = alpk[ik]; /*Q6*/ move16(); - *ix = x_save; + *ix = x_save; /*Q0*/ move16(); return; } @@ -437,7 +445,7 @@ static void E_ACELP_1pulse_search( UWord8 tracks[2], * Returns: * void */ -static void E_ACELP_xh_corr( Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr ) +static void E_ACELP_xh_corr( Word16 *x /*Qx*/, Word16 *y /*Qy*/, Word16 *h /*Q12*/, Word16 L_subfr /*Q0*/ ) { Word16 i, j, k; Word32 L_tmp, y32[L_SUBFR16k], L_maxloc, L_tot; @@ -452,16 +460,16 @@ static void E_ACELP_xh_corr( Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr ) L_maxloc = L_deposit_l( 0 ); FOR( i = k; i < L_subfr; i += 4 ) { - L_tmp = L_mac0( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] */ + L_tmp = L_mac0( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+Q12*/ FOR( j = i; j < L_subfr - 1; j++ ) { - L_tmp = L_mac0( L_tmp, x[j + 1], h[j + 1 - i] ); + L_tmp = L_mac0( L_tmp, x[j + 1], h[j + 1 - i] ); /*Qx+Q12*/ } - y32[i] = L_tmp; + y32[i] = L_tmp; /*Qx+Q12*/ move32(); - L_tmp = L_abs( L_tmp ); - L_maxloc = L_max( L_tmp, L_maxloc ); + L_tmp = L_abs( L_tmp ); /*Qx+Q12*/ + L_maxloc = L_max( L_tmp, L_maxloc ); /*Qx+Q12*/ } /* tot += 3*max / 8 */ L_maxloc = L_shr( L_maxloc, 2 ); @@ -482,7 +490,7 @@ static void E_ACELP_xh_corr( Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr ) j = sub( norm_l( L_tot ), 4 + 16 ); /* 4 -> 16 x tot */ - Copy_Scale_sig_32_16( y32, y, L_subfr, j ); + Copy_Scale_sig_32_16( y32, y, L_subfr, j ); /*Qy = Qx+Q12+j*/ return; } @@ -494,7 +502,7 @@ static void E_ACELP_xh_corr( Word16 *x, Word16 *y, Word16 *h, Word16 L_subfr ) * \param bits amount of target headroom bits for y * \return exponent of y */ -Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ) +Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, Word16 L_subfr /*Q0*/, Word16 bits /*Q0*/ ) { Word16 i, j, k = 0; /* initialize just to avoid compiler warning */ Word32 L_tmp, L_sum; @@ -504,21 +512,21 @@ Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ) Word64 L_tmp_64; Word64 L_sum_64; - L_tmp_64 = W_mult0_16_16( x[i], x[0] ); + L_tmp_64 = W_mult0_16_16( x[i], x[0] ); /*Q22*/ FOR( j = i + 2; j < L_subfr; j += 2 ) { - L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); + L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); /*Q22*/ } L_sum_64 = L_tmp_64; move64(); - L_tmp_64 = W_mult0_16_16( x[i + 1], x[1] ); + L_tmp_64 = W_mult0_16_16( x[i + 1], x[1] ); /*Q22*/ FOR( j = i + 3; j < L_subfr; j += 2 ) { - L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); + L_tmp_64 = W_mac0_16_16( L_tmp_64, x[j], x[j - i] ); /*Q22*/ } L_sum_64 = W_add_nosat( W_shr( L_sum_64, 1 ), W_shr( L_tmp_64, 1 ) ); - L_sum = W_sat_l( L_sum_64 ); + L_sum = W_sat_l( L_sum_64 ); /*Q22*/ /* L_sum = L_shr( L_sum, 1 ); */ if ( i == 0 ) { @@ -529,12 +537,12 @@ Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ) k = sub( k, bits ); } - y[i] = round_fx( L_shl( L_sum, k ) ); + y[i] = round_fx( L_shl( L_sum, k ) ); /*Q22+k-16*/ } - L_tmp = L_mult0( x[i], x[0] ); + L_tmp = L_mult0( x[i], x[0] ); /*Q22*/ L_sum = L_shr( L_tmp, 1 ); - y[i] = round_fx( L_shl( L_sum, k ) ); + y[i] = round_fx( L_shl( L_sum, k ) ); /*Qy = Q22+k-16*/ k = add( 1, k ); @@ -560,13 +568,14 @@ Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ) * Returns: * pitch gain (0 ... 1.2F) (Q14) */ -Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 norm_flag, Word16 L_subfr, Word16 exp_xn ) +Word16 E_ACELP_xy1_corr_fx( Word16 xn[] /*Q15-exp_xn*/, Word16 y1[] /*Q15-exp_xn*/, ACELP_CbkCorr *g_corr, Word16 norm_flag /*Q0*/, Word16 L_subfr /*Q0*/, Word16 exp_xn ) { Word16 i, Q_xn; Word16 xy, yy, exp_xy, exp_yy, gain; Word32 L_off; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif L_off = L_shr( 10737418l /*0.01f/2.0f Q31*/, s_min( add( exp_xn, exp_xn ), 31 ) ); @@ -574,10 +583,10 @@ Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 #ifdef BASOP_NOGLOB /* Compute scalar product t1: */ - yy = round_fx_o( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ), &Overflow ); + yy = round_fx_o( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ), &Overflow ); /*Q15 - exp_yy*/ /* Compute scalar product t0: */ - xy = round_fx_o( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ), &Overflow ); + xy = round_fx_o( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ), &Overflow ); /*Q15 - exp_xy*/ #else /* Compute scalar product t1: */ yy = round_fx( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ) ); @@ -606,8 +615,8 @@ Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 /* compute gain = xy/yy */ - xy = mult_r( xy, 0x4000 ); /* Be sure xy < yy */ - gain = div_s( xy, yy ); + xy = mult_r( xy, 0x4000 ); /* Be sure xy < yy Q15 - exp_xy*/ + gain = div_s( xy, yy ); /*Q14*/ i = add( exp_xy, 1 - 1 ); /* -1 -> gain in Q14 */ i = sub( i, exp_yy ); @@ -622,7 +631,7 @@ Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 /* if (gain > 1.2) gain = 1.2 in Q14 */ - gain = s_min( 19661 /*1.2f Q14*/ /* 19661 */, gain ); + gain = s_min( 19661 /*1.2f Q14*/ /* 19661 */, gain ); /*Q14*/ /*Limit the energy of pitch contribution*/ IF( norm_flag ) @@ -631,7 +640,7 @@ Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 /* Compute scalar product */ #ifdef BASOP_NOGLOB - tmp = round_fx_o( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ), &Overflow ); + tmp = round_fx_o( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ), &Overflow ); /*Q15 - exp_tmp*/ #else tmp = round_fx( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ) ); #endif @@ -639,19 +648,19 @@ Word16 E_ACELP_xy1_corr( Word16 xn[], Word16 y1[], ACELP_CbkCorr *g_corr, Word16 tmp = BASOP_Util_Divide1616_Scale( tmp, yy, &exp_div ); exp_tmp = add( sub( exp_tmp, exp_yy ), exp_div ); - tmp = Sqrt16( tmp, &exp_tmp ); + tmp = Sqrt16( tmp, &exp_tmp ); /*Q15 - exp_tmp*/ /* Note: shl works as shl or shr. */ exp_tmp = sub( exp_tmp, 1 ); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB - tmp = round_fx_o( L_shl_o( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp, &Overflow ), &Overflow ); -#else /* BASOP_NOGLOB */ + tmp = round_fx_o( L_shl_o( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp, &Overflow ), &Overflow ); /*Q14*/ +#else /* BASOP_NOGLOB */ tmp = round_fx( L_shl( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp ) ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ BASOP_SATURATE_WARNING_ON_EVS - gain = s_min( gain, tmp ); + gain = s_min( gain, tmp ); /*Q14*/ } bail: @@ -679,7 +688,7 @@ bail: * Returns: * pitch gain (0 ... 1.2F) */ -void E_ACELP_xy2_corr( Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn ) +void E_ACELP_xy2_corr( Word16 xn[] /*Q_xn*/, Word16 y1[] /*Q_xn*/, Word16 y2[] /*Q9*/, ACELP_CbkCorr *g_corr, Word16 L_subfr /*Q0*/, Word16 exp_xn ) { Word16 xny2, y2y2, y1y2, xx, exp_xny2, exp_y2y2, exp_y1y2, exp_xx; Word32 L_off; @@ -687,20 +696,20 @@ void E_ACELP_xy2_corr( Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_c BASOP_SATURATE_ERROR_ON_EVS; /* Compute scalar product */ - y2y2 = extract_h( Dot_product15_offs( y2, y2, L_subfr, &exp_y2y2, 5243l /*0.01f Q19*/ ) ); + y2y2 = extract_h( Dot_product15_offs( y2, y2, L_subfr, &exp_y2y2, 5243l /*0.01f Q19*/ ) ); /*Q15-exp_y2y2*/ /* L_off = 1L; */ L_off = L_shr( 10737418l /*0.01f/2.0f Q31*/, sub( 30 - 9, exp_xn ) ); /* Compute scalar product */ - xny2 = extract_h( Dot_product12_offs( xn, y2, L_subfr, &exp_xny2, L_off ) ); + xny2 = extract_h( Dot_product12_offs( xn, y2, L_subfr, &exp_xny2, L_off ) ); /*Q15-exp_xny2*/ /* Compute scalar product */ - y1y2 = extract_h( Dot_product12_offs( y1, y2, L_subfr, &exp_y1y2, L_off ) ); + y1y2 = extract_h( Dot_product12_offs( y1, y2, L_subfr, &exp_y1y2, L_off ) ); /*Q15-exp_y1y2*/ /* Compute scalar product */ L_off = L_shr( 21474836l /*0.01f Q31*/, s_min( 31, sub( 30, shl( exp_xn, 1 ) ) ) ); - xx = extract_h( Dot_product12_offs( xn, xn, L_subfr, &exp_xx, L_off ) ); + xx = extract_h( Dot_product12_offs( xn, xn, L_subfr, &exp_xx, L_off ) ); /*Q15-exp_xx*/ g_corr->y2y2 = y2y2; @@ -741,12 +750,13 @@ void E_ACELP_xy2_corr( Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_c * Returns: * void */ -void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 gain, Word16 L_subfr ) +void E_ACELP_codebook_target_update_fx( Word16 *x /*Q_xn*/, Word16 *x2 /*Q_xn*/, Word16 *y /*Q_xn*/, Word16 gain /*Q14*/, Word16 L_subfr /*Q0*/ ) { Word16 i, Q15_flag; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif assert( gain >= 0 ); @@ -757,21 +767,21 @@ void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 ga Q15_flag = 1; move16(); } - gain = shl( gain, Q15_flag ); + gain = shl( gain, Q15_flag ); /*Q14*/ FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_deposit_h( x[i] ); + L_tmp = L_deposit_h( x[i] ); /*Q_xn+16*/ if ( Q15_flag == 0 ) { #ifdef BASOP_NOGLOB - L_tmp = L_msu_o( L_tmp, y[i], gain, &Overflow ); + L_tmp = L_msu_o( L_tmp, y[i], gain, &Overflow ); /*Q_xn+15*/ #else L_tmp = L_msu( L_tmp, y[i], gain ); #endif } #ifdef BASOP_NOGLOB - x2[i] = msu_ro( L_tmp, y[i], gain, &Overflow ); + x2[i] = msu_ro( L_tmp, y[i], gain, &Overflow ); /*Q_xn*/ #else x2[i] = msu_r( L_tmp, y[i], gain ); #endif @@ -800,7 +810,7 @@ void E_ACELP_codebook_target_update( Word16 *x, Word16 *x2, Word16 *y, Word16 ga * Returns: * void */ -void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, const Word16 sign_val, const Word16 L_subfr ) +void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 dn2[] /*Qdn2*/, Word16 sign[] /*Q13*/, Word16 vec[] /*Q15*/, const Word16 alp /*Q13*/, const Word16 sign_val /*Q15*/, const Word16 L_subfr /*Q0*/ ) { Word16 i; Word32 Lval, Lcor; @@ -810,21 +820,22 @@ void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sig Word16 val, index; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* calculate energy for normalization of cn[] and dn[] */ - Lval = L_mac0( 1, cn[0], cn[0] ); - Lcor = L_mac0( 1, dn[0], dn[0] ); + Lval = L_mac0( 1, cn[0], cn[0] ); /*2*Q_xn*/ + Lcor = L_mac0( 1, dn[0], dn[0] ); /*2*Qdn*/ FOR( i = 1; i < L_subfr; i++ ) { #ifdef BASOP_NOGLOB - Lval = L_mac0_o( Lval, cn[i], cn[i], &Overflow ); -#else /* BASOP_NOGLOB */ + Lval = L_mac0_o( Lval, cn[i], cn[i], &Overflow ); /*2*Q_xn*/ +#else /* BASOP_NOGLOB */ Lval = L_mac0( Lval, cn[i], cn[i] ); -#endif /* BASOP_NOGLOB */ - Lcor = L_mac0( Lcor, dn[i], dn[i] ); +#endif /* BASOP_NOGLOB */ + Lcor = L_mac0( Lcor, dn[i], dn[i] ); /*2*Qdn*/ } e_dn = 31; @@ -832,8 +843,8 @@ void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sig e_cn = 31; move16(); - Lval = Sqrt32( Lval, &e_dn ); - Lcor = Sqrt32( Lcor, &e_cn ); + Lval = Sqrt32( Lval, &e_dn ); /*Q31 - e_dn*/ + Lcor = Sqrt32( Lcor, &e_cn ); /*Q31 - e_cn*/ i = sub( e_dn, e_cn ); if ( i < 0 ) Lval = L_shl( Lval, i ); @@ -841,55 +852,55 @@ void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sig Lcor = L_shr( Lcor, i ); #ifdef BASOP_NOGLOB - k_dn = round_fx_o( Lval, &Overflow ); - k_cn = round_fx_o( Lcor, &Overflow ); -#else /* BASOP_NOGLOB */ + k_dn = round_fx_o( Lval, &Overflow ); /*Q15 - e_dn*/ + k_cn = round_fx_o( Lcor, &Overflow ); /*Q15 - e_cn*/ +#else /* BASOP_NOGLOB */ k_dn = round_fx( Lval ); k_cn = round_fx( Lcor ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ k_cn = mult_r( 0x2000, k_cn ); /* 1 in Q13 */ k_dn = mult_r( alp, k_dn ); /* alp in Q13 */ - sign_neg = negate( sign_val ); + sign_neg = negate( sign_val ); /*Q15*/ - signs[0] = sign_neg; + signs[0] = sign_neg; /*Q15*/ move16(); - signs[1] = sign_val; + signs[1] = sign_val; /*Q15*/ move16(); - signs[2] = sign_neg; + signs[2] = sign_neg; /*Q15*/ move16(); - ptr16 = &signs[1]; + ptr16 = &signs[1]; /*Q15*/ FOR( i = 0; i < L_subfr; i++ ) { /*cor = (s * cn[i]) + (alp * dn[i]); MULT(1);MAC(1);*/ - Lcor = L_mult( cn[i], k_cn ); - Lcor = L_mac( Lcor, dn[i], k_dn ); + Lcor = L_mult( cn[i], k_cn ); /*Q_xn + Q15 - e_cn + 1*/ + Lcor = L_mac( Lcor, dn[i], k_dn ); /*Qdn + Q15 - e_dn + 1*/ #ifdef BASOP_NOGLOB - val = round_fx_o( L_shl_o( Lcor, 4, &Overflow ), &Overflow ); /*shifting by 4 may overflow but improves accuracy*/ + val = round_fx_o( L_shl_o( Lcor, 4, &Overflow ), &Overflow ); /*shifting by 4 may overflow but improves accuracy Qdn + 4 - e_dn*/ #else val = round_fx( L_shl( Lcor, 4 ) ); /*shifting by 4 may overflow but improves accuracy*/ #endif index = shr( val, 15 ); - sign[i] = ptr16[index]; - move16(); /* yields -1 (when ps < 0) or 0 (when ps >= 0) */ - vec[i] = ptr16[index + 1]; + sign[i] = ptr16[index]; /*Q15*/ + move16(); /* yields -1 (when ps < 0) or 0 (when ps >= 0) */ + vec[i] = ptr16[index + 1]; /*Q15*/ move16(); if ( val < 0 ) { - dn[i] = negate( dn[i] ); + dn[i] = negate( dn[i] ); /*Qdn*/ move16(); } - dn2[i] = abs_s( val ); - move16(); /* dn2[] = mix of dn[] and cn[] */ + dn2[i] = abs_s( val ); /*Qdn2 = Qdn + 4 - e_dn*/ + move16(); /* dn2[] = mix of dn[] and cn[] */ } } -void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] ) +void E_ACELP_findcandidates( Word16 dn2[] /*Qx*/, Word16 dn2_pos[] /*Q0*/, Word16 pos_max[] /*Q0*/ ) { Word16 i, k, j, i8; Word16 *ps_ptr; @@ -899,13 +910,13 @@ void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] ) i8 = shl( i, 3 ); FOR( k = i8; k < i8 + 8; k++ ) { - ps_ptr = &dn2[i]; + ps_ptr = &dn2[i]; /*Qx*/ FOR( j = i + 4; j < L_SUBFR; j += 4 ) { if ( GT_16( dn2[j], *ps_ptr ) ) { - ps_ptr = &dn2[j]; + ps_ptr = &dn2[j]; /*Qx*/ move16(); } } @@ -915,15 +926,15 @@ void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] ) dn2_pos[k] = (Word16) ( ps_ptr - dn2 ); move16(); } - pos_max[i] = dn2_pos[i8]; + pos_max[i] = dn2_pos[i8]; /*Q0*/ move16(); } } -static void E_ACELP_apply_sign( Word16 *p0, Word16 *psign0 ) +static void E_ACELP_apply_sign( Word16 *p0 /*Qx*/, Word16 *psign0 /*Q15*/ ) { - p0[0] = mult_r( p0[0], psign0[0] ); + p0[0] = mult_r( p0[0], psign0[0] ); /*Qx*/ move16(); p0[1] = mult_r( p0[1], psign0[4] ); move16(); @@ -957,7 +968,7 @@ static void E_ACELP_apply_sign( Word16 *p0, Word16 *psign0 ) move16(); } -void E_ACELP_vec_neg( Word16 h[], Word16 h_inv[], Word16 L_subfr ) +void E_ACELP_vec_neg_fx( Word16 h[] /*Qx*/, Word16 h_inv[] /*Qx*/, Word16 L_subfr /*Q0*/ ) { Word16 i; @@ -969,7 +980,7 @@ void E_ACELP_vec_neg( Word16 h[], Word16 h_inv[], Word16 L_subfr ) } -void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[4][16], Word16 rrixiy[4][256] ) +void E_ACELP_corrmatrix_fx( Word16 h[] /*Q12*/, Word16 sign[] /*Q0*/, Word16 vec[] /*Q15*/, Word16 rrixix[4][16] /*Q9*/, Word16 rrixiy[4][256] /*Q9*/ ) { Word16 *p0, *p1, *p2, *p3, *psign0, *psign1, *psign2, *psign3; @@ -989,20 +1000,20 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ p2 = &rrixix[2][16 - 1]; p3 = &rrixix[3][16 - 1]; - ptr_h1 = h; + ptr_h1 = h; /*Q12*/ cor = L_deposit_l( 0 ); FOR( i = 0; i < 16; i++ ) { - cor = L_mac( cor, *ptr_h1, *ptr_h1 ); + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); /*Q25*/ ptr_h1++; - *p3-- = round_fx( L_shr( cor, 1 ) ); - cor = L_mac( cor, *ptr_h1, *ptr_h1 ); + *p3-- = round_fx( L_shr( cor, 1 ) ); /* Q9 */ + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); /*Q25*/ ptr_h1++; - *p2-- = round_fx( L_shr( cor, 1 ) ); - cor = L_mac( cor, *ptr_h1, *ptr_h1 ); + *p2-- = round_fx( L_shr( cor, 1 ) ); /* Q9 */ + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); /*Q25*/ ptr_h1++; - *p1-- = round_fx( L_shr( cor, 1 ) ); - cor = L_mac( cor, *ptr_h1, *ptr_h1 ); + *p1-- = round_fx( L_shr( cor, 1 ) ); /* Q9 */ + cor = L_mac( cor, *ptr_h1, *ptr_h1 ); /*Q25*/ ptr_h1++; *p0-- = round_fx( L_shr( cor, 1 ) ); /* Q9 */ } @@ -1015,77 +1026,88 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ /* storage order --> i2i3, i1i2, i0i1, i3i0 */ pos = 256 - 1; - ptr_hf = h + 1; + move16(); + ptr_hf = h + 1; /*Q12*/ FOR( k = 0; k < 16; k++ ) { - p3 = &rrixiy[2][pos]; + p3 = &rrixiy[2][pos]; /* Q9 */ p2 = &rrixiy[1][pos]; p1 = &rrixiy[0][pos]; p0 = &rrixiy[3][pos - 16]; cor = L_deposit_h( 0 ); - ptr_h1 = h; - ptr_h2 = ptr_hf; + ptr_h1 = h; /*Q12*/ + ptr_h2 = ptr_hf; /*Q12*/ FOR( i = k; i < 16 - 1; i++ ) { - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p3 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p2 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p1 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p0 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p3 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p2 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p1 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p0 = round_fx( cor ); /*Q9*/ p3 -= ( 16 + 1 ); p2 -= ( 16 + 1 ); p1 -= ( 16 + 1 ); p0 -= ( 16 + 1 ); } - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p3 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p2 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p1 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p3 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p2 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p1 = round_fx( cor ); /*Q9*/ + move16(); + move16(); + move16(); pos -= 16; + move16(); ptr_hf += 4; } /* storage order --> i3i0, i2i3, i1i2, i0i1 */ pos = 256 - 1; - ptr_hf = h + 3; + move16(); + ptr_hf = h + 3; /*Q12*/ FOR( k = 0; k < 16; k++ ) { - p3 = &rrixiy[3][pos]; + p3 = &rrixiy[3][pos]; /*Q9*/ p2 = &rrixiy[2][pos - 1]; p1 = &rrixiy[1][pos - 1]; p0 = &rrixiy[0][pos - 1]; cor = L_deposit_h( 0 ); - ptr_h1 = h; - ptr_h2 = ptr_hf; + ptr_h1 = h; /*Q12*/ + ptr_h2 = ptr_hf; /*Q12*/ FOR( i = k; i < 16 - 1; i++ ) { - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p3 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p2 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p1 = round_fx( cor ); - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p0 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p3 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p2 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p1 = round_fx( cor ); /*Q9*/ + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p0 = round_fx( cor ); /*Q9*/ + move16(); + move16(); + move16(); + move16(); p3 -= ( 16 + 1 ); p2 -= ( 16 + 1 ); p1 -= ( 16 + 1 ); p0 -= ( 16 + 1 ); } - cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); - *p3 = round_fx( cor ); + cor = L_mac( cor, *ptr_h1++, *ptr_h2++ ); /*Q25*/ + *p3 = round_fx( cor ); /*Q9*/ + move16(); pos--; ptr_hf += 4; @@ -1095,7 +1117,7 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ * Modification of rrixiy[][] to take signs into account. */ - p0 = &rrixiy[0][0]; + p0 = &rrixiy[0][0]; /*Q9*/ /* speed-up: 11% */ p1 = &rrixiy[1][0]; @@ -1105,19 +1127,19 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ FOR( i = 0; i < L_SUBFR; i += 4 ) { - psign0 = &vec[1]; + psign0 = &vec[1]; /*Q15*/ if ( sign[i + 0] > 0 ) psign0 = &sign[1]; - psign1 = &vec[2]; + psign1 = &vec[2]; /*Q15*/ if ( sign[i + 1] > 0 ) psign1 = &sign[2]; - psign2 = &vec[3]; + psign2 = &vec[3]; /*Q15*/ if ( sign[i + 2] > 0 ) psign2 = &sign[3]; - psign3 = &vec[0]; + psign3 = &vec[0]; /*Q15*/ if ( sign[i + 3] > 0 ) psign3 = &sign[0]; @@ -1136,7 +1158,7 @@ void E_ACELP_corrmatrix( Word16 h[], Word16 sign[], Word16 vec[], Word16 rrixix[ return; } -void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[] ) +void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const Word16 H[] /*Q12*/, Word16 code[] /*Q9*/, const PulseConfig *config, Word16 ind[] /*Q0*/, Word16 y[] /*Qy*/ ) { Word16 sign[L_SUBFR], vec[L_SUBFR]; Word16 cor_x[16], cor_y[16], h_buf[4 * L_SUBFR]; @@ -1157,6 +1179,7 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word Word16 check = 0; /* debug code not instrumented */ #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -1197,12 +1220,12 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, H[i], H[i], &Overflow ); + L_tmp = L_mac_o( L_tmp, H[i], H[i], &Overflow ); /*Q25*/ #else L_tmp = L_mac( L_tmp, H[i], H[i] ); #endif } - val = extract_h( L_tmp ); + val = extract_h( L_tmp ); /*Q9*/ BASOP_SATURATE_WARNING_ON_EVS if ( GT_16( val, 0x2000 ) ) @@ -1216,15 +1239,15 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word move16(); } - Copy_Scale_sig( H, h, L_SUBFR, scale ); + Copy_Scale_sig( H, h, L_SUBFR, scale ); /*Q12+scale*/ - E_ACELP_vec_neg( h, h_inv, L_SUBFR ); + E_ACELP_vec_neg_fx( h, h_inv, L_SUBFR ); /* * Compute correlation matrices needed for the codebook search. */ - E_ACELP_corrmatrix( h, sign, vec, rrixix, rrixiy ); + E_ACELP_corrmatrix_fx( h, sign, vec, rrixix, rrixiy ); /* @@ -1275,25 +1298,25 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word i = shr( ind[0], 2 ); j = shr( ind[1], 2 ); l = add( shl( i, 4 ), j ); - s = L_mult( rrixix[ipos[0]][i], _1_ ); /* Q9+Q12+1 */ - s = L_mac( s, rrixix[ipos[1]][j], _1_ ); - alp = mac_r( s, rrixiy[ipos[0]][l], _1_ ); + s = L_mult( rrixix[ipos[0]][i], _1_ ); /* Q9+Q12+1 */ + s = L_mac( s, rrixix[ipos[1]][j], _1_ ); /* Q9+Q12+1 */ + alp = mac_r( s, rrixiy[ipos[0]][l], _1_ ); /* Q9+Q12+1-16 */ - p0 = h - ind[0]; + p0 = h - ind[0]; /*Q12+scale*/ if ( sign[ind[0]] < 0 ) { - p0 = h_inv - ind[0]; + p0 = h_inv - ind[0]; /*Q12+scale*/ } - p1 = h - ind[1]; + p1 = h - ind[1]; /*Q12+scale*/ if ( sign[ind[1]] < 0 ) { - p1 = h_inv - ind[1]; + p1 = h_inv - ind[1]; /*Q12+scale*/ } FOR( i = 0; i < L_SUBFR; i++ ) { - vec[i] = add( *p0++, *p1++ ); + vec[i] = add( *p0++, *p1++ ); /*Q12+scale*/ move16(); } } @@ -1301,57 +1324,57 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word { /* first stage: fix 4 pulses */ - ind[0] = pos_max[ipos[0]]; + ind[0] = pos_max[ipos[0]]; /*Q0*/ move16(); - ind[1] = pos_max[ipos[1]]; + ind[1] = pos_max[ipos[1]]; /*Q0*/ move16(); - ind[2] = pos_max[ipos[2]]; + ind[2] = pos_max[ipos[2]]; /*Q0*/ move16(); - ind[3] = pos_max[ipos[3]]; + ind[3] = pos_max[ipos[3]]; /*Q0*/ move16(); /*ps = dn[ind[0]] + dn[ind[1]] + dn[ind[2]] + dn[ind[3]];*/ ps = add( add( add( dn[ind[0]], dn[ind[1]] ), dn[ind[2]] ), dn[ind[3]] ); - p0 = h - ind[0]; + p0 = h - ind[0]; /*Q12+scale*/ if ( sign[ind[0]] < 0 ) { - p0 = h_inv - ind[0]; + p0 = h_inv - ind[0]; /*Q12+scale*/ } - p1 = h - ind[1]; + p1 = h - ind[1]; /*Q12+scale*/ if ( sign[ind[1]] < 0 ) { - p1 = h_inv - ind[1]; + p1 = h_inv - ind[1]; /*Q12+scale*/ } - p2 = h - ind[2]; + p2 = h - ind[2]; /*Q12+scale*/ if ( sign[ind[2]] < 0 ) { - p2 = h_inv - ind[2]; + p2 = h_inv - ind[2]; /*Q12+scale*/ } - p3 = h - ind[3]; + p3 = h - ind[3]; /*Q12+scale*/ if ( sign[ind[3]] < 0 ) { - p3 = h_inv - ind[3]; + p3 = h_inv - ind[3]; /*Q12+scale*/ } FOR( i = 0; i < L_SUBFR; i++ ) { - vec[i] = add( add( add( *p0++, *p1++ ), *p2++ ), *p3++ ); + vec[i] = add( add( add( *p0++, *p1++ ), *p2++ ), *p3++ ); /*Q12+scale*/ move16(); } - L_tmp = L_mult( vec[0], vec[0] ); + L_tmp = L_mult( vec[0], vec[0] ); /*Q25+2*scale*/ FOR( i = 1; i < L_SUBFR; i++ ) #ifdef BASOP_NOGLOB - L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); + L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q25+2*scale*/ #else L_tmp = L_mac( L_tmp, vec[i], vec[i] ); #endif - alp = round_fx( L_shr( L_tmp, 3 ) ); + alp = round_fx( L_shr( L_tmp, 3 ) ); /*Q6+2*scale*/ /*alp *= 0.5F; */ } @@ -1368,9 +1391,9 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word * of the next 2 pulses with previous fixed pulses. * Each pulse can have 16 possible positions. */ - E_ACELP_h_vec_corr1( h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, config->nbpos[st] ); + E_ACELP_h_vec_corr1_fx( h, vec, ipos[j], sign, rrixix, cor_x, dn2_pos, config->nbpos[st] ); - E_ACELP_h_vec_corr2( h, vec, ipos[j + 1], sign, rrixix, cor_y ); + E_ACELP_h_vec_corr2_fx( h, vec, ipos[j + 1], sign, rrixix, cor_y ); /* * Find best positions of 2 pulses. @@ -1380,9 +1403,9 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word } ELSE /* single pulse search */ { - E_ACELP_h_vec_corr2( h, vec, ipos[j], sign, rrixix, cor_x ); + E_ACELP_h_vec_corr2_fx( h, vec, ipos[j], sign, rrixix, cor_x ); - E_ACELP_h_vec_corr2( h, vec, ipos[j + 1], sign, rrixix, cor_y ); + E_ACELP_h_vec_corr2_fx( h, vec, ipos[j + 1], sign, rrixix, cor_y ); E_ACELP_1pulse_search( &ipos[j], &ps, &alp, &ind[j], dn, cor_x, cor_y ); @@ -1390,16 +1413,16 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word IF( GT_16( nb_pulse_m2, j ) ) { - p0 = h - ind[j]; + p0 = h - ind[j]; /*Q12+scale*/ if ( sign[ind[j]] < 0 ) { - p0 = h_inv - ind[j]; + p0 = h_inv - ind[j]; /*Q12+scale*/ } - p1 = h - ind[j + 1]; + p1 = h - ind[j + 1]; /*Q12+scale*/ if ( sign[ind[j + 1]] < 0 ) { - p1 = h_inv - ind[j + 1]; + p1 = h_inv - ind[j + 1]; /*Q12+scale*/ } @@ -1428,6 +1451,7 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word if ( psk < 0 ) { s = 1; + move32(); } IF( s > 0 ) { @@ -1435,8 +1459,8 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word move16(); alpk = alp; move16(); - Copy( ind, codvec, nb_pulse ); - check = 1; /* debug code not instrumented */ + Copy( ind, codvec, nb_pulse ); /*Q0*/ + check = 1; /* debug code not instrumented */ } } @@ -1451,9 +1475,9 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word set16_fx( y, 0, L_SUBFR ); FOR( k = 0; k < nb_pulse; ++k ) { - i = codvec[k]; + i = codvec[k]; /*Q0*/ move16(); - p0 = h_inv - i; + p0 = h_inv - i; /*Q12+scale*/ if ( sign[i] > 0 ) { p0 -= 2 * L_SUBFR; @@ -1461,7 +1485,7 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - y[i] = add_o( y[i], *p0++, &Overflow ); + y[i] = add_o( y[i], *p0++, &Overflow ); /*Q12+scale*/ #else y[i] = add( y[i], *p0++ ); #endif @@ -1507,19 +1531,19 @@ void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word * void */ void E_ACELP_4t_fx( - Word16 dn[], + Word16 dn[], /*Qdn*/ Word16 cn[] /* Q_xn */, - Word16 H[], - Word16 R[], - Word8 acelpautoc, - Word16 code[], - Word16 cdk_index, - Word16 _index[], - const Word16 L_frame, - const Word16 last_L_frame, - const Word32 total_brate, - const Word16 i_subfr, - const int16_t cmpl_flag ) + Word16 H[], /*Q12*/ + Word16 R[], /*Qx*/ + Word8 acelpautoc, /*Q0*/ + Word16 code[], /*Q9*/ + Word16 cdk_index, /*Q0*/ + Word16 _index[], /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 last_L_frame, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 i_subfr, /*Q0*/ + const int16_t cmpl_flag /*Q0*/ ) { PulseConfig config; Word16 ind[NPMAXPT * 4]; @@ -1570,20 +1594,20 @@ void E_ACELP_4t_fx( } void E_ACELP_4t_ivas_fx( - Word16 dn[], + Word16 dn[], /*Qdn*/ Word16 cn[] /* Q_xn */, - Word16 H[], - Word16 R[], - Word8 acelpautoc, - Word16 code[], - Word16 cdk_index, - Word16 _index[], - const Word16 L_frame, - const Word16 last_L_frame, - const Word32 total_brate, - const Word16 i_subfr, - const int16_t cmpl_flag, - Word16 element_mode ) + Word16 H[], /*Q12*/ + Word16 R[], /*Qx*/ + Word8 acelpautoc, /*Q0*/ + Word16 code[], /*Q9*/ + Word16 cdk_index, /*Q0*/ + Word16 _index[], /*Q0*/ + const Word16 L_frame, /*Q0*/ + const Word16 last_L_frame, /*Q0*/ + const Word32 total_brate, /*Q0*/ + const Word16 i_subfr, /*Q0*/ + const int16_t cmpl_flag, /*Q0*/ + Word16 element_mode /*Q0*/ ) { PulseConfig config; Word16 ind[NPMAXPT * 4]; @@ -1634,11 +1658,11 @@ void E_ACELP_4t_ivas_fx( } static void E_ACELP_indexing_shift( - Word16 wordcnt, /* i: 16-bit word count including the newly shifted-in bits */ - Word16 shift_bits, /* i: number of bits to shift in from the lsb */ - UWord16 lsb_bits, /* i: bits to shift in from the lsb */ - const UWord16 src[], /* i: source buffer */ - UWord16 dst[] /* o: destination buffer */ + Word16 wordcnt, /* i: 16-bit word count including the newly shifted-in bits Q0*/ + Word16 shift_bits, /* i: number of bits to shift in from the lsb Q0*/ + UWord16 lsb_bits, /* i: bits to shift in from the lsb Q0*/ + const UWord16 src[], /* i: source buffer Q0*/ + UWord16 dst[] /* o: destination buffer Q(shift_bits)*/ ) { Word16 right_shift, i; @@ -1649,10 +1673,10 @@ static void E_ACELP_indexing_shift( FOR( i = sub( wordcnt, 1 ); i > 0; --i ) { - dst[i] = s_or( lshl( src[i], shift_bits ), lshr( src[i - 1], right_shift ) ); + dst[i] = s_or( lshl( src[i], shift_bits ), lshr( src[i - 1], right_shift ) ); /*Q0+shift_bits*/ move16(); } - dst[i] = s_or( lshl( src[i], shift_bits ), lsb_bits ); + dst[i] = s_or( lshl( src[i], shift_bits ), lsb_bits ); /*Q(shift_bits)*/ move16(); return; } @@ -1660,10 +1684,10 @@ static void E_ACELP_indexing_shift( #define MAX_IDX_LEN 9 Word16 E_ACELP_indexing_fx( - const Word16 code[], + const Word16 code[], /*Q9*/ const PulseConfig *config, - Word16 num_tracks, - Word16 prm[] ) + Word16 num_tracks, /*Q0*/ + Word16 prm[] /*Q(shift_bits)*/ ) { Word16 track, shift_bits; Word16 p[NB_TRACK_FCB_4T], wordcnt; @@ -1716,6 +1740,7 @@ Word16 E_ACELP_indexing_fx( if ( GT_16( p[3], p[1] ) ) { track = add( track, 2 ); + move16(); } shift_bits = 2; move16(); @@ -1788,15 +1813,15 @@ Word16 E_ACELP_indexing_fx( void E_ACELP_adaptive_codebook( Word16 *exc, /* i/o: pointer to the excitation frame Q_new */ Word16 T0, /* i : integer pitch lag Q0 */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_res_max, /* i : maximum pitch resolution */ - Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 T0_res_max, /* i : maximum pitch resolution Q0 */ + Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) Q0 */ Word16 i_subfr, /* i : subframe index */ - Word16 L_subfr, /* i : subframe length */ - Word16 L_frame, /* i : subframe length */ + Word16 L_subfr, /* i : subframe length Q0 */ + Word16 L_frame, /* i : subframe length Q0 */ Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ - Word16 clip_gain, /* i : flag to indicate ??? */ + Word16 clip_gain, /* i : flag to indicate ??? Q14 */ Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_xn */ ACELP_CbkCorr *g_corr, /* o : ACELP correlation values */ @@ -1813,15 +1838,20 @@ void E_ACELP_adaptive_codebook( Word16 y2[L_SUBFR], xn2[L_SUBFR], code[L_SUBFR]; ACELP_CbkCorr g_corr2; Word16 gain1 = 0, gain2 = 0, fac_m, fac_n; + move16(); + move16(); Word16 i, select, exp_ener; Word32 L_tmp, L_ener; const Word16 *pitch_inter; Word16 pit_L_interpol, pit_up_samp; Word16 use_prev_sf_pit_gain = 0; + move16(); - if ( rf_mode == 1 && rf_coder_type == 100 ) + test(); + IF( EQ_16( rf_mode, 1 ) && EQ_16( rf_coder_type, 100 ) ) { use_prev_sf_pit_gain = 1; + move16(); } BASOP_SATURATE_ERROR_ON_EVS; @@ -1830,14 +1860,15 @@ void E_ACELP_adaptive_codebook( /* find pitch excitation */ /*for &exc[i_subfr]*/ - if ( EQ_16( T0_res, shr( T0_res_max, 1 ) ) ) + IF( EQ_16( T0_res, shr( T0_res_max, 1 ) ) ) { - T0_frac = shl( T0_frac, 1 ); + T0_frac = shl( T0_frac, 1 ); /*Q0*/ } + test(); IF( EQ_16( T0_res_max, 6 ) && rf_mode == 0 ) { - pitch_inter = pitch_inter6_2; + pitch_inter = pitch_inter6_2; /*Q14*/ pit_L_interpol = PIT_L_INTERPOL6_2; move16(); pit_up_samp = PIT_UP_SAMP6; @@ -1845,7 +1876,7 @@ void E_ACELP_adaptive_codebook( } ELSE { - pitch_inter = pitch_inter4_2; + pitch_inter = pitch_inter4_2; /*Q14*/ pit_L_interpol = L_INTERPOL2; move16(); pit_up_samp = PIT_UP_SAMP; @@ -1861,22 +1892,23 @@ void E_ACELP_adaptive_codebook( IF( use_prev_sf_pit_gain == 0 ) { - gain1 = E_ACELP_xy1_corr( xn, y1, g_corr, 1, L_subfr, exp_xn ); + gain1 = E_ACELP_xy1_corr_fx( xn, y1, g_corr, 1, L_subfr, exp_xn ); /*Q14*/ - /* clip gain if necessary to avoid problem at decoder */ test(); - if ( clip_gain && GT_16( gain1, 15565 /*0.95 Q14*/ ) ) + /* clip gain if necessary to avoid problem at decoder */ + test(); + IF( clip_gain && GT_16( gain1, 15565 /*0.95 Q14*/ ) ) { gain1 = 15565 /*0.95f Q14*/; move16(); } - *pitch_gain = gain1; + *pitch_gain = gain1; /*Q14*/ move16(); } /* find energy of new target xn2[] */ - E_ACELP_codebook_target_update( xn, xn2, y1, gain1, L_subfr ); - L_ener = Dot_product12_offs( xn2, xn2, L_subfr, &exp_ener, 0 ); - L_ener = L_shr( L_ener, sub( 31, exp_ener ) ); + E_ACELP_codebook_target_update_fx( xn, xn2, y1, gain1, L_subfr ); + L_ener = Dot_product12_offs( xn2, xn2, L_subfr, &exp_ener, 0 ); /*Q31-exp_ener*/ + L_ener = L_shr( L_ener, sub( 31, exp_ener ) ); /*Q0*/ } /*-----------------------------------------------------------------* @@ -1896,28 +1928,29 @@ void E_ACELP_adaptive_codebook( move16(); } /* fac_n = 0.5*(1.0-fac_m); */ - fac_n = mult_r( sub( 0x7FFF, fac_m ), 0x4000 ); + fac_n = mult_r( sub( 0x7FFF, fac_m ), 0x4000 ); /*Q15*/ FOR( i = 0; i < L_subfr; i++ ) { - L_tmp = L_mult( fac_n, exc[i - 1 + i_subfr] ); - L_tmp = L_mac( L_tmp, fac_m, exc[i + 0 + i_subfr] ); - code[i] = mac_r( L_tmp, fac_n, exc[i + 1 + i_subfr] ); + L_tmp = L_mult( fac_n, exc[i - 1 + i_subfr] ); /*Q_new+Q16*/ + L_tmp = L_mac( L_tmp, fac_m, exc[i + 0 + i_subfr] ); /*Q_new+Q16*/ + code[i] = mac_r( L_tmp, fac_n, exc[i + 1 + i_subfr] ); /*Q_new*/ move16(); } E_UTIL_f_convolve( code, h1, y2, L_subfr ); - gain2 = E_ACELP_xy1_corr( xn, y2, &g_corr2, 1, L_subfr, exp_xn ); + gain2 = E_ACELP_xy1_corr_fx( xn, y2, &g_corr2, 1, L_subfr, exp_xn ); /*Q14*/ - /* clip gain if necessary to avoid problem at decoder */ test(); - if ( clip_gain && GT_16( gain2, 15565 /*0.95 Q14*/ ) ) + /* clip gain if necessary to avoid problem at decoder */ + test(); + IF( clip_gain && GT_16( gain2, 15565 /*0.95 Q14*/ ) ) { gain2 = 15565 /*0.95f Q14*/; move16(); } /* find energy of new target xn2[] */ - E_ACELP_codebook_target_update( xn, xn2, y2, gain2, L_subfr ); - L_tmp = Dot_product12_offs( xn2, xn2, L_subfr, &exp_ener, 0 ); - L_tmp = L_shr( L_tmp, sub( 31, exp_ener ) ); + E_ACELP_codebook_target_update_fx( xn, xn2, y2, gain2, L_subfr ); + L_tmp = Dot_product12_offs( xn2, xn2, L_subfr, &exp_ener, 0 ); /*Q31 - exp_ener*/ + L_tmp = L_shr( L_tmp, sub( 31, exp_ener ) ); /*Q0*/ /*-----------------------------------------------------------------* * use the best prediction (minimise quadratic error). * @@ -1928,9 +1961,9 @@ void E_ACELP_adaptive_codebook( /* use the lp filter for pitch excitation prediction */ select = LOW_PASS; move16(); - Copy( code, &exc[i_subfr], L_subfr ); - Copy( y2, y1, L_subfr ); - *pitch_gain = gain2; + Copy( code, &exc[i_subfr], L_subfr ); /*Q_new*/ + Copy( y2, y1, L_subfr ); /*Q_xn*/ + *pitch_gain = gain2; /*Q14*/ move16(); g_corr->y1y1 = g_corr2.y1y1; move16(); @@ -1946,7 +1979,7 @@ void E_ACELP_adaptive_codebook( /* no filter used for pitch excitation prediction */ select = FULL_BAND; move16(); - *pitch_gain = gain1; + *pitch_gain = gain1; /*Q14*/ move16(); } @@ -1964,6 +1997,7 @@ void E_ACELP_adaptive_codebook( move16(); } *lp_select = select; + move16(); BASOP_SATURATE_ERROR_OFF_EVS; } @@ -1993,9 +2027,9 @@ void E_ACELP_innovative_codebook_fx( Word16 **pt_indice, /* i/o: quantization indices pointer */ Word16 *code, /* o : innovative codebook Q9 Q9 */ Word16 shift, /* i : Scaling to get 12 bits */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 last_L_frame, /* i : length of the last frame */ - const Word32 total_brate /* i : ttoal bit-rate */ + const Word16 L_frame, /* i : length of the frame Q0*/ + const Word16 last_L_frame, /* i : length of the last frame Q0*/ + const Word32 total_brate /* i : ttoal bit-rate Q0*/ ) { Word16 xn2[L_SUBFR] /* Q_xn */, cn2[L_SUBFR] /* Q_xn */, dn[L_SUBFR] /* Rw2*cn2 */, h2[L_SUBFR] /* 4Q11 */; @@ -2014,7 +2048,7 @@ void E_ACELP_innovative_codebook_fx( BASOP_SATURATE_ERROR_ON_EVS; /* Update target vector for ACELP codebook search */ - E_ACELP_codebook_target_update( xn, xn2, y1, pitch_gain, L_SUBFR ); + E_ACELP_codebook_target_update_fx( xn, xn2, y1, pitch_gain, L_SUBFR ); /* Include fixed-gain pitch contribution into impulse resp. h1[] */ Copy_Scale_sig( h1, h2, L_SUBFR, sub( -3, shift ) ); /*h2 1Q14+shift -> 4Q11, 1bit of headroom for Residu and xh_corr*/ @@ -2036,7 +2070,7 @@ void E_ACELP_innovative_codebook_fx( ELSE { BASOP_SATURATE_WARNING_OFF_EVS; - E_ACELP_codebook_target_update( cn, cn2, &exc[i_subfr], pitch_gain, L_SUBFR ); + E_ACELP_codebook_target_update_fx( cn, cn2, &exc[i_subfr], pitch_gain, L_SUBFR ); BASOP_SATURATE_WARNING_ON_EVS; Scale_sig( cn2, L_SUBFR, shift ); E_ACELP_xh_corr( xn2, dn, h2, L_SUBFR ); @@ -2073,7 +2107,7 @@ void E_ACELP_innovative_codebook_fx( * n - (output) range of possible states (0...n-1) * p - (output) number of pulses found *--------------------------------------------------------------------------*/ -static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Word16 *p ) +static void E_ACELP_codearithp_fx( const Word16 v[] /*Q9*/, UWord32 *n /*Q0*/, UWord32 *ps /*Q0*/, Word16 *p /*Q0*/ ) { Word16 k, nb_pulse, i, t, pos[NPMAXPT], posno; Word16 sign, m; @@ -2081,6 +2115,8 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; Flag Carry = 0; + move32(); + move32(); #endif /* Collect different pulse positions to pos[], number of them to posno */ @@ -2096,6 +2132,7 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo move16(); } t = add( t, 1 ); + move16(); if ( sub( posno, NPMAXPT ) >= 0 ) { BREAK; @@ -2110,13 +2147,14 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo move16(); FOR( k = 0; k < posno; ++k ) { - sign = shr( v[shl( pos[k], 2 )], 9 ); /* sign with multiplicity */ - m = abs_s( sign ); /* multiplicity */ + sign = shr( v[( pos[k] * 4 )], 9 ); /* sign with multiplicity Q0*/ + m = abs_s( sign ); /* multiplicity */ nb_pulse = add( nb_pulse, m ); /* Code m-1 pulses */ FOR( i = 1; i < m; ++i ) { Carry = 0; + move32(); #ifdef BASOP_NOGLOB s = L_add_co( s, pulsestostates[pos[k]][t], &Carry, &Overflow ); #else /* BASOP_NOGLOB */ @@ -2133,6 +2171,7 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo /* We use L_add_c since we want to work with unsigned UWord32 */ /* Therefore, we have to clear carry */ Carry = 0; + move32(); s = L_lshl( s, 1 ); if ( sign < 0 ) { @@ -2145,6 +2184,7 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo /* Code last pulse */ Carry = 0; + move32(); #ifdef BASOP_NOGLOB s = L_add_co( s, pulsestostates[pos[k]][t], &Carry, &Overflow ); #else /* BASOP_NOGLOB */ @@ -2153,21 +2193,21 @@ static void E_ACELP_codearithp_fx( const Word16 v[], UWord32 *n, UWord32 *ps, Wo t = add( t, 1 ); } - *ps = s; + *ps = s; /*Q0*/ move32(); *n = L_deposit_l( 0 ); if ( nb_pulse ) { - *n = pulsestostates[NB_POS_FCB_4T][nb_pulse - 1]; + *n = pulsestostates[NB_POS_FCB_4T][nb_pulse - 1]; /*Q0*/ move32(); } - *p = nb_pulse; + *p = nb_pulse; /*Q0*/ move16(); return; } -void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ) +void fcb_pulse_track_joint_fx( UWord16 *idxs /*Q0*/, Word16 wordcnt /*Q0*/, UWord32 *index_n /*Q0*/, Word16 *pulse_num /*Q0*/, Word16 track_num /*Q0*/ ) { Word16 hi_to_low[10]; UWord32 index, index_mask; @@ -2176,7 +2216,7 @@ void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 track, track_num1, pulse_num0, pulse_num1; Word16 indx_flag_2; - Copy( hi_to_low_tmpl, hi_to_low, 10 ); + Copy( hi_to_low_tmpl, hi_to_low, 10 ); /*Q0*/ indx_flag = 0; move16(); @@ -2196,7 +2236,7 @@ void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, { hi_to_low[7] = 9; move16(); - index_mask = 0xFFFFFF; + index_mask = 0xFFFFFF; /*Q0*/ move32(); } ELSE @@ -2206,34 +2246,35 @@ void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, hi_to_low[4] = 1; move16(); } - index_mask = L_shr( 0xFFFF, sub( 9, hi_to_low[4] ) ); + index_mask = L_shr( 0xFFFF, sub( 9, hi_to_low[4] ) ); /*Q0*/ } IF( GE_16( indx_flag_1, track_num ) ) { indx_tmp = L_deposit_l( 0 ); - index = L_shr( index_n[0], low_len[pulse_num[0]] ); + index = L_shr( index_n[0], low_len[pulse_num[0]] ); /*Q0*/ FOR( track = 1; track < track_num; track++ ) { - pulse_num0 = pulse_num[track - 1]; + pulse_num0 = pulse_num[track - 1]; /*Q0*/ move16(); - pulse_num1 = pulse_num[track]; + pulse_num1 = pulse_num[track]; /*Q0*/ move16(); - indx_tmp = L_lshr( index_n[track], low_len[pulse_num1] ); + indx_tmp = L_lshr( index_n[track], low_len[pulse_num1] ); /*Q0*/ /* index = index * indx_fact[pulse_num1] + indx_tmp; */ - index = UL_Mpy_32_32( index, UL_deposit_l( indx_fact[pulse_num1] ) ); + index = UL_Mpy_32_32( index, UL_deposit_l( indx_fact[pulse_num1] ) ); /*Q0*/ index = UL_addNsD( index, indx_tmp ); index_n[track - 1] = L_add( L_and( index_n[track - 1], low_mask[pulse_num0] ), - L_and( L_lshl( index, low_len[pulse_num0] ), index_mask ) ); + L_and( L_lshl( index, low_len[pulse_num0] ), index_mask ) ); /*Q0*/ index = L_lshr( index, hi_to_low[pulse_num0] ); } track_num1 = sub( track_num, 1 ); - pulse_num1 = pulse_num[track_num1]; + move16(); + pulse_num1 = pulse_num[track_num1]; /*Q0*/ move16(); index_n[track_num1] = L_and( L_add( L_and( index_n[track_num1], low_mask[pulse_num1] ), L_lshl( index, low_len[pulse_num1] ) ), - index_mask ); + index_mask ); /*Q0*/ index = L_lshr( index, hi_to_low[pulse_num1] ); IF( GE_16( indx_flag, track_num ) ) { @@ -2266,11 +2307,11 @@ void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, } ELSE { - index = index_n[0]; + index = index_n[0]; /*Q0*/ move32(); FOR( track = 1; track < 4; track++ ) { - pulse_num1 = pulse_num[track]; + pulse_num1 = pulse_num[track]; /*Q0*/ index = L_add( L_lshl( index, index_len[pulse_num1] ), index_n[track] ); } track = 0; diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index 0ee3c51856af219d536d57f65af0ff536d9fa766..3498321646e22d98a77ebd738db6e55f43fdee03 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -18,15 +18,15 @@ * encoder function for coding ACELP/TCX *--------------------------------------------------------------------*/ void enc_acelp_tcx_main_fx( - const Word16 new_samples[], /* i : new samples */ - Encoder_State *st, /* i/o: encoder state structure */ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 new_samples[], /* i : new samples Q15*/ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame Q15*/ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q_new*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 pitch_buf[], /* o : floating pitch for each subframe Q6*/ + Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ Word16 *Q_new, Word16 *shift ) { @@ -39,7 +39,7 @@ void enc_acelp_tcx_main_fx( IF( EQ_16( st->last_core, ACELP_CORE ) ) { set16_fx( old_bwe_exc + PIT16k_MAX * 2, 0, ( ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 ); - Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); + Copy( hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); /*Q_exc*/ } ELSE { @@ -74,7 +74,7 @@ void enc_acelp_tcx_main_fx( non_linearity_fx( ptr_bwe_exc, bwe_exc_extended, L_FRAME32k, &hBWE_TD->bwe_non_lin_prev_scale_fx, *Q_new, st->coder_type, voice_factors, st->L_frame ); /* update the old BWE exe memory */ - Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); + Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); /*Q_exc*/ } ELSE { diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index af773cac453fa0e258ffb57e8936fc6cd0c5b302..99c9568ebfc47d055d81a3d9444bf5b7a4d30321 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -19,13 +19,13 @@ /*--------------------------------------------------------------------------------------* * E_ACELP_update_cor *--------------------------------------------------------------------------------------*/ -static void E_ACELP_update_cor( - const Word16 pos[], /* i */ - Word16 nb_pulse, /* i */ - const Word16 sign[], /* i */ - const Word16 R[], /* i */ - const Word16 cor_in[], /* i */ - Word16 cor_out[] /* o */ +static void E_ACELP_update_cor_fx( + const Word16 pos[], /* i Q0*/ + Word16 nb_pulse, /* i Q0*/ + const Word16 sign[], /* i Q13*/ + const Word16 R[], /* i Q9+scale*/ + const Word16 cor_in[], /* i Q9*/ + Word16 cor_out[] /* o Q9*/ ) { Word16 sign_x, sign_y; @@ -36,9 +36,9 @@ static void E_ACELP_update_cor( { /* Update product of autocorrelation and already fixed pulses. with the * two newly found ones */ - sign_x = sign[pos[0]]; + sign_x = sign[pos[0]]; /*Q13*/ move16(); - sign_y = sign[pos[1]]; + sign_y = sign[pos[1]]; /*Q13*/ move16(); IF( s_xor( sign_x, sign_y ) < 0 ) @@ -50,24 +50,24 @@ static void E_ACELP_update_cor( i = 0; move16(); } - pRx = R - pos[i]; - pRy = R - pos[1 - i]; + pRx = R - pos[i]; /*Q9+scale*/ + pRy = R - pos[1 - i]; /*Q9+scale*/ /* different sign x and y */ FOR( i = 0; i < L_SUBFR; i++ ) { tmp = sub( pRx[i], pRy[i] ); if ( cor_in != NULL ) { - tmp = add( tmp, cor_in[i] ); + tmp = add( tmp, cor_in[i] ); /* Q9 */ } - cor_out[i] = tmp; + cor_out[i] = tmp; /* Q9 */ move16(); } } ELSE { - pRx = R - pos[0]; - pRy = R - pos[1]; + pRx = R - pos[0]; /*Q9+scale*/ + pRy = R - pos[1]; /*Q9+scale*/ IF( sign_x > 0 ) { /* sign x and y is positive */ @@ -76,9 +76,9 @@ static void E_ACELP_update_cor( tmp = add( pRx[i], pRy[i] ); if ( cor_in != NULL ) { - tmp = add( tmp, cor_in[i] ); + tmp = add( tmp, cor_in[i] ); /* Q9 */ } - cor_out[i] = tmp; + cor_out[i] = tmp; /* Q9 */ move16(); } } @@ -90,13 +90,13 @@ static void E_ACELP_update_cor( tmp = add( pRx[i], pRy[i] ); if ( cor_in != NULL ) { - tmp = sub( cor_in[i], tmp ); + tmp = sub( cor_in[i], tmp ); /* Q9 */ } if ( cor_in == NULL ) { tmp = negate( tmp ); } - cor_out[i] = tmp; + cor_out[i] = tmp; /* Q9 */ move16(); } } @@ -104,8 +104,8 @@ static void E_ACELP_update_cor( } ELSE IF( EQ_16( nb_pulse, 4 ) ) { - E_ACELP_update_cor( pos, 2, sign, R, cor_in, cor_out ); - E_ACELP_update_cor( pos + 2, 2, sign, R, cor_out, cor_out ); + E_ACELP_update_cor_fx( pos, 2, sign, R, cor_in, cor_out ); + E_ACELP_update_cor_fx( pos + 2, 2, sign, R, cor_out, cor_out ); } else { @@ -116,20 +116,20 @@ static void E_ACELP_update_cor( * E_ACELP_2pulse_searchx * Iterations: nb_pos_ix*16 *--------------------------------------------------------------------------------------*/ -static void E_ACELP_2pulse_searchx( - const Word16 nb_pos_ix, - const Word16 track_x, - const Word16 track_y, - Word16 *R, - Word16 *ps, - Word16 *alp, - Word16 *ix, - Word16 *iy, - Word16 dn[], - Word16 *dn2, - Word16 cor[], - Word16 sign[], - Word16 sign_val_2 ) +static void E_ACELP_2pulse_searchx_fx( + const Word16 nb_pos_ix, /*Q0*/ + const Word16 track_x, /*Q0*/ + const Word16 track_y, /*Q0*/ + Word16 *R, /*Q9+scale*/ + Word16 *ps, /*Qdn*/ + Word16 *alp, /*Q6*/ + Word16 *ix, /*Q0*/ + Word16 *iy, /*Q0*/ + Word16 dn[], /*Qdn*/ + Word16 *dn2, /*Q0*/ + Word16 cor[], /*Q9*/ + Word16 sign[], /*Q13*/ + Word16 sign_val_2 /*Q15*/ ) { Word16 i, x; Word32 y; @@ -141,18 +141,19 @@ static void E_ACELP_2pulse_searchx( Word16 sqk[2], alpk[2], ik; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* eight dn2 max positions per track */ - pos_x = &dn2[shl( track_x, 3 )]; + pos_x = &dn2[( track_x * 8 )]; /*Qdn*/ move16(); /* save these to limit memory searches */ - ps0 = *ps; + ps0 = *ps; /*Qdn*/ move16(); /*alp0 = *alp + 2.0f*R[0]; move16();*/ alp0 = L_deposit_h( *alp ); /* Qalp = Q_R*Q_signval */ #ifdef BASOP_NOGLOB - alp0 = L_mac_sat( alp0, R[0], sign_val_2 ); + alp0 = L_mac_sat( alp0, R[0], sign_val_2 ); /*Q9+scale+Q15*/ #else alp0 = L_mac( alp0, R[0], sign_val_2 ); #endif @@ -164,7 +165,7 @@ static void E_ACELP_2pulse_searchx( move16(); x = pos_x[0]; move16(); - sgnx = sign[track_y]; + sgnx = sign[track_y]; /*Q13*/ move16(); if ( sign[x] < 0 ) { @@ -183,19 +184,19 @@ static void E_ACELP_2pulse_searchx( ik = 0; move16(); - xy_save = L_mac0( L_deposit_l( track_y ), track_x, L_SUBFR ); + xy_save = L_mac0( L_deposit_l( track_y ), track_x, L_SUBFR ); /*Q0*/ /* loop track 1 */ FOR( i = 0; i < nb_pos_ix; i++ ) { - x = pos_x[i]; + x = pos_x[i]; /*Q0*/ move16(); - sgnx = sign[x]; + sgnx = sign[x]; /*Q13*/ move16(); /* dn[x] has only nb_pos_ix positions saved */ /*ps1 = ps0 + dn[x]; INDIRECT(1);ADD(1);*/ #ifdef BASOP_NOGLOB - ps1 = add_sat( ps0, dn[x] ); + ps1 = add_sat( ps0, dn[x] ); /*Qdn*/ #else ps1 = add( ps0, dn[x] ); #endif @@ -205,13 +206,13 @@ static void E_ACELP_2pulse_searchx( #else alp1 = L_mac( alp0, cor[x], sgnx ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #endif - pR = R - x; + pR = R - x; /*Q9+scale*/ FOR( y = track_y; y < L_SUBFR; y += 4 ) { /*ps2 = ps1 + dn[y]; ADD(1);*/ #ifdef BASOP_NOGLOB - ps2 = add_sat( ps1, dn[y] ); + ps2 = add_sat( ps1, dn[y] ); /*Qdn*/ #else ps2 = add( ps1, dn[y] ); #endif @@ -244,12 +245,12 @@ static void E_ACELP_2pulse_searchx( alp2_16 = msu_r( alp2, pR[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #endif } - alpk[1 - ik] = alp2_16; + alpk[1 - ik] = alp2_16; /* Qalp */ move16(); /*sq = ps2 * ps2; MULT(1);*/ sq = mult_r( ps2, ps2 ); /* (3+3)Q -> 6Q9 */ - sqk[1 - ik] = sq; + sqk[1 - ik] = sq; /* Q9 */ move16(); @@ -265,7 +266,7 @@ static void E_ACELP_2pulse_searchx( } if ( s > 0 ) { - xy_save = L_mac0( y, x, L_SUBFR ); + xy_save = L_mac0( y, x, L_SUBFR ); /* Q0 */ } assert( ( ( s >= 0 && i == 0 && y == track_y ) ) || ( y > track_y ) || ( i > 0 ) ); } @@ -273,21 +274,21 @@ static void E_ACELP_2pulse_searchx( ps1 = extract_l( xy_save ); pos[1] = s_and( ps1, L_SUBFR - 1 ); move16(); - pos[0] = lshr( ps1, 6 ); + pos[0] = lshr( ps1, 6 ); /* Q0 */ move16(); /* Update numerator */ - *ps = add( add( ps0, dn[pos[0]] ), dn[pos[1]] ); + *ps = add( add( ps0, dn[pos[0]] ), dn[pos[1]] ); /* Qdn */ move16(); /* Update denominator */ - *alp = alpk[ik]; + *alp = alpk[ik]; /* Q_alp */ move16(); - E_ACELP_update_cor( pos, 2, sign, R, cor, cor ); + E_ACELP_update_cor_fx( pos, 2, sign, R, cor, cor ); - *ix = pos[0]; + *ix = pos[0]; /* Q0 */ move16(); - *iy = pos[1]; + *iy = pos[1]; /* Q0 */ move16(); assert( ( ( pos[0] & 3 ) == track_x ) && ( ( pos[1] & 3 ) == track_y ) ); /* sanity check */ @@ -296,16 +297,16 @@ static void E_ACELP_2pulse_searchx( /*--------------------------------------------------------------------------------------* * E_ACELP_1pulse_searchx *--------------------------------------------------------------------------------------*/ -static void E_ACELP_1pulse_searchx( - UWord8 tracks[2], - Word16 *R, - Word16 *ps, - Word16 *alp, - Word16 *ix, - Word16 dn[], - Word16 cor[], - Word16 sign[], - Word16 sign_val_1 ) +static void E_ACELP_1pulse_searchx_fx( + UWord8 tracks[2], /*Q0*/ + Word16 *R, /*Q9+scale*/ + Word16 *ps, /* Qdn */ + Word16 *alp, /*Q6*/ + Word16 *ix, /*Q0*/ + Word16 dn[], /* Qdn */ + Word16 cor[], /* Q9 */ + Word16 sign[], /* Q13 */ + Word16 sign_val_1 /* Q15 */ ) { Word16 x, x_save = 0; Word16 ps0; @@ -315,14 +316,16 @@ static void E_ACELP_1pulse_searchx( Word32 s; Word16 ntracks, t; Word16 sqk[2], alpk[2], ik; + move16(); #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /* save these to limit memory searches */ /*alp0 = *alp + R[0]; INDIRECT(1);*/ - ps0 = *ps; + ps0 = *ps; /* Qdn */ move16(); - alp0 = L_deposit_h( *alp ); + alp0 = L_deposit_h( *alp ); /* Q22 */ alp0 = L_mac( alp0, R[0], sign_val_1 ); /* Qalp = (Q_R=Q_cor)*Q_signval */ /* Ensure that in the loop below s > 0 in the first iteration, the actual values do not matter. */ @@ -342,10 +345,11 @@ static void E_ACELP_1pulse_searchx( move16(); } - x_save = tracks[0]; + x_save = tracks[0]; /* Q0 */ move16(); ntracks = 1; + move16(); if ( NE_16( tracks[1], tracks[0] ) ) { ntracks = 2; @@ -364,18 +368,18 @@ static void E_ACELP_1pulse_searchx( #else alp1 = mac_r( alp0, cor[x], sign[x] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ #endif - alpk[1 - ik] = alp1; + alpk[1 - ik] = alp1; /* Qalp */ move16(); /*sq = ps1 * ps1; MULT(1);*/ sq = mult_r( ps1, ps1 ); /* 6Q9 */ - sqk[1 - ik] = sq; + sqk[1 - ik] = sq; /* Q9 */ move16(); /*s = (alpk[ik] * sq) - (sqk[ik] * alp1); MULT(1);MAC(1);*/ #ifdef BASOP_NOGLOB - s = L_msu_o( L_mult_o( alpk[ik], sq, &Overflow ), sqk[ik], alp1, &Overflow ); + s = L_msu_o( L_mult_o( alpk[ik], sq, &Overflow ), sqk[ik], alp1, &Overflow ); /* Q9+Qalp+1 */ #else s = L_msu( L_mult( alpk[ik], sq ), sqk[ik], alp1 ); #endif @@ -392,11 +396,11 @@ static void E_ACELP_1pulse_searchx( } } - *ps = add( ps0, dn[x_save] ); + *ps = add( ps0, dn[x_save] ); /* Qdn */ move16(); - *alp = alpk[ik]; + *alp = alpk[ik]; /* Qalp */ move16(); - *ix = x_save; + *ix = x_save; /* Q0 */ move16(); } @@ -406,12 +410,12 @@ static void E_ACELP_1pulse_searchx( * Algorithm is identical to traditional covariance method *--------------------------------------------------------------------------------------*/ void E_ACELP_4tsearchx_fx( - Word16 dn[], - const Word16 cn[], - Word16 Rw[], - Word16 code[], + Word16 dn[], /*Qdn*/ + const Word16 cn[], /*Q_new*/ + Word16 Rw[], /*Q9*/ + Word16 code[], /*Q9*/ const PulseConfig *config, - Word16 ind[] ) + Word16 ind[] /*Q0*/ ) { Word16 sign[L_SUBFR], vec[L_SUBFR]; Word16 cor[L_SUBFR]; @@ -427,8 +431,11 @@ void E_ACELP_4tsearchx_fx( Word16 scale; Word16 sign_val_1, sign_val_2; Word16 nb_pulse, nb_pulse_m2; + move16(); + move16(); ps = 0; /* to avoid compilation warnings */ + move16(); alp = config->alp; /* Q13 */ @@ -447,10 +454,10 @@ void E_ACELP_4tsearchx_fx( scale = 0; move16(); - s = L_mult0( Rw[0], Rw[0] ); + s = L_mult0( Rw[0], Rw[0] ); /*Q18*/ FOR( i = 1; i < L_SUBFR; i++ ) { - s = L_mac0( s, Rw[i], Rw[i] ); + s = L_mac0( s, Rw[i], Rw[i] ); /*Q18*/ } if ( s_and( (Word16) GE_16( nb_pulse, 9 ), (Word16) GT_32( s, 0x800000 ) ) ) { @@ -493,7 +500,7 @@ void E_ACELP_4tsearchx_fx( /* Set up autocorrelation vector */ R = R_buf + L_SUBFR - 1; - Copy_Scale_sig( Rw, R, L_SUBFR, scale ); + Copy_Scale_sig( Rw, R, L_SUBFR, scale ); /*Q9+scale*/ FOR( k = 1; k < L_SUBFR; k++ ) { R[-k] = R[k]; @@ -501,13 +508,13 @@ void E_ACELP_4tsearchx_fx( } /* Sign value */ - sign_val_2 = 0x2000; + sign_val_2 = 0x2000; /* Q15 */ move16(); if ( GE_16( nb_pulse, 24 ) ) { - sign_val_2 = shr( sign_val_2, 1 ); + sign_val_2 = shr( sign_val_2, 1 ); /* Q15 */ } - sign_val_1 = shr( sign_val_2, 1 ); + sign_val_1 = shr( sign_val_2, 1 ); /* Q15 */ /* * Find sign for each pulse position. @@ -535,7 +542,7 @@ void E_ACELP_4tsearchx_fx( E_ACELP_setup_pulse_search_pos( config, k, ipos ); /* index to first non-fixed position */ - pos = config->fixedpulses; + pos = config->fixedpulses; /* Q0 */ move16(); IF( config->fixedpulses == 0 ) /* 1100, 11, 1110, 1111, 2211 */ @@ -553,23 +560,23 @@ void E_ACELP_4tsearchx_fx( /* set fixed positions */ FOR( i = 0; i < pos; ++i ) { - ind[i] = pos_max[ipos[i]]; + ind[i] = pos_max[ipos[i]]; /* Q0 */ move16(); } /* multiplication of autocorrelation with signed fixed pulses */ - E_ACELP_update_cor( ind, config->fixedpulses, sign, R, NULL, cor ); + E_ACELP_update_cor_fx( ind, config->fixedpulses, sign, R, NULL, cor ); /* normalisation contribution of fixed part */ - s = L_mult0( cor[ind[0]], sign[ind[0]] ); - ps = dn[ind[0]]; + s = L_mult0( cor[ind[0]], sign[ind[0]] ); /* Q22 */ + ps = dn[ind[0]]; /* Qdn */ move16(); FOR( i = 1; i < pos; ++i ) { - s = L_mac0( s, cor[ind[i]], sign[ind[i]] ); /*Q12+Q9+1=Q6 */ - ps = add( ps, dn[ind[i]] ); + s = L_mac0( s, cor[ind[i]], sign[ind[i]] ); /*Q12+Q9+1=Q22 */ + ps = add( ps, dn[ind[i]] ); /* Qdn */ } - alp = round_fx( s ); /*mac0 >>1 sign = 2*/ + alp = round_fx( s ); /*mac0 >>1 sign = 2 Q6*/ } /* other stages of 2 pulses */ @@ -585,13 +592,13 @@ void E_ACELP_4tsearchx_fx( * Each pulse can have 16 possible positions. */ - E_ACELP_2pulse_searchx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, - &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); + E_ACELP_2pulse_searchx_fx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, + &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); } ELSE /* single pulse search */ { - E_ACELP_1pulse_searchx( &ipos[j], R, &ps, &alp, - &ind[j], dn, cor, sign, sign_val_1 ); + E_ACELP_1pulse_searchx_fx( &ipos[j], R, &ps, &alp, + &ind[j], dn, cor, sign, sign_val_1 ); } @@ -600,10 +607,10 @@ void E_ACELP_4tsearchx_fx( /* memorise the best codevector */ /*ps2 = ps * ps; MULT(1);*/ - ps2 = mult( ps, ps ); + ps2 = mult( ps, ps ); /* 2*Qdn+1 */ /*s = (alpk * ps2) - (ps2k * alp); MULT(2);ADD(1);*/ - s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); + s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); /* 2*Qdn+8 */ IF( s > 0 ) { @@ -611,7 +618,7 @@ void E_ACELP_4tsearchx_fx( move16(); alpk = alp; move16(); - Copy( ind, codvec, nb_pulse ); + Copy( ind, codvec, nb_pulse ); /* Q0 */ } } @@ -623,12 +630,12 @@ void E_ACELP_4tsearchx_fx( } void E_ACELP_4tsearchx_ivas_fx( - Word16 dn[], - const Word16 cn[], - Word16 Rw[], - Word16 code[], + Word16 dn[], /*Qdn*/ + const Word16 cn[], /*Q_new*/ + Word16 Rw[], /*Q9*/ + Word16 code[], /*Q9*/ const PulseConfig *config, - Word16 ind[], + Word16 ind[], /*Q0*/ Word16 element_mode ) { Word16 sign[L_SUBFR], vec[L_SUBFR]; @@ -670,10 +677,10 @@ void E_ACELP_4tsearchx_ivas_fx( scale = 0; move16(); - s = L_mult0( Rw[0], Rw[0] ); + s = L_mult0( Rw[0], Rw[0] ); /* Q18 */ FOR( i = 1; i < L_SUBFR; i++ ) { - s = L_mac0( s, Rw[i], Rw[i] ); + s = L_mac0( s, Rw[i], Rw[i] ); /* Q18 */ } if ( s_and( (Word16) GE_16( nb_pulse, 9 ), (Word16) GT_32( s, 0x800000 ) ) ) { @@ -716,7 +723,7 @@ void E_ACELP_4tsearchx_ivas_fx( /* Set up autocorrelation vector */ R = R_buf + L_SUBFR - 1; - Copy_Scale_sig( Rw, R, L_SUBFR, scale ); + Copy_Scale_sig( Rw, R, L_SUBFR, scale ); /* Q9 + scale */ FOR( k = 1; k < L_SUBFR; k++ ) { R[-k] = R[k]; @@ -724,13 +731,13 @@ void E_ACELP_4tsearchx_ivas_fx( } /* Sign value */ - sign_val_2 = 0x2000; + sign_val_2 = 0x2000; /* Q15 */ move16(); if ( GE_16( nb_pulse, 24 ) ) { - sign_val_2 = shr( sign_val_2, 1 ); + sign_val_2 = shr( sign_val_2, 1 ); /* Q15 */ } - sign_val_1 = shr( sign_val_2, 1 ); + sign_val_1 = shr( sign_val_2, 1 ); /* Q15 */ /* * Find sign for each pulse position. @@ -758,7 +765,7 @@ void E_ACELP_4tsearchx_ivas_fx( E_ACELP_setup_pulse_search_pos( config, k, ipos ); /* index to first non-fixed position */ - pos = config->fixedpulses; + pos = config->fixedpulses; /* Q0 */ move16(); IF( config->fixedpulses == 0 ) /* 1100, 11, 1110, 1111, 2211 */ @@ -776,23 +783,23 @@ void E_ACELP_4tsearchx_ivas_fx( /* set fixed positions */ FOR( i = 0; i < pos; ++i ) { - ind[i] = pos_max[ipos[i]]; + ind[i] = pos_max[ipos[i]]; /* Q0 */ move16(); } /* multiplication of autocorrelation with signed fixed pulses */ - E_ACELP_update_cor( ind, config->fixedpulses, sign, R, NULL, cor ); + E_ACELP_update_cor_fx( ind, config->fixedpulses, sign, R, NULL, cor ); /* normalisation contribution of fixed part */ - s = L_mult0( cor[ind[0]], sign[ind[0]] ); - ps = dn[ind[0]]; + s = L_mult0( cor[ind[0]], sign[ind[0]] ); /* Q22 */ + ps = dn[ind[0]]; /* Qdn */ move16(); FOR( i = 1; i < pos; ++i ) { - s = L_mac0( s, cor[ind[i]], sign[ind[i]] ); /*Q12+Q9+1=Q6 */ + s = L_mac0( s, cor[ind[i]], sign[ind[i]] ); /*Q12+Q9+1=Q22 */ ps = add( ps, dn[ind[i]] ); } - alp = round_fx( s ); /*mac0 >>1 sign = 2*/ + alp = round_fx( s ); /*mac0 >>1 sign = 2 Q6*/ } /* other stages of 2 pulses */ @@ -808,24 +815,24 @@ void E_ACELP_4tsearchx_ivas_fx( * Each pulse can have 16 possible positions. */ - E_ACELP_2pulse_searchx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, - &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); + E_ACELP_2pulse_searchx_fx( config->nbpos[st], ipos[j], ipos[j + 1], R, &ps, &alp, + &ind[j], &ind[j + 1], dn, dn2_pos, cor, sign, sign_val_2 ); } ELSE /* single pulse search */ { - E_ACELP_1pulse_searchx( &ipos[j], R, &ps, &alp, - &ind[j], dn, cor, sign, sign_val_1 ); + E_ACELP_1pulse_searchx_fx( &ipos[j], R, &ps, &alp, + &ind[j], dn, cor, sign, sign_val_1 ); } IF( GT_16( alp, ONE_IN_Q14 ) ) { alp = shr( alp, 1 ); - Scale_sig( cor, L_SUBFR, -1 ); - Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 ); + Scale_sig( cor, L_SUBFR, -1 ); /*Q8*/ + Scale_sig( R_buf, 2 * L_SUBFR - 1, -1 ); /*Q8+scale*/ #ifndef MSAN_FIX Scale_sig( dn, 2 * L_SUBFR, -1 ); #else - Scale_sig( dn, L_SUBFR, -1 ); + Scale_sig( dn, L_SUBFR, -1 ); /*Qdn-1*/ #endif } @@ -835,10 +842,10 @@ void E_ACELP_4tsearchx_ivas_fx( /* memorise the best codevector */ /*ps2 = ps * ps; MULT(1);*/ - ps2 = mult( ps, ps ); + ps2 = mult( ps, ps ); /* 2*Qdn+1 */ /*s = (alpk * ps2) - (ps2k * alp); MULT(2);ADD(1);*/ - s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); + s = L_msu( L_mult( alpk, ps2 ), ps2k, alp ); /* 2*Qdn+8 */ IF( s > 0 ) { @@ -848,7 +855,7 @@ void E_ACELP_4tsearchx_ivas_fx( move16(); alpk = alp; move16(); - Copy( ind, codvec, nb_pulse ); + Copy( ind, codvec, nb_pulse ); /*Q0*/ } } @@ -868,9 +875,9 @@ void E_ACELP_4tsearchx_ivas_fx( FOR( k = 0; k < config->nb_pulse; k++ ) { - i = codvec[k]; /* read pulse position */ + i = codvec[k]; /* read pulse position Q0*/ move16(); - val = sign[i]; /* read sign */ + val = sign[i]; /* read sign Q13*/ move16(); index = shr( i, 2 ); /* pos of pulse (0..15) */ @@ -878,16 +885,16 @@ void E_ACELP_4tsearchx_ivas_fx( track = s_and( i, 3 ); IF( L_mult0( val, psk ) > 0 ) { - code[i] = add( code[i], ONE_IN_Q9 /*1.0f*/ ); + code[i] = add( code[i], ONE_IN_Q9 /*1.0f*/ ); /* Q9 */ move16(); - codvec[k] = add( codvec[k], 2 * L_SUBFR ); + codvec[k] = add( codvec[k], 2 * L_SUBFR ); /* Q0 */ move16(); } ELSE { - code[i] = sub( code[i], ONE_IN_Q9 /*1.0f*/ ); + code[i] = sub( code[i], ONE_IN_Q9 /*1.0f*/ ); /* Q9 */ move16(); - index = add( index, 16 ); + index = add( index, 16 ); /* Q0 */ } i = imult1616( track, NPMAXPT ); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 5d5ee6c48af075fa34ded5aadf29b936f275607e..edc04bc832fa4f64ef737883f5d9c6ed83b0e5ef 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -18,16 +18,16 @@ *-------------------------------------------------------------------*/ void encod_amr_wb_fx( Encoder_State *st, /* i/o: state structure */ - const Word16 speech[], /* i : input speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, /* i : input speech @16kHz */ + const Word16 speech[], /* i : input speech Q_new-1*/ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + Word16 *syn, /* i/o: core synthesis st->Q_syn*/ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *exc2, /* i/o: current enhanced excitation Q_new*/ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ + const Word16 *speech16k_fx, /* i : input speech @16kHz Qx*/ Word16 shift, Word16 Q_new ) { @@ -66,6 +66,7 @@ void encod_amr_wb_fx( LPD_state_HANDLE hLPDmem = st->hLPDmem; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*------------------------------------------------------------------* @@ -84,31 +85,33 @@ void encod_amr_wb_fx( unbits = 0; move16(); - p_Aw = Aw; - p_Aq = Aq; - pt_pitch = pitch_buf; + p_Aw = Aw; /*Q12*/ + p_Aq = Aq; /*Q12*/ + pt_pitch = pitch_buf; /*Q6*/ shift_wsp = add( Q_new, shift ); - Copy( st->pitch, T_op, 2 ); + Copy( st->pitch, T_op, 2 ); /*Q0*/ if ( LE_16( T_op[0], PIT_MIN ) ) { - T_op[0] = shl( T_op[0], 1 ); + T_op[0] = shl( T_op[0], 1 ); /*Q0*/ move16(); } if ( LE_16( T_op[1], PIT_MIN ) ) { /*T_op[1] *= 2;*/ - T_op[1] = shl( T_op[1], 1 ); + T_op[1] = shl( T_op[1], 1 ); /*Q0*/ move16(); } st->acelp_cfg.fcb_mode = 0; /* flag used in inov_encode() */ + move16(); /*-----------------------------------------------------------------* * Select LP filtering flag *-----------------------------------------------------------------*/ lp_flag = NORMAL_OPERATION; + move16(); if ( LT_32( st->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; @@ -126,7 +129,7 @@ void encod_amr_wb_fx( * target in residual domain "cn" * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ - Copy( &res[i_subfr], &exc[i_subfr], L_SUBFR ); + Copy( &res[i_subfr], &exc[i_subfr], L_SUBFR ); /*Q_new*/ find_targets_fx( speech, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq, res, L_SUBFR, p_Aw, TILT_FAC_FX, xn, cn, h1 ); @@ -186,18 +189,19 @@ void encod_amr_wb_fx( gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); #ifdef BASOP_NOGLOB Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o( Lgcode, &Overflow ); -#else /* BASOP_NOGLOB */ + gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ +#else /* BASOP_NOGLOB */ Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx( Lgcode ); -#endif /* BASOP_NOGLOB */ +#endif /* BASOP_NOGLOB */ - hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); + hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); /*Q15*/ FOR( i = 0; i < L_SUBFR; i++ ) { #ifdef BASOP_NOGLOB - exc2[i + i_subfr] = round_fx_o( L_shl_o( L_mult( gain_pit, exc[i + i_subfr] ), 1, &Overflow ), &Overflow ); + exc2[i + i_subfr] = round_fx_o( L_shl_o( L_mult( gain_pit, exc[i + i_subfr] ), 1, &Overflow ), &Overflow ); /*Q_new*/ + move16(); #else /* BASOP_NOGLOB */ exc2[i + i_subfr] = round_fx( L_shl( L_mult( gain_pit, exc[i + i_subfr] ), 1 ) ); #endif /* BASOP_NOGLOB */ @@ -208,14 +212,15 @@ void encod_amr_wb_fx( *-----------------------------------------------------------------*/ /*st->mem_w0 = xn[L_SUBFR-1] - gain_pit * y1[L_SUBFR-1] - gain_code * y2[L_SUBFR-1];*/ - Ltmp = L_mult( gcode16, y2[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_mult( gcode16, y2[L_SUBFR - 1] ); /*Q10*/ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15 - shift*/ Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 ); - Ltmp = L_msu( Ltmp, y1[L_SUBFR - 1], gain_pit ); + Ltmp = L_mac( Ltmp, xn[L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_msu( Ltmp, y1[L_SUBFR - 1], gain_pit /*Q14*/ ); /* Q_new-1+shift+14+1 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new+15 */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ @@ -225,17 +230,18 @@ void encod_amr_wb_fx( *-----------------------------------------------------------------*/ FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult( gcode16, code[i] ); + L_tmp = L_mult( gcode16, code[i] ); /*Q10*/ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); + L_tmp = L_shl_sat( L_tmp, 5 ); /*Q15*/ + L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); /* Q_new+15 */ #else L_tmp = L_shl( L_tmp, 5 ); L_tmp = L_mac( L_tmp, exc[i + i_subfr], gain_pit ); #endif #ifdef BASOP_NOGLOB - L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here */ - exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q_new+15*/ + exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /*Q_new*/ + move16(); #else /* BASOP_NOGLOB */ L_tmp = L_shl( L_tmp, 1 ); /* saturation can occur here */ exc[i + i_subfr] = round_fx( L_tmp ); diff --git a/lib_enc/enc_gain_fx.c b/lib_enc/enc_gain_fx.c index 3bf3db1aa705c07972ac8d67bb437604ce668cdb..7c9606cfc24bcf592bfd1a0390ea625645414b50 100644 --- a/lib_enc/enc_gain_fx.c +++ b/lib_enc/enc_gain_fx.c @@ -14,7 +14,7 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr ); +void E_GAIN_norm_corr_fx( Word16 exc[] /*Q_new*/, Word16 xn[] /*(Q_new+shift-1)*/, Word16 h[] /*(Q14+shift)*/, Word16 t_min, Word16 t_max, Word16 corr_norm[] /*(Q15+(Q_new+shift-1)+scale)*/, Word16 L_subfr ); /* * E_GAIN_norm_corr @@ -36,7 +36,7 @@ void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word * Returns: * void */ -void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word16 t_max, Word16 corr_norm[], Word16 L_subfr ) +void E_GAIN_norm_corr_fx( Word16 exc[] /*Q_new*/, Word16 xn[] /*(Q_new+shift-1)*/, Word16 h[] /*(Q14+shift)*/, Word16 t_min, Word16 t_max, Word16 corr_norm[] /*(Q15+(Q_new+shift-1)+scale)*/, Word16 L_subfr ) { Word16 excf[L_SUBFR]; /* filtered past excitation (Q_new+shift-1) */ Word16 ps, norm, exp_alp, exp_ps, scale, L_subfr2; @@ -53,7 +53,8 @@ void E_GAIN_norm_corr( Word16 exc[], Word16 xn[], Word16 h[], Word16 t_min, Word /* Compute rounded down 1/sqrt(energy of xn[]) */ Dot_product12_offs( xn, xn, L_subfr, &scale, 1 ); - scale = add( scale, 2 + 1 ); /* energy of xn[] x 2 + rounded up */ + scale = add( scale, 2 + 1 ); /* energy of xn[] x 2 + rounded up */ + move16(); scale = negate( shr( scale, 1 ) ); /* (1< 0 ) { t0_min = add( t0_min, 1 ); + move16(); } t_min = sub( t0_min, L_INTERPOL1 ); t_max = add( t0_max, L_INTERPOL1 ); + move16(); + move16(); /* allocate memory to normalized correlation vector */ corr = &corr_v[negate( t_min )]; /* corr[t_min..t_max] */ /* Compute normalized correlation between target and filtered excitation */ - E_GAIN_norm_corr( exc, xn, h, t_min, t_max, corr_v, L_subfr ); + E_GAIN_norm_corr_fx( exc, xn, h, t_min, t_max, corr_v, L_subfr ); /* find integer pitch */ - max = corr[t0_min]; + max = corr[t0_min]; /*(Q15+(Q_new+shift-1)+scale)*/ move16(); - t0 = t0_min; + t0 = t0_min; /*Q0*/ move16(); FOR( i = t0_min + 1; i <= t0_max; i++ ) @@ -306,26 +310,28 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], IF( EQ_16( t0_min_max_res, shr( pit_res_max, 1 ) ) ) { - t0_min_frac = shl( t0_min_frac, 1 ); - t0_max_frac = shl( t0_max_frac, 1 ); + t0_min_frac = shl( t0_min_frac, 1 ); /*Q0*/ + t0_max_frac = shl( t0_max_frac, 1 ); /*Q0*/ } step = 1; - frac1 = sub( 1, pit_res_max ); - frac2 = sub( pit_res_max, 1 ); + move16(); + frac1 = sub( 1, pit_res_max ); /*Q0*/ + frac2 = sub( pit_res_max, 1 ); /*Q0*/ test(); test(); IF( ( ( i_subfr == 0 ) && GE_16( t0, pit_fr2 ) ) || LE_16( pit_fr2, pit_min ) ) { step = 2; - frac1 = sub( 2, pit_res_max ); - frac2 = sub( pit_res_max, 2 ); + move16(); + frac1 = sub( 2, pit_res_max ); /*Q0*/ + frac2 = sub( pit_res_max, 2 ); /*Q0*/ } test(); IF( ( EQ_16( t0, t0_min ) ) && ( t0_min_frac == 0 ) ) { - frac1 = t0_min_frac; + frac1 = t0_min_frac; /*Q0*/ move16(); } ELSE @@ -333,28 +339,29 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], test(); IF( ( EQ_16( t0, t0_min ) ) && ( LT_16( add( frac1, pit_res_max ), t0_min_frac ) ) ) { - frac1 = sub( t0_min_frac, pit_res_max ); + frac1 = sub( t0_min_frac, pit_res_max ); /*Q0*/ } } if ( EQ_16( t0, t0_max ) ) { - frac2 = t0_max_frac; + frac2 = t0_max_frac; /*Q0*/ move16(); } assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 ); IF( EQ_16( pit_res_max, 6 ) ) { - cor_max = E_GAIN_norm_corr_interpolate6( &corr[t0], frac1 ); - fraction = frac1; + cor_max = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ + fraction = frac1; /*Q0*/ + move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate6( &corr[t0], i ); + temp = E_GAIN_norm_corr_interpolate6_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ IF( GT_16( temp, cor_max ) ) { - cor_max = temp; + cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ move16(); fraction = i; move16(); @@ -363,15 +370,16 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], } ELSE { - cor_max = E_GAIN_norm_corr_interpolate( &corr[t0], frac1 ); - fraction = frac1; + cor_max = E_GAIN_norm_corr_interpolate_fx( &corr[t0], frac1 ); /*(Q15+(Q_new+shift-1)+scale)*/ + fraction = frac1; /*Q0*/ + move16(); FOR( i = ( frac1 + step ); i <= frac2; i += step ) { - temp = E_GAIN_norm_corr_interpolate( &corr[t0], i ); + temp = E_GAIN_norm_corr_interpolate_fx( &corr[t0], i ); /*(Q15+(Q_new+shift-1)+scale)*/ IF( GT_16( temp, cor_max ) ) { - cor_max = temp; + cor_max = temp; /*(Q15+(Q_new+shift-1)+scale)*/ move16(); fraction = i; move16(); @@ -382,23 +390,23 @@ Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /* limit the fraction value */ IF( fraction < 0 ) { - fraction = add( fraction, pit_res_max ); + fraction = add( fraction, pit_res_max ); /*Q0*/ t0 = sub( t0, 1 ); } test(); test(); IF( ( ( i_subfr == 0 ) && GE_16( t0, pit_fr2 ) ) || LE_16( pit_fr2, pit_min ) ) { - *pit_res = shr( pit_res_max, 1 ); + *pit_res = shr( pit_res_max, 1 ); /*Q0*/ move16(); - *pit_frac = shr( fraction, 1 ); + *pit_frac = shr( fraction, 1 ); /*Q0*/ move16(); } ELSE { - *pit_res = pit_res_max; + *pit_res = pit_res_max; /*Q0*/ move16(); - *pit_frac = fraction; + *pit_frac = fraction; /*Q0*/ move16(); } return ( t0 ); diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index 32d3c7a1a75fa196d987da91c2bae6119d42bb6b..243b9f0490e6d58847c2b4b4de4daf7f46733798 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -51,20 +51,20 @@ void encod_gen_voic_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + const Word16 speech_fx[], /* i : input speech Q0*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ + Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 shift, Word16 Q_new ) { @@ -77,23 +77,32 @@ void encod_gen_voic_fx( Word16 y1_fx[L_SUBFR] = { 0 }; /* Filtered adaptive excitation */ Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ Word16 gain_pit_fx = 0; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 gain_code_fx = 0; /* Gain of code */ - Word16 gain_inov_fx = 0; /* inovation gain */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ - Word16 i, i_subfr_fx; /* tmp variables */ - Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ - Word16 T0_min_fx, T0_max_fx; /* pitch variables */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain_fx; /* LSF clip gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ + move16(); + Word16 voice_fac_fx; /* Voicing factor */ + Word32 gain_code_fx = 0; /* Gain of code */ + move32(); + Word16 gain_inov_fx = 0; /* inovation gain */ + move16(); + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + Word16 i, i_subfr_fx; /* tmp variables */ + Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ + move16(); + move16(); + Word16 T0_min_fx, T0_max_fx; /* pitch variables */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain_fx; /* LSF clip gain */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + move16(); Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ Word32 norm_gain_code_fx = 0; + move16(); + move32(); Word16 pitch_limit_flag; Word16 gcode16; Word32 Ltmp; @@ -105,6 +114,7 @@ void encod_gen_voic_fx( Word16 lp_select, lp_flag, L_frame; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -148,9 +158,9 @@ void encod_gen_voic_fx( *unbits_fx = 0; move16(); - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; + p_Aw_fx = Aw_fx; /* Q12 */ + p_Aq_fx = Aq_fx; /* Q12 */ + pt_pitch_fx = pitch_buf_fx; /* Q6 */ gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -186,19 +196,19 @@ void encod_gen_voic_fx( * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ - Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); + Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ find_targets_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q(14+shift)*/ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); *pt_pitch_fx = pit_encode_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ tbe_celp_exc( L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx ); @@ -283,7 +293,7 @@ void encod_gen_voic_fx( if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) ) { /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ - st_fx->clip_var_fx[1] = gain_pit_fx; + st_fx->clip_var_fx[1] = gain_pit_fx; /*Q14*/ move16(); } } @@ -291,13 +301,14 @@ void encod_gen_voic_fx( #ifdef BASOP_NOGLOB Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o( Lgcode, &Overflow ); + gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ #else Lgcode = L_shl( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx( Lgcode ); #endif - hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); + hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */ + move16(); /*-----------------------------------------------------------------* * Transform domain contribution encoding - inactive frames @@ -315,14 +326,15 @@ void encod_gen_voic_fx( *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); + Ltmp = L_mult( gcode16, y2_fx[L_SUBFR - 1] ); /*Q10*/ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); /*Q15+shift*/ Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 ); - Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx ); + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ ); /* Q_new-1+shift+14+1 */ + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); /* Q_new-1+shift+14+1 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* 15 + Q_new */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ @@ -339,8 +351,9 @@ void encod_gen_voic_fx( Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ /* Compute exc2 */ - Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); - exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); + Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); /* Q16 */ + exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ + move16(); #else /* Contribution from AVQ layer */ Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ @@ -352,12 +365,12 @@ void encod_gen_voic_fx( #endif /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); - Ltmp = L_shl( Ltmp, 5 ); - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ + Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ #else Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ @@ -374,12 +387,12 @@ void encod_gen_voic_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, 5, &Overflow ); - Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 */ + Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); /* Q15 */ + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ #else Ltmp = L_shl( Ltmp, 5 ); Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); @@ -418,9 +431,9 @@ void encod_gen_voic_fx( IF( st_fx->Opt_SC_VBR ) { /* SC-VBR */ - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */ move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); } return; @@ -428,20 +441,20 @@ void encod_gen_voic_fx( void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + const Word16 speech_fx[], /* i : input speech Q0*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ + Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 shift, Word16 Q_new ) { @@ -454,23 +467,32 @@ void encod_gen_voic_ivas_fx( Word16 y1_fx[L_SUBFR] = { 0 }; /* Filtered adaptive excitation */ Word16 y2_fx[L_SUBFR]; /* Filtered algebraic excitation */ Word16 gain_pit_fx = 0; /* Pitch gain */ - Word16 voice_fac_fx; /* Voicing factor */ - Word32 gain_code_fx = 0; /* Gain of code */ - Word16 gain_inov_fx = 0; /* inovation gain */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ - Word16 i, i_subfr_fx; /* tmp variables */ - Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ - Word16 T0_min_fx, T0_max_fx; /* pitch variables */ - Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ - Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ - Word16 clip_gain_fx; /* LSF clip gain */ - const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ + move16(); + Word16 voice_fac_fx; /* Voicing factor */ + Word32 gain_code_fx = 0; /* Gain of code */ + Word16 gain_inov_fx = 0; /* inovation gain */ + move32(); + move16(); + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes*/ + Word16 i, i_subfr_fx; /* tmp variables */ + Word16 T0_fx = 0, T0_frac_fx = 0; /* close loop integer pitch and fractional part */ + move16(); + move16(); + Word16 T0_min_fx, T0_max_fx; /* pitch variables */ + Word16 *pt_pitch_fx; /* pointer to floating pitch buffer */ + Word16 g_corr_fx[10]; /* ACELP correl, values + gain pitch */ + Word16 clip_gain_fx; /* LSF clip gain */ + const Word16 *p_Aw_fx, *p_Aq_fx; /* pointer to LP filter coeff. vector*/ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + move16(); Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word16 unbits_PI_fx = 0; /* number of unused bits for PI */ Word32 norm_gain_code_fx = 0; + move16(); + move32(); Word16 pitch_limit_flag; Word16 gcode16; Word32 Ltmp; @@ -482,6 +504,7 @@ void encod_gen_voic_ivas_fx( Word16 lp_select, lp_flag, L_frame; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -525,9 +548,9 @@ void encod_gen_voic_ivas_fx( *unbits_fx = 0; move16(); - p_Aw_fx = Aw_fx; - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; + p_Aw_fx = Aw_fx; /*Q12*/ + p_Aq_fx = Aq_fx; /*Q12*/ + pt_pitch_fx = pitch_buf_fx; /*Q6*/ gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -563,19 +586,19 @@ void encod_gen_voic_ivas_fx( * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ - Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); + Copy( &res_fx[i_subfr_fx], &exc_fx[i_subfr_fx], L_SUBFR ); /*Q_new*/ find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr_fx, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); - Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); - Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution */ + Copy_Scale_sig( h1_fx, h2_fx, L_SUBFR, -2 ); /*Q11*/ + Scale_sig( h1_fx, L_SUBFR, add( 1, shift ) ); /* set h1[] in Q14 with scaling for convolution Q14+shift*/ /* scaling of xn[] to limit dynamic at 12 bits */ Scale_sig( xn_fx, L_SUBFR, shift ); *pt_pitch_fx = pit_encode_ivas_fx( hBstr, st_fx->acelp_cfg.pitch_bits, st_fx->core_brate, 0, L_frame, st_fx->coder_type, &pitch_limit_flag, i_subfr_fx, exc_fx, - L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); + L_SUBFR, st_fx->pitch, &T0_min_fx, &T0_max_fx, &T0_fx, &T0_frac_fx, h1_fx, xn_fx, tdm_Pitch_reuse_flag, tdm_Pri_pitch_buf ); /* Q6 */ // tbe_celp_exc(L_frame, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx); tbe_celp_exc_ivas( st_fx->element_mode, st_fx->idchan, L_frame, L_SUBFR, i_subfr_fx, T0_fx, T0_frac_fx, &error_fx, bwe_exc_fx, st_fx->tdm_LRTD_flag ); @@ -613,7 +636,8 @@ void encod_gen_voic_ivas_fx( /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ #ifdef BASOP_NOGLOB - hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ + hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /* Q14 */ + move16(); #else hSpMusClas->lowrate_pitchGain = round_fx( L_mac( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ #endif @@ -661,7 +685,7 @@ void encod_gen_voic_ivas_fx( if ( EQ_16( hSC_VBR->last_ppp_mode, 1 ) ) { /* SC-VBR - all other st->clip_var values will be updated even in a PPP frame */ - st_fx->clip_var_fx[1] = gain_pit_fx; + st_fx->clip_var_fx[1] = gain_pit_fx; /* Q14 */ move16(); } } @@ -669,13 +693,14 @@ void encod_gen_voic_ivas_fx( #ifdef BASOP_NOGLOB Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o( Lgcode, &Overflow ); + gcode16 = round_fx_o( Lgcode, &Overflow ); /* Q0 */ #else Lgcode = L_shl( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx( Lgcode ); #endif - hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); + hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */ + move16(); /*-----------------------------------------------------------------* * Transform domain contribution encoding - inactive frames @@ -693,14 +718,15 @@ void encod_gen_voic_ivas_fx( *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, shift ) ); // Q_new+14+shift + Ltmp = L_mult0( gcode16, y2_fx[L_SUBFR - 1] ); /* Q9 */ + Ltmp = L_shl( Ltmp, add( 5, shift ) ); // Q_new+14+shift Ltmp = L_negate( Ltmp ); - Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 ); // Q_new-1+15+shift - Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx ); // Q_new-1+15+shift + Ltmp = L_mac( Ltmp, xn_fx[L_SUBFR - 1], 16384 /*Q14*/ ); // Q_new-1+15+shift + Ltmp = L_msu( Ltmp, y1_fx[L_SUBFR - 1], gain_pit_fx /*Q14*/ ); // Q_new-1+15+shift #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); hLPDmem->mem_w0 = round_fx( Ltmp ); /*Q_new-1 */ @@ -717,8 +743,9 @@ void encod_gen_voic_ivas_fx( Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ /* Compute exc2 */ - Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); - exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); + Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); /* Q0 */ + exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ + move16(); #else /* Contribution from AVQ layer */ Ltmp1 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ @@ -730,12 +757,13 @@ void encod_gen_voic_ivas_fx( #endif /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); - Ltmp = L_shl( Ltmp, 5 ); - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ + Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ + move16(); #else Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ @@ -752,12 +780,12 @@ void encod_gen_voic_ivas_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, 5, &Overflow ); - Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 */ + Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); /* Q15 */ + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ #else Ltmp = L_shl( Ltmp, 5 ); Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); diff --git a/lib_enc/enc_gen_voic_rf.c b/lib_enc/enc_gen_voic_rf.c deleted file mode 100644 index 33df891b88cc405395df6c65726cdab8fcfcb354..0000000000000000000000000000000000000000 --- a/lib_enc/enc_gen_voic_rf.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "wmc_auto.h" -#include "prot_fx.h" diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index fa91460173d533b2f9c9c4c8a8fce0287500c69f..7d1aac5af606d013baa03454f41609eb5e4d025b 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -5,11 +5,9 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" #include "rom_com_fx.h" #include "stl.h" #include "rom_basop_util.h" -//#include "basop_mpy.h" #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ @@ -50,7 +48,7 @@ void reset_rf_indices_fx( hRF->rf_target_bits = 0; move16(); - hRF->rf_tcxltp_pitch_int_past = st->L_frame; + hRF->rf_tcxltp_pitch_int_past = st->L_frame; /* Q0 */ move16(); hRF->rf_last_tns_active = 0; move16(); @@ -117,18 +115,18 @@ void reset_rf_indices_fx( *-------------------------------------------------------------------*/ void coder_acelp_rf_fx( ACELP_config *acelp_cfg, /*input/output: configuration of the ACELP coding*/ - const Word16 coder_type, /* input: coding type */ - const Word16 A[], /* input: coefficients 4xAz[M+1] */ - const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] */ - Word16 speech[], /* input: speech[-M..lg] */ - const Word16 voicing[], /* input: open-loop LTP gain */ - const Word16 T_op[], /* input: open-loop LTP lag */ - Word16 stab_fac, + const Word16 coder_type, /* input: coding type Q0*/ + const Word16 A[], /* input: coefficients 4xAz[M+1] Q12*/ + const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] Q12*/ + Word16 speech[], /* input: speech[-M..lg] Q_new-1*/ + const Word16 voicing[], /* input: open-loop LTP gain Q15*/ + const Word16 T_op[], /* input: open-loop LTP lag Q0*/ + Word16 stab_fac, /* Q15 */ Encoder_State *st, - Word16 target_bits, /* i/o : coder memory state */ - const Word16 rf_frame_type, /* i : rf_frame_type */ - Word16 *exc_rf, /* i/o: pointer to RF excitation */ - Word16 *syn_rf, /* i/o: pointer to RF synthesis */ + Word16 target_bits, /* i/o : coder memory state Q0*/ + const Word16 rf_frame_type, /* i : rf_frame_type Q0*/ + Word16 *exc_rf, /* i/o: pointer to RF excitation Q_new*/ + Word16 *syn_rf, /* i/o: pointer to RF synthesis Q_new-1*/ Word16 Q_new, Word16 shift ) { @@ -169,6 +167,7 @@ void coder_acelp_rf_fx( Word16 lp_select; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif RF_ENC_HANDLE hRF = st->hRF; @@ -184,16 +183,26 @@ void coder_acelp_rf_fx( voice_fac = 0; prev_gain_pit = 0; Es_pred_rf = 0; + move32(); + move32(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + set16_fx( code, 0, L_SUBFR ); /*-----------------------------------------------------------------------* * Configure ACELP partial copy * *------------------------------------------------------------------------*/ - tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &( hRF->acelp_cfg_rf ), 0, st->nb_subfr ); + tmp2 = BITS_ALLOC_config_acelp( target_bits, rf_frame_type, &( hRF->acelp_cfg_rf ), 0, st->nb_subfr ); /* Q0 */ /* Init Framing parameters */ - L_frame = st->L_frame; - + L_frame = st->L_frame; /* Q0 */ + move16(); /*------------------------------------------------------------------------* * Initialize buffers * *------------------------------------------------------------------------*/ @@ -219,10 +228,13 @@ void coder_acelp_rf_fx( *------------------------------------------------------------------------*/ Es_pred_rf = 0; + move16(); + + test(); IF( acelp_cfg->nrg_mode > 0 && NE_16( rf_frame_type, RF_NELP ) ) { Es_pred_enc_fx( &Es_pred_rf, &hRF->rf_indx_EsPred[0], L_frame, exc_rf, voicing, - acelp_cfg->nrg_bits, acelp_cfg->nrg_mode > 1, Q_new ); + acelp_cfg->nrg_bits, extract_l( GT_16( acelp_cfg->nrg_mode, 1 ) ), Q_new ); } /*------------------------------------------------------------------------* @@ -275,7 +287,7 @@ void coder_acelp_rf_fx( Scale_sig( h1, L_SUBFR, add( 1, shift ) ); /* Q13+1-shift */ /* scaling of xn[] to limit dynamic at 12 bits */ - Scale_sig( xn, L_SUBFR, shift ); + Scale_sig( xn, L_SUBFR, shift ); /* Q_new + shift */ } @@ -290,12 +302,12 @@ void coder_acelp_rf_fx( { nelp_encoder_fx( st, exc_rf, exc_nelp, &Q_new, 0 ); } - Copy( &exc_nelp[i_subfr], exc2, L_SUBFR ); - Copy( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); + Copy( &exc_nelp[i_subfr], exc2, L_SUBFR ); /* Q_new */ + Copy( &exc_nelp[i_subfr], exc_rf, L_SUBFR ); /* Q_new */ } ELSE { - clip_gain = Mode2_gp_clip_fx( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); + clip_gain = Mode2_gp_clip_fx( voicing, i_subfr, coder_type, xn, hRF->rf_clip_var, L_SUBFR, Q_xn ); // Q0 /*-----------------------------------------------------------------* * - find unity gain pitch excitation (adaptive codebook entry) * @@ -311,7 +323,7 @@ void coder_acelp_rf_fx( IF( acelp_cfg->ltp_bits != 0 ) { - prm_rf = &hRF->rf_indx_pitch[0][nSubfr]; + prm_rf = &hRF->rf_indx_pitch[0][nSubfr]; /* Q0 */ /* Adaptive Codebook (GC and VC) */ Mode2_pit_encode_fx( acelp_cfg->ltp_mode, i_subfr, &prm_rf, &exc_rf[i_subfr], @@ -324,7 +336,7 @@ void coder_acelp_rf_fx( move16(); if ( acelp_cfg->gains_mode[i_subfr / L_SUBFR] > 0 ) { - rf_coder_type = acelp_cfg->gains_mode[i_subfr / L_SUBFR]; + rf_coder_type = acelp_cfg->gains_mode[i_subfr / L_SUBFR]; /* Q0 */ move16(); } @@ -335,7 +347,7 @@ void coder_acelp_rf_fx( if ( EQ_16( acelp_cfg->ltf_mode, NORMAL_OPERATION ) ) { - hRF->rf_indx_ltfMode[0][nSubfr] = lp_select; + hRF->rf_indx_ltfMode[0][nSubfr] = lp_select; /* Q0 */ move16(); } } @@ -402,7 +414,7 @@ void coder_acelp_rf_fx( *----------------------------------------------------------*/ IF( acelp_cfg->gains_mode[i_subfr / L_SUBFR] != 0 ) { - prm_rf = &hRF->rf_indx_gain[0][nSubfr]; + prm_rf = &hRF->rf_indx_gain[0][nSubfr]; /* Q0 */ encode_acelp_gains_fx( code, acelp_cfg->gains_mode[j_subfr], Es_pred_rf, clip_gain, &g_corr, &gain_pit, &gain_code, &prm_rf, &past_gcode, @@ -428,20 +440,20 @@ void coder_acelp_rf_fx( * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); + Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, add( 5, Q_xn ), &Overflow ); - Ltmp = L_mac_o( Ltmp, y1[L_SUBFR - 1], gain_pit, &Overflow ); + Ltmp = L_shl_o( Ltmp, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */ + Ltmp = L_mac_o( Ltmp, y1[L_SUBFR - 1], gain_pit, &Overflow ); /* Q15 + Q_xn */ #else Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit ); #endif /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); - Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); - hRF->rf_mem_w0 = sub_o( xn[L_SUBFR - 1], round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ), &Overflow ); + Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */ + Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); /* Q15 + Q_xn */ + hRF->rf_mem_w0 = sub_o( xn[L_SUBFR - 1], round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ), &Overflow ); /* Q_xn */ move16(); hRF->rf_mem_w0 = shr_o( hRF->rf_mem_w0, shift, &Overflow ); /*Qnew-1*/ #else @@ -465,11 +477,12 @@ void coder_acelp_rf_fx( FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_o( Ltmp, Q_new_p5, &Overflow ); - Ltmp = L_mac_o( Ltmp, gain_pit, exc_rf[i + i_subfr], &Overflow ); - exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); + Ltmp = L_shl_o( Ltmp, Q_new_p5, &Overflow ); /* Q15 + Q_new */ + Ltmp = L_mac_o( Ltmp, gain_pit, exc_rf[i + i_subfr], &Overflow ); /* Q15 + Q_new */ + exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); /* Q_new */ + move16(); #else Ltmp = L_shl( Ltmp, Q_new_p5 ); Ltmp = L_mac( Ltmp, gain_pit, exc_rf[i + i_subfr] ); @@ -477,12 +490,13 @@ void coder_acelp_rf_fx( exc2[i] = round_fx( L_shl( Ltmp, 1 ) ); BASOP_SATURATE_WARNING_ON_EVS #endif - Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp2 = L_shl_o( Ltmp2, Q_new_p5, &Overflow ); - Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ - exc_rf[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); + Ltmp2 = L_shl_o( Ltmp2, Q_new_p5, &Overflow ); /* Q15 + Q_new */ + Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); /* Q15 + Q_new */ + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new*/ + exc_rf[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */ + move16(); #else Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); Ltmp = L_add( Ltmp, Ltmp2 ); @@ -493,6 +507,7 @@ void coder_acelp_rf_fx( #endif } tmp2 = L_SUBFR; + move16(); } @@ -506,7 +521,8 @@ void coder_acelp_rf_fx( } } - IF( i_subfr < sub( L_frame, L_SUBFR ) || NE_16( rf_frame_type, RF_NELP ) ) + test(); + IF( LT_16( i_subfr, sub( L_frame, L_SUBFR ) ) || NE_16( rf_frame_type, RF_NELP ) ) { /*----------------------------------------------------------* @@ -524,11 +540,12 @@ void coder_acelp_rf_fx( p_Aq += ( M + 1 ); nSubfr++; - st->gain_code[j_subfr] = gain_code; + st->gain_code[j_subfr] = gain_code; /* Q16 */ j_subfr = add( j_subfr, 1 ); /* copy current gain for next subframe use, in case there is no explicit encoding */ prev_gain_pit = gain_pit; + move16(); } diff --git a/lib_enc/enc_higher_acelp.c b/lib_enc/enc_higher_acelp.c deleted file mode 100644 index a01b229ff9cdd26addc170ce3100e40a897bbc12..0000000000000000000000000000000000000000 --- a/lib_enc/enc_higher_acelp.c +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "rom_com.h" -#include "wmc_auto.h" - -/*---------------------------------------------------------------------* - * Local function prototypes - *---------------------------------------------------------------------*/ diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 13c6afb40f06a464e6b977f2fc986a5bdc266ed7..3630be38e58ed97d2c08a750cdab36562b500cf2 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -21,25 +21,25 @@ static void find_cn_fx( const Word16 xn[], const Word16 Ap[], const Word16 *p_Aq #define Q_MINUS 4 void transf_cdbk_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + Word16 cn[], /* i/o: target vector in residual domain Q_new*/ + Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ + const Word16 h1[], /* i : weighted filter input response Q15*/ + Word16 xn[], /* i/o: target vector Q_new + shift -1*/ + Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ + const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ + const Word32 gain_code, /* i : innovative excitation gain Q16*/ + Word16 g_corr[], /* o : ACELP correlation values Q15*/ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ + Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ + Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ + Word16 *unbits, /* o : number of AVQ unused bits Q0*/ const Word16 Q_new, /* i : Current frame scaling */ const Word16 shift /* i : shifting applied to y1, xn,... */ ) @@ -56,11 +56,12 @@ void transf_cdbk_enc_fx( Word16 trgtSvPos; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif avq_bit_sFlag = 0; move16(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { avq_bit_sFlag = 1; move16(); @@ -72,7 +73,7 @@ void transf_cdbk_enc_fx( Nsv = 8; move16(); - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; /* Q0 */ move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -97,10 +98,11 @@ void transf_cdbk_enc_fx( Ltmp = L_shl( Ltmp, add( 5, shift ) ); Ltmp = L_negate( Ltmp ); Ltmp = L_mac( Ltmp, xn[i], 16384 ); - Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); + Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); /* Q_new + 14 + shift */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ + x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ + move16(); #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); x_tran[i] = round_fx( Ltmp ); /*Q_new-1 */ @@ -179,7 +181,7 @@ void transf_cdbk_enc_fx( m_corr = shr( m_corr, 1 ); e_corr = add( e_corr, 1 ); } - m_corr = div_s( m_corr, m_ener ); + m_corr = div_s( m_corr, m_ener ); /* e_corr - e_ener */ e_corr = sub( e_corr, e_ener ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ @@ -203,7 +205,7 @@ void transf_cdbk_enc_fx( e_corr = sub( 14 + 4, e_den ); Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ #ifdef BASOP_NOGLOB - stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); + stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */ #else stmp = round_fx( L_shl( Ltmp, 16 ) ); #endif @@ -215,15 +217,15 @@ void transf_cdbk_enc_fx( } IF( GT_32( st_fx->core_brate, 56000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } ELSE { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } Ltmp = Mult_32_16( gain_code, stmp ); /* Q16 * Q12 - 15 -> Q13*/ #ifdef BASOP_NOGLOB @@ -238,11 +240,11 @@ void transf_cdbk_enc_fx( { IF( Es_pred < 0 ) { - Es_pred_loc = shr( negate( Es_pred ), 2 ); + Es_pred_loc = shr( negate( Es_pred ), 2 ); /* Q8 */ } ELSE { - Es_pred_loc = Es_pred; + Es_pred_loc = Es_pred; /* Q8 */ move16(); } @@ -252,9 +254,9 @@ void transf_cdbk_enc_fx( test(); IF( m_corr > 0 && m_den > 0 ) { - m_corr = div_s( 16384, m_den ); + m_corr = div_s( 16384, m_den ); /* 14 - 8 - e_den */ e_corr = sub( 14 - 8, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /* Q18 */ } ELSE { @@ -263,11 +265,11 @@ void transf_cdbk_enc_fx( test(); IF( LE_32( st_fx->core_brate, 42000 ) && GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ } ELSE { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ } Ltmp = L_mult( stmp, Es_pred_loc ); /* Q0*Q8 -> Q9*/ Ltmp = L_shl( Ltmp, add( e_den, 9 ) ); /* Q18*/ @@ -296,7 +298,7 @@ void transf_cdbk_enc_fx( AVQ_encmux_fx( st_fx->hBstr, -1, x_norm, &nBits, Nsv, nq, avq_bit_sFlag, trgtSvPos ); /* save # of AVQ unused bits for next subframe */ - *unbits = nBits; + *unbits = nBits; /* Q0 */ move16(); /* at the last subframe, write AVQ unused bits */ @@ -332,7 +334,7 @@ void transf_cdbk_enc_fx( test(); IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) { - Copy( x_tran, code_preQ, L_SUBFR ); + Copy( x_tran, code_preQ, L_SUBFR ); /* Q_AVQ_OUT_DEC */ } ELSE { @@ -404,7 +406,7 @@ void transf_cdbk_enc_fx( updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); #ifdef BASOP_NOGLOB - *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); + *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); /* Q14 */ #else *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0 ); #endif @@ -412,7 +414,7 @@ void transf_cdbk_enc_fx( test(); if ( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) { - *gain_pit = 15565; + *gain_pit = 15565; /* 0.95 in Q15 */ move16(); } updt_tar_fx( xn, xn2, y1, *gain_pit, L_SUBFR ); @@ -425,25 +427,25 @@ void transf_cdbk_enc_fx( } void transf_cdbk_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + Word16 cn[], /* i/o: target vector in residual domain Q_new*/ + Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ + const Word16 h1[], /* i : weighted filter input response Q15*/ + Word16 xn[], /* i/o: target vector Q_new + shift -1*/ + Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ + const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ + const Word32 gain_code, /* i : innovative excitation gain Q16*/ + Word16 g_corr[], /* o : ACELP correlation values Q15*/ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ + Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ + Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ + Word16 *unbits, /* o : number of AVQ unused bits Q0*/ const Word16 Q_new, /* i : Current frame scaling */ const Word16 shift /* i : shifting applied to y1, xn,... */ ) @@ -460,11 +462,12 @@ void transf_cdbk_enc_ivas_fx( Word16 trgtSvPos; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif avq_bit_sFlag = 0; move16(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { avq_bit_sFlag = 1; move16(); @@ -476,7 +479,7 @@ void transf_cdbk_enc_ivas_fx( Nsv = 8; move16(); - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[i_subfr >> 6]; /* Q0 */ move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -501,10 +504,10 @@ void transf_cdbk_enc_ivas_fx( Ltmp = L_shl( Ltmp, add( 5, shift ) ); Ltmp = L_negate( Ltmp ); Ltmp = L_mac( Ltmp, xn[i], 16384 ); - Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); + Ltmp = L_msu( Ltmp, y1[i], *gain_pit ); /* Q_new + 14 + shift */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); - x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ + x_tran[i] = round_fx_sat( Ltmp ); /*Q_new-1 */ #else Ltmp = L_shl( Ltmp, sub( 1, shift ) ); x_tran[i] = round_fx( Ltmp ); /*Q_new-1 */ @@ -575,15 +578,15 @@ void transf_cdbk_enc_ivas_fx( m_corr = extract_h( L_shl( L_corr, e_corr ) ); e_corr = sub( 30, add( e_corr, sub( Qdct, Q_AVQ_OUT ) ) ); e_ener = norm_l( L_ener ); - m_ener = extract_h( L_shl( L_ener, e_ener ) ); + m_ener = extract_h( L_shl( L_ener, e_ener ) ); /* 30 - e-ener */ e_ener = sub( 30, e_ener ); IF( GT_16( m_corr, m_ener ) ) { - m_corr = shr( m_corr, 1 ); + m_corr = shr( m_corr, 1 ); /* e_corr + 1 */ e_corr = add( e_corr, 1 ); } - m_corr = div_s( m_corr, m_ener ); + m_corr = div_s( m_corr, m_ener ); /* e_corr - e_ener */ e_corr = sub( e_corr, e_ener ); #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( m_corr, s_min( add( e_corr, 1 ), 31 ) ); /* Lgain in Q16 */ @@ -607,7 +610,7 @@ void transf_cdbk_enc_ivas_fx( e_corr = sub( 14 + 4, e_den ); Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ #ifdef BASOP_NOGLOB - stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); + stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */ #else stmp = round_fx( L_shl( Ltmp, 16 ) ); #endif @@ -619,20 +622,21 @@ void transf_cdbk_enc_ivas_fx( } IF( GT_32( st_fx->core_brate, 56000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } ELSE { - index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); + index = usquant_fx( stmp, &stmp, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1, ( 1 << G_AVQ_BITS ) ); /* Q0 */ } Ltmp = Mult_32_16( gain_code, stmp ); /* Q16 * Q12 - 15 -> Q13*/ #ifdef BASOP_NOGLOB Ltmp = L_shl_sat( Ltmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx_sat( Ltmp ); /* Q2*/ + move16(); #else Ltmp = L_shl( Ltmp, 5 ); /* Q13 -> Q18*/ *gain_preQ = round_fx( Ltmp ); /* Q2*/ @@ -658,7 +662,7 @@ void transf_cdbk_enc_ivas_fx( { m_corr = div_s( 16384, m_den ); e_corr = sub( 14 - 8, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /* Q16 */ } ELSE { @@ -667,22 +671,23 @@ void transf_cdbk_enc_ivas_fx( test(); IF( LE_32( st_fx->core_brate, 42000 ) && GT_32( st_fx->core_brate, ACELP_24k40 ) ) { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_32kbps_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ } ELSE { - index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); + index = gain_quant_fx( &Ltmp, &stmp, LG10_G_AVQ_MIN_Q14, LG10_G_AVQ_MAX_Q13, G_AVQ_BITS, &e_den ); /* Q0 */ } Ltmp = L_mult( stmp, Es_pred_loc ); /* Q0*Q8 -> Q9*/ Ltmp = L_shl( Ltmp, add( e_den, 9 ) ); /* Q18*/ *gain_preQ = round_fx( Ltmp ); /* Q2*/ + move16(); } push_indice( st_fx->hBstr, IND_AVQ_GAIN, index, G_AVQ_BITS ); /*--------------------------------------------------------------* * Encode and multiplex subvectors into bit-stream *--------------------------------------------------------------*/ - trgtSvPos = Nsv - 1; + trgtSvPos = sub( Nsv, 1 ); move16(); test(); test(); @@ -712,7 +717,8 @@ void transf_cdbk_enc_ivas_fx( { i = s_min( *unbits, 16 ); push_indice( st_fx->hBstr, IND_UNUSED, 0, i ); - *unbits -= i; + *unbits = sub( *unbits, i ); + move16(); } } @@ -736,7 +742,7 @@ void transf_cdbk_enc_ivas_fx( test(); IF( NE_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && !harm_flag_acelp ) { - Copy( x_tran, code_preQ, L_SUBFR ); + Copy( x_tran, code_preQ, L_SUBFR ); /* Q_AVQ_OUT_DEC */ } ELSE { @@ -762,7 +768,7 @@ void transf_cdbk_enc_ivas_fx( } st_fx->last_nq_preQ = nq[7]; move16(); -#if 1 // def IVAS_CODE + /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ test(); test(); @@ -771,13 +777,11 @@ void transf_cdbk_enc_ivas_fx( test(); IF( GT_16( st_fx->element_mode, EVS_MONO ) && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { - // if ( (float) abs( st->last_code_preq ) > 16.0f * (float) fabs( code_preQ[0] ) ) IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 4 ); move16(); } - // else if ( (float) abs( st->last_code_preq ) > 8.0f * (float) fabs( code_preQ[0] ) ) ELSE IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 3 ) ) ) { st_fx->mem_preemp_preQ_fx = shr( st_fx->mem_preemp_preQ_fx, 3 ); @@ -785,9 +789,9 @@ void transf_cdbk_enc_ivas_fx( } } - // st->last_code_preq = (int16_t) code_preQ[L_SUBFR - 1]; st_fx->last_code_preq = shr( code_preQ[L_SUBFR - 1], 9 ); // Q0 -#endif + move16(); + PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &( st_fx->mem_preemp_preQ_fx ) ); /*--------------------------------------------------------------* @@ -818,7 +822,8 @@ void transf_cdbk_enc_ivas_fx( updt_tar_HR_fx( xn, xn, x_tran, *gain_preQ, sub( Q_new, add( -15 + 2, Q_AVQ_OUT_DEC ) ), L_SUBFR ); #ifdef BASOP_NOGLOB - *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); + *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0, &Overflow ); /* Q14 */ + move16(); #else *gain_pit = corr_xy1_fx( xn, y1, g_corr, L_SUBFR, 0 ); #endif @@ -826,7 +831,7 @@ void transf_cdbk_enc_ivas_fx( test(); if ( EQ_16( clip_gain, 1 ) && GT_16( *gain_pit, 15565 ) ) { - *gain_pit = 15565; + *gain_pit = 15565; /* 0.95 in Q14 */ move16(); } updt_tar_fx( xn, xn2, y1, *gain_pit, L_SUBFR ); @@ -842,16 +847,16 @@ void transf_cdbk_enc_ivas_fx( *-------------------------------------------------------------------*/ static void find_cn_fx( - const Word16 xn[], /* i : target signal */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 *p_Aq, /* i : 12k8 LP coefficients */ - Word16 cn[] /* o : target signal in residual domain */ + const Word16 xn[], /* i : target signal Qx*/ + const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ + const Word16 *p_Aq, /* i : 12k8 LP coefficients Q12*/ + Word16 cn[] /* o : target signal in residual domain Qx*/ ) { Word16 tmp, tmp_fl[L_SUBFR + M]; set16_fx( tmp_fl, 0, M ); - Copy( xn, tmp_fl + M, L_SUBFR ); + Copy( xn, tmp_fl + M, L_SUBFR ); /* Qx */ tmp = 0; move16(); PREEMPH_FX( tmp_fl + M, PREEMPH_FAC_16k, L_SUBFR, &tmp ); @@ -865,12 +870,12 @@ static void find_cn_fx( /*-----------------------------------------------------------------* * Transform domain contribution encoding *-----------------------------------------------------------------*/ -Word16 gain_quant_fx( /* o: quantization index */ - Word32 *gain, /* i: quantized gain (Q16) */ - Word16 *gain16, /* o: quantized gain (expg) */ - const Word16 c_min, /* i: log10 of lower limit in Q14 */ - const Word16 c_max, /* i: log10 of upper limit in Q13 */ - const Word16 bits, /* i: number of bits to quantize */ +Word16 gain_quant_fx( /* o: quantization index Q0*/ + Word32 *gain, /* i: quantized gain Q16*/ + Word16 *gain16, /* o: quantized gain expg*/ + const Word16 c_min, /* i: log10 of lower limit in Q14*/ + const Word16 c_max, /* i: log10 of upper limit in Q13*/ + const Word16 bits, /* i: number of bits to quantize Q0*/ Word16 *expg /* o: output exponent of gain16 */ ) { @@ -913,15 +918,15 @@ Word16 gain_quant_fx( /* o: quantization index IF( tmp1 != 0 ) { exp = norm_s( tmp1 ); - frac = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(15-exp)*/ - L_tmp = L_mult( tmp2, frac ); /*Q(30-exp)*/ - L_tmp = Mult_32_16( L_tmp, sub( levels, 1 ) ); /*Q(15-exp)*/ - index = extract_l( L_shr( L_add( L_tmp, shr( 1 << 14, exp ) ), sub( 15, exp ) ) ); + frac = div_s( shl( 1, sub( 14, exp ) ), tmp1 ); /*Q(15-exp)*/ + L_tmp = L_mult( tmp2, frac ); /*Q(30-exp)*/ + L_tmp = Mult_32_16( L_tmp, sub( levels, 1 ) ); /*Q(15-exp)*/ + index = extract_l( L_shr( L_add( L_tmp, shr( 1 << 14, exp ) ), sub( 15, exp ) ) ); /* Q0 */ } ELSE { - L_tmp = L_mult( tmp2, sub( levels, 1 ) ); /*Q15*/ - index = extract_l( L_shr( L_add( L_tmp, 1 << 14 ), 15 ) ); + L_tmp = L_mult( tmp2, sub( levels, 1 ) ); /*Q15*/ + index = extract_l( L_shr( L_add( L_tmp, 1 << 14 ), 15 ) ); /* Q0 */ } index = s_max( index, 0 ); diff --git a/lib_enc/enc_uv.c b/lib_enc/enc_uv.c deleted file mode 100644 index ccdf49ed34f76e6fc8e0305d1de54cbdde0ce8fa..0000000000000000000000000000000000000000 --- a/lib_enc/enc_uv.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include -#include "options.h" -#include -#include "cnst.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/enc_uv_fx.c b/lib_enc/enc_uv_fx.c index bbe16cea2c377fddd0209da2821cb6dfea5e2dc9..d2d8c95706f3d41e3a1c8f45f1326493003664d2 100644 --- a/lib_enc/enc_uv_fx.c +++ b/lib_enc/enc_uv_fx.c @@ -18,18 +18,18 @@ /*fixed point implementation of unvoiced_encoder*/ void encod_unvoiced_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 *speech_fx, /* i : Input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* o : core synthesis Q_new*/ + Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ const Word16 Q_new, const Word16 shift ) { @@ -91,7 +91,7 @@ void encod_unvoiced_fx( * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ i_subfr_idx = shr( i_subfr, 6 ); - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); + Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); @@ -108,7 +108,7 @@ void encod_unvoiced_fx( { *pt_pitch_fx = gaus_encode_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */ } ELSE { @@ -148,7 +148,7 @@ void encod_unvoiced_fx( *----------------------------------------------------------*/ index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); + st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */ #ifdef DEBUGGING assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); @@ -175,14 +175,14 @@ void encod_unvoiced_fx( * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); - Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); + Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */ + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); /* Q15 + Q_xn */ + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Q15 + Q_xn */ /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); - Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); - Ltmp = L_add( Ltmp, Ltmp2 ); - hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */ + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); /* Q15 + Q_xn */ + Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_xn */ + hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); /* Q_xn */ move16(); BASOP_SATURATE_WARNING_OFF_EVS; #ifdef BASOP_NOGLOB @@ -202,15 +202,15 @@ void encod_unvoiced_fx( FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); - Ltmp = L_shl( Ltmp, Q_new_p5 ); - Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); - Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); - Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); - Ltmp = L_add( Ltmp, Ltmp2 ); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ + Ltmp = L_shl( Ltmp, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q_new + Q15 */ + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */ + Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_add( Ltmp, Ltmp2 ); /* Q15 + Q_new */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ + exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ #else BASOP_SATURATE_WARNING_OFF_EVS Ltmp = L_shl( Ltmp, 1 ); /* saturation can occur here */ @@ -223,7 +223,7 @@ void encod_unvoiced_fx( } } - *tmp_noise_fx = extract_h( norm_gain_code_fx ); + *tmp_noise_fx = extract_h( norm_gain_code_fx ); /* Q0 */ voice_factors_fx[i_subfr / L_SUBFR] = 0; move16(); @@ -241,9 +241,9 @@ void encod_unvoiced_fx( } /* SC-VBR */ - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */ move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); return; @@ -251,18 +251,18 @@ void encod_unvoiced_fx( void encod_unvoiced_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 *speech_fx, /* i : Input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* o : core synthesis Q_new*/ + Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ const Word16 Q_new, const Word16 shift ) { @@ -325,7 +325,7 @@ void encod_unvoiced_ivas_fx( * Compute impulse response, h1[], of weighted synthesis filter *----------------------------------------------------------------*/ i_subfr_idx = shr( i_subfr, 6 ); - Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); + Copy( &res_fx[i_subfr], &exc_fx[i_subfr], L_SUBFR ); /* Q_new */ find_targets_ivas_fx( speech_fx, hLPDmem->mem_syn, i_subfr, &hLPDmem->mem_w0, p_Aq_fx, res_fx, L_SUBFR, p_Aw_fx, st_fx->preemph_fac, xn_fx, cn_fx, h1_fx ); @@ -342,7 +342,7 @@ void encod_unvoiced_ivas_fx( { *pt_pitch_fx = gaus_encode_ivas_fx( st_fx, i_subfr, h1_fx, xn_fx, exc_fx, &hLPDmem->mem_w0, st_fx->clip_var_fx, &hLPDmem->tilt_code, code_fx, &L_gain_code_fx, y2_fx, &gain_inov_fx, - &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); + &voice_fac_fx, &gain_pit_fx, Q_new, shift, &norm_gain_code_fx ); /* Q0 */ move16(); } ELSE @@ -390,7 +390,7 @@ void encod_unvoiced_ivas_fx( *----------------------------------------------------------*/ index = gain_enc_uv_fx( code_fx, code2, L_SUBFR, &gain_pit_fx, &L_gain_code_fx, &gain_code2, - st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); + st_fx->flag_noisy_speech_snr, &g_corr, Es_pred, &norm_gain_code_fx, &gain_inov_fx, FUNC_GAIN_ENC_GACELP_UV ); /* Q0 */ #ifdef DEBUGGING assert( st_fx->acelp_cfg.gains_mode[i_subfr_idx] == 7 && "Error: UC two-stage, only 5+2 gain Q is supported" ); @@ -418,13 +418,13 @@ void encod_unvoiced_ivas_fx( * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); - Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); // Qxn+15 - Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); + Ltmp = Mpy_32_16_1( L_gain_code_fx, y2_fx[L_SUBFR - 1] ); /* Q10 */ + Ltmp = L_shl( Ltmp, add( 5, Q_xn ) ); // Qxn+15 + Ltmp = L_mac( Ltmp, y1[L_SUBFR - 1], gain_pit_fx ); /* Qxn + Q15 */ /* Add Gaussian contribution*/ - Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); - Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15 - Ltmp = L_add( Ltmp, Ltmp2 ); + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */ + Ltmp2 = L_shl( Ltmp2, add( 5, Q_xn ) ); // Q_xn+15 + Ltmp = L_add( Ltmp, Ltmp2 ); /* Qxn + Q15 */ hLPDmem->mem_w0 = sub( xn_fx[L_SUBFR - 1], round_fx( L_shl( Ltmp, 1 ) ) ); // Q_xn move16(); BASOP_SATURATE_WARNING_OFF_EVS; @@ -446,20 +446,20 @@ void encod_unvoiced_ivas_fx( FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp = L_shl_sat( Ltmp, Q_new_p5 ); - Ltmp = L_mac_sat( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); + Ltmp = L_shl_sat( Ltmp, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_mac_sat( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); /* Q15 + Q_new */ #else Ltmp = L_shl( Ltmp, Q_new_p5 ); Ltmp = L_mac( Ltmp, gain_pit_fx, exc_fx[i + i_subfr] ); #endif - Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code_fx[i] ); /* Q10 */ #ifdef BASOP_NOGLOB - Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); - Ltmp = L_add_sat( Ltmp, Ltmp2 ); - Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); + Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ + exc_fx[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ #else BASOP_SATURATE_WARNING_OFF_EVS Ltmp2 = L_shl( Ltmp2, Q_new_p5 ); @@ -496,9 +496,9 @@ void encod_unvoiced_ivas_fx( /* SC-VBR */ IF( hSC_VBR ) { - hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; + hSC_VBR->prev_ppp_gain_pit_fx = gain_pit_fx; /* Q14 */ move16(); - hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; + hSC_VBR->prev_tilt_code_fx = hLPDmem->tilt_code; /* Q15 */ move16(); } diff --git a/lib_enc/energy.c b/lib_enc/energy.c deleted file mode 100644 index 59a3eb11a82f687754109ba17252b6dfe625aca8..0000000000000000000000000000000000000000 --- a/lib_enc/energy.c +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "prot.h" -#include "cnst.h" -#include "rom_enc.h" -#include "wmc_auto.h" diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 054245a6d288b432c1c5b5107d52f713ce9ed4d6..e645395f1aabcce56c261b367d4be78c82e7204a 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -17,18 +17,18 @@ * *-------------------------------------------------------------------*/ void est_energy_fx( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ - Word16 enerBuffer_exp, /* i : exponent of energy vector */ - Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /* o : frame energy 2*/ - Word32 *HB_Power_p, /* o : high frequency energy*/ - Word32 *frame_energy_p, /* o : frame energy 1*/ - Word16 *sb_power_Q, /* o : the scaling of sb_power*/ - Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ - Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ - Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ - const Word32 bandwidth /* i : band width*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band enerBuffer_exp*/ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly frame_sb_energy_scale*/ + Word32 *frame_energy2_p, /* o : frame energy 2 frame_energy2_Q*/ + Word32 *HB_Power_p, /* o : high frequency energy HB_Power_Q*/ + Word32 *frame_energy_p, /* o : frame energy 1 frame_energy_Q*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power */ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy */ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power */ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy */ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[] */ + const Word32 bandwidth /* i : band width Q0*/ ) { Word32 i, j; @@ -56,13 +56,13 @@ void est_energy_fx( BandNum = BAND_NUM_TAB[bandwidth]; move16(); - frame_energy2 = L_shr( sb_power[1], shr_tmp ); - HB_Power = L_shr( sb_power[6], shr_tmp ); + frame_energy2 = L_shr( sb_power[1], shr_tmp ); /* 31 - enerBuffer_exp - shr_tmp */ + HB_Power = L_shr( sb_power[6], shr_tmp ); /* 31 - enerBuffer_exp - shr_tmp */ FOR( i = 2; i < BandNum; i++ ) { - Ltmp32 = L_shr( sb_power[i], shr_tmp ); + Ltmp32 = L_shr( sb_power[i], shr_tmp ); /* 31 - enerBuffer_exp - shr_tmp */ #ifdef BASOP_NOGLOB - frame_energy2 = L_add_sat( frame_energy2, Ltmp32 ); + frame_energy2 = L_add_sat( frame_energy2, Ltmp32 ); /* 31 - enerBuffer_exp - shr_tmp */ if ( i > 6 ) HB_Power = L_add_sat( HB_Power, Ltmp32 ); #else @@ -71,29 +71,29 @@ void est_energy_fx( HB_Power = L_add( HB_Power, Ltmp32 ); #endif } - frame_energy2 = L_sub( frame_energy2, Ltmp32 ); + frame_energy2 = L_sub( frame_energy2, Ltmp32 ); /* 31 - enerBuffer_exp - shr_tmp */ - sb_power_tmp = L_shr( sb_power[0], shr_tmp ); + sb_power_tmp = L_shr( sb_power[0], shr_tmp ); /* 31 - enerBuffer_exp - shr_tmp */ IF( EQ_32( bandwidth, 1 ) ) { - frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x147a ) ); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x147a /* 0.16 in Q15 */ ) ); } ELSE IF( EQ_32( bandwidth, 2 ) ) { - frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x1eb8 ) ); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x1eb8 /* 0.24 in Q15 */ ) ); } ELSE IF( EQ_32( bandwidth, 3 ) ) { - frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 /* 0.28 in Q15 */ ) ); } ELSE IF( EQ_32( bandwidth, 4 ) ) { - frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 /* 0.28 in Q15 */ ) ); } ELSE { - frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 ) ); + frame_energy = L_add( frame_energy2, MUL_F( sb_power_tmp, 0x23d7 /* 0.28 in Q15 */ ) ); } *frame_energy2_p = frame_energy2; @@ -115,7 +115,7 @@ void est_energy_fx( FOR( i = 0; i < 6; i++ ) { - frame_sb_energy[i] = sb_power[i]; + frame_sb_energy[i] = sb_power[i]; /* sb_power_Q */ move32(); } @@ -123,17 +123,17 @@ void est_energy_fx( { s32CopyPower = 0; move32(); - widthsb = sub( Nregion_index[i + 1], Nregion_index[i] ); + widthsb = sub( Nregion_index[i + 1], Nregion_index[i] ); /* Q0 */ s16MaxCoefNorm = sub( ffr_getSfWord32( ( sb_power + Nregion_index[i] ), widthsb ), NREGION_PREOFF[i] ); FOR( j = Nregion_index[i]; j < Nregion_index[i + 1]; j++ ) { - tmpspec_amp = L_shl( sb_power[j], s16MaxCoefNorm ); + tmpspec_amp = L_shl( sb_power[j], s16MaxCoefNorm ); /* sb_power_Q + s16MaxCoefNorm */ s32CopyPower = L_add( s32CopyPower, tmpspec_amp ); } #ifdef BASOP_NOGLOB - frame_sb_energy[i] = L_shr_o( s32CopyPower, s16MaxCoefNorm, &Overflow ); -#else /* BASOP_NOGLOB */ + frame_sb_energy[i] = L_shr_o( s32CopyPower, s16MaxCoefNorm, &Overflow ); /* sb_power_Q */ +#else /* BASOP_NOGLOB */ frame_sb_energy[i] = L_shr( s32CopyPower, s16MaxCoefNorm ); #endif move32(); @@ -180,28 +180,29 @@ static void NormEnergyWord32( * *-------------------------------------------------------------------*/ static void update_sb_bg_energy( - Word32 *sb_bg_energy, - Word16 *tbg_energy_count, + Word32 *sb_bg_energy, /* p_scale_sb_energy */ + Word16 *tbg_energy_count, /* Q0 */ Word16 *p_scale_sb_energy, - const Word32 SNR_sb_num, - const Word32 *frame_sb_energy, + const Word32 SNR_sb_num, /* Q0 */ + const Word32 *frame_sb_energy, /* frame_sb_energy_scale */ const Word16 frame_sb_energy_scale, - const Word16 FAC_16Q15_a, + const Word16 FAC_16Q15_a, /* Q15 */ const Word16 tmp_Q_add, - const Word16 FAC_16Q19_b ) + const Word16 FAC_16Q19_b /* Q19 */ +) { Word32 sb_bg_energy_ti, tmp; Word16 tmpQ, i; - *tbg_energy_count = add( *tbg_energy_count, 1 ); + *tbg_energy_count = add( *tbg_energy_count, 1 ); /* Q0 */ move16(); tmpQ = add( tmp_Q_add, frame_sb_energy_scale ); FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F( sb_bg_energy[i], FAC_16Q15_a ); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], FAC_16Q15_a ); /* p_scale_sb_energy */ tmp = MUL_F( frame_sb_energy[i], FAC_16Q19_b ); - sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); /* p_scale_sb_energy */ move32(); } } @@ -212,12 +213,13 @@ static void update_sb_bg_energy( * *-------------------------------------------------------------------*/ void background_update_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ - Word32 snr ) + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy */ + Word32 frame_energy, /* i : current frame energy scale*/ + Word32 update_flag, /* i : update flag Q0*/ + Word16 music_backgound_f, /* i : background music flag Q0*/ + Word32 snr /* Q25 */ +) { Word32 tmp; Word16 i, tmpQ, cmp_lt_frame, cmp_pre_frame; @@ -279,12 +281,13 @@ void background_update_fx( test(); test(); test(); - IF( ( LT_16( hVAD_CLDFB->frameloop, 60 ) ) && ( GT_16( hVAD_CLDFB->frameloop, 5 ) ) && ( LT_16( f_tonality_rate[0], 9174 /* 0.56 Q14 */ ) ) && ( LT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) && ( LT_16( ltd_stable_rate[1], 1966 /* 0.06 Q15 */ ) ) && LT_32( snr, 83886080 ) ) + IF( ( LT_16( hVAD_CLDFB->frameloop, 60 ) ) && ( GT_16( hVAD_CLDFB->frameloop, 5 ) ) && ( LT_16( f_tonality_rate[0], 9174 /* 0.56 Q14 */ ) ) && ( LT_16( f_tonality_rate[1], 8192 /* 0.5 Q14 */ ) ) && ( LT_16( ltd_stable_rate[1], 1966 /* 0.06 Q15 */ ) ) && LT_32( snr, 83886080 /* 2.5f in Q25 */ ) ) { IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); /* exp(divout) */ exp_frame_energy_amendment.s16Exp = q_divout; + move16(); t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE @@ -303,8 +306,9 @@ void background_update_fx( { IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); /* exp(q_divout) */ exp_frame_energy_amendment.s16Exp = q_divout; + move16(); t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE @@ -314,7 +318,8 @@ void background_update_fx( update_sb_bg_energy( sb_bg_energy, &hVAD_CLDFB->tbg_energy_count, p_scale_sb_energy, SNR_sb_num, frame_sb_energy, hVAD_CLDFB->frame_sb_energy_scale, 31456 /* 0.96 Q15 */, 4, 20971 /* 0.04 Q19 */ ); - hVAD_CLDFB->bg_update_count = add( hVAD_CLDFB->bg_update_count, 1 ); + hVAD_CLDFB->bg_update_count = add( hVAD_CLDFB->bg_update_count, 1 ); /* Q0 */ + move16(); } ELSE { @@ -329,9 +334,9 @@ void background_update_fx( tmpQ = add( 9, hVAD_CLDFB->frame_sb_energy_scale ); FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); /* p_scale_sb_energy */ tmp = MUL_F( frame_sb_energy[i], 16777 /* 0.001 Q24 */ ); - sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); /* p_scale_sb_energy */ move32(); } } @@ -340,8 +345,9 @@ void background_update_fx( { IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); /* exp(q_divout) */ exp_frame_energy_amendment.s16Exp = q_divout; + move16(); t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE @@ -358,8 +364,9 @@ void background_update_fx( { IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); /* exp(q_divout) */ exp_frame_energy_amendment.s16Exp = q_divout; + move16(); t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } ELSE @@ -373,7 +380,7 @@ void background_update_fx( { IF( LT_16( hVAD_CLDFB->frameloop, 50 ) ) { - exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); + exp_frame_energy_amendment.s32Mantissa = VAD_L_div( exp_frame_energy.s32Mantissa, 10, exp_frame_energy.s16Exp, 0, &q_divout ); /* exp(q_divout) */ exp_frame_energy_amendment.s16Exp = q_divout; t_bg_energy_sum = VAD_AddExp( t_bg_energy_sum, exp_frame_energy_amendment ); } @@ -390,7 +397,7 @@ void background_update_fx( ELSE { cmp_pre_frame = VAD_L_CMP( t_bg_energy, hVAD_CLDFB->scale_t_bg_energy, MUL_F( exp_frame_energy.s32Mantissa, 32000 ), sub( exp_frame_energy.s16Exp, 9 ) ); - cmp_lt_frame = VAD_L_CMP( sb_bg_energy[0], scale_sb_energy, MUL_F( frame_sb_energy[0], 20480 ), sub( hVAD_CLDFB->frame_sb_energy_scale, 4 ) ); + cmp_lt_frame = VAD_L_CMP( sb_bg_energy[0], scale_sb_energy, MUL_F( frame_sb_energy[0], 20480 /* 10 in Q11 */ ), sub( hVAD_CLDFB->frame_sb_energy_scale, 4 ) ); test(); IF( ( cmp_pre_frame > 0 ) && ( cmp_lt_frame > 0 ) ) @@ -398,9 +405,9 @@ void background_update_fx( tmpQ = add( 3, hVAD_CLDFB->frame_sb_energy_scale ); FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 29490 /* 0.90 Q15 */ ); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 29490 /* 0.90 Q15 */ ); /* p_scale_sb_energy */ tmp = MUL_F( frame_sb_energy[i], 26214 /* 0.10 Q18 */ ); - sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); /* p_scale_sb_energy */ move32(); } } @@ -412,16 +419,16 @@ void background_update_fx( tmpQ = add( 9, hVAD_CLDFB->frame_sb_energy_scale ); FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); + sb_bg_energy_ti = MUL_F( sb_bg_energy[i], 32734 /* 0.999 Q15 */ ); /* exp(p_scale_sb_energy) */ tmp = MUL_F( frame_sb_energy[i], 16777 /* 0.001 Q24 */ ); - sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); + sb_bg_energy[i] = VAD_L_ADD( sb_bg_energy_ti, p_scale_sb_energy[i], tmp, tmpQ, &p_scale_sb_energy[i] ); /* exp(p_scale_sb_energy) */ move32(); } } } } - tmp = L_mult0( 160, (Word16) hVAD_CLDFB->tbg_energy_count ); + tmp = L_mult0( 160, (Word16) hVAD_CLDFB->tbg_energy_count ); /* Q31 */ cmp_pre_frame = VAD_L_CMP( t_bg_energy_sum.s32Mantissa, t_bg_energy_sum.s16Exp, tmp, 0 ); IF( cmp_pre_frame > 0 ) { @@ -438,10 +445,10 @@ void background_update_fx( test(); IF( ( EQ_16( music_backgound_f, 1 ) ) && ( LT_32( hVAD_CLDFB->lt_snr_org, 107374179 /* 3.2 Q25 */ ) ) && ( cmp_pre_frame > 0 ) && update_flag == 0 ) { - tmp = L_shr( 2147 /* 0.000001 Q31 */, sub( 31, scale_sb_energy ) ); + tmp = L_shr( 2147 /* 0.000001 Q31 */, sub( 31, scale_sb_energy ) ); /* scale_sb_energy */ FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy[i] = L_add( MUL_F( sb_bg_energy[i], 32112 /* 0.98 Q15 */ ), tmp ); + sb_bg_energy[i] = L_add( MUL_F( sb_bg_energy[i], 32112 /* 0.98 Q15 */ ), tmp ); /* scale_sb_energy */ move32(); } } @@ -451,10 +458,10 @@ void background_update_fx( cmp_pre_frame = VAD_L_CMP( exp_frame_energy.s32Mantissa, exp_frame_energy.s16Exp, MUL_F( t_bg_energy, 5000 ), sub( hVAD_CLDFB->scale_t_bg_energy, 15 ) ); IF( cmp_pre_frame < 0 ) { - tmp = L_shr( 2147 /* 0.000001 Q31 */, sub( 31, scale_sb_energy ) ); + tmp = L_shr( 2147 /* 0.000001 Q31 */, sub( 31, scale_sb_energy ) ); /* scale_sb_energy */ FOR( i = 0; i < SNR_sb_num; i++ ) { - sb_bg_energy[i] = L_add( MUL_F( sb_bg_energy[i], 32112 /* 0.98 Q15 */ ), tmp ); + sb_bg_energy[i] = L_add( MUL_F( sb_bg_energy[i], 32112 /* 0.98 Q15 */ ), tmp ); /* scale_sb_energy */ move32(); } } @@ -467,7 +474,7 @@ void background_update_fx( t_bg_energy_sum.s32Mantissa = MUL_F( t_bg_energy_sum.s32Mantissa, 24575 /* 0.75 Q15 */ ); } - t_bg_energy = VAD_L_div( t_bg_energy_sum.s32Mantissa, hVAD_CLDFB->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout ); + t_bg_energy = VAD_L_div( t_bg_energy_sum.s32Mantissa, hVAD_CLDFB->tbg_energy_count, t_bg_energy_sum.s16Exp, 0, &q_divout ); /* exp(q_divout) */ hVAD_CLDFB->scale_t_bg_energy = q_divout; move16(); hVAD_CLDFB->t_bg_energy = t_bg_energy; diff --git a/lib_enc/eval_pit_contr.c b/lib_enc/eval_pit_contr.c deleted file mode 100644 index d441f6ead49ddcb3a6a1ffab0962633db8157cd0..0000000000000000000000000000000000000000 --- a/lib_enc/eval_pit_contr.c +++ /dev/null @@ -1,43 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "wmc_auto.h" diff --git a/lib_enc/eval_pit_contr_fx.c b/lib_enc/eval_pit_contr_fx.c index a438b79a69d7c00f4014be221038ba6ef65b1921..e49463a5cf1a9eccf19b817a54d636bf68ca46c3 100644 --- a/lib_enc/eval_pit_contr_fx.c +++ b/lib_enc/eval_pit_contr_fx.c @@ -51,11 +51,11 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ + const Word16 *dct_res, /* i : DCT of residual Qnew*/ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ + Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ) { @@ -80,6 +80,8 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + move16(); + move16(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { @@ -115,8 +117,8 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit FOR( j = 0; j < mfreq_bindiv_loc[i]; j++ ) /* up to maximum allowed voiced critical band */ { - tmp_ex = mult_r( dct_pitex[j + freq], 8192 ); - tmp_res = mult_r( dct_res[j + freq], 8192 ); + tmp_ex = mult_r( dct_pitex[j + freq], 8192 /* 0.25 in Q15 */ ); + tmp_res = mult_r( dct_res[j + freq], 8192 /* 0.25 in Q15 */ ); corr_tmp = L_mac0( corr_tmp, tmp_res, tmp_ex ); /*2*Qnew*/ ener_res = L_mac0( ener_res, tmp_res, tmp_res ); /*2*Qnew*/ ener_pit = L_mac0( ener_pit, tmp_ex, tmp_ex ); /*2*Qnew*/ @@ -145,10 +147,10 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */ { - L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); - L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); + L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q30 */ + L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q30 */ - tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); + tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q30 */ tmp = s_max( tmp, val_thrs ); corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); @@ -176,7 +178,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { /*av_corr *= 1.25f;*/ - av_corr = add( av_corr, shr( av_corr, 2 ) ); + av_corr = add( av_corr, shr( av_corr, 2 ) ); /* Q2 */ } test(); if ( GE_16( st_fx->GSC_IVAS_mode, 1 ) || LT_32( st_fx->core_brate, ACELP_9k60 ) ) @@ -193,7 +195,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit { last_pit_band = i; move16(); - min_corr = ftmp; + min_corr = ftmp; /* Q2 */ move16(); } } @@ -315,13 +317,13 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit { last_pit_band = add( BAND1k2, 1 ); } - last_pit_bin = mfreq_loc_div_25[last_pit_band]; + last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q0 */ move16(); st_fx->bpf_off = 0; move16(); - max_len = sub( st_fx->L_frame, last_pit_bin ); + max_len = sub( st_fx->L_frame, last_pit_bin ); /* Q0 */ if ( EQ_16( st_fx->bwidth, NB ) ) { @@ -350,7 +352,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit FOR( i = 0; i < Len; i++ ) { - dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); + dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */ } FOR( ; i < max_len; i++ ) { @@ -358,7 +360,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit move16(); } } - hGSCEnc->mem_last_pit_band = last_pit_band; + hGSCEnc->mem_last_pit_band = last_pit_band; /* Q0 */ move16(); pit_contr_idx = sub( last_pit_band, BAND1k2 ); } @@ -383,7 +385,7 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit #ifndef IVAS_CODE_BITSTREAM IF( hBstr->ind_list[i].nb_bits != -1 ) { - hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[i].nb_bits ); /* Q0 */ hBstr->ind_list[i].nb_bits = -1; move16(); } @@ -395,7 +397,8 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit #ifndef IVAS_CODE_BITSTREAM IF( hBstr->ind_list[IND_ES_PRED].nb_bits != -1 ) { - hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); + hBstr->nb_bits_tot = sub( hBstr->nb_bits_tot, hBstr->ind_list[IND_ES_PRED].nb_bits ); /* Q0 */ + move16(); hBstr->ind_list[IND_ES_PRED].nb_bits = -1; move16(); } @@ -434,11 +437,11 @@ Word16 Pit_exc_contribution_len_fx( /* o : bin where pit Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ + const Word16 *dct_res, /* i : DCT of residual Q_new*/ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution Q_new*/ + Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ) { @@ -463,6 +466,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; + move16(); if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { @@ -521,33 +525,33 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher move16(); /* 0.5 in Q14*/ /* Smooth the inter-correlation value and skip the last band for the average (since last band is almost always 0)*/ tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[0] ), ALPAM1_FX, corr_dct_pit[1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); + tmp = s_max( tmp, val_thrs ); /*Qnew */ - corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); + corr_dct_pit_tmp[0] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ move16(); FOR( i = 1; i < Mbands_loc - 1; i++ ) /* up to maximum allowed voiced critical band */ { - L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); - L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); + L_tmp = L_mult( BETA_FX, corr_dct_pit[i - 1] ); /* Q_new + 16 */ + L_tmp = L_mac( L_tmp, BETA_FX, corr_dct_pit[i + 1] ); /* Q_new + 16 */ - tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); - tmp = s_max( tmp, val_thrs ); + tmp = mac_r( L_tmp, ALPA_FX, corr_dct_pit[i] ); /* Q_new */ + tmp = s_max( tmp, val_thrs ); /* Q_new */ - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); + corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ move16(); } tmp = mac_r( L_mult( ALPA_FX, corr_dct_pit[i] ), ALPAM1_FX, corr_dct_pit[i - 1] ); /*Qnew*/ - tmp = s_max( tmp, val_thrs ); - corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); + tmp = s_max( tmp, val_thrs ); /* Q_new */ + corr_dct_pit_tmp[i] = shl( sub( tmp, val_thrs ), 1 ); /* Q_new + 1 */ move16(); - Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); + Copy( corr_dct_pit_tmp, corr_dct_pit, Mbands_loc ); /* Q_new + 1 */ L_tmp1 = L_mult( DIV_NB_VOIC_FX, corr_dct_pit[0] ); /*Qnew*/ FOR( i = 1; i < NB_VOIC_FX; i++ ) /* up to maximum allowed voiced critical band */ { - L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); + L_tmp1 = L_mac( L_tmp1, DIV_NB_VOIC_FX, corr_dct_pit[i] ); /* Q_new + 16 */ } av_corr = round_fx( L_tmp1 ); /*Qnew*/ @@ -652,7 +656,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher move16(); } - ( *hangover ) = sub( ( *hangover ), 1 ); + ( *hangover ) = sub( ( *hangover ), 1 ); /* Q0 */ if ( *hangover < 0 ) { *hangover = 0; @@ -678,7 +682,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher test(); test(); /*if(st_fx->core_brate core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 ) ) + IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 4096 /* 64 in Q6 */ ) ) { last_pit_band = add( 9, BAND1k2 ); if ( EQ_16( st_fx->bwidth, NB ) ) @@ -686,7 +690,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher last_pit_band = add( 7, BAND1k2 ); } } - ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 ) ) + ELSE IF( LT_32( st_fx->core_brate, ACELP_9k60 ) && LT_16( low_pit, 8192 /* 128 in Q6 */ ) ) { last_pit_band = add( 5, BAND1k2 ); } @@ -698,7 +702,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher { last_pit_band = add( BAND1k2, 1 ); } - last_pit_bin = mfreq_loc_div_25[last_pit_band]; + last_pit_bin = mfreq_loc_div_25[last_pit_band]; /* Q15 */ move16(); st_fx->bpf_off = 0; @@ -733,7 +737,7 @@ Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin wher FOR( i = 0; i < Len; i++ ) { - dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); + dct_pitex[i + last_pit_bin] = mult_r( dct_pitex[i + last_pit_bin], sm_table_fx[i] ); /* Q_new */ } FOR( ; i < max_len; i++ ) { diff --git a/lib_enc/evs_enc.c b/lib_enc/evs_enc.c deleted file mode 100644 index d4fe802221847d9ecedad7d46d88d7aeb2f2d099..0000000000000000000000000000000000000000 --- a/lib_enc/evs_enc.c +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#include -#include "options.h" -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "wmc_auto.h" -#include "ivas_prot_fx.h" -#include "prot_fx.h" -#include "prot_fx_enc.h" diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 787eb6c68f8cf45fef04ca67e6b8eecba7d44cc1..3005edd6e61cd9f11d47b5f0a858a4a02377daad 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -30,10 +30,10 @@ static void configure_core_coder_loc( Encoder_State *st ); *-------------------------------------------------------------------*/ ivas_error evs_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *data, /* i : input signal */ - Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory */ - const Word16 n_samples /* i : number of input samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *data, /* i : input signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of input samples Q0*/ ) { Word16 i, input_frame, delay; @@ -144,13 +144,13 @@ ivas_error evs_enc_fx( /* get delay to synchronize ACELP and MDCT frame */ delay = NS2SA_FX2( st->input_Fs, DELAY_FIR_RESAMPL_NS ); - Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); + Copy( st->input_fx - delay, st->old_input_signal_fx, input_frame + delay ); /* st->q_inp */ /*----------------------------------------------------------------* * convert 'short' input data to 'float' *----------------------------------------------------------------*/ - Copy( data, st->input_fx, input_frame ); + Copy( data, st->input_fx, input_frame ); /* st-> q_inp */ IF( LT_16( n_samples, input_frame ) ) { set16_fx( st->input_fx + n_samples, 0, sub( input_frame, n_samples ) ); @@ -225,7 +225,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->last_L_frame, L_FRAME ) && st->ini_frame != 0 ) { /* this is just an approximation, but it is sufficient */ - Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); + Copy( st->lsp_old1_fx, st->lspold_enc_fx, M ); /* Q15 */ } } ELSE @@ -238,7 +238,7 @@ ivas_error evs_enc_fx( move16(); } - st->sr_core = L_mult0( FRAMES_PER_SEC, st->L_frame ); + st->sr_core = L_mult0( FRAMES_PER_SEC, st->L_frame ); /* Q0 */ st->core_brate = st->total_brate; move32(); @@ -332,7 +332,7 @@ ivas_error evs_enc_fx( bwe_exc_extended, voice_factors, pitch_buf, vad_hover_flag, &Q_new, &shift ); #ifndef FIX_I4_OL_PITCH - Copy( pitch_orig, st->pitch, 3 ); /* populate the original OL pitch values back */ + Copy( pitch_orig, st->pitch, 3 ); /* populate the original OL pitch values back Q0*/ #endif /*---------------------------------------------------------------------* @@ -393,12 +393,12 @@ ivas_error evs_enc_fx( move32(); } - st->core_brate = L_sub( st->total_brate, st->extl_brate ); + st->core_brate = L_sub( st->total_brate, st->extl_brate ); /* Q0 */ IF( EQ_16( st->tec_tfa, 1 ) ) { - st->core_brate = L_sub( st->core_brate, BITS_TEC ); - st->core_brate = L_sub( st->core_brate, BITS_TFA ); + st->core_brate = L_sub( st->core_brate, BITS_TEC ); /* Q0 */ + st->core_brate = L_sub( st->core_brate, BITS_TFA ); /* Q0 */ } } @@ -413,14 +413,14 @@ ivas_error evs_enc_fx( IF( st->igf != 0 && EQ_16( st->core, ACELP_CORE ) && GT_32( st->core_brate, SID_2k40 ) ) { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) ) + get_tbe_bits(st->total_brate, st->bwidth, st->rf_mode )); */ - tmp = add( get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ), sub( st->rf_target_bits_write, st->rf_mode ) ); - padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot ), tmp ); + tmp = add( get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_mode ), sub( st->rf_target_bits_write, st->rf_mode ) ); /* Q0 */ + padBits = sub( sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), hBstr->nb_bits_tot ), tmp ); /* Q0 */ } ELSE { /* padBits = ((st->bits_frame+7)/8)*8 - (st->nb_bits_tot + (st->rf_target_bits_write - ((st->Opt_RF_ON==1)?1:0) )); */ - tmp = sub( st->rf_target_bits_write, st->rf_mode ); - padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot, tmp ) ); + tmp = sub( st->rf_target_bits_write, st->rf_mode ); /* Q0 */ + padBits = sub( shl( shr( add( st->bits_frame, 7 ), 3 ), 3 ), add( hBstr->nb_bits_tot, tmp ) ); /* Q0 */ } FOR( i = 0; i < padBits; i++ ) @@ -517,7 +517,7 @@ ivas_error evs_enc_fx( st->hTECEnc->corrFlag = 0; move16(); } - st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core, st->voicing_fx, pitch_buf, shl( Q_shb_spch, 1 ) ); + st->tfa_flag = tfaEnc_TBE_fx( st->tfa_enr, st->last_core, st->voicing_fx, pitch_buf, shl( Q_shb_spch, 1 ) ); /* Q0 */ set_TEC_TFA_code_fx( st->hTECEnc->corrFlag, &st->tec_flag, &st->tfa_flag ); } ELSE diff --git a/lib_enc/igf_scf_enc.c b/lib_enc/igf_scf_enc.c index 5ac4f4e3e9c278705e73817d0c46402ae38b93bb..04ca67979f1eb2a809bf66b850d15804691b9c61 100644 --- a/lib_enc/igf_scf_enc.c +++ b/lib_enc/igf_scf_enc.c @@ -93,11 +93,11 @@ static void arith_encode_bits( FOR( i = nBits - 1; i >= 0; --i ) /* nBits > 0 */ { bit = s_and( shr( x, i ), 1 ); - hPrivateData->ptrBitIndex = ari_encode_14bits_sign( ptr, - hPrivateData->ptrBitIndex, - 32767, /* disable the bit count limitation */ - &hPrivateData->acState, - bit ); + hPrivateData->ptrBitIndex = ari_encode_14bits_sign_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + 32767, /* disable the bit count limitation */ + &hPrivateData->acState, + bit ); } } @@ -128,11 +128,11 @@ static void arith_encode_residual( { x = sub( x, IGF_MIN_ENC_SEPARATE - 1 ); /* (x - IGF_MIN_ENC_SEPARATE) + 1 */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - x, - cumulativeFrequencyTable ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + x, + cumulativeFrequencyTable ); return; } @@ -141,21 +141,21 @@ static void arith_encode_residual( { /* send escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ extra = sub( IGF_MIN_ENC_SEPARATE - 1, x ); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - 0, - cumulativeFrequencyTable ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + 0, + cumulativeFrequencyTable ); } ELSE /* x > IGF_MAX_ENC_SEPARATE */ { /* send escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ extra = sub( x, IGF_MAX_ENC_SEPARATE + 1 ); - hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - IGF_SYMBOLS_IN_TABLE - 1, - cumulativeFrequencyTable ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + IGF_SYMBOLS_IN_TABLE - 1, + cumulativeFrequencyTable ); } /* encode one of the tails of the distribution */ @@ -221,11 +221,11 @@ static void encode_sfe_vector( { /* (t == 0) && (f == 0) */ /* encode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - hPrivateData->ptrBitIndex = ari_encode_14bits_ext( ptr, - hPrivateData->ptrBitIndex, - &hPrivateData->acState, - shr( x[f], 2 ), - (const UWord16 *) hPrivateData->cf_se00 ); + hPrivateData->ptrBitIndex = ari_encode_14bits_ext_ivas_fx( ptr, + hPrivateData->ptrBitIndex, + &hPrivateData->acState, + shr( x[f], 2 ), + (const UWord16 *) hPrivateData->cf_se00 ); arith_encode_bits( hPrivateData, ptr, x[f] & 3, 2 ); /* LSBs as 2 bit raw */ } ELSE IF( EQ_16( f, 1 ) ) @@ -298,7 +298,7 @@ Word16 IGFSCFEncoderEncode( encode_sfe_vector( hPublicData, ptr, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] ); - hPublicData->ptrBitIndex = ari_done_encoding_14bits( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); /* finish AC encoding */ + hPublicData->ptrBitIndex = ari_done_encoding_14bits_ivas_fx( ptr, hPublicData->ptrBitIndex, &hPublicData->acState ); /* finish AC encoding */ hPublicData->bitCount = add( hPublicData->bitCount, hPublicData->ptrBitIndex ); move16(); move16(); diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 5caa4d0b991e9bc7000187791799913c5fb00250..dcc55f5ad00003a0d2d1a9dae89a19b9ab97905d 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -210,7 +210,7 @@ Word32 pow32_fx( Word16 inp, Word16 indx ) /*! r: AGC enable flag */ Word16 ivas_agc_enc_get_flag( - const Word16 nchan_transport /* i : number of transport channels */ + const Word16 nchan_transport /* i : number of transport channels Q0*/ ) { Word16 agc_flag; @@ -236,15 +236,16 @@ Word16 ivas_agc_enc_get_flag( static void ivas_agc_enc_init_fx( ivas_agc_enc_state_t *hAgcEnc, - const Word16 input_frame, - const Word16 nchan_inp, - const Word16 delay ) + const Word16 input_frame, /* Q0 */ + const Word16 nchan_inp, /* Q0 */ + const Word16 delay /* Q0 */ +) { Word16 i; ivas_agc_enc_chan_state_t *ptrG = hAgcEnc->gain_state; ivas_agc_chan_data_t *ptr = hAgcEnc->gain_data; - hAgcEnc->agc_com.in_delay = delay; + hAgcEnc->agc_com.in_delay = delay; /* Q0 */ move16(); hAgcEnc->agc_com.num_coeff = FOA_CHANNELS; move16(); @@ -284,9 +285,9 @@ static void ivas_agc_enc_init_fx( ptrG++; /* gain_data */ - ptr->absGainExp = hAgcEnc->agc_com.absEmin; + ptr->absGainExp = hAgcEnc->agc_com.absEmin; /* Q0 */ move16(); - ptr->absGainExpCurr = hAgcEnc->agc_com.absEmin; + ptr->absGainExpCurr = hAgcEnc->agc_com.absEmin; /* Q0 */ move16(); ptr++; } @@ -303,8 +304,8 @@ static void ivas_agc_enc_init_fx( ivas_error ivas_spar_agc_enc_open_fx( ivas_agc_enc_state_t **hAgcEnc, /* i/o: SPAR AGC encoder handle */ - const Word32 input_Fs, /* i : input sampling rate */ - const Word16 nchan_inp /* i : number of input channels */ + const Word32 input_Fs, /* i : input sampling rate Q0*/ + const Word16 nchan_inp /* i : number of input channels Q0*/ ) { ivas_agc_enc_state_t *hAgc; @@ -315,7 +316,7 @@ ivas_error ivas_spar_agc_enc_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR AGC encoder" ); } - input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); + input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ delay = NS2SA_FX2( input_Fs, ( IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ) ); IF( ( hAgc->agc_com.winFunc_fx = (Word16 *) malloc( sizeof( Word16 ) * ( input_frame - delay ) ) ) == NULL ) @@ -386,9 +387,9 @@ void ivas_spar_agc_enc_close_fx( void ivas_agc_enc_process_fx( ivas_agc_enc_state_t *hAgcEnc, /* i/o: AGC encoder handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ - Word32 **ppPcm_in, /* i : input audio channels */ - Word32 **ppPcm_out, /* o : output audio channels */ - const Word16 n_channels, /* i : number of channels */ + Word32 **ppPcm_in, /* i : input audio channels q_ppPcm*/ + Word32 **ppPcm_out, /* o : output audio channels q_ppPcm*/ + const Word16 n_channels, /* i : number of channels Q0*/ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ Word16 *q_ppPcm ) { @@ -400,8 +401,8 @@ void ivas_agc_enc_process_fx( Word16 q_predMaxAbsVal, q_MaxAbsVal; ivas_agc_enc_state_t *pState = hAgcEnc; - input_frame = extract_l( Mpy_32_16_1( hEncoderConfig->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); - offset = sub( input_frame, pState->agc_com.in_delay ); + input_frame = extract_l( Mpy_32_16_1( hEncoderConfig->input_Fs, INV_FRAME_PER_SEC_Q15 ) ); /* Q0 */ + offset = sub( input_frame, pState->agc_com.in_delay ); /* Q0 */ AGC_flag = 0; move16(); @@ -429,20 +430,20 @@ void ivas_agc_enc_process_fx( IF( LT_16( pState->gain_state[i].q_lastGain_fx, Q31 ) ) { gain_norm = norm_l( L_abs( pState->gain_state[i].lastGain_fx ) ); - pState->gain_state[i].lastGain_fx = L_shl( pState->gain_state[i].lastGain_fx, gain_norm ); + pState->gain_state[i].lastGain_fx = L_shl( pState->gain_state[i].lastGain_fx, gain_norm ); /* pState->gain_state[i].q_lastGain_fx + gain_norm */ move32(); pState->gain_state[i].q_lastGain_fx = add( pState->gain_state[i].q_lastGain_fx, gain_norm ); move16(); } FOR( j = 0; j < input_frame; j++ ) { - sampleAbsVal = L_abs( ppPcm_in[i][j] ); + sampleAbsVal = L_abs( ppPcm_in[i][j] ); /* q_ppPcm */ q_sampleAbsVal = q_ppPcm[i]; move16(); IF( EQ_16( BASOP_Util_Cmp_Mant32Exp_sat( sampleAbsVal, sub( Q31, q_sampleAbsVal ), MaxAbsVal, sub( Q31, q_MaxAbsVal ) ), 1 ) ) { - MaxAbsVal = sampleAbsVal; + MaxAbsVal = sampleAbsVal; /* q_sampleAbsVal */ move32(); q_MaxAbsVal = q_sampleAbsVal; move16(); @@ -454,14 +455,14 @@ void ivas_agc_enc_process_fx( { IF( EQ_16( BASOP_Util_Cmp_Mant32Exp_sat( sampleAbsVal, sub( Q31, q_sampleAbsVal ), predMaxAbsVal, sub( Q31, q_predMaxAbsVal ) ), 1 ) ) { - predMaxAbsVal = sampleAbsVal; + predMaxAbsVal = sampleAbsVal; /* q_sampleAbsVal */ move32(); q_predMaxAbsVal = q_sampleAbsVal; move16(); } } - ppPcm_out[i][j] = Mpy_32_32( ppPcm_in[i][j], pState->gain_state[i].lastGain_fx ); + ppPcm_out[i][j] = Mpy_32_32( ppPcm_in[i][j], pState->gain_state[i].lastGain_fx ); /* q_ppPcm + State->gain_state[i].q_lastGain_fx - 31 */ move32(); q_pcm = add( q_ppPcm[i], sub( pState->gain_state[i].q_lastGain_fx, Q31 ) ); IF( !isClipped ) @@ -501,7 +502,7 @@ void ivas_agc_enc_process_fx( } } - pState->gain_state[i].MaxAbsVal_del_fx = predMaxAbsVal; + pState->gain_state[i].MaxAbsVal_del_fx = predMaxAbsVal; /* q_predMaxAbsVal */ move32(); pState->gain_state[i].q_MaxAbsVal_del_fx = q_predMaxAbsVal; move16(); @@ -537,10 +538,10 @@ void ivas_agc_enc_process_fx( temp1 = Mpy_32_32( pState->smFact_fx, MaxAbsVal ); // q_MaxAbsVal temp2 = Mpy_32_32( ( L_sub( ONE_IN_Q31, pState->smFact_fx ) ), pState->gain_state[i].lastMaxAbs_fx ); // q_lastMaxAbs_fx - smoothedMaxAbsVal = BASOP_Util_Add_Mant32Exp( temp1, sub( Q31, q_MaxAbsVal ), temp2, sub( Q31, pState->gain_state[i].q_lastMaxAbs_fx ), &e_result ); + smoothedMaxAbsVal = BASOP_Util_Add_Mant32Exp( temp1, sub( Q31, q_MaxAbsVal ), temp2, sub( Q31, pState->gain_state[i].q_lastMaxAbs_fx ), &e_result ); /* exp(e_result) */ q_smoothedMaxAbsVal = sub( Q31, e_result ); - pState->gain_state[i].lastMaxAbs_fx = smoothedMaxAbsVal; + pState->gain_state[i].lastMaxAbs_fx = smoothedMaxAbsVal; /* q_smoothedMaxAbsVal */ move32(); pState->gain_state[i].q_lastMaxAbs_fx = q_smoothedMaxAbsVal; move16(); @@ -548,7 +549,7 @@ void ivas_agc_enc_process_fx( Comp_flag = BASOP_Util_Cmp_Mant32Exp_sat( smoothedMaxAbsVal, sub( Q31, q_smoothedMaxAbsVal ), MaxAbsVal, sub( Q31, q_MaxAbsVal ) ); IF( EQ_16( Comp_flag, 1 ) ) { - temp1 = smoothedMaxAbsVal; + temp1 = smoothedMaxAbsVal; /* q_smoothedMaxAbsVal */ move32(); q_temp = q_smoothedMaxAbsVal; move16(); @@ -560,9 +561,9 @@ void ivas_agc_enc_process_fx( q_temp = q_MaxAbsVal; move16(); } - temp1 = Mpy_32_32( temp1, TWO_IN_Q29 ); + temp1 = Mpy_32_32( temp1, TWO_IN_Q29 ); /* q_temp + 29 - 31 */ q_temp = add( q_temp, Q29 - Q31 ); - maxGain = Mpy_32_32( temp1, pState->gain_state[i].lastGain_fx ); + maxGain = Mpy_32_32( temp1, pState->gain_state[i].lastGain_fx ); /* q_temp + pState->gain_state[i].q_lastGain_fx - 31 */ q_maxGain = add( q_temp, sub( pState->gain_state[i].q_lastGain_fx, Q31 ) ); temp2 = ONE_MINUS_M_DELTA_PROD_FLT_FC; // Q15 @@ -582,7 +583,7 @@ void ivas_agc_enc_process_fx( } ELSE { - pState->gain_state[i].lastMaxAbs_fx = MaxAbsVal; + pState->gain_state[i].lastMaxAbs_fx = MaxAbsVal; /* q_MaxAbsVal */ move32(); pState->gain_state[i].q_lastMaxAbs_fx = q_MaxAbsVal; move16(); @@ -604,7 +605,7 @@ void ivas_agc_enc_process_fx( Word32 temp1, temp2; actualMaxAbsVal = Mpy_32_32( pState->gain_state[i].lastMaxAbs_fx, pState->gain_state[i].lastGain_fx ); // QlastGain_fx q_actualMaxAbsVal = add( pState->gain_state[i].q_lastMaxAbs_fx, sub( pState->gain_state[i].q_lastGain_fx, Q31 ) ); - idx = s_min( sub( offset, 1 ), MaxAbsValIdx ); + idx = s_min( sub( offset, 1 ), MaxAbsValIdx ); /* Q0 */ q_actualMaxAbsVal = add( q_actualMaxAbsVal, norm_l( actualMaxAbsVal ) ); temp1 = L_shl( actualMaxAbsVal, norm_l( actualMaxAbsVal ) ); @@ -620,16 +621,16 @@ void ivas_agc_enc_process_fx( } ELSE { - temp_16 = BASOP_Util_Divide3232_Scale( temp1, temp2, &div_e ); + temp_16 = BASOP_Util_Divide3232_Scale( temp1, temp2, &div_e ); /* exp(div_e) */ IF( div_e < 0 ) { temp_16 = shr( temp_16, (Word16) abs( div_e ) ); div_e = 0; move16(); } - temp_16 = ceil_fx( temp_16, sub( Q15, div_e ) ); + temp_16 = ceil_fx( temp_16, sub( Q15, div_e ) ); /* Q0 */ } - pState->gain_state[i].gainExpVal = temp_16; + pState->gain_state[i].gainExpVal = temp_16; /* Q0 */ move16(); WHILE( !isCompensated ) @@ -641,7 +642,7 @@ void ivas_agc_enc_process_fx( move16(); Word32 tmp_2 = ONE_IN_Q31; move16(); - tmp_1 = pState->gain_state[i].gainExpVal; + tmp_1 = pState->gain_state[i].gainExpVal; /* Q0 */ move16(); FOR( idx = clippedIdx; idx <= MaxAbsValIdx; idx++ ) { @@ -651,21 +652,21 @@ void ivas_agc_enc_process_fx( move16(); IF( tmp_1 < 0 ) { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); /* Q31 */ IF( tmp_2 < 0 ) { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); /* exp(e_div) */ tmp_2 = L_negate( tmp_2 ); } ELSE { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); /* exp(e_div) */ } q_tmp_2 = sub( Q31, e_div ); } ELSE { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); /* Q31 */ q_tmp_2 = Q31; move16(); } @@ -674,15 +675,15 @@ void ivas_agc_enc_process_fx( { IF( tmp_1 < 0 ) { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[idx], ( negate( tmp_1 ) ) ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[idx], ( negate( tmp_1 ) ) ); /* Q31 */ IF( tmp_2 < 0 ) { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); /* exp(e_div) */ tmp_2 = L_negate( tmp_2 ); } ELSE { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); /* exp(e_div) */ } q_tmp_2 = sub( Q31, e_div ); } @@ -694,7 +695,7 @@ void ivas_agc_enc_process_fx( } } - tmpSignal = Mpy_32_32( ppPcm_out[i][idx], tmp_2 ); + tmpSignal = Mpy_32_32( ppPcm_out[i][idx], tmp_2 ); /* q_pcm + q_tmp_2 - 31 */ q_tmpSignal = add( q_pcm, sub( q_tmp_2, 31 ) ); Word16 comp_flag_1 = BASOP_Util_Cmp_Mant32Exp_sat( tmpSignal, sub( Q31, q_tmpSignal ), ONE_MINUS_M_DELTA_PROD_FLT_FC, Q16 ); @@ -730,13 +731,13 @@ void ivas_agc_enc_process_fx( } IF( !isCompensated ) { - pState->gain_state[i].gainExpVal = add( pState->gain_state[i].gainExpVal, 1 ); + pState->gain_state[i].gainExpVal = add( pState->gain_state[i].gainExpVal, 1 ); /* Q0 */ move16(); } IF( GT_16( pState->gain_state[i].gainExpVal, currMaxAttExp ) ) { - pState->gain_state[i].gainExpVal = s_min( pState->gain_state[i].gainExpVal, currMaxAttExp ); + pState->gain_state[i].gainExpVal = s_min( pState->gain_state[i].gainExpVal, currMaxAttExp ); /* Q0 */ move16(); BREAK; } @@ -748,7 +749,7 @@ void ivas_agc_enc_process_fx( { Word16 tmp_1, q_tmp_2, e_div; Word32 tmp_2; - tmp_1 = pState->gain_state[i].gainExpVal; + tmp_1 = pState->gain_state[i].gainExpVal; /* Q0 */ move16(); IF( GT_16( offset, idx ) ) @@ -758,18 +759,18 @@ void ivas_agc_enc_process_fx( tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[idx], ( negate( tmp_1 ) ) ); IF( tmp_2 < 0 ) { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); /* exp(e_div) */ tmp_2 = L_negate( tmp_2 ); } ELSE { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); /* exp(e_div) */ } q_tmp_2 = sub( Q31, e_div ); } ELSE { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[idx], tmp_1 ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[idx], tmp_1 ); /* Q31 */ q_tmp_2 = Q31; move16(); } @@ -778,21 +779,21 @@ void ivas_agc_enc_process_fx( { IF( tmp_1 < 0 ) { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); /* Q31 */ IF( tmp_2 < 0 ) { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); /* exp(e_div) */ tmp_2 = L_negate( tmp_2 ); } ELSE { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); /* exp(e_div) */ } q_tmp_2 = sub( Q31, e_div ); } ELSE { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); /* Q31 */ q_tmp_2 = Q31; move16(); } @@ -806,29 +807,29 @@ void ivas_agc_enc_process_fx( Word16 tmp_1, q_tmp_2, e_div; Word32 tmp_2; - tmp_1 = pState->gain_state[i].gainExpVal; + tmp_1 = pState->gain_state[i].gainExpVal; /* Q0 */ move16(); IF( tmp_1 < 0 ) { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], ( negate( tmp_1 ) ) ); /* Q31 */ IF( tmp_2 < 0 ) { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_negate( tmp_2 ), &e_div ) ); /* exp(e_div) */ tmp_2 = L_negate( tmp_2 ); } ELSE { - tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); + tmp_2 = L_deposit_h( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, tmp_2, &e_div ) ); /* exp(e_div) */ } q_tmp_2 = sub( Q31, e_div ); } ELSE { - tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); + tmp_2 = pow32_fx( pState->agc_com.winFunc_fx[offset - 1], tmp_1 ); /* Q31 */ q_tmp_2 = Q31; move16(); } - pState->gain_state[i].lastGain_fx = Mpy_32_32( pState->gain_state[i].lastGain_fx, tmp_2 ); + pState->gain_state[i].lastGain_fx = Mpy_32_32( pState->gain_state[i].lastGain_fx, tmp_2 ); /* pState->gain_state[i].q_lastGain_fx + q_tmp_2 - 31 */ move32(); pState->gain_state[i].q_lastGain_fx = add( pState->gain_state[i].q_lastGain_fx, sub( q_tmp_2, Q31 ) ); move16(); @@ -860,11 +861,11 @@ void ivas_agc_enc_process_fx( { IF( pState->gain_state[i].gainExpVal <= 0 ) { - pState->gain_state[i].gainExpVal = add( pState->agc_com.maxAttExp, 1 ); + pState->gain_state[i].gainExpVal = add( pState->agc_com.maxAttExp, 1 ); /* Q0 */ move16(); } } - pState->gain_data[i].absGainExpCurr = sub( pState->gain_data[i].absGainExp, pState->gain_state[i].gainExpVal ); + pState->gain_data[i].absGainExpCurr = sub( pState->gain_data[i].absGainExp, pState->gain_state[i].gainExpVal ); /* Q0 */ move16(); test(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index c38d03cc480a39d9118397d3f729a24abcc078cf..667bd89ae5263b104e00fb15f8027537d0b1cd69 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -49,41 +49,41 @@ /*-------------------------------------------------------------------* - * ivas_core_enc() + * ivas_core_enc_fx() * * Principal IVAS core coder routine, where number of core channels is 1 or 2 *-------------------------------------------------------------------*/ -ivas_error ivas_core_enc( +ivas_error ivas_core_enc_fx( SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const Word16 n_CoreChannels, /* i : number of core channels to be coded */ - Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ - Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ + const Word16 n_CoreChannels, /* i : number of core channels to be coded Q0*/ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal Q_new-1*/ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal Q_new-1*/ Word16 Q_new[], - Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q */ - Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ - Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ - Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q */ + Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q*/ + Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes Q12*/ + Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes Q12*/ + Word32 epsP_fx[][M + 1], /* i : LP prediction errors epsP_fx_q*/ Word16 epsP_fx_q[], /* i : LP prediction errors */ - Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15 */ - Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15 */ - const Word16 vad_hover_flag[], /* i : VAD hanglover flag */ - Word16 attack_flag[], /* i : attack flag (GSC or TC) */ - Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer */ - Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer */ + Word16 lsp_new_fx[][M], /* i : LSPs at the end of the frame Q15*/ + Word16 lsp_mid_fx[][M], /* i : LSPs in the middle of the frame Q15*/ + const Word16 vad_hover_flag[], /* i : VAD hanglover flag Q0*/ + Word16 attack_flag[], /* i : attack flag (GSC or TC) Q0*/ + Word32 realBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer q_re_im_buf*/ + Word32 imagBuffer_fx[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer q_re_im_buf*/ Word16 *q_re_im_buf, - Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer */ + Word16 old_wsp_fx[][L_WSP], /* i : weighted input signal buffer e_old_wsp*/ Word16 e_old_wsp[], - const Word16 loc_harm[], /* i : harmonicity flag */ - const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8 */ - const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO */ - Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer */ - Word16 enerBuffer_fx_exp[], /* o : energy buffer */ - Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer */ - const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag */ - const Word16 ivas_format, /* i : IVAS format */ - const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ + const Word16 loc_harm[], /* i : harmonicity flag Q0*/ + const Word16 cor_map_sum_fx[], /* i : speech/music clasif. parameter Q8*/ + const Word16 vad_flag_dtx[], /* i : HE-SAD flag with additional DTX HO Q0*/ + Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX], /* o : energy buffer enerBuffer_fx_exp*/ + Word16 enerBuffer_fx_exp[], /* o : energy buffer */ + Word16 fft_buff_fx[][2 * L_FFT], /* i : FFT buffer Qx*/ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag Q0*/ + const Word16 ivas_format, /* i : IVAS format Q0*/ + const Word16 flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz Q0*/ ) { Word16 n, input_frame; @@ -150,9 +150,9 @@ ivas_error ivas_core_enc( sts = hSCE->hCoreCoder; hStereoTD = NULL; hStereoICBWE = NULL; - element_brate = hSCE->element_brate; + element_brate = hSCE->element_brate; /* Q0 */ move32(); - last_element_brate = hSCE->last_element_brate; + last_element_brate = hSCE->last_element_brate; /* Q0 */ move32(); last_element_mode = IVAS_SCE; move16(); @@ -161,7 +161,7 @@ ivas_error ivas_core_enc( } ELSE { - cpe_id = hCPE->cpe_id; + cpe_id = hCPE->cpe_id; /* Q0 */ move16(); MCT_flag = 0; move16(); @@ -172,17 +172,17 @@ ivas_error ivas_core_enc( } sts = hCPE->hCoreCoder; hStereoICBWE = hCPE->hStereoICBWE; - element_brate = hCPE->element_brate; + element_brate = hCPE->element_brate; /* Q0 */ move32(); - last_element_brate = hCPE->last_element_brate; + last_element_brate = hCPE->last_element_brate; /* Q0 */ move32(); - last_element_mode = hCPE->last_element_mode; + last_element_mode = hCPE->last_element_mode; /* Q0 */ move16(); IF( hCPE->hStereoTD != NULL ) { hStereoTD = hCPE->hStereoTD; - tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag; + tdm_Pitch_reuse_flag = hCPE->hStereoTD->tdm_Pitch_reuse_flag; /* Q0 */ move16(); } ELSE @@ -211,7 +211,7 @@ ivas_error ivas_core_enc( unbits[n] = 0; move16(); - st->element_brate = element_brate; + st->element_brate = element_brate; /* Q0 */ move32(); /*---------------------------------------------------------------------* @@ -224,7 +224,7 @@ ivas_error ivas_core_enc( tmp_shift = sub( tmp_shift, 5 ); IF( tmp_shift < 0 ) { - scale_sig32( enerBuffer_fx[n], st->cldfbAnaEnc->no_channels, tmp_shift ); + scale_sig32( enerBuffer_fx[n], st->cldfbAnaEnc->no_channels, tmp_shift ); /* enerBuffer_fx_exp[n] - tmp_shift */ enerBuffer_fx_exp[n] = sub( enerBuffer_fx_exp[n], tmp_shift ); move16(); } @@ -308,8 +308,8 @@ ivas_error ivas_core_enc( /* write TD stereo spatial parameters */ move_indices( hStereoTD->tdm_hBstr_tmp.ind_list, st->hBstr->ind_list, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); - st->hBstr->nb_ind_tot = add( st->hBstr->nb_ind_tot, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); - st->hBstr->nb_bits_tot = add( st->hBstr->nb_bits_tot, hStereoTD->tdm_hBstr_tmp.nb_bits_tot ); + st->hBstr->nb_ind_tot = add( st->hBstr->nb_ind_tot, hStereoTD->tdm_hBstr_tmp.nb_ind_tot ); /* Q0 */ + st->hBstr->nb_bits_tot = add( st->hBstr->nb_bits_tot, hStereoTD->tdm_hBstr_tmp.nb_bits_tot ); /* Q0 */ reset_indices_enc( &hStereoTD->tdm_hBstr_tmp, MAX_IND_TDM_TMP ); } @@ -363,7 +363,7 @@ ivas_error ivas_core_enc( Scale_sig( old_inp_12k8_fx[n], L_INP_12k8, sub( Q1, Q_new[n] ) ); // Q0 Scale_sig( old_inp_16k_fx[n], L_INP, sub( Q1, Q_new[n] ) ); // Q0 - Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( -1, st->hTcxEnc->q_Txnq ) ); + Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( negate( 1 ), st->hTcxEnc->q_Txnq ) ); /* Q(-1) */ st->hTcxEnc->q_Txnq = -Q1; move16(); Q_spec_old = hTcxEnc->spectrum_long_e; @@ -646,10 +646,10 @@ ivas_error ivas_core_enc( move16(); IF( st->hBWE_FD != NULL ) { - Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( -1, st->Q_old_wtda ) ); - st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further + Scale_sig( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k, sub( negate( 1 ), st->Q_old_wtda ) ); // Q(-1) + st->Q_old_wtda = -1; // This reset is required for resolving crash issue. Needs to be looked into further move16(); - Scale_sig( st->hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( sub( Q_new[n], 1 ), st->hBWE_FD->prev_Q_input_lp ) ); + Scale_sig( st->hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( sub( Q_new[n], 1 ), st->hBWE_FD->prev_Q_input_lp ) ); /* Q_new[n] - 1 */ st->hBWE_FD->prev_Q_input_lp = sub( Q_new[n], 1 ); move16(); } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 057424445a512e3fcb8b0da59a791b95cc4ac7ae..07e3aece51546bd7b28d76f4db0a43bbac7430e2 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -1077,7 +1077,7 @@ ivas_error ivas_cpe_enc_fx( e_old_wsp[n] = 16; move16(); } - IF( NE_32( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_enc_fx( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 1722d665ae2b36f672407a729693b28fc9d0d00b..11f1d4cb9fd022a85b0c1e39f0433c159b4440e5 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -440,7 +440,7 @@ ivas_error ivas_ism_enc_fx( Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); e_old_wsp[sce_id][0] = 16; move16(); - IF( NE_32( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 302f10cbab1ac1a2d903bd1a92692c5899acf3db..bf87179a3766c474821a04b040c385f17b036d38 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -1115,10 +1115,12 @@ static void ivas_omasa_param_est_enc_fx( { q = q_data; move16(); +#if 0 scale_sig32( hOMasa->cldfbAnaEnc[i]->cldfb_state_fx, hOMasa->cldfbAnaEnc[i]->cldfb_state_length, sub( q, hOMasa->cldfbAnaEnc[i]->Q_cldfb_state ) ); hOMasa->cldfbAnaEnc[i]->Q_cldfb_state = q; move16(); - cldfbAnalysis_ts_fx_fixed_q( &( data[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &q ); /*q_data-5*/ +#endif + cldfbAnalysis_ts_fx_var_q( &( data[i][l_ts * ts] ), Chnl_RealBuffer_fx[i], Chnl_ImagBuffer_fx[i], l_ts, hOMasa->cldfbAnaEnc[i], &q ); /*q_data-5*/ norm_buff = s_min( norm_buff, L_norm_arr( Chnl_RealBuffer_fx[i], 60 ) ); norm_buff = s_min( norm_buff, L_norm_arr( Chnl_ImagBuffer_fx[i], 60 ) ); } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 75f1ede13062172a94b34d14f21ab0738638068f..f55be64697f53e17723c8f4741841c4991919189 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -352,7 +352,7 @@ ivas_error ivas_sce_enc_fx( Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); e_old_wsp[0] = 16; move16(); - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc_fx( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index e0673b1cb99bfb3bba677e486fcd8004cae501f5..4f1d4a5a7a7927f93a359bac2bbbdb9aa03c8910 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -851,8 +851,8 @@ Word16 corr_xy1_fx( /* o : pitch gain (0..GAIN_PIT_MAX) #endif ); -Word16 E_ACELP_indexing_fx( const Word16 code[], const PulseConfig *config, Word16 num_tracks, Word16 prm[] ); -void fcb_pulse_track_joint_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *index_n, Word16 *pulse_num, Word16 track_num ); +Word16 E_ACELP_indexing_fx( const Word16 code[] /*Q9*/, const PulseConfig *config, Word16 num_tracks /*Q0*/, Word16 prm[] /*Q(shift_bits)*/ ); +void fcb_pulse_track_joint_fx( UWord16 *idxs /*Q0*/, Word16 wordcnt /*Q0*/, UWord32 *index_n /*Q0*/, Word16 *pulse_num /*Q0*/, Word16 track_num /*Q0*/ ); Word16 gain_quant_fx( /* o: quantization index */ Word32 *gain, /* i/o: quantized gain */ @@ -1545,15 +1545,15 @@ void Mode2_pit_encode_fx( Word16 pit_fr2, Word16 pit_max, Word16 pit_res_max ); -void E_ACELP_4tsearch_fx( Word16 dn[], const Word16 cn[], const Word16 H[], Word16 code[], const PulseConfig *config, Word16 ind[], Word16 y[] ); +void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const Word16 H[] /*Q12*/, Word16 code[] /*Q9*/, const PulseConfig *config, Word16 ind[] /*Q0*/, Word16 y[] /*Qy*/ ); void E_ACELP_4t_fx( - Word16 dn[], + Word16 dn[], /* Qdn */ Word16 cn[] /* Q_xn */, - Word16 H[], - Word16 R[], + Word16 H[], /* Q12 */ + Word16 R[], /* Qx */ Word8 acelpautoc, - Word16 code[], + Word16 code[], /* Q9 */ Word16 cdk_index, Word16 _index[], const Word16 L_frame, @@ -1563,12 +1563,12 @@ void E_ACELP_4t_fx( const Word16 cmpl_flag ); void E_ACELP_4t_ivas_fx( - Word16 dn[], + Word16 dn[], /* Qdn */ Word16 cn[] /* Q_xn */, - Word16 H[], - Word16 R[], + Word16 H[], /* Q12 */ + Word16 R[], /* Qx */ Word8 acelpautoc, - Word16 code[], + Word16 code[], /* Q9 */ Word16 cdk_index, Word16 _index[], const Word16 L_frame, @@ -1742,21 +1742,22 @@ void ari_copy_states_fx( TastatEnc *dest ); Word16 ari_encode_14bits_ext_fx( - Word16 *ptr, - Word16 bp, + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ TastatEnc *s, - Word32 symbol, - UWord16 const *cum_freq ); + Word32 symbol, /* Q0 */ + UWord16 const *cum_freq /* Q0 */ +); Word16 ari_put_bit_plus_follow( - Word16 ptr[], /* o: bit-stream */ - Word16 bp, /* i: bit-stream position */ - Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' */ - Word16 bit /* i: bit to send */ + Word16 ptr[], /* o: bit-stream Q0*/ + Word16 bp, /* i: bit-stream position Q0*/ + Word16 bits_to_follow, /* i: number of opposite bits to follow 'bit' Q0*/ + Word16 bit /* i: bit to send Q0*/ ); Word16 ari_done_encoding_14bits_fx( - Word16 *ptr, - Word16 bp, + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ TastatEnc *s ); void reset_rf_indices_fx( @@ -1943,18 +1944,18 @@ void deleteFdCngEnc_fx( HANDLE_FD_CNG_ENC *hFdCngEnc ); void coder_acelp_rf_fx( ACELP_config *acelp_cfg_rf, /*i /o : configuration of the ACELP coding*/ - const Word16 coder_type, /* i : coding type */ - const Word16 A[], /* i : coefficients 4xAz[M+1] */ - const Word16 Aq[], /* i : coefficients 4xAz_q[M+1] */ - Word16 speech[], /* i : speech[-M..lg] */ - const Word16 voicing[], /* i : open-loop LTP gain */ - const Word16 T_op[], /* i : open-loop LTP lag */ - Word16 stab_fac, + const Word16 coder_type, /* input: coding type Q0*/ + const Word16 A[], /* input: coefficients 4xAz[M+1] Q12*/ + const Word16 Aq[], /* input: coefficients 4xAz_q[M+1] Q12*/ + Word16 speech[], /* input: speech[-M..lg] Q_new-1*/ + const Word16 voicing[], /* input: open-loop LTP gain Q15*/ + const Word16 T_op[], /* input: open-loop LTP lag Q0*/ + Word16 stab_fac, /* Q15 */ Encoder_State *st, - Word16 target_bits, /* i/o : coder memory state */ - const Word16 rf_frame_type, /* i : rf_frame_type */ - Word16 *exc_rf, /* i/o: pointer to RF excitation */ - Word16 *syn_rf, /* i/o: pointer to RF synthesis */ + Word16 target_bits, /* i/o : coder memory state Q0*/ + const Word16 rf_frame_type, /* i : rf_frame_type Q0*/ + Word16 *exc_rf, /* i/o: pointer to RF excitation Q_new*/ + Word16 *syn_rf, /* i/o: pointer to RF synthesis Q_new-1*/ Word16 Q_new, Word16 shift ); /* Create an instance of type FD_CNG */ @@ -2012,48 +2013,48 @@ void resetFdCngEnc_fx( Encoder_State *st ); void encod_unvoiced_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 *speech_fx, /* i : Input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* o : core synthesis Q_new*/ + Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ const Word16 Q_new, const Word16 shift ); void encod_unvoiced_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *speech_fx, /* i : Input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 *Aq_fx, /* i : 12k8 Lp coefficient */ - const Word16 Es_pred, /* i : predicted scaled innov. energy */ - const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* o : core synthesis */ - Word16 *tmp_noise_fx, /* o : long-term noise energy */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE */ + const Word16 *speech_fx, /* i : Input speech Q_new*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 *Aq_fx, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred, /* i : predicted scaled innov. energy Q8*/ + const Word16 uc_two_stage_flag, /* i : flag indicating two-stage UC Q0*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* o : core synthesis Q_new*/ + Word16 *tmp_noise_fx, /* o : long-term noise energy Q0*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* i/o: excitation for SWB TBE Q_exc*/ const Word16 Q_new, const Word16 shift ); void enc_acelp_tcx_main_fx( - const Word16 new_samples[], /* i : new samples */ - Encoder_State *st, /* i/o: encoder state structure */ - Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes*/ - const Word16 lsp_new[M], /* i : LSPs at the end of the frame */ - const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[], /* o : floating pitch for each subframe */ - Word16 vad_hover_flag, /* i : VAD hangover flag */ + const Word16 new_samples[], /* i : new samples Q15*/ + Encoder_State *st, /* i/o: encoder state structure */ + Word16 Aw[NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquant. for subframes Q12*/ + const Word16 lsp_new[M], /* i : LSPs at the end of the frame Q15*/ + const Word16 lsp_mid[M], /* i : LSPs at the middle of the frame Q15*/ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q_new*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ + Word16 pitch_buf[], /* o : floating pitch for each subframe Q6*/ + Word16 vad_hover_flag, /* i : VAD hangover flag Q0*/ Word16 *Q_new, Word16 *shift ); ivas_error encod_ppp_fx( @@ -2086,39 +2087,39 @@ ivas_error encod_ppp_ivas_fx( Word16 shift ); void encod_gen_voic_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : i speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + const Word16 speech_fx[], /* i : i speech Q0*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ + Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 shift, Word16 Q_new ); void encod_gen_voic_ivas_fx( Encoder_State *st_fx, /* i/o: state structure */ - const Word16 speech_fx[], /* i : input speech */ - const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq_fx[], /* i : 12k8 Lp coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ - const Word16 *res_fx, /* i : residual signal */ - Word16 *syn_fx, /* i/o: core synthesis */ - Word16 *exc_fx, /* i/o: current non-enhanced excitation */ - Word16 *exc2_fx, /* i/o: current enhanced excitation */ - Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ - Word16 *unbits_fx, /* i/o: number of unused bits */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer */ + const Word16 speech_fx[], /* i : input speech Q0*/ + const Word16 Aw_fx[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq_fx[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8*/ + const Word16 *res_fx, /* i : residual signal Q_new*/ + Word16 *syn_fx, /* i/o: core synthesis Q_new*/ + Word16 *exc_fx, /* i/o: current non-enhanced excitation Q0*/ + Word16 *exc2_fx, /* i/o: current enhanced excitation Q0*/ + Word16 *pitch_buf_fx, /* i/o: floating pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15*/ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q0*/ + Word16 *unbits_fx, /* i/o: number of unused bits Q0*/ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag Q0*/ + const Word16 tdm_Pri_pitch_buf[], /* i : primary channel pitch buffer Q6*/ Word16 shift, Word16 Q_new ); @@ -2243,9 +2244,26 @@ void find_wsp_fx( ); Word16 ari_encode_overflow_fx( TastatEnc *s ); -Word16 ari_encode_14bits_range_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 cum_freq_low, Word16 cum_freq_high ); -Word16 ari_encode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s, Word16 sign ); -Word16 ari_done_cbr_encoding_14bits_fx( Word16 *ptr, Word16 bp, Word16 bits, TastatEnc *s ); +Word16 ari_encode_14bits_range_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s, + Word16 cum_freq_low, /* Q0 */ + Word16 cum_freq_high /* Q0 */ +); +Word16 ari_encode_14bits_sign_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s, + Word16 sign /* Q0 */ +); +Word16 ari_done_cbr_encoding_14bits_fx( + Word16 *ptr, /* Q0 */ + Word16 bp, /* Q0 */ + Word16 bits, /* Q0 */ + TastatEnc *s ); void tcx_hm_analyse_fx( const Word32 abs_spectrum[], /* i: absolute spectrum Q31-e */ @@ -2259,15 +2277,15 @@ void tcx_hm_analyse_fx( const Word16 LtpGain, /* i: LTP gain Q15 */ Word16 *hm_bits_out /* o: bit consumption Q0 */ ); -void E_ACELP_4tsearchx_fx( Word16 dn[], const Word16 cn[], Word16 Rw[], Word16 code[], const PulseConfig *config, Word16 ind[] ); +void E_ACELP_4tsearchx_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_new*/, Word16 Rw[] /*Q9*/, Word16 code[] /*Q9*/, const PulseConfig *config, Word16 ind[] /*Q0*/ ); void E_ACELP_4tsearchx_ivas_fx( - Word16 dn[], - const Word16 cn[], - Word16 Rw[], - Word16 code[], + Word16 dn[], /*Qdn*/ + const Word16 cn[], /*Q_new*/ + Word16 Rw[], /*Q9*/ + Word16 code[], /*Q9*/ const PulseConfig *config, - Word16 ind[], + Word16 ind[], /*Q0*/ Word16 element_mode ); void E_ACELP_weighted_code( @@ -2306,27 +2324,27 @@ void find_targets_ivas_fx( ); void E_ACELP_adaptive_codebook( - Word16 *exc, /* i : pointer to the excitation frame */ - Word16 T0, /* i : integer pitch lag */ - Word16 T0_frac, /* i : fraction of lag */ - Word16 T0_res, /* i : pitch resolution */ - Word16 T0_res_max, /* i : maximum pitch resolution */ - Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) */ - Word16 i_subfr, /* i : subframe index */ - Word16 L_subfr, /* i : subframe length */ - Word16 L_frame, /* i : subframe length */ - Word16 *h1, /* i : impulse response of weighted synthesis filter */ - Word16 clip_gain, - Word16 *xn, /* i : Close-loop Pitch search target vector */ - Word16 *y1, /* o : zero-memory filtered adaptive excitation */ + Word16 *exc, /* i : pointer to the excitation frame Q_new */ + Word16 T0, /* i : integer pitch lag Q0 */ + Word16 T0_frac, /* i : fraction of lag Q0 */ + Word16 T0_res, /* i : pitch resolution Q0 */ + Word16 T0_res_max, /* i : maximum pitch resolution Q0 */ + Word16 mode, /* i : filtering mode (0: no, 1: yes, 2: adaptive) Q0 */ + Word16 i_subfr, /* i : subframe index */ + Word16 L_subfr, /* i : subframe length Q0 */ + Word16 L_frame, /* i : subframe length Q0 */ + Word16 *h1, /* i : impulse response of weighted synthesis filter 1Q14+shift */ + Word16 clip_gain, /* Q14 */ + Word16 *xn, /* i : Close-loop Pitch search target vector Q_xn */ + Word16 *y1, /* o : zero-memory filtered adaptive excitation Q_xn */ ACELP_CbkCorr *g_corr, /* o : ACELP correlation values */ Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *pitch_gain, /* o : adaptive codebook gain */ + Word16 *pitch_gain, /* o : adaptive codebook gain 1Q14 */ Word16 exp_xn, Word16 rf_mode, Word16 use_prev_sf_pit_gain, Word16 *lp_select ); -void E_ACELP_xy2_corr( Word16 xn[], Word16 y1[], Word16 y2[], ACELP_CbkCorr *g_corr, Word16 L_subfr, Word16 exp_xn ); +void E_ACELP_xy2_corr( Word16 xn[] /*Q_xn*/, Word16 y1[] /*Q_xn*/, Word16 y2[] /*Q9*/, ACELP_CbkCorr *g_corr, Word16 L_subfr /*Q0*/, Word16 exp_xn ); void gauss_L2_fx( const Word16 h[], /* i : weighted LP filter impulse response Q14+s */ @@ -2718,9 +2736,9 @@ void enc_prm_rf_fx( void enc_prm_rf_ivas_fx( Encoder_State *st, const Word16 rf_frame_type, const Word16 fec_offset ); -void E_ACELP_pulsesign( const Word16 cn[], Word16 dn[], Word16 dn2[], Word16 sign[], Word16 vec[], const Word16 alp, Word16 const sign_val, const Word16 L_subfr ); +void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 dn2[] /*Qdn2*/, Word16 sign[] /*Q13*/, Word16 vec[] /*Q15*/, const Word16 alp /*Q13*/, Word16 const sign_val /*Q15*/, const Word16 L_subfr /*Q0*/ ); -void E_ACELP_findcandidates( Word16 dn2[], Word16 dn2_pos[], Word16 pos_max[] ); +void E_ACELP_findcandidates( Word16 dn2[] /*Qx*/, Word16 dn2_pos[] /*Q0*/, Word16 pos_max[] /*Q0*/ ); void E_ACELP_setup_pulse_search_pos( const PulseConfig *config, /* i: pulse configuration */ @@ -3216,32 +3234,33 @@ void frame_spec_dif_cor_rate_fx( ); void est_energy_fx( - Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band */ - Word16 enerBuffer_exp, /* i : exponent of energy vector */ - Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly*/ - Word32 *frame_energy2_p, /* o : frame energy 2*/ - Word32 *HB_Power_p, /* o : high frequency energy*/ - Word32 *frame_energy_p, /* o : frame energy 1*/ - Word16 *sb_power_Q, /* o : the scaling of sb_power*/ - Word16 *frame_energy2_Q, /* o : the scaling of frame_energy*/ - Word16 *HB_Power_Q, /* o : the scaling of HB_Power*/ - Word16 *frame_energy_Q, /* o : the Scaling of frame_energy*/ - Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[]*/ - const Word32 bandwidth /* i : band width*/ + Word32 enerBuffer[CLDFB_NO_CHANNELS_MAX], /* i : energy vector per band enerBuffer_exp*/ + Word16 enerBuffer_exp, /* i : exponent of energy vector */ + Word32 *frame_sb_energy, /* o : energy of sub-band divided non-uniformly frame_sb_energy_scale*/ + Word32 *frame_energy2_p, /* o : frame energy 2 frame_energy2_Q*/ + Word32 *HB_Power_p, /* o : high frequency energy HB_Power_Q*/ + Word32 *frame_energy_p, /* o : frame energy 1 frame_energy_Q*/ + Word16 *sb_power_Q, /* o : the scaling of sb_power */ + Word16 *frame_energy2_Q, /* o : the scaling of frame_energy */ + Word16 *HB_Power_Q, /* o : the scaling of HB_Power */ + Word16 *frame_energy_Q, /* o : the Scaling of frame_energy */ + Word16 *frame_sb_energy_scale, /* o : the Scaling of frame_sb_energy[] */ + const Word32 bandwidth /* i : band width Q0*/ ); void background_update_fx( - VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ - Word16 scale, /* i : the scaling of frame energy*/ - Word32 frame_energy, /* i : current frame energy*/ - Word32 update_flag, /* i : update flag*/ - Word16 music_backgound_f, /* i : background music flag*/ - Word32 snr ); + VAD_CLDFB_HANDLE hVAD_CLDFB, /* i/o: CLDFB VAD state */ + Word16 scale, /* i : the scaling of frame energy */ + Word32 frame_energy, /* i : current frame energy scale*/ + Word32 update_flag, /* i : update flag Q0*/ + Word16 music_backgound_f, /* i : background music flag Q0*/ + Word32 snr /* Q25 */ +); /* enc_gain.c */ -Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], - Word16 xn[], - Word16 h[], +Word16 E_GAIN_closed_loop_search_fx( Word16 exc[], /*Q_new*/ + Word16 xn[], /*Q_xn*/ + Word16 h[], /* Q14+shift */ Word16 t0_min, Word16 t0_min_frac, Word16 t0_max, @@ -3526,16 +3545,16 @@ void analy_lp_AMR_WB_fx( void encod_amr_wb_fx( Encoder_State *st, /* i/o: state structure */ - const Word16 speech[], /* i : i speech */ - const Word16 Aw[], /* i : weighted A(z) unquantized for subframes */ - const Word16 Aq[], /* i : 12k8 Lp coefficient */ - const Word16 *res, /* i : residual signal */ - Word16 *syn, /* i/o: core synthesis */ - Word16 *exc, /* i/o: current non-enhanced excitation */ - Word16 *exc2, /* i/o: current enhanced excitation */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subframe */ - Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - const Word16 *speech16k_fx, /* i : i speech @16kHz */ + const Word16 speech[], /* i : i speech Q_new-1*/ + const Word16 Aw[], /* i : weighted A(z) unquantized for subframes Q12*/ + const Word16 Aq[], /* i : 12k8 Lp coefficient Q12*/ + const Word16 *res, /* i : residual signal Q_new*/ + Word16 *syn, /* i/o: core synthesis st->Q_syn*/ + Word16 *exc, /* i/o: current non-enhanced excitation Q_new*/ + Word16 *exc2, /* i/o: current enhanced excitation Q_new*/ + Word16 *pitch_buf, /* i/o: floating pitch values for each subframe Q6*/ + Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain Q0*/ + const Word16 *speech16k_fx, /* i : i speech @16kHz Qx*/ Word16 shift, Word16 Q_new ); @@ -3604,50 +3623,50 @@ void hf_cod_fx( void transf_cdbk_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter i response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + Word16 cn[], /* i/o: target vector in residual domain Q_new*/ + Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ + const Word16 h1[], /* i : weighted filter input response Q15*/ + Word16 xn[], /* i/o: target vector Q_new + shift -1*/ + Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ + const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ + const Word32 gain_code, /* i : innovative excitation gain Q16*/ + Word16 g_corr[], /* o : ACELP correlation values Q15*/ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ + Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ + Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ + Word16 *unbits, /* o : number of AVQ unused bits Q0*/ const Word16 Q_new, /* i : Current frame scaling */ const Word16 shift /* i : shifting applied to y1, xn,... */ ); void transf_cdbk_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter input response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ + const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP Q0*/ + const Word16 i_subfr, /* i : subframe index Q0*/ + Word16 cn[], /* i/o: target vector in residual domain Q_new*/ + Word16 exc[], /* i/o: pointer to excitation signal frame Q_new*/ + const Word16 *p_Aq, /* i : 12k8 Lp coefficient Q12*/ + const Word16 Ap[], /* i : weighted LP filter coefficients Q12*/ + const Word16 h1[], /* i : weighted filter input response Q15*/ + Word16 xn[], /* i/o: target vector Q_new + shift -1*/ + Word16 xn2[], /* i/o: target vector for innovation search Q_new + shift -1*/ + Word16 y1[], /* i/o: zero-memory filtered adaptive excitation Q_new + shift -1*/ + const Word16 y2[], /* i : zero-memory filtered innovative excitation Q9*/ + const Word16 Es_pred, /* i : predicited scaled innovation energy Q8*/ + Word16 *gain_pit, /* i/o: adaptive excitation gain Q14*/ + const Word32 gain_code, /* i : innovative excitation gain Q16*/ + Word16 g_corr[], /* o : ACELP correlation values Q15*/ + const Word16 clip_gain, /* i : adaptive gain clipping flag Q0*/ + Word16 *gain_preQ, /* o : prequantizer excitation gain Q2*/ + Word16 code_preQ[], /* o : prequantizer excitation Q_AVQ_OUT_DEC*/ + Word16 *unbits, /* o : number of AVQ unused bits Q0*/ const Word16 Q_new, /* i : Current frame scaling */ const Word16 shift /* i : shifting applied to y1, xn,... */ ); @@ -3830,30 +3849,6 @@ void transition_enc_ivas_fx( ); -void transf_cdbk_enc_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 harm_flag_acelp, /* i : harmonic flag for higher rates ACELP */ - const Word16 i_subfr, /* i : subframe index */ - Word16 cn[], /* i/o: target vector in residual domain */ - Word16 exc[], /* i/o: pointer to excitation signal frame */ - const Word16 *p_Aq, /* i : 12k8 Lp coefficient */ - const Word16 Ap[], /* i : weighted LP filter coefficients */ - const Word16 h1[], /* i : weighted filter i response */ - Word16 xn[], /* i/o: target vector */ - Word16 xn2[], /* i/o: target vector for innovation search */ - Word16 y1[], /* i/o: zero-memory filtered adaptive excitation */ - const Word16 y2[], /* i : zero-memory filtered innovative excitation */ - const Word16 Es_pred, /* i : predicited scaled innovation energy */ - Word16 *gain_pit, /* i/o: adaptive excitation gain */ - const Word32 gain_code, /* i : innovative excitation gain */ - Word16 g_corr[], /* o : ACELP correlation values */ - const Word16 clip_gain, /* i : adaptive gain clipping flag */ - Word16 *gain_preQ, /* o : prequantizer excitation gain */ - Word16 code_preQ[], /* o : prequantizer excitation */ - Word16 *unbits, /* o : number of AVQ unused bits */ - const Word16 Q_new, /* i : Current frame scaling */ - const Word16 shift /* i : shifting applied to y1, xn,... */ -); void gain_enc_tc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 gains_mode[], /* i : gain bits Q0*/ @@ -4013,20 +4008,20 @@ void enc_pit_exc_ivas_fx( Word16 Pit_exc_contribution_len_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ + const Word16 *dct_res, /* i : DCT of residual Qnew*/ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ + Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); Word16 Pit_exc_contribution_len_ivas_fx( /* o : bin where pitch contribution is significant */ Encoder_State *st_fx, /* i/o: state structure */ - const Word16 *dct_res, /* i : DCT of residual */ - Word16 *dct_pitex, /* i/o: DCT of pitch contribution */ - Word16 *pitch_buf, /* i/o: Pitch per subframe */ - const Word16 nb_subfr, /* i : Number of subframe considered */ - Word16 *hangover, /* i : hangover for the time contribution switching */ + const Word16 *dct_res, /* i : DCT of residual Qnew*/ + Word16 *dct_pitex, /* i/o: DCT of pitch contribution Qnew*/ + Word16 *pitch_buf, /* i/o: Pitch per subframe Q6*/ + const Word16 nb_subfr, /* i : Number of subframe considered Q0*/ + Word16 *hangover, /* i : hangover for the time contribution switching Q0*/ Word16 Qnew ); Word16 pvq_core_enc_fx( @@ -4343,7 +4338,7 @@ void InitSWBencBuffer_ivas_fx( void ResetSHBbuffer_Enc_fx( Encoder_State *st_fx /* i/o: SHB encoder structure */ ); -Word16 E_ACELP_hh_corr( Word16 *x, Word16 *y, Word16 L_subfr, Word16 bits ); +Word16 E_ACELP_hh_corr( Word16 *x /*Q11*/, Word16 *y /*Qy*/, Word16 L_subfr /*Q0*/, Word16 bits /*Q0*/ ); void acelp_1t64_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -4408,10 +4403,10 @@ Word16 acelp_4t64_ivas_fx( Word16 element_mode ); ivas_error evs_enc_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *data, /* i : i signal */ - Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory */ - const Word16 n_samples /* i : number of i samples */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 *data, /* i : input signal Q0*/ + Word32 *mem_hp20_in_fx, /* i/o: hp20 filter memory Qx*/ + const Word16 n_samples /* i : number of input samples Q0*/ ); /* y(n)(Qx) = alpha(Q15) * x(Qx) + (1.0f-alpha)* y(n-1) (Qx) */