Commit 2024077c authored by vaclav's avatar vaclav
Browse files

port CR

parent ad827404
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -668,6 +668,9 @@ enum
#define ACELP_TCX_TRANS_NS                  1250000                             /* Duration of the ACELP->TCX overlap - 1.25 ms */
#define L_FRAME_MAX                         L_FRAME48k                          /* Max 20ms frame size @48kHz              */
#define L_FRAME_PLUS                        1200                                /* Max frame size (long TCX frame)            */
#ifdef FIX_1320_STACK_CPE_DECODER
#define L_FRAME_PLUS_INTERNAL               800                                 /* Max frame size (long TCX frame) at maximum internal sampling rate */
#endif
#define L_MDCT_OVLP_MAX                     NS2SA( 48000, ACELP_LOOK_NS )       /* = Max mdct overlap */
#define N_TCX10_MAX                         480                                 /* Max size of TCX10 MDCT spectrum */
#define BITS_TEC                            1                                   /* number of bits for TEC */
+1 −0
Original line number Diff line number Diff line
@@ -168,6 +168,7 @@
#define NONBE_1293_SR_HRTF                              /* VA: issue 1293: add support of external HRTFs in split rendering */
#define NONBE_1220_OMASA_JBM_BRATE_SW_FLUSH             /* VA: issue 1220: fix bug in renderer flush in OMASA 1ISM JBM bitrate switching */
#define FIX_1139_REV_COLORATION_SHORT_T60               /* Nokia,FhG: Fix issue 1139, prevent sound coloration artefacts at very low reverberation times */
#define FIX_1320_STACK_CPE_DECODER                      /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */

/* #################### End BASOP porting switches ############################ */

+8 −0
Original line number Diff line number Diff line
@@ -36,7 +36,11 @@ void decoder_LPD_fx(
)
{
    Word16 *param_lpc;
#ifdef FIX_1320_STACK_CPE_DECODER
    Word16 synth_buf[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M];
#else
    Word16 synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
#endif
    Word16 *synth;
    Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M];
    Word16 *synthFB;
@@ -114,7 +118,11 @@ void decoder_LPD_fx(
    synth = synth_buf + hTcxDec->old_synth_len;
    /*st->old_synth: Q_0*/
    Copy( hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len );
#ifdef FIX_1320_STACK_CPE_DECODER
    set16_fx( synth, 0, L_FRAME_PLUS_INTERNAL + M );
#else
    set16_fx( synth, 0, L_FRAME_PLUS + M );
#endif

    synthFB = synth_bufFB + hTcxDec->old_synth_lenFB;
    Copy( hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB );
+33 −0
Original line number Diff line number Diff line
@@ -76,7 +76,12 @@ ivas_error ivas_core_dec_fx(
    set16_fx( tmp_buffer_fx, 0, L_FRAME48k );

    Word16 tmps, incr;
#ifdef FIX_1320_STACK_CPE_DECODER
    Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL };
    Word16 flag_bwe_bws;
#else
    Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET];
#endif

    Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q15
    Word16 core_switching_flag[CPE_CHANNELS];
@@ -298,6 +303,9 @@ ivas_error ivas_core_dec_fx(
        set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k );
        set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k );
        set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k );
#ifdef FIX_1320_STACK_CPE_DECODER
        bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */
#endif

        /*------------------------------------------------------------------*
         * Decision matrix (selection of technologies)
@@ -1044,9 +1052,18 @@ ivas_error ivas_core_dec_fx(
         * SWB(FB) BWE decoding
         *---------------------------------------------------------------------*/

#ifdef FIX_1320_STACK_CPE_DECODER
        test();
        test();
        test();
        flag_bwe_bws = ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && st->bfi == 0 );
        move16();
#endif

        Q_white_exc = 0;
        move16();

#ifndef FIX_1320_STACK_CPE_DECODER
        test();
        test();
        test();
@@ -1054,6 +1071,7 @@ ivas_error ivas_core_dec_fx(
        test();
        test();
        test();
#endif
        test();
        test();
        test();
@@ -1085,7 +1103,11 @@ ivas_error ivas_core_dec_fx(
                fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame );
            }
        }
