Commit 9facd165 authored by vasilache's avatar vasilache
Browse files

update check qmetadata branch

parent 6c8a9816
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -45,11 +45,12 @@
#pragma warning(disable:4310)     /* cast truncates constant value this affects mainly constants tables*/
#endif

/*#define DEBUGGING*/                             /* Allows debugging message to be printed out during runtime */
#define DEBUGGING                             /* Allows debugging message to be printed out during runtime */
#ifdef DEBUGGING
#define DEBUG_MODE_INFO /* define to output most important parameters to the subdirectory "res/" */
#define DEBUG_MODE_INFO_TWEAK /* enable command line switch to specify subdirectory for debug info output inside "./res/" */
/*#define DEBUG_MODE_INFO */ /* define to output most important parameters to the subdirectory "res/" */
/*#define DEBUG_MODE_INFO_TWEAK *//* enable command line switch to specify subdirectory for debug info output inside "./res/" */
/*#define DBG_WAV_WRITER*/ /* enable dbgwrite_wav() function for generating ".wav" files */
#define DEBUG_MODE_QMETADATA
#endif

#define SUPPORT_JBM_TRACEFILE                   /* Support for JBM tracefile, which is needed for 3GPP objective/subjective testing, but not relevant for real-world implementations */
+6 −0
Original line number Diff line number Diff line
@@ -4354,6 +4354,12 @@ static void create_masa_ext_out_meta_fx(
            {
                FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ )
                {
                    #if 1
                    IF (EQ_32(hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], 1073741824))
                    {
                        hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf]--;
                    }
                    #endif
                    UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 );
                    move16();
                    extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp;
