Commit b536f4d8 authored by vaclav's avatar vaclav
Browse files

ivas_dec_feed_tc_to_renderer() changes for ParamISM

parent 97428651
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -840,12 +840,14 @@ int16_t ivas_dec_get_num_tc_channels(
    Decoder_Struct *st_ivas                                     /* i  : IVAS decoder handle                                         */
);

void ivas_dec_copy_tc_no_tsm( 
#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS
void ivas_jbm_dec_copy_tc_no_tsm( 
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                                         */
    float *tc[],                                                /* i  : transport channels                                          */
    const int16_t output_frame                                  /* i  : output frame size                                           */
);

#endif
void ivas_dec_get_md_map_even_spacing(
    const int16_t len,                                          /* i  : length of the modefied frames in metadata slots             */
    const int16_t subframe_len,                                 /* i  : default length of a subframe                                */
+8 −0
Original line number Diff line number Diff line
@@ -148,12 +148,20 @@ uint32_t ivas_syn_output(
}


#ifdef UNIFIED_DECODING_PATHS_LEFTOVERS
/*-------------------------------------------------------------------*
 * ivas_syn_output_f()
 *
 * Output IVAS synthesis signal into a linear buffer
 *-------------------------------------------------------------------*/
#else
/*-------------------------------------------------------------------*
 * ivas_syn_output_f()
 *
 * Output ivas synthesis signal with compensation for saturation
 * returns number of clipped samples
 *-------------------------------------------------------------------*/
#endif

/*! r: number of clipped samples */
void ivas_syn_output_f(
+1 −1
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@
/*#define FIX_I4_OL_PITCH*/                             /* fix open-loop pitch used for EVS core switching */
#define TMP_FIX_1119_SPLIT_RENDERING_VOIP               /* FhG: Add error check for unsupported config: split rendering with VoIP mode */
#define FIX_1209_SID_SIGNALING                          /* VA: issue 1209: remove dead code in IVAS SID signaling */

#define UNIFIED_DECODING_PATHS_LEFTOVERS                /* VA: issue 880: remove leftovers ater NONBE_UNIFIED_DECODING_PATHS */

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

+218 −18
Original line number Diff line number Diff line
@@ -50,8 +50,10 @@
 * Local function prototypes
 *-----------------------------------------------------------------------*/

static void ivas_dec_copy_tc( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *data, float *tc_digest_f[] );
#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS
static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *data, float *tc_digest_f[] );

#endif
static void ivas_dec_tc_buffer_playout( Decoder_Struct *st_ivas, const uint16_t nSamplesAsked, uint16_t *nSamplesRendered, float *output[] );

static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas );
@@ -730,11 +732,13 @@ ivas_error ivas_dec_tc(
    {
        ivas_syn_output_f( p_output, output_frame, nchan_out, data );
    }
#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS
    else
    {
        /* directly copy to TC buffers */
        ivas_dec_copy_tc_no_tsm( st_ivas, p_output, output_frame );
        /* directly copy to tc buffers */
        ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, output_frame );
    }
#endif

    /*----------------------------------------------------------------*
     * Common updates
@@ -772,6 +776,7 @@ ivas_error ivas_dec_tc(
}


#ifdef UNIFIED_DECODING_PATHS_LEFTOVERS
/*--------------------------------------------------------------------------*
 * ivas_dec_feed_tc_to_renderer()
 *
@@ -787,9 +792,15 @@ void ivas_dec_feed_tc_to_renderer(
{
    float data_f[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k]; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */
    float *p_data_f[MAX_CLDFB_DIGEST_CHANNELS];
    int16_t n, n_render_timeslots;
    int16_t n, n_render_timeslots, n_ch_cldfb;
    int16_t ch, output_frame;
    DECODER_TC_BUFFER_HANDLE hTcBuffer;
    float *cldfb_real_buffer;
    float *cldfb_imag_buffer;
    int16_t cldfb_ch, slot_idx, num_freq_bands;

    hTcBuffer = st_ivas->hTcBuffer;

    push_wmops( "ivas_dec_feed_tc_to_renderer" );
    for ( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ )
    {
        p_data_f[n] = &data_f[n][0];
@@ -805,13 +816,196 @@ void ivas_dec_feed_tc_to_renderer(

    if ( st_ivas->hDecoderConfig->Opt_tsm )
    {
        ivas_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data, p_data_f );
        int16_t n_samples_still_available, m;
        int16_t n_ch_full_copy;
        int16_t n_ch_res_copy;

        n_samples_still_available = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_rendered;
        hTcBuffer->n_samples_buffered = n_samples_still_available + nSamplesForRendering + hTcBuffer->n_samples_discard;
        hTcBuffer->n_samples_available = hTcBuffer->n_samples_granularity * ( hTcBuffer->n_samples_buffered / hTcBuffer->n_samples_granularity );
        *nSamplesResidual = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_available;
        n_ch_full_copy = min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
        n_ch_res_copy = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
        n_ch_cldfb = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;

        for ( ch = 0; ch < n_ch_full_copy; ch++ )
        {
            set_zero( hTcBuffer->tc[ch], hTcBuffer->n_samples_discard );
            mvr2r( hTcBuffer->tc[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
            for ( m = 0; m < nSamplesForRendering; m++ )
            {
                hTcBuffer->tc[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_rend + ch];
            }
        }

        if ( n_ch_res_copy > 0 )
        {
            for ( ; ch < hTcBuffer->nchan_transport_rend; ch++ )
            {
                mvr2r( hTcBuffer->tc[ch], p_data_f[ch], n_samples_still_available );
                for ( m = 0; m < nSamplesForRendering; m++ )
                {
                    p_data_f[ch][n_samples_still_available + m] = data[m * hTcBuffer->nchan_transport_rend + ch];
                }
                mvr2r( p_data_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc[ch], *nSamplesResidual );
            }
        }

        n_render_timeslots = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity;

        //ivas_param_ism_dec_digest_tc( st_ivas, n_render_timeslots, p_data_f );

        /* CLDFB analysis for ParamMC/ParamISM */
        if ( n_ch_cldfb > 0 )
        {
            cldfb_real_buffer = NULL;
            cldfb_imag_buffer = NULL;
            num_freq_bands = 0;

            if ( st_ivas->ivas_format == ISM_FORMAT )
            {
                cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
                cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
                num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
                //ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, st_ivas->p_output_f );
            }
            else if ( st_ivas->ivas_format == MC_FORMAT )
            {
                cldfb_real_buffer = st_ivas->hParamMC->Cldfb_RealBuffer_tc;
                cldfb_imag_buffer = st_ivas->hParamMC->Cldfb_ImagBuffer_tc;
                num_freq_bands = st_ivas->hParamMC->num_freq_bands;
            }
#ifdef DEBUGGING
            else
            {
                assert( 0 && "Residual (direct CLDFB transport channels) only possible for ParamMC/ParamISM!" );
            }
#endif

            output_frame = n_render_timeslots * num_freq_bands;

            //if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) )
            if ( st_ivas->ivas_format == ISM_FORMAT )
            {
                ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, p_data_f );

                for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
                {
                    /* CLDFB Analysis */
                    for ( slot_idx = 0; slot_idx < n_render_timeslots; slot_idx++ )
                    {
                        cldfbAnalysis_ts( &( p_data_f[ch][num_freq_bands * slot_idx] ),
                                          &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
                                          &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
                                          num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] );
                    }
                }
            }
            else if ( st_ivas->ivas_format == MC_FORMAT )
            {
                if ( st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_RENDERER )
                {
                    ivas_param_mc_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, p_data_f );
                }
            }
        }
    }
    else
    {
        output_frame = nSamplesForRendering;

        hTcBuffer->n_samples_buffered = output_frame;
        hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
        n_ch_cldfb = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;

        /* CLDFB ana for ParamMC/ParamISM */
        if ( n_ch_cldfb > 0 )
        {
            cldfb_real_buffer = NULL;
            cldfb_imag_buffer = NULL;
            num_freq_bands = 0;

            if ( st_ivas->ivas_format == ISM_FORMAT )
            {
                cldfb_real_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc;
                cldfb_imag_buffer = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc;
                num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
                ivas_ism_param_dec_tc_gain_ajust( st_ivas, output_frame, output_frame / 2, st_ivas->p_output_f );
            }
            else if ( st_ivas->ivas_format == MC_FORMAT )
            {
                cldfb_real_buffer = st_ivas->hParamMC->Cldfb_RealBuffer_tc;
                cldfb_imag_buffer = st_ivas->hParamMC->Cldfb_ImagBuffer_tc;
                num_freq_bands = st_ivas->hParamMC->num_freq_bands;
            }
#ifdef DEBUGGING
            else
            {
                assert( 0 && "Residual (direct CLDFB transport channels) only possible for ParamMC/ParamISM!" );
            }
#endif

            /* CLDFB Analysis*/
            for ( ch = 0, cldfb_ch = 0; cldfb_ch < n_ch_cldfb; cldfb_ch++, ch++ )
            {
                for ( slot_idx = 0; slot_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; slot_idx++ )
                {
                    cldfbAnalysis_ts( &( st_ivas->p_output_f[ch][num_freq_bands * slot_idx] ),
                                      &cldfb_real_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
                                      &cldfb_imag_buffer[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
                                      num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch] );
                }
            }
        }

        *nSamplesResidual = 0;
    }

    hTcBuffer->n_samples_rendered = 0;
    hTcBuffer->subframes_rendered = 0;

    return;
}
#else
/*--------------------------------------------------------------------------*
 * ivas_dec_feed_tc_to_renderer()
 *
 * Feed decoded transport channels and metadata to the IVAS JBM renderer routine
 *--------------------------------------------------------------------------*/

