Commit abc0b903 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

Merge branch 'main' of ssh://forge.3gpp.org:29419/sa4/audio/ivas-basop into...

Merge branch 'main' of ssh://forge.3gpp.org:29419/sa4/audio/ivas-basop into float-1574-fix-efap-code-lint
parents 3dec6887 0c11e1c8
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@
#define FIX_BASOP_2513_EXTRA_RETURN_REND_OPEN           /* Nokia: BASOP issue 2513: Removes extra return block */
#define FIX_BASOP_2514_EFAP_PORTING_ERROR               /* Nokia: BASOP issue 2514: Fix wrongly ported line */
#define FIX_BASOP_2516_REND_CUSTOM_LAYOUT_PORT_BUG      /* Nokia: BASOP issue 2516: Fix porting bug in setting planar state for custom layout in renderer */
#define USE_RTPDUMP                                     /* FhG: RTPDUMP format (rtptools standard) instead of custom format */
#define FIX_FLOAT_1569_REND_RENDER_CONFIG_CHECKS        /* Nokia: float issue 1569: fix render config checks in renderer */
#define FIX_BASOP_2526_SPAR_MASA_PARAM_MAP_Q_BUG        /* Nokia: BASOP issue 2526: Fix wrong Q variable in SPAR to MASA param mapping */
#define FIX_BASOP_2524_MASA_REDUCE_META_BUG             /* Nokia: BASOP issue 2524: Fix wrong reset of W_tmp in reduce_metadata_further_fx */
@@ -121,7 +122,7 @@
#define FIX_2505_IVAS_DEC_SEGFAULT                      /* FhG: BASOP #2505: Add headroom to input of ivas_rend_crendProcessSubframe_fx() for ivas_mdft_fx() calculation */
#define HARMONIZE_DoRTFTn                               /* VA: harmonize functions DoRTFTn_fx() and DoRTFTn_fx_ivas() */
#define FIX_1574_EFAP_CODE_LINT                         /* FhG: float issue 1574: Code quality fixes in ivas_efap.c */

#define FIX_BASOP_2529_MASA_RATIO_SCALINGS              /* Nokia: BASOP issue 2529: Fix MASA ratio scalings and verifications */

/* ##################### End NON-BE switches ########################### */

+24 −0
Original line number Diff line number Diff line
@@ -2303,9 +2303,17 @@ static void compensate_energy_ratios_fx(
            move32();
            FOR( dir = 0; dir < numDirs; dir++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                ratioSum = L_add( ratioSum, L_shr( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], 1 ) ); // accumulate in Q29
#else
                ratioSum = L_add( ratioSum, hMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); // Q30
#endif
            }
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            ratioSum = L_add( ratioSum, L_shr( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], 1 ) ); // accumulate in  Q29
#else
            ratioSum = L_add( ratioSum, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // Q30
#endif

            IF( ratioSum == 0 )
            {
@@ -2317,8 +2325,12 @@ static void compensate_energy_ratios_fx(
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; // Q30
                move32();
            }
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            ELSE IF( GT_32( L_abs( L_sub( ratioSum, ONE_IN_Q29 ) ), 1 ) ) // else if ( ratioSum != 1.0f ) from float with minor rounding tolerance
#else
            // ELSE IF( NE_32( ratioSum, ONE_IN_Q30 ) )
            ELSE /* Removing the check against 1 works well!!! */
#endif
            {
                Word16 exp_diff;
                FOR( dir = 0; dir < numDirs; dir++ )
@@ -2326,13 +2338,21 @@ static void compensate_energy_ratios_fx(
                    hMeta->directional_meta[dir].energy_ratio_fx[sf][band] =
                        BASOP_Util_Divide3232_Scale_newton( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff );
                    move32();
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                    hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q2 ) ); // back to Q30
#else
                    hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30
#endif
                    move32();
                }
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] =
                    BASOP_Util_Divide3232_Scale_newton( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff );
                move32();
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q2 ) ); // back to Q30
#else
                hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30
#endif
                move32();
            }
        }
