Commit 7dedf056 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

Merge branch...

Merge branch '119-pointer-variables-clean-up-for-ivas_quantise_real_values-and-ivas_deindex_real_index' into 'main'

Fix for issue 119: Pointer variables clean up for ivas_quantise_real_values() and ivas_deindex_real_index()

See merge request !136
parents 92ee6e06 1cc2ac30
Loading
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -4243,16 +4243,30 @@ int16_t ivas_map_num_decd_r_to_idx( const int16_t num_quant_points_decd_r );

/* Quantization utilities */
void ivas_quantise_real_values(
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
        const float *values,
#else
        float **values,
#endif
        const int16_t q_levels,
        const float min_value,
        const float max_value,
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
        int16_t *index,
        float *quant,
#else
        int16_t **index,
        float **quant,
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    const int16_t dim
#else
    const int16_t dim1,
    const int16_t dim2
#endif
);


void ivas_spar_get_uniform_quant_strat(
    ivas_spar_md_com_cfg *pSpar_md_com_cfg,
    const int16_t table_idx
+49 −10
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@
#include "ivas_rom_com.h"
#include <assert.h>
#include "wmops.h"

#ifndef QUANTISE_REAL_FCN_CLEAN_UP
/*-----------------------------------------------------------------------------------------*
 * Function ivas_limit_values()
 *
@@ -56,7 +56,6 @@ static void ivas_limit_values(
    const int16_t dim2 )
{
    int16_t i, j;

    for ( i = 0; i < dim1; i++ )
    {
        for ( j = 0; j < dim2; j++ )
@@ -64,48 +63,73 @@ static void ivas_limit_values(
            ppValues[i][j] = max( min_value, min( ppValues[i][j], max_value ) );
        }
    }

    return;
}

#endif

/*-----------------------------------------------------------------------------------------*
 * Function ivas_quantise_real_values()
 *
 * Quantize real values
 *-----------------------------------------------------------------------------------------*/

void ivas_quantise_real_values(
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    const float *values,
#else
    float **values,
#endif
    const int16_t q_levels,
    const float min_value,
    const float max_value,
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    int16_t *index,
    float *quant,
#else
    int16_t **index,
    float **quant,
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    const int16_t dim
#else
    const int16_t dim1,
    const int16_t dim2 )
    const int16_t dim2
#endif
)
{
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
    int16_t i, j;
#else
    int16_t i;
#endif
    float q_step, one_by_q_step;

    if ( q_levels == 1 )
    {
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
        for ( i = 0; i < dim1; i++ )
        {
            for ( j = 0; j < dim2; j++ )
            {

                quant[i][j] = 0;
                index[i][j] = 0;
            }
        }
#else
        for ( i = 0; i < dim; i++ )
        {
            quant[i] = 0;
            index[i] = 0;
        }
#endif
    }
    else if ( q_levels && max_value != min_value )
    {
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
        ivas_limit_values( values, min_value, max_value, dim1, dim2 );

#endif
        q_step = ( max_value - min_value ) / ( q_levels - 1 );
        one_by_q_step = ( q_levels - 1 ) / ( max_value - min_value );

#ifndef QUANTISE_REAL_FCN_CLEAN_UP
        for ( i = 0; i < dim1; i++ )
        {
            for ( j = 0; j < dim2; j++ )
@@ -114,9 +138,19 @@ void ivas_quantise_real_values(
                quant[i][j] = index[i][j] * q_step;
            }
        }
#else
        float val;
        for ( i = 0; i < dim; i++ )
        {
            val = max( min_value, min( values[i], max_value ) );
            index[i] = (int16_t) round( one_by_q_step * val );
            quant[i] = index[i] * q_step;
        }
#endif
    }
    else
    {
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
        for ( i = 0; i < dim1; i++ )
        {
            for ( j = 0; j < dim2; j++ )
@@ -124,8 +158,13 @@ void ivas_quantise_real_values(
                quant[i][j] = values[i][j];
            }
        }
#else
        for ( i = 0; i < dim; i++ )
        {
            quant[i] = values[i];
        }
#endif
    }

    return;
}

+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@
#define SBA_INTERN_CONFIG_FIX_HOA2                      /* Issue 99 : Fix for incorrect internal_config when output format is HOA2 or FOA*/
#define FIX_I98_HANDLES_TO_NULL                         /* Issue 98: do the setting of all handles to NULL in one place */

#define QUANTISE_REAL_FCN_CLEAN_UP                      /*Clean up the ivas_quantise_real_values() function*/