void ivas_dec_feed_tc_to_renderer(
    Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                          */
    const int16_t nSamplesForRendering, /* i  : number of TC samples available for rendering    */
    int16_t *nSamplesResidual,          /* o  : number of samples not fitting into the renderer grid and buffer for the next call*/
    float *data                         /* i  : transport channels                              */
)
{
    float data_f[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k]; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */
    float *p_data_f[MAX_CLDFB_DIGEST_CHANNELS];
    int16_t n, n_render_timeslots;

    push_wmops( "ivas_jbm_dec_feed_tc_to_renderer" );
    for ( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ )
    {
        p_data_f[n] = &data_f[n][0];
    }

    if ( !st_ivas->hDecoderConfig->Opt_tsm )
    {
        for ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
        {
            st_ivas->hTcBuffer->tc[n] = st_ivas->p_output_f[n]; /* note: buffers needed in the TD decorellator */
        }
    }

    if ( st_ivas->hDecoderConfig->Opt_tsm )
    {
        ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data, p_data_f );
    }
    else
    {
        *nSamplesResidual = 0;
    }
    n_render_timeslots = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity;

    if ( st_ivas->ivas_format == ISM_FORMAT )
@@ -836,6 +1030,7 @@ void ivas_dec_feed_tc_to_renderer(
    pop_wmops();
    return;
}
#endif


