Commit b01be322 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 81cdb4b6 61b27367
Loading
Loading
Loading
Loading
+107 −26
Original line number Diff line number Diff line
@@ -51,11 +51,6 @@
#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
@@ -140,7 +135,7 @@ typedef struct
    AcousticEnvironmentSequence aeSequence;
    bool dpidEnabled;
    uint16_t directivityPatternId[IVAS_MAX_NUM_OBJECTS];
#ifdef OBJ_EDITING_EXAMPLE
#ifdef OBJ_EDITING_COMMANDLINE
    bool objEditEnabled;
#endif

@@ -174,6 +169,9 @@ static void usage_dec( void );
static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf );
static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec );
static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs );
#ifdef OBJ_EDITING_EXAMPLE
static void do_object_editing_fx( IVAS_EDITABLE_PARAMETERS *editableParameters );
#endif


/*------------------------------------------------------------------------------------------*
@@ -407,7 +405,15 @@ int main(
    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 )
#ifdef OBJ_EDITING_COMMANDLINE
    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.objEditEnabled, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK )
#else
    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 )
#endif
#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 )
@@ -873,7 +879,7 @@ static bool parseCmdlIVAS_dec(
    {
        arg->directivityPatternId[i] = 65535;
    }
#ifdef OBJ_EDITING_EXAMPLE
#ifdef OBJ_EDITING_COMMANDLINE
    arg->objEditEnabled = false;
#endif

@@ -1344,7 +1350,7 @@ static bool parseCmdlIVAS_dec(

            i += tmp;
        }
#ifdef OBJ_EDITING_EXAMPLE
#ifdef OBJ_EDITING_COMMANDLINE
        else if ( strcmp( argv_to_upper, "-OBJ_EDIT" ) == 0 )
        {
            arg->objEditEnabled = true;
@@ -1539,6 +1545,10 @@ static void usage_dec( void )
    fprintf( stdout, "                      without braces and spaces, with ':' character separating ID from duration and ',' separating\n" );
    fprintf( stdout, "                      ID and duration pairs, where duration is specified in frames\n" );
    fprintf( stdout, "                      for BINAURAL_ROOM_REVERB output configuration.\n" );
#ifdef OBJ_EDITING_COMMANDLINE
    fprintf( stdout, "-obj_edit           : Enable objects editing\n" );
#endif

    fprintf( stdout, "-level level        : Complexity level, level = (1, 2, 3), will be defined after characterisation. \n" );
    fprintf( stdout, "                      Currently, all values default to level 3 (full functionality).\n" );
    fprintf( stdout, "-q                  : Quiet mode, no frame counter\n" );
@@ -1904,11 +1914,6 @@ 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
@@ -2196,18 +2201,21 @@ static ivas_error decodeG192(
                }

#ifdef OBJ_EDITING_API
#ifdef OBJ_EDITING_EXAMPLE
                /* Object metadata editing */
                if ( arg.objEditEnabled )
                {
                    IVAS_EDITABLE_PARAMETERS editableParameters;

                    /* 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;
                        return error;
                    }

#ifdef OBJ_EDITING_EXAMPLE
                    /* Do object metadata editing here ... */
                    do_object_editing_fx( &editableParameters );
#else
                    /* edit object parameters...*/

                    /* put the objects equally spaced at the horizontal plane */
@@ -2246,6 +2254,7 @@ static ivas_error decodeG192(
                    }

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

                    /* set new object parameters*/
                    if ( ( error = IVAS_DEC_SetEditableParameters( hIvasDec, editableParameters ) ) != IVAS_ERR_OK )
@@ -2254,7 +2263,7 @@ static ivas_error decodeG192(
                        goto cleanup;
                    }
                }
#endif

                /* Do the final preparations needed for rendering */
                if ( ( error = IVAS_DEC_PrepareRenderer( hIvasDec ) ) != IVAS_ERR_OK )
                {
@@ -2283,7 +2292,7 @@ static ivas_error decodeG192(
                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 ) );
                    fprintf( stderr, "\nError in IVAS_DEC_GetSamplesRenderer(): %s\n", IVAS_DEC_GetErrorMessage( error ) );
                    goto cleanup;
                }
                nSamplesRendered += nSamplesRendered_loop;
@@ -2298,7 +2307,6 @@ static ivas_error decodeG192(
                    fprintf( stdout, "%-8d\b\b\b\b\b\b\b\b", frame );
                }
            }

        } while ( nSamplesRendered < nOutSamples && error == IVAS_ERR_OK );


