Commit a4b9e4c4 authored by Jouni Paulus's avatar Jouni Paulus
Browse files

Merge remote-tracking branch 'origin/main' into...

Merge remote-tracking branch 'origin/main' into 570-use-correct-subframe-for-external-orientations-interpolation
parents c9bd49de ec85a5ba
Loading
Loading
Loading
Loading
Loading
+136 −0
Original line number Diff line number Diff line
@@ -169,6 +169,131 @@ Word16 rate2EVSmode(
 * Re-allocate the list of indices
 *-------------------------------------------------------------------*/

#ifdef FIX_MEM_REALLOC_IND_LIST
ivas_error ind_list_realloc(
    INDICE_HANDLE old_ind_list,    /* i  : pointer to the beginning of the old buffer of indices */
    const int16_t max_num_indices, /* i  : new maximum number of allowed indices in the list */
    Encoder_Struct *st_ivas        /* i  : IVAS encoder structure                  */
)
{
    int16_t i, n, ch, n_channels, ind_list_pos, is_metadata, ivas_max_num_indices;
    INDICE_HANDLE new_ind_list;
    BSTR_ENC_HANDLE hBstr;

    if ( st_ivas == NULL )
    {
        return IVAS_ERR_OK;
    }

    /* get the pointer to the beginning of the old buffer of indices (either metadata or core coders) */
    if ( old_ind_list == st_ivas->ind_list_metadata )
    {
        is_metadata = 1;
        ivas_max_num_indices = st_ivas->ivas_max_num_indices_metadata;
    }
    else
    {
        is_metadata = 0;
        ivas_max_num_indices = st_ivas->ivas_max_num_indices;
    }

    /* allocate new buffer of indices */
    if ( ( new_ind_list = (INDICE_HANDLE) malloc( max_num_indices * sizeof( Indice ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
    }

    /* move indices from the old list to the new list */
    for ( i = 0; i < min( max_num_indices, ivas_max_num_indices ); i++ )
    {
        if ( old_ind_list[i].nb_bits > -1 )
        {
            new_ind_list[i].id = old_ind_list[i].id;
            new_ind_list[i].value = old_ind_list[i].value;
        }
        new_ind_list[i].nb_bits = old_ind_list[i].nb_bits;
    }

    /* reset nb_bits of all other indices to -1 */
    for ( ; i < max_num_indices; i++ )
    {
        new_ind_list[i].nb_bits = -1;
    }

    /* update parameters in all SCE elements */
    for ( n = 0; n < st_ivas->nSCE; n++ )
    {
        /* get the pointer to hBstr */
        if ( is_metadata )
        {
            hBstr = st_ivas->hSCE[n]->hMetaData;
        }
        else
        {
            hBstr = st_ivas->hSCE[n]->hCoreCoder[0]->hBstr;
        }

        if ( hBstr != NULL )
        {
            /* get the current position inside the old list */
            ind_list_pos = (int16_t) ( hBstr->ind_list - old_ind_list );

            /* set pointers in the new list */
            *( hBstr->ivas_ind_list_zero ) = new_ind_list;
            hBstr->ind_list = &new_ind_list[ind_list_pos];

            /* set the new maximum number of indices */
            *( hBstr->ivas_max_num_indices ) = max_num_indices;
        }
    }

    /* update parameters in all CPE elements */
    for ( n = 0; n < st_ivas->nCPE; n++ )
    {
        /* get the pointer to hBstr */
        if ( is_metadata )
        {
            n_channels = 1;
        }
        else
        {
            n_channels = CPE_CHANNELS;
        }

        for ( ch = 0; ch < n_channels; ch++ )
        {
            if ( is_metadata )
            {
                hBstr = st_ivas->hCPE[n]->hMetaData;
            }
            else
            {
                hBstr = st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr;
            }

            if ( hBstr != NULL )
            {
                /* get the current position inside the old list */
                ind_list_pos = (int16_t) ( hBstr->ind_list - old_ind_list );

                /* set pointers in the new list */
                *( hBstr->ivas_ind_list_zero ) = new_ind_list;
                hBstr->ind_list = &new_ind_list[ind_list_pos];

                /* set the new maximum number of indices */
                *( hBstr->ivas_max_num_indices ) = max_num_indices;
            }
        }
    }

    /* free the old list */
    free( old_ind_list );

    return IVAS_ERR_OK;
}

#else

ivas_error ind_list_realloc(
    BSTR_ENC_HANDLE hBstr,        /* i/o: encoder bitstream handle                          */
    const int16_t max_num_indices /* i  : new maximum number of allowed indices in the list */
@@ -216,6 +341,8 @@ ivas_error ind_list_realloc(
    return IVAS_ERR_OK;
}

#endif


/*-----------------------------------------------------------------------*
 * get_ivas_max_num_indices()
@@ -468,6 +595,7 @@ int16_t get_core_max_num_indices(
    const int32_t total_brate /* i  : total bitrate             */
)
{

    /* set the maximum number of indices in the core coder */
    if ( core == ACELP_CORE || core == AMR_WB_CORE )
    {
@@ -866,7 +994,11 @@ ivas_error check_ind_list_limits(
#endif

        /* reallocate the buffer of indices with increased limit */
#ifdef FIX_MEM_REALLOC_IND_LIST
        if ( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK )
#else
        if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK )
#endif
        {
            return error;
        }
@@ -894,7 +1026,11 @@ ivas_error check_ind_list_limits(
#endif

                /* no available empty slot -> need to re-allocate the buffer */
#ifdef FIX_MEM_REALLOC_IND_LIST
                if ( ( error = ind_list_realloc( *hBstr->ivas_ind_list_zero, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES, hBstr->st_ivas ) ) != IVAS_ERR_OK )
#else
                if ( ( error = ind_list_realloc( hBstr, *( hBstr->ivas_max_num_indices ) + STEP_MAX_NUM_INDICES ) ) != IVAS_ERR_OK )
#endif
                {
                    return error;
                }
+2 −1
Original line number Diff line number Diff line
@@ -127,7 +127,6 @@
/*#define DEBUG_BINAURAL_FILTER_DESIGN*/        /* debugging of Crend binaural filter design */
/*#define DEBUG_AGC_ENCODER_CMD_OPTION*/        /* Ability to force enable or disable AGC behaviour in DIRAC/SPAR via command line option */
#define DEBUG_JBM_CMD_OPTION                    /* ability for telling the decoder the frontend fetch size and to not delay compensate for bad frames at the beginning */

#define VARIABLE_SPEED_DECODING                 /* variable speed decoding employing the JBM functioniality; move to DEBUGGING after build for disabled is fixed */

#endif
@@ -168,6 +167,8 @@
#define FIX_570_SF_EXT_ORIENTATION
#define FIX_593_STL_INCLUDE                             /* FhG: Issue 593: correct include of stl.h in lib_enc/ivas_stereo_eclvq_enc.c */
#define FIX_583_CLANG_TRANS_DET                         /* FhG: Issue 583: clang left shift on ramp_up_flag in transient detector */
#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*/

/* ################## End BE DEVELOPMENT switches ######################### */

+8 −0
Original line number Diff line number Diff line
@@ -538,10 +538,18 @@ int16_t get_ivas_max_num_indices_metadata(
    const int32_t ivas_total_brate /* i  : IVAS total bitrate       */
);

#ifdef FIX_MEM_REALLOC_IND_LIST
ivas_error ind_list_realloc(
    INDICE_HANDLE old_ind_list,    /* i  : pointer to the beginning of the old buffer of indices */
    const int16_t max_num_indices, /* i  : new maximum number of allowed indices in the list */
    Encoder_Struct *st_ivas        /* i  : IVAS encoder structure                  */
);
#else
ivas_error ind_list_realloc(
    BSTR_ENC_HANDLE hBstr,        /* i/o: encoder bitstream handle  */
    const int16_t max_num_indices /* i  : new maximum number of allowed indices in the list */
);
#endif

ivas_error check_ind_list_limits(
    BSTR_ENC_HANDLE hBstr /* i/o: encoder bitstream handle                    */
+18 −2
Original line number Diff line number Diff line
@@ -701,8 +701,13 @@ ivas_error ivas_jbm_dec_render(
                *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
                pan_left = ( st_ivas->hDecoderConfig->non_diegetic_pan_gain + 1.f ) * 0.5f;
                pan_right = 1.f - pan_left;
#ifdef NONBE_FIX_589_JBM_TC_OFFSETS
                v_multc( p_tc[0], pan_right, output[1], *nSamplesRendered );
                v_multc( p_tc[0], pan_left, output[0], *nSamplesRendered );
#else
                v_multc( st_ivas->hTcBuffer->tc[0], pan_right, output[1], *nSamplesRendered );
                v_multc( st_ivas->hTcBuffer->tc[0], pan_left, output[0], *nSamplesRendered );
#endif
            }
            else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
            {
@@ -729,8 +734,13 @@ ivas_error ivas_jbm_dec_render(
            {
                pan_left = ( st_ivas->hDecoderConfig->non_diegetic_pan_gain + 1.f ) * 0.5f;
                pan_right = 1.f - pan_left;
#ifdef NONBE_FIX_589_JBM_TC_OFFSETS
                v_multc( p_tc[0], pan_right, output[1], *nSamplesRendered );
                v_multc( p_tc[0], pan_left, output[0], *nSamplesRendered );
#else
                v_multc( st_ivas->hTcBuffer->tc[0], pan_right, output[1], *nSamplesRendered );
                v_multc( st_ivas->hTcBuffer->tc[0], pan_left, output[0], *nSamplesRendered );
#endif
            }
            else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
            {
@@ -816,8 +826,11 @@ ivas_error ivas_jbm_dec_render(
                {
                    return error;
                }

#ifdef NONBE_FIX_589_JBM_TC_OFFSETS
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
#else
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc, p_output );
#endif
            }
            else if ( st_ivas->renderer_type == RENDERER_MC )
            {
@@ -834,8 +847,11 @@ ivas_error ivas_jbm_dec_render(
                {
                    return error;
                }

#ifdef NONBE_FIX_589_JBM_TC_OFFSETS
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, p_tc, p_output );
#else
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc, p_output );
#endif
            }
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
+1 −22
Original line number Diff line number Diff line
@@ -2873,9 +2873,6 @@ void ivas_spar_to_dirac(
    float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS];
    float radius;
    float en_ratio, res_pow;
#ifdef ENABLE_DITHER
    int16_t *seed_ptr;
#endif
    int16_t num_slots_in_subfr;
    int16_t tmp_write_idx_param_band;
    int16_t tmp_write_idx_band;
@@ -2898,9 +2895,6 @@ void ivas_spar_to_dirac(
    if ( hDirAC != NULL && ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) == 0 )
    {
        band_grouping = hDirAC->band_grouping;
#ifdef ENABLE_DITHER
        seed_ptr = &hDirAC->dithering_seed;
#endif
        num_slots_in_subfr = st_ivas->hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1;

        for ( band = start_band; band < end_band; band++ )
@@ -2975,17 +2969,10 @@ void ivas_spar_to_dirac(

        for ( band = start_band; band < end_band; band++ )
        {
#ifdef ENABLE_DITHER
            int16_t diff_idx, azi_dith, ele_dith;
#else
            int16_t azi_dith, ele_dith;
#endif
            tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx;

            en_ratio = 1.0f - diffuseness[band];
#ifdef ENABLE_DITHER
            diff_idx =
#endif
            masa_sq( 1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS );

            qmf_band_start = band_grouping[band];
@@ -3000,16 +2987,8 @@ void ivas_spar_to_dirac(
                for ( b = qmf_band_start; b < qmf_band_end; b++ )
                {

#ifdef ENABLE_DITHER
                    azi_dith = (int16_t) ( azi[band] + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f );
                    ele_dith = (int16_t) ( ele[band] + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f );
                    /* limit the elevation to [-90, 90] */
                    ele_dith = min( 90, ele_dith );
                    ele_dith = max( -90, ele_dith );
#else
                    azi_dith = azi[band];
                    ele_dith = ele[band];
#endif

                    hDirAC->energy_ratio1[block][b] = en_ratio;
                    tmp_write_idx_band = tmp_write_idx_param_band;
Loading