@@ -3990,7 +4010,11 @@ void ivas_merge_masa_metadata_fx(
                    direct_scaler_e = 0;
                    move16();
                    hMeta->directional_meta[0].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/
#ifdef FIX_BASOP_2525_MASA_MERGE_WRONG_ASSIGN
                    hMeta->directional_meta[1].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[1].energy_ratio_fx[sf][band] ); /*q30*/
#else
                    hMeta->directional_meta[1].energy_ratio_fx[sf][band] = Mpy_32_32( direct_scaler_fx, hMeta->directional_meta[0].energy_ratio_fx[sf][band] ); /*q30*/
#endif
                    move32();
                    move32();
                }
+37 −0
Original line number Diff line number Diff line
@@ -9017,7 +9017,11 @@ static void renderMasaToMasa(
    IVAS_REND_AudioBuffer outAudio )
{
    Word16 sf, band, dir, numDirs;
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
    Word32 ratioSum_fx; /* Q29 for accumulation */
#else
    Word32 ratioSum_fx; /* Q30 */
#endif
    MASA_DECODER_EXT_OUT_META_HANDLE outMeta;
    MASA_METADATA_FRAME *inMeta;
    Word32 tmpBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k];
@@ -9145,9 +9149,17 @@ static void renderMasaToMasa(
            move32();
            FOR( dir = 0; dir < numDirs; dir++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                ratioSum_fx = L_add( ratioSum_fx, L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], 1 ) ); // accumulate in Q29
#else
                ratioSum_fx = L_add( ratioSum_fx, inMeta->directional_meta[dir].energy_ratio_fx[sf][band] );
#endif
            }
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            ratioSum_fx = L_add( ratioSum_fx, L_shr( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], 1 ) ); // accumulate in Q29
#else
            ratioSum_fx = L_add( ratioSum_fx, inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] );
#endif

            IF( ratioSum_fx == 0 )
            {
@@ -9159,7 +9171,11 @@ static void renderMasaToMasa(
                inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30;
                move32();
            }
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            ELSE IF( GT_32( L_abs( L_sub( ratioSum_fx, ONE_IN_Q29 ) ), 1 ) ) // else if ( ratioSum != 1.0f ) from float with minor rounding tolerance
#else
            ELSE IF( NE_32( ratioSum_fx, ONE_IN_Q30 ) )
#endif
            {
                Word16 tmp_e = 0;
                move16();
@@ -9168,7 +9184,11 @@ static void renderMasaToMasa(
                FOR( dir = 0; dir < numDirs; dir++ )
                {
                    tmp = BASOP_Util_Divide3232_Scale_newton( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum_fx, &tmp_e );
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                    inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 2 ) ); /* Back to Q30 */
#else
                    inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */
#endif
                    move32();
                }
                tmp_e = 0;
@@ -9176,7 +9196,11 @@ static void renderMasaToMasa(
                tmp = 0;
                move32();
                tmp = BASOP_Util_Divide3232_Scale_newton( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum_fx, &tmp_e );
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 2 ) ); /* Back to Q30 */
#else
                inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */
#endif
                move32();
            }
        }
@@ -9191,16 +9215,29 @@ static void renderMasaToMasa(
            FOR( dir = 0; dir < numDirs; dir++ )
            {
                outMeta->directionIndex[dir][sf][band] = index_theta_phi_16_fx( &inMeta->directional_meta[dir].elevation_fx[sf][band], &inMeta->directional_meta[dir].azimuth_fx[sf][band], masaInput->hMasaPrerend->sph_grid16 );
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                outMeta->directToTotalRatio[dir][sf][band] = (UWord8) W_extract_h( W_mult_32_16( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], UINT8_MAX << 1 ) );
#else
                outMeta->directToTotalRatio[dir][sf][band] = (UWord8) L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], Q22 );
#endif
                outMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( outMeta->diffuseToTotalRatio[sf][band], outMeta->directToTotalRatio[dir][sf][band] );
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                outMeta->spreadCoherence[dir][sf][band] = (UWord8) W_extract_h( W_mult_32_16( L_deposit_h( inMeta->directional_meta[dir].spread_coherence_fx[sf][band] ), UINT8_MAX << 1 ) );
#else
                outMeta->spreadCoherence[dir][sf][band] = (UWord8) shr( inMeta->directional_meta[dir].spread_coherence_fx[sf][band], Q7 );
