Commit b3c0bbf8 authored by vaclav's avatar vaclav
Browse files

Merge branch 'basop-2280-back-and-forth-scaling-in-core-coder-nonBE' into 'main'

[non-BE] [allow-regression] Back and forth scaling in core decoder - non-BE

See merge request !2787
parents b7da79f9 456c9be8
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1587,8 +1587,12 @@ void ivas_hq_core_dec_fx(
    const Word16 output_frame,                                  /* i  : output frame length                     */
    const Word16 hq_core_type,                                  /* i  : HQ core type                            */
    const Word16 core_switching_flag,                           /* i  : ACELP->HQ switching frame flag          */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 *output_32_fx                                        /* o  : synthesis @internal_Fs, Q11             */
#else
    Word16 output[],
    Word16 *Q_output 
#endif
);

#ifndef HARMONIZE_TBE
@@ -1890,7 +1894,11 @@ void GenShapedWBExcitation_ivas_fx(
/* o : Q_syn_hb*/
Word16 ivas_wb_bwe_dec_fx(
    Decoder_State *st_fx,                                       /* i/o: decoder state structure                 */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 output_fx32[],                                       /* o  : synthesis @internal Fs               Q11*/
#else
    const Word16 output[],                                      /* i  : suntehsis @ internal Fs Q_input         */
    #endif
    Word16 *synth_fx,                                           /* i/o: ACELP core synthesis/final synthesis   Q0/Qpost */
    Word16 *hb_synth_fx,                                        /* o  : SHB synthesis/final synthesis          Q_syn_hb */
    const Word16 use_cldfb_for_dft,                             /* i  : flag to use of CLDFB for DFT Stereo     */
@@ -2088,7 +2096,11 @@ void ivas_buffer_deinterleaved_to_interleaved_fx(
void stereo_tcx_core_dec_fx(
    Decoder_State *st,                                          /* i/o: decoder state structure                     */
    const FRAME_MODE frameMode,                                 /* i  : Decoder frame mode                          */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 *signal_out_32_fx,                                   /* o  : synthesis @internal_Fs, Q11                 */
#else
    Word16 *signal_out,                                         /* o  : synthesis @internal_Fs, Q0                  */
#endif
    Word16 *signal_outFB,                                       /* o  : synthesis @output_Fs, Q0                    */
    Word16 pitch_buf[],                                         /* o  : floating pitch for each subframe, Q6        */
    const Word16 sba_dirac_stereo_flag,                         /* i  : signal stereo output for SBA DirAC          */
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@
#define FIX_2397_COPY_AQ_MDCT_CORE_BFI                  /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */
#define HARMONIZE_TBE                                   /* VA: harmonize core-coder TBE function duplications */
#define FIX_2405_HARM_SMC_INIT                          /* VA, basop 2405, harmonisation of SMC init */
#define FIX_2280_REDUCTION_UNNECESSARY_SCALING          /* VA: reduction of unnecessary scaling */
#define FIX_2280_REDUCTION_UNNECESSARY_SCALING_NONBE    /* VA: reduction of unnecessary scaling, non-BE part */

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

/* #################### Start NON-BE switches ############################ */
+21 −8
Original line number Diff line number Diff line
@@ -7574,8 +7574,13 @@ ivas_error core_switching_pre_dec_fx(
ivas_error core_switching_post_dec_fx(
    Decoder_State *st_fx, /* i/o: decoder state structure                                                           */
    Word16 *synth,        /* i/o: output synthesis                                                            Qsynth*/
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 *output_fx,        /* i/o: LB synth/upsampled LB synth                                                    Q11*/
    Word32 output_mem_fx32[], /* i  : OLA memory from last TCX/HQ frame                                               Qx*/
#else
    Word32 *output_fx,           /* i/o: LB synth/upsampled LB synth                                                     Q4*/
    Word16 output_mem_fx[],      /* i  : OLA memory from last TCX/HQ frame                                               Qx*/
#endif
    const Word16 use_cldfb_for_dft,     /* i  : flag to use of CLDFB for DFT Stereo                                             Q0*/
    const Word16 output_frame,          /* i  : frame length                                                                    Q0*/
    const Word16 core_switching_flag,   /* i  : ACELP->HQ switching flag                                                        Q0*/
@@ -10110,9 +10115,17 @@ Word16 swb_bwe_dec_fx32(
ivas_error acelp_core_dec_fx(
    Decoder_State *st, /* i/o: decoder state structure                                                 */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 output_fx32[], /* o  : synthesis @internal Fs                                               Q11*/
#else
    Word16 output_fx[],          /* o  : synthesis @internal Fs                                                  */
#endif
    Word16 synth_fx16[], /* o  : synthesis                                                               */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 save_hb_synth_fx32[], /* o  : HB synthesis                                                          Q0*/
#else
    Word16 save_hb_synth_fx16[], /* o  : HB synthesis                                                            */
#endif
    Word32 bwe_exc_extended_fx[],        /* i/o: bandwidth extended excitation                                           */
    Word16 *voice_factors_fx,            /* o  : voicing factors                                                         */
    Word16 old_syn_12k8_16k_fx[],        /* o  : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE  */
+29 −5
Original line number Diff line number Diff line
@@ -53,9 +53,17 @@

ivas_error acelp_core_dec_fx(
    Decoder_State *st, /* i/o: decoder state structure                                                 */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 output_fx32[], /* o  : synthesis @internal Fs                                                  Q11*/
#else
    Word16 output_fx[],                         /* o  : synthesis @internal Fs                                                  Q_syn*/
#endif
    Word16 synth_fx16[], /* o  : synthesis                                                               Q_syn2*/
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 save_hb_synth_fx32[], /* o  : HB synthesis                                                            Q0*/
#else
    Word16 save_hb_synth_fx16[],                /* o  : HB synthesis                                                            Q0*/
#endif
    Word32 bwe_exc_extended_fx[],        /* i/o: bandwidth extended excitation                                           2*Q_exc*/
    Word16 *voice_factors_fx,            /* o  : voicing factors                                                         Q15*/
    Word16 old_syn_12k8_16k_fx[],        /* o  : intermediate ACELP synthesis at 12.8kHz or 16kHz to be used by SWB BWE  Q_syn2-1*/
@@ -205,7 +213,11 @@ ivas_error acelp_core_dec_fx(
            Copy( lsp_new_fx, st->lsp_old_fx, M ); /*Q15*/
        }

#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
        set32_fx( output_fx32, 0, st->L_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
#else
        set16_fx( output_fx, 0, output_frame ); /* output and synth are not used in DFT domain CNG generation and the decoder output is unaffected if they are left uninitalized */
#endif
        set16_fx( synth_fx16, 0, output_frame ); /* They are however read in a few places which causes errors in the valgrind tests. Simplest solution from a code perspective was to set them to zero. */

        /* CN generation done in DFT domain */
@@ -2008,7 +2020,11 @@ ivas_error acelp_core_dec_fx(
                }
            }

#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
            IF( save_hb_synth_fx32 != NULL )
#else
            IF( save_hb_synth_fx16 != NULL )
#endif
            {
                /* save and then zero-out lowband */
                max_real = 0;
@@ -2049,9 +2065,13 @@ ivas_error acelp_core_dec_fx(
                    }
                }

#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
                cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx32, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB );
#else
                cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*tmp buffer for save_hb_synth_fx[] */, -1, sub( Q11, Q_real ), -10, st->cldfbSynHB );

                Copy_Scale_sig_32_16( synth_fx, save_hb_synth_fx16, output_frame, 0 ); // Q0
#endif

                /* restore lowband */
                FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ )
@@ -2194,10 +2214,14 @@ ivas_error acelp_core_dec_fx(

        /* Copy output signal */
        Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), negate( st->Q_syn ) ); // Q0
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
        Copy_Scale_sig_16_32_no_sat( psyn_fx, output_fx32, st->L_frame, sub( Q11, st->Q_syn2 ) ); // Q_syn2->Q11
#else
        IF( st->element_mode > EVS_MONO )
        {
            Copy( psyn_fx, output_fx, st->L_frame ); /*Q_syn*/
        }
#endif

        Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); // Q_syn2
        st->Q_syn2 = 0;
+68 −8
Original line number Diff line number Diff line
@@ -172,7 +172,6 @@ void bw_switching_pre_proc_fx(
        }
    }


    test();
    test();
    test();
@@ -207,11 +206,25 @@ void bw_switching_pre_proc_fx(
}


/*---------------------------------------------------------------------*
 * core_switching_post_dec()
 *
 * Postprocessing for ACELP/HQ core switching
 *---------------------------------------------------------------------*/

ivas_error core_switching_post_dec_fx(
    Decoder_State *st_fx, /* i/o: decoder state structure                                                           */
    Word16 *synth,        /* i/o: output synthesis                                                            Qsynth*/
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 *output_fx, /* i/o: LB synth/upsampled LB synth                                                    Q11*/
#else
    Word32 *output_fx,                                                                                      /* i/o: LB synth/upsampled LB synth                                                     Q4*/
#endif
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Word32 output_mem_fx32[], /* i  : OLA memory from last TCX/HQ frame                                               Qx*/
#else
    Word16 output_mem_fx[],                                                                                 /* i  : OLA memory from last TCX/HQ frame                                               Qx*/
#endif
    const Word16 use_cldfb_for_dft,     /* i  : flag to use of CLDFB for DFT Stereo                                             Q0*/
    const Word16 output_frame,          /* i  : frame length                                                                    Q0*/
    const Word16 core_switching_flag,   /* i  : ACELP->HQ switching flag                                                        Q0*/
@@ -433,7 +446,11 @@ ivas_error core_switching_post_dec_fx(
                test();
                IF( ( ( NE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_core_brate, FRAME_NO_DATA ) ) || ( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) && NE_16( st_fx->element_mode, IVAS_CPE_TD ) ) || EQ_16( nchan_out, 1 ) ) && !( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_fx->idchan, 1 ) && ( EQ_16( nchan_out, 1 ) || EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) )
                {
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
                    Scale_sig32( output_fx, L_FRAME48k, Q10 - Q11 ); /* Q10 */
#else
                    Scale_sig32( output_fx, L_FRAME48k, Q10 - Q4 );                                         /* Q10 */
#endif
                    core_switch_lb_upsamp_fx( st_fx, output_fx );
                }

@@ -491,7 +508,11 @@ ivas_error core_switching_post_dec_fx(
                    FOR( i = 0; i < delta; i++ )
                    {
                        st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] =
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
                            Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */
#else
                            Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */
#endif
                        move32();
                        IF( LT_16( alpha, sub( 32767, tmp ) ) )
                        {
@@ -540,7 +561,11 @@ ivas_error core_switching_post_dec_fx(
                    FOR( i = 0; i < delta; i++ )
                    {
                        st_fx->cldfbAna->cldfb_state_fx[offset - delta + i] =
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
                            Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q11 ), alpha ); /* Q10 */
#else
                            Mpy_32_16_1( L_shl( output_fx[st_fx->L_frame - delta + i], Q10 - Q4 ), alpha ); /* Q10 */
#endif
                        move32();
                        IF( LT_16( alpha, sub( 32767, tmp ) ) )
                        {
@@ -602,10 +627,18 @@ ivas_error core_switching_post_dec_fx(
                    hHQ_core->Q_old_wtda = Qtmp;
                    move16();
                }
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
                Word16 output_mem_fx[NS2SA( 48000, STEREO_DFT32MS_OVL_NS )];
                IF( output_mem_fx32 != NULL )
                {
                    Copy_Scale_sig_32_16( output_mem_fx32, output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Qtmp, Q11 ) ); // Qtmp
                }
#else
                IF( output_mem_fx != NULL )
                {
                    Scale_sig( output_mem_fx, NS2SA_FX2( st_fx->output_Fs, STEREO_DFT32MS_OVL_NS ), Qtmp ); /* Qtmp */
                }
#endif
                *Qsynth = Qtmp;
                move16();

@@ -795,7 +828,6 @@ ivas_error core_switching_post_dec_fx(
        test();
        test();
        test();

        IF( ( ( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || EQ_16( st_fx->extl, SWB_CNG ) ) &&
              ( NE_16( st_fx->L_frame, st_fx->last_L_frame ) || ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && NE_16( st_fx->last_core, TCX_20_CORE ) && NE_16( st_fx->last_core, TCX_10_CORE ) ) || EQ_16( st_fx->last_core, HQ_CORE ) ) ) ||
            ( LT_16( st_fx->bwidth, st_fx->last_bwidth ) && NE_16( st_fx->last_extl, SWB_TBE ) ) || st_fx->old_ppp_mode || ( ( EQ_16( st_fx->prev_coder_type, AUDIO ) || EQ_16( st_fx->prev_coder_type, INACTIVE ) ) && st_fx->bws_cnt > 0 ) || ( st_fx->bws_cnt == 0 && EQ_16( st_fx->prev_bws_cnt, N_WS2N_FRAMES ) ) )
@@ -871,6 +903,7 @@ ivas_error core_switching_post_dec_fx(
    return error;
}


/*---------------------------------------------------------------------*
 * core_switching_hq_prepare_dec()
 *
@@ -954,9 +987,17 @@ void core_switching_hq_prepare_dec_fx(

    /* reset state of old_out if switching */
    set16_fx( st_fx->hHQ_core->old_out_fx, 0, output_frame );

    return;
}


/*---------------------------------------------------------------------*
 * core_switch_lb_upsamp()
 *
 * Resample HQ/TCX-LB to the output sampling rate (8/16/32/48 kHz)
 *---------------------------------------------------------------------*/

static void core_switch_lb_upsamp_fx(
    Decoder_State *st, /* i/o: Decoder state                  */
    Word32 *output     /* i/o: LB synth/upsampled LB synth Q10*/
@@ -1032,17 +1073,36 @@ static void core_switch_lb_upsamp_fx(
        no_col = s_min( no_col, temp );
    }

#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( st->hTcxDec->L_frameTCX, imult1616( no_col, st->cldfbSyn->no_channels ) ), Q11 - Q10 ); /* Q11 */
#else
    Scale_sig32( output + imult1616( no_col, st->cldfbSyn->no_channels ), sub( L_FRAME48k, imult1616( no_col, st->cldfbSyn->no_channels ) ), 4 - 10 ); /* Q4 */
#endif

    /* save synthesis - needed in case of core switching */
    IF( st->hTcxDec != NULL )
    {
        Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -4 ); /* Q0 */
#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
        Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 ); /* Q0 */
#else
        Copy_Scale_sig_32_16( output, st->previoussynth_fx, st->hTcxDec->L_frameTCX, -Q4 );                                                            /* Q0 */
#endif
    }

#ifdef FIX_2280_REDUCTION_UNNECESSARY_SCALING
    Scale_sig32( output, imult1616( no_col, st->cldfbSyn->no_channels ), Q11 - Q4 ); /* Q11 */
#endif

    return;
}


/*---------------------------------------------------------------------*
 * smoothTransitionDtxToTcx()
 *
 * apply smoothing to the transition part for inactive to active transitions in DTX
 *---------------------------------------------------------------------*/

#define TRANSITION_SMOOTHING_LEN_16k 15
#define TRANSITION_SMOOTHING_LEN_32k 31
#define TRANSITION_SMOOTHING_LEN_48k 47
Loading