/* ################## End DEVELOPMENT switches ######################### */
/* clang-format on */
+169 −17
Original line number Diff line number Diff line
@@ -82,9 +82,11 @@ static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coe
static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const int16_t nchan_transport, float *pFC );

static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band );

#ifdef QUANTISE_REAL_FCN_CLEAN_UP
static ivas_error ivas_deindex_real_index( const int16_t *index, const int16_t q_levels, const float min_value, const float max_value, float *quant, const int16_t num_ch_dim2 );
#else
static ivas_error ivas_deindex_real_index( int16_t **index, const int16_t q_levels, const float min_value, const float max_value, float **quant, const int16_t num_ch, const int16_t dim2 );

#endif
static void ivas_spar_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode );


@@ -1601,23 +1603,31 @@ static void ivas_spar_dec_parse_md_bs(
        for ( i = 0; i < *nB; i++ )
        {
            int16_t ii, jj;
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            int16_t *index_scratch[IVAS_SPAR_P_LOWERTRI];
            float *quant_scratch[IVAS_SPAR_P_LOWERTRI];
#endif
            int16_t ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( *bands_bw ) * i];
            int16_t ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( *bands_bw ) * i];
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            int16_t **index = (int16_t **) &index_scratch[0];
            float **quant = (float **) &quant_scratch[0];
            float coeff_decd[IVAS_SPAR_MAX_CH - 1];
            float coeff_decx_re[IVAS_SPAR_P_LOWERTRI];
            int16_t decx_index_re[IVAS_SPAR_P_LOWERTRI];
            int16_t pred_index_re[IVAS_SPAR_MAX_CH - 1];
            int16_t drct_index_re[IVAS_SPAR_MAX_C_COEFF];
            int16_t decd_index_re[IVAS_SPAR_MAX_CH - 1];
            int16_t decx_index_re[IVAS_SPAR_P_LOWERTRI];
#else
            float quant[IVAS_SPAR_MAX_C_COEFF];
#endif
#ifndef QUANTISE_REAL_FCN_CLEAN_UP

            for ( j = 0; j < ndm + ndec - 1; j++ )
            {
                pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j];
            }

            for ( j = 0; j < ndec * ( ndm - 1 ); j++ )
            {
                drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j];
@@ -1626,10 +1636,14 @@ static void ivas_spar_dec_parse_md_bs(
            {
                decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j];
            }

#endif
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            index[0] = &pred_index_re[0];
            quant[0] = &hMdDec->spar_md.band_coeffs[i].pred_re[0];

#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, hMdDec->spar_md.band_coeffs[i].pred_re, ndm + ndec - 1 );
#else
            ivas_deindex_real_index( index, qs.PR.q_levels[0], qs.PR.min, qs.PR.max, quant, 1, ndm + ndec - 1 );
            for ( ii = 0; ii < ndec; ii++ )
            {
@@ -1638,7 +1652,19 @@ static void ivas_spar_dec_parse_md_bs(
                    hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = 0;
                }
            }
#endif

            j = 0;
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            for ( ii = 0; ii < ndec; ii++ )
            {
                for ( jj = 0; jj < ndm - 1; jj++ )
                {
                    quant[j] = hMdDec->spar_md.band_coeffs[i].C_re[ii][jj];
                    j++;
                }
            }
#else
            for ( ii = 0; ii < ndec; ii++ )
            {
                for ( jj = 0; jj < ndm - 1; jj++ )
@@ -1648,29 +1674,76 @@ static void ivas_spar_dec_parse_md_bs(
                    j++;
                }
            }
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].drct_index_re, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ) );
#else
            ivas_deindex_real_index( index, qs.C.q_levels[0], qs.C.min, qs.C.max, quant, ndec * ( ndm - 1 ), 1 );

#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            j = 0;
            for ( ii = 0; ii < ndec; ii++ )
            {
                for ( jj = 0; jj < ndm - 1; jj++ )
                {
                    hMdDec->spar_md.band_coeffs[i].C_re[ii][jj] = quant[j];
                    j++;
                }
            }
#endif
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            index[0] = &decd_index_re[0];
            quant[0] = &coeff_decd[0];
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, hMdDec->spar_md.band_coeffs[i].P_re, ndm + ndec - 1 );
#else
            ivas_deindex_real_index( index, qs.P_r.q_levels[0], qs.P_r.min, qs.P_r.max, quant, 1, ndm + ndec - 1 );

