Commit 79f880d5 authored by gaoyuy's avatar gaoyuy
Browse files

Fixed issue with new HRIR.

parent 038ca4d2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1205,6 +1205,11 @@ typedef enum

#define MP_MAX_CHANNELS_DECORR                  4
#define MP_MAX_DECORR_CONFIG                    ( 3 * 4 )
#ifdef FIX_IVAS_SBA_MP_768KBPS
#define MP_MIN_POST_DIFFUSENESS                 0.125f
#define MP_GAIN_POST_FACTOR                     0.125f                    
#define MP_SMOOTH_SFB_INDEX                     8
#endif
#endif

/*----------------------------------------------------------------------------------*
+1 −1
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@
#define IVAS_SBA_MP_768KBPS                             /* HW: IVAS SBA MP 768KBPS */
#ifdef IVAS_SBA_MP_768KBPS
#define IVAS_SBA_MP_768KBPS_BR_SWITCHING                /* HW: ongoing bitrate switch */

#define FIX_IVAS_SBA_MP_768KBPS
#endif

/* ################## End DEVELOPMENT switches ######################### */
+140 −0
Original line number Diff line number Diff line
@@ -371,6 +371,36 @@ static void ivas_mp_parameters_dec(
        }
    }

#ifdef FIX_IVAS_SBA_MP_768KBPS
    for ( ch = 0; ch < nchan_reference_gain_delay; ch++ )
    {
        for ( subframe_idx = 1; subframe_idx < ( nb_subframes + nb_subframe_delay ); subframe_idx++ )
        {
            for ( b = 0; b < hConfig->nb_subbands; b++ )
            {
                hMp->synth_reference_gain[ch][subframe_idx][b] = 0.5f * hMp->synth_reference_gain[ch][subframe_idx - 1][b] + 0.5f * hMp->synth_reference_gain[ch][subframe_idx][b];
            }
        }

        for ( subframe_idx = 0; subframe_idx < nb_subframes; subframe_idx++ )
        {
            for ( b = 1; b < MP_SMOOTH_SFB_INDEX; b++ )
            {
                hMp->synth_reference_gain[ch][subframe_idx][b] = 0.15f * hMp->synth_reference_gain[ch][subframe_idx][b - 1] +
                                                                 0.6f * hMp->synth_reference_gain[ch][subframe_idx][b] +
                                                                 0.25f * hMp->synth_reference_gain[ch][subframe_idx][b + 1];
            }

            for ( ; b < hConfig->nb_subbands - 1; b++ )
            {
                hMp->synth_reference_gain[ch][subframe_idx][b] = 0.1f * hMp->synth_reference_gain[ch][subframe_idx][b - 1] +
                                                                 0.75f * hMp->synth_reference_gain[ch][subframe_idx][b] +
                                                                 0.15f * hMp->synth_reference_gain[ch][subframe_idx][b + 1];
            }
        }
    }
