Commit 92a13f5d authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'hq_core_enc_fdcng_enc_fxd' into 'main'

FdCngEncodeMDCTStereoSID subfunctions, hq_core_enc function and sub-functions converted to fxd

See merge request !610
parents faf66e6a 04de10ed
Loading
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -7454,6 +7454,15 @@ void fd_bwe_dec_init(
    FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle  */
);
void hq_core_enc_ivas_fx(
    Encoder_State *st,          /* i/o: encoder state structure                   */
    const Word16 *audio_fx,     /* i  : input audio signal                       Q0 */
    const Word16 input_frame,   /* i  : frame length                              */
    const Word16 hq_core_type,  /* i  : HQ core type                              */
    const Word16 Voicing_flag,  /* i  : Voicing flag for FER method selection     */
    const Word16 vad_hover_flag /* i  : VAD hangover flag                         */
);
// hq_core_dec_fx.c
void hq_core_dec_fx(
    Decoder_State *st_fx,            /* i/o: decoder state structure fx         */
+25 −2
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@
#include "prot_fx.h"
#include "prot_fx_enc.h"

#ifdef IVAS_FLOAT_FIXED
#include "prot_fx.h"
#endif

/*-----------------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------------*/
@@ -440,6 +444,11 @@ void init_coder_ace_plus(
            set_zero( hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 );
            hTcxEnc->acelp_zir_flt = hTcxEnc->Txnq_flt + L_FRAME / 2;
            hTcxEnc->tcx_target_bits_fac_flt = 1.0f;

#ifdef IVAS_FLOAT_FIXED
            set16_fx( hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
            hTcxEnc->acelp_zir = hTcxEnc->Txnq + L_FRAME / 2;
#endif
        }
    }

@@ -1061,8 +1070,13 @@ static void init_sig_buffers_ivas_fx( Encoder_State *st, const Word16 L_frame_ol

    if ( st->hTcxEnc != NULL )
    {
        hTcxEnc->new_speech_TCX = st->input_buff_fx + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) - NS2SA( st->input_Fs, DELAY_FIR_RESAMPL_NS );
        hTcxEnc->speech_TCX = hTcxEnc->new_speech_TCX - st->encoderLookahead_FB;
        st->hTcxEnc->new_speech_TCX_flt = st->input_buff + st->input_Fs / FRAMES_PER_SEC; /* note: in EVS st->new_speech_TCX == st->input - 0.9375ms; in IVAS st->new_speech_TCX == st->input */
        st->hTcxEnc->speech_TCX_flt = st->hTcxEnc->new_speech_TCX_flt - st->encoderLookahead_FB;

#ifdef IVAS_FLOAT_FIXED
        st->hTcxEnc->new_speech_TCX = st->input_buff_fx + Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 );
        st->hTcxEnc->speech_TCX = st->hTcxEnc->new_speech_TCX - st->encoderLookahead_FB;
#endif
    }
    st->speech_enc = st->buf_speech_enc + st->encoderPastSamples_enc;
    st->speech_enc_pe = st->buf_speech_enc_pe + st->encoderPastSamples_enc;
@@ -1227,6 +1241,11 @@ static void init_acelp(
        {
            set_zero( st->hTcxEnc->Txnq_flt, L_FRAME32k / 2 + 64 );
            st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 );

#ifdef IVAS_FLOAT_FIXED
            set16_fx( st->hTcxEnc->Txnq, 0, L_FRAME32k / 2 + 64 );
            st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 );
#endif
        }
    }
    else /*Rate switching*/
@@ -1242,6 +1261,10 @@ static void init_acelp(
                lerp_flt( st->hTcxEnc->Txnq_flt, st->hTcxEnc->Txnq_flt, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_length_old );
            }
            st->hTcxEnc->acelp_zir_flt = st->hTcxEnc->Txnq_flt + ( st->L_frame / 2 );

#ifdef IVAS_FLOAT_FIXED
            st->hTcxEnc->acelp_zir = st->hTcxEnc->Txnq + ( st->L_frame / 2 );
#endif
        }

        /* Rate switching */
+175 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#include "prot_fx.h"
#include "prot_fx_enc.h"
#endif

