Commit 69f80188 authored by Devansh Kandpal's avatar Devansh Kandpal
Browse files

Merge branch 'main' of https://forge.3gpp.org/rep/sa4/audio/ivas-basop into 1863_basop_port_fl1678

parents 55714b3b 6d538ee3
Loading
Loading
Loading
Loading
Loading
+48 −49
Original line number Diff line number Diff line
@@ -6198,7 +6198,7 @@ ivas_error ivas_core_enc_fx(
    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[],
    Word16 Q_new[],                                             /* i  : Q factor of speech buffers              */
    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*/
@@ -6210,9 +6210,9 @@ ivas_error ivas_core_enc_fx(
    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 *q_re_im_buf,                                        /* i  : Q factor of re/in CLDFB buffers         */
    Word16 old_wsp_fx[][L_WSP],                                 /* i  : weighted input signal buffer            e_old_wsp*/
    Word16 e_old_wsp[],
    Word16 e_old_wsp[],                                         /* i  : Q factor of old_wsp buffer              */
    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*/
@@ -6308,12 +6308,11 @@ ivas_error ivas_ism_metadata_enc_create_fx(
    Word32 element_brate_tmp[]                                  /* o  : element bitrate per object                  */
);


/*----------------------------------------------------------------------------------*
 * Parametric ISM prototypes
 *----------------------------------------------------------------------------------*/

/*! r: ISM format mode */

ivas_error ivas_param_ism_enc_open_fx(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder structure                      */
);
@@ -6328,11 +6327,11 @@ void ivas_ism_metadata_close(
    const Word16 first_idx                                      /* i  : index of first handle to deallocate         */
);


ivas_error ivas_ism_enc_config(
    Encoder_Struct *st_ivas                                     /* i/o: IVAS encoder structure                      */
);


/*----------------------------------------------------------------------------------*
 * ISM DTX prototypes
 *----------------------------------------------------------------------------------*/
+20 −0
Original line number Diff line number Diff line
@@ -89,6 +89,24 @@


#define FIX_1931_BIN_COHR_CROSS_MIX                    /* FhG: correct binauralCoherenceCrossmixGains_fx calculation */

#define EVS_BE_REUSAGE
#ifdef EVS_BE_REUSAGE
#define REUSE_EVS_BE_ACELP_LP_FILT
#define REUSE_EVS_BE_ACELP_4T64
#define REUSE_EVS_BE_ACELP_2t32
#define REUSE_EVS_BE_ACELP_1t64
#define REUSE_EVS_BE_ACELP_AVQ
#define REUSE_EVS_BE_GAUSS          
#define REUSE_EVS_BE_GAINQ          
#define REUSE_EVS_BE_ACELP_PITCH
#define REUSE_EVS_BE_ACELP_PITCH_PIT_Q
#define REUSE_EVS_BE_GAINQ_LBR   // BE by adding one condition, but could be harmonized in a non-BE way. There is a small difference in how Etot is computed

#endif
#define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW  /* FhG: bit-exact, replace carry and overflow operations by 64-bit operations, MR 1931 */
#define FIX_1844_MISSING_FREE                                /* FhG: add missing free in ivas_binRenderer_convModuleClose_fx() */

/* #################### Start BASOP porting switches ############################ */

#define FIX_1372_ISAR_POST_REND
@@ -140,11 +158,13 @@
#define NONBE_1229_FIX_ISM1_DPID                        /* Eri: issue 1229: fix bug causing ISM 1 to use default -dpid instead of the specified one */
#define FIX_1135_EXT_RENDERER_HANDLES                   /* VA: issue 1135: Memory usage reduction in external renderer: Allocate only handles that are really needed. */
#define FIX_1209_SID_SIGNALING                          /* VA: issue 1209: remove dead code in IVAS SID signaling */
#define NONBE_1250_MCMASA_LS_OUTPUT                     /* VA: issue 1250: fix crash in McMASA to custom LS output decoding */
#define NONBE_FIX_1176_OSBA_REVERB_JBM_ASAN_ERROR       /* Ericsson: Issue 1176, fix in TDREND_firfilt for subframes shorter than the filter length */
#define NONBE_1131_ACELP_OOB                            /* VA: issue 1131: fix division-by-zero in acelp gain decoding caused by wrong length of buffer update when switching from HQ core to ACELP core */
#define NONBE_1240_FIX_CORE_SELECTION_ISM_SW            /* VA: issue 1240: Remove the forcing of the TCX core in ISM when switching from a high bitarte to a low one */
#define FIX_1101_CLEANING_JBM_CALL                      /* VA: issue 1101: remove obsolete call of ivas_jbm_dec_tc_buffer_open() */
#define FIX_VOIP_FUNCTIONS                              /* VA: fix data type mismatch in IVAS_DEC_VoIP_SetScale() + add sanity checks to API functions */
#define FIX_1298_MEMORY_OPT_IVAS_CORE_ENC               /* VA: issue 1298: Memory saving in ivas_core_enc() */
#define NONBE_FIX_1337_MISSING_DIRECTIVITY_DISTATT_EXTREND /* Eri: issue 1337: Missing directivity setting and distance attenuation in external renderer IVAS_rend */
#define NONBE_1214_PLC_LSF_MEMORY                       /* VA: issue 1224: reset ACELP PLC FEC memory in case of switching from MDCT stereo to TD/DFT stereo */
#define NONBE_1293_SR_HRTF                              /* VA: issue 1293: add support of external HRTFs in split rendering */
+8 −0
Original line number Diff line number Diff line
@@ -4006,7 +4006,15 @@ void ivas_dirac_dec_render_sf_fx(

            /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */
            Copy32( &( output_buf_fx[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated_fx, num_samples_subframe );
#ifdef NONBE_1250_MCMASA_LS_OUTPUT
            if ( hDirACRend->hOutSetup.num_lfe > 0 )
            {
                Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
            }
#else
            Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe );
#endif

            FOR( ch = 0; ch < outchannels; ch++ )
            {

+35 −8
Original line number Diff line number Diff line
@@ -412,7 +412,12 @@ static void encod_gen_voic_core_switch_fx(
     *----------------------------------------------------------------*/
    set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */
    pitch = pit_encode_fx( hBstr,
                           st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/ ); /* Q6 */
                           st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/
#if defined REUSE_EVS_BE_ACELP_PITCH && !defined REUSE_EVS_ACELP_PITCH_NORM_CORR
                           ,
                           st_fx->element_mode, Q_new
#endif
    ); /* Q6 */

    /*-----------------------------------------------------------------*
     * Find adaptive exitation
@@ -618,10 +623,18 @@ static void encod_gen_voic_core_switch_ivas_fx(
     * Adaptive exc. construction
     *----------------------------------------------------------------*/
    set16_fx( dummyF, -1, NB_SUBFR16k ); /* hack to signal ACELP->HQ switching frame */

#ifndef REUSE_EVS_BE_ACELP_PITCH
    pitch = pit_encode_ivas_fx( hBstr,
                                st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/, Q_new ); /* Q6 */

#else
    pitch = pit_encode_fx( hBstr,
                           st_fx->acelp_cfg.pitch_bits, core_bitrate, 0, L_frame, GENERIC, &pitch_limit_flag, 0, exc, L_SUBFR, T_op, &T0_min, &T0_max, &T0, &T0_frac, h1, xn, 0 /*hStereoTD->tdm_Pitch_reuse_flag*/, dummyF /*hStereoTD->tdm_Pri_pitch_buf*/
#if defined REUSE_EVS_BE_ACELP_PITCH && !defined REUSE_EVS_ACELP_PITCH_NORM_CORR
                           ,
                           st_fx->element_mode, Q_new
#endif
    );                                                                                                                                        /* Q6 */
#endif
    /*-----------------------------------------------------------------*
     * Find adaptive exitation
     *-----------------------------------------------------------------*/
@@ -640,8 +653,11 @@ static void encod_gen_voic_core_switch_ivas_fx(
     *-----------------------------------------------------------------*/
    lp_flag = st_fx->acelp_cfg.ltf_mode;       /* Q0 */
    Scale_sig( h1, L_SUBFR, sub( 14, q_h1 ) ); /* set h1[] in Q14 with scaling for convolution Q14+shift*/
#ifdef REUSE_EVS_BE_ACELP_LP_FILT
    lp_select = lp_filt_exc_enc_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */
#else
    lp_select = lp_filt_exc_enc_ivas_fx( MODE1, GENERIC, 0, exc, h1, xn, y1, xn2, L_SUBFR, L_frame, g_corr, clip_gain, &gain_pit, &lp_flag ); /* Q0 */

#endif
    IF( EQ_16( lp_flag, NORMAL_OPERATION ) )
    {
        push_indice( hBstr, IND_LP_FILT_SELECT, lp_select, 1 );
@@ -657,6 +673,7 @@ static void encod_gen_voic_core_switch_ivas_fx(
    /*-----------------------------------------------------------------*
     * Gain encoding
     *-----------------------------------------------------------------*/
#ifndef REUSE_EVS_BE_GAINQ
    IF( EQ_16( L_frame, L_FRAME ) )
    {
        gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
@@ -667,7 +684,18 @@ static void encod_gen_voic_core_switch_ivas_fx(
        gain_enc_mless_ivas_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                                &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }

#else
    IF( EQ_16( L_frame, L_FRAME ) )
    {
        gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                           &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }
    ELSE
    {
        gain_enc_mless_fx( hBstr, st_fx->acelp_cfg.gains_mode, st_fx->element_mode, L_frame, 0, -1, xn, y1, shift_wsp, y2, code, st_fx->old_Es_pred_fx,
                           &gain_pit, &gain_code, &gain_inov, &norm_gain_code, g_corr, clip_gain );
    }
#endif
    gp_clip_test_gain_pit_fx( st_fx->element_mode, core_bitrate, gain_pit, st_fx->clip_var_fx );

    Lgcode = L_shl( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/
@@ -713,7 +741,6 @@ static void encod_gen_voic_core_switch_ivas_fx(
    return;
}


/*-------------------------------------------------------------------*
 * bwe_switch_enc()
 *
+63 −7
Original line number Diff line number Diff line
@@ -14,8 +14,9 @@
 * Local prototypes
 *-------------------------------------------------------------------*/
static void wrte_cv( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits );
#ifndef REUSE_EVS_BE_ACELP_AVQ
static void wrte_cv_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 nq, const Word16 i_ind, const Word16 kv_ind, UWord16 I, Word16 kv[], Word16 *bits );

#endif
/*-------------------------------------------------------------------*
 * Function AVQ_cod()                                                *
 *                                                                   *
@@ -182,7 +183,9 @@ void AVQ_encmux_fx(
    Word16 bitsMod, Nsvm1, Nsvm2;
    Word16 unusedbitsFlag;
    Word16 svOrder[NSV_MAX], k, nullVec, dummy_bits;

#ifdef REUSE_EVS_BE_ACELP_AVQ
    Word16 tmp;
#endif
    test();
    IF( EQ_16( extl, SWB_BWE_HIGHRATE ) || EQ_16( extl, FB_BWE_HIGHRATE ) )
    {
@@ -344,7 +347,19 @@ void AVQ_encmux_fx(
        test();
        test();
        test();
#ifdef REUSE_EVS_BE_ACELP_AVQ
        tmp = bits;
        move16();
        WHILE( GE_16( tmp, 5 ) )
        {
            tmp = sub( tmp, 5 );
        }
        assert( tmp == bits % 5 );
        IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( tmp, 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) )

#else
        IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( s_and( bits, 4 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, Nsvm1 ) )
#endif
        {
            ordr_esti( sub( Nsv, i ), &trgtSvPos, &svOrder[i], Nsv );
            k = svOrder[i];
@@ -408,8 +423,19 @@ void AVQ_encmux_fx(
    test();
    IF( avq_bit_sFlag > 0 && GT_16( bits, 8 ) )
    {
#ifndef REUSE_EVS_BE_ACELP_AVQ
        // PMT("code not validated yet")
        bitsMod = s_and( bits, 4 /*bits%5*/ );
#else
        /* bitsMod = bits % 5;*/
        bitsMod = bits;
        move16();
        WHILE( bitsMod >= 5 )
        {
            bitsMod = sub( bitsMod, 5 );
        }
        assert( bitsMod == bits % 5 );
#endif
        i = svOrder[Nsvm1];
        move16();
        IF( NE_16( i, Nsvm1 ) )
@@ -445,11 +471,25 @@ void AVQ_encmux_fx(
                bitsMod = 0;
                move16();
            }
#ifdef REUSE_EVS_BE_ACELP_AVQ
            ELSE IF( GT_16( nq_est, 4 ) && ( ( bitsMod == 0 && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/
#else
            ELSE IF( nq_est > 4 && ( ( bitsMod == 0 && GT_16( nullVec, 3 ) && GT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && nq[svOrder[Nsvm2]] == 0 ) /* wasted bits 4, 5 for nq 6,7..*/
#endif
            {
                overflow = 0;
                move16();
#ifdef REUSE_EVS_BE_ACELP_AVQ
                tmp = add( bitsMod, nullVec );
                WHILE( tmp >= 5 )
                {
                    tmp = sub( tmp, 5 );
                }
                assert( tmp == add( bitsMod, nullVec ) % 5 );
                if ( tmp != 0 )
#else
                if ( s_and( add( bitsMod, nullVec ), 4 ) != 0 )
#endif
                {
                    overflow = 1;
                    move16();
@@ -476,7 +516,18 @@ void AVQ_encmux_fx(
            unused_bits = sub( unused_bits, 1 ); /*Stop Bit*/
        }
        /*unused_bits_idx = (int16_t)unused_bits / 5;*/
#ifdef REUSE_EVS_BE_ACELP_AVQ
        IF( unused_bits >= 0 )
        {
            unused_bits_idx = mult( unused_bits, 6554 /*1/5 in Q15*/ );
        }
        ELSE
        {
            unused_bits_idx = negate( mult( negate( unused_bits ), 6554 /*1/5 in Q15*/ ) );
        }
#else
        unused_bits_idx = mult( unused_bits, 6554 );
#endif
        assert( unused_bits_idx == unused_bits / 5 );
        unusedbitsFlag = 0;
        move16();
@@ -506,7 +557,11 @@ void AVQ_encmux_fx(
        IF( j > 0 )
        {
            /* write the unary code */
#ifdef REUSE_EVS_BE_ACELP_AVQ
            push_indice( hBstr, nq_ind, u_extract_l( L_sub( L_shl_sat( 1, j ), 1 ) ), j );
#else
            push_indice( hBstr, nq_ind, sub( shl( 1, j ), 1 ), j );
#endif
        }

        IF( nq[i] != 0 )
@@ -558,7 +613,7 @@ void AVQ_encmux_fx(

    return;
}

#ifndef REUSE_EVS_BE_ACELP_AVQ
void AVQ_encmux_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle            */
    const Word16 extl,     /* i  : extension layer                                 */
@@ -807,7 +862,7 @@ void AVQ_encmux_ivas_fx(
                bits = sub( bits, 1 );
            }

            wrte_cv_ivas_fx( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits );
            wrte_cv( hBstr, nq[k], i_ind, kv_ind, I[k], &kv[k * 8], &bits );
        }
    } /* for */
    /* Bit Saving Solution */
@@ -965,7 +1020,7 @@ void AVQ_encmux_ivas_fx(
        move16();

        /* write codebook indices (rank I and event. Voronoi index kv) */
        wrte_cv_ivas_fx( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits );
        wrte_cv( hBstr, nq[i], i_ind, kv_ind, I[i], &kv[i * 8], &bits );

        bits = sub( bits, dummy_bits );

@@ -985,7 +1040,7 @@ void AVQ_encmux_ivas_fx(

    return;
}

#endif
/*-------------------------------------------------------------------*
 * Function AVQ_cod_lpc_fx()                                            *
 *                                                                   *
@@ -1134,7 +1189,7 @@ static void wrte_cv(
    move16();
    return;
}

#ifndef REUSE_EVS_BE_ACELP_AVQ
static void wrte_cv_ivas_fx(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle         */
    const Word16 nq,       /* i  : AVQ nq index                     */
@@ -1194,3 +1249,4 @@ static void wrte_cv_ivas_fx(
    move16();
    return;
}
#endif
Loading