#endif

                move16();
                move16();
                move16();
                move16();
            }

#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            outMeta->surroundCoherence[sf][band] = (UWord8) W_extract_h( W_mult_32_16( L_deposit_h( inMeta->common_meta.surround_coherence_fx[sf][band] ), UINT8_MAX << 1 ) );
#else
            outMeta->surroundCoherence[sf][band] = (UWord8) shr( inMeta->common_meta.surround_coherence_fx[sf][band], Q7 );
#endif
            move16();
        }
    }
+71 −1
Original line number Diff line number Diff line
@@ -37,14 +37,26 @@
#include "ivas_error_utils.h"
#include "float_to_fix_ops.h"


#define Q15 15

#ifdef USE_RTPDUMP
#include "rtpdump.h"

struct IVAS_RTP_FILE
{
    bool isFileWriter;
    RTPDUMP_HANDLE f_rtpstream;
    uint32_t offset_ms;
};

#else  // USE_RTPDUMP

struct IVAS_RTP_FILE
{
    bool isFileWriter;
    FILE *f_rtpstream;
};
#endif // USE_RTPDUMP

static ivas_error IvasRtpFile_Open(
    const char *filePath,           /* i : path to CA config file                */
@@ -52,12 +64,29 @@ static ivas_error IvasRtpFile_Open(
    IVAS_RTP_FILE_HANDLE *phRtpFile /* o : pointer to an IVAS file reader handle */
)
{
#ifdef USE_RTPDUMP
    RTPDUMP_HANDLE f_rtpstream;
    RTPDUMP_ERROR rderr;
    if ( isFileWriter )
    {
        rderr = RTPDUMP_OpenForWriting( &f_rtpstream, filePath );
    }
    else
    {
        rderr = RTPDUMP_OpenForReading( &f_rtpstream, filePath );
    }
    if ( rderr != RTPDUMP_NO_ERROR )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "rtpdump open error %d", rderr );
    }
#else  // USE_RTPDUMP
    const char *mode = isFileWriter ? "wb" : "rb";
    FILE *f_rtpstream = fopen( filePath, mode );
    if ( f_rtpstream == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "could not open: %s\n", filePath );
    }
#endif // USE_RTPDUMP

    *phRtpFile = calloc( 1, sizeof( struct IVAS_RTP_FILE ) );
    if ( *phRtpFile != NULL )