/*-------------------------------------------------------------------*
@@ -248,7 +250,180 @@ ivas_error evs_enc(

        if ( st->core == HQ_CORE )
        {
#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            PWord16 *p;
            Word16 q = 0;
            Word16 overlap, tmp;
            Word16 left_overlap, right_overlap;
            IF( st->element_mode > EVS_MONO && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) )
            {
                left_overlap = st->hTcxCfg->tcx_mdct_window_lengthFB;
                right_overlap = st->hTcxCfg->tcx_mdct_window_delayFB;
                Word16 L_frame1 = 640;

                p = st->hTcxCfg->tcx_mdct_window_minimumFB;
                tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );

                Word16 q1 = Q_factor_arr( st->hTcxCfg->tcx_mdct_window_minimumFB_flt, tmp );
                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i + tmp], q1 );
                }

                p = st->hTcxCfg->tcx_mdct_window_transFB;
                tmp = shr( st->hTcxCfg->tcx_mdct_window_min_lengthFB, 1 );

                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_transFB_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_transFB_flt[i + tmp], q1 );
                }

                p = st->hTcxCfg->tcx_aldo_window_2_FB;
                tmp = shr( st->hTcxCfg->tcx_mdct_window_delayFB, 1 );

                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i + tmp], q1 );
                }

                tmp = st->hTcxCfg->tcx_mdct_window_min_length / 2;
                p = st->hTcxCfg->tcx_mdct_window_minimum;
                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimum_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_minimum_flt[i + tmp], q1 );
                }


                Word16 l1 = ( shr( left_overlap, 1 ) * 2 ) + sub( L_frame1, shr( add( left_overlap, right_overlap ), 1 ) ) + ( shr( right_overlap, 1 ) * 2 ) - shr( left_overlap, 1 ) + st->hTcxCfg->tcx_offsetFB;
                q = Q_factor_arr( st->hTcxEnc->speech_TCX_flt, l1 ) - 1;
                st->hTcxEnc->q_speech_TCX = q;

                Word16 offset, overlap1;
                offset = negate( shr( st->hTcxCfg->tcx_mdct_window_trans_lengthFB, 1 ) );
                overlap1 = st->hTcxCfg->tcx_mdct_window_trans_lengthFB;

                floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, l1 );
                floatToFixed_arr( st->hTcxEnc->speech_TCX_flt - overlap1 / 2 + offset, st->hTcxEnc->speech_TCX - overlap1 / 2 + offset, q, 2 * L_FRAME48k + 960 );

                q1 = 15;
                tmp = st->hTcxCfg->tcx_mdct_window_half_length / 2;
                p = st->hTcxCfg->tcx_mdct_window_half;
                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_half_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_half_flt[i + tmp], q1 );
                }

                tmp = st->hTcxCfg->tcx_mdct_window_min_length / 2;
                p = st->hTcxCfg->tcx_mdct_window_trans;
                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_mdct_window_trans_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_mdct_window_trans_flt[i + tmp], q1 );
                }

                overlap = st->hTcxCfg->tcx_mdct_window_length;
                tmp = overlap / 2;
                p = st->hTcxCfg->tcx_aldo_window_2;
                FOR( i = 0; i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_flt[i], q1 );
                }
                FOR( i = 0; i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_2_flt[i + tmp], q1 );
                }

                tmp = overlap / 2;
                p = st->hTcxCfg->tcx_aldo_window_1_trunc;
                FOR( i = -NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i < tmp; i++ )
                {
                    p[i].v.im = float_to_fix16( st->hTcxCfg->tcx_aldo_window_1_trunc_flt[i], q1 );
                }
                FOR( i = -NS2SA( st->sr_core, N_ZERO_MDCT_NS ); i < tmp; i++ )
                {
                    p[tmp - 1 - i].v.re = float_to_fix16( st->hTcxCfg->tcx_aldo_window_1_trunc_flt[i + tmp], q1 );
                }

                FOR( i = 0; i < L_FRAME32k / 2 + 64; i++ )
                {
                    st->hTcxEnc->Txnq[i] = float_to_fix16( st->hTcxEnc->Txnq_flt[i], 0 );
                }
            }
            ELSE
            {
                FOR( i = 0; i < L_FRAME32k; i++ )
                {
                    st->hTcxEnc->old_out_fx[i] = float_to_fix16( st->hTcxEnc->old_out[i], 0 );
                }
            }

            IF( NE_16( hq_core_type, LOW_RATE_HQ_CORE ) )
            {
                IF( NE_16( st->element_mode, EVS_MONO ) )
                {
                    Word16 temp_e;

                    f2me( st->hHQ_core->crest_lp, &st->hHQ_core->crest_lp_fx, &temp_e );
                    st->hHQ_core->crest_lp_q = sub( Q31, temp_e );
                    f2me( st->hHQ_core->crest_mod_lp, &st->hHQ_core->crest_mod_lp_fx, &temp_e );
                    st->hHQ_core->crest_mod_lp_q = sub( Q31, temp_e );
                }
            }

            floatToFixed_arr( st->input - delay, st->input_fx - delay, 0, 960 );
#endif
            hq_core_enc_ivas_fx( st, st->input_fx - delay, input_frame, hq_core_type, Voicing_flag, vad_hover_flag );

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) )
            {
                fixedToFloat_arrL( st->hHQ_core->last_ni_gain_fx, st->hHQ_core->last_ni_gain, Q17, BANDS_MAX );
                fixedToFloat_arr( st->hHQ_core->last_env_fx, st->hHQ_core->last_env, Q1, BANDS_MAX );
            }
            ELSE
            {
                IF( NE_16( st->element_mode, EVS_MONO ) )
                {

                    st->hHQ_core->crest_lp = fix_to_float( st->hHQ_core->crest_lp_fx, st->hHQ_core->crest_lp_q );
                    st->hHQ_core->crest_mod_lp = fix_to_float( st->hHQ_core->crest_mod_lp_fx, st->hHQ_core->crest_mod_lp_q );
                }
            }
            IF( st->element_mode > EVS_MONO )
            {
                FOR( i = 0; i < L_FRAME32k; i++ )
                {
                    st->hLPDmem->old_exc_flt[i] = fix16_to_float( st->hLPDmem->old_exc[i], 0 );
                }
            }
#endif
#else
            hq_core_enc( st, st->input - delay, input_frame, hq_core_type, Voicing_flag, vad_hover_flag );
#endif
        }

        /*---------------------------------------------------------------------*
+131 −23
Original line number Diff line number Diff line
@@ -1180,10 +1180,19 @@ void FdCngEncodeMDCTStereoSID(
    int16_t gain_idx[CPE_CHANNELS];
    int16_t N, stages, ch, p, coh_idx;
    float side_energy;
#ifdef IVAS_FLOAT_FIXED
    Word32 *lr_out_ptr_fx[CPE_CHANNELS];
    Word32 gain_fx[CPE_CHANNELS];
    Word32 side_energy_fx;
    Word32 *invTrfMatrix_fx;
    Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; /*24*18*/
    invTrfMatrix_fx = (Word32 *) tmpRAM_fx;                    /* dynamically filled  */
