Commit 93ca80c1 authored by multrus's avatar multrus
Browse files

[cleanup] accept COVARIANCE_MEMORY_OPT

parent e2e7dafb
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -224,12 +224,7 @@ int16_t ivas_sba_get_nchan_metadata(
    {
        if ( ivas_total_brate >= IVAS_512k )
        {
#ifndef COVARIANCE_MEMORY_OPT
            nb_channels = ( SBA_HOA2_ORDER + 1 ) * ( SBA_HOA2_ORDER + 1 );
            nb_channels += 2;
#else
            nb_channels = IVAS_SPAR_MAX_CH;
#endif
            nb_channels = min( nb_channels, ( sba_order + 1 ) * ( sba_order + 1 ) );
        }
        else
+0 −1
Original line number Diff line number Diff line
@@ -151,7 +151,6 @@
/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */


#define COVARIANCE_MEMORY_OPT                           /* Dlb : Issue 231: define SPAR covariance buffers in stack instead of inter-frame heap */
#define NONBE_FIX_589_JBM_TC_OFFSETS                    /* FhG: issue 589: wrong offset into the TC buffers is used in some rendering paths in the JBM main rendering function */
#define FIX_MEM_REALLOC_IND_LIST                        /* VA: issue 601: failure of the automatic memory re-allocation mechanism when ind_list[] buffer is depleted in MASA mode with 2 TC*/
#define FIX_1720_HRTF_FASTCONV                          /* Dlb : Binaural and Binaural room format RAM saving in SBA mode */
+0 −163
Original line number Diff line number Diff line
@@ -373,7 +373,6 @@ ivas_error ivas_spar_enc(
}


#ifdef COVARIANCE_MEMORY_OPT
/*-------------------------------------------------------------------*
 * ivas_spar_cov_md_process()
 *
@@ -564,7 +563,6 @@ static ivas_error ivas_spar_cov_md_process(

    return error;
}
#endif


/*-----------------------------------------------------------------------------------------*
@@ -587,20 +585,11 @@ static ivas_error ivas_spar_enc_process(
{
    float pcm_tmp[DIRAC_MAX_ANA_CHANS][L_FRAME48k * 2];
    float *p_pcm_tmp[DIRAC_MAX_ANA_CHANS];
#ifdef COVARIANCE_MEMORY_OPT
    int16_t i, j, input_frame, dtx_vad;
#else
    int16_t i, j, b, i_ts, input_frame, dtx_vad;
#endif
    int16_t transient_det[2];
    int16_t hodirac_flag;
    int32_t ivas_total_brate, input_Fs;
    int16_t nchan_inp, sba_order, nchan_transport;
#ifndef COVARIANCE_MEMORY_OPT
    float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH];
    int16_t table_idx;
#endif
    int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH];
    ivas_error error;
    const int16_t *order;
@@ -631,10 +620,6 @@ static ivas_error ivas_spar_enc_process(
    sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER );
    nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate );
    assert( nchan_inp <= hEncoderConfig->nchan_inp );
#ifndef COVARIANCE_MEMORY_OPT
    int16_t active_w_vlbr;
    active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0;
#endif

    nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in;
    nchan_transport = st_ivas->nchan_transport;
@@ -743,7 +728,6 @@ static ivas_error ivas_spar_enc_process(
    }
#endif

#ifdef COVARIANCE_MEMORY_OPT
    /*-----------------------------------------------------------------------------------------*
     * Covariance and MD processing
     *-----------------------------------------------------------------------------------------*/
@@ -758,153 +742,6 @@ static ivas_error ivas_spar_enc_process(
    {
        return error;
    }
#else
    /*-----------------------------------------------------------------------------------------*
     * Set SPAR bitrates
     *-----------------------------------------------------------------------------------------*/

    table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL );

    if ( hSpar->hMdEnc->table_idx != table_idx )
    {
        hSpar->hMdEnc->table_idx = table_idx;
        if ( ( ivas_total_brate != hEncoderConfig->last_ivas_total_brate ) && ( !hSpar->spar_reconfig_flag ) )
        {
            if ( ( error = ivas_spar_md_enc_init( hSpar->hMdEnc, hEncoderConfig, sba_order ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else
        {
            ivas_spar_set_bitrate_config( &hSpar->hMdEnc->spar_md_cfg, table_idx, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, hSpar->AGC_Enable );
        }
    }

    /*-----------------------------------------------------------------------------------------*
     * Covariance process
     *-----------------------------------------------------------------------------------------*/

    for ( i = 0; i < nchan_inp; i++ )
    {
        for ( j = 0; j < nchan_inp; j++ )
        {
            cov_real[i][j] = hSpar->hMdEnc->cov_real[i][j];
            cov_dtx_real[i][j] = hSpar->hMdEnc->cov_dtx_real[i][j];
        }
    }

    ivas_enc_cov_handler_process( hSpar->hCovEnc, ppIn_FR_real, ppIn_FR_imag, cov_real, cov_dtx_real, hSpar->hFbMixer->pFb, 0, hSpar->hFbMixer->pFb->filterbank_num_bands, nchan_inp, dtx_vad, transient_det, hSpar->hMdEnc->HOA_md_ind
#ifdef FIX_SBA_VANISHING_RESIDUAL
                                  ,
                                  &hSpar->hMdEnc->spar_md.res_ind,
                                  remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order],
                                  &dyn_active_w_flag, st_ivas->nchan_transport, 1

#endif
    );

    nchan_transport = st_ivas->nchan_transport;
#ifdef FIX_SBA_VANISHING_RESIDUAL
    if ( nchan_transport > 1 && nchan_transport <= ( FOA_CHANNELS - 1 ) )
    {
        push_next_indice( hMetaData, dyn_active_w_flag, 1 );
        if ( ( dyn_active_w_flag == 1 ) && ( nchan_transport == 2 ) )
        {
            push_next_indice( hMetaData, hSpar->hMdEnc->spar_md.res_ind - nchan_transport, 1 );
        }
        st_ivas->hSpar->front_vad_flag = ( dyn_active_w_flag == 1 ) ? 1 : st_ivas->hSpar->front_vad_flag;
    }
    else
    {
        if ( nchan_transport == FOA_CHANNELS )
        {
            push_next_indice( hMetaData, 0, 1 );
        }
    }
#endif

    /*-----------------------------------------------------------------------------------------*
     * MetaData encoder
     *-----------------------------------------------------------------------------------------*/

    if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 )
    {
        ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer
#ifdef FIX_SBA_VANISHING_RESIDUAL
                                  ,
                                  dyn_active_w_flag
#endif
#ifdef FIX_527_SBA_MONO_INPUT
                                  ,
                                  hQMetaData->dirac_mono_flag
#endif
        );
    }

    if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag )
    {
        float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
        float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
        float diffuseness[IVAS_MAX_NUM_BANDS];
        float Wscale_d[IVAS_MAX_NUM_BANDS];
        int16_t d_start_band, d_end_band;
        int16_t dirac_band_idx;

        d_start_band = hSpar->enc_param_start_band;
        d_end_band = IVAS_MAX_NUM_BANDS;

        for ( b = d_start_band; b < d_end_band; b++ )
        {
            dirac_band_idx = hSpar->dirac_to_spar_md_bands[b] - d_start_band;
            for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ )
            {
                azi_dirac[b][i_ts] = hQMetaData->q_direction[0].band_data[dirac_band_idx].azimuth[i_ts];
                ele_dirac[b][i_ts] = hQMetaData->q_direction[0].band_data[dirac_band_idx].elevation[i_ts];
            }
            diffuseness[b] = 1.0f - hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0];
        }

        if ( d_start_band >= 6 && dtx_vad == 1 )
        {
            mvr2r( hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_quant_re, hSpar->hMdEnc->spar_md.band_coeffs[d_start_band - 1].P_re, IVAS_SPAR_MAX_CH - 1 );
        }

        for ( b = d_start_band; b < d_end_band; b++ )
        {
            Wscale_d[b] = 1.0f;
            for ( i = 1; i < nchan_inp; i++ )
            {
                Wscale_d[b] += cov_real[i][i][b] / max( EPSILON, cov_real[0][0][b] );
            }
            Wscale_d[b] = Wscale_d[b] / ( 1.0f + (float) sba_order ); /*DirAC normalized signal variance sums to 1 + order*/
            Wscale_d[b] = sqrtf( Wscale_d[b] );
            Wscale_d[b] = min( 2.0f, max( Wscale_d[b], 1.0f ) );
        }

        ivas_get_spar_md_from_dirac( azi_dirac, ele_dirac, diffuseness, 1, hSpar->hMdEnc->mixer_mat, &hSpar->hMdEnc->spar_md, &hSpar->hMdEnc->spar_md_cfg, d_start_band, d_end_band, ( hSpar->hMdEnc->spar_hoa_md_flag ) ? 1 : sba_order, dtx_vad, Wscale_d,
                                     hQMetaData->useLowerRes, active_w_vlbr
#ifdef FIX_SBA_VANISHING_RESIDUAL
                                     ,
                                     dyn_active_w_flag
#endif
        );
    }

    if ( hSpar->hMdEnc->spar_hoa_md_flag )
    {
        ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer
#ifdef FIX_SBA_VANISHING_RESIDUAL
                                  ,
                                  dyn_active_w_flag
#endif
#ifdef FIX_527_SBA_MONO_INPUT
                                  ,
                                  hQMetaData->dirac_mono_flag
#endif
        );
    }
