Commit 5cbb65c4 authored by vaclav's avatar vaclav
Browse files

port CR

parent ad827404
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -363,17 +363,14 @@ ivas_error ivas_core_dec_fx(
        move16();
    }

    save_hb_synth_32_fx = NULL;
    test();
    test();
    test();
    IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) )
    if ( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) )
    {
        save_hb_synth_32_fx = hSCE->save_hb_synth_fx;
    }
    ELSE
    {
        save_hb_synth_32_fx = NULL;
    }

    /*------------------------------------------------------------------*
     * Decode SID for MDCT-Stereo DTX mode
+14 −15
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ ivas_error ivas_cpe_dec_fx(
    Word16 q_res_buf;
    Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */
    CPE_DEC_HANDLE hCPE;
    STEREO_DFT_CONFIG_DATA_HANDLE hConfigDft;
    Decoder_State **sts;
    Word32 ivas_total_brate;
    ivas_error error;
@@ -159,6 +160,12 @@ ivas_error ivas_cpe_dec_fx(
        }
    }

    hConfigDft = NULL;
    if ( hCPE->hStereoDft != NULL )
    {
        hConfigDft = hCPE->hStereoDft->hConfig;
    }

    /*------------------------------------------------------------------*
     * Initialization
     *-----------------------------------------------------------------*/