#endif
    int16_t no_side_flag;
    int16_t is_inp_ms;

    float tot_sig_ext[FDCNG_VQ_MAX_LEN], dct_target[CPE_CHANNELS][FDCNG_VQ_DCT_MAXTRUNC]; /* 24 +2*18*/
    float tot_sig_ext[FDCNG_VQ_MAX_LEN] /*, dct_target[CPE_CHANNELS][FDCNG_VQ_DCT_MAXTRUNC]*/;   /* 24 +2*18*/
    Word32 tot_sig_ext_fx[FDCNG_VQ_MAX_LEN], dct_target_fx[CPE_CHANNELS][FDCNG_VQ_DCT_MAXTRUNC]; /* 24 +2*18*/
    float *invTrfMatrix;
    float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; /*24*18*/
    invTrfMatrix = (float *) tmpRAM;                       /* dynamically filled  */
@@ -1202,6 +1211,9 @@ void FdCngEncodeMDCTStereoSID(
        lr_in_ptr[ch] = &sts[ch]->hFdCngEnc->msNoiseEst[0];
        ms_ptr[ch] = &logNoiseEst[ch][0];
        lr_out_ptr[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt[0];
#ifdef IVAS_FLOAT_FIXED
        lr_out_ptr_fx[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0];
#endif
    }
    N = sts[0]->hFdCngEnc->npartDec;
    set_f( weights, 1.f, NPART );
@@ -1216,17 +1228,19 @@ void FdCngEncodeMDCTStereoSID(
            E[ch] += ms_ptr[ch][p];
        }
    }

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
    Word32 ms_ptr_fx[2][NPART];
    Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1;
    floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N );
    floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N );
#endif
    /* M/S transform on log envelopes */
    if ( is_inp_ms == 0 )
    {
#ifndef IVAS_FLOAT_FIXED
        convertToMS( N, ms_ptr[0], ms_ptr[1], 0.5f );
#else
        Word32 ms_ptr_fx[2][NPART];
        Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1;
        floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N );
        floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N );


        convertToMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q30 );

