Commit dbfff24f authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Encoder clean up in core-coder functions

parent cc285e8c
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -3223,22 +3223,41 @@ int16_t read_GR0(
/*----------------------------------------------------------------------------------*
 * MCT prototypes
 *----------------------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_mdct_core_whitening_enc_fx(
    CPE_ENC_HANDLE hCPE,                                        /* i/o: CPE encoder structure                   */
    Word16 new_samples_fx[CPE_CHANNELS][L_INP],                     /* i  : new samples                             */
    Word16 old_wsp_fx[CPE_CHANNELS][L_WSP],                         /* i  : 12.8kHz weighted speech (for LTP        */
    Word16 pitch_buf[CPE_CHANNELS][NB_SUBFR16k],                 /* o  : floating pitch for each subframe        */
    Word32 *mdst_spectrum_long[CPE_CHANNELS],                    /* o  : buffer for MDST spectrum                */
    int16_t tnsBits[CPE_CHANNELS][NB_DIV],                      /* o  : buffer TNS bits                         */
    Word32 *orig_spectrum_long[CPE_CHANNELS],                    /* o  : origingal spectrum w/o whitening        */
    int16_t tnsSize[CPE_CHANNELS][NB_DIV],                      /* o  : size of TNS                             */
    int16_t p_param[CPE_CHANNELS][NB_DIV],                      /* o  : pointer to parameter array              */
    BSTR_ENC_HANDLE hBstr,                                      /* i/o: encoder bitstream handle                */
    const int16_t mct_on,                                       /* i  : flag mct block (1) or stereo (0)        */
    const int16_t nChannels,                                     /* i  : total number of coded channels          */
Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV],
Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV]
);
#else
void ivas_mdct_core_whitening_enc(
    CPE_ENC_HANDLE hCPE,                                        /* i/o: CPE encoder structure                   */
    Word16 new_samples_fx[CPE_CHANNELS][L_INP],                     /* i  : new samples                             */
    Word16 old_wsp_fx[CPE_CHANNELS][L_WSP],                         /* i  : 12.8kHz weighted speech (for LTP        */
    Word16 pitch_buf[CPE_CHANNELS][NB_SUBFR16k],                 /* o  : floating pitch for each subframe        */
    float *mdst_spectrum_long[CPE_CHANNELS],                    /* o  : buffer for MDST spectrum                */
    Word32 *mdst_spectrum_long[CPE_CHANNELS],                    /* o  : buffer for MDST spectrum                */
    int16_t tnsBits[CPE_CHANNELS][NB_DIV],                      /* o  : buffer TNS bits                         */
    float *orig_spectrum_long[CPE_CHANNELS],                    /* o  : origingal spectrum w/o whitening        */
    Word32 *orig_spectrum_long[CPE_CHANNELS],                    /* o  : origingal spectrum w/o whitening        */
    int16_t tnsSize[CPE_CHANNELS][NB_DIV],                      /* o  : size of TNS                             */
    int16_t p_param[CPE_CHANNELS][NB_DIV],                      /* o  : pointer to parameter array              */
    BSTR_ENC_HANDLE hBstr,                                      /* i/o: encoder bitstream handle                */
    const int16_t mct_on,                                       /* i  : flag mct block (1) or stereo (0)        */
    const int16_t nChannels                                     /* i  : total number of coded channels          */
    const int16_t nChannels,                                     /* i  : total number of coded channels          */
Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV],
Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV]
);