#ifdef FIX_1320_STACK_CPE_DECODER
        ELSE IF( st->extl == SWB_BWE || st->extl == FB_BWE || flag_bwe_bws )
#else
        ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) )
#endif
        {
            /* SWB BWE decoder */
            Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame );
@@ -1095,6 +1117,17 @@ ivas_error ivas_core_dec_fx(
            Copy_Scale_sig_32_16( hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp
        }

#ifdef FIX_1320_STACK_CPE_DECODER
        test();
        test();
        test();
        IF( ( st->core == ACELP_CORE && ( st->extl == -1 || st->extl == SWB_CNG ) ) && flag_bwe_bws == 0 )
        {
            set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k );
        }

#endif

        /*---------------------------------------------------------------------*
         * FEC - recovery after lost HQ core (smoothing of the BWE component)
         *---------------------------------------------------------------------*/
+217 −2
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ static void read_stereo_mode_and_bwidth_fx( CPE_DEC_HANDLE hCPE, const Decoder_S

static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE );

#ifdef FIX_1320_STACK_CPE_DECODER
static ivas_error stereo_dft_dec_main( CPE_DEC_HANDLE hCPE, const Word32 ivas_total_brate, const Word16 n_channels, Word32 *p_res_buf_fx, Word32 *output[], Word32 outputHB[][L_FRAME48k], const Word16 output_frame, const Word32 output_Fs );
#endif


/*--------------------------------------------------------------------------*
 * ivas_cpe_dec_fx()
@@ -71,8 +75,12 @@ ivas_error ivas_cpe_dec_fx(
    Word16 last_bwidth;
    Word16 tdm_ratio_idx;
    Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */
#ifdef FIX_1320_STACK_CPE_DECODER
    Word32 *res_buf_fx = NULL; /* Q8 */
#else
    Word16 q_res_buf;
    Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */
#endif
    CPE_DEC_HANDLE hCPE;
    Decoder_State **sts;
    Word32 ivas_total_brate;