@@ -1234,8 +1248,15 @@ void FdCngEncodeMDCTStereoSID(
        fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, N );
#endif
    }

#ifndef IVAS_FLOAT_FIXED
    side_energy = sum2_f( ms_ptr[1], N );
#else
    Word16 gb = find_guarded_bits_fx( N );
    side_energy_fx = sum2_f_32_fx( ms_ptr_fx[1], N, gb );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
    side_energy = fixedToFloat( side_energy_fx, 2 * q - 31 - gb );
#endif
#endif

    /* do not transmit side shape if initial noise shapes are very similar */
    if ( side_energy <= 0.1f )
@@ -1269,27 +1290,68 @@ void FdCngEncodeMDCTStereoSID(
    /* High quality cosine smooth basis extension used  to not introduce noise in stage#1  DCT24 analysis and subsequent VQ-steps */
    if ( N == FDCNG_VQ_MAX_LEN_WB )
    {
        create_IDCT_N_Matrix( invTrfMatrix, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) ); /*WB: create truncated IDCT21 matrix */
#ifdef IVAS_FLOAT_FIXED
        Word16 size_value, temp_e;
        size_value = BASOP_Util_Divide1616_Scale( sizeof( tmpRAM_fx ), ( sizeof( Word32 ) ), &temp_e ); /*Q15*/
        size_value = shr( size_value, sub( 15, temp_e ) );
        create_IDCT_N_Matrix_fx( invTrfMatrix_fx, N, FDCNG_VQ_DCT_MAXTRUNC, size_value ); // Q31 /*WB: create truncated IDCT21 matrix */
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        for ( int i = 0; i < FDCNG_VQ_MAX_LEN; i++ )
        {
            fixedToFloat_arrL( tmpRAM_fx[i], tmpRAM[i], Q31, FDCNG_VQ_DCT_MAXTRUNC );
        }
        q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1;
        floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N );
        floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N );

#endif
#else
        create_IDCT_N_Matrix( invTrfMatrix, N, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) ); /*WB: create truncated IDCT21 matrix */
#endif
        for ( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
            /* run DCT_N N==21 , truncated at 18/21 ~= 86% , i.e use a bit better better quality in extrapolation , than subsequent DCT24 analysis which is truncated at 75%*/
#ifdef IVAS_FLOAT_FIXED
            /* truncated DCT 21 analysis */
            dctT2_N_apply_matrix_fx( (const Word32 *) ms_ptr_fx[ch], dct_target_fx[ch], FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix_fx, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX );
            /* extrapolate extend fdcng envelope signal in the fdncg ienvelope/"time" domain using DCT21 basis vectors,
                estimated DCT21 coeffs scaling extended basis vectors are used to create extrapolated   length 24 input target envelope signal */
            /* this DCT21 extension does not introduce DCT24 coefficient noise for  the subsequent dct24 target analysis, and later in IDCT24 synthesis  */

            /* truncated IDCT 21 extension synthesis  */
            extend_dctN_input_fx( ms_ptr_fx[ch], dct_target_fx[ch], N, tot_sig_ext_fx, FDCNG_VQ_MAX_LEN, invTrfMatrix_fx /* DCT_N basis vectors */, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); /* use 18 basis vectors*/
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            fixedToFloat_arrL( tot_sig_ext_fx, tot_sig_ext, q, FDCNG_VQ_MAX_LEN );
#endif
#else
            /* truncated DCT 21 analysis */
            dctT2_N_apply_matrix( (const float *) ms_ptr[ch], dct_target[ch], FDCNG_VQ_DCT_MAXTRUNC, N, invTrfMatrix, FDCNG_VQ_DCT_MAXTRUNC, DCT_T2_21_XX );

            /* extrapolate extend fdcng envelope signal in the fdncg ienvelope/"time" domain using DCT21 basis vectors,
                estimated DCT21 coeffs scaling extended basis vectors are used to create extrapolated   length 24 input target envelope signal */
            /* this DCT21 extension does not introduce DCT24 coefficient noise for  the subsequent dct24 target analysis, and later in IDCT24 synthesis  */

            /* truncated IDCT 21 extension synthesis  */
            extend_dctN_input( ms_ptr[ch], dct_target[ch], N, tot_sig_ext, FDCNG_VQ_MAX_LEN, invTrfMatrix /* DCT_N basis vectors */, FDCNG_VQ_DCT_MAXTRUNC, IDCT_T2_XX_21 ); /* use 18 basis vectors*/
#endif


            mvr2r( tot_sig_ext, ms_ptr[ch], FDCNG_VQ_MAX_LEN ); /*  write  extended result as input to  VQ */
        }
    }
