Commit dc3a983f authored by vaclav's avatar vaclav
Browse files

Merge branch '2430-simplify-ivas_core_enc_fx' into 'main'

Simplify ivas_core_enc_fx()

Closes #2430

See merge request !2819
parents 486529f5 29ec64ac
Loading
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -2800,17 +2800,34 @@ void InternalTCXDecoder_fx(

void stereo_tcx_core_enc(
    Encoder_State *st,                                          /* i/o: encoder state structure                 */
#ifdef SIMPLIFY_CORE_ENC
    Word16 new_samples_12k8[],                                  /* i  : buffer of input signal @12.8 kHz        */
    Word16 new_samples_16k[],                                   /* i  : buffer of input signal @16 kHz          */
#else
    const Word16 new_samples_12k8[],                            /* i  : buffer of input signal @12.8 kHz        */
    const Word16 new_samples_16k[],                             /* i  : buffer of input signal @16 kHz          */
#endif
    const Word16 Aw_fx[],                                       /* i  : weighted A(z) unquant. for subframes,Q12*/
    Word16 lsp_new_fx[],                                        /* i  : LSPs at the end of the frame,    Q15    */
    Word16 lsp_mid_fx[],                                        /* i  : LSPs in the middle of the frame, Q15    */
    Word16 pitch_buf_fx[NB_SUBFR16k],                           /* o  : pitch for each subframe, Q6             */
    const Word16 last_element_mode,                             /* i  : last element mode, Q0                   */
    const Word16 vad_hover_flag,                                /* i  : VAD hangover flag, Q0                   */
#ifdef SIMPLIFY_CORE_ENC
    const Word16 Q_new_orig                                     /* i  : Scaling factor of new_samples_xx[]     */
#else
    Word16 Q_new
#endif
);

#ifdef SIMPLIFY_CORE_ENC
void stereo_tcx_enc_scale_buffers( 
    Encoder_State *st,                                          /* i/o: encoder state structure                 */
    const Word16 n_channels,                                    /* i  : number of core channels                 */
    const Word16 Q_spec_old                                     /* i  : Q of old spectrum                       */
);

#endif
Word16 transient_analysis_ivas_fx(
    TRAN_DET_HANDLE hTranDet,                                   /* i  : handle transient detection              */
    const Word16 cor_map_LT[],                                  /* i  : LT correlation map  Q_cor_map = Qx      */
@@ -5747,7 +5764,11 @@ void pre_proc_ivas_fx(
    const Word16 vad_hover_flag,                                /* i  : VAD hangover flag                                    Q0*/
    const Word16 flag_16k_smc,                                  /* i  : flag to indicate if the OL SMC is run at 16 kHz      Q0*/
    Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX],                /* i  : energy buffer                             e_enerBuffer */
#ifdef SIMPLIFY_CORE_ENC
    Word16 e_enerBuffer,                                        /* i  : Q value of energy buffer                               */
#else
    const Word16 e_enerBuffer,                                  /* i  : Q value of energy buffer                               */
#endif
    Word16 fft_buff_fx[2 * L_FFT],                              /* i  : FFT buffer                                           Qx*/
    const Word16 cor_map_sum_fx,                                /* i  : speech/music clasif. parameter                       Q8*/
    Word16 *Q_new                                               /* i/o: Q factor of speech buffers                             */
@@ -5816,8 +5837,8 @@ ivas_error ivas_core_enc_fx(
    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                                   */
    Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX],              /* i  : energy buffer                  enerBuffer_fx_exp*/
    Word16 enerBuffer_fx_exp[],                                 /* i  : 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*/
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
#define HARMONIZE_2499_CONFIGUREFDCNGDEC                /* FhG: basop issue 2499: harmonoize configureFdCngDec */
#define FIX_BASOP_2530_IVAS_DECISION_MAT                /* VA: Fix ambiguous usage of extract_l() */
#define SIMPLIFY_CORE_ENC                               /* VA: basop issue 2430: Simplify ivas_core_enc_fx() */
#define FIX_2402_SIMPLIFY_ARI_CODEC                     /* FhG: basop issue 2402: simplified arithmetic in TCX arithmetic coder */
#define FIX_2402_REPL_EVS_ARI_CODEC_ENC                 /* FhG: basop issue 2402: replace EVS arith encoder with IVAS arith encoder */
#define FIX_BASOP_2546_HARMONIZE_TCX_SCALAR             /* FhG: Fix issue 2546 Harmonize function tcx_scalar_quantization_rateloop*/
+25 −2
Original line number Diff line number Diff line
@@ -71,7 +71,11 @@ void HQ_core_enc_init_fx(

void hq_core_enc_fx(
    Encoder_State *st, /* i/o: encoder state structure                    */
#ifdef SIMPLIFY_CORE_ENC
    Word16 *audio_fx, /* i  : input audio signal                       Q0*/
#else
    const Word16 *audio_fx, /* i  : input audio signal                       Q0*/
#endif
    const Word16 input_frame_orig, /* i  : frame length                             Q0*/
    const Word16 hq_core_type,     /* i  : HQ core type                             Q0*/
    const Word16 Voicing_flag,     /* i  : Voicing flag for FER method selection    Q0*/
@@ -123,6 +127,25 @@ void hq_core_enc_fx(
    st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW;
    move16();

#ifdef SIMPLIFY_CORE_ENC
    /*--------------------------------------------------------------------------
     * Scaling of buffers
     *--------------------------------------------------------------------------*/

    IF( st->element_mode > EVS_MONO )
    {
        Scale_sig( audio_fx, input_frame, negate( st->q_inp ) ); // Q0
        st->q_inp = 0;
        move16();
        Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); // Q0
        st->q_old_inp = 0;
        move16();
        Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); // Q0
        st->hTcxEnc->q_Txnq = 0;
        move16();
    }

#endif
    /*--------------------------------------------------------------------------
     * Preprocessing in the first HQ frame after ACELP frame
     * Find the number of bits for PVQ coding
+55 −4
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ ivas_error ivas_core_enc_fx(
    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                                      */
    Word32 enerBuffer_fx[][CLDFB_NO_CHANNELS_MAX],                   /* i  : energy buffer                     enerBuffer_fx_exp*/
    Word16 enerBuffer_fx_exp[],                                      /* i  : 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*/
@@ -111,7 +111,11 @@ ivas_error ivas_core_enc_fx(
    Word16 diff_nBits;
    ivas_error error;
    Word16 max_num_indices_BWE;
#ifdef SIMPLIFY_CORE_ENC
    Word16 i, shift;
#else
    Word16 i, shift, Q_min;
#endif

    FOR( i = 0; i < CPE_CHANNELS; i++ )
    {
@@ -205,6 +209,7 @@ ivas_error ivas_core_enc_fx(
         * Pre-processing, incl. Decision matrix
         *---------------------------------------------------------------------*/

#ifndef SIMPLIFY_CORE_ENC
        IF( st->cldfbAnaEnc )
        {
            Word16 tmp_shift = L_norm_arr( enerBuffer_fx[n], st->cldfbAnaEnc->no_channels );
@@ -219,6 +224,7 @@ ivas_error ivas_core_enc_fx(

        Scale_sig( fft_buff_fx[n], ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum
                                                        // fft_buff_fx_exp = add(fft_buff_fx_exp,1);
#endif
        FOR( i = 0; i < st->nb_subfr; i++ )
        {
            Scale_sig( &Aw_fx[n][i * ( M + 1 )], M + 1, sub( norm_s( Aw_fx[n][i * ( M + 1 )] ), 2 ) ); // scaling to Q12
@@ -324,6 +330,10 @@ ivas_error ivas_core_enc_fx(
        test();
        IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
        {
            /* TCX core encoder */
#ifdef SIMPLIFY_CORE_ENC
            stereo_tcx_core_enc( st, old_inp_12k8_fx[n] + L_INP_MEM, old_inp_16k_fx[n] + L_INP_MEM, Aw_fx[n], lsp_new_fx[n], lsp_mid_fx[n], pitch_buf_fx[n], last_element_mode, vad_hover_flag[0], Q_new[n] );
#else
            TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
            Word16 Q_spec_old, L_spec;

@@ -344,7 +354,7 @@ ivas_error ivas_core_enc_fx(
            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;
            Q_spec_old = st->hTcxEnc->spectrum_long_e;
            move16();

            /* TCX core encoder */
@@ -387,11 +397,13 @@ ivas_error ivas_core_enc_fx(
            move16();
            hTcxEnc->spectrum_e[1] = hTcxEnc->spectrum_long_e;
            move16();
#endif
        }

        IF( EQ_16( st->core, HQ_CORE ) )
        {
            /* HQ core encoder */
#ifndef SIMPLIFY_CORE_ENC
            Scale_sig( st->input_fx, input_frame, negate( st->q_inp ) ); // Q0
            st->q_inp = 0;
            move16();
@@ -401,6 +413,7 @@ ivas_error ivas_core_enc_fx(
            Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); // Q0
            st->hTcxEnc->q_Txnq = 0;
            move16();
#endif
            hq_core_enc_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] );
        }

@@ -429,6 +442,9 @@ ivas_error ivas_core_enc_fx(
            {
                Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV];
                Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV];
#ifdef SIMPLIFY_CORE_ENC
                Word16 Q_spec_old[CPE_CHANNELS];
#else
                Word16 pitch_buf_fx_new[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */
                FOR( n = 0; n < n_CoreChannels; n++ )
                {
@@ -443,21 +459,38 @@ ivas_error ivas_core_enc_fx(
                    }
                }
                Word16 Q_spec_old[2], L_spec;
#endif
                Q_spec_old[0] = hCPE->hCoreCoder[0]->hTcxEnc->spectrum_long_e;
                move16();
                Q_spec_old[1] = hCPE->hCoreCoder[1]->hTcxEnc->spectrum_long_e;
                move16();

#ifdef SIMPLIFY_CORE_ENC
#ifndef NONBE_FIX_ISSUE_2206
                ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id],
                                                 hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e );
#else
#ifdef NONBE_FIX_ISSUE_2206_MDCT_STEREO_FIX_2549
                ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, Q_new, old_wsp_fx, pitch_buf_fx, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id],
                                                 hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e );
#else
                ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id],
                                                 hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e );
#endif
#endif
#else
#ifdef NONBE_FIX_ISSUE_2206_MDCT_STEREO_FIX_2549
                ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, Q_new, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id],
                                                 hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e );
#else
                ivas_mdct_core_whitening_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long_fx[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long_fx[cpe_id],
                                                 hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE, mdst_spectrum_e, orig_spectrum_e );
#endif
#endif

                FOR( i = 0; i < CPE_CHANNELS; i++ )
                {
#ifndef SIMPLIFY_CORE_ENC
                    st = sts[i];
                    Word16 nSubframes = NB_DIV;
                    move16();
@@ -469,16 +502,22 @@ ivas_error ivas_core_enc_fx(
                        nSubframes = 1;
                        move16();
                    }

#endif
                    hMCT->q_mdst_spectrum_long_fx[cpe_id][i][0] = sub( Q31, mdst_spectrum_e[i][0] );
                    move16();
#ifdef SIMPLIFY_CORE_ENC
                    IF( NE_16( sts[i]->hTcxEnc->tcxMode, TCX_20 ) )
#else
                    IF( EQ_16( nSubframes, NB_DIV ) )
#endif
                    {
                        hMCT->q_mdst_spectrum_long_fx[cpe_id][i][1] = sub( Q31, mdst_spectrum_e[i][1] );
                        move16();
#ifndef SIMPLIFY_CORE_ENC
                    }
                    IF( EQ_16( nSubframes, NB_DIV ) )
                    {
#endif
                        Word16 max_e = s_max( orig_spectrum_e[i][0], orig_spectrum_e[i][1] );
                        scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i], N_TCX10_MAX, sub( orig_spectrum_e[i][0], max_e ) );               // exp(max_e)
                        scale_sig32( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, N_TCX10_MAX, sub( orig_spectrum_e[i][1], max_e ) ); // exp(max_e)
@@ -491,6 +530,9 @@ ivas_error ivas_core_enc_fx(
                        move16();
                    }

#ifdef SIMPLIFY_CORE_ENC
                    stereo_tcx_enc_scale_buffers( sts[i], CPE_CHANNELS, Q_spec_old[i] );
#else
                    IF( EQ_16( st->hTcxEnc->tcxMode, TCX_20 ) )
                    {
                        Word16 e_max = s_max( st->hTcxEnc->spectrum_e[0], Q_spec_old[i] );
@@ -521,10 +563,18 @@ ivas_error ivas_core_enc_fx(
                    move16();
                    st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_long_e;
                    move16();
#endif
                }
            }
            ELSE
            {
#ifdef SIMPLIFY_CORE_ENC
#if !defined( NONBE_FIX_ISSUE_2206 ) || defined( NONBE_FIX_ISSUE_2206_MDCT_STEREO_FIX_2549 )
                stereo_mdct_core_enc_fx( hCPE, old_inp_16k_fx, Q_new, old_wsp_fx, pitch_buf_fx );
#else
                stereo_mdct_core_enc_fx( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx );
#endif
#else
                FOR( i = 0; i < CPE_CHANNELS; i++ )
                {
                    st = sts[i];
@@ -606,6 +656,7 @@ ivas_error ivas_core_enc_fx(
                    st->hTcxEnc->spectrum_e[1] = st->hTcxEnc->spectrum_long_e;
                    move16();
                }
#endif
            }
        }
        ELSE IF( EQ_32( sts[0]->core_brate, SID_2k40 ) && EQ_32( sts[1]->core_brate, SID_2k40 ) )
+29 −4
Original line number Diff line number Diff line
@@ -81,7 +81,11 @@ void pre_proc_ivas_fx(
    const Word16 vad_hover_flag,                 /* i  : VAD hangover flag                                  Q0*/
    const Word16 flag_16k_smc,                   /* i  : flag to indicate if the OL SMC is run at 16 kHz    Q0*/
    Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX], /* i  : energy buffer                             e_enerBuffer */
#ifdef SIMPLIFY_CORE_ENC
    Word16 e_enerBuffer, /* i  : Q value of energy buffer                               */
#else
    const Word16 e_enerBuffer, /* i  : Q value of energy buffer                               */
#endif
    Word16 fft_buff_fx[2 * L_FFT], /* i  : FFT buffer                                           Qx*/
    const Word16 cor_map_sum_fx,   /* i  : speech/music clasif. parameter                       Q8*/
    Word16 *Q_new                  /* i/o: Q factor of speech buffers                             */
@@ -94,6 +98,27 @@ void pre_proc_ivas_fx(

    push_wmops( "pre_proc" );

#ifdef SIMPLIFY_CORE_ENC
    /*----------------------------------------------------------------*
     * Scaling of buffers
     *----------------------------------------------------------------*/

    IF( st->cldfbAnaEnc )
    {
        Word16 tmp_shift = L_norm_arr( enerBuffer_fx, st->cldfbAnaEnc->no_channels );
        tmp_shift = sub( tmp_shift, 5 );
        IF( tmp_shift < 0 )
        {
            scale_sig32( enerBuffer_fx, st->cldfbAnaEnc->no_channels, tmp_shift ); /* enerBuffer_fx_exp[n] - tmp_shift */
            e_enerBuffer = sub( e_enerBuffer, tmp_shift );
            move16();
        }
    }

    Scale_sig( fft_buff_fx, ( 2 * L_FFT ), -1 ); // To create 1 headroom for addition of magnitude square spectrum
                                                 // fft_buff_fx_exp = add(fft_buff_fx_exp,1);
#endif

    /*----------------------------------------------------------------*
     * Initialization
     *----------------------------------------------------------------*/
Loading