+179 −2
Original line number Diff line number Diff line
@@ -156,6 +156,27 @@ Word16 ivas_qmetadata_dec_decode(
    Word16 ind_order[MASA_MAXIMUM_CODING_SUBBANDS];
    Word32 tmp32;

    #ifdef DEBUG_MODE_QMETADATA
    static FILE *pF = NULL;
    static FILE *pF_azi = NULL;
    static FILE *pF_ele = NULL;
    static FILE *pF_ratio = NULL;
    static FILE *pF_spcoh = NULL;
    static FILE *pF_surcoh = NULL;

    if ( pF == NULL )
        pF = fopen( "./res/qmetadata_dec.txt", "w" );
    if ( pF_azi == NULL )
        pF_azi = fopen( "./res/qmetadata_azi_dec.txt", "w" );
    if ( pF_ele == NULL )
        pF_ele = fopen( "./res/qmetadata_ele_dec.txt", "w" );
    if ( pF_ratio == NULL )
        pF_ratio = fopen( "./res/qmetadata_ratio_dec.txt", "w" );
    if ( pF_spcoh == NULL )
        pF_spcoh = fopen( "./res/qmetadata_spcoh_dec.txt", "w" );
    if ( pF_surcoh == NULL )
        pF_surcoh = fopen( "./res/qmetadata_surcoh_dec.txt", "w" );
#endif

    ec_flag = 0;
    move16();
@@ -676,6 +697,44 @@ Word16 ivas_qmetadata_dec_decode(

        bits_dir_target = add( bits_dir_target, bits_dir_raw );
        bits_dir_used = add( bits_dir_used, bits_dir );
#ifdef DEBUG_MODE_QMETADATA
        fprintf( pF, " diff %d coh %d surcoh %d ", bits_diff, bits_coherence, bits_sur_coherence );
        fprintf( pF, "dir %d %d,%d,%d\n", ec_flag, start_index_0 - *index, total_bits_1dir, bits_dir_raw );

        fprintf( pF_azi, "/dir/ec %d/%d: ", d, ec_flag );
        fprintf( pF_ele, "/dir/ec %d/%d: ", d, ec_flag );
        fprintf( pF_ratio, "/dir %d: ", d );
        fprintf( pF_spcoh, "/dir %d: ", d );
        if ( d == 0 )
        {
            fprintf( pF_surcoh, "/dir %d: ", d );
        }
        for ( b = start_band; b < nbands; b++ )
        {
            for ( m = 0; m < q_direction->cfg.nblocks; m++ )
            {
                fprintf( pF_azi, " %+5.2f ", (int16_t) ( 100.f * q_direction->band_data[b].azimuth_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
                fprintf( pF_ele, " %+5.2f ", (int16_t) ( 100.f * q_direction->band_data[b].elevation_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
                fprintf( pF_ratio, " %1.3f ", q_direction->band_data[b].energy_ratio_fx[m] / ( (float) 1073741824.0f ) );
                if ( q_direction->coherence_band_data != NULL )
                {
                    fprintf( pF_spcoh, " %d ", q_direction->coherence_band_data[b].spread_coherence[m] );
                }
                if ( d == 0 && hQMetaData->surcoh_band_data != NULL )
                {
                    fprintf( pF_surcoh, " %d ", hQMetaData->surcoh_band_data[b].surround_coherence[m] );
                }
            }
        }
        fprintf( pF_azi, "\n" );
        fprintf( pF_ele, "\n" );
        fprintf( pF_ratio, "\n" );
        fprintf( pF_spcoh, "\n" );
        if ( d == 0 )
        {
            fprintf( pF_surcoh, "\n" );
        }
#endif
    }
    /* move 2 dir data to its correct subband */
    IF( EQ_32( hQMetaData->no_directions, 2 ) )
@@ -1348,6 +1407,30 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
    UWord16 all_coherence_zero;
    Word16 p[MASA_MAXIMUM_CODING_SUBBANDS], dif_p[MASA_MAXIMUM_CODING_SUBBANDS];
    Word16 codedBands, sf_nbands0, sf_nbands1;
#ifdef DEBUG_MODE_QMETADATA
    int16_t bits_diff_sum;
    int16_t bits_no_dirs_coh, bits_sur_coherence;
    static FILE *pF = NULL;
    static FILE *pF_azi = NULL;
    static FILE *pF_ele = NULL;
    static FILE *pF_ratio = NULL;
    static FILE *pF_spcoh = NULL;
    static FILE *pF_surcoh = NULL;

    if ( pF == NULL )
        pF = fopen( "./res/qmetadata_dec.txt", "w" );
    if ( pF_azi == NULL )
        pF_azi = fopen( "./res/qmetadata_azi_dec.txt", "w" );
    if ( pF_ele == NULL )
        pF_ele = fopen( "./res/qmetadata_ele_dec.txt", "w" );
    if ( pF_ratio == NULL )
        pF_ratio = fopen( "./res/qmetadata_ratio_dec.txt", "w" );
    if ( pF_spcoh == NULL )
        pF_spcoh = fopen( "./res/qmetadata_spcoh_dec.txt", "w" );
    if ( pF_surcoh == NULL )
        pF_surcoh = fopen( "./res/qmetadata_surcoh_dec.txt", "w" );
#endif

    sf_nbands1 = 1;
    move16();
    Word64 W_nrg_ratio[2][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES];
@@ -1426,6 +1509,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
    move16();

    /*Coherence flag decoding*/
#ifdef DEBUG_MODE_QMETADATA
    bits_no_dirs_coh = 0;
#endif
    all_coherence_zero = 1;
    move16();
    IF( hQMetaData->coherence_flag )
@@ -1433,6 +1519,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
        /* read if coherence is zero */
        all_coherence_zero = bitstream[( *index )--];
        move16();
#ifdef DEBUG_MODE_QMETADATA
        bits_no_dirs_coh += 1;
#endif
    }

    hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero;
@@ -1473,6 +1562,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
            hQMetaData->twoDirBands[p[b]] = 1;
            move16();
        }
#ifdef DEBUG_MODE_QMETADATA
        bits_no_dirs_coh += ( d - *index );
#endif
    }

    test();
@@ -1486,10 +1578,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
            move16();
        }
    }
#ifdef DEBUG_MODE_QMETADATA
    bits_diff_sum =
#endif
    ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[0] ) );

    IF( EQ_32( hQMetaData->no_directions, 2 ) )
    {
#ifdef DEBUG_MODE_QMETADATA
        bits_diff_sum +=
#endif
        ivas_qmetadata_entropy_decode_diffuseness_hr_512( bitstream, index, &( hQMetaData->q_direction[1] ) );
    }

@@ -1595,10 +1693,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(

    IF( !all_coherence_zero )
    {
#ifdef DEBUG_MODE_QMETADATA
        bits_sur_coherence =
#endif
        read_surround_coherence_hr_fx( bitstream, index, hQMetaData, W_nrg_ratio );
    }
    ELSE
    {
#ifdef DEBUG_MODE_QMETADATA
        bits_sur_coherence = 0;
#endif
        /*Surround coherence*/
        FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ )
        {
@@ -1608,7 +1712,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
            }
        }
    }

#ifdef DEBUG_MODE_QMETADATA
    bits_no_dirs_coh += bits_sur_coherence;
