Commit f1ff24fc authored by Manuel Jander's avatar Manuel Jander
Browse files

Correct scale discrepancy of st->synth and Q_new from outer scope of...

Correct scale discrepancy of st->synth and Q_new from outer scope of tcx_encoder_memory_update_ivas_fx(). Also compensate change of scale from inside of stereo_dft_enc_synthesize_fx().
parent cda9ea54
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4319,7 +4319,11 @@ void DoRTFTn_fx_ivas(
Word16 find_guarded_bits_fx( const Word32 n );

Word16 L_norm_arr( const Word32 *arr, Word16 size );
#ifdef NONBE_FIX_ISSUE_2206
Word16 norm_arr( const Word16 *arr, Word16 size );
#else
Word16 norm_arr( Word16 *arr, Word16 size );
#endif
Word16 W_norm_arr( Word64 *arr, Word16 size );

Word16 get_min_scalefactor( Word32 x, Word32 y );
+6 −0
Original line number Diff line number Diff line
@@ -5525,9 +5525,15 @@ Word16 L_norm_arr(
    return q;
}

#ifdef NONBE_FIX_ISSUE_2206
Word16 norm_arr(
    const Word16 *arr,
    Word16 size )
#else
Word16 norm_arr(
    Word16 *arr,
    Word16 size )
#endif
{
    Word16 q = 15;
    Word16 exp = 0;
+1 −1
Original line number Diff line number Diff line
@@ -795,7 +795,7 @@ ivas_error acelp_core_enc_fx(
                move16();
                Scale_sig( st->hBWE_FD->old_syn_12k8_16k_fx, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ), sub( s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn ), st->hBWE_FD->q_mem_deemph_old_syn ) ); // s_min( st->Q_syn, st->hBWE_FD->q_mem_deemph_old_syn )

#ifdef NONBE_FIX_ISSUE_2206_NO
#ifdef NONBE_FIX_ISSUE_2206
                Scale_sig( old_syn_12k8_16k, st->L_frame, sub( st->Q_syn, sub( Q_new, 1 ) ) );
#endif
                save_old_syn_fx( st->L_frame, syn_fx, old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx );
+9 −0
Original line number Diff line number Diff line
@@ -3857,6 +3857,14 @@ void coder_tcx_post_ivas_fx(
    Word16 *wsig,
    Word16 Q_new )
{
#ifdef NONBE_FIX_ISSUE_2206
    /*-----------------------------------------------------------*
     * Memory update                                             *
     *-----------------------------------------------------------*/

    /* Update LPDmem (Txnq,syn,syn_pe,old_exc,wsyn,Ai,Aq) */
    tcx_encoder_memory_update_ivas_fx( wsig, synth, st->L_frame, Ai, A, hTcxCfg->preemph_fac, LPDmem, st, Q_new );
#else
    Word16 xn_buf[L_FRAME_MAX];

    /* TCX output */
@@ -3869,6 +3877,7 @@ void coder_tcx_post_ivas_fx(

    /* Update LPDmem (Txnq,syn,syn_pe,old_exc,wsyn,Ai,Aq) */
    tcx_encoder_memory_update_ivas_fx( wsig, xn_buf, st->L_frame, Ai, A, hTcxCfg->preemph_fac, LPDmem, st, synth, Q_new );
#endif

    return;
}
+40 −0
Original line number Diff line number Diff line
@@ -469,7 +469,11 @@ void core_signal_analysis_high_bitrate_fx(
 *-------------------------------------------------------------------*/

void core_signal_analysis_high_bitrate_ivas_fx(
#ifdef NONBE_FIX_ISSUE_2206
    const Word16 *new_samples, /*i: *Q_new */
#else
    const Word16 *new_samples, /*i: Q0 */
#endif
    const Word16 T_op[3],      /* i  : open-loop pitch values for quantiz. Q0*/
    Word16 lsp_new[],          /* Q15 */
    Word16 lsp_mid[],          /* Q15 */
@@ -523,7 +527,9 @@ void core_signal_analysis_high_bitrate_ivas_fx(
    Word16 tmp, *tmpP16;
    Word16 q_mdstWin = st->q_inp, q_tcx20Win = st->q_inp;
    Word32 *tmpP32;
#ifndef NONBE_FIX_ISSUE_2206
    Word16 Q_exp;
#endif
    Word32 L_tmpbuf[N_MAX + L_MDCT_OVLP_MAX];
    move16();
    move16();
@@ -560,9 +566,28 @@ void core_signal_analysis_high_bitrate_ivas_fx(
    test();
    IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    {
#ifdef NONBE_FIX_ISSUE_2206
        IF ( st->element_mode > EVS_MONO ) {
            Word16 nq;

            nq = add( sub( 15, st->exp_buf_speech_enc ), norm_arr( st->buf_speech_enc, (Word16)( st->new_speech_enc - st->buf_speech_enc ) ) );
            nq = s_min( nq, add( sub( 15, st->exp_buf_speech_enc ), norm_arr( st->new_speech_enc + L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, add( L_frame, (Word16)( st->new_speech_enc - st->buf_speech_enc ) ) ) ) ) );
            nq = s_min( nq, add( sub( *Q_new, 1 ), norm_arr( new_samples, L_frame ) ) );
            scale_sig( st->buf_speech_enc, (Word16)( st->new_speech_enc - st->buf_speech_enc ), sub( nq, sub( 15, st->exp_buf_speech_enc ) ) );
            Copy_Scale_sig_nosat( new_samples, st->new_speech_enc, L_frame, sub( nq, sub( *Q_new, 1 ) ) );
            scale_sig( st->new_speech_enc + L_frame, sub( L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, add( L_frame, (Word16)( st->new_speech_enc - st->buf_speech_enc ) ) ), sub( nq, sub( 15, st->exp_buf_speech_enc ) ) );
            //scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( nq, sub( 15, st->exp_buf_speech_enc ) ) );
            st->exp_buf_speech_enc = sub( Q15, nq );
        } ELSE {
            Copy_Scale_sig_nosat( new_samples, st->new_speech_enc, L_frame, sub( 15, st->exp_buf_speech_enc ) );
            /* st->new_speech_enc copied from new_samples in Q  st->exp_buf_speech_enc
            This is considering new_samples is in q 0 in current code*/
        }
#else
        Copy_Scale_sig( new_samples, st->new_speech_enc, L_frame, sub( 15, st->exp_buf_speech_enc ) );
        /* st->new_speech_enc copied from new_samples in Q  st->exp_buf_speech_enc
        This is considering new_samples is in q 0 in current code*/
#endif
    }

    /*--------------------------------------------------------------*
@@ -598,11 +623,25 @@ void core_signal_analysis_high_bitrate_ivas_fx(
    test();
    IF( st->tcxonly && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
    {
#ifdef NONBE_FIX_ISSUE_2206
        Word16 nexp;

        nexp = s_max( s_max( st->exp_buf_speech_enc, st->exp_buf_speech_enc_pe ), st->exp_mem_preemph_enc );
        scale_sig( st->buf_speech_enc_pe, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( st->exp_buf_speech_enc_pe, nexp ) );
        Copy_Scale_sig_nosat( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame, sub( st->exp_buf_speech_enc, nexp ) );
        st->mem_preemph_enc = shl( st->mem_preemph_enc, sub( st->exp_mem_preemph_enc , nexp ) );
        st->exp_mem_preemph_enc = nexp;
        move16();
        st->exp_buf_speech_enc_pe = nexp;
        move16();
#else
        Copy( st->speech_enc + st->encoderLookahead_enc, st->new_speech_enc_pe, L_frame ); // Assuming both exp_buf_speech_enc_pe and exp_buf_speech_enc are same
#endif

        preemph_fx( st->new_speech_enc_pe, st->preemph_fac, L_frame, &( st->mem_preemph_enc ) ); // using this to keep values alligned in Q-1
    }

#ifndef NONBE_FIX_ISSUE_2206
    /* Rescale Memory */
    Q_exp = sub( *Q_new, st->prev_Q_new );
    move16();
@@ -619,6 +658,7 @@ void core_signal_analysis_high_bitrate_ivas_fx(
#endif
        Scale_sig( &( st->mem_wsp_enc ), 1, Q_exp ); // *Q_new
    }
#endif

    IF( EQ_16( hTcxEnc->tcxMode, TCX_10 ) )
    {
Loading