Commit f1f85f75 authored by Dominik Weckbecker's avatar Dominik Weckbecker 💬
Browse files

improve readability of ivas_jbm_dec.c

parent 7b976c57
Loading
Loading
Loading
Loading
Loading
+189 −188
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@ ivas_error ivas_jbm_dec_tc(
    }
    else if ( st_ivas->ivas_format == ISM_FORMAT )
    {

        /* Metadata decoding and configuration */
        if ( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA )
        {
@@ -921,6 +920,7 @@ void ivas_jbm_dec_feed_tc_to_renderer(
        if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT || st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

            if ( st_ivas->hDecoderConfig->Opt_tsm )
            {
                ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
@@ -998,191 +998,6 @@ void ivas_jbm_dec_feed_tc_to_renderer(
    return;
}

#ifdef OBJ_EDITING_API
/*--------------------------------------------------------------------------*
 * ivas_jbm_dec_prepare_renderer()
 *
 * prepare IVAS JBM renderer routine
 *--------------------------------------------------------------------------*/

void ivas_jbm_dec_prepare_renderer(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure                                      */
)
{
    int16_t n, n_render_timeslots;

    push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );

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

    if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
    {
        ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

        if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->hDecoderConfig->Opt_tsm )
        {
            ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
        }
    }
    else if ( st_ivas->ivas_format == STEREO_FORMAT )
    {
        ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    }
    else if ( st_ivas->ivas_format == ISM_FORMAT )
    {
        /* Rendering */
        if ( st_ivas->ism_mode == ISM_MODE_PARAM )
        {
#ifdef OBJ_EDITING_PARAMISM

#else
            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
            {
                ivas_dirac_dec_set_md_map( st_ivas, n_render_timeslots );

                ivas_param_ism_params_to_masa_param_mapping( st_ivas );
            }
            else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
            {
                ivas_param_ism_dec_prepare_renderer( st_ivas, n_render_timeslots );
            }
#endif
        }
        else /* ISM_MODE_DISC */
        {
            ivas_ism_dec_digest_tc( st_ivas );
        }
    }
    else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
    {
        ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    }
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {

        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            ivas_ism_dec_digest_tc( st_ivas );

            /* delay the objects here for all renderers where it is needed */
            if (
#ifdef SPLIT_REND_WITH_HEAD_ROT
                (
#endif
                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
                    st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
                    st_ivas->renderer_type == RENDERER_OSBA_LS ||
                    st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    ) &&
                ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
#endif
            )
            {
                for ( n = 0; n < st_ivas->nchan_ism; n++ )
                {
                    delay_signal( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size );
                }
            }

            if ( !st_ivas->sba_dirac_stereo_flag )
            {
                if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
                {
                    n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
                }

                ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
            }
        }
        else
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
    }
    else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
    {
        if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT || st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

            if ( st_ivas->hDecoderConfig->Opt_tsm )
            {
                ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
            }
        }
        else
        {
            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
            {
                n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
            }

            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );

            if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
            {
                ivas_ism_dec_digest_tc( st_ivas );
            }

            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_DIRAC )
            {
                int16_t num_objects;
                /* Delay the signal to match CLDFB delay. Delay the whole buffer. */
                num_objects = 0;
                if ( ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC )
                {
                    num_objects = 1;
                }
                else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
                {
                    num_objects = st_ivas->nchan_ism;
                }
                for ( n = 0; n < num_objects; n++ )
                {
                    if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
                    {
                        v_multc( st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN, st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available );
                    }
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    if ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
                    {
#endif
                        delay_signal( st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size );
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    }
#endif
                }
            }
        }
    }
    else if ( st_ivas->ivas_format == MC_FORMAT )
    {
        if ( st_ivas->mc_mode == MC_MODE_MCT )
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
        {
            ivas_mc_paramupmix_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
        {
            ivas_param_mc_dec_prepare_renderer( st_ivas, (uint8_t) n_render_timeslots );
        }
        else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
        {
            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
    }

    pop_wmops();
    return;
}
#endif

/*--------------------------------------------------------------------------*
 * ivas_dec_render()
@@ -3280,3 +3095,189 @@ void ivas_jbm_masa_sf_to_sf_map(

    return;
}

#ifdef OBJ_EDITING_API
/*--------------------------------------------------------------------------*
 * ivas_jbm_dec_prepare_renderer()
 *
 * prepare IVAS JBM renderer routine
 *--------------------------------------------------------------------------*/

void ivas_jbm_dec_prepare_renderer(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure                                      */
)
{
    int16_t n, n_render_timeslots;

    push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );

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

    if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER )
    {
        ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

        if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL && st_ivas->hDecoderConfig->Opt_tsm )
        {
            ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
        }
    }
    else if ( st_ivas->ivas_format == STEREO_FORMAT )
    {
        ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
    }
    else if ( st_ivas->ivas_format == ISM_FORMAT )
    {
        /* Rendering */
        if ( st_ivas->ism_mode == ISM_MODE_PARAM )
        {
#ifdef OBJ_EDITING_PARAMISM

#else
            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
            {
                ivas_dirac_dec_set_md_map( st_ivas, n_render_timeslots );

                ivas_param_ism_params_to_masa_param_mapping( st_ivas );
            }
            else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC )
            {
                ivas_param_ism_dec_prepare_renderer( st_ivas, n_render_timeslots );
            }
#endif
        }
        else /* ISM_MODE_DISC */
        {
            ivas_ism_dec_digest_tc( st_ivas );
        }
    }
    else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
    {
        ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
    }
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {

        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            ivas_ism_dec_digest_tc( st_ivas );

            /* delay the objects here for all renderers where it is needed */
            if (
#ifdef SPLIT_REND_WITH_HEAD_ROT
                (
#endif
                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ||
                    st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ||
                    st_ivas->renderer_type == RENDERER_OSBA_AMBI ||
                    st_ivas->renderer_type == RENDERER_OSBA_LS ||
                    st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    ) &&
                ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
#endif
            )
            {
                for ( n = 0; n < st_ivas->nchan_ism; n++ )
                {
                    delay_signal( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer[n], st_ivas->hSbaIsmData->delayBuffer_size );
                }
            }

            if ( !st_ivas->sba_dirac_stereo_flag )
            {
                if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
                {
                    n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
                }

                ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
            }
        }
        else
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
    }
    else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
    {
        if ( st_ivas->renderer_type == RENDERER_OMASA_MIX_EXT || st_ivas->renderer_type == RENDERER_OMASA_OBJECT_EXT )
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );

            if ( st_ivas->hDecoderConfig->Opt_tsm )
            {
                ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
            }
        }
        else
        {
            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
            {
                n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size );
            }

            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );

            if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
            {
                ivas_ism_dec_digest_tc( st_ivas );
            }

            if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_DIRAC )
            {
                int16_t num_objects;
                /* Delay the signal to match CLDFB delay. Delay the whole buffer. */
                num_objects = 0;
                if ( ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC )
                {
                    num_objects = 1;
                }
                else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
                {
                    num_objects = st_ivas->nchan_ism;
                }
                for ( n = 0; n < num_objects; n++ )
                {
                    if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
                    {
                        v_multc( st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN, st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available );
                    }
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    if ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
                    {
#endif
                        delay_signal( st_ivas->hTcBuffer->tc[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size );
#ifdef SPLIT_REND_WITH_HEAD_ROT
                    }
#endif
                }
            }
        }
    }
    else if ( st_ivas->ivas_format == MC_FORMAT )
    {
        if ( st_ivas->mc_mode == MC_MODE_MCT )
        {
            ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
        {
            ivas_mc_paramupmix_dec_digest_tc( st_ivas, (uint8_t) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
        else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
        {
            ivas_param_mc_dec_prepare_renderer( st_ivas, (uint8_t) n_render_timeslots );
        }
        else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
        {
            ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
        }
    }

    pop_wmops();
    return;
}
#endif