Commit b375b255 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'lib_com_enc_integration' into 'main'

Integration of common fixed point functions in encoder

See merge request !416
parents 438bf483 af01ef9a
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@ static void ivas_set_up_cov_smoothing(
 * Allocate and initialize SPAR Covar. smoothing handle
 *------------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
ivas_error ivas_spar_covar_smooth_enc_open(
    ivas_cov_smooth_state_t **hCovState_out,     /* i/o: SPAR Covar. smoothing handle       */
    const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i  : SPAR config. handle                */
@@ -332,7 +333,48 @@ ivas_error ivas_spar_covar_smooth_enc_open(

    return IVAS_ERR_OK;
}
#else
ivas_error ivas_spar_covar_smooth_enc_open(
    ivas_cov_smooth_state_t **hCovState_out,     /* i/o: SPAR Covar. smoothing handle       */
    const ivas_cov_smooth_cfg_t *cov_smooth_cfg, /* i  : SPAR config. handle                */
    ivas_filterbank_t *pFb,                      /* i/o: FB handle                          */
    const int16_t nchan_inp,                     /* i  : number of input channels           */
    const COV_SMOOTHING_TYPE smooth_mode,        /* i  : Smooth covariance for SPAR or MC   */
    const int32_t ivas_total_brate               /* i  : IVAS total bitrate                 */
)
{
    ivas_cov_smooth_state_t *hCovState;
    int16_t i, j;

    if ( ( hCovState = (ivas_cov_smooth_state_t *) malloc( sizeof( ivas_cov_smooth_state_t ) ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
    }

    if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
    }

    for ( i = 0; i < nchan_inp; i++ )
    {
        for ( j = 0; j < nchan_inp; j++ )
        {
            if ( ( hCovState->pPrior_cov_real[i][j] = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL )
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" );
            }
            set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands );
        }
    }

    ivas_set_up_cov_smoothing( hCovState, pFb, cov_smooth_cfg->max_update_rate, cov_smooth_cfg->min_pool_size, smooth_mode, ivas_total_brate );

    *hCovState_out = hCovState;

    return IVAS_ERR_OK;
}
#endif

/*-------------------------------------------------------------------------
 * ivas_spar_covar_smooth_enc_close()
@@ -340,6 +382,7 @@ ivas_error ivas_spar_covar_smooth_enc_open(
 * Deallocate SPAR Covar. smoothing handle
 *------------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_spar_covar_smooth_enc_close(
    ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle   */
    const int16_t nchan_inp                  /* i  : number of input channels       */
@@ -379,6 +422,38 @@ void ivas_spar_covar_smooth_enc_close(

    return;
}
#else
void ivas_spar_covar_smooth_enc_close(
    ivas_cov_smooth_state_t **hCovState_out, /* i/o: SPAR Covar. smoothing handle   */
    const int16_t nchan_inp                  /* i  : number of input channels       */
)
{
    ivas_cov_smooth_state_t *hCovState;
    int16_t i, j;

    hCovState = *hCovState_out;

    if ( hCovState != NULL )
    {
        free( hCovState->pSmoothing_factor );
        hCovState->pSmoothing_factor = NULL;

        for ( i = 0; i < nchan_inp; i++ )
        {
            for ( j = 0; j < nchan_inp; j++ )
            {
                free( hCovState->pPrior_cov_real[i][j] );
                hCovState->pPrior_cov_real[i][j] = NULL;
            }
        }

        free( hCovState );
        hCovState_out = NULL;
    }

    return;
}
#endif


#ifdef IVAS_FLOAT_FIXED
+24 −24
Original line number Diff line number Diff line
@@ -61,38 +61,38 @@ static UWord16 deindex_sph_idx_general_fx( const Word16 idx_sph, const Word16 no
 *------------------------------------------------------------------------*/

/*! r: HO-DirAC flag */
int16_t ivas_get_hodirac_flag(
    const int32_t ivas_total_brate, /* i  : IVAS total bitrate      */
    const int16_t sba_order         /* i  : Ambisonic (SBA) order   */
#ifdef IVAS_FLOAT_FIXED
Word16 ivas_get_hodirac_flag_fx(
    const Word32 ivas_total_brate, /* i  : IVAS total bitrate      */
    const Word16 sba_order         /* i  : Ambisonic (SBA) order   */
)
{
    if ( sba_order > 1 && ivas_total_brate > IVAS_256k )
    IF( GT_16( sba_order, 1 ) && GT_32( ivas_total_brate, IVAS_256k ) )
    {
        return 1;
    }
    else
    ELSE
    {
        return 0;
    }
}
#endif

#ifdef IVAS_FLOAT_FIXED
Word16 ivas_get_hodirac_flag_fx(
    const Word32 ivas_total_brate, /* i  : IVAS total bitrate      */
    const Word16 sba_order         /* i  : Ambisonic (SBA) order   */
int16_t ivas_get_hodirac_flag(
    const int32_t ivas_total_brate, /* i  : IVAS total bitrate      */
    const int16_t sba_order         /* i  : Ambisonic (SBA) order   */
)
{
    IF( GT_16( sba_order, 1 ) && GT_32( ivas_total_brate, IVAS_256k ) )
    if ( sba_order > 1 && ivas_total_brate > IVAS_256k )
    {
        return 1;
    }
    ELSE
    else
    {
        return 0;
    }
}

#endif
/*-------------------------------------------------------------------------
 * ivas_dirac_sba_config()
 *
@@ -169,7 +169,7 @@ ivas_error ivas_dirac_config_fx(

        spar_dirac_split_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );

        IF( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) ) // add call after merge of 100861_dirac_dec
        IF( ivas_get_hodirac_flag_fx( ivas_total_brate, sba_order ) ) // add call after merge of 100861_dirac_dec
        {
            spar_dirac_split_band = 0;
        }
@@ -204,7 +204,7 @@ ivas_error ivas_dirac_config_fx(
            hConfig->enc_param_start_band = spar_dirac_split_band;
        }

        IF( ivas_get_hodirac_flag( ivas_total_brate, sba_order ) )
        IF( ivas_get_hodirac_flag_fx( ivas_total_brate, sba_order ) )
        {
            hConfig->dec_param_estim = FALSE;
            hConfig->enc_param_start_band = 0;
@@ -217,17 +217,16 @@ ivas_error ivas_dirac_config_fx(
    IF( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT )
    {
        // 100861_dirac_dec
        ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft );
        ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hConfig->enc_param_start_band, hFbMdft );
    }
    ELSE
    {
        ivas_dirac_config_bands( band_grouping, hConfig->nbands, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), NULL, 0, 0, hFbMdft );
        ivas_dirac_config_bands_fx( band_grouping, hConfig->nbands, (Word16) ( Fs * INV_CLDFB_BANDWIDTH + 0.5f ), NULL, 0, 0, hFbMdft );
    }

    return error;
}
#endif

#else
ivas_error ivas_dirac_config(
    void *st_ivas,        /* i/o: IVAS encoder/decoder state structure  */
    const int16_t enc_dec /* i  : encoder or decoder flag               */
@@ -354,6 +353,7 @@ ivas_error ivas_dirac_config(

    return error;
}
#endif


/*-------------------------------------------------------------------------
@@ -362,6 +362,7 @@ ivas_error ivas_dirac_config(
 * DirAC Configuration freq. band function; used also in MASA decoder
 *------------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
void ivas_dirac_config_bands(
    int16_t *band_grouping, /* o  : band grouping                          */
    const int16_t nbands,   /* i  : number of bands                        */
@@ -458,8 +459,7 @@ void ivas_dirac_config_bands(

    return;
}

#ifdef IVAS_FLOAT_FIXED
#else
void ivas_dirac_config_bands_fx(
    Word16 *band_grouping, /* o  : band grouping                          */
    const Word16 nbands,   /* i  : number of bands                        */
@@ -673,8 +673,7 @@ void ivas_get_dirac_sba_max_md_bits_fx(

    return;
}
#endif

#else
void ivas_get_dirac_sba_max_md_bits(
    const int32_t sba_total_brate,
    int16_t *bits_frame_nominal,
@@ -743,6 +742,7 @@ void ivas_get_dirac_sba_max_md_bits(

    return;
}
#endif

/*-------------------------------------------------------------------------
 * ivas_dirac_sba_config()
@@ -832,8 +832,7 @@ ivas_error ivas_dirac_sba_config_fx(

    return error;
}
#endif

#else
ivas_error ivas_dirac_sba_config(
    IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle                                    */
    int16_t *element_mode,            /* i/o: element mode of the core coder                       */
@@ -908,6 +907,7 @@ ivas_error ivas_dirac_sba_config(

    return error;
}
#endif


#ifdef IVAS_FLOAT_FIXED
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ static ivas_error ivas_dirac_dec_config_internal_fx(
     * DirAC main configuration
     *-----------------------------------------------------------------*/

    IF( NE_32( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) )
    IF( NE_32( ( error = ivas_dirac_config_fx( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) )
    {
        return error;
    }
+8 −8
Original line number Diff line number Diff line
@@ -2054,7 +2054,7 @@ ivas_error ivas_init_decoder_fx(
            }
        }

        Word16 hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order );
        Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
        IF( hodirac_flag )
        {
            IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
@@ -2089,7 +2089,7 @@ ivas_error ivas_init_decoder_fx(

            st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
            move16();
            IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
            IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
            {
                st_ivas->hSpar->enc_param_start_band = 0;
                move16();
@@ -2245,17 +2245,17 @@ ivas_error ivas_init_decoder_fx(
            }
        }

        Word16 hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order );
        Word16 hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order );
        IF( hodirac_flag )
        {
            IF( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
            IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, IVAS_MAX_NUM_BANDS, st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
            {
                return error;
            }
        }
        ELSE
        {
            IF( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
            IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
            {
                return error;
            }
@@ -2280,7 +2280,7 @@ ivas_error ivas_init_decoder_fx(
            Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];

            st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
            IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
            IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
            {
                st_ivas->hSpar->enc_param_start_band = 0;
                move16();
@@ -2289,7 +2289,7 @@ ivas_error ivas_init_decoder_fx(
                move16();
            }

            ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ),
            ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ),
                                        st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );
        }

+15 −7
Original line number Diff line number Diff line
@@ -432,11 +432,19 @@ ivas_error ivas_sba_dec_reconfigure(
        ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
    }

#ifdef IVAS_FLOAT_FIXED
    if ( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ),
                                             st_ivas->ivas_format ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#else
    if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ),
                                          st_ivas->ivas_format ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) ) )
    {
@@ -462,7 +470,7 @@ ivas_error ivas_sba_dec_reconfigure(
        int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1];

        st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND );
        if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) )
        if ( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
        {
            st_ivas->hSpar->enc_param_start_band = 0;

@@ -470,7 +478,7 @@ ivas_error ivas_sba_dec_reconfigure(
            st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
        }

        ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
        ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ),
                                    st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );

        if ( st_ivas->hDirAC )
@@ -1084,7 +1092,7 @@ ivas_error ivas_sba_dec_reconfigure_fx(
        ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
    }

    if ( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ),
    if ( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ),
                                                    st_ivas->ivas_format ) ),
                IVAS_ERR_OK ) )
    {
@@ -1122,7 +1130,7 @@ ivas_error ivas_sba_dec_reconfigure_fx(
            move16();
        }

        ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ),
        ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ),
                                    st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 );

        if ( st_ivas->hDirAC )
Loading