#ifdef IVAS_FLOAT_FIXED
    Word16 size_value, temp_e;
    size_value = BASOP_Util_Divide1616_Scale( sizeof( tmpRAM_fx ), ( sizeof( Word32 ) ), &temp_e ); /*Q15*/
    size_value = shr( size_value, sub( 15, temp_e ) );
    create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, size_value ); /*always create/set up  IDCT24 matrix in RAM */
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
    for ( int i = 0; i < FDCNG_VQ_MAX_LEN; i++ )
    {
        fixedToFloat_arrL( tmpRAM_fx[i], tmpRAM[i], Q31, FDCNG_VQ_DCT_MAXTRUNC );
    }
#endif
#else
    create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) );                                                   /*always create/set up  IDCT24 matrix in RAM */

#endif
    /* end split */
    for ( ch = 0; ch < CPE_CHANNELS; ch++ )
    {
@@ -1310,19 +1372,17 @@ void FdCngEncodeMDCTStereoSID(
        {
#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            Word32 ms_ptr_fx[24];

            Word16 ms_ptr_e;
            Word32 *invTrfMatrix_fx;
            Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
            Word16 weights_fx[24];
            invTrfMatrix_fx = (Word32 *) tmpRAM_fx;

            f2me_buf( ms_ptr[ch], ms_ptr_fx, &ms_ptr_e, N );
            f2me_buf( ms_ptr[ch], ms_ptr_fx[ch], &ms_ptr_e, N );
            floatToFixed_arrL( invTrfMatrix, invTrfMatrix_fx, Q31, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
            floatToFixed_arr( weights, weights_fx, Q8, 24 );

#endif
            msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, ms_ptr_fx, ms_ptr_e, levels_37bits, FD_CNG_maxC_37bits, stages, weights_fx, N, FD_CNG_maxN_37bits, 1, invTrfMatrix_fx, indices[ch] );
            msvq_enc_ivas_fx( ivas_cdk_37bits_fx, Q7, NULL, NULL, ms_ptr_fx[ch], ms_ptr_e, levels_37bits, FD_CNG_maxC_37bits, stages, weights_fx, N, FD_CNG_maxN_37bits, 1, invTrfMatrix_fx, indices[ch] );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            fixedToFloat_arrL( invTrfMatrix_fx, invTrfMatrix, Q31, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC );
#endif
@@ -1344,15 +1404,17 @@ void FdCngEncodeMDCTStereoSID(
#ifndef IVAS_FLOAT_FIXED
        convertToMS( N, ms_ptr[0], ms_ptr[1], 1.0f );
#else
        Word32 ms_ptr_fx[2][NPART];
        Word16 q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1;
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        //   Word32 ms_ptr_fx[2][NPART];
        q = s_min( Q_factor_arrL( ms_ptr[0], N ), Q_factor_arrL( ms_ptr[1], N ) ) - 1;
        floatToFixed_arrL( ms_ptr[0], ms_ptr_fx[0], q, N );
        floatToFixed_arrL( ms_ptr[1], ms_ptr_fx[1], q, N );

#endif
        convertToMS_fx( N, ms_ptr_fx[0], ms_ptr_fx[1], ONE_IN_Q31 );

#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        fixedToFloat_arrL( ms_ptr_fx[0], ms_ptr[0], q, N );
        fixedToFloat_arrL( ms_ptr_fx[1], ms_ptr[1], q, N );
#endif
#endif
    }

@@ -1365,8 +1427,18 @@ void FdCngEncodeMDCTStereoSID(
            gain[ch] += ms_ptr[ch][p];
        }
        gain[ch] = ( E[ch] - gain[ch] ) / (float) N;
#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        gain_fx[ch] = floatToFixed_32( gain[ch], Q23 );
#endif
        apply_scale( &gain_fx[ch], sts[ch]->hFdCngEnc->hFdCngCom->CngBandwidth, sts[ch]->element_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        gain[ch] = fixedToFloat_32( gain_fx[ch], Q23 );
#endif
#else
        apply_scale_flt( &gain[ch], sts[ch]->hFdCngEnc->hFdCngCom->CngBandwidth, sts[ch]->element_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );

#endif
        /* quantize gain */
        gain_idx[ch] = (int16_t) floor( gain[ch] * 1.5f + GAIN_Q_OFFSET_IVAS + .5f );
        gain_idx[ch] = max( 0, min( 127, gain_idx[ch] ) );
@@ -1385,11 +1457,27 @@ void FdCngEncodeMDCTStereoSID(
            lr_out_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
        }

#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        q = Q_factor_arrL( lr_out_ptr[ch], N );
        floatToFixed_arrL( lr_out_ptr[ch], lr_out_ptr_fx[ch], q, N );
#endif
        /* scale bands and get scalefactors */
        scalebands( lr_out_ptr_fx[ch], hFdCngEnc->partDec, N, hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, sub( hFdCngEnc->stopBandDec, hFdCngEnc->startBandDec ), hFdCngCom->cngNoiseLevel, 1 );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        fixedToFloat_arrL( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel_flt, q, FFTCLDFBLEN );
#endif
        lpc_from_spectrum( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        sts[ch]->preemph_fac_flt = fixedToFloat( sts[ch]->preemph_fac, Q15 );
#endif
#else
        /* scale bands and get scalefactors */
        scalebands_flt( lr_out_ptr[ch], hFdCngEnc->partDec, N, hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, hFdCngEnc->stopBandDec - hFdCngEnc->startBandDec, hFdCngCom->cngNoiseLevel_flt, 1 );

        lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt );

#endif

        sts[ch]->hDtxEnc->last_CNG_L_frame = sts[ch]->L_frame;
    }

@@ -1451,6 +1539,9 @@ void FdCngEncodeDiracMDCTStereoSID(
    float *lr_in_ptr[CPE_CHANNELS];
    float *ms_ptr[CPE_CHANNELS];
    float *lr_out_ptr[CPE_CHANNELS];
#ifdef IVAS_FLOAT_FIXED
    Word32 *lr_out_ptr_fx[CPE_CHANNELS];
#endif
    float logNoiseEst[CPE_CHANNELS][NPART];
    float E[CPE_CHANNELS];
    float gain[CPE_CHANNELS];
@@ -1473,6 +1564,9 @@ void FdCngEncodeDiracMDCTStereoSID(
        lr_in_ptr[ch] = &sts[ch]->hFdCngEnc->msNoiseEst[0];
        ms_ptr[ch] = &logNoiseEst[ch][0];
        lr_out_ptr[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst_flt[0];
#ifdef IVAS_FLOAT_FIXED
        lr_out_ptr_fx[ch] = &sts[ch]->hFdCngEnc->hFdCngCom->sidNoiseEst[0];
#endif
    }
    set_f( weights, 1.f, NPART );

@@ -1602,12 +1696,26 @@ void FdCngEncodeDiracMDCTStereoSID(
        {
            lr_out_ptr[ch][N[ch] - 1] *= SWB_13k2_LAST_BAND_SCALE_FLT;
        }

#ifdef IVAS_FLOAT_FIXED
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        q = Q_factor_arrL( lr_out_ptr[ch], N[ch] );
        floatToFixed_arrL( lr_out_ptr[ch], lr_out_ptr_fx[ch], q, N[ch] );
#endif
        /* scale bands and get scalefactors */
        scalebands( lr_out_ptr_fx[ch], hFdCngEnc->partDec, N[ch], hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, sub( hFdCngEnc->stopBandDec, hFdCngEnc->startBandDec ), hFdCngCom->cngNoiseLevel, 1 );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        fixedToFloat_arrL( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel_flt, q, FFTCLDFBLEN );
#endif
        lpc_from_spectrum( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
        sts[ch]->preemph_fac_flt = fixedToFloat( sts[ch]->preemph_fac, Q15 );
#endif
#else
        /* scale bands and get scalefactors */
        scalebands_flt( lr_out_ptr[ch], hFdCngEnc->partDec, N[ch], hFdCngEnc->midbandDec, hFdCngEnc->nFFTpartDec, hFdCngEnc->stopBandDec - hFdCngEnc->startBandDec, hFdCngCom->cngNoiseLevel_flt, 1 );

        lpc_from_spectrum_flt( hFdCngCom, hFdCngEnc->startBandDec, hFdCngEnc->stopFFTbinDec, sts[ch]->preemph_fac_flt );

#endif
        sts[ch]->hDtxEnc->last_CNG_L_frame = sts[ch]->L_frame;
    }
    sts[0]->hFdCngEnc->hFdCngCom->coherence_flt = 0.0f;
+364 −50

File changed.

Preview size limit exceeded, changes collapsed.

Loading