Commit a453eddb authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Merge remote-tracking branch 'origin/main' into 1793-fix-decoder-mc-to-mono-output-scaling

parents e7150d46 22b74eae
Loading
Loading
Loading
Loading
+147 −1
Original line number Diff line number Diff line
@@ -51,6 +51,11 @@
#include "wmc_auto.h"
#include "options.h"
#include "stl.h"
#ifdef OBJ_EDITING_API
#ifdef OBJ_EDITING_EXAMPLE
#include <math.h>
#endif
#endif


#define WMC_TOOL_SKIP
@@ -135,6 +140,9 @@ typedef struct
    AcousticEnvironmentSequence aeSequence;
    bool dpidEnabled;
    uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS];
#ifdef OBJ_EDITING_EXAMPLE
    bool objEditEnabled;
#endif

} DecArguments;

@@ -397,12 +405,18 @@ int main(

    asked_frame_size = arg.renderFramesize;
    uint16_t aeID = arg.aeSequence.count > 0 ? arg.aeSequence.pID[0] : 65535;

#ifdef LIB_DEC_REVISION
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain_fx, arg.dpidEnabled, aeID, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
#else
    if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.non_diegetic_pan_enabled, arg.non_diegetic_pan_gain_fx,
                                       arg.dpidEnabled, aeID, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
#endif
    {
        fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
        goto cleanup;
    }

    if ( ( error = IVAS_DEC_GetRenderFramesize( hIvasDec, &arg.renderFramesize ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
@@ -859,6 +873,9 @@ static bool parseCmdlIVAS_dec(
    {
        arg->directivityPatternId[i] = 65535;
    }
#ifdef OBJ_EDITING_EXAMPLE
    arg->objEditEnabled = false;
#endif

    /*-----------------------------------------------------------------*
     * Initialization
@@ -885,18 +902,30 @@ static bool parseCmdlIVAS_dec(

        if ( strcmp( argv_to_upper, "-VOIP" ) == 0 )
        {
#ifdef LIB_DEC_REVISION
            arg->voipMode = true;
#else
            arg->voipMode = 1;
#endif
            i++;
        }
        else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 )
        {
#ifdef LIB_DEC_REVISION
            arg->voipMode = true;
#else
            arg->voipMode = 1;
#endif
            arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP;
            i++;
        }
        else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 )
        {
#ifdef LIB_DEC_REVISION
            arg->voipMode = true;
#else
            arg->voipMode = 1;
#endif
            arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF;
            i++;
        }
@@ -977,6 +1006,11 @@ static bool parseCmdlIVAS_dec(
            {
                if ( !is_digits_only( argv[i] ) )
                {
#ifdef LIB_DEC_REVISION
                    fprintf( stderr, "Error: Render frame size is invalid or not specified!\n\n" );
                    usage_dec();
#endif

                    return false;
                }

@@ -1310,6 +1344,13 @@ static bool parseCmdlIVAS_dec(

            i += tmp;
        }
#ifdef OBJ_EDITING_EXAMPLE
        else if ( strcmp( argv_to_upper, "-OBJ_EDIT" ) == 0 )
        {
            arg->objEditEnabled = true;
            i++;
        }
#endif

        /*-----------------------------------------------------------------*
         * Option not recognized
@@ -1570,6 +1611,7 @@ static ivas_error initOnFirstGoodFrame(
        return error;
    }

#ifndef LIB_DEC_REVISION
    int32_t pcmFrameSize;

    if ( ( error = IVAS_DEC_GetPcmFrameSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK )
@@ -1577,7 +1619,7 @@ static ivas_error initOnFirstGoodFrame(
        fprintf( stderr, "\nError in IVAS_DEC_GetPcmFrameSize, error code: %d\n", error );
        return error;
    }

#endif
    if ( isSplitRend )
    {
        /* Open split rendering metadata writer */
@@ -1635,7 +1677,23 @@ static ivas_error initOnFirstGoodFrame(
        }
    }

#ifdef LIB_DEC_REVISION
    int16_t pcmFrameSize;
    if ( ( error = IVAS_DEC_GetOutputBufferSize( hIvasDec, &pcmFrameSize ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_GetOutputBufferSize, error code: %d\n", error );
        return error;
    }

#endif
    int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) );
#ifdef LIB_DEC_REVISION
    if ( zeroBuf == NULL )
    {
        fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" );
        return IVAS_ERR_FAILED_ALLOC;
    }
#endif
    memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) );

    for ( int16_t i = 0; i < numInitialBadFrames; ++i )
@@ -1846,7 +1904,25 @@ static ivas_error decodeG192(
    int16_t isSplitRend, isSplitCoded;
    IVAS_RENDER_CONFIG_DATA renderConfig;
    RenderConfigReader *renderConfigReader = NULL;
#ifdef OBJ_EDITING_API
#ifdef OBJ_EDITING_EXAMPLE
    IVAS_EDITABLE_PARAMETERS editableParameters;
#endif
#endif

#ifdef VARIABLE_SPEED_DECODING
#ifdef LIB_DEC_REVISION
    if ( arg.tsmEnabled )
    {
        if ( ( error = IVAS_DEC_EnableTsm( hIvasDec ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_DEC_EnableTsm, code: %d\n", error );
            return error;
        }
    }

#endif
#endif
    if ( ( error = IVAS_DEC_is_split_rendering_enabled( hIvasDec, &isSplitRend ) ) != IVAS_ERR_OK )
    {
        fprintf( stderr, "\nError in IVAS_DEC_is_split_rendering_enabled, code: %d\n", error );
@@ -2120,6 +2196,65 @@ static ivas_error decodeG192(
                }

#ifdef OBJ_EDITING_API
#ifdef OBJ_EDITING_EXAMPLE
                if ( arg.objEditEnabled )
                {

                    /* Do object info editing here */
                    /* get object parameters */
                    if ( ( error = IVAS_DEC_GetEditableParameters( hIvasDec, &editableParameters ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nError: could not get the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }

                    /* edit object parameters...*/

                    /* put the objects equally spaced at the horizontal plane */
                    /* and play a little bit with the gains... */
                    Word16 obj_idx, non_diegetic_obj_idx;
                    Word16 num_nondiegetic_objects;

                    num_nondiegetic_objects = 0;
                    for ( obj_idx = 0; obj_idx < editableParameters.num_obj; obj_idx++ )
                    {
                        if ( !editableParameters.ism_metadata[obj_idx].non_diegetic_flag )
                        {
                            num_nondiegetic_objects++;
                        }
                    }
                    if ( num_nondiegetic_objects )
                    {
                        float start_angle, angle_inc;
                        angle_inc = 360.0f / (float) num_nondiegetic_objects;
                        start_angle = angle_inc / 2.0f;
                        for ( obj_idx = 0, non_diegetic_obj_idx = 0; obj_idx < editableParameters.num_obj; obj_idx++ )
                        {
                            if ( !editableParameters.ism_metadata[obj_idx].non_diegetic_flag )
                            {
                                editableParameters.ism_metadata[obj_idx].elevation_fx = 0;
                                editableParameters.ism_metadata[obj_idx].azimuth_fx = (Word32) ( ( start_angle + (float) non_diegetic_obj_idx * angle_inc ) * powf( 2.0f, 22.0f ) );
                                non_diegetic_obj_idx++;
                            }
                        }
                    }

                    /* breakover object gains */
                    for ( obj_idx = 0; obj_idx < editableParameters.num_obj; obj_idx++ )
                    {
                        editableParameters.ism_metadata[obj_idx].gain_fx = (Word32) ( ( 0.5f + (float) ( ( frame + obj_idx * 50 ) % 250 ) / 250.0f ) * powf( 2.0f, 29.0f ) );
                    }

                    editableParameters.gain_bed_fx = ( 1 << 28 ); // 0.5 in Q29

                    /* set new object parameters*/
                    if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK )
                    {
                        fprintf( stderr, "\nError: could not set the editable parameters: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                        goto cleanup;
                    }
                }
#endif
                /* Do the final preparations needed for rendering */
                if ( ( error = IVAS_DEC_PrepareRenderer( hIvasDec ) ) != IVAS_ERR_OK )
                {
@@ -2142,7 +2277,11 @@ static ivas_error decodeG192(
            }
            else
            {
#ifdef LIB_DEC_REVISION
                if ( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
#else
                if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK )
#endif
                {
                    fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
@@ -2182,6 +2321,9 @@ static ivas_error decodeG192(
            {
                if ( ( error = initOnFirstGoodFrame( hIvasDec, arg, numInitialBadFrames, &nOutSamples, &vec_pos_len, delayNumSamples_orig, &delayNumSamples, &delayTimeScale, &bsFormat, &afWriter, &masaWriter, ismWriters, &nOutChannels, &numObj, &splitRendWriter ) ) != IVAS_ERR_OK )
                {
#ifdef LIB_DEC_REVISION
                    fprintf( stderr, "Error in initOnFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
#endif
                    goto cleanup;
                }
            }
@@ -2932,7 +3074,11 @@ static ivas_error decodeVoIP(
        {
            if ( ( error = IVAS_DEC_HasDecodedFirstGoodFrame( hIvasDec, &decodedGoodFrame ) ) != IVAS_ERR_OK )
            {
#ifdef LIB_DEC_REVISION
                fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
#else
                fprintf( stderr, "Error in IVAS_DEC_HasDecodedFirstGoodFrame, code: %d\n", error );
#endif
                goto cleanup;
            }

+3 −3
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ typedef struct _IVAS_ISM_METADATA
    Word32 elevation_fx;  /* Q22 */
    Word16 radius_fx;     /* Q9 */
    Word32 spread_fx;     /* Q22 */
    Word32 gainFactor_fx; /* Q31 */
    Word32 gainFactor_fx; /* Q29 */
    Word32 yaw_fx;        /* Q22 */
    Word32 pitch_fx;      /* Q22 */
    float azimuth;
@@ -138,7 +138,7 @@ typedef struct _IVAS_ISM_METADATA
    float pitch;
    Word16 non_diegetic_flag;
#ifdef OBJ_EDITING_API
    Word32 gain_fx;
    Word32 gain_fx; // Q29
#endif

} IVAS_ISM_METADATA;
@@ -148,7 +148,7 @@ typedef struct _IVAS_EDITABLE_PARAMETERS
{
    Word16 num_obj;
    IVAS_ISM_METADATA ism_metadata[IVAS_MAX_NUM_OBJECTS];
    Word32 gain_bed_fx;
    Word32 gain_bed_fx; // Q29
} IVAS_EDITABLE_PARAMETERS;
#endif

+6 −1
Original line number Diff line number Diff line
@@ -1256,10 +1256,15 @@ enum
#define MASA_MAXIMUM_TWO_DIR_BANDS              24
#define NBITS_HR_COH                            4
#define OMASA_TDREND_MATCHING_GAIN_FX 26026
//TODO: insert proper Q representations
#ifdef OMASA_OBJECT_EDITING
#define OMASA_GAIN_EDIT_THR_FX                  246                         /* OMASA gain change threshold, 0.06f in Q12 */
#define OMASA_AZI_EDIT_THR_FX                   ONE_IN_Q22                  /* OMASA-DISC azimuth change threshold, 1.0f in Q22 */
#define OMASA_ELE_EDIT_THR_FX                   ONE_IN_Q23                  /* OMASA-DISC elevation change threshold, 2.0f in Q22 */
#endif

#define MASA_INV_ANGLE_AT_EQUATOR_DEG_Q30       1453366656l                 /* 1.353553128183453f in Q30 */


#define MASA_JBM_RINGBUFFER_FRAMES              3
#define TOLERANCE_360_Q22                       1510033326                  /* 360 in Q22 + 0.02 in Q22*/
#define MINUS_TOLERANCE_360_Q22                 -1510033326                 /* - (360 in Q22 + 0.02 in Q22) */
+2 −2
Original line number Diff line number Diff line
@@ -471,13 +471,13 @@ void ivas_ism_reset_metadata(
    move16();

#ifdef OBJ_EDITING_API
    hIsmMeta->edited_gain_fx = ONE_IN_Q31;
    hIsmMeta->edited_gain_fx = ONE_IN_Q29;
    hIsmMeta->edited_azimuth_fx = 0;
    hIsmMeta->edited_elevation_fx = 0;
    hIsmMeta->edited_pitch_fx = 0;
    hIsmMeta->edited_yaw_fx = 0;
    hIsmMeta->edited_radius_fx = ONE_IN_Q9;
    hIsmMeta->gain_fx = ONE_IN_Q31;
    hIsmMeta->gain_fx = ONE_IN_Q29;
    hIsmMeta->non_diegetic_flag = 0;
#endif

+58 −2
Original line number Diff line number Diff line
@@ -41,13 +41,19 @@
#include <assert.h>
#include "ivas_prot_fx.h"


#ifdef FIX_2089_NONBE_LIMITER_CONSTS
#define RELEASE_CNST_20MS   ( 85899345 ) // Q30
#define RELEASE_CNST_2_20MS ( 21474836 ) // Q30
#define RELEASE_CNST_10MS   ( 42949672 ) // Q30
#define RELEASE_CNST_2_10MS ( 10737418 ) // Q30
#define RELEASE_CNST_5MS    ( 21474836 ) // Q30
#define RELEASE_CNST_2_5MS  ( 5368709 )  // Q30
#endif
#define ATTACK_CNST_48k ( 2106670080 ) // Q31
#define ATTACK_CNST_32k ( 2086555136 ) // Q31
#define ATTACK_CNST_16k ( 2027355264 ) // Q31
#define ATTACK_CNST_8k  ( 1913946752 ) // Q31


/*-------------------------------------------------------------------*
 * detect_strong_saturations()
 *
@@ -349,6 +355,55 @@ void limiter_process_fx(
     * keep the gain curve smoother if the threshold is exceeded in many frames
     * in a short span of time.
     */
#ifdef FIX_2089_NONBE_LIMITER_CONSTS
    IF( EQ_32( L_mult0( output_frame, 50 ), hLimiter->sampling_rate ) )
    {
        releaseHeuristic_cnst = RELEASE_CNST_20MS;
        move32();
        releaseHeuristic_cnst_2 = RELEASE_CNST_2_20MS;
        move32();
    }
    ELSE IF( EQ_32( L_mult0( output_frame, 100 ), hLimiter->sampling_rate ) )
    {
        releaseHeuristic_cnst = RELEASE_CNST_10MS;
        move32();
        releaseHeuristic_cnst_2 = RELEASE_CNST_2_10MS;
        move32();
    }
    ELSE IF( EQ_32( L_mult0( output_frame, 200 ), hLimiter->sampling_rate ) )
    {
        releaseHeuristic_cnst = RELEASE_CNST_5MS;
        move32();
        releaseHeuristic_cnst_2 = RELEASE_CNST_2_5MS;
        move32();
    }
    ELSE
    {
#ifdef FIX_2089_NONBE_LIMITER_CONSTS_WITH_DIV
        // computing output_frame/hLimiter->sampling_rate in Q30
        i = norm_s( output_frame );
        c = norm_l( hLimiter->sampling_rate );
        scale = extract_h( L_shl( hLimiter->sampling_rate, c ) );
        idx = shl( output_frame, i );
        IF( GT_16( idx, scale ) )
        {
            idx = shr( idx, 1 );
            i = sub( i, 1 );
        }
        scale = div_s( idx, scale );
        i = sub( sub( c, i ), 1 ); // Q30
        releaseHeuristic_cnst_2 = L_shl( scale, i );
        releaseHeuristic_cnst = L_shl( releaseHeuristic_cnst_2, 2 );
#else
        /* or same default values as previous code version */
        releaseHeuristic_cnst = RELEASE_CNST_5MS;
        move32();
        releaseHeuristic_cnst_2 = RELEASE_CNST_2_5MS;
        move32();
#endif
    }

#else
    SWITCH( output_frame )
    {
        case 960:
@@ -367,6 +422,7 @@ void limiter_process_fx(
            move32();
            BREAK;
    }
#endif
    releaseHeuristic = hLimiter->release_heuristic_fx; /* Q30 */
    move32();

Loading