Commit fdfb89b8 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Fixes rate switching in OMASA JBM.

parent ea5e4a39
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -4963,7 +4963,13 @@ void ivas_masa_enc_reconfigure(
);

ivas_error ivas_masa_dec_reconfigure(
#ifdef MASA_AND_OBJECTS
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                          */
    uint16_t *nSamplesRendered,                                 /* o  : number of samples flushed from the previous frame (JBM) */
    int16_t *data                                               /* o  : flushed PCM samples                             */
#else
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                          */
#endif
);

ivas_error ivas_masa_encode(
@@ -5655,7 +5661,13 @@ ivas_error ivas_omasa_enc_config(
);

ivas_error ivas_omasa_dec_config(
#ifdef MASA_AND_OBJECTS
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder structure                  */
    uint16_t *nSamplesRendered,                                 /* o  : number of samples flushed from the previous frame (JBM) */
    int16_t *data                                               /* o  : flushed PCM samples                     */
#else
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                  */
#endif
);

void ivas_omasa_set_config(
+6 −2
Original line number Diff line number Diff line
@@ -326,7 +326,11 @@ ivas_error ivas_dec_setup(
                        }
                        else
                        {
#ifdef MASA_AND_OBJECTS
                            if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered ,data ) ) != IVAS_ERR_OK )
#else
                            if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
#endif
                            {
                                return error;
                            }
@@ -335,7 +339,7 @@ ivas_error ivas_dec_setup(
                    }
                    else
                    {
                        if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK )
                        if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK )
                        {
                            return error;
                        }
@@ -358,7 +362,7 @@ ivas_error ivas_dec_setup(
                /* reconfigure in case a change of operation mode is detected */
                if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) )
                {
                    if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK )
                    if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
+32 −0
Original line number Diff line number Diff line
@@ -1319,6 +1319,38 @@ ivas_error ivas_jbm_dec_flush_renderer(
                return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" );
            }
        }
#ifdef MASA_AND_OBJECTS
        else if ( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MASA_FORMAT )
        {
            if ( ism_mode_old == ISM_MASA_MODE_DISC )
            {
                float *tc_local[MAX_TRANSPORT_CHANNELS];

                for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
                {
                    tc_local[ch_idx] = &st_ivas->hTcBuffer->tc[ch_idx + 2][hTcBuffer->n_samples_rendered];
                    mvr2r( st_ivas->hMasaIsmData->delayBuffer[ch_idx], tc_local[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size );
                }

                if ( st_ivas->nchan_ism > 0 )
                {
                    if ( ( ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
                }
                else
                {
                    for ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ )
                    {
                        set_zero( p_output[ch_idx], (int16_t) (*nSamplesRendered) );
                    }
                    st_ivas->hTcBuffer->slots_rendered += 1;
                    st_ivas->hTcBuffer->subframes_rendered += 1;
                }
            }
        }
#endif
        else
        {
            return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" );
+83 −0
Original line number Diff line number Diff line
@@ -1282,7 +1282,13 @@ static int16_t decode_lfe_to_total_energy_ratio(
 *-------------------------------------------------------------------*/

ivas_error ivas_masa_dec_reconfigure(
#ifdef MASA_AND_OBJECTS
    Decoder_Struct *st_ivas,    /* i/o: IVAS decoder structure */
    uint16_t *nSamplesRendered, /* o  : number of samples flushed from the previous frame (JBM) */
    int16_t *data               /* o  : flushed PCM samples    */
#else
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
#endif
)
{
    int16_t n, tmp, num_bits;
@@ -1304,6 +1310,18 @@ ivas_error ivas_masa_dec_reconfigure(
    ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
    last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate;

#ifdef MASA_AND_OBJECTS
    if ( st_ivas->hDecoderConfig->voip_active == 1 )
    {
        if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity )
        {
            mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
            st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
            st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
        }
    }
#endif

    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );

    /* renderer might have changed, reselect */
@@ -1323,7 +1341,11 @@ ivas_error ivas_masa_dec_reconfigure(
            return error;
        }
    }
#ifdef MASA_AND_OBJECTS
    else if ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX )
#else
    else if ( st_ivas->renderer_type == RENDERER_DISABLE )
#endif
    {
        if ( st_ivas->hDirAC != NULL )
        {
@@ -1505,23 +1527,84 @@ ivas_error ivas_masa_dec_reconfigure(
        int16_t tc_nchan_to_allocate;
        int16_t tc_nchan_transport;
        TC_BUFFER_MODE buffer_mode_new;
#ifdef MASA_AND_OBJECTS
        int16_t n_samples_granularity;

        n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
#endif
        buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas );
        tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels( st_ivas );

        tc_nchan_to_allocate = tc_nchan_transport;
        if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
        {
#ifdef MASA_AND_OBJECTS
            if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
            {
                tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2;
            }
            else
            {
                tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS;
            }

            if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
            {
                n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */

                if ( n_samples_granularity > st_ivas->hTcBuffer->n_samples_granularity )
                {
                    if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
                }
            }
            else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC )
            {
                if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity )
                {
                    if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK )
                    {
                        return error;
                    }
                }
            }
#else
            tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS;
#endif
        }

        if ( tc_nchan_transport != st_ivas->hTcBuffer->nchan_transport_jbm || tc_nchan_to_allocate != st_ivas->hTcBuffer->nchan_transport_internal || buffer_mode_new != st_ivas->hTcBuffer->tc_buffer_mode )
        {
#ifdef MASA_AND_OBJECTS
            if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK )
#else
            if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK )
#endif
            {
                return error;
            }
        }

#ifdef MASA_AND_OBJECTS
        if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity )
        {
            mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS );
            st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
            st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
        }

        if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC )
        {
            int16_t granularityMultiplier = st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size;

            for ( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ )
            {
                st_ivas->hSpatParamRendCom->subframe_nbslots[n] = st_ivas->hTcBuffer->subframe_nbslots[n] * granularityMultiplier;
            }
        }
#endif
    }

    return error;
+4 −2
Original line number Diff line number Diff line
@@ -151,7 +151,9 @@ void ivas_omasa_data_close(
 *--------------------------------------------------------------------------*/

ivas_error ivas_omasa_dec_config(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
    Decoder_Struct *st_ivas,    /* i/o: IVAS decoder structure */
    uint16_t *nSamplesRendered, /* o  : number of samples flushed from the previous frame (JBM) */
    int16_t *data               /* o  : flushed PCM samples    */
)
{
    int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD;
@@ -192,7 +194,7 @@ ivas_error ivas_omasa_dec_config(
    {
        st_ivas->hCPE[0]->nchan_out = 1;
    }
    else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
    else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK )
    {
        return error;
    }