Commit 4eabe5a3 authored by bayers's avatar bayers
Browse files

fix ParamISM tx energy adjustment, fix tc offsets

parent 01319e9f
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1074,6 +1074,15 @@ void ivas_param_ism_dec_digest_tc(
    float *transport_channels_f[]                               /* i : synthesized core-coder transport channels/DirAC output  */
);

#ifdef API_5MS
void ivas_ism_param_dec_tc_gain_ajust(
    Decoder_Struct *st_ivas,      /* i/o: IVAS decoder handle                                     */
    const uint16_t nSamples,      /* i  : number of samples to be compensate         */
    const uint16_t nFadeLength,   /* i  : length of the crossfade in samples   */
    float *transport_channels_f[] /* i  : synthesized core-coder transport channels/DirAC output  */
);
#endif

void ivas_param_ism_dec_render(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                         */
    const uint16_t nSamplesAsked,                               /* i  : number of CLDFB slots requested             */
+87 −3
Original line number Diff line number Diff line
@@ -748,8 +748,12 @@ void ivas_param_ism_dec(
    int32_t ivas_total_brate;
#ifdef FIX_549_DMX_GAIN
    int16_t output_frame;
#ifndef API_5MS
    float gain, ene_tc, ene_sum, grad;
    float last_gain;
#else
    float *p_tc[PARAM_ISM_MAX_DMX];
#endif
#endif
    float ref_power[CLDFB_NO_CHANNELS_MAX];
    float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
@@ -775,9 +779,16 @@ void ivas_param_ism_dec(
    hDirAC = st_ivas->hDirAC;
    assert( hDirAC );
#ifdef FIX_549_DMX_GAIN
#ifdef API_5MS
    for ( i = 0; i < PARAM_ISM_MAX_DMX; i++ )
    {
        p_tc[i] = output_f[i];
    }
#else
    ene_tc = 0.0f;
    ene_sum = 0.0f;
    last_gain = st_ivas->hDirAC->hParamIsm->last_dmx_gain;
#endif
    output_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#endif

@@ -862,7 +873,9 @@ void ivas_param_ism_dec(
            }
        }
    }

#ifdef API_5MS
    ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, p_tc );
#else
#ifdef FIX_549_DMX_GAIN
    /* Energy Compensation */
    for ( i = 0; i < output_frame; i++ )
@@ -898,7 +911,7 @@ void ivas_param_ism_dec(
    }
    st_ivas->hDirAC->hParamIsm->last_dmx_gain = gain;
#endif

#endif
    for ( ch = 0; ch < nchan_transport; ch++ )
    {
        /*-----------------------------------------------------------------*
@@ -1114,10 +1127,12 @@ void ivas_param_ism_dec_digest_tc(
    int16_t ch, nchan_transport, nchan_out, nchan_out_woLFE, i;
    int16_t slot_idx, bin_idx;
    int32_t ivas_total_brate;
#ifndef API_5MS
#ifdef FIX_549_DMX_GAIN
    int16_t output_frame;
    float gain, ene_tc, ene_sum, grad;
    float last_gain;
#endif
#endif
    float ref_power[CLDFB_NO_CHANNELS_MAX];
    float cx_diag[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_DMX];
@@ -1128,11 +1143,13 @@ void ivas_param_ism_dec_digest_tc(
    /* Initialization */
    hDirAC = st_ivas->hDirAC;
    assert( hDirAC );
#ifndef API_5MS
#ifdef FIX_549_DMX_GAIN
    ene_tc = 0.0f;
    ene_sum = 0.0f;
    last_gain = st_ivas->hDirAC->hParamIsm->last_dmx_gain;
    output_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
#endif
#endif

    nchan_transport = st_ivas->nchan_transport;
@@ -1219,7 +1236,12 @@ void ivas_param_ism_dec_digest_tc(
            }
        }
    }

#ifdef API_5MS
    if ( st_ivas->hDecoderConfig->tsm_active )
    {
        ivas_ism_param_dec_tc_gain_ajust( st_ivas, nCldfbSlots * st_ivas->hDirAC->num_freq_bands, (int16_t) ( st_ivas->hDecoderConfig->output_Fs / ( 2 * FRAMES_PER_SEC ) ), transport_channels_f );
    }
#else
#ifdef FIX_549_DMX_GAIN
    /* Energy Compensation */
    for ( i = 0; i < output_frame; i++ )
@@ -1254,6 +1276,7 @@ void ivas_param_ism_dec_digest_tc(
        }
    }
    st_ivas->hDirAC->hParamIsm->last_dmx_gain = gain;
#endif
#endif

    for ( ch = 0; ch < nchan_transport; ch++ )
@@ -1298,6 +1321,67 @@ void ivas_param_ism_dec_digest_tc(
}


#ifdef API_5MS
/*-------------------------------------------------------------------------*
 * ivas_ism_param_dec_tc_gain_ajust()
 *
 *
 *-------------------------------------------------------------------------*/

