Commit 1f6e7418 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

EstimateTCXNoiseLevel, sub-functions in init_coder_ace_plus,...

EstimateTCXNoiseLevel, sub-functions in init_coder_ace_plus, stereo_mdct_core_enc and stereo_icBWE_preproc fixed implementation
parent a7716790
Loading
Loading
Loading
Loading
Loading
+226 −2
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "wmc_auto.h"
#include "ivas_prot.h"
#include "prot_fx.h"
#include "ivas_prot_fx.h"

#define FSCALE_DENOM_BY_12800_Q15 1311
/*-------------------------------------------------------------------*
@@ -229,6 +230,78 @@ int16_t getTcxonly_ivas(
    return tcxonly;
}


#ifdef IVAS_FLOAT_FIXED
Word16 getTcxonly_ivas_fx(
    const Word16 element_mode, /* i  : IVAS element mode                   */
    const Word32 total_brate,  /* i  : total bitrate                       */
    const Word16 MCT_flag,     /* i  : hMCT handle allocated (1) or not (0)*/
    const Word16 is_ism_format /* i  : flag indicating ISM format          */
)
{
    Word16 tcxonly = 0;
    move16();
    Word32 temp_flag;
    if ( MCT_flag )
    {
        temp_flag = IVAS_32k;
        move32();
    }
    else
    {
        temp_flag = IVAS_48k;
        move32();
    }

    SWITCH( element_mode )
    {
        case EVS_MONO:
            if ( GT_32( total_brate, ACELP_32k ) )
            {
                tcxonly = 1;
                move16();
            }
            BREAK;
        case IVAS_SCE:
            if ( is_ism_format )
            {
                if ( GT_32( total_brate, MAX_ACELP_BRATE_ISM ) )
                {
                    tcxonly = 1;
                    move16();
                }
            }
            else
            {
                if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
                {
                    tcxonly = 1;
                    move16();
                }
            }
            BREAK;

        case IVAS_CPE_DFT:
        case IVAS_CPE_TD:
            if ( GT_32( total_brate, MAX_ACELP_BRATE ) )
            {
                tcxonly = 1;
                move16();
            }
            BREAK;
        case IVAS_CPE_MDCT:
            if ( GE_32( total_brate, temp_flag ) )
            {
                tcxonly = 1;
                move16();
            }
            BREAK;
    }

    return tcxonly;
}
#endif