#endif
    FOR( d = 0; d < hQMetaData->no_directions; d++ )
    {
        q_direction = &hQMetaData->q_direction[d];
@@ -1642,6 +1748,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
        /* Decode quantized directions frame-wise */

        ivas_qmetadata_raw_decode_dir_512_fx( q_direction, bitstream, index, nbands, start_band, sph_grid16 );

    }

    IF( EQ_32( hQMetaData->no_directions, 2 ) )
@@ -1743,7 +1850,43 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512(
            }
        }
#endif // MSAN_FIX


    }
#ifdef DEBUG_MODE_QMETADATA
    FOR( d = 0; d < hQMetaData->no_directions; d++ )
    {
        fprintf( pF, "diff %d  surcoh %d ", bits_diff_sum, bits_sur_coherence );

        fprintf( pF_azi, "/dir/ec %d: ", d );
        fprintf( pF_ele, "/dir/ec %d: ", d );
        fprintf( pF_spcoh, "/dir %d: ", d );
        fprintf( pF_ratio, "/dir %d: ", d );

        for ( b = hQMetaData->q_direction[d].cfg.start_band; b < hQMetaData->q_direction[d].cfg.nbands; b++ )
        {
            for ( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ )
            {
                fprintf( pF_azi, " %+5.0f ", (int16_t) ( 100.f * hQMetaData->q_direction[d].band_data[b].azimuth_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
                fprintf( pF_ele, " %+5.2f ", (int16_t) ( 100.f * hQMetaData->q_direction[d].band_data[b].elevation_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
                fprintf( pF_ratio, " %1.3f ", hQMetaData->q_direction[d].band_data[b].energy_ratio_fx[m] / ( (float) 1073741824.0f ) );
                if ( hQMetaData->q_direction[d].coherence_band_data != NULL )
                {
                    fprintf( pF_spcoh, " %d ", hQMetaData->q_direction[d].coherence_band_data[b].spread_coherence[m] );
                }
                if ( d == 0 && hQMetaData->surcoh_band_data != NULL )
                {
                    fprintf( pF_surcoh, " %d ", hQMetaData->surcoh_band_data[b].surround_coherence[m] );
                }
            }
        }
        fprintf( pF_azi, "\n" );
        fprintf( pF_ele, "\n" );
        fprintf( pF_ratio, "\n" );
        fprintf( pF_spcoh, "\n" );
    }

#endif
    /* Store status information for renderer use */
    hQMetaData->ec_flag = 0;
    move16();
@@ -2123,7 +2266,21 @@ Word16 ivas_qmetadata_dec_sid_decode(
    Word32 direction_vector_fx[3];
    Word16 metadata_sid_bits; /* bits allocated to SID for metadata */
    Word16 bits_delta, bits_dir;

#ifdef DEBUG_MODE_QMETADATA
    static FILE *pF = NULL;
    static FILE *pF_azi = NULL;
    static FILE *pF_ele = NULL;
    static FILE *pF_ratio = NULL;

    if ( pF == NULL )
        pF = fopen( "./res/qmetadata_sid_dec.txt", "w" );
    if ( pF_azi == NULL )
        pF_azi = fopen( "./res/qmetadata_sid_azi_dec.txt", "w" );
    if ( pF_ele == NULL )
        pF_ele = fopen( "./res/qmetadata_sid_ele_dec.txt", "w" );
    if ( pF_ratio == NULL )
        pF_ratio = fopen( "./res/qmetadata_sid_ratio_dec.txt", "w" );
#endif
    IF( EQ_16( ivas_format, SBA_FORMAT ) )
    {
        metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/
@@ -2363,7 +2520,27 @@ Word16 ivas_qmetadata_dec_sid_decode(
        b = bitstream[( *index )--];
        move16();
    }
#ifdef DEBUG_MODE_QMETADATA
    fprintf( pF, " all %d  ", start_index - *index );

    fprintf( pF_azi, "SID: " );
    fprintf( pF_ele, "SID: " );
    fprintf( pF_ratio, "SID: " );

    for ( b = start_band; b < nbands; b++ )
    {
        for ( m = 0; m < nblocks; m++ )
        {
            fprintf( pF_azi, " %+5.2f ", (int16_t) ( 100.f * q_direction->band_data[b].azimuth_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
            fprintf( pF_ele, " %+5.2f ", (int16_t) ( 100.f * q_direction->band_data[b].elevation_fx[m] / ( (float) 4194304.0f ) ) / 100.f );
            fprintf( pF_ratio, " %1.3f ", q_direction->band_data[b].energy_ratio_fx[m] / ( (float) 1073741824.0f ) );
        }
    }
    fprintf( pF_azi, "\n" );
    fprintf( pF_ele, "\n" );
    fprintf( pF_ratio, "\n" );

#endif
    return sub( start_index, *index );
}