Commit 15873556 authored by vaclav's avatar vaclav
Browse files

FIX_2344_ALIGN_PREPROC

parent 2997f3e6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5870,8 +5870,8 @@ ivas_error ivas_compute_core_buffers_fx(
    Word32 epsP[M + 1],                                         /* i/o: LP prediction errors                     */
    Word16 lsp_new_fx[M],                                       /* i/o: LSPs at the end of the frame             */
    Word16 lsp_mid_fx[M],                                       /* i/o: LSPs in the middle of the frame          */
    Word16 Q_old_inp_16k,
    Word16 Q_r[2],
    const Word16 Q_old_inp_16k,
    const Word16 Q_r[2],
    Word16 *Q_new 
);

+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define OPT_BE_2311_HARM_GSC_GAIN                       /* VA: issue 2311: BE part of the GSC gain harmonization pipeline #70380 shows the BE */
#define HARM_CORECODER_UPDT                             /* VA: basop issue 2342: Remove duplicated code in core-coder common update functions */
#define HARM_CORE_SW                                    /* VA: basop issue 2314: Remove duplicated code in the core switching */
#define FIX_2344_ALIGN_PREPROC                          /* VA: basop issue 2344: Align pre_proc_ivas() between FLP and BASOP */

/* #################### End BE switches ################################## */

+20 −0
Original line number Diff line number Diff line
@@ -230,6 +230,24 @@ ivas_error ivas_core_enc_fx(
#endif
            Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12
        }

#ifdef FIX_2344_ALIGN_PREPROC
        Word32 last_element_brate_tmp = last_element_brate;
        move32();
        IF( EQ_32( ivas_format, SBA_FORMAT ) )
        {
            last_element_brate_tmp = element_brate;
            move32();
        }

        IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate_tmp, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */,
                                               &inp_fx[n], &ener_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], new_inp_resamp16k_fx[n], &Voicing_flag[n], old_wsp_fx[n], e_old_wsp[n], loc_harm[n],
                                               vad_flag_dtx[n], MCT_flag, vad_hover_flag[n], flag_16k_smc, enerBuffer_fx[n], enerBuffer_fx_exp[n], fft_buff_fx[n], cor_map_sum_fx[n], &Q_new[n] ) ),
                   IVAS_ERR_OK ) )
        {
            return error;
        }