Word16 getTcxonly(
#ifdef IVAS_CODE_SWITCHING
    const Word16 element_mode, /* i  : IVAS element mode                   */
@@ -706,7 +779,7 @@ Word16 getTcxBandwidth(

    tcxBandwidth = 16384 /*0.5f Q15*/;
    move16();
    if ( bwidth == NB )
    if ( EQ_16( bwidth, NB ) )
    {
        tcxBandwidth = 10240 /*0.3125f Q15*/;
        move16();
@@ -1411,6 +1484,157 @@ void init_tcx_cfg(

    return;
}

#ifdef IVAS_FLOAT_FIXED
void init_tcx_cfg_ivas_fx(
    TCX_CONFIG_HANDLE hTcxCfg,
    const Word32 total_brate,
    const Word32 sr_core,
    const Word32 input_Fs,
    const Word16 L_frame,
    const Word16 bwidth,
    const Word16 L_frameTCX,
    const Word16 fscale,
    const Word16 preemph_fac,
    const Word16 tcxonly,
    const Word16 rf_mode,
    const Word16 igf,
    const Word16 infoIGFStopFreq,
    const Word16 element_mode,
    const Word16 ini_frame,
    const Word16 MCT_flag )
{
    Word16 i;
    Word16 mdctWindowLength;
    Word16 mdctWindowLengthFB;
    Word16 na_scale_bwidth;

    hTcxCfg->preemph_fac = preemph_fac;
    move16();

    hTcxCfg->tcx5Size = shr( L_frame, 2 );      /* Always 5 ms */
    hTcxCfg->tcx5SizeFB = shr( L_frameTCX, 2 ); /* Always 5 ms */
    move16();
    move16();

    hTcxCfg->tcx_mdct_window_length_old = hTcxCfg->tcx_mdct_window_length;
    move16();
    mdctWindowLength = getMdctWindowLength_fx( fscale );
    mdctWindowLengthFB = (Word16) ( mdctWindowLength * input_Fs / sr_core );

    init_tcx_window_cfg_fx( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, mdctWindowLength, mdctWindowLengthFB, element_mode );
    /* SQ deadzone & memory quantization*/
    hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
    move16();

    /* TCX rate loop */
    hTcxCfg->tcxRateLoopOpt = 0;
    move16();

    if ( tcxonly != 0 )
    {
        hTcxCfg->tcxRateLoopOpt = 2;
        move16();
    }
    if ( EQ_16( element_mode, IVAS_CPE_MDCT ) )
    {
        hTcxCfg->tcxRateLoopOpt = 3;
        move16();
    }
    hTcxCfg->bandwidth = getTcxBandwidth( bwidth );
    move16();

    /* set number of coded lines */
    hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth );
    move16();

    /* TNS in TCX */
    hTcxCfg->pCurrentTnsConfig = NULL;
    hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, igf, element_mode );
    move16();

    IF( hTcxCfg->fIsTNSAllowed )
    {
        InitTnsConfigs_ivas_fx( bwidth, hTcxCfg->tcx_coded_lines, hTcxCfg->tnsConfig, infoIGFStopFreq, total_brate, element_mode, MCT_flag );

        SetAllowTnsOnWhite( hTcxCfg->tnsConfig, (Word8) EQ_16( element_mode, IVAS_CPE_MDCT ) );
    }

    IF( ini_frame == 0 )
    {
        hTcxCfg->tcx_curr_overlap_mode = hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW;
        hTcxCfg->last_aldo = 1;
        move16();
        move16();
        move16();
    }

    /* Context HM*/
    hTcxCfg->ctx_hm = getCtxHm( element_mode, total_brate, rf_mode );
    move16();

    /* Residual Coding*/
    hTcxCfg->resq = getResq( total_brate );
    move16();
    test();
    if ( hTcxCfg->resq && !tcxonly )
    {
        hTcxCfg->tcxRateLoopOpt = 1;
        move16();
    }

    /*Set bandwidth scale*/
    IF( EQ_16( bwidth, NB ) )
    {
        na_scale_bwidth = NB;
    }
    ELSE IF( LE_32( sr_core, INT_FS_16k ) )
    {
        na_scale_bwidth = WB;
    }
    ELSE
    {
        na_scale_bwidth = SWB;
    }
    move16();
    hTcxCfg->na_scale = 32767 /*1.0f Q15*/;
    move16();

    test();
    IF( LT_16( na_scale_bwidth, SWB ) && !tcxonly )
    {
        FOR( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ )
        {
            test();
            test();
            IF( ( EQ_16( na_scale_bwidth, scaleTcxTable[i].bwmode ) ) &&
                ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) &&
                ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) )
            {
                if ( rf_mode )
                {
                    i = sub( i, 1 );
                }
                hTcxCfg->na_scale = scaleTcxTable[i].scale;
                move16();
                BREAK;
            }
        }
    }

    IF( tcxonly )
    {
        InitPsychLPC_fx( sr_core, L_frame, hTcxCfg );
    }
    ELSE
    {
        hTcxCfg->psychParamsCurrent = NULL;
    }

    return;
}
#endif