@@ -77,7 +106,11 @@ static ivas_error IvasRtpFile_Close(
    {
        if ( ( *phReader )->f_rtpstream != NULL )
        {
#ifdef USE_RTPDUMP
            RTPDUMP_Close( &( *phReader )->f_rtpstream, 1 );
#else  // USE_RTPDUMP
            fclose( ( *phReader )->f_rtpstream );
#endif // USE_RTPDUMP
            ( *phReader )->f_rtpstream = NULL;
        }
        free( *phReader );
@@ -95,9 +128,20 @@ static ivas_error IvasRtpFile_Write(
    ivas_error error = IVAS_ERR_OK;
    if ( hRtpFile->isFileWriter )
    {
#ifdef USE_RTPDUMP
        RTPDUMP_RTPPACKET pkt;
        RTPDUMP_SetDefaultRtpPacketHeader( &pkt );
        numBytes = ( numBytes > sizeof( pkt.data ) ) ? sizeof( pkt.data ) : numBytes;
        memcpy( pkt.data, packet, numBytes );
        RTPDUMP_ParseRTPHeader( &pkt );
        pkt.payloadSize = (unsigned short) ( numBytes - pkt.headerSize );
        /* compute time offset in ms from RTP timestamp (16kHz clock) */
        error = ( RTPDUMP_WritePacket( hRtpFile->f_rtpstream, &pkt, pkt.timeStamp / 16 ) != RTPDUMP_NO_ERROR ) ? IVAS_ERR_FAILED_FILE_WRITE : IVAS_ERR_OK;
#else  // USE_RTPDUMP
        uint32_t length = (uint32_t) numBytes; /* Max packet length is < 32 bits*/
        fwrite( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream );
        fwrite( packet, sizeof( uint8_t ), numBytes, hRtpFile->f_rtpstream );
#endif // USE_RTPDUMP
    }
    else
    {
@@ -114,12 +158,35 @@ static ivas_error IvasRtpFile_Read(
)
{
    size_t nread = 0;
#ifndef USE_RTPDUMP
    uint32_t length = 0;
#endif // USE_RTPDUMP
    if ( hRtpFile->isFileWriter )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "File open for writing cannot be read" );
    }

#ifdef USE_RTPDUMP
    RTPDUMP_RTPPACKET pd;
    RTPDUMP_ERROR rderr = RTPDUMP_ReadPacket( hRtpFile->f_rtpstream, &pd, &hRtpFile->offset_ms );
    if ( rderr == RTPDUMP_READ_ENDOFFILE )
    {
        return IVAS_ERR_END_OF_FILE;
    }
    if ( rderr != RTPDUMP_NO_ERROR )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "rtpdump read error %d", rderr );
    }

    /* copy raw data to unpack buffer */
    nread = pd.headerSize + pd.payloadSize;
    if ( nread > capacity )
    {
        return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE;
    }
    memcpy( packet, pd.data, nread );
    *numBytes = nread;
#else  // USE_RTPDUMP
    nread = fread( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream ); /* Read Packet Length */
    if ( nread == 0 )
    {
@@ -138,6 +205,7 @@ static ivas_error IvasRtpFile_Read(
    {
        return IVAS_ERR_END_OF_FILE;
    }
#endif // USE_RTPDUMP

    return IVAS_ERR_OK;
}
@@ -902,6 +970,7 @@ ivas_error IVAS_RTP_WRITER_Init(
            return error;
        }

        /* initialize RTP packer header sequence only in file-based mode */
#ifdef FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API
        error = IVAS_RTP_PACK_UpdateHeader( rtp->hPack, payloadType, seqNumInitVal, SSRC, 0, NULL, 0, 0, NULL );
#else
@@ -935,6 +1004,7 @@ ivas_error IVAS_RTP_READER_Init(
    error = IVAS_RTP_UNPACK_Open( &rtp->hUnpack, &rtp->unpackCfg );
    if ( error == IVAS_ERR_OK )
    {
        /* Open the output file for RTPDump writing */
        error = IvasRtpFile_Open( inputBitstreamFilename, false, &rtp->hRtpFile );
        if ( error != IVAS_ERR_OK )
        {
+20 −0
Original line number Diff line number Diff line
@@ -194,7 +194,11 @@ ivas_error MasaFileReader_readNextFrame(

            for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30
#else
                hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30
#endif
            }

            /* Spread coherence */
@@ -205,7 +209,11 @@ ivas_error MasaFileReader_readNextFrame(

            for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( ( (int32_t) readOther[b] * ONE_IN_Q15 + 254 ) / 255 ); // Q15
#else
                hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 ); // Q15
#endif
            }
        }

@@ -218,7 +226,11 @@ ivas_error MasaFileReader_readNextFrame(

        for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ )
        {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30
#else
            hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30
#endif
        }

        /* Surround coherence */
@@ -229,8 +241,12 @@ ivas_error MasaFileReader_readNextFrame(

        for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ )
        {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            hMeta->common_meta.surround_coherence_fx[j][b] = (Word16) ( ( (int32_t) readOther[b] * ONE_IN_Q15 + 254 ) / 255 ); // Q15
#else
            hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15
            move16();
#endif
        }

        /* Remainder-to-total ratio */
@@ -241,8 +257,12 @@ ivas_error MasaFileReader_readNextFrame(

        for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ )
        {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
            hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30
#else
            hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = L_shl( (Word32) readOther[b], Q22 ); // Q8 -> Q30
            move32();
#endif
        }
    }

Loading