@@ -83,8 +91,10 @@ ivas_error ivas_cpe_dec_fx(

    error = IVAS_ERR_OK;
    move32();
#ifndef FIX_1320_STACK_CPE_DECODER
    q_res_buf = Q8;
    move16();
#endif

    push_wmops( "ivas_cpe_dec" );

@@ -347,6 +357,10 @@ ivas_error ivas_cpe_dec_fx(
            }
            ELSE
            {
#ifdef FIX_1320_STACK_CPE_DECODER
                res_buf_fx = outputHB_fx[0]; /* note: temporarily reused buffer */

#endif
                test();
                IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
                {
@@ -616,10 +630,17 @@ ivas_error ivas_cpe_dec_fx(
    /*----------------------------------------------------------------*
     * Stereo decoder & upmixing
     *----------------------------------------------------------------*/

    test();
    test();
    IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
    {
#ifdef FIX_1320_STACK_CPE_DECODER
        IF( NE_32( ( error = stereo_dft_dec_main( hCPE, ivas_total_brate, n_channels, res_buf_fx, output, outputHB_fx, output_frame, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
        {
            return error;
        }
#else
        Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft
        set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX );
        set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX );
@@ -784,6 +805,7 @@ ivas_error ivas_cpe_dec_fx(
            hCPE->q_output_mem_fx[n] = Q11;
            move16();
        }
#endif
    }
    ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
    {
@@ -823,7 +845,6 @@ ivas_error ivas_cpe_dec_fx(
     * Update parameters for stereo CNA
     *----------------------------------------------------------------*/

    // stereo_cna_update_params( hCPE, output_flt, output_frame, tdm_ratio_idx );
    stereo_cna_update_params_fx( hCPE, output, output_frame, tdm_ratio_idx );

    /*----------------------------------------------------------------*
@@ -857,7 +878,6 @@ ivas_error ivas_cpe_dec_fx(

    stereo_tca_dec_fx( hCPE, output, output_frame );


    /*----------------------------------------------------------------*
     * Common Stereo updates
     *----------------------------------------------------------------*/
@@ -889,6 +909,201 @@ ivas_error ivas_cpe_dec_fx(
    return error;
}

#ifdef FIX_1320_STACK_CPE_DECODER

/*-------------------------------------------------------------------------
 * stereo_dft_dec_main()
 *
 * DFT decoder main function
 *-------------------------------------------------------------------------*/

static ivas_error stereo_dft_dec_main(
    CPE_DEC_HANDLE hCPE,              /* i/o: CPE decoder structure               */
    const Word32 ivas_total_brate,    /* i  : IVAS total bitrate                  */
    const Word16 n_channels,          /* i  : number of channels to be decoded    */
    Word32 *p_res_buf_fx,             /* i  : DFT stereo residual S signal        */
    Word32 *output[],                 /* o  : output synthesis signal             */
    Word32 outputHB_fx[][L_FRAME48k], /* o  : output HB synthesis signal          */
    const Word16 output_frame,        /* i  : output frame length per channel     */
    const Word32 output_Fs            /* i  : output sampling rate                */
)
{
    Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX];
    Word16 n;
    Word16 q_res_buf, q_dft;
    Decoder_State *st0;
    ivas_error error;
    Word16 shift;
    Word32 tmp1, tmp2;
    Word16 shift1, shift2;

    st0 = hCPE->hCoreCoder[0];

    q_res_buf = Q8;
    move16();

    /* copy from temporary buffer */
    test();
    IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi )
    {
        Copy32( p_res_buf_fx, DFT_fx[1], STEREO_DFT_N_8k );
    }

    /* core decoder */
    IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, NULL, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) )
    {
        return error;
    }

    /* Scaling of DFT's */
    maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 );
    maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 );

    IF( tmp1 == 0 )
    {
        shift1 = Q31;
        move16();
    }
    ELSE
    {
        shift1 = norm_l( tmp1 );
    }
    IF( tmp2 == 0 )
    {
        shift2 = Q31;
        move16();
    }
    ELSE
    {
        shift2 = norm_l( tmp2 );
    }
    shift = s_min( shift1, shift2 );

    IF( NE_16( shift, 31 ) )
    {
        shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q16 ); /* Q16 for guard bits */

        IF( GT_16( shift, hCPE->hStereoDft->q_dft ) )
        {
            Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
            Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
            hCPE->hStereoDft->q_dft = shift;
            move16();
        }
    }
    ELSE
    {
        hCPE->hStereoDft->q_dft = Q8;
        move16();
    }

    /* DFT Stereo residual decoding */
    test();
    IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi )
    {
        Word16 q;
        Word16 q_out_DFT[2];

        q = Q11;
        move16();

        Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6

        stereo_dft_dec_res_fx( hCPE, p_res_buf_fx, q_res_buf, output[1] );

        Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16

        Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11

        q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft;
        move16();
        move16();

        stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT );

        Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft
    }

    /* DFT stereo CNG */
    q_dft = hCPE->hStereoDft->q_dft;
    move16();
    stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft );

    /* decoding */
    IF( EQ_16( hCPE->nchan_out, 1 ) )
    {
        IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
        {
            hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
            move16();
            FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
            {
                hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
                move16();
            }
            hCPE->hStereoDft->first_frame = 0;
            move16();
        }

        scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
        hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
        move16();
        stereo_dft_unify_dmx_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata );
        scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
        hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
        move16();
    }
    ELSE
    {
        IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
        {
            hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
            move16();
            FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
            {
                hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
                move16();
            }
            hCPE->hStereoDft->first_frame = 0;
            move16();
        }

        scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
        hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
        move16();

        stereo_dft_dec_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
        scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
        hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
        move16();
    }

    FOR( n = 0; n < hCPE->nchan_out; n++ )
    {
        Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) );                                                 // q_dft
        scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
        hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft;
        move16();
    }

    /* synthesis iFFT */
    FOR( n = 0; n < hCPE->nchan_out; n++ )
    {
        stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame );
    }

    FOR( n = 0; n < hCPE->nchan_out; n++ )
    {
        Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) );                                                 // Q11
        scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
        hCPE->q_output_mem_fx[n] = Q11;
        move16();
    }

    return IVAS_ERR_OK;
}

#endif

/*-------------------------------------------------------------------------
 * create_cpe_dec_fx()
Loading