#endif
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            index[0] = &decx_index_re[0];
            quant[0] = &coeff_decx_re[0];
#endif
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( index, qs.P_c.q_levels[0], qs.P_c.min, qs.P_c.max, quant, 1, ndec * ( ndec - 1 ) >> 2 );

#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            /* Store prior coefficient indices */
            for ( j = 0; j < ndm + ndec - 1; j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j];
            }
#else
            /* Store prior coefficient indices */
            for ( j = 0; j < ndm + ndec - 1; j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = pred_index_re[j];
            }
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            for ( j = 0; j < ndec * ( ndm - 1 ); j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j];
            }
#else
            for ( j = 0; j < ndec * ( ndm - 1 ); j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = drct_index_re[j];
            }
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            for ( j = 0; j < ndec; j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j];
            }
#else
            for ( j = 0; j < ndec; j++ )
            {
                hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = decd_index_re[j];
            }
#endif

#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            for ( k = 0; k < ndec; k++ )
            {
                hMdDec->spar_md.band_coeffs[i].P_re[k] = 0;
@@ -1680,7 +1753,7 @@ static void ivas_spar_dec_parse_md_bs(
                /* Don't bother adding in the decx parameters */
                hMdDec->spar_md.band_coeffs[i].P_re[j] = coeff_decd[j];
            }

#endif
            hMdDec->valid_bands[i] |= ( do_diff[i] == 0 ) ? 1 : 0;
        }
    }
@@ -2324,35 +2397,58 @@ static void ivas_spar_unquant_dtx_indicies(
{
    int16_t i, b;
    int16_t q_lvl;
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
    float **ppVal, *pVal, val;
    int16_t **ppIdx, *pIdx, idx;
#else
    float val;
    int16_t idx;
#endif
    float pr_min_max[2];

    pr_min_max[0] = pSpar_md->min_max[0];
    pr_min_max[1] = pSpar_md->min_max[1];

#ifndef QUANTISE_REAL_FCN_CLEAN_UP
    ppVal = (float **) &pVal;
    ppIdx = (int16_t **) &pIdx;

    ppVal[0] = (float *) &val;
    ppIdx[0] = (int16_t *) &idx;

#endif
    for ( b = 0; b < nB; b++ )
    {
        for ( i = 0; i < FOA_CHANNELS - 1; i++ )
        {
            q_lvl = dtx_pr_real_q_levels[ndm_per_band[bw * b] - 1][i];
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            ppIdx[0][0] = pSpar_md->band_coeffs_idx[b].pred_index_re[i];
#else
            idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i];
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( &idx, q_lvl, pr_min_max[0], pr_min_max[1], &val, 1 );
            pSpar_md->band_coeffs[b].pred_re[i] = val;
#else
            ivas_deindex_real_index( ppIdx, q_lvl, pr_min_max[0], pr_min_max[1], ppVal, 1, 1 );
            pSpar_md->band_coeffs[b].pred_re[i] = ppVal[0][0];
#endif
        }

        for ( i = 0; i < FOA_CHANNELS - ndm_per_band[bw * b]; i++ )
        {
            q_lvl = dtx_pd_real_q_levels[ndm_per_band[bw * b] - 1][i];
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
            ppIdx[0][0] = pSpar_md->band_coeffs_idx[b].decd_index_re[i];
#else
            idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i];
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
            ivas_deindex_real_index( &idx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &val, 1 );
            pSpar_md->band_coeffs[b].P_re[i] = val;
#else
            ivas_deindex_real_index( ppIdx, q_lvl, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppVal, 1, 1 );
            pSpar_md->band_coeffs[b].P_re[i] = ppVal[0][0];
#endif
        }
    }

