Commit 051c900b authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Encoder LTV crash fixes and float code clean up

parent ec2f9eb3
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -751,6 +751,7 @@ enum
#define E_MIN_Q11_FX                            7                      /* minimum allowable energy in Q11*/
#define E_MIN                               0.0035f                /* minimum allowable energy */
#define E_MIN_Q11_FX                            7                      /* minimum allowable energy in Q11*/
#define E_MIN_Q16_FX                         229                      /* minimum allowable energy in Q16*/
#define STEP_DELTA                          0.0625f                /* quantization step for tilt compensation of gaussian cb. excitation */
#define GAMMA_EV                            0.92f                  /* weighting factor for core synthesis error weighting */
#define FORMANT_SHARPENING_NOISE_THRESHOLD  21.0f                  /* lp_noise level above which formant sharpening is deactivated */
+4 −18
Original line number Diff line number Diff line
@@ -1257,6 +1257,7 @@ Word16 getTcxLpcShapedAri(
}


#ifndef IVAS_FLOAT_FIXED
/*-----------------------------------------------------------------------*
 * init_tcx_window_cfg()
 *
@@ -1362,6 +1363,7 @@ void init_tcx_window_cfg(

    return;
}
#endif

/*-----------------------------------------------------------------------*
 * init_tcx()
@@ -1369,6 +1371,7 @@ void init_tcx_window_cfg(
 * Initialization of TCX
 *-----------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
void init_tcx_cfg(
    TCX_CONFIG_HANDLE hTcxCfg,
    const int32_t total_brate,
@@ -1405,22 +1408,14 @@ void init_tcx_cfg(
    init_tcx_window_cfg( hTcxCfg, sr_core, input_Fs, L_frame, L_frameTCX, encoderLookahead_enc, encoderLookahead_FB, mdctWindowLength, mdctWindowLengthFB, element_mode );

    /* SQ deadzone & memory quantization*/
#ifndef IVAS_FLOAT_FIXED
    hTcxCfg->sq_rounding_flt = 0.375f; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
#else
    hTcxCfg->sq_rounding = 12288; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
#endif

    /* TCX rate loop */
    hTcxCfg->tcxRateLoopOpt = ( tcxonly ) ? 2 : 0;
    hTcxCfg->tcxRateLoopOpt = ( element_mode == IVAS_CPE_MDCT ) ? 3 : hTcxCfg->tcxRateLoopOpt;

    /* TCX bandwidth */
#ifndef IVAS_FLOAT_FIXED
    hTcxCfg->bandwidth_flt = getTcxBandwidth_flt( bwidth );
#else
    hTcxCfg->bandwidth = getTcxBandwidth( bwidth );
#endif

    /* set number of coded lines */
    hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth );
@@ -1464,11 +1459,7 @@ void init_tcx_cfg(
    }

    /* Scale TCX for non-active frames to adjust loudness with ACELP*/
#ifndef IVAS_FLOAT_FIXED
    hTcxCfg->na_scale_flt = 1.f;
#else
    hTcxCfg->na_scale = 32767;
#endif

    if ( na_scale_bwidth < SWB && !tcxonly )
    {
@@ -1482,11 +1473,7 @@ void init_tcx_cfg(
                {
                    i--;
                }
#ifndef IVAS_FLOAT_FIXED
                hTcxCfg->na_scale_flt = scaleTcxTable[i].scale_flt;
#else
                hTcxCfg->na_scale = scaleTcxTable[i].scale;
#endif
                break;
            }
        }
@@ -1503,8 +1490,7 @@ void init_tcx_cfg(

    return;
}

#ifdef IVAS_FLOAT_FIXED
#else
void init_tcx_cfg_ivas_fx(
    TCX_CONFIG_HANDLE hTcxCfg,
    const Word32 total_brate,     /*Q0*/
+23 −12
Original line number Diff line number Diff line
@@ -236,7 +236,7 @@ ivas_error pre_proc_front_ivas_fx(
    Word16 old_inp_12k8_fx[],                                  /* o  : (Q-1) buffer of old input signal              */
    float old_inp_12k8[],                                      /* o  : buffer of old input signal              */
    float old_inp_16k[],                                       /* o  : buffer of old input signal @16kHz          */
    float *ener,                                               /* o  : residual energy from Levinson-Durbin    */
    Word32 *ener_fx,                                              /* o  : residual energy from Levinson-Durbin  Q_r  */
    Word16 *relE_fx,                                               /* o  : frame relative energy                  Q8 */
    Word16 A_fx[NB_SUBFR16k * ( M + 1 )],                          /* o  : A(z) unquantized for the 4 subframes    */
    Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )],                         /* o  : weighted A(z) unquantized for subframes */