/*--------------------------------------------------------------------------*
@@ -2010,15 +2205,16 @@ int16_t ivas_dec_get_num_tc_channels(
    return num_tc;
}

#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS

/*--------------------------------------------------------------------------*
 * ivas_dec_copy_tc()
 * ivas_jbm_dec_copy_tc()
 *
 * Copy interleaved transport chnannels to the correct buffers, update the TC
 * buffer handle
 *--------------------------------------------------------------------------*/

static void ivas_dec_copy_tc(
static void ivas_jbm_dec_copy_tc(
    Decoder_Struct *st_ivas,            /* i/o: IVAS decoder structure                                 */
    const int16_t nSamplesForRendering, /* i  : number of samples to digest                            */
    int16_t *nSamplesResidual,          /* o  : number of samples that will be left for the next frame */
@@ -2037,8 +2233,8 @@ static void ivas_dec_copy_tc(
    hTcBuffer->n_samples_buffered = n_samples_still_available + nSamplesForRendering + hTcBuffer->n_samples_discard;
    hTcBuffer->n_samples_available = hTcBuffer->n_samples_granularity * ( hTcBuffer->n_samples_buffered / hTcBuffer->n_samples_granularity );
    *nSamplesResidual = hTcBuffer->n_samples_buffered - hTcBuffer->n_samples_available;
    n_ch_full_copy = min( hTcBuffer->nchan_transport_rend, hTcBuffer->nchan_buffer_full );
    n_ch_res_copy = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
    n_ch_full_copy = min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
    n_ch_res_copy = hTcBuffer->nchan_transport_jbm - hTcBuffer->nchan_buffer_full;

    for ( ch = 0; ch < n_ch_full_copy; ch++ )
    {
@@ -2046,18 +2242,18 @@ static void ivas_dec_copy_tc(
        mvr2r( hTcBuffer->tc[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
        for ( m = 0; m < nSamplesForRendering; m++ )
        {
            hTcBuffer->tc[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_rend + ch];
            hTcBuffer->tc[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch];
        }
    }

    if ( n_ch_res_copy > 0 )
    {
        for ( ; ch < hTcBuffer->nchan_transport_rend; ch++ )
        for ( ; ch < hTcBuffer->nchan_transport_jbm; ch++ )
        {
            mvr2r( hTcBuffer->tc[ch], tc_digest_f[ch], n_samples_still_available );
            for ( m = 0; m < nSamplesForRendering; m++ )
            {
                tc_digest_f[ch][n_samples_still_available + m] = data[m * hTcBuffer->nchan_transport_rend + ch];
                tc_digest_f[ch][n_samples_still_available + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch];
            }
            mvr2r( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc[ch], *nSamplesResidual );
        }
@@ -2069,6 +2265,7 @@ static void ivas_dec_copy_tc(
    return;
}

#endif

/*--------------------------------------------------------------------------*
 * ivas_dec_get_render_granularity()
@@ -2574,14 +2771,15 @@ TC_BUFFER_MODE ivas_dec_get_tc_buffer_mode(
    return buffer_mode;
}

#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS

/*--------------------------------------------------------------------------*
 * ivas_dec_copy_tc_no_tsm()
 * ivas_jbm_dec_copy_tc_no_tsm()
 *
 *
 * Copy to TC handle in non-JBM processing
 *--------------------------------------------------------------------------*/

void ivas_dec_copy_tc_no_tsm(
void ivas_jbm_dec_copy_tc_no_tsm(
    Decoder_Struct *st_ivas,   /* i/o: IVAS decoder handle      */
    float *tc[],               /* i  : transport channels       */
    const int16_t output_frame /* i  : output frame size        */
@@ -2594,7 +2792,7 @@ void ivas_dec_copy_tc_no_tsm(
    hTcBuffer = st_ivas->hTcBuffer;
    hTcBuffer->n_samples_buffered = output_frame;
    hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
    n_ch_cldfb = hTcBuffer->nchan_transport_rend - hTcBuffer->nchan_buffer_full;
    n_ch_cldfb = hTcBuffer->nchan_transport_jbm - hTcBuffer->nchan_buffer_full;

#ifdef DEBUGGING
    assert( st_ivas->hDecoderConfig->Opt_tsm == 0 );
@@ -2642,13 +2840,13 @@ void ivas_dec_copy_tc_no_tsm(
            }
        }
    }

    hTcBuffer->n_samples_rendered = 0;
    hTcBuffer->subframes_rendered = 0;

    return;
}

#endif

/*--------------------------------------------------------------------------*
 * ivas_jbm_dec_metadata_open()
@@ -2660,10 +2858,12 @@ ivas_error ivas_jbm_dec_metadata_open(
    Decoder_Struct *st_ivas )
{
    JBM_METADATA_HANDLE hJbmMetadata;

    if ( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL )
    {
        return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) );
    }

    hJbmMetadata->sf_write_idx = 0;
    hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;

+5 −1
Original line number Diff line number Diff line
@@ -4321,11 +4321,15 @@ static ivas_error evs_dec_main(
        v_multc( p_output[0], mixer_left, p_output[0], nOutSamples );
    }

#ifndef UNIFIED_DECODING_PATHS_LEFTOVERS
    if ( !st_ivas->hDecoderConfig->Opt_tsm )
    {
        ivas_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples );
        ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples );
    }
#else
    else if ( floatBuf != NULL )
#endif
    if ( floatBuf != NULL )
    {
        /* BE workaround */
        int16_t pcm_buf_local[L_FRAME48k * MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];