#endif

#ifdef DEBUG_LBR_SBA
    /* Dumping SPAR Coefficients */
+0 −79
Original line number Diff line number Diff line
@@ -142,45 +142,6 @@ ivas_error ivas_spar_md_enc_open(
        }
    }

#ifndef COVARIANCE_MEMORY_OPT
    if ( ( hMdEnc->cov_real = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" );
    }
    for ( i = 0; i < num_channels; i++ )
    {
        if ( ( hMdEnc->cov_real[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" );
        }
        for ( j = 0; j < num_channels; j++ )
        {
            if ( ( hMdEnc->cov_real[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov real matrix" );
            }
        }
    }

    if ( ( hMdEnc->cov_dtx_real = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" );
    }
    for ( i = 0; i < num_channels; i++ )
    {
        if ( ( hMdEnc->cov_dtx_real[i] = (float **) malloc( num_channels * sizeof( float * ) ) ) == NULL )
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" );
        }
        for ( j = 0; j < num_channels; j++ )
        {
            if ( ( hMdEnc->cov_dtx_real[i][j] = (float *) malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR cov dtx real matrix" );
            }
        }
    }
#endif
    if ( ( hMdEnc->mixer_mat_local = (float ***) malloc( num_channels * sizeof( float ** ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" );
@@ -250,33 +211,6 @@ void ivas_spar_md_enc_close(
        free( hMdEnc->mixer_mat );
    }

#ifndef COVARIANCE_MEMORY_OPT
    if ( hMdEnc->cov_real != NULL )
    {
        for ( i = 0; i < num_channels; i++ )
        {
            for ( j = 0; j < num_channels; j++ )
            {
                free( hMdEnc->cov_real[i][j] );
            }
            free( hMdEnc->cov_real[i] );
        }
        free( hMdEnc->cov_real );
    }

    if ( hMdEnc->cov_dtx_real != NULL )
    {
        for ( i = 0; i < num_channels; i++ )
        {
            for ( j = 0; j < num_channels; j++ )
            {
                free( hMdEnc->cov_dtx_real[i][j] );
            }
            free( hMdEnc->cov_dtx_real[i] );
        }
        free( hMdEnc->cov_dtx_real );
    }
#endif
    if ( hMdEnc->mixer_mat_local != NULL )
    {
        for ( i = 0; i < num_channels; i++ )
@@ -372,19 +306,6 @@ ivas_error ivas_spar_md_enc_init(
        }
    }

#ifndef COVARIANCE_MEMORY_OPT
    for ( i = 0; i < num_channels; i++ )
    {
        for ( j = 0; j < num_channels; j++ )
        {
            for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
            {
                hMdEnc->cov_real[i][j][k] = 0;
                hMdEnc->cov_dtx_real[i][j][k] = 0;
            }
        }
    }
#endif
    ivas_clear_band_coeffs( hMdEnc->spar_md.band_coeffs, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdEnc->spar_md.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
    ivas_clear_band_coeff_idx( hMdEnc->spar_md_prior.band_coeffs_idx, IVAS_MAX_NUM_BANDS );
+0 −4
Original line number Diff line number Diff line
@@ -667,10 +667,6 @@ typedef struct ivas_spar_md_enc_state_t
    int16_t num_decorr;

    float ***mixer_mat;
#ifndef COVARIANCE_MEMORY_OPT
    float ***cov_real;
    float ***cov_dtx_real;
#endif
    float ***mixer_mat_local;
    ivas_spar_md_com_cfg spar_md_cfg;
    ivas_arith_coeffs_t arith_coeffs;