#endif

    for ( subframe_idx = 0; subframe_idx < nb_subframes; subframe_idx++ )
    {
        if ( subframe_idx < nb_subframe_delay )
@@ -952,6 +982,9 @@ static void ivas_mp_synthesis_high_order_ambisonics_components_dec_ts(
    int16_t num_freq_bands, num_subframe_slots;
    int16_t nb_directions;
    MP_CONFIG_DATA_HANDLE hConfig;
#ifdef FIX_IVAS_SBA_MP_768KBPS
    float w;
#endif
    float tmp_spectrum[MP_MAX_DIRECTIONS][L_FRAME48k >> 1];
    float *tmp_cldfb_real_buffer[MP_MAX_DIRECTIONS][CLDFB_NO_COL_MAX];
    float *tmp_cldfb_imag_buffer[MP_MAX_DIRECTIONS][CLDFB_NO_COL_MAX];
@@ -967,6 +1000,9 @@ static void ivas_mp_synthesis_high_order_ambisonics_components_dec_ts(

    set_f( hMp->diffuseness, 0.f, hConfig->nb_subbands );
    set_f( hMp->normal_energy_factor, 0.f, hConfig->nb_subbands );
#ifdef FIX_IVAS_SBA_MP_768KBPS
    w = max( 0.75f, min( 0.25f, 1.f / (float) hMp->nb_directions ) );
#endif

    for ( k = 0; k < nb_directions; k++ )
    {
@@ -1001,6 +1037,9 @@ static void ivas_mp_synthesis_high_order_ambisonics_components_dec_ts(
        }

        hMp->diffuseness[i] = max( 0.f, min( hMp->diffuseness[i], 1.f ) );
#ifdef FIX_IVAS_SBA_MP_768KBPS
        hMp->diffuseness[i] = w * hMp->prev_diffuseness[i] + ( 1.f - w ) * hMp->diffuseness[i];
#endif
    }


@@ -1102,6 +1141,96 @@ static void ivas_mp_panning_HOA3_dec_ts(
    return;
}

#ifdef FIX_IVAS_SBA_MP_768KBPS
static void ivas_mp_apply_synthesis_gain_dec_ts(
    MP_DEC_HANDLE hMp,
    float *cldfb_real_part,
    float *cldfb_imag_part,
    float *reference_power,
    const int16_t chan_idx,
    float gain[MP_MAX_NBANDS],
    const int16_t is_transient )
{
    int16_t i, b, order;
    int16_t channel_mask;
    float reference_power_sfb, tmp_power_sfb, direction_gain;
    float w, g, g1, beta, alpha, gama, tmp_alpha;
    MP_CONFIG_DATA_HANDLE hConfig;

    hConfig = hMp->hConfig;

    order = ivas_mp_channel_index_to_sba_order( chan_idx );
    tmp_alpha = mean( hMp->averge_ndirs, MP_MAX_AVERG_DIRS );
    alpha = 0.1f * (float) ( hMp->nb_directions ) + 0.9f * tmp_alpha;
    gama = MP_ORDER2CH( order );
    gama = max( gama, 1.f );
    channel_mask = hConfig->channels_mask_table[chan_idx];

    for ( b = 0; b < hConfig->nb_subbands; b++ )
    {
        reference_power_sfb = reference_power[b];
        direction_gain = 1.f - hMp->diffuseness[b];
        tmp_power_sfb = 0.f;
        w = 0.01f;
        g1 = 1.f;

        beta = (float) MP_ORDER2CH( hMp->sba_order + 1 );

        w = w + alpha * 0.05f;
        w = max( w, 0.01f );
        
        for ( i = hConfig->band_grouping[b]; i < hConfig->band_grouping[b + 1]; i++ )
        {
            tmp_power_sfb += ( cldfb_real_part[i] * cldfb_real_part[i] ) + ( cldfb_imag_part[i] * cldfb_imag_part[i] );
        }

        g = powf( 10.f, gain[b] / 10.f );
        g = max( g, EPSILON );

        reference_power_sfb = reference_power_sfb * g;

        if ( tmp_power_sfb > EPSILON )
        {
            g = max( sqrtf( reference_power_sfb ) / ( sqrtf( tmp_power_sfb ) + EPSILON ), EPSILON );
        }
        else
        {
            g = 0.f;
        }

        if ( !channel_mask || ( is_transient && b < 2 ) || b == 0 )
        {
            beta = beta * ( 1.f + w );

            alpha = alpha + alpha * ( 1.f - (float) ( 1.25f * b ) / ( hConfig->nb_subbands + 2 ) );
            alpha = max( 0.75f, min( 2.5f, alpha ) );

            g1 = expf( -( alpha * ( b + 1 ) ) / ( beta - 0.5f * gama ) );
            g1 = w * g1 + ( 1.f - w ) * direction_gain;
            g1 = ( direction_gain > MP_MIN_POST_DIFFUSENESS ) ? direction_gain : ( direction_gain * direction_gain );
        }
        else
        {
            direction_gain = sqrtf( 1.f - hMp->diffuseness[b] );
            w += ( (float) ( b + 1 ) / ( hConfig->nb_subbands + 2 ) ) * MP_GAIN_POST_FACTOR;
            w = min( 1.f, max( w, 0.01f ) );

            g1 = 1.f - w * direction_gain;
            g1 = ( b < hMp->max_band_decorr ) ? g1 * ( 1.f - MP_GAIN_POST_FACTOR ) : g1 * 0.925f;
        }

        g1 = max( EPSILON, min( 1.f, g1 ) );

        for ( i = hConfig->band_grouping[b]; i < hConfig->band_grouping[b + 1]; i++ )
        {
            cldfb_real_part[i] = cldfb_real_part[i] * g * g1;
            cldfb_imag_part[i] = cldfb_imag_part[i] * g * g1;
        }
    }

    return;
}
#else
static void ivas_mp_apply_synthesis_gain_dec_ts(
    MP_DEC_HANDLE hMp,
    float *cldfb_real_part,
@@ -1187,6 +1316,7 @@ static void ivas_mp_apply_synthesis_gain_dec_ts(

    return;
}
#endif

static void ivas_mp_dec_parameters_update(
    MP_DEC_HANDLE hMp )
@@ -1199,6 +1329,10 @@ static void ivas_mp_dec_parameters_update(
    mvr2r( hMp->averge_ndirs + 1, hMp->averge_ndirs, MP_MAX_AVERG_DIRS - 1 );
    hMp->averge_ndirs[MP_MAX_AVERG_DIRS - 1] = (float) ( hMp->nb_directions );

#ifdef FIX_IVAS_SBA_MP_768KBPS
    mvr2r( hMp->diffuseness, hMp->prev_diffuseness, MP_MAX_NBANDS );
#endif

    return;
}

@@ -1738,6 +1872,9 @@ int16_t ivas_mp_dec_open(

    hMp->decorr_flag = 0;
    hMp->nchan_decorr = 0;
#ifdef FIX_IVAS_SBA_MP_768KBPS
    hMp->max_band_decorr = 0;
#endif

    for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ )
    {
@@ -1748,6 +1885,9 @@ int16_t ivas_mp_dec_open(
    }

    set_f( hMp->averge_ndirs, (float) MP_MAX_DIRECTIONS, MP_MAX_AVERG_DIRS );
#ifdef FIX_IVAS_SBA_MP_768KBPS
    set_f( hMp->prev_diffuseness, 0.f, MP_MAX_NBANDS );
#endif

    if ( ( error = ivas_mp_memory_open_dec( hMp ) ) != IVAS_ERR_OK )
    {
+3 −0
Original line number Diff line number Diff line
@@ -911,6 +911,9 @@ typedef struct ivas_mp_dec_data_structure
    float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF];
    float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MP_MAX_NBANDS];
    float diffuseness[MP_MAX_NBANDS];
#ifdef FIX_IVAS_SBA_MP_768KBPS
    float prev_diffuseness[MP_MAX_NBANDS];
#endif
    float normal_energy_factor[MP_MAX_NBANDS];

    /* decorrelation */
+7 −0
Original line number Diff line number Diff line
@@ -163,6 +163,13 @@ static void adjustCorrelationMatrix(
        }
    }

#ifdef FIX_IVAS_SBA_MP_768KBPS
    if ( count_active_ch <= 5 )
    {
        set_f( xCorrMatrix[0], 0.f, nchan );
    }
#endif

    /* adjust group thr */
    for ( ch1 = FOA_CHANNELS; ch1 < nchan; ch1++ )
    {