#endif
void ivas_mct_core_enc(
    const IVAS_FORMAT ivas_format,                              /* i  : IVAS format                             */
    MCT_ENC_HANDLE hMCT,                                        /* i/o: MCT encoder structure                   */
+2 −2
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@ void init_coder_ace_plus_ivas_fx(
    {
        st->acelpFramesCount = 0;
        move16();
        st->prevTempFlatness_fx = 16 /*1.0f Q4*/;
        st->prevTempFlatness_fx = 128 /*1.0f Q7*/;
        move16();
    }

@@ -405,7 +405,7 @@ void init_coder_ace_plus(
#endif
#ifdef IVAS_FLOAT_FIXED
#ifdef MSAN_FIX
        st->prevTempFlatness_fx = 16; // Q4
        st->prevTempFlatness_fx = 128; // Q7
#endif
#endif
    }
+61 −3
Original line number Diff line number Diff line
@@ -478,22 +478,80 @@ ivas_error ivas_core_enc(
        {
            IF( MCT_flag )
            {
                Word16 mdst_spectrum_e[CPE_CHANNELS][NB_DIV];
                Word16 orig_spectrum_e[CPE_CHANNELS][NB_DIV];
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
                Word16 old_inp_16k_fx[CPE_CHANNELS][L_INP];
                Word16 old_wsp_fx[CPE_CHANNELS][L_WSP], q_fac[CPE_CHANNELS];
                Word16 old_wsp_fx[CPE_CHANNELS][L_WSP], q_fac[CPE_CHANNELS], q_fac1 = Q15;
                Word16 pitch_buf_fx_new[CPE_CHANNELS][NB_SUBFR16k]; /* Q6 */
                for ( i = 0; i < CPE_CHANNELS; i++ )
                {
                    Encoder_State *st1 = sts[i];
                    TCX_ENC_HANDLE hTcxEncCh = st1->hTcxEnc;
                    Word16 nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV;
                    for ( n = 0; n < nSubframes; n++ )
                    {
                        Word16 nl = (Word16) ( (float) ( hTcxEncCh->L_frameTCX / nSubframes ) * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
                        floatToFixed_arr( &hTcxEncCh->new_speech_TCX_flt[nl - ( hTcxEncCh->L_frameTCX / nSubframes )],
                                          &hTcxEncCh->new_speech_TCX[nl - ( hTcxEncCh->L_frameTCX / nSubframes )],
                                          0,
                                          2 * hTcxEncCh->L_frameTCX / nSubframes );

                        IF( n == 0 )
                        {
                            floatToFixed_arr( &hTcxEncCh->speech_TCX_flt[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )],
                                              &hTcxEncCh->speech_TCX[-( sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB - 0 )],
                                              0,
                                              sts[0]->hTcxCfg->tcx_mdct_window_min_lengthFB );
                        }
                    }

                    floatToFixed_arr( old_inp_16k[i], old_inp_16k_fx[i], 0, L_INP );
                    q_fac[i] = Q_factor_arr( old_wsp[i], L_WSP );
                    floatToFixed_arr( old_wsp[i], old_wsp_fx[i], q_fac[i], L_WSP );
                    if ( st1->element_mode == IVAS_CPE_DFT )
                    {
                        q_fac1 = Q_factor_arr( st1->buf_wspeech_enc_flt, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 );
                        floatToFixed_arr( st1->buf_wspeech_enc_flt, st1->buf_wspeech_enc, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 );
                        st1->exp_buf_wspeech_enc = 15 - q_fac1;
                    }
                    else if ( st1->element_mode != IVAS_CPE_MDCT )
                    {
                        q_fac1 = Q_factor_arr( st1->buf_speech_enc_flt, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
                        floatToFixed_arr( st1->buf_speech_enc_flt, st1->buf_speech_enc, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
                        st1->exp_buf_speech_enc = 15 - q_fac1;
                        floatToFixed_arr( st1->hTcxEnc->buf_speech_ltp_flt, st1->hTcxEnc->buf_speech_ltp, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
                        st1->hTcxEnc->exp_buf_speech_ltp = 15 - q_fac1;
                    }
                    floatToFixed_arr( st1->input_buff, st1->input_buff_fx, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) );
                }
#endif
                ivas_mdct_core_whitening_enc( hCPE, old_inp_16k_fx, old_wsp_fx, pitch_buf_fx_new, hMCT->p_mdst_spectrum_long[cpe_id], hMCT->tnsBits[cpe_id], hMCT->p_orig_spectrum_long[cpe_id],
                                              hMCT->tnsSize[cpe_id], hMCT->p_param[cpe_id], hMCT->hBstr, 1, hMCT->nchan_out_woLFE );
                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 );
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
                for ( i = 0; i < CPE_CHANNELS; i++ )
                {
                    Encoder_State *st1 = sts[i];
                    Word16 nSubframes = ( st1->hTcxEnc->tcxMode == TCX_20 ) ? 1 : NB_DIV;
                    if ( st1->element_mode == IVAS_CPE_DFT )
                    {
                        fixedToFloat_arr( st1->buf_wspeech_enc, st1->buf_wspeech_enc_flt, q_fac1, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320 );
                    }
                    else if ( st1->element_mode != IVAS_CPE_MDCT )
                    {
                        fixedToFloat_arr( st1->hTcxEnc->buf_speech_ltp, st1->hTcxEnc->buf_speech_ltp_flt, q_fac1, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k );
                    }
                    fixedToFloat_arr( st1->input_buff_fx, st1->input_buff, 0, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) );

                    fixedToFloat_arrL( st1->hTcxEnc->spectrum_fx[0], st1->hTcxEnc->spectrum[0], 31 - st1->hTcxEnc->spectrum_e[0], st1->hTcxEnc->L_frameTCX / nSubframes );
                    fixedToFloat_arrL( hMCT->p_orig_spectrum_long_fx[cpe_id][i], hMCT->p_orig_spectrum_long[cpe_id][i], 31 - orig_spectrum_e[i][0], N_TCX10_MAX );
                    fixedToFloat_arrL( hMCT->p_mdst_spectrum_long_fx[cpe_id][i], hMCT->p_mdst_spectrum_long[cpe_id][i], 31 - mdst_spectrum_e[i][0], N_TCX10_MAX );
                    if ( nSubframes == NB_DIV )
                    {
                        fixedToFloat_arrL( st1->hTcxEnc->spectrum_fx[1], st1->hTcxEnc->spectrum[1], 31 - st1->hTcxEnc->spectrum_e[1], st1->hTcxEnc->L_frameTCX / nSubframes );
                        fixedToFloat_arrL( hMCT->p_orig_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, hMCT->p_orig_spectrum_long[cpe_id][i] + N_TCX10_MAX, 31 - orig_spectrum_e[i][1], N_TCX10_MAX );
                        fixedToFloat_arrL( hMCT->p_mdst_spectrum_long_fx[cpe_id][i] + N_TCX10_MAX, hMCT->p_mdst_spectrum_long[cpe_id][i] + N_TCX10_MAX, 31 - mdst_spectrum_e[i][1], N_TCX10_MAX );
                    }
                    fixedToFloat_arr( old_wsp_fx[i], old_wsp[i], q_fac[i], L_WSP );
                }
#endif
+0 −27
Original line number Diff line number Diff line
@@ -2588,33 +2588,6 @@ ivas_error pre_proc_front_ivas_fx(
        /* Switch to ACELP for non-harmonic transient signals */
        else if ( ( ( element_mode >= IVAS_CPE_DFT && element_brate <= IVAS_16k4 ) || ( element_mode == IVAS_SCE && element_brate < SCE_SMC_THR ) ) && ( loc_harm[0] != 1 ) && smc_dec == MUSIC )
        {
#ifdef IVAS_FLOAT_FIXED_CONVERSIONS
            IF( EQ_16( element_mode, IVAS_SCE ) )
            {
                Word16 q1 = Q7;
                Word16 q2 = Q7;
                st->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 );
                st->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 );
                move16();
                move16();
                move16();
                move16();
            }
            ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
            {
                FOR( i = 0; i < CPE_CHANNELS; i++ )
                {
                    Word16 q1 = Q7;
                    Word16 q2 = Q7;
                    hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.subblockNrg_e = sub( 31, q1 );
                    hCPE->hCoreCoder[i]->hTranDet->subblockEnergies.accSubblockNrg_e = sub( 31, q2 );
                    move16();
                    move16();
                    move16();
                    move16();
                }
            }
#endif
            IF( EQ_16( element_mode, IVAS_SCE ) )
            {
                if ( transient_analysis_ivas_fx( st->hTranDet, st->hNoiseEst->cor_map_fx, Q15, st->hNoiseEst->multi_harm_limit_fx, Q9 ) )
+1 −1
Original line number Diff line number Diff line
@@ -459,7 +459,7 @@ ivas_error ivas_cpe_enc_fx(
            RunTransientDetection_ivas_fx( sts[n]->input_fx, input_frame, sts[n]->hTranDet, q_inp ); // Note q of sts[n]->input_fx changes inside function
        }

        currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q4
        currFlatness_fx[n] = GetTCXAvgTemporalFlatnessMeasure_ivas_fx( (const TransientDetection *) sts[n]->hTranDet, NSUBBLOCKS, 0 ); // Q7
        move16();
    }

Loading