Commit 921fa531 authored by TYAGIRIS's avatar TYAGIRIS
Browse files

ISM SBA format at all bitrates

parent 518ed000
Loading
Loading
Loading
Loading
Loading
+99 −17
Original line number Diff line number Diff line
@@ -679,17 +679,24 @@ ivas_error ivas_dec(
#ifdef SBA_AND_OBJECTS
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        int16_t nchan_ism;
        int16_t nchan_ism, sba_ch_idx;

        set_s( nb_bits_metadata, 0, MAX_SCE + 1 );

#ifdef SBA_AND_OBJECTS
        nchan_ism = st_ivas->nchan_ism;
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            /* set ISM parameters and decode ISM metadata in OSBA format */
            if ( ( error = ivas_osba_ism_metadata_dec( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
#endif
            sba_ch_idx = st_ivas->nchan_ism;
        }
        else
        {
            nb_bits_metadata[1] += NO_BITS_MASA_ISM_NO_OBJ;
            sba_ch_idx = 0;
        }

        /* SBA metadata decoding */
        if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK )
@@ -697,21 +704,45 @@ ivas_error ivas_dec(
            return error;
        }

        st = st_ivas->hCPE[0]->hCoreCoder[0];
        if ( st_ivas->nchan_transport == CPE_CHANNELS && st_ivas->nCPE >= 1 )
        {
            st_ivas->hCPE[0]->element_brate = ivas_total_brate;
        }

        /* core-decoding of transport channels */
        if ( st_ivas->nSCE == 1 )
        {
            st = st_ivas->hSCE[0]->hCoreCoder[0];
            if ( ( error = ivas_sce_dec( st_ivas, 0, &output[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else if ( st_ivas->nCPE == 1 )
        {
            st = st_ivas->hCPE[0]->hCoreCoder[0];
            if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else if ( st_ivas->nCPE > 1 )
        {
            st = st_ivas->hCPE[0]->hCoreCoder[0];
            if ( ( error = ivas_mct_dec( st_ivas, output, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

#ifdef SBA_AND_OBJECTS
        if ( st_ivas->sba_dirac_stereo_flag )
        {
            ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, &output[st_ivas->nchan_ism], &output[st_ivas->nchan_ism], st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
            ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, &output[sba_ch_idx], &output[sba_ch_idx], st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );

            if ( st_ivas->hSpar->hPCA != NULL )
            {
                ivas_pca_dec( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &output[st_ivas->nchan_ism] );
                ivas_pca_dec( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &output[sba_ch_idx] );
            }

            ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi,
@@ -722,7 +753,7 @@ ivas_error ivas_dec(
#endif
                                                                           ) );

            ivas_sba_dirac_stereo_dec( st_ivas, &output[st_ivas->nchan_ism], output_frame, 0 );
            ivas_sba_dirac_stereo_dec( st_ivas, &output[sba_ch_idx], output_frame, 0 );
        }
#endif

@@ -732,9 +763,10 @@ ivas_error ivas_dec(
            hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
        }

        nchan_remapped = ivas_sba_remapTCs( &output[st_ivas->nchan_ism], st_ivas, output_frame );
        nchan_remapped = ivas_sba_remapTCs( &output[sba_ch_idx], st_ivas, output_frame );

#ifdef DEBUG_OSBA
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            int16_t nchan = st_ivas->nchan_transport + st_ivas->nchan_ism;
            for ( int t = 0; t < output_frame; t++ )
@@ -747,14 +779,64 @@ ivas_error ivas_dec(
            }
        }
#endif
        if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
        {
#ifdef VLBR_20MS_MD
            num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate,
                                                                    st_ivas->last_active_ivas_total_brate );
            ivas_sba_mix_matrix_determiner( st_ivas->hSpar, &output[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames );
#else
            ivas_sba_mix_matrix_determiner( st_ivas->hSpar, output, st_ivas->bfi, nchan_remapped, output_frame );
#endif
        }
        else if ( st_ivas->renderer_type != RENDERER_DISABLE )
        {
            ivas_spar_dec_agc_pca( st_ivas, &output[sba_ch_idx], output_frame );
        }

        if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
        if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
        {
#ifdef FIX_564
            /* loudness correction */
            ivas_dirac_dec_binaural_sba_gain( &output[sba_ch_idx], nchan_remapped, output_frame );
#else
            float gain;

            if ( nchan_remapped == 1 )
            {
                gain = 1.4454f;
            }
            else
            {
                gain = 1.3657f;
            }

            for ( n = 0; n < nchan_remapped; n++ )
            {
                v_multc( output[n], gain, output[n], output_frame );
            }
#endif
        }

        /* Loudspeakers, Ambisonics or Binaural rendering */
        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_binaural( st_ivas, st_ivas->hCombinedOrientationData, &output[sba_ch_idx], nchan_remapped );
        }
        else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
        {
            if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
            {
                if ( ( error = ivas_osba_dirac_td_binaural( st_ivas, output, output_frame ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else
            {
                ivas_sba_upmixer_renderer( st_ivas, &output[sba_ch_idx], output_frame );
            }
        }
#ifdef SBA_AND_OBJECTS
        else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_OSBA_STEREO || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) )
        {
+79 −34
Original line number Diff line number Diff line
@@ -423,32 +423,27 @@ ivas_error ivas_dec_setup(
            /* the number of objects is written at the end of the bitstream, in the SBA metadata */
            st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1;

            if ( ivas_total_brate < IVAS_24k4 || ivas_total_brate >= IVAS_256k )
            {
                /* read Ambisonic (SBA) planar flag */
                st_ivas->sba_planar = st_ivas->bit_stream[num_bits_read];
                num_bits_read += SBA_PLANAR_BITS;
            }

            /* read Ambisonic (SBA) order */
            if ( ivas_total_brate >= IVAS_256k )
            {
            st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1];
            st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read];
                st_ivas->ism_mode = ISM_SBA_MODE_DISC;
            }
            else
            num_bits_read += SBA_ORDER_BITS;

            /* read Ambisonic (SBA) order */
            if ( ivas_total_brate < IVAS_256k )
            {
                st_ivas->sba_order = 3;

                st_ivas->nchan_ism = st_ivas->bit_stream[num_bits_read + 1];
                st_ivas->nchan_ism += 2 * st_ivas->bit_stream[num_bits_read];
                st_ivas->nchan_ism++;
                st_ivas->ivas_format = SBA_FORMAT;
                st_ivas->ism_mode = ISM_MODE_NONE;
            }


            /* set Ambisonic (SBA) order used for analysis and coding */
            st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order );

            num_bits_read += SBA_ORDER_BITS;
            if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 )
            {
                if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
@@ -474,9 +469,15 @@ ivas_error ivas_dec_setup(
                st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1;
            }
#endif

            if ( ivas_total_brate >= IVAS_256k )
            {
                st_ivas->ism_mode = ISM_SBA_MODE_DISC;
            }
            else
            {
                st_ivas->ism_mode = ISM_MODE_NONE;
            }
        }
#endif
        else if ( st_ivas->ivas_format == MC_FORMAT )
        {
@@ -748,6 +749,17 @@ static ivas_error ivas_read_format(
                else
                {
                    st_ivas->ivas_format = SBA_FORMAT;
#ifdef SBA_AND_OBJECTS
                    /* read Ambisonic (SBA) planar flag */
                    st_ivas->sba_planar = st_ivas->bit_stream[( *num_bits_read ) + 1];
                    /* read Ambisonic (SBA) order */
                    st_ivas->sba_order = st_ivas->bit_stream[( *num_bits_read ) + 2 + SBA_PLANAR_BITS];
                    st_ivas->sba_order += 2 * st_ivas->bit_stream[( *num_bits_read ) + 1 + SBA_PLANAR_BITS];
                    if ( st_ivas->sba_order == 0 )
                    {
                        st_ivas->ivas_format = SBA_ISM_FORMAT;
                    }
#endif
                }
                ( *num_bits_read )++;

@@ -863,9 +875,16 @@ int16_t getNumChanSynthesis(
    }
#ifdef SBA_AND_OBJECTS
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            n = st_ivas->nchan_transport + st_ivas->nchan_ism;
        }
        else
        {
            n = st_ivas->nchan_transport;
        }
    }
#endif
    return n;
}
@@ -1485,9 +1504,21 @@ ivas_error ivas_init_decoder(
        }
        st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );

        st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1;
        for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
        {
            if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] );
        }

        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1;
            st_ivas->element_mode_init = IVAS_CPE_MDCT;
        }

        for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
        {
@@ -1503,25 +1534,36 @@ ivas_error ivas_init_decoder(
        }

#ifdef OSBA_BR_SWITCHING
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            st_ivas->nchan_transport += st_ivas->nchan_ism;
        }
#endif
        if ( st_ivas->nCPE > 1 )
        {
            if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK )
            {
                return error;
            }

        /* set CNA/CNG flags */
        ivas_sba_set_cna_cng_flag( st_ivas );
            if ( ( error = ivas_masa_ism_data_open( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }


        /* set CNA/CNG flags */
        ivas_sba_set_cna_cng_flag( st_ivas );
    }
#endif
#ifdef MASA_AND_OBJECTS
    else if ( st_ivas->ivas_format == MASA_ISM_FORMAT )
@@ -2051,12 +2093,15 @@ ivas_error ivas_init_decoder(
                return error;
            }
        }
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */
            if ( ( error = ivas_sba_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
    }
#endif

    /*-----------------------------------------------------------------*
+85 −69
Original line number Diff line number Diff line
@@ -135,14 +135,26 @@ ivas_error ivas_sba_dec_reconfigure(
    ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
    nchan_hp20_old = getNumChanSynthesis( st_ivas );
#ifdef OSBA_BR_SWITCHING
    if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ivas_format == SBA_ISM_FORMAT )
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        if ( ivas_total_brate >= IVAS_256k )
        {
            st_ivas->ism_mode = ISM_SBA_MODE_DISC;
        }
        else
        {
            st_ivas->ism_mode = ISM_MODE_NONE;
        }
        if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            nchan_hp20_old = st_ivas->nchan_transport;
        }
    else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ivas_format == SBA_FORMAT )
        else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE )
        {
            nchan_hp20_old += st_ivas->nchan_ism;
        }
    }

#endif
    nSCE_old = st_ivas->nSCE;
    nCPE_old = st_ivas->nCPE;
@@ -327,7 +339,9 @@ ivas_error ivas_sba_dec_reconfigure(
     * Allocate, initialize, and configure SCE/CPE/MCT handles
     *-----------------------------------------------------------------*/
#ifdef OSBA_BR_SWITCHING
    if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ivas_format == SBA_ISM_FORMAT )
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            int32_t temp_brate[MAX_SCE];
            st_ivas->ism_mode = ISM_SBA_MODE_DISC;
@@ -376,7 +390,7 @@ ivas_error ivas_sba_dec_reconfigure(
            st_ivas->nchan_transport += st_ivas->nchan_ism;
            st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1;
        }
    else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ivas_format == SBA_FORMAT )
        else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE )
        {
            /* ISM renderer handle */
            if ( st_ivas->hIsmRendererData != NULL )
@@ -404,14 +418,16 @@ ivas_error ivas_sba_dec_reconfigure(
            nchan_transport_old += st_ivas->nchan_ism;
            st_ivas->ism_mode = ISM_MODE_NONE;
        }
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
        else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
        {
            st_ivas->nchan_transport += st_ivas->nchan_ism;
            st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1;
            nCPE_old = st_ivas->nCPE;
            nchan_transport_old = st_ivas->nchan_transport;
        }
    }
#endif

    if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
    {
        return error;
+6 −0
Original line number Diff line number Diff line
@@ -165,6 +165,12 @@ ivas_error ivas_sce_dec(
        {
            st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC );
        }
#ifdef SBA_AND_OBJECTS
        if ( st_ivas->ism_mode == ISM_MODE_NONE && st_ivas->ivas_format == SBA_ISM_FORMAT )
        {
            st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC );
        }
#endif
        else
        {
            st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal;
+2 −2
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ ivas_error ivas_spar_dec(
    next_bit_pos_orig = st0->next_bit_pos;

#ifdef SBA_AND_OBJECTS
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
#ifndef SBA_AND_OBJECTS
        last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
@@ -352,7 +352,7 @@ ivas_error ivas_spar_dec(
    }

#ifdef SBA_AND_OBJECTS
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC )
    if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ) - nb_bits_read[1];
    }
Loading