#else
        IF( EQ_32( ivas_format, SBA_FORMAT ) )
        {
            IF( NE_32( ( error = pre_proc_ivas_fx( st, last_element_mode, element_brate, last_element_brate, input_frame, old_inp_12k8_fx[n] /* i: -1, o: Q_new - 1 */, old_inp_16k_fx[n] /* i: -1, o: Q_new - 1 */,
@@ -250,6 +268,8 @@ ivas_error ivas_core_enc_fx(
                return error;
            }
        }
#endif

        test();
        IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) || EQ_16( st->element_mode, IVAS_SCE ) )
        {
+124 −21
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ ivas_error pre_proc_ivas_fx(
        lMemRecalc_12k8 = NS2SA( INT_FS_12k8, L_MEM_RECALC_NS );
        move16();
    }

    /*----------------------------------------------------------------*
     * Selection of internal ACELP Fs (12.8 kHz or 16 kHz)
     *----------------------------------------------------------------*/
@@ -163,6 +164,26 @@ ivas_error pre_proc_ivas_fx(
        move16();
    }

#ifdef FIX_2344_ALIGN_PREPROC
    IF( EQ_16( st->L_frame, L_FRAME16k ) )
    {
        total_brate_tmp = ACELP_16k40;
        move16();
    }
    ELSE
    {
        total_brate_tmp = ACELP_9k60;
        move16();
    }

    test();
    test();
    test();
    IF( st->hFdCngEnc != NULL && NE_16( st->element_mode, IVAS_CPE_MDCT ) && ( ( NE_16( st->hFdCngEnc->hFdCngCom->frameSize, st->L_frame ) ) || ( NE_16( st->hFdCngEnc->hFdCngCom->CngBandwidth, st->input_bwidth ) ) ) )
    {
        configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), total_brate_tmp );
    }
#else
    test();
    test();
    test();
@@ -182,6 +203,7 @@ ivas_error pre_proc_ivas_fx(
    {
        configureFdCngEnc_ivas_fx( st->hFdCngEnc, s_max( st->input_bwidth, WB ), flag_1 );
    }
#endif

    if ( st->ini_frame == 0 )
    {
@@ -224,6 +246,7 @@ ivas_error pre_proc_ivas_fx(
     * IC frames selection
     * enforce TC frames in case of switching
     *-----------------------------------------------------------------*/

    test();
    test();
    test();
@@ -284,7 +307,6 @@ ivas_error pre_proc_ivas_fx(
        move16();
    }


    /*---------------------------------------------------------------------*
     * Decision matrix (selection of technologies)
     *---------------------------------------------------------------------*/
@@ -305,6 +327,7 @@ ivas_error pre_proc_ivas_fx(

    /* core selection */
    ivas_decision_matrix_enc_fx( st, element_brate, fft_buff_fx, enerBuffer_fx, e_enerBuffer, last_element_mode );

    test();
    test();
    if ( EQ_16( st->L_frame, L_FRAME16k ) && ( EQ_16( st->coder_type, VOICED ) || EQ_16( st->coder_type, UNVOICED ) ) ) /* VOICED and UNVOICED are not supported in ACELP@16k */
@@ -396,14 +419,14 @@ ivas_error pre_proc_ivas_fx(
        }
    }


    /*-----------------------------------------------------------------*
     * Update of ACELP harmonicity counter (used in ACELP transform codebook @32kbps)
     *-----------------------------------------------------------------*/

    test();
    test();
    test();
    IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << 8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) )
    IF( EQ_16( loc_harm, 1 ) && GT_16( cor_map_sum_fx, 50 << Q8 ) && EQ_16( st->clas, VOICED_CLAS ) && EQ_16( st->coder_type, GENERIC ) )
    {
        st->last_harm_flag_acelp = add( st->last_harm_flag_acelp, 1 ); /* Q0 */
        move16();
@@ -471,6 +494,7 @@ ivas_error pre_proc_ivas_fx(
        }
    }

#ifndef FIX_2344_ALIGN_PREPROC
    /* channel-aware mode - due to lack of signaling bit, sharpFlag is 1 always in RF mode */
    test();
    test();
@@ -479,7 +503,7 @@ ivas_error pre_proc_ivas_fx(
        st->sharpFlag = 1;
        move16();
    }

#endif
    /* TD stereo, secondary channel - due to lack of signaling bits, sharpFlag is always 1 */
    test();
    IF( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) )
@@ -514,6 +538,7 @@ ivas_error pre_proc_ivas_fx(
    /*-----------------------------------------------------------------*
     * Compute core-coder buffers at internal sampling rate
     *-----------------------------------------------------------------*/

    IF( st->tcxonly == 0 )
    {
        sr_core_tmp = INT_FS_16k;
@@ -567,16 +592,28 @@ ivas_error pre_proc_ivas_fx(
    move16();
    st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k );
    move16();
#ifndef FIX_2344_ALIGN_PREPROC
    Word16 Q_inp_12k8 = *Q_new;
    move16();
    Word16 Q_inp_16k = *Q_new;
    move16();
#endif

    IF( !flag_16k_smc )
    {
        error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx,
                                              A_fx, Aw_fx,
                                              epsP_fx,
                                              lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k );
#ifdef FIX_2344_ALIGN_PREPROC
        Word16 Q_inp_12k8 = *Q_new;
        move16();
        Word16 Q_inp_16k;
#endif
        error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, A_fx, Aw_fx, epsP_fx, lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, &Q_inp_16k );
#ifdef FIX_2344_ALIGN_PREPROC
        IF( error != IVAS_ERR_OK )
        {
            return error;
        }
#endif

        IF( GT_16( Q_inp_16k, Q_inp_12k8 ) )
        {
            Scale_sig( old_inp_16k_fx, L_INP, sub( Q_inp_12k8, Q_inp_16k ) );
@@ -589,11 +626,12 @@ ivas_error pre_proc_ivas_fx(
        }
        move16();

#ifndef FIX_2344_ALIGN_PREPROC
        IF( error != IVAS_ERR_OK )
        {
            return error;
        }

#endif
        test();
        IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
        {
@@ -601,6 +639,7 @@ ivas_error pre_proc_ivas_fx(
            move16();
        }
    }

    test();
    IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) )
    {
@@ -681,11 +720,13 @@ ivas_error pre_proc_ivas_fx(
    return error;
}


/*-------------------------------------------------------------------*
 * ivas_compute_core_buffers()
 *
 * Compute core-coder buffers at internal sampling rate
 *--------------------------------------------------------------------*/

ivas_error ivas_compute_core_buffers_fx(
    Encoder_State *st,                     /* i/o: encoder state structure                  */
    Word16 **inp16k_out_fx,                /* o  : ptr. to inp. signal in the current frame Q_new-1*/
@@ -700,8 +741,8 @@ ivas_error ivas_compute_core_buffers_fx(
    Word32 epsP_fx[M + 1],                 /* i/o: LP prediction errors                     Q_r*/
    Word16 lsp_new_fx[M],                  /* i/o: LSPs at the end of the frame             Q15*/
    Word16 lsp_mid_fx[M],                  /* i/o: LSPs in the middle of the frame          Q15*/
    Word16 Q_old_inp_16k,
    Word16 Q_r[2],
    const Word16 Q_old_inp_16k,
    const Word16 Q_r[2],
    Word16 *Q_new )
{
    Word16 *inp_16k_fx, *new_inp_16k_fx;
@@ -716,19 +757,28 @@ ivas_error ivas_compute_core_buffers_fx(
    Word16 Q_tmp, mem_decim16k_size, size_modified;
    Word16 epsP_h[M + 1];
    Word16 epsP_l[M + 1];

#ifdef FIX_2344_ALIGN_PREPROC
    Word16 i, shift, Q_min;
    Word16 preemp_len, inp_max;
#else
    Word16 headroom = 1, preemp_len = 0, inp_max = 0;
    move16();
    move16();
    move16();
#endif
    Word16 *preemp_start_idx = NULL;
#ifdef FIX_2344_ALIGN_PREPROC
    Word32 sig_out[STEREO_DFT_OVL_16k + L_FRAME16k /* = max( L_FRAME16k + STEREO_DFT_OVL_16k, L_FRAME16k + L_FILT16k + lMemRecalc_16k ) */], max_32;
#else
    Word32 sig_out[960], max_32;
    /*Word16 Q_exp, Q_wsp_exp*/;
#endif

#ifndef FIX_2344_ALIGN_PREPROC
    set16_fx( new_inp_resamp16k_fx, 0, L_FRAME16k );
    set16_fx( epsP_h, 0, M + 1 );
    set16_fx( epsP_l, 0, M + 1 );
    set16_fx( input_buf_fx, 0, L_FRAME48k * 2 );

#endif
    Copy_Scale_sig( st->input_fx - input_frame, input_buf_fx, input_frame, sub( -1, st->q_old_inp ) );
    Copy_Scale_sig( st->input_fx, input_buf_fx + input_frame, input_frame, sub( -1, st->q_inp ) );

@@ -754,9 +804,9 @@ ivas_error ivas_compute_core_buffers_fx(
    /*---------------------------------------------------------------*
     * Preprocessing at other sampling frequency rate (16/25.6/32kHz)
     *----------------------------------------------------------------*/

    IF( st->tcxonly == 0 )
    {

        L_frame_tmp = L_FRAME16k;
        move16();
    }
@@ -845,14 +895,23 @@ ivas_error ivas_compute_core_buffers_fx(
                Scale_sig( new_inp_16k_fx - lMemRecalc_16k - length_16k, size_modified, negate( Q_tmp ) );                                                                                                                    /* scaling back to Q_old_inp_16k */
            }

#ifdef FIX_2344_ALIGN_PREPROC
            size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - lMemRecalc_16k, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */
            Scale_sig( new_inp_16k_fx - lMemRecalc_16k, size_modified, negate( Q_tmp ) );                                                                                                        /* scaling back to Q_old_inp_16k */
#else
            size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc, input_frame, input_Fs, new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, st->mem_decim16k_fx, 0, &Q_tmp, &mem_decim16k_size );                                                          /* Q0 */
            Scale_sig( new_inp_16k_fx - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) );                                                                                                                                                                 /* scaling back to Q_old_inp_16k */
#endif
            Copy( st->mem_decim16k_fx, mem_decim16k_dummy_fx, 2 * L_FILT_MAX );

            IF( lMemRecalc > 0 )
            {
#ifdef FIX_2344_ALIGN_PREPROC
                size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */
                Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - lMemRecalc_16k, size_modified, negate( Q_tmp ) );                                                                                                                       /* scaling back to Q_old_inp_16k */
#else
                size_modified = modify_Fs_ivas_fx( signal_in_fx - lMemRecalc + input_frame, lMemRecalc, input_Fs, new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, sr_core, mem_decim16k_dummy_fx, 0, &Q_tmp, &mem_decim16k_size ); /* Q0 */
                Scale_sig( new_inp_16k_fx + NS2SA_FX2( sr_core, FRAME_SIZE_NS ) - ( lMemRecalc * sr_core ) / st->input_Fs, size_modified, negate( Q_tmp ) );                                                                                                                       /* scaling back to Q_old_inp_16k */
#endif
            }

            set16_fx( temp1F_icatdmResampBuf_fx, 0, L_FILT_MAX );
@@ -936,6 +995,7 @@ ivas_error ivas_compute_core_buffers_fx(
        move16();
    }

#ifndef FIX_2344_ALIGN_PREPROC
    test();
    test();

@@ -948,10 +1008,21 @@ ivas_error ivas_compute_core_buffers_fx(
    {
        headroom = add( headroom, 1 );
    }

#endif
    test();
#ifdef FIX_2344_ALIGN_PREPROC
    IF( EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
#else
    test();
    IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
#endif
    {
#ifdef FIX_2344_ALIGN_PREPROC
        preemp_len = 0;
        move16();
#endif

        IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
        {
            Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching    Q(-1) */
@@ -1037,8 +1108,11 @@ ivas_error ivas_compute_core_buffers_fx(
        maximum_abs_32_fx( sig_out, preemp_len, &max_32 );
        inp_max = s_max( extract_h( max_32 ), 1 );

#ifdef FIX_2344_ALIGN_PREPROC
        shift = sub( norm_s( inp_max ), 1 /* headroom */ );
#else
        Word16 shift = sub( norm_s( inp_max ), headroom );
        Word16 Q_min, i;
#endif
        shift = s_max( shift, 0 );
        shift = s_min( shift, Q_MAX );
        minimum_fx( st->Q_max_16k, L_Q_MEM, &Q_min );
@@ -1063,8 +1137,13 @@ ivas_error ivas_compute_core_buffers_fx(
        Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, add( *Q_new, 1 ) );
        Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new );
    }
#ifdef FIX_2344_ALIGN_PREPROC
    ELSE /* keep memory up-to-date in case of bitrate switching */
#else
    ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */
#endif
    {
#ifndef FIX_2344_ALIGN_PREPROC
        IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
        {
            st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; /* Q_new - 1 */
@@ -1075,7 +1154,9 @@ ivas_error ivas_compute_core_buffers_fx(
            st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; /* Q_new - 1 */
            move16();
        }
        ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) )
        ELSE
#endif
        IF( EQ_16( element_mode, IVAS_CPE_MDCT ) )
        {
            st->mem_preemph16k_fx = 0;
            move16();
@@ -1098,7 +1179,9 @@ ivas_error ivas_compute_core_buffers_fx(
    IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
    {
        /* update signal buffers */
#ifndef FIX_2344_ALIGN_PREPROC
        Word16 shift;
#endif
        shift = negate( *Q_new );
        move16();
        IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
@@ -1134,6 +1217,14 @@ ivas_error ivas_compute_core_buffers_fx(
            analy_lp_fx( inp_16k_fx, L_FRAME16k, L_look, ener_fx, A_fx, epsP_h, epsP_l, lsp_new_fx, lsp_mid_fx, st->lspold_enc_fx, st->pitch, st->voicing_fx, INT_FS_16k, element_mode, 0, -1, Q_r );
        }

#ifdef FIX_2344_ALIGN_PREPROC
        FOR( i = 0; i < M + 1; i++ )
        {
            epsP_fx[i] = L_Comp( epsP_h[i], epsP_l[i] );
            move32();
        }

#endif
        /*--------------------------------------------------------------*
         * Compute Weighted Input
         *---------------------------------------------------------------*/
@@ -1148,20 +1239,30 @@ ivas_error ivas_compute_core_buffers_fx(
    /* update old input signal @16kHz buffer */
    test();
    test();
#ifndef FIX_2344_ALIGN_PREPROC
    test();
#endif
    IF( ( EQ_16( element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) || EQ_16( element_mode, IVAS_CPE_MDCT ) )
    {
        set16_fx( st->old_inp_16k_fx, 0, L_INP_MEM );
        st->exp_old_inp_16k = 0;
        move16();
    }
#ifdef FIX_2344_ALIGN_PREPROC
    ELSE IF( EQ_32( sr_core, INT_FS_16k ) )
#else
    ELSE IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) )
#endif
    {
        Copy( &old_inp_16k_fx[L_frame_tmp], st->old_inp_16k_fx, L_INP_MEM );
        st->exp_old_inp_16k = sub( Q16, *Q_new ); //(*Q_new - 1)
        move16();
    }
#ifdef FIX_2344_ALIGN_PREPROC
    ELSE
#else
    ELSE IF( GT_32( input_Fs, 8000 ) )
#endif
    {
        lerp( st->old_inp_12k8_fx + L_INP_MEM - L_INP_MEM * 4 / 5, st->old_inp_16k_fx, L_INP_MEM, L_INP_MEM * 4 / 5 );
        Scale_sig( st->old_inp_16k_fx, L_INP_MEM, sub( -1 /* Q st->old_inp_16k_fx = -1 */, sub( 15, st->exp_old_inp_12k8 ) ) );
@@ -1178,6 +1279,8 @@ ivas_error ivas_compute_core_buffers_fx(
    {
        Copy( new_inp_resamp16k_fx, new_inp_resamp16k_out_fx, L_FRAME16k );
    }

#ifndef FIX_2344_ALIGN_PREPROC
    test();
    IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) )
    {
@@ -1187,6 +1290,6 @@ ivas_error ivas_compute_core_buffers_fx(
            move32();
        }
    }

#endif
    return IVAS_ERR_OK;
}