Commit 8075eabd authored by fotopoulou's avatar fotopoulou
Browse files

enable decoder functionality . Core cofing functionality working as expected

parent 7dcdd71b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -2759,6 +2759,17 @@ ivas_error preview_indices(

            ivas_sba_config( total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &( st_ivas->nSCE ), &( st_ivas->nCPE ), &( st_ivas->element_mode_init ) );
        }
#ifdef OSBA_DISC_OBJ_MCT
        else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
        {
            /* read number of objects from the bitstream */
            if ( total_brate != SID_2k40 && total_brate != FRAME_NO_DATA )
            {
                st_ivas->nchan_ism = 2 * bit_stream[total_brate / FRAMES_PER_SEC - 1] + bit_stream[total_brate / FRAMES_PER_SEC - 2] + 1;
                st_ivas->ism_mode = ISM_SBA_MODE_DISC;
            }
        }
#endif
    }

    st_ivas->hDecoderConfig->ivas_total_brate = total_brate;
+3 −0
Original line number Diff line number Diff line
@@ -1258,6 +1258,9 @@ typedef enum
    MASA_FRAME_4SF
} MASA_FRAME_MODE;

#ifdef OSBA_DISC_OBJ_MCT
#define NO_BITS_MASA_ISM_NO_OBJ 2
#endif
/*----------------------------------------------------------------------------------*
 * Multichannel format
 *----------------------------------------------------------------------------------*/
+37 −0
Original line number Diff line number Diff line
@@ -962,6 +962,10 @@ ivas_error ivas_ism_metadata_enc(
    const int16_t ism_mode,                                     /* i  : ISM mode                                    */
    const PARAM_ISM_CONFIG_HANDLE hParamIsm,                    /* i  : Param ISM Config Handle                     */
    const int16_t ism_extended_metadata_flag                    /* i  : Extended metadata flag                      */
#ifdef OSBA_DISC_OBJ_MCT
    ,
    const int16_t ini_frame
#endif
);