#ifdef IVAS_FLOAT_FIXED
void init_tcx_window_cfg_fx(
    TCX_CONFIG_HANDLE hTcxCfg,       /* i/o: TCX Config handle        */
@@ -1529,7 +1753,7 @@ void init_tcx_cfg_fx(
    const Word16 bwidth,
    const Word16 L_frameTCX,
    const Word16 fscale,
    const Word16 preemph_fac,
    const Word16 preemph_fac, /*Q15*/
    const Word16 tcxonly,
    const Word16 rf_mode,
    const Word16 igf,
+23 −1
Original line number Diff line number Diff line
@@ -3034,7 +3034,21 @@ void QuantizeTCXSpectrum(
    float *gain_tcx,                                            /* o  : global gain                             */
    int16_t prm[]                                               /* o  : tcx parameters                          */
);

#ifdef IVAS_FLOAT_FIXED
void EstimateStereoTCXNoiseLevel_fx(
    Encoder_State **sts,                     /* i  : state handle                                    */
    Word32 *q_spectrum[CPE_CHANNELS][NB_DIV], /* i  : quantized MDCT spectrum                         */
    Word16 gain_tcx[][NB_DIV],                /* i  : global gain                                     */
    Word16 gain_tcx_e,                        /* i  : global gain exponent                            */
    Word16 L_frame[][NB_DIV],                /* i  : frame length                                    */
    Word16 noiseFillingBorder[][NB_DIV],     /* i  : noise filling border                            */
    Word16 hm_active[][NB_DIV],              /* i  : flag indicating if the harmonic model is active */
    const Word16 ignore_chan[],              /* i  : flag indicating whether the channel should be ignored */
    Word16 fac_ns[][NB_DIV],                  /* o  : noise filling level                             */
    Word16 param_core[][NB_DIV * NPRM_DIV],  /* o  : quantized noise filling level                   */
    const Word16 MCT_flag                    /* i  : hMCT handle allocated (1) or not (0)            */
);
#endif
void EstimateStereoTCXNoiseLevel(
    Encoder_State **sts,                                        /* i  : state handle                            */
    float *q_spectrum[CPE_CHANNELS][NB_DIV],                    /* i  : quantized MDCT spectrum                 */
@@ -4081,6 +4095,14 @@ void ivas_mdct_quant_coder(
    const int16_t MCT_flag                                      /* i  : hMCT handle allocated (1) or not (0)    */
);

void ivas_mdct_quant_coder_fx(
    CPE_ENC_HANDLE hCPE,                   /* i/o: Encoder CPE handle                   */
    int16_t tnsBits[CPE_CHANNELS][NB_DIV], /* i  : bits needed for TNS parameters       */
    int16_t tnsSize[CPE_CHANNELS][NB_DIV], /* i  : size of TNS                          */
    int16_t p_param[CPE_CHANNELS][NB_DIV], /* i  : pointer to parameter array           */
    const int16_t MCT_flag                 /* i  : hMCT handle allocated (1) or not (0) */
);

void apply_MCT_enc(
    MCT_ENC_HANDLE hMCT,                                        /* i/o: MCT encoder structure                   */
    Encoder_State **sts,                                        /* i/o: encoder state structure                 */
+30 −1
Original line number Diff line number Diff line
@@ -2613,7 +2613,6 @@ void apply_MCT_enc_fx(
    Word32 *inv_mdst_spectrum[MCT_MAX_CHANNELS][NB_DIV], /* i/o: inverse MDST spectrum               */
    const Word16 nchan                                   /* i  : number of channels                  */
);
#endif

void ivas_spar_config_fx(
    Word32 ivas_total_brate,    /* i  : codec total bitrate                     */
@@ -2700,4 +2699,34 @@ void stereo_dft_enc_process_fx(
    const Word16 vad_hover_flag[], /* i  : VAD hangover flags          */
    const Word16 input_frame       /* i  : input frame length          */
);

void spectral_balancer_fx16(
    Word16 *signal,        /* i/o  : signal  Qx                 */
    Word16 *mem,           /* i/o  : mem  Qx                    */
    const Word16 lg,       /* i  : input signal length          */
    const Word16 coeff_set /* i  : coefficient set              */
);

void stereo_icBWE_preproc_fx(
    CPE_ENC_HANDLE hCPE,        /* i/o: CPE encoder structure                           */
    const Word16 input_frame,   /* i  : input frame length                              */
    Word16 shb_speech_nonref[], /* o  : SHB speech non-ref channel                      */
    Word16 q_shb_speech_nonref  /* i  : Q SHB speech non-ref channel                    */
);

#endif

void QuantizeSpectrum_ivas_fx(
    Encoder_State *st,           /* i/o: encoder state structure                         */
    const float A[],             /* i  : quantized coefficients NxAz_q[M+1]              */
    const Word16 Aqind[],        /* i  : frame-independent quantized coefficients (M+1)  */
    float gainlpc[],             /* i  : MDCT gains of the previous frame                */
    float synth[],               /* o  : synthesis buffer                                */
    const int16_t nb_bits,       /* i  : bit budget                                      */
    const int16_t tnsSize,       /* i  : number of tns parameters put into prm           */
    int16_t prm[],               /* o  : tcx parameters                                  */
    const int16_t frame_cnt,     /* i  : frame counter in the super_frame                */
    CONTEXT_HM_CONFIG *hm_cfg,   /* i  : HM configuration                                */
    const int16_t vad_hover_flag /* i  : VAD hangover flag                               */
);
#endif
+52 −0
Original line number Diff line number Diff line
@@ -6859,11 +6859,24 @@ void init_coder_ace_plus(
    const int16_t MCT_flag          /* i  : hMCT handle allocated (1) or not (0)*/
);
#ifdef IVAS_FLOAT_FIXED
void init_coder_ace_plus_ivas_fx(
    Encoder_State *st,             /* i  : Encoder state                          */
    const Word32 last_total_brate, /* i  : last total bitrate                     */
    const Word16 MCT_flag          /* i  : hMCT handle allocated (1) or not (0)   */
);
#endif
void core_coder_reconfig(
    Encoder_State *st,             /* i/o: encoder state structure             */
    const int32_t last_total_brate /* i  : last total bitrate                  */
);
#ifdef IVAS_FLOAT_FIXED
void core_coder_reconfig_ivas_fx(
    Encoder_State *st );
#endif
void core_coder_mode_switch(
    Encoder_State *st,              /* i/o: encoder state structure             */
    const int32_t last_total_brate, /* i  : last bitrate                        */
@@ -9926,6 +9939,15 @@ int16_t getTcxonly_ivas(
    const int16_t is_ism_format /* i  : flag indicating ISM format          */
);
#ifdef IVAS_FLOAT_FIXED
Word16 getTcxonly_ivas_fx(
    const Word16 element_mode, /* i  : IVAS element mode                   */
    const Word32 total_brate,  /* i  : total bitrate                       */
    const Word16 MCT_flag,     /* i  : hMCT handle allocated (1) or not (0)*/
    const Word16 is_ism_format /* i  : flag indicating ISM format          */
);
#endif
int16_t getTnsAllowed(
    const int32_t total_brate, /* i  : total bitrate               */
    const int16_t igf,         /* i  : flag indicating IGF activity*/
@@ -10071,6 +10093,16 @@ void IGFEncSetMode(
    const int16_t rf_mode                  /* i  : flag to signal the RF mode     */
);
#ifdef IVAS_FLOAT_FIXED
void IGFEncSetMode_ivas_fx(
    const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i/o: instance handle of IGF Encoder */
    const Word32 total_brate,              /* i  : encoder total bitrate          */
    const Word16 bwidth,                   /* i  : encoder audio bandwidth        */
    const Word16 element_mode,             /* i  : IVAS element mode              */
    const Word16 rf_mode                   /* i  : flag to signal the RF mode     */
);
#endif
/*! r: number of bits written per frame */
int16_t IGFEncWriteBitstream(
    const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i  : instance handle of IGF Encoder                                              */
@@ -10286,4 +10318,24 @@ void init_tcx_cfg(
    const int16_t MCT_flag /* i  : hMCT handle allocated (1) or not (0)  */
);
#ifdef IVAS_FLOAT_FIXED
void init_tcx_cfg_ivas_fx(
    TCX_CONFIG_HANDLE hTcxCfg,
    const Word32 total_brate,
    const Word32 sr_core,
    const Word32 input_Fs,
    const Word16 L_frame,
    const Word16 bwidth,
    const Word16 L_frameTCX,
    const Word16 fscale,
    const Word16 preemph_fac,
    const Word16 tcxonly,
    const Word16 rf_mode,
    const Word16 igf,
    const Word16 infoIGFStopFreq,
    const Word16 element_mode,
    const Word16 ini_frame,
    const Word16 MCT_flag );
#endif
#endif
+5 −1
Original line number Diff line number Diff line
@@ -3319,6 +3319,7 @@ void InitTnsConfiguration(
    const Word16 element_mode,
    const Word16 is_mct );
#ifdef IVAS_FLOAT_FIXED
void InitTnsConfiguration_ivas_fx(
    const Word16 bwidth,
    const Word16 frameLength,
@@ -3327,6 +3328,7 @@ void InitTnsConfiguration_ivas_fx(
    const Word32 total_brate,
    const Word16 element_mode,
    const Word16 is_mct );
#endif
/** Modify spectrum using TNS filter.
 * Modifies spectrum unsing TNS filter defined by pTnsData.
@@ -4028,6 +4030,7 @@ void InitTnsConfigs(
    const Word16 element_mode,
    const Word16 is_mct );
#ifdef IVAS_FLOAT_FIXED
void InitTnsConfigs_ivas_fx(
    const Word16 bwidth,
    const Word16 L_frame,
@@ -4036,6 +4039,7 @@ void InitTnsConfigs_ivas_fx(
    const Word32 total_brate,
    const Word16 element_mode,
    const Word16 is_mct );
#endif
#define IVAS_CODE_TCX_UTIL
#ifdef IVAS_CODE_TCX_UTIL
@@ -6345,7 +6349,7 @@ void init_tcx_cfg_fx(
    const Word16 bwidth,
    const Word16 L_frameTCX,
    const Word16 fscale,
    const Word16 preemph_fac,
    const Word16 preemph_fac, /*Q15*/
    const Word16 tcxonly,
    const Word16 rf_mode,
    const Word16 igf,
Loading