@@ -2375,19 +2471,25 @@ static void ivas_parse_parameter_bitstream_dtx(
    int16_t *num_dec_per_band )
{
    int16_t i, j;
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    float val;
    int16_t idx;
#else
    float **ppVal, *pVal, val;
    int16_t **ppIdx, *pIdx, idx;
#endif
    float pr_min_max[2];
    int16_t pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits;
    int16_t pr_q_lvls1, pr_q_lvls2, pr_idx1, pr_idx2, pr_pr_bits;
    int16_t zero_pad_bits, sid_bits_len;
    sid_bits_len = st0->next_bit_pos;
#ifndef QUANTISE_REAL_FCN_CLEAN_UP
    ppVal = (float **) &pVal;
    ppIdx = (int16_t **) &pIdx;

    ppVal[0] = (float *) &val;
    ppIdx[0] = (int16_t *) &idx;

#endif
    pr_min_max[0] = pSpar_md->min_max[0];
    pr_min_max[1] = pSpar_md->min_max[1];

@@ -2427,16 +2529,26 @@ static void ivas_parse_parameter_bitstream_dtx(

                    pr = (int16_t) floor( value / pd_q_lvls );
                    pd = value - pr * pd_q_lvls;

#ifdef QUANTISE_REAL_FCN_CLEAN_UP
                    val = dtx_pd_real_min_max[0];
                    ivas_quantise_real_values( &val, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], &idx, &val, 1 );
#else
                    ppVal[0][0] = dtx_pd_real_min_max[0];
                    ivas_quantise_real_values( ppVal, pd_q_lvls, dtx_pd_real_min_max[0], dtx_pd_real_min_max[1], ppIdx, ppVal, 1, 1 );
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
                    pd = pd + idx;

                    val = pr_min_max[0];
                    ivas_quantise_real_values( &val, pr_q_lvls, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );
                    pr = pr + idx;
#else
                    pd = pd + ppIdx[0][0];

                    ppVal[0][0] = pr_min_max[0];
                    ivas_quantise_real_values( ppVal, pr_q_lvls, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );

                    pr = pr + ppIdx[0][0];
#endif

                    if ( ( j + 1 ) <= ndec )
                    {
@@ -2456,7 +2568,17 @@ static void ivas_parse_parameter_bitstream_dtx(

                    pr_idx2 = (int16_t) floor( value / pr_q_lvls1 );
                    pr_idx1 = value - pr_idx2 * pr_q_lvls1;
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
                    val = pr_min_max[0];
                    ivas_quantise_real_values( &val, pr_q_lvls1, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );

                    pr_idx1 += idx;

                    val = pr_min_max[0];
                    ivas_quantise_real_values( &val, pr_q_lvls2, pr_min_max[0], pr_min_max[1], &idx, &val, 1 );

                    pr_idx2 += idx;
#else
                    ppVal[0][0] = pr_min_max[0];
                    ivas_quantise_real_values( ppVal, pr_q_lvls1, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );

@@ -2466,7 +2588,7 @@ static void ivas_parse_parameter_bitstream_dtx(
                    ivas_quantise_real_values( ppVal, pr_q_lvls2, pr_min_max[0], pr_min_max[1], ppIdx, ppVal, 1, 1 );

                    pr_idx2 += ppIdx[0][0];

#endif
                    pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_1 - 1] = pr_idx1;
                    pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1] = pr_idx2;
                }
@@ -2495,15 +2617,32 @@ static void ivas_parse_parameter_bitstream_dtx(
 *-----------------------------------------------------------------------------------------*/

static ivas_error ivas_deindex_real_index(
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    const int16_t *index,
#else
    int16_t **index,
#endif
    const int16_t q_levels,
    const float min_value,
    const float max_value,
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    float *quant,
#else
    float **quant,
#endif
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    const int16_t dim
#else
    const int16_t num_ch,
    const int16_t dim2 )
    const int16_t dim2
#endif
)
{
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
    int16_t i;
#else
    int16_t i, j;
#endif
    float q_step;

    if ( q_levels == 0 )
@@ -2513,6 +2652,12 @@ static ivas_error ivas_deindex_real_index(

    if ( q_levels == 1 )
    {
#ifdef QUANTISE_REAL_FCN_CLEAN_UP
        for ( i = 0; i < dim; i++ )
        {
            quant[i] = 0;
        }
#else
        for ( i = 0; i < num_ch; i++ )
        {
            for ( j = 0; j < dim2; j++ )
@@ -2520,11 +2665,17 @@ static ivas_error ivas_deindex_real_index(
                quant[i][j] = 0;
            }
        }
#endif
    }
    else
    {
        q_step = ( max_value - min_value ) / ( q_levels - 1 );

#ifdef QUANTISE_REAL_FCN_CLEAN_UP
        for ( i = 0; i < dim; i++ )
        {
            quant[i] = index[i] * q_step;
        }
#else
        for ( i = 0; i < num_ch; i++ )
        {
            for ( j = 0; j < dim2; j++ )
@@ -2532,6 +2683,7 @@ static ivas_error ivas_deindex_real_index(
                quant[i][j] = index[i][j] * q_step;
            }
        }
#endif
    }

    return IVAS_ERR_OK;
+145 −33

File changed.

Preview size limit exceeded, changes collapsed.