ivas_error ivas_ism_metadata_dec(
@@ -977,6 +981,9 @@ ivas_error ivas_ism_metadata_dec(
    const PARAM_ISM_CONFIG_HANDLE hParamIsm,                    /* i  : Param ISM Config Handle                     */
    int16_t *ism_extended_metadata_flag,                        /* i/o: Extended metadata active in renderer        */
    int16_t *ism_extmeta_cnt                                   /* i/o: Number of change frames observed            */
#ifdef OSBA_DISC_OBJ_MCT
    , DEC_CORE_HANDLE st0
#endif
);


@@ -3594,6 +3601,9 @@ void ivas_dirac_dec_read_BS(
    DIRAC_DEC_HANDLE hDirAC,                                    /* i/o: decoder DirAC handle                    */
    IVAS_QMETADATA_HANDLE hQMetaData,                           /* i/o: q metadata                              */
    int16_t *nb_bits,                                           /* o  : number of bits read                     */
#ifdef OSBA_DISC_OBJ_MCT
    const int16_t last_bit_pos, /* i  : last read bitstream position*/
#endif
    const int16_t hodirac_flag,                                 /* i  : flag to indicate HO-DirAC mode          */
    int16_t *dirac_to_spar_md_bands                             /* o  : DirAC->SPAR MD bands                    */
);
@@ -5563,6 +5573,33 @@ void ivas_osba_enc(
    const ISM_MODE ism_mode,                                    /* i  : ISM mode                                  */
    const int16_t sba_analysis_order                            /* i  : SBA order evaluated in DirAC/SPAR encoder */
);
#ifdef OSBA_DISC_OBJ_MCT
ivas_error ivas_masa_ism_data_open(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder handle  */
);
ivas_error ivas_masa_ism_separate_object_renderer_open(
    Decoder_Struct *st_ivas /* i/o: IVAS decoder structure      */
);

ivas_error ivas_omasa_dirac_td_binaural(
    Decoder_Struct *st_ivas,    /* i/o: IVAS decoder structure          */
    float output[][L_FRAME48k], /* o  : output synthesis signal         */
    const int16_t output_frame  /* i  : output frame length per channel */
);

ivas_error ivas_osba_ism_metadata_dec(
    Decoder_Struct *st_ivas,             /* i/o: IVAS decoder structure            */
    const int32_t ism_total_brate,       /* i  : ISM total bitrate                 */
    int16_t *nchan_ism,                  /* o  : number of ISM separated channels  */
    int16_t *nchan_transport_ism,        /* o  : number of ISM TCs                 */
    const int16_t dirac_bs_md_write_idx, /* i  : DirAC bitstream write index       */
    int16_t nb_bits_metadata[]           /* o  : number of ISM metadata bits       */
);

void ivas_masa_ism_data_close(
    MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle    */
);
#endif
#endif

/*----------------------------------------------------------------------------------*
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@
#define SBA_AND_OBJECTS
#ifdef SBA_AND_OBJECTS
#define OSBA_DISC_OBJ_MCT
//#define ENABLE_ISM_MD_CODING
#endif

/* ################## End DEVELOPMENT switches ######################### */
+218 −2
Original line number Diff line number Diff line
@@ -165,14 +165,24 @@ ivas_error ivas_dec(
        }
        else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
        {
            if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hDirAC->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK )
            if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hDirAC->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt
#ifdef OSBA_DISC_OBJ_MCT
                                                  ,
                                                  st_ivas->hSCE[0]->hCoreCoder[0]
#endif
                                                  ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else /* ISM_MODE_DISC */
        {
            if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK )
            if ( ( error = ivas_ism_metadata_dec( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt
#ifdef OSBA_DISC_OBJ_MCT
                                                  ,
                                                  st_ivas->hSCE[0]->hCoreCoder[0]
#endif
                                                  ) ) != IVAS_ERR_OK )
            {
                return error;
            }
@@ -440,6 +450,212 @@ ivas_error ivas_dec(
            ivas_sba_upmixer_renderer( st_ivas, output, output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */
        }
    }
#ifdef OSBA_DISC_OBJ_MCT
    // Todo OSBA merge: This was added as a whole block so probably something is wrong.
    else if ( st_ivas->ivas_format == SBA_ISM_FORMAT )
    {
        int16_t nchan_ism, nchan_transport_ism;
        int16_t dirac_bs_md_write_idx;

        set_s( nb_bits_metadata, 0, MAX_SCE );
        nchan_transport_ism = 1;

        dirac_bs_md_write_idx = 0;
        if ( st_ivas->hDirAC != NULL )
        {
            dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */
        }


        /* SBA metadata decoding */
        if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#ifdef ENABLE_ISM_MD_CODING
        /* set ISM parameters and decode ISM metadata in OSBA format */
        if ( ( error = ivas_osba_ism_metadata_dec( st_ivas, ivas_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#endif
#if 0
        /* Configuration of combined-format bit-budget distribution */
        ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate );

        if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
        {
            /* set ISM parameters and decode ISM metadata in OSBA format */
            if ( ( error = ivas_omasa_ism_metadata_dec( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            /* the separated object */
            st = st_ivas->hSCE[0]->hCoreCoder[0];
            st->bit_stream = &( st_ivas->bit_stream[0] );
            if ( ( error = ivas_sce_dec( st_ivas, 0, &output[st_ivas->nchan_transport], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }

            /* prepare for SBA content decoding */
            if ( st_ivas->nchan_transport == 1 )
            {
                st = st_ivas->hSCE[1]->hCoreCoder[0];
            }
            else
            {
                st = st_ivas->hCPE[0]->hCoreCoder[0];
            }
#if 1
            st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] );
#else
            st->bit_stream = st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream; //& ( st_ivas->bit_stream[( st_ivas->hSCE[0]->hCoreCoder[0]->total_brate / FRAMES_PER_SEC )] );
#endif
        }
        else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
        {
            // TBD !!!!!
        }

        if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
        {
#endif
#if 1 /*TODOfto: no MD for now*/

#endif
#if 0
        /* decode ISM channels */
        for ( n = 0; n < nchan_transport_ism; n++ )
        {
            if ( ( error = ivas_sce_dec( st_ivas, n, &output[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }

        if ( st_ivas->nchan_transport == 1 )
        {
            st = st_ivas->hSCE[nchan_transport_ism]->hCoreCoder[0];
        }
        else
        {
            st = st_ivas->hCPE[0]->hCoreCoder[0];
        }
#else
        st = st_ivas->hCPE[0]->hCoreCoder[0];
#endif
        //  st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] );
        // st->next_bit_pos = SBA_PLANAR_BITS + SBA_ORDER_BITS;

#if 0
        /* decode SBA transport channels */
        if ( st_ivas->nchan_transport == 1 )
        {
            if ( ( error = ivas_sce_dec( st_ivas, nchan_transport_ism, &output[0], output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else if ( st_ivas->nCPE == 1 )
        {
            if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else if ( st_ivas->nCPE > 1 )
        {
    
            if ( ( error = ivas_mct_dec( st_ivas, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
#else
        if ( ( error = ivas_mct_dec( st_ivas, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
        {
            return error;
        }
#endif

        /* HP filtering */
        for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
        {
            hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
        }

#if 1

        {
            int16_t nchan = st_ivas->nchan_transport + st_ivas->nchan_ism;
            for ( int t = 0; t < output_frame; t++ )
            {
                for ( int c = 0; c < nchan; c++ )
                {
                    int16_t val = (int16_t) ( output[c][t] + 0.5f );
                    dbgwrite( &val, sizeof( int16_t ), 1, 1, "int_dec_core_out.raw" );
                }
            }
        }
#endif

        nchan_remapped = ivas_sba_remapTCs( output, st_ivas, output_frame );


        if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
        {
            ivas_sba_mix_matrix_determiner( st_ivas->hSpar, output, st_ivas->bfi, nchan_remapped, output_frame );
        }
#if 0
        /* Set the number of objects for the parametric rendering */
        if ( st_ivas->hDirAC != NULL )
        {
            st_ivas->hDirAC->numIsmDirections = 0;
            if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ )
            {
                st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism;
            }
        }
#endif
#if 0
        if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
        {
            /* loudness correction */
            ivas_dirac_dec_binaural_gain( output, nchan_remapped, output_frame );
        }

        /* 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 )
        {
            if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC )
            {
                if ( ( error = ivas_omasa_dirac_td_binaural( st_ivas, output, output_frame ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
            else
            {
                ivas_dirac_dec_binaural( st_ivas, st_ivas->hCombinedOrientationData, output, st_ivas->nchan_transport );
            }
        }
        else
#endif
        if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
        {
            if ( ( error = ivas_omasa_dirac_td_binaural( st_ivas, output, output_frame ) ) != IVAS_ERR_OK )
            {
                return error;
            }
        }
        else
        {
            /* Todo OSBA: Implement other outputs. */
        }
    }
#endif
    else if ( st_ivas->ivas_format == MC_FORMAT )
    {
        st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
Loading