@@ -2715,7 +2723,7 @@ static ivas_error decodeVoIP(
    int16_t nOutSamples = 0;
    bool bitstreamReadDone = false;
#ifdef OBJ_EDITING_API
    bool parametersAvailableForEditing = false;
    bool parameterAvailableForEditing = false;
#endif
    uint16_t nSamplesRendered;

@@ -3003,13 +3011,13 @@ static ivas_error decodeVoIP(
        {
#ifdef SUPPORT_JBM_TRACEFILE
#ifdef OBJ_EDITING_API
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, &parametersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, &parameterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, writeJbmTraceFileFrameWrapper, jbmTraceWriter, &bitstreamReadDone, &nSamplesRendered, systemTime_ms ) ) != IVAS_ERR_OK )
#endif
#else
#ifdef OBJ_EDITING_API
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, &bitstreamReadDone, &parametersAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, &bitstreamReadDone, &parameterAvailableForEditing, systemTime_ms ) ) != IVAS_ERR_OK )
#else
            if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, (void *) pcmBuf, &bitstreamReadDone, systemTime_ms ) ) != IVAS_ERR_OK )
#endif
@@ -3044,9 +3052,29 @@ static ivas_error decodeVoIP(
            }

#ifdef OBJ_EDITING_API
            if ( parametersAvailableForEditing == true )
            /* Object metadata editing */
            if ( arg.objEditEnabled && parameterAvailableForEditing == true )
            {
                IVAS_EDITABLE_PARAMETERS editableParameters;

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

                /* Do object metadata editing here ... */
#ifdef OBJ_EDITING_EXAMPLE
                do_object_editing_fx( &editableParameters );

#endif
                /* 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 ) );
                    return error;
                }
            }
#endif
        } /* while ( nSamplesRendered < nOutSamples ) */
@@ -3338,6 +3366,59 @@ cleanup:
    return error;
}

#ifdef OBJ_EDITING_EXAMPLE

/*---------------------------------------------------------------------*
 * do_object_editing()
 *
 * Example function to edit objects parameters
 *---------------------------------------------------------------------*/

static void do_object_editing_fx(
    IVAS_EDITABLE_PARAMETERS *editableParameters )
{
    /* 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 ) * 4194304 /* Q22 */ );
                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 ) * 536870912 /*Q29*/ );
    }

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

    return;
}

#endif

/*---------------------------------------------------------------------*
 * load_hrtf_from_file()
+3 −2
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ typedef struct _IVAS_ISM_METADATA
    float pitch;
    Word16 non_diegetic_flag;
#ifdef OBJ_EDITING_API
    Word32 gain_fx; // Q29
    Word32 gain_fx; /* Q29 */
#endif

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

} IVAS_EDITABLE_PARAMETERS;
#endif

+7 −0
Original line number Diff line number Diff line
@@ -77,6 +77,9 @@ typedef enum
    IVAS_ERR_EXT_ORIENTATION_NOT_SUPPORTED,
    IVAS_ERR_DIRECTIVITY_NOT_SUPPORTED,
    IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED,
#ifdef OBJ_EDITING_API
    IVAS_ERR_OBJECTS_EDITING_NOT_SUPPORTED,
#endif
    IVAS_ERR_INVALID_HRTF,
    IVAS_ERR_INVALID_HRTF_SAMPLING_RATE,
    IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA,
@@ -249,6 +252,10 @@ static inline const char *ivas_error_to_string( ivas_error error_code )
            return "Directivity not supported";
        case IVAS_ERR_ACOUSTIC_ENVIRONMENT_NOT_SUPPORTED:
            return "Acoustic environment not supported";
#ifdef OBJ_EDITING_API
        case IVAS_ERR_OBJECTS_EDITING_NOT_SUPPORTED:
            return "Objects editing not supported";
#endif
        case IVAS_ERR_INVALID_HRTF:
            return "Unsupported HRTF filter set";
        case IVAS_ERR_INVALID_HRTF_SAMPLING_RATE:
+8 −0
Original line number Diff line number Diff line
@@ -472,13 +472,21 @@ void ivas_ism_reset_metadata(

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

    return;
+26 −20
Original line number Diff line number Diff line
@@ -783,12 +783,6 @@ ivas_error ivas_ism_metadata_dec_fx(
    DEC_CORE_HANDLE st0                                         /* i  : core-coder handle                       */
);

#ifdef OBJ_EDITING_API
void ivas_ism_renderer_update_md(
	Decoder_Struct *st_ivas                                     /* i/o:  main IVAS decoder handle                   */
);
#endif

void ivas_get_ism_sid_quan_bitbudget_fx(
    const Word16 nchan_ism,                                     /* i  : number of objects                       */
    Word16 *nBits_azimuth,                                      /* o  : number of Q bits for azimuth            */
@@ -3930,6 +3924,17 @@ ivas_error ivas_osba_render_sf_fx(
    Word32 *p_output[]                                          /* o  : rendered time signal                        */
);

#ifdef OBJ_EDITING_API
void ivas_osba_stereo_add_channels_fx(
    Word32 *tc_fx[],                                            /* i  : transport channels                          */
    Word32 *output_fx[],                                        /* i/o: output channels                             */
    const Word32 gain_bed_fx,                                   /* i  : gain bed value Q11                          */
    const Word16 nchan_out,                                     /* i  : number of output channels                   */
    const Word16 nchan_ism,                                     /* i  : number of ISM channels                      */
    const Word16 ism_mode,                                      /* i  : ISM mode                                    */
    const UWord16 n_samples_to_render                           /* i  : output frame length per channel             */
);
#else
void ivas_osba_stereo_add_channels_fx(
    Word32 *tc_fx[],                                            /* i  : transport channels                          */
    Word32 *output_fx[],                                        /* i/o: output channels                             */
@@ -3938,6 +3943,7 @@ void ivas_osba_stereo_add_channels_fx(
    const Word16 nchan_ism,                                     /* i  : number of ISM channels                      */
    const UWord16 n_samples_to_render                           /* i  : output frame length per channel             */
);
#endif

void ivas_osba_data_close_fx(
    SBA_ISM_DATA_HANDLE *hSbaIsmData                            /* i/o: OSBA rendering handle                       */
@@ -4254,7 +4260,7 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx(
);

#ifdef OBJ_EDITING_API
void ivas_jbm_dec_prepare_renderer(
void ivas_dec_prepare_renderer_fx(
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder structure                                      */
);
#endif
@@ -4346,20 +4352,20 @@ void ivas_ism_dec_digest_tc_fx(

void ivas_param_ism_dec_digest_tc_fx(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                         */
    const UWord16 nCldfbSlots,                                  /* i  : number of CLFBS slots in the transport channels         */
    const UWord16 nCldfbSlots,                                  /* i  : number of CLDFB slots in transport channels */
    Word32 *transport_channels[],                               /* i  : synthesized core-coder transport channels/DirAC output  */
    Word16 q_tc_in 
    const Word16 q_tc_in 
);


#ifdef OBJ_EDITING_API
void ivas_param_ism_dec_dequant_md_fx(
    Decoder_Struct *st_ivas 
    Decoder_Struct *st_ivas                                     /* i/o: IVAS decoder handle                         */
);

void ivas_param_ism_dec_prepare_renderer_fx(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                         */
    const Word16 nCldfbSlots                                  /* i  : number of CLFBS slots in the transport channels         */
    const Word16 nCldfbSlots                                    /* i  : number of CLDFB slots in transport channels */
);
#endif

@@ -5157,8 +5163,8 @@ void ivas_param_mc_dec_close_fx(
void ivas_param_mc_dec_digest_tc_fx(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                             */
    const UWord8 nCldfbSlots,                                   /* i  : number of CLFBS slots in the transport channels */
    Word32 *transport_channels_f_fx[],
    Word16 transport_f_e 
    Word32 *p_data_fx[],                                        /* i/o: synthesized core-coder transport channels/DirAC output */
    const Word16 transport_f_e
);

#ifdef OBJ_EDITING_API
@@ -6618,7 +6624,7 @@ void ivas_mc_paramupmix_dec_read_BS(
    Word16 *nb_bits                                             /* o  : number of bits written                  */
);

void ivas_mc_paramupmix_dec_digest_tc(
void ivas_mc_paramupmix_dec_digest_tc_fx(
    Decoder_Struct *st_ivas,                                    /* i/o: IVAS decoder handle                     */
    const UWord8 nCldfbSlots,                                   /* i  : number of CLFBS slots in the transport channels */
    const Word16 nSamplesForRendering                           /* i  : number of samples provided              */
Loading