void ivas_ism_param_dec_tc_gain_ajust(
    Decoder_Struct *st_ivas,      /* i/o: IVAS decoder handle                                     */
    const uint16_t nSamples,      /* i  : number of samples to be compensate         */
    const uint16_t nFadeLength,   /* i  : length of the crossfade in samples   */
    float *transport_channels_f[] /* i  : synthesized core-coder transport channels/DirAC output  */
)

{
    int16_t i;
    float gain, ene_tc, ene_sum, grad;
    float last_gain;

    ene_tc = 0.0f;
    ene_sum = 0.0f;
    last_gain = st_ivas->hDirAC->hParamIsm->last_dmx_gain;


    for ( i = 0; i < nSamples; i++ )
    {
        ene_tc += transport_channels_f[0][i] * transport_channels_f[0][i] + transport_channels_f[1][i] * transport_channels_f[1][i];          // L*L + R*R
        ene_sum += ( transport_channels_f[0][i] + transport_channels_f[1][i] ) * ( transport_channels_f[0][i] + transport_channels_f[1][i] ); // (L+R)*(L+R)
    }
    gain = sqrtf( ene_tc / ( ene_sum + EPSILON ) );
    if ( st_ivas->hSCE[0]->hCoreCoder[0]->ini_frame > 1 )
    {
        /* Smoothing */
        gain = 0.75f * gain + 0.25f * last_gain;
        /* 10ms ramp */
        grad = ( gain - last_gain ) / (float) nFadeLength; /* slope between two consecutive gains, 480 samples length */
        for ( i = 0; i < ( nFadeLength ); i++ )
        {
            transport_channels_f[0][i] *= ( last_gain + i * grad );
            transport_channels_f[1][i] *= ( last_gain + i * grad );
        }
        for ( ; i < nSamples; i++ )
        {
            transport_channels_f[0][i] *= gain;
            transport_channels_f[1][i] *= gain;
        }
    }
    else
    {
        for ( i = 0; i < nSamples; i++ )
        {
            transport_channels_f[0][i] *= gain;
            transport_channels_f[1][i] *= gain;
        }
    }
    st_ivas->hDirAC->hParamIsm->last_dmx_gain = gain;

    return;
}
#endif

/*-------------------------------------------------------------------------*
 * ivas_ism_param_dec_render_sf()
 *
+7 −11
Original line number Diff line number Diff line
@@ -776,8 +776,8 @@ 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 API_5MS
                    v_multc( st_ivas->hTcBuffer->tc[0], pan_right, output[1], nSamplesRenderedLocal );
                    v_multc( st_ivas->hTcBuffer->tc[0], pan_left, output[0], nSamplesRenderedLocal );
                    v_multc( p_tc[0], pan_right, output[1], nSamplesRenderedLocal );
                    v_multc( p_tc[0], pan_left, output[0], nSamplesRenderedLocal );
#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 );
@@ -827,8 +827,8 @@ 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 API_5MS
                    v_multc( st_ivas->hTcBuffer->tc[0], pan_right, output[1], nSamplesRenderedLocal );
                    v_multc( st_ivas->hTcBuffer->tc[0], pan_left, output[0], nSamplesRenderedLocal );
                    v_multc( p_tc[0], pan_right, output[1], nSamplesRenderedLocal );
                    v_multc( p_tc[0], pan_left, output[0], nSamplesRenderedLocal );
#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 );
@@ -884,11 +884,6 @@ ivas_error ivas_jbm_dec_render(
                    ivas_binaural_cldfb_sf( st_ivas, *nSamplesRendered, p_output );
#endif
                }
#endif
#ifdef API_5MS
                {
                    st_ivas->hTcBuffer->subframes_rendered++;
                }
#endif
            }
        }
@@ -987,7 +982,7 @@ ivas_error ivas_jbm_dec_render(
                        return error;
                    }
#ifdef API_5MS
                    ivas_binaural_add_LFE( st_ivas, nSamplesRenderedLocal, st_ivas->hTcBuffer->tc, p_output );
                    ivas_binaural_add_LFE( st_ivas, nSamplesRenderedLocal, p_tc, p_output );
#else
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc, p_output );
#endif
@@ -1021,7 +1016,7 @@ ivas_error ivas_jbm_dec_render(
                        return error;
                    }
#ifdef API_5MS
                    ivas_binaural_add_LFE( st_ivas, nSamplesRenderedLocal, st_ivas->hTcBuffer->tc, p_output );
                    ivas_binaural_add_LFE( st_ivas, nSamplesRenderedLocal, p_tc, p_output );
#else
                ivas_binaural_add_LFE( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc, p_output );
#endif
@@ -2265,6 +2260,7 @@ void ivas_jbm_dec_copy_tc_no_tsm(
            cldfb_real_buffer = st_ivas->hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc;
            cldfb_imag_buffer = st_ivas->hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc;
            num_freq_bands = st_ivas->hDirAC->num_freq_bands;
            ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, tc );
        }
        else if ( st_ivas->ivas_format == MC_FORMAT )
        {