Commit 13b77d96 authored by vaclav's avatar vaclav
Browse files

HARM_HQ_CORE2

parent 376de564
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1580,6 +1580,7 @@ ivas_error ivas_osba_render_sf_fx(
    Word32 *p_output[]                                          /* o  : rendered time signal                    */
);

#ifndef HARM_HQ_CORE2
void ivas_hq_core_dec_fx(
    Decoder_State *st_fx,                                       /* i/o: decoder state structure fx              */
    Word16 synth[],                                             /* o  : output synthesis                        */
@@ -1589,7 +1590,7 @@ void ivas_hq_core_dec_fx(
    const Word16 core_switching_flag,                           /* i  : ACELP->HQ switching frame flag          */
    Word32 *output_32_fx                                        /* o  : synthesis @internal_Fs, Q11             */
);

#endif
/* o  : Consumed bits  Q0 */
Word16 ivas_hq_classifier_dec_fx(                          
    Decoder_State *st_fx,                                       /* i/o: decoder state structure                 */
+1 −1
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@
#define FIX_2424_REMOVE_GAUSS_L2_ENC                    /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */
#define HARM_HQ_CORE                                    /* harmonize HQ core functions */
#define HARM_HQ_CORE_KEEP_EVS_BE                  // hack to keep EVS BE
//#define HARM_HQ_CORE2
#define HARM_HQ_CORE2

/* #################### End BE switches ################################## */

+14 −8
Original line number Diff line number Diff line
@@ -7071,6 +7071,7 @@ void fd_bwe_dec_init(
    FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle  */
);

#ifndef HARM_HQ_CORE2
void hq_core_enc_ivas_fx(
    Encoder_State *st,          /* i/o: encoder state structure                   */
    const Word16 *audio_fx,     /* i  : input audio signal                       Q0 */
@@ -7079,14 +7080,19 @@ void hq_core_enc_ivas_fx(
    const Word16 Voicing_flag,  /* i  : Voicing flag for FER method selection     Q0*/
    const Word16 vad_hover_flag /* i  : VAD hangover flag                         Q0*/
);

#endif
void hq_core_dec_fx(
    Decoder_State *st_fx,      /* i/o: decoder state structure fx         */
    Word16 synth[],            /* o  : output synthesis                   Q_synth*/
    Word16 *Q_synth,           /* o  : Q value of synth                   */
    const Word16 output_frame, /* i  : output frame length                Q0*/
    const Word16 hq_core_type, /* i  : HQ core type                       Q0*/
#ifdef HARM_HQ_CORE2
    const Word16 core_switching_flag, /* i  : ACELP->HQ switching frame flag     */
    Word32 *output_32_fx              /* o  : synthesis @internal_Fs, Q11        */
#else
    const Word16 core_switching_flag /* i  : ACELP->HQ switching frame flag     Q0*/
#endif
);

void HQ_core_dec_init_fx(
+4 −0
Original line number Diff line number Diff line
@@ -348,7 +348,11 @@ ivas_error evs_dec_fx(
        }
        ELSE
        {
#ifdef HARM_HQ_CORE2
            hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag, NULL );
#else
            hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag );
#endif
            Qpostd = Q_synth;
            move16();
        }
+146 −21
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 *
 *  HQ core decoder
 *--------------------------------------------------------------------------*/

void hq_core_dec_fx(
#ifndef HARM_HQ_CORE2
    Decoder_State *st_fx,            /* i/o: decoder state structure fx         */
    Word16 synth[],                  /* o  : output synthesis                   Q_synth*/
    Word16 *Q_synth,                 /* o  : Q value of synth                   */
@@ -471,6 +471,7 @@ void hq_core_dec_fx(


void ivas_hq_core_dec_fx(
#endif
    Decoder_State *st_fx,             /* i/o: decoder state structure fx         */
    Word16 synth[],                   /* o  : output synthesis                   Q_synth*/
    Word16 *Q_synth,                  /* o  : Q value of synth                   */
@@ -499,16 +500,15 @@ void ivas_hq_core_dec_fx(
    UWord16 lsb;
    Word16 L_spec;
    HQ_DEC_HANDLE hHQ_core;

    hHQ_core = st_fx->hHQ_core;

#ifdef HARM_HQ_CORE2
    const Word16 *sfmsize, *sfm_start, *sfm_end;
#endif
    TCX_DEC_HANDLE hTcxDec;
    TCX_CONFIG_HANDLE tcx_cfg;
    Word16 index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX;
    Word16 tcx_offset, overlap, L_frame;
    Word16 L_frameTCX_glob, L_frame_glob;
    Word16 acelp_zir[L_FRAME_MAX / 2];
    // Word16 encoderLookahead, encoderLookaheadFB;
    Word16 hq_recovery_flag;
    Word16 mdctWindowLength;
    Word16 mdctWindowLengthFB;
@@ -516,6 +516,8 @@ void ivas_hq_core_dec_fx(
    Word16 output[L_FRAME16k];
    Word16 Q_output;

    hHQ_core = st_fx->hHQ_core;

    Q_output = 0;
    move16();
    *Q_synth = 0;
@@ -580,13 +582,25 @@ void ivas_hq_core_dec_fx(
            }
            ELSE
            {
#ifdef HARM_HQ_CORE2
                core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame );

                /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */
                if ( GT_16( num_bits, HQ_48k / 50 ) )
                {
                    num_bits = (Word16) ( HQ_48k / 50 );
                    move16();
                }
#else
                /* this cannot happen in IVAS */
#endif
            }
        }
        IF( hq_recovery_flag )
        {
            acelp_plc_mdct_transition_fx( st_fx );
        }

        /* subtract signalling bits */
        num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */

@@ -633,6 +647,13 @@ void ivas_hq_core_dec_fx(
        }
    }

#ifdef HARM_HQ_CORE2
    IF( EQ_16( output_frame, L_FRAME8k ) )
    {
        hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end );
    }

#endif
    /*--------------------------------------------------------------------------
     * transform-domain decoding
     *--------------------------------------------------------------------------*/
@@ -679,13 +700,27 @@ void ivas_hq_core_dec_fx(
    {
        IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) )
        {
#ifdef HARM_HQ_CORE2
            IF( EQ_16( st_fx->prev_bfi, 1 ) )
            {
                set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX );
                set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX );
                hHQ_core->last_max_pos_pulse = 0;
                move16();
            }

            /* HQ low rate decoder */
            hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient );

#else
            /* this cannot happen in IVAS */

            is_transient = 0;
            move16();
#endif
            hqswb_clas = is_transient; /* Q0 */
            move16();
            Q_audio = 12;
            Q_audio = Q12;
            move16();
            Q_G_audio = Q_audio;
            move16();
@@ -694,7 +729,16 @@ void ivas_hq_core_dec_fx(
        {
            /* HQ high rate decoder */
#ifdef HARM_HQ_CORE2
#ifdef HARM_HQ_CORE_KEEP_EVS_BE
            IF( st_fx->element_mode == EVS_MONO )
            {
                hq_hr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag );
            }
            ELSE
#endif
            {
                hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag );
            }
#else
            ivas_hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag );
#endif
@@ -808,9 +852,6 @@ void ivas_hq_core_dec_fx(
        L_spec = hTcxDec->L_frameTCX; /* Q0 */
        move16();
        st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */
        // fscaleFB = sr2fscale( st_fx->output_Fs );
        // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM;
        // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM;
        mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */
        Word16 temp, temp_e;
        temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e );
@@ -918,13 +959,57 @@ void ivas_hq_core_dec_fx(
            move16();
        }

#ifdef HARM_HQ_CORE2
        IF( EQ_16( output_frame, L_FRAME8k ) )
        {
            test();
            IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 )
            {
                Copy_Scale_sig( st_fx->hHQ_core->old_out_fx + N_ZERO_NB, st_fx->hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */
            }
            ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) )
            {
                set16_fx( st_fx->hHQ_nbfec->prev_oldauOut_fx, 0, output_frame );
            }

            test();
            test();
            test();
            test();
            IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && hHQ_core->old_is_transient[2] == 0 && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) )
            {
                time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth );
            }
            ELSE
            {
                window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame,
                               st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx );
                st_fx->hHQ_nbfec->phase_mat_next = 0;
                move16();
            }

            test();
            test();
            IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) )
            {
                preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx,
                               &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth );
            }
        }
        ELSE
#endif
        {
            test();
            IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) )
            {
                /* PHASE_ECU active */
#ifdef HARM_HQ_CORE2
                IF( st_fx->element_mode > EVS_MONO )
#endif
                {
                    Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) );
                Q_audio = 15;
                }
                Q_audio = Q15;
                move16();
                window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame,
                               ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx );
@@ -953,6 +1038,33 @@ void ivas_hq_core_dec_fx(
        }
    }

#ifdef HARM_HQ_CORE2
    IF( st_fx->element_mode == EVS_MONO )
    {
        test();
        test();
        test();
        test();
        test();
        test();
        test();
        test();
        IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->hPlcInfo->concealment_method == TCX_NONTONAL && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) )
        {
            st_fx->hPlcInfo->recovery_gain = shl_sat( st_fx->hPlcInfo->recovery_gain, *Q_synth ); /* Q14 + Q_synth */
            move16();
            IF( st_fx->hTonalMDCTConc->q_lastPcmOut != 0 )
            {
                Scale_sig( st_fx->hTonalMDCTConc->secondLastPcmOut, shr( st_fx->hPlcInfo->L_frameTCX, 1 ), negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) );
                Scale_sig( st_fx->hTonalMDCTConc->lastPcmOut, st_fx->hPlcInfo->L_frameTCX, negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) );
                st_fx->hTonalMDCTConc->q_lastPcmOut = 0;
                move16();
            }
            waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth, 0, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi );
        }
    }

#endif
    IF( GE_16( output_frame, L_FRAME16k ) )
    {
        IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) )
@@ -979,15 +1091,23 @@ void ivas_hq_core_dec_fx(
        move16();
    }

    /* prepare synthesis output buffer (as recent as possible) for HQ FEC */
#ifdef HARM_HQ_CORE2
    IF( EQ_16( output_frame, L_FRAME8k ) )
    {
        Copy32( wtda_audio, st_fx->hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 );                                        /* q_wtda */
        Copy( &st_fx->hHQ_nbfec->old_auOut_2fr_fx[output_frame], st_fx->hHQ_nbfec->old_auOut_2fr_fx, output_frame );  /* q_old_auOut */
        Copy_Scale_sig( synth, &st_fx->hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */
    }

#endif
    /* prepare synthesis output buffer (as recent as possible) for HQ FEC */
    {
        Word16 nbsubfr;
        /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/
        nbsubfr = 4; /* Q0 */
        if ( EQ_16( st_fx->L_frame, 320 ) )
        nbsubfr = NB_SUBFR; /* Q0 */
        move16();
        if ( EQ_16( st_fx->L_frame, L_FRAME16k ) )
        {
            nbsubfr = 5; /* Q0 */
            nbsubfr = NB_SUBFR16k; /* Q0 */
            move16();
        }

@@ -1003,11 +1123,16 @@ void ivas_hq_core_dec_fx(
        set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr );
    }

#ifdef HARM_HQ_CORE2
    IF( output_32_fx != NULL )
#endif
    {
        /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */
        Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */

        Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11
        st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) );
    }

    return;
}
Loading