@@ -254,9 +254,10 @@ ivas_error pre_proc_front_ivas_fx(
    Word16 *loc_harm,                                          /* o  : harmonicity flag                        */
    Word16 *cor_map_sum_fx,                                    /* o  : speech/music clasif. parameter       Q8 */
    Word16 *vad_flag_dtx,                                      /* o  : HE-SAD flag with additional DTX HO      */
    float enerBuffer[CLDFB_NO_CHANNELS_MAX],                   /* o  : energy buffer                           */
    float fft_buff[2 * L_FFT],                                 /* o  : FFT buffer                              */
    Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX],                      /* o  : energy buffer                           */
    Word16 *enerBuffer_fx_exp,                      /* o  : energy buffer                           */
    Word16 fft_buff_fx[2 * L_FFT],                             /* o  : FFT buffer                                 */
    Word16 *fft_buff_fx_q,                                     /* o  : FFT buffer                                 */
    const Word16 tdm_A_PCh_fx[M + 1],                              /* i  : unq. LP coeff. of primary channel  Q12     */
    const Word16 tdm_lsp_new_PCh_fx[M],                            /* i  : unq. LSPs of primary channel       Q15     */
    const Word16 currFlatness_fx,                                  /* i  : flatness parameter                    Q7  */
@@ -285,13 +286,13 @@ ivas_error pre_proc_ivas(
    Word16 old_inp_12k8_fx[],                                       /* i/o: buffer of old input signal              */
    float old_inp_16k[],                                        /* i/o: buffer of old input signal @ 16kHz      */
    float **inp,                                                /* o  : ptr. to inp. signal in the current frame*/
    float *ener,                                                /* o  : residual energy from Levinson-Durbin    */
    Word32 *ener_fx,                                            /* o  : residual energy from Levinson-Durbin Q6 */
    Word16 A[NB_SUBFR16k * ( M + 1 )],                           /* i/o: A(z) unquantized for the 4 subframes    */
    Word16 Aw[NB_SUBFR16k * ( M + 1 )],                          /* i/o: weighted A(z) unquantized for subframes */
    float epsP[M + 1],                                          /* i/o: LP prediction errors                    */
    Word16 lsp_new[M],                                           /* i/o: LSPs at the end of the frame            */
    Word16 lsp_mid[M],                                           /* i/o: LSPs in the middle of the frame         */
    float *new_inp_resamp16k,                                   /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
    Word16 *new_inp_resamp16k_fx,                                   /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE */
    int16_t *Voicing_flag,                                      /* o  : voicing flag for HQ FEC                 */
    float old_wsp[],                                      /* i  : weighted input signal buffer            */
    const int16_t loc_harm,                                     /* i  : harmonicity flag                        */
@@ -525,7 +526,7 @@ ivas_error ivas_core_enc(
    const int16_t n_CoreChannels,                                /* i  : number of core channels to be coded    */
    float old_inp_12k8[][L_INP_12k8],                            /* i  : buffer of old input signal             */
    float old_inp_16k[][L_INP],                                  /* i  : buffer of old input signal             */
    float ener[],                                                /* i  : residual energy from Levinson-Durbin   */
    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*/
    float epsP[][M + 1],                                         /* i  : LP prediction errors                   */
@@ -533,14 +534,16 @@ ivas_error ivas_core_enc(
    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)                */
    float realBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: real buffer                            */
    float imagBuffer[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer                            */
    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 q_re_im_buf,
    float old_wsp[][L_WSP],                                      /* i  : weighted input signal buffer           */
    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     */
    float enerBuffer[][CLDFB_NO_CHANNELS_MAX],                   /* i  : energy buffer                          */
    float fft_buff[][2 * L_FFT],                                 /* i  : FFT buffer                             */
    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 */
@@ -1390,6 +1393,7 @@ void ivas_ism_dtx_limit_noise_energy_for_near_silence(
 * DFT Stereo prototypes
 *----------------------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
ivas_error stereo_dft_enc_create(
    STEREO_DFT_ENC_DATA_HANDLE *hStereoDft,                     /* o  : encoder DFT stereo handle           */
    const int32_t input_Fs,                                     /* i  : input sampling rate                 */
@@ -1404,16 +1408,15 @@ void stereo_enc_itd_init(
    ITD_DATA_HANDLE hItd                                        /* i/o: encoder ITD handle                  */
);

#ifndef IVAS_FLOAT_FIXED
void stereo_dft_enc_update(
    STEREO_DFT_ENC_DATA_HANDLE hStereoDft,                      /* i/o: encoder DFT stereo handle           */
    const int16_t max_bwidth                                    /* i  : maximum encoded bandwidth           */
);
#endif

void stereo_dft_enc_destroy(
    STEREO_DFT_ENC_DATA_HANDLE *hStereoDft                      /* i/o: encoder DFT stereo handle           */
);
#endif

void stereo_dft_enc_analyze(
    Encoder_State **sts,                                        /* i/o: encoder state structure             */
@@ -1816,6 +1819,12 @@ int16_t read_BS_adapt_GR_sg(
    int16_t *GR_ord,                                            /* o  : GR order to be used                 */
    const int16_t *map0                                         /* i  : mapping array for side gains        */
);

void stereo_dft_hybrid_ITD_flag(
    STEREO_DFT_CONFIG_DATA_HANDLE hConfig,                      /* o  : DFT stereo configuration                */
    const int32_t input_Fs,                                     /* i  : CPE element sampling rate               */
    const int16_t hybrid_itd_max                                /* i  : flag for hybrid ITD for very large ITDs */
);
#endif

void stereo_dft_enc_compute_itd(
@@ -4643,11 +4652,13 @@ void ivas_spar_dec_upmixer(
);

/* MD module */
#ifndef IVAS_FLOAT_FIXED
ivas_error ivas_spar_md_enc_open(
    ivas_spar_md_enc_state_t **hMdEnc,                          /* i/o: SPAR MD encoder handle                  */
    const ENCODER_CONFIG_HANDLE hEncoderConfig,                 /* i  : configuration structure                 */
    const int16_t sba_order                                     /* i  : Ambisonic (SBA) order                   */
);
#endif

void ivas_spar_md_enc_close(
    ivas_spar_md_enc_state_t **hMdEnc                           /* i/o: SPAR MD encoder handle                  */
+15 −2
Original line number Diff line number Diff line
@@ -1395,6 +1395,15 @@ void stereo_tdm_downmix_ivas_fx(
    const Word16 tdm_ratio_idx_SM        /* i  : TDM ratio index for SM mode             */
);

ivas_error initMdctItdHandling_fx(
    STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure        */
    const Word32 input_Fs              /* i  : input sampling rate                     */
);

void stereo_mdct_enc_destroy_fx(
    STEREO_MDCT_ENC_DATA_HANDLE *hStereoMdct /* i/o: encoder MDCT stereo handle              */
);

void stereo_mdct_init_bands_fx(
    const Word16 L_frame,       /* i  : frame length                                       */
    const Word16 tmp_tcx_mode,  /* i  : tcx mode (TCX10, TCX 20), -1 if transition frame   */
@@ -4244,6 +4253,10 @@ void stereo_dft_enc_update_fx(
    const Word16 max_bwidth                /* i  : maximum encoded bandwidth */
);

void stereo_dft_enc_destroy_fx(
    STEREO_DFT_ENC_DATA_HANDLE *hStereoDft /* i/o: encoder DFT stereo handle           */
);

void stereo_dft_quantize_res_gains_fx(
    const Word32 *g, // Q31
    const Word32 *r, // Q31
@@ -4337,7 +4350,7 @@ Word16 write_bitstream_GR(
    const Word16 GR_ord    /* i  : GR order                 */
);

void stereo_dft_hybrid_ITD_flag(
void stereo_dft_hybrid_ITD_flag_fx(
    STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o  : DFT stereo configuration                */
    const Word32 input_Fs,                 /* i  : CPE element sampling rate               */
    const Word16 hybrid_itd_max            /* i  : flag for hybrid ITD for very large ITDs */
@@ -5838,7 +5851,7 @@ ivas_error ivas_compute_core_buffers_fx(
    const Word16 input_frame,              /* i  : frame length                             */
    const Word16 last_element_mode,        /* i  : last element mode                        */
    const Word32 sr_core,                  /* i  : core-coder sampling rate                 */
    Word32 *ener,                          /* o  : residual energy from Levinson-Durbin     */
    Word32 *ener_fx,                       /* o  : residual energy from Levinson-Durbin Q_r */
    Word16 A_fx[NB_SUBFR16k * ( M + 1 )],  /* i/o: A(z) unquantized for the 4 subframes     */
    Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: weighted A(z) unquantized for subframes  */
    Word32 epsP[M + 1],                    /* i/o: LP prediction errors                     */
+1 −1
Original line number Diff line number Diff line
@@ -496,7 +496,7 @@ void L_lerp_fx( Word32 *f /*q*/, Word32 *f_out /*q*/, Word16 bufferNewSize /*Q0*
    IF( LT_16( getScaleFactor32( f, bufferOldSize ), guard_bits ) )
    {
        *q = sub( *q, guard_bits );
        FOR( Word16 ind = 0; ind < bufferNewSize; ind++ )
        FOR( Word16 ind = 0; ind < bufferOldSize; ind++ )
        {
            f[ind] = L_shr( f[ind], guard_bits ); /*Q(guard_bits)*/
            move32();
Loading