@@ -222,25 +229,16 @@ ivas_error ivas_cpe_dec_fx(
    test();
    IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) )
    {
        STEREO_DFT_CONFIG_DATA_HANDLE hConfig;
        IF( hCPE->hStereoDft == NULL )
        {
            hConfig = NULL;
        }
        ELSE
        {
            hConfig = hCPE->hStereoDft->hConfig;
        }
        test();
        IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
        {
            IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
            {
                stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
            ELSE
            {
                stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
        }
        ELSE
@@ -248,11 +246,11 @@ ivas_error ivas_cpe_dec_fx(
            /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */
            IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
            {
                stereo_dft_config_fx( hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
            ELSE
            {
                stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
        }
    }
@@ -598,7 +596,7 @@ ivas_error ivas_cpe_dec_fx(

    test();
    test();
    IF( NE_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 ) ) )
    IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
    {
        IF( NE_32( ( error = ivas_core_dec_fx( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) )
        {
@@ -616,9 +614,10 @@ 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 ) ) )
    IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
    {
        Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft
        set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX );
+1 −1
Original line number Diff line number Diff line
@@ -286,7 +286,7 @@ ivas_error ivas_core_enc_fx(
    test();
    IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 )
    {
        ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits );
        ivas_combined_format_brate_sanity_fx( element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits );
    }

    /*---------------------------------------------------------------------*
+47 −32
Original line number Diff line number Diff line
@@ -51,13 +51,16 @@
/*--------------------------------------------------------------------------*
 * Local function prototypes
 *--------------------------------------------------------------------------*/

static void stereo_mode_combined_format_enc_fx( const Encoder_Struct *st_ivas, CPE_ENC_HANDLE hCPE );


/*-------------------------------------------------------------------*
 * ivas_cpe_enc()
 *
 * Channel Pair Element (CPE) encoding routine
 *-------------------------------------------------------------------*/

ivas_error ivas_cpe_enc_fx(
    Encoder_Struct *st_ivas,       /* i/o: IVAS encoder structure						*/
    const Word16 cpe_id,           /* i  : CPE # identifier								Q0*/
@@ -69,13 +72,13 @@ ivas_error ivas_cpe_enc_fx(
    Word16 Q_new_out[] )
{
    CPE_ENC_HANDLE hCPE;
    STEREO_DFT_CONFIG_DATA_HANDLE hConfigDft;
    Encoder_State **sts;
    Word16 n, n_CoreChannels;
    Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8];   /* buffer of input signal @ 12k8        Q15 */
    Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8    Q_new-1 */
    Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP];         /* buffer of input signal @ 16kHz       Q15 */
    Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP];       /* buffer of input signal @ 16kHz   Q_new-1 */
    Word16 Q_new[CPE_CHANNELS] = { 0 };
    Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT];        /* FFT buffer                               */
    Word16 fft_buff_fx_q[CPE_CHANNELS];                 /* FFT buffer                               */
    set16_fx( fft_buff_fx_q, 0, CPE_CHANNELS );
@@ -104,7 +107,6 @@ ivas_error ivas_cpe_enc_fx(
    Word32 currFlatness_fx[CPE_CHANNELS];                      /* flatness parameter                       Q21 */
    Word16 tdm_ratio_idx, tdm_ratio_idx_SM;                    /* temp. TD stereo parameters               */
    Word16 tdm_SM_or_LRTD_Pri;                                 /* temp. TD stereo parameters               */

    Word16 nb_bits;                                            /* number of DFT stereo side bits           */
    Word32 fr_bands_fx[CPE_CHANNELS][2 * NB_BANDS];            /* energy in frequency bands  (Q_buffer + QSCALE) */
    Word16 Etot_LR_fx[CPE_CHANNELS];                           /* total energy                             Q8 */
@@ -127,8 +129,9 @@ ivas_error ivas_cpe_enc_fx(
    Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */
    Word16 old_wsp_fx[CPE_CHANNELS][L_WSP];
    Word16 e_old_wsp[CPE_CHANNELS], q_old_wsp;
    move16(); // Q_new
    move16(); // Q_new
    Word16 Q_new[CPE_CHANNELS] = { 0 };
    move16();
    move16();
    Word16 q_com, shift, q_min, gb;

    error = IVAS_ERR_OK;
@@ -185,6 +188,7 @@ ivas_error ivas_cpe_enc_fx(
        set16_zero_fx( old_inp_12k8_16fx[i], L_INP_12k8 );
        set_zero_fx( old_inp_12k8_fx[i], L_INP_12k8 );
    }

    /*------------------------------------------------------------------*
     * CPE initialization - core coder
     *-----------------------------------------------------------------*/
@@ -263,6 +267,7 @@ ivas_error ivas_cpe_enc_fx(
     * Stereo technology selection
     * Front-VAD on input L and R channels
     *----------------------------------------------------------------*/

    test();
    IF( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL )
    {
@@ -367,11 +372,17 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * dynamically allocate data structures depending on the actual stereo mode
     *----------------------------------------------------------------*/

    IF( ( error = stereo_memory_enc_fx( hCPE, input_Fs, max_bwidth, ivas_format, st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    hConfigDft = NULL;
    IF( hCPE->hStereoDft != NULL )
    {
        hConfigDft = hCPE->hStereoDft->hConfig;
    }

    /*----------------------------------------------------------------*
     * Set TD stereo parameters
@@ -386,6 +397,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Resets/updates in case of stereo switching
     *----------------------------------------------------------------*/

    test();
    IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) )
    {
@@ -416,6 +428,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Temporal inter-channel alignment, stereo adjustment
     *----------------------------------------------------------------*/

    shift = s_min( L_norm_arr( sts[0]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), L_norm_arr( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) );
    q_min = add( sts[0]->q_inp32, sub( shift, find_guarded_bits_fx( input_frame ) ) );
    scale_sig32( sts[1]->input_buff32_fx, L_FRAME48k + L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), sub( q_min, sts[1]->q_inp32 ) ); /* q_min */
@@ -438,6 +451,7 @@ ivas_error ivas_cpe_enc_fx(
    move16();
    move16();
    move16();

    /*----------------------------------------------------------------*
     * Input signal buffering - needed in IC-BWE and TD ITD in MDCT stereo
     *----------------------------------------------------------------*/
@@ -513,32 +527,23 @@ ivas_error ivas_cpe_enc_fx(
    IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 ||
                                                        ( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) || LE_32( sts[0]->last_core_brate, SID_2k40 ) ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */
    {
        STEREO_DFT_CONFIG_DATA_HANDLE hConfig;
        IF( hCPE->hStereoDft == NULL )
        {
            hConfig = NULL;
        }
        ELSE
        {
            hConfig = hCPE->hStereoDft->hConfig;
        }
        IF( st_ivas->hQMetaData != NULL )
        {
            test();
            /* No Basop - st_ivas->ism_mode != ISM_MODE_NONE as comparison with 0 */
            IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && st_ivas->ism_mode != ISM_MODE_NONE )
            {
                stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.70f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.70f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
            ELSE
            {
                stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                stereo_dft_config_fx( hConfigDft, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            }
        }
        ELSE
        {
            /* note; "bits_frame_nominal" needed in TD stereo as well */
            stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
            stereo_dft_config_fx( hConfigDft, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
        }
    }

@@ -631,6 +636,7 @@ ivas_error ivas_cpe_enc_fx(
     * Stereo processing
     * Stereo down-mix
     *----------------------------------------------------------------*/

    IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
    {
        test();
@@ -677,17 +683,18 @@ ivas_error ivas_cpe_enc_fx(
            hCPE->q_input_mem[n] = q_com;
            move16();
        }
        stereo_dft_hybrid_ITD_flag_fx( hCPE->hStereoDft->hConfig, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max );

        stereo_dft_hybrid_ITD_flag_fx( hConfigDft, input_Fs, hCPE->hStereoDft->hItd->hybrid_itd_max );

        /* Time Domain ITD compensation using extrapolation */
        stereo_td_itd_fx( hCPE->hStereoDft->hItd, hCPE->hStereoDft->input_mem_itd_fx, hCPE->hStereoDft->q_input_mem_itd, hCPE->hStereoDft->hConfig->hybrid_itd_flag, hCPE->hStereoDft->dft_ovl, sts, input_frame, hCPE->input_mem_fx, hCPE->q_input_mem );
        stereo_td_itd_fx( hCPE->hStereoDft->hItd, hCPE->hStereoDft->input_mem_itd_fx, hCPE->hStereoDft->q_input_mem_itd, hConfigDft->hybrid_itd_flag, hCPE->hStereoDft->dft_ovl, sts, input_frame, hCPE->input_mem_fx, hCPE->q_input_mem );

        stereo_dft_enc_analyze_fx( sts, CPE_CHANNELS, input_frame, hCPE->hStereoDft, NULL, hCPE->hStereoDft->DFT_fx, hCPE->hStereoDft->DFT_fx_e, hCPE->input_mem_fx, hCPE->q_input_mem );

        sts[0]->total_brate = L_mult0( add( sts[0]->bits_frame_nominal, 10 ), FRAMES_PER_SEC ); /* add small overhead; st[0]->total_brate used in coder_type_modif()	Q0*/
        /* Update DFT Stereo memories */

        stereo_dft_enc_update_fx( hCPE->hStereoDft, sts[0]->max_bwidth );
        stereo_dft_enc_update_fx( hCPE->hStereoDft, max_bwidth );

        /* DFT stereo processing */
        stereo_dft_enc_process_fx( hCPE, vad_flag_dtx, vad_hover_flag, input_frame );
@@ -796,6 +803,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * DFT stereo: iDFT and resampling on both channels
     *----------------------------------------------------------------*/

    IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
    {
        Word32 internal_Fs;
@@ -889,6 +897,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Front Pre-processing
     *----------------------------------------------------------------*/

    FOR( n = 0; n < n_CoreChannels; n++ )
    {
        set16_fx( old_wsp_fx[n], 0, L_WSP );
@@ -949,6 +958,7 @@ ivas_error ivas_cpe_enc_fx(
    /*----------------------------------------------------------------*
     * Stereo DTX updates
     *----------------------------------------------------------------*/

    test();
    test();
    IF( EQ_16( ivas_format, MASA_FORMAT ) && nb_bits_metadata > 0 && hCPE->hCoreCoder[0]->Opt_DTX_ON )
@@ -988,7 +998,7 @@ ivas_error ivas_cpe_enc_fx(
        test();
        test();
        test();
        IF( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) )
        IF( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != max_bwidth ) )
        {
            initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, sts[0]->bwidth, 0, NULL, 0 );

@@ -1023,13 +1033,13 @@ ivas_error ivas_cpe_enc_fx(
            Word16 bw;

            /* float uses ternary operator for this: bw = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? sts[n]->bwidth : sts[n]->max_bwidth; */
            bw = sts[n]->max_bwidth;
            bw = max_bwidth;
            IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) )
            {
                bw = sts[n]->bwidth;
            }
            igf = getIgfPresent_fx( sts[n]->element_mode, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), bw, sts[n]->rf_mode ); /* Q0 */
            IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), sts[n]->max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK )
            IF( ( error = IGF_Reconfig_fx( &sts[n]->hIGFEnc, igf, 0, L_mult0( sts[n]->bits_frame_nominal, FRAMES_PER_SEC ), max_bwidth, sts[n]->element_mode, sts[n]->rf_mode ) ) != IVAS_ERR_OK )
            {
                return error;
            }
@@ -1117,11 +1127,11 @@ ivas_error ivas_cpe_enc_fx(
                /* Reconfigure DFT Stereo for inactive frames */
                IF( EQ_32( sts[0]->core_brate, SID_2k40 ) )
                {
                    stereo_dft_config_fx( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                    stereo_dft_config_fx( hConfigDft, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                }
                ELSE
                {
                    stereo_dft_config_fx( hCPE->hStereoDft->hConfig, FRAME_NO_DATA, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                    stereo_dft_config_fx( hConfigDft, FRAME_NO_DATA, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
                }

                stereo_dft_cng_side_gain_fx( hCPE->hStereoDft, hCPE->hStereoCng, sts[0]->core_brate, sts[0]->last_core_brate, sts[0]->bwidth );
@@ -1306,11 +1316,13 @@ ivas_error ivas_cpe_enc_fx(
    return error;
}


/*-------------------------------------------------------------------------
 * create_cpe_enc()
 *
 * Create, allocate and initialize IVAS encoder CPE handle
 *-------------------------------------------------------------------------*/

ivas_error create_cpe_enc_fx(
    Encoder_Struct *st_ivas,   /* i/o: IVAS encoder structure      */
    const Word16 cpe_id,       /* i  : CPE # identifier            Q0*/
@@ -1612,6 +1624,8 @@ ivas_error create_cpe_enc_fx(

    return error;
}


/*-------------------------------------------------------------------------
 * destroy_cpe_enc()
 *
@@ -1767,5 +1781,6 @@ static void stereo_mode_combined_format_enc_fx(
            }
        }
    }

    return;
}