Commit 799edbf9 authored by vaclav's avatar vaclav
Browse files

review of HR_METADATA

parent 71cde830
Loading
Loading
Loading
Loading
+188 −13
Original line number Diff line number Diff line
@@ -412,12 +412,19 @@ void masa_sample_rate_band_correction(
    return;
}


#ifdef HR_METADATA
/*-------------------------------------------------------------------------
 * index_theta_phi_16()
 *
 *
 *------------------------------------------------------------------------*/

/*! r: output index for direction */
uint16_t index_theta_phi_16(
    float *p_theta,                     /* i/o: input elevation to be indexed   */
    float *p_phi,                       /* i/o: input azimuth to be indexed     */
    SPHERICAL_GRID_DATA *gridData /* i  : generated grid data */
    const SPHERICAL_GRID_DATA *gridData /* i  : generated grid data             */
)
{
    float abs_theta;
@@ -501,13 +508,20 @@ uint16_t index_theta_phi_16(
        }
    }


    return idx_sph;
}


/*-------------------------------------------------------------------------
 * quantize_phi_masa()
 *
 *
 *------------------------------------------------------------------------*/

/*! r: output index */
int16_t quantize_theta(
    float x,             /* i  : theta value to be quantized  */
    int16_t no_cb, /* i  : number of codewords          */
    const int16_t no_cb, /* i  : number of codewords          */
    float *xhat          /* o  : quantized value              */
)
{
@@ -540,10 +554,16 @@ int16_t quantize_theta(
}


/*-------------------------------------------------------------------------
 * quantize_phi_masa()
 *
 *
 *------------------------------------------------------------------------*/

/*! r: index azimuth */
int16_t quantize_phi_masa(
    float phi,                /* i  : azimuth value                                                   */
    int16_t flag_delta, /* i  : flag indicating if the azimuth codebook is translated or not    */
    const int16_t flag_delta, /* i  : flag indicating if the azimuth codebook is translated or not    */
    float *phi_hat,           /* o  : quantized azimuth                                               */
    const int16_t n           /* i  : azimuth codebook size                                           */
)
@@ -587,4 +607,159 @@ int16_t quantize_phi_masa(
    return id_phi;
}


/*-------------------------------------------------------------------------
 * deindex_sph_idx()
 *
 *  deindex the MASA metadata from the input metadata file
 *------------------------------------------------------------------------*/

void deindex_sph_idx(
    const uint16_t sphIndex,             /* i  : Spherical index            */
    const SPHERICAL_GRID_DATA *gridData, /* i  : Prepared spherical grid    */
    float *theta,                        /* o  : Elevation                  */
    float *phi                           /* o  : Azimuth                    */
)
{
    float ba_crt, del_crt, div_crt, a4_crt;
    float estim;
    int32_t base_low, base_up;
    int16_t n_crt;
    int16_t id_th;
    int16_t sign_theta;
    int16_t id_phi;
    int16_t no_th = gridData->no_theta;
    const int16_t *n = gridData->no_phi;
    const float ba[3] = {
        2.137991118026424e+02f,
        1.244854404591542e+02f,
        1.228408647140870e+02f,
    };
    const float del[3] = { 7.998262115303199e+05f, 1.300883976959332e+06f, 1.424072242426373e+06f };
    const float div[3] = { -0.237662341081474f, -0.100938185496887f, -0.092050209205032f };
    const float a4[3] = { -8.415300425381099f, -19.814106922515204f, -21.727272727270197f };
    const uint16_t limit_index1 = 64964, limit_index2 = 47870;

    if ( sphIndex >= limit_index1 )
    {
        ba_crt = ba[2];
        div_crt = div[2];
        a4_crt = a4[2];
        del_crt = del[2];
    }
    else if ( sphIndex >= limit_index2 )
    {
        ba_crt = ba[1];
        div_crt = div[1];
        a4_crt = a4[1];
        del_crt = del[1];
    }
    else
    {
        ba_crt = ba[0];
        div_crt = div[0];
        a4_crt = a4[0];
        del_crt = del[0];
    }
    estim = ba_crt + div_crt * sqrtf( del_crt + a4_crt * sphIndex );

    if ( estim > MASA_NO_CIRCLES )
    {
        estim = MASA_NO_CIRCLES;
    }

    assert( estim > 0 );
    id_th = (int16_t) roundf( estim ) - 1;
    if ( id_th < 0 )
    {
        id_th = 0;
    }

    if ( id_th == 0 )
    {
        base_low = 0;
        base_up = n[0];
    }
    else
    {
        estim = MASA_ANGLE_AT_EQUATOR * (float) ( id_th - 0.5f );
        base_low = n[0];
        if ( id_th >= 2 )
        {
            if ( id_th == 2 )
            {
                base_low += 2 * (int16_t) ceilf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
            }
            else
            {
                base_low += 2 * (int16_t) roundf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) );
            }
        }
        base_up = base_low + 2 * n[id_th];
    }

    sign_theta = 1;

    n_crt = n[id_th];
    if ( sphIndex < base_low )
    {
        id_th--;
        n_crt = n[id_th];
        if ( id_th == 0 )
        {
            base_low = 0;
            base_up = n_crt;
        }
        else
        {
            base_up = base_low;
            base_low -= 2 * n[id_th];
        }
        assert( sphIndex >= base_low );
    }
    else if ( sphIndex >= base_up )
    {
        id_th++;
        n_crt = n[id_th];
        base_low = base_up;
        base_up += 2 * n_crt;
        assert( sphIndex < base_up );
    }

    id_phi = (int16_t) ( sphIndex - base_low );
    if ( sphIndex - base_low >= n_crt )
    {
        id_phi -= n_crt;
        sign_theta = -1;
    }

    if ( id_th == 0 )
    {
        *theta = 0.f;
        *phi = (float) sphIndex * 360 / (float) n_crt - 180;
    }
    else
    {
        if ( id_th == no_th - 1 )
        {
            id_phi = 0;
            *phi = -180;
            *theta = 90 * (float) sign_theta;
        }
        else
        {
            *theta = id_th * MASA_ANGLE_AT_EQUATOR_DEG * (float) sign_theta;
            if ( id_th % 2 == 0 )
            {
                *phi = (float) id_phi * 360 / (float) n_crt - 180;
            }
            else
            {
                *phi = ( (float) id_phi + 0.5f ) * 360 / (float) n_crt - 180;
            }
        }
    }

    return;
}
#endif
+78 −64
Original line number Diff line number Diff line
@@ -2949,20 +2949,11 @@ ivas_error ivas_qmetadata_enc_encode(
);

#ifdef HR_METADATA

ivas_error ivas_qmetadata_enc_encode_hr_384_512(
    BSTR_ENC_HANDLE hMetaData,                                  /* i/o: metadata bitstream handle               */
    IVAS_QMETADATA *hQMetaData,                                 /* i/o: metadata handle                         */
    int16_t bits_sph_idx,
    int16_t bits_sp_coh
);
int16_t ivas_qmetadata_dec_decode_hr_384_512(
    IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle  */
    uint16_t *bitstream,              /* i  : bitstream          */
    int16_t *index,                   /* i/o: bitstream position */
    SPHERICAL_GRID_DATA *sph_grid16,   /* i: spherical grid for deindexing */
    int16_t bits_sph_idx,
    int16_t bits_sp_coh
    const int16_t bits_sph_idx,
    const int16_t bits_sp_coh
);

void deindex_sph_idx(
@@ -2972,23 +2963,24 @@ void deindex_sph_idx(
    float *phi                                                  /* o  : Azimuth                                 */
);


/*! r: output index for direction */
uint16_t index_theta_phi_16(
    float * p_theta,                                            /* i/o: input elevation to be indexed           */
    float * p_phi,                                              /* i/o: input azimuth to be indexed             */
    SPHERICAL_GRID_DATA *gridData /* i  : generated grid data */
    const SPHERICAL_GRID_DATA *gridData                         /* i  : generated grid data                     */
);

/*! r: output index */
int16_t quantize_theta(
    float x,                                                    /* i  : theta value to be quantized             */
    int16_t no_cb, /* i  : number of codewords          */
    const int16_t no_cb,                                        /* i  : number of codewords                     */
    float *xhat                                                 /* o  : quantized value                         */
);

/*! r: index azimuth */
int16_t quantize_phi_masa(
    float phi,                                                  /* i  : azimuth value                                                   */
    int16_t flag_delta, /* i  : flag indicating if the azimuth codebook is translated or not    */
    const int16_t flag_delta,                                   /* i  : flag indicating if the azimuth codebook is translated or not    */
    float *phi_hat,                                             /* o  : quantized azimuth                                               */
    const int16_t n                                             /* i  : azimuth codebook size                                           */
);
@@ -3024,6 +3016,18 @@ int16_t ivas_qmetadata_dec_decode(
#endif
);

#ifdef HR_METADATA
/*! r: number of bits read */
int16_t ivas_qmetadata_dec_decode_hr_384_512(
    IVAS_QMETADATA_HANDLE hQMetaData,                           /* i/o: hQMetaData handle                       */
    uint16_t *bitstream,                                        /* i  : bitstream                               */
    int16_t *index,                                             /* i/o: bitstream position                      */
    const SPHERICAL_GRID_DATA *sph_grid16,                      /* i  : spherical grid for deindexing           */
    const int16_t bits_sph_idx,
    const int16_t bits_sp_coh
);
#endif

/*! r: number of bits read */
int16_t ivas_qmetadata_dec_sid_decode(
    IVAS_QMETADATA_HANDLE hQMetaData,                           /* i/o: q_metadata handle                       */
@@ -3103,7 +3107,7 @@ void quantize_direction_frame(
    float elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] 
#ifdef HR_METADATA
    ,
    int16_t is_hr
    const int16_t hrmasa_flag                                   /* i  : flag indicating high-rate MASA MD coding*/
#endif
);

@@ -3324,14 +3328,16 @@ int16_t ivas_sba_get_nchan_metadata(
void ivas_sba_get_spar_hoa_ch_ind(
    const int16_t num_md_chs,                                   /* i  : number of MD channels                   */
    const int32_t ivas_total_brate,                             /* i  : IVAS total bitrate                      */
    int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] );
    int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] 
);

/*! r: flag indicating to code SPAR HOA MD for all bands */
void ivas_sba_get_spar_hoa_md_flag(
    const int16_t sba_order,                                    /* i  : Ambisonic (SBA) order                   */
    const int32_t ivas_total_brate,                             /* i  : IVAS total bitrate                      */
    int16_t *spar_hoa_md_flag,
    int16_t *spar_hoa_dirac2spar_md_flag );
    int16_t *spar_hoa_dirac2spar_md_flag 
);
#else
/*! r: flag indicating to code SPAR HOA MD for all bands */
int16_t ivas_sba_get_spar_hoa_md_flag(
@@ -3339,6 +3345,7 @@ int16_t ivas_sba_get_spar_hoa_md_flag(
    const int32_t ivas_total_brate                              /* i  : IVAS total bitrate                      */
);
#endif

void ivas_sba_zero_vert_comp(
    float sba_data[][L_FRAME48k],                               /* i/o: SBA data frame                          */
    const int16_t sba_order,                                    /* i  : Ambisonic (SBA) order                   */
@@ -3728,26 +3735,33 @@ void ivas_mc_paramupmix_enc(
    float data_f[][L_FRAME48k],                                     /* i/o: input: CICP6, CICP12, CICP14, CICP16 or CICP19 MC data */
    const int16_t input_frame                                       /* i  : input frame length                              */
);

ivas_error ivas_mc_paramupmix_enc_open(
    Encoder_Struct *st_ivas                                         /* i/o: IVAS encoder handle                             */
);

void ivas_mc_paramupmix_enc_close(
    MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix,                        /* i/o: MC Param-Upmix encoder handle                   */
    const int32_t sampling_rate
);

void ivas_mc_paramupmix_dec(
    Decoder_Struct *st_ivas,                                        /* i/o: IVAS decoder handle                                     */
    float output_f[][L_FRAME48k]                                    /* i/o: synthesized core-coder transport channels/DirAC output  */
);

int16_t ivas_mc_paramupmix_getNumTransportChannels(
    void
);

ivas_error ivas_mc_paramupmix_dec_open(
    Decoder_Struct *st_ivas                                         /* i/o: IVAS decoder structure                          */
);

void ivas_mc_paramupmix_dec_close(
    MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out                     /* i/o: Parametric MC decoder handle                    */
);

void ivas_mc_paramupmix_dec_read_BS(
    const int32_t ivas_total_brate,                                 /* i  : IVAS total bitrate                              */
    Decoder_State *st,                                              /* i/o: decoder state structure                         */
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@
#define FIX_425_MASA_BRSW_RENDERER                      /* Nokia: Issue 425: renderer not reconfigure in MASA bitrate switching */

#define EUALER2QUAT_FIX                                 /* Dlb :fix for issue 430 issue in euler2quat, sign of quat y is inverted */
#define HR_METADATA                                     /* Nok: encode directional MASA metadata with more bits at 384k and 512k */
#define HR_METADATA                                     /* Nok: Contribution #45: encode directional MASA metadata with more bits at 384k and 512k */
#define SBA_TD_RESIDUAL                                 /* Dlb : Issue 426: SBA encoder complexity optimization */

#define FIX_357_DTX_32K                                 /* Eri: issue 357 - Forced LP-CNG at 32k */
+4 −0
Original line number Diff line number Diff line
@@ -47,9 +47,11 @@
/*-----------------------------------------------------------------------*
 * Local constants
 *-----------------------------------------------------------------------*/

#define SPAR_META_DELAY_SUBFRAMES 2                              /* Number of subframes to delay the SPAR metadata */
#define SPH_IDX_FRONT             ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */


/*-----------------------------------------------------------------------*
 * Local function prototypes
 *-----------------------------------------------------------------------*/
@@ -58,7 +60,9 @@ static int16_t quantize_theta( float x, int16_t no_cb, float *xhat );
static uint16_t index_theta_phi_16( float theta, float phi, SPHERICAL_GRID_DATA *Sph_Grid16 );
static int16_t quantize_phi_masa( float phi, int16_t flag_delta, float *phi_hat, const int16_t n );
#endif

static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 );

static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport );

static void replicate_subframes( IVAS_QMETADATA_HANDLE hQMetaData );
+115 −92

File changed.

Preview size limit exceeded, changes collapsed.

Loading