From 6d4b7ea192c831af553bb3210e4c8029fccf05c7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 10:17:27 +0100 Subject: [PATCH 01/19] add error codes for orientation tracking --- apps/renderer.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 46102c54b6..9a3986a77c 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -761,7 +761,7 @@ int main( } #ifdef FIX_I109_ORIENTATION_TRACKING - if ( IVAS_REND_SetOrientationTrackingMode( hIvasRend, args.orientationTracking ) ) + if ( ( error = IVAS_REND_SetOrientationTrackingMode( hIvasRend, args.orientationTracking ) ) != IVAS_ERR_OK ) { return error; } @@ -988,17 +988,18 @@ int main( { IVAS_QUATERNION quaternion; #ifdef TD5 - if ( HeadRotationFileReading( referenceRotReader, &quaternion, NULL ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReading( referenceRotReader, &quaternion, NULL ) ) != IVAS_ERR_OK ) #else if ( HeadRotationFileReading( referenceRotReader, &quaternion ) != IVAS_ERR_OK ) #endif { - fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); + fprintf( stderr, "Error in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } - if ( IVAS_REND_SetReferenceRotation( hIvasRend, quaternion ) != IVAS_ERR_OK ) + + if ( ( error = IVAS_REND_SetReferenceRotation( hIvasRend, quaternion ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "Error setting Reference Rotation.\r\n" ); + fprintf( stderr, "Error setting Reference Rotation: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } } @@ -1008,16 +1009,17 @@ int main( if ( headRotReader != NULL ) { IVAS_QUATERNION quatBuffer[RENDERER_HEAD_POSITIONS_PER_FRAME]; + #ifdef FIX_I109_ORIENTATION_TRACKING for ( i = 0; i < RENDERER_HEAD_POSITIONS_PER_FRAME; i++ ) { #ifdef TD5 - if ( HeadRotationFileReading( headRotReader, &quatBuffer[i], &Pos[i] ) != IVAS_ERR_OK ) + if ( ( error = HeadRotationFileReading( headRotReader, &quatBuffer[i], &Pos[i] ) ) != IVAS_ERR_OK ) #else if ( HeadRotationFileReading( headRotReader, &quatBuffer[i] ) != IVAS_ERR_OK ) #endif { - fprintf( stderr, "Error in Head Rotation File Reading.\r\n" ); + fprintf( stderr, "Error in Head Rotation File Reading: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } } @@ -1029,24 +1031,24 @@ int main( #endif #endif #ifdef TD5 - if ( IVAS_REND_SetHeadRotation( hIvasRend, quatBuffer, Pos ) != IVAS_ERR_OK ) + if ( ( error = IVAS_REND_SetHeadRotation( hIvasRend, quatBuffer, Pos ) ) != IVAS_ERR_OK ) #else if ( IVAS_REND_SetHeadRotation( hIvasRend, quatBuffer ) != IVAS_ERR_OK ) #endif { - fprintf( stderr, "Error setting Head Rotation\n" ); + fprintf( stderr, "Error setting Head Rotation: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } } else { #ifdef TD5 - if ( ( IVAS_REND_SetHeadRotation( hIvasRend, NULL, NULL ) != IVAS_ERR_OK ) && ( IVAS_REND_SetHeadRotation( hIvasRend, NULL, NULL ) != IVAS_ERR_INVALID_OUTPUT_FORMAT ) ) + if ( ( ( error = IVAS_REND_SetHeadRotation( hIvasRend, NULL, NULL ) ) != IVAS_ERR_OK ) && ( IVAS_REND_SetHeadRotation( hIvasRend, NULL, NULL ) != IVAS_ERR_INVALID_OUTPUT_FORMAT ) ) // VE: TBC #else if ( ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_OK ) && ( IVAS_REND_SetHeadRotation( hIvasRend, NULL ) != IVAS_ERR_INVALID_OUTPUT_FORMAT ) ) #endif { - fprintf( stderr, "Error setting Head Rotation\n" ); + fprintf( stderr, "Error setting Head Rotation: %s\n", ivas_error_to_string( error ) ); exit( -1 ); } } -- GitLab From 93c37bbd73e17ecc2156fdf360462e308938e2d4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 10:37:28 +0100 Subject: [PATCH 02/19] comments/formatting within MD5 --- lib_com/ivas_prot.h | 6 ++-- lib_dec/ivas_ism_metadata_dec.c | 45 ++++++++++++++++++++---------- lib_dec/lib_dec.c | 4 +-- lib_enc/ivas_ism_metadata_enc.c | 49 ++++++++++++++++++++------------- lib_enc/ivas_stat_enc.h | 7 ++--- lib_enc/lib_enc.c | 1 + 6 files changed, 69 insertions(+), 43 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a0506e7473..194559ee79 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -783,9 +783,9 @@ ivas_error ivas_set_ism_metadata( const float azimuth, /* i : azimuth value */ #ifdef TD5 const float elevation, /* i : elevation value */ - float radius_meta, /* i : radius */ - float yaw, /* i : yaw */ - float pitch /* i : pitch */ + const float radius_meta, /* i : radius */ + const float yaw, /* i : yaw */ + const float pitch /* i : pitch */ #else const float elevation /* i : elevation value */ #endif diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 7c8946fc43..4b604c3b8c 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -42,13 +42,15 @@ #endif #include "wmc_auto.h" -/* Local Functions */ + #ifdef TD5 /*-----------------------------------------------------------------------* * Local functions *-----------------------------------------------------------------------*/ + static void decode_angle_indices( DEC_CORE_HANDLE st0, ISM_METADATA_ANGLE_HANDLE angle, int16_t *flag_abs_azimuth ); -int16_t decode_radius( DEC_CORE_HANDLE st0, int16_t *last_radius_idx, int16_t *flag_abs_radius ); + +static int16_t decode_radius( DEC_CORE_HANDLE st0, int16_t *last_radius_idx, int16_t *flag_abs_radius ); #endif /*-------------------------------------------------------------------------* @@ -172,12 +174,15 @@ ivas_error ivas_ism_metadata_dec( /* IVAS_fmToDo: more work needed when the number of transported objects is not constant */ return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); } + #ifdef TD5 + /* read extended metadata presence flag */ if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) { ism_extended_metadata_flag = get_next_indice( st0, ISM_EXTENDED_METADATA_BITS ); } #endif + /* Read ISm present flags (one per object) */ for ( ch = 0; ch < *nchan_transport; ch++ ) { @@ -241,6 +246,7 @@ ivas_error ivas_ism_metadata_dec( flag_abs_orientation = 0; flag_abs_radius = 0; #endif + if ( hIsmMeta[ch]->ism_metadata_flag ) { #ifdef TD5 @@ -631,18 +637,26 @@ ivas_error ivas_ism_metadata_dec_create( return IVAS_ERR_OK; } + #ifdef TD5 +/*------------------------------------------------------------------------- + * decode_angle_indices() + * + * Decoding of an angle + *-------------------------------------------------------------------------*/ + static void decode_angle_indices( DEC_CORE_HANDLE st0, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ int16_t *flag_abs_azimuth /* o : Azimuth encoding mode */ ) { + int16_t idx_azimuth, nbits_diff_azimuth, diff, sgn; + int16_t idx_elevation, nbits_diff_elevation; + /*----------------------------------------------------------------* * Azimuth decoding and dequantization *----------------------------------------------------------------*/ - int16_t idx_azimuth, nbits_diff_azimuth, diff, sgn; - int16_t idx_elevation, nbits_diff_elevation; /* Decode azimuth index */ if ( get_next_indice( st0, 1 ) == 1 ) /* azimuth_abs_flag */ @@ -759,28 +773,32 @@ static void decode_angle_indices( { idx_elevation = angle->last_elevation_idx; } + /*----------------------------------------------------------------* * Final updates *----------------------------------------------------------------*/ - /* updates */ angle->last_azimuth_idx = idx_azimuth; angle->last_elevation_idx = idx_elevation; + return; } -int16_t decode_radius( + +/*------------------------------------------------------------------------- + * decode_radius() + * + * Radius decoding and dequantization + *-------------------------------------------------------------------------*/ + +static int16_t decode_radius( DEC_CORE_HANDLE st0, /* i/o: bitstream handle */ int16_t *last_radius_idx, /* i/o: last radius index */ int16_t *flag_abs_radius /* o : Radius encoding mode */ ) { - /*----------------------------------------------------------------* - * Radius decoding and dequantization - *----------------------------------------------------------------*/ int16_t idx_radius, nbits_diff_radius, diff, sgn; - /* Decode radius index */ if ( get_next_indice( st0, 1 ) == 1 ) /* elevation_abs_flag */ { @@ -829,12 +847,9 @@ int16_t decode_radius( idx_radius = *last_radius_idx; } - /*----------------------------------------------------------------* - * Final updates - *----------------------------------------------------------------*/ - - /* updates */ + /* Final updates */ *last_radius_idx = idx_radius; + return idx_radius; } #endif diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index da9c6efae4..3dd712b934 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -890,10 +890,10 @@ ivas_error IVAS_DEC_GetMasaMetadata( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_FeedHeadTrackData( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ #ifdef TD5 IVAS_QUATERNION *orientation, /* i : head-tracking data, listener orientation */ - IVAS_POSITION *Pos /* i : listener position */ + IVAS_POSITION *Pos /* i : listener position */ #else IVAS_QUATERNION *orientation /* i : head-tracking data, listener orientation */ #endif diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 3472de0c5a..c10eda7640 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -70,6 +70,7 @@ * Local functions *-----------------------------------------------------------------------*/ static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, ISM_METADATA_ANGLE_HANDLE angle, const int16_t last_ism_metadata_flag, const int16_t ini_frame, const int16_t idx_azimuth_abs, const int16_t idx_elevation_abs, int16_t *flag_abs_azimuth, int16_t *flag_abs_elevation ); + static void encode_radius( BSTR_ENC_HANDLE hBstr, int16_t *last_radius_idx, int16_t *radius_diff_cnt, const int16_t last_ism_metadata_flag, const int16_t idx_radius_abs, int16_t *flag_abs_radius ); #endif @@ -84,10 +85,10 @@ ivas_error ivas_set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* o : ISM metadata handle */ const float azimuth, /* i : azimuth value */ #ifdef TD5 - const float elevation, /* i : elevation */ - float radius_meta, /* i : radius */ - float yaw, /* i : yaw */ - float pitch /* i : pitch */ + const float elevation, /* i : elevation */ + const float radius_meta, /* i : radius */ + const float yaw, /* i : yaw */ + const float pitch /* i : pitch */ #else const float elevation /* i : elevation value */ #endif @@ -108,6 +109,7 @@ ivas_error ivas_set_ism_metadata( hIsmMeta->yaw = yaw; hIsmMeta->pitch = pitch; #endif + return IVAS_ERR_OK; } @@ -246,7 +248,6 @@ ivas_error ivas_ism_metadata_enc( set_s( flag_abs_radius, 0, num_obj ); #endif - /*----------------------------------------------------------------* * Set Metadata presence / importance flag *----------------------------------------------------------------*/ @@ -352,12 +353,15 @@ ivas_error ivas_ism_metadata_enc( push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); } push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); + #ifdef TD5 + /* write extended metadata presence flag */ if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) { push_indice( hBstr, IND_ISM_EXTENDED_FLAG, ism_extended_metadata_flag, ISM_EXTENDED_METADATA_BITS ); } #endif + /* write ISm metadata flag (one per object) */ for ( ch = 0; ch < nchan_transport; ch++ ) { @@ -406,11 +410,11 @@ ivas_error ivas_ism_metadata_enc( if ( hIsmMeta[ch]->ism_metadata_flag ) { - #ifdef TD5 /*----------------------------------------------------------------* * Obtain quantizer indices for azimuth and elevation *----------------------------------------------------------------*/ + if ( ism_mode == ISM_MODE_DISC ) { idx_azimuth_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ); @@ -433,6 +437,7 @@ ivas_error ivas_ism_metadata_enc( encode_angle_indices( hBstr, &( hIsmMetaData->angle[1] ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_azimuth_abs, idx_elevation_abs, &flag_abs_azimuth_orientation[ch], &flag_abs_elevation[ch] ); encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); } + /* save number of metadata bits written */ if ( ism_mode == ISM_MODE_DISC ) { @@ -860,6 +865,7 @@ ivas_error ivas_ism_metadata_enc( return error; } + /*------------------------------------------------------------------------- * ivas_ism_metadata_enc_create() * @@ -926,7 +932,14 @@ ivas_error ivas_ism_metadata_enc_create( return IVAS_ERR_OK; } + #ifdef TD5 +/*------------------------------------------------------------------------- + * encode_radius() + * + * Radius index encoding + *-------------------------------------------------------------------------*/ + static void encode_radius( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ int16_t *last_radius_idx, /* i/o: last radius index */ @@ -938,14 +951,8 @@ static void encode_radius( { int16_t idx_radius, nbits_diff_radius, diff; - - /*----------------------------------------------------------------* - * Radius index encoding - *----------------------------------------------------------------*/ idx_radius = idx_radius_abs; - nbits_diff_radius = 0; - *flag_abs_radius = 0; /* differential coding by default */ if ( *radius_diff_cnt == ISM_FEC_MAX /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ @@ -1023,17 +1030,23 @@ static void encode_radius( push_indice( hBstr, IND_ISM_RADIUS, idx_radius, nbits_diff_radius ); } - /*----------------------------------------------------------------* - * Updates - *----------------------------------------------------------------*/ + /* Updates */ *last_radius_idx = idx_radius_abs; + return; } + +/*----------------------------------------------------------------* + * encode_angle_indices() + * + * Encoding of an angle + *----------------------------------------------------------------*/ + static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ ISM_METADATA_ANGLE_HANDLE angle, /* i/o: angle handle */ - const int16_t last_ism_metadata_flag, /* last frame ism_metadata_flag */ + const int16_t last_ism_metadata_flag, /* i : last frame ism_metadata_flag */ const int16_t ini_frame, /* i : initialization frames counter */ const int16_t idx_azimuth_abs, /* i : Azimuth index */ const int16_t idx_elevation_abs, /* i : Elevation index */ @@ -1044,7 +1057,6 @@ static void encode_angle_indices( int16_t idx_azimuth, nbits_diff_azimuth, diff; int16_t idx_elevation, nbits_diff_elevation; - /*----------------------------------------------------------------* * Azimuth index encoding *----------------------------------------------------------------*/ @@ -1145,10 +1157,9 @@ static void encode_angle_indices( /*----------------------------------------------------------------* * Elevation index encoding *----------------------------------------------------------------*/ - idx_elevation = idx_elevation_abs; + idx_elevation = idx_elevation_abs; nbits_diff_elevation = 0; - *flag_abs_elevation = 0; /* differential coding by default */ if ( angle->elevation_diff_cnt == ISM_FEC_MAX /* make differential encoding in ISM_FEC_MAX consecutive frames at maximum (in order to control the decoding in FEC) */ || last_ism_metadata_flag == 0 /* If last frame had no metadata coded, do not use differential coding */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 896dc0563b..1256955e87 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1013,6 +1013,9 @@ typedef struct encoder_config_structure int16_t sba_order; /* Ambisonic (SBA) order */ int16_t sba_planar; /* Ambisonic (SBA) planar flag */ MC_LS_SETUP mc_input_setup; /* multichannel input ls setup */ +#ifdef TD5 + int16_t ism_extended_metadata_flag; /* flag indicating extended metadata encoding, including radius and orientation (yaw, pitch) in ISM format */ +#endif int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ @@ -1027,10 +1030,6 @@ typedef struct encoder_config_structure int16_t Opt_SC_VBR; /* flag indicating SC-VBR mode */ int16_t last_Opt_SC_VBR; /* flag indicating prev frame's SC-VBR mode */ -#ifdef TD5 - int16_t ism_extended_metadata_flag; /* flag indicating whether extended metadata encoding, including radius and orientation (yaw, pitch) */ -#endif - /* temp. development parameters */ int16_t Opt_PCA_ON; /* flag indicating PCA operation in SBA */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 3742dbcfdc..a63788356b 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2013,6 +2013,7 @@ static ivas_error sanitizeBitrateISM( { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } + #ifdef TD5 if ( hEncoderConfig->ivas_total_brate < ISM_EXTENDED_METADATA_BRATE && hEncoderConfig->ism_extended_metadata_flag == 1 ) { -- GitLab From 1d70aebbf790c48e57580cb6b0206b4311b64d4b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 10:42:55 +0100 Subject: [PATCH 03/19] comments/formal issues in ivas_orient_trk.c --- lib_rend/ivas_orient_trk.c | 224 +++++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 94 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 58ae7fd457..750b10ae44 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -60,94 +60,31 @@ *------------------------------------------------------------------------------------------*/ #ifdef FIX_I109_ORIENTATION_TRACKING - /*------------------------------------------------------------------------------------------* - * Declarations + * IdentityQuaternion() + * + * *------------------------------------------------------------------------------------------*/ -static IVAS_QUATERNION IdentityQuaternion( - void ); - -void QuaternionProduct( - const IVAS_QUATERNION q1, - const IVAS_QUATERNION q2, - IVAS_QUATERNION *const result ); - -float QuaternionDotProduct( - const IVAS_QUATERNION q1, - const IVAS_QUATERNION q2 ); - -void QuaternionDivision( - const IVAS_QUATERNION q, - const float d, - IVAS_QUATERNION *const result ); - -void QuaternionNormalize( - const IVAS_QUATERNION q, - IVAS_QUATERNION *const result ); - -void QuaternionSlerp( - const IVAS_QUATERNION q1, - const IVAS_QUATERNION q2, - const float t, - IVAS_QUATERNION *const result ); - -void QuaternionConjugate( - const IVAS_QUATERNION q, - IVAS_QUATERNION *const result ); - -float QuaternionAngle( - const IVAS_QUATERNION q1, - const IVAS_QUATERNION q2 ); - -void QuaternionInverse( - const IVAS_QUATERNION q, - IVAS_QUATERNION *const result ); - -#ifdef OTR_REFERENCE_VECTOR_TRACKING -float QuaternionLength( - const IVAS_QUATERNION q ); - -IVAS_VECTOR3 VectorSubtract( - const IVAS_VECTOR3 p1, - const IVAS_VECTOR3 p2 ); - -IVAS_VECTOR3 VectorCrossProduct( - const IVAS_VECTOR3 p1, - const IVAS_VECTOR3 p2 ); - -float VectorDotProduct( - const IVAS_VECTOR3 p1, - const IVAS_VECTOR3 p2 ); - -float VectorLength( - const IVAS_VECTOR3 p ); - -IVAS_VECTOR3 VectorNormalize( - const IVAS_VECTOR3 p ); - -void VectorRotationToQuaternion( - const IVAS_VECTOR3 p1, - const IVAS_VECTOR3 p2, - IVAS_QUATERNION *const result ); -#endif /* OTR_REFERENCE_VECTOR_TRACKING */ - -/*------------------------------------------------------------------------------------------* - * Quaternion product - *------------------------------------------------------------------------------------------*/ static IVAS_QUATERNION IdentityQuaternion( void ) { IVAS_QUATERNION q; + q.w = 1.0f; q.x = q.y = q.z = 0.0f; + return q; } + /*------------------------------------------------------------------------------------------* + * QuaternionProduct() + * * Quaternion product *------------------------------------------------------------------------------------------*/ -void QuaternionProduct( + +static void QuaternionProduct( const IVAS_QUATERNION q1, const IVAS_QUATERNION q2, IVAS_QUATERNION *const r ) @@ -159,21 +96,30 @@ void QuaternionProduct( tmp.z = q1.w * q2.z + q1.x * q2.y - q1.y * q2.x + q1.z * q2.w; *r = tmp; + + return; } /*------------------------------------------------------------------------------------------* + * QuaternionDotProduct() + * * Quaternion dot product *------------------------------------------------------------------------------------------*/ -float QuaternionDotProduct( + +static float QuaternionDotProduct( const IVAS_QUATERNION q1, const IVAS_QUATERNION q2 ) { return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w; } + /*------------------------------------------------------------------------------------------* + * QuaternionDivision() + * * Divides a quaternion by a scalar *------------------------------------------------------------------------------------------*/ + void QuaternionDivision( const IVAS_QUATERNION q, const float d, @@ -183,34 +129,49 @@ void QuaternionDivision( r->x = q.x / d; r->y = q.y / d; r->z = q.z / d; + + return; } + /*------------------------------------------------------------------------------------------* + * QuaternionNormalize() + * * Normalizes a quaternion *------------------------------------------------------------------------------------------*/ -void QuaternionNormalize( + +static void QuaternionNormalize( const IVAS_QUATERNION q, IVAS_QUATERNION *const r ) { QuaternionDivision( q, sqrtf( QuaternionDotProduct( q, q ) ), r ); + + return; } + /*------------------------------------------------------------------------------------------* + * QuaternionSlerp() + * * Computes a spherical linear interpolation between two quaternions *------------------------------------------------------------------------------------------*/ -void QuaternionSlerp( + +static void QuaternionSlerp( const IVAS_QUATERNION q1, const IVAS_QUATERNION q2, const float t, IVAS_QUATERNION *const r ) { float angle, denom, s, s2; + s = QuaternionDotProduct( q1, q2 ); + if ( fabsf( s ) >= 1.0f ) { *r = q2; return; } + angle = acosf( s ); denom = sinf( angle ); @@ -222,12 +183,18 @@ void QuaternionSlerp( r->w = ( q1.w * s + q2.w * s2 ) / denom; QuaternionNormalize( *r, r ); + + return; } + /*------------------------------------------------------------------------------------------* + * QuaternionConjugate() + * * Computes a quaternion conjugate *------------------------------------------------------------------------------------------*/ -void QuaternionConjugate( + +static void QuaternionConjugate( const IVAS_QUATERNION q, IVAS_QUATERNION *const r ) { @@ -235,27 +202,39 @@ void QuaternionConjugate( r->x = -q.x; r->y = -q.y; r->z = -q.z; + + return; } + /*------------------------------------------------------------------------------------------* + * QuaternionAngle() + * * Computes an angle between two quaternions *------------------------------------------------------------------------------------------*/ -float QuaternionAngle( + +static float QuaternionAngle( const IVAS_QUATERNION q1, const IVAS_QUATERNION q2 ) { IVAS_QUATERNION q12; float angle; + QuaternionConjugate( q1, &q12 ); QuaternionProduct( q12, q2, &q12 ); angle = 2.0f * atan2f( sqrtf( q12.x * q12.x + q12.y * q12.y + q12.z * q12.z ), q12.w ); + return angle; } + /*------------------------------------------------------------------------------------------* + * QuaternionInverse() + * * Computes an inverse quaternion *------------------------------------------------------------------------------------------*/ -void QuaternionInverse( + +static void QuaternionInverse( const IVAS_QUATERNION q, IVAS_QUATERNION *const r ) { @@ -264,36 +243,39 @@ void QuaternionInverse( dot_product = QuaternionDotProduct( q, q ); QuaternionConjugate( q, r ); QuaternionDivision( *r, dot_product, r ); -} -#ifdef OTR_REFERENCE_VECTOR_TRACKING -/*------------------------------------------------------------------------------------------* - * Computes the length of a quaternion - *------------------------------------------------------------------------------------------*/ -float QuaternionLength( - const IVAS_QUATERNION q ) -{ - return sqrtf( q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z ); + return; } + +#ifdef OTR_REFERENCE_VECTOR_TRACKING /*------------------------------------------------------------------------------------------* + * VectorSubtract() + * * Computes the difference of two vectors *------------------------------------------------------------------------------------------*/ -IVAS_VECTOR3 VectorSubtract( + +static IVAS_VECTOR3 VectorSubtract( const IVAS_VECTOR3 p1, const IVAS_VECTOR3 p2 ) { IVAS_VECTOR3 result; + result.x = p1.x - p2.x; result.y = p1.y - p2.y; result.z = p1.z - p2.z; + return result; } + /*------------------------------------------------------------------------------------------* + * VectorCrossProduct() + * * Computes the cross product of two vectors *------------------------------------------------------------------------------------------*/ -IVAS_VECTOR3 VectorCrossProduct( + +static IVAS_VECTOR3 VectorCrossProduct( const IVAS_VECTOR3 p1, const IVAS_VECTOR3 p2 ) { @@ -301,46 +283,66 @@ IVAS_VECTOR3 VectorCrossProduct( result.x = p1.y * p2.z - p1.z * p2.y; result.y = p1.z * p2.x - p1.x * p2.z; result.z = p1.x * p2.y - p1.y * p2.x; + return result; } + /*------------------------------------------------------------------------------------------* + * VectorDotProduct( + * * Computes the dot product of two vectors *------------------------------------------------------------------------------------------*/ -float VectorDotProduct( + +static float VectorDotProduct( const IVAS_VECTOR3 p1, const IVAS_VECTOR3 p2 ) { return p1.x * p2.x + p1.y * p2.y + p1.z * p2.z; } + /*------------------------------------------------------------------------------------------* + * VectorLength() + * * Computes the length of a vector *------------------------------------------------------------------------------------------*/ -float VectorLength( + +static float VectorLength( const IVAS_VECTOR3 p ) { return sqrtf( p.x * p.x + p.y * p.y + p.z * p.z ); } + /*------------------------------------------------------------------------------------------* + * VectorNormalize() + * * Normalizes a vector *------------------------------------------------------------------------------------------*/ -IVAS_VECTOR3 VectorNormalize( + +static IVAS_VECTOR3 VectorNormalize( const IVAS_VECTOR3 p ) { IVAS_VECTOR3 result; + const float length = VectorLength( p ); + result.x = p.x / length; result.y = p.y / length; result.z = p.z / length; + return result; } + /*------------------------------------------------------------------------------------------* + * VectorRotationToQuaternion() + * * Computes a quaternion representing the rotation from vector p1 to vector p2 *------------------------------------------------------------------------------------------*/ -void VectorRotationToQuaternion( + +static void VectorRotationToQuaternion( const IVAS_VECTOR3 p1, const IVAS_VECTOR3 p2, IVAS_QUATERNION *const r ) @@ -369,7 +371,10 @@ void VectorRotationToQuaternion( r->z = cross_product.z; r->w = 1.0f + dot_product; } + QuaternionNormalize( *r, r ); + + return; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ #else @@ -513,6 +518,12 @@ void ivas_orient_trk_SetTrackingType( #endif #ifdef FIX_I109_ORIENTATION_TRACKING +/*-------------------------------------------------------------------* + * ivas_orient_trk_SetReferenceRotation() + * + * + *-------------------------------------------------------------------*/ + ivas_error ivas_orient_trk_SetReferenceRotation( ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ IVAS_QUATERNION refRot ) /* i : reference rotation */ @@ -535,6 +546,13 @@ ivas_error ivas_orient_trk_SetReferenceRotation( return IVAS_ERR_OK; } + +/*-------------------------------------------------------------------* + * ivas_orient_trk_GetMainOrientation() + * + * + *-------------------------------------------------------------------*/ + ivas_error ivas_orient_trk_GetMainOrientation( ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ IVAS_QUATERNION *pOrientation /* i/o : average/reference orientation */ @@ -560,9 +578,17 @@ ivas_error ivas_orient_trk_GetMainOrientation( *pOrientation = pOTR->absAvgRot; break; } + return IVAS_ERR_OK; } + +/*-------------------------------------------------------------------* + * ivas_orient_trk_GetTrackedRotation() + * + * + *-------------------------------------------------------------------*/ + ivas_error ivas_orient_trk_GetTrackedRotation( ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ IVAS_QUATERNION *pRotation /* i/o : processed rotation */ @@ -578,7 +604,14 @@ ivas_error ivas_orient_trk_GetTrackedRotation( return IVAS_ERR_OK; } + #ifdef OTR_REFERENCE_VECTOR_TRACKING +/*-------------------------------------------------------------------* + * ivas_orient_trk_SetReferenceVector() + * + * + *-------------------------------------------------------------------*/ + ivas_error ivas_orient_trk_SetReferenceVector( ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ const IVAS_VECTOR3 listenerPos, /* i : Listener position */ @@ -604,6 +637,7 @@ ivas_error ivas_orient_trk_SetReferenceVector( case OTR_TRACKING_REF_VEC_LEV: { IVAS_VECTOR3 listenerPosLevel, refPosLevel; + /* ignore the height difference between listener position and reference position */ listenerPosLevel.z = refPosLevel.z = listenerPos.z; listenerPosLevel.x = listenerPos.x; @@ -615,6 +649,7 @@ ivas_error ivas_orient_trk_SetReferenceVector( } acousticFrontVectorLength = VectorLength( acousticFrontVector ); + /* if the length is zero, the user has entered insensible listener and reference positions */ if ( acousticFrontVectorLength < 0.0001f ) { @@ -625,6 +660,7 @@ ivas_error ivas_orient_trk_SetReferenceVector( ivasForwardVector.y = 0.0f; ivasForwardVector.z = 0.0f; VectorRotationToQuaternion( ivasForwardVector, acousticFrontVector, &pOTR->refRot ); + return IVAS_ERR_OK; } #endif /* OTR_REFERENCE_VECTOR_TRACKING */ -- GitLab From 51e20eecf83f0a0523b5030cee4b0d25197cc1b9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 10:58:29 +0100 Subject: [PATCH 04/19] address a ToDo comment --- lib_rend/ivas_orient_trk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 750b10ae44..ec367f3657 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -50,9 +50,7 @@ #define MAX_TRACKED_ANGLE_AVG_ORIENT PI_OVER_2 #define MAX_TRACKED_ANGLE_REF_ORIENT EVS_PI - -/* TODO relate to frame rate - assumed here 50Hz, i.e. 20ms frame length */ -#define OTR_UPDATE_RATE ( 50.0f ) /* rate of the Process() calls [Hz]; 1x per IVAS frame */ +#define OTR_UPDATE_RATE (float) FRAMES_PER_SEC /* rate of the Process() calls [Hz]; 1x per IVAS frame */ /*------------------------------------------------------------------------------------------* -- GitLab From d36437a72c05f65ec03593fde2df49d98fbcf677 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 11:00:41 +0100 Subject: [PATCH 05/19] fix MSVC warning C4701: potentially uninitialized local variable 'acousticFrontVector' used --- lib_rend/ivas_orient_trk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index ec367f3657..4990063435 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -617,6 +617,7 @@ ivas_error ivas_orient_trk_SetReferenceVector( ) { IVAS_VECTOR3 acousticFrontVector, ivasForwardVector; + IVAS_VECTOR3 listenerPosLevel, refPosLevel; float acousticFrontVectorLength; if ( pOTR == NULL ) @@ -633,9 +634,6 @@ ivas_error ivas_orient_trk_SetReferenceVector( acousticFrontVector = VectorSubtract( listenerPos, refPos ); break; case OTR_TRACKING_REF_VEC_LEV: - { - IVAS_VECTOR3 listenerPosLevel, refPosLevel; - /* ignore the height difference between listener position and reference position */ listenerPosLevel.z = refPosLevel.z = listenerPos.z; listenerPosLevel.x = listenerPos.x; @@ -643,7 +641,9 @@ ivas_error ivas_orient_trk_SetReferenceVector( refPosLevel.x = refPos.x; refPosLevel.y = refPos.y; acousticFrontVector = VectorSubtract( listenerPosLevel, refPosLevel ); - } + break; + default: + return IVAS_ERR_WRONG_PARAMS; } acousticFrontVectorLength = VectorLength( acousticFrontVector ); -- GitLab From 4970f2bec41e664360222a930926f290eb860592 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 11:22:09 +0100 Subject: [PATCH 06/19] add more error codes for orientation tracking --- lib_dec/ivas_init_dec.c | 25 +++++++++--- lib_rend/ivas_orient_trk.c | 34 +++++++++------- lib_rend/ivas_prot_rend.h | 32 +++++++-------- lib_rend/ivas_rotation.c | 7 +++- lib_rend/lib_rend.c | 81 +++++++++++++++++++++++++++++++------- 5 files changed, 127 insertions(+), 52 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index a3a48030a9..db95d1ee4e 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -757,24 +757,39 @@ ivas_error ivas_init_decoder( { if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_NONE ) { - ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_NONE ); + if ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_AVG ) { - ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_AVG_ORIENT ); + if ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_AVG_ORIENT ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_REF ) { - ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_ORIENT ); + if ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_ORIENT ) ) != IVAS_ERR_OK ) + { + return error; + } } #ifdef OTR_REFERENCE_VECTOR_TRACKING else if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_REF_VEC ) { - ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_VEC ); + if ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_VEC ) ) != IVAS_ERR_OK ) + { + return error; + } } else if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_REF_VEC_LEV ) { - ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_VEC_LEV ); + if ( ( error = ivas_orient_trk_SetTrackingType( st_ivas->hHeadTrackData->OrientationTracker, OTR_TRACKING_REF_VEC_LEV ) ) != IVAS_ERR_OK ) + { + return error; + } } else { diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 4990063435..4d32f5606c 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -495,8 +495,9 @@ void ivas_orient_trk_Init( #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_SetTrackingType( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const OTR_TRACKING_T trackingType ) /* i/o : orientation tracking type */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + const OTR_TRACKING_T trackingType /* i/o: orientation tracking type */ +) { if ( pOTR == NULL ) { @@ -523,8 +524,9 @@ void ivas_orient_trk_SetTrackingType( *-------------------------------------------------------------------*/ ivas_error ivas_orient_trk_SetReferenceRotation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION refRot ) /* i : reference rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + const IVAS_QUATERNION refRot /* i : reference rotation */ +) { if ( pOTR == NULL ) { @@ -552,8 +554,8 @@ ivas_error ivas_orient_trk_SetReferenceRotation( *-------------------------------------------------------------------*/ ivas_error ivas_orient_trk_GetMainOrientation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION *pOrientation /* i/o : average/reference orientation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION *pOrientation /* i/o: average/reference orientation */ ) { if ( pOTR == NULL || pOrientation == NULL ) @@ -588,8 +590,8 @@ ivas_error ivas_orient_trk_GetMainOrientation( *-------------------------------------------------------------------*/ ivas_error ivas_orient_trk_GetTrackedRotation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION *pRotation /* i/o : processed rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION *pRotation /* i/o: processed rotation */ ) { if ( pOTR == NULL || pRotation == NULL ) @@ -611,9 +613,9 @@ ivas_error ivas_orient_trk_GetTrackedRotation( *-------------------------------------------------------------------*/ ivas_error ivas_orient_trk_SetReferenceVector( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const IVAS_VECTOR3 listenerPos, /* i : Listener position */ - const IVAS_VECTOR3 refPos /* i : Reference position */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + const IVAS_VECTOR3 listenerPos, /* i : Listener position */ + const IVAS_VECTOR3 refPos /* i : Reference position */ ) { IVAS_VECTOR3 acousticFrontVector, ivasForwardVector; @@ -693,10 +695,11 @@ void ivas_orient_trk_SetAbsoluteOrientation( #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_Process( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION absRot, /* i : absolute head rotation */ - float updateRate, /* i : rotation update rate [Hz] */ - IVAS_QUATERNION *pTrkRot ) /* o : tracked rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION absRot, /* i : absolute head rotation */ + float updateRate, /* i : rotation update rate [Hz] */ + IVAS_QUATERNION *pTrkRot /* o : tracked rotation */ +) { float normalizedOrientation; float relativeOrientationRate; @@ -779,6 +782,7 @@ ivas_error ivas_orient_trk_Process( { *pTrkRot = pOTR->trkRot; } + return result; } #else diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 2b0e67e5f4..33359eee8c 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -877,7 +877,7 @@ ivas_error ivas_orient_trk_Init( #else void ivas_orient_trk_Init( #endif - ivas_orient_trk_state_t *pOTR /* i/o : orientation tracker handle */ + ivas_orient_trk_state_t *pOTR /* i/o: orientation tracker handle */ ); #ifdef FIX_I109_ORIENTATION_TRACKING @@ -885,41 +885,41 @@ ivas_error ivas_orient_trk_SetTrackingType( #else void ivas_orient_trk_SetTrackingType( #endif - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const OTR_TRACKING_T trackingType /* i : orientation tracking type */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + const OTR_TRACKING_T trackingType /* i : orientation tracking type */ ); #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_SetReferenceRotation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientatoin trakcer handle */ - IVAS_QUATERNION refRot /* i : reference rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientatoin trakcer handle */ + const IVAS_QUATERNION refRot /* i : reference rotation */ ); #ifdef OTR_REFERENCE_VECTOR_TRACKING ivas_error ivas_orient_trk_SetReferenceVector( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - const IVAS_VECTOR3 listenerPos, /* i : Listener position */ - const IVAS_VECTOR3 refPos /* i : Reference position */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + const IVAS_VECTOR3 listenerPos, /* i : Listener position */ + const IVAS_VECTOR3 refPos /* i : Reference position */ ); #endif /* OTR_REFERENCE_VECTOR_TRACKING */ ivas_error ivas_orient_trk_GetMainOrientation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION *pOrientation /* i/o : average/reference orientation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION *pOrientation /* i/o: average/reference orientation */ ); ivas_error ivas_orient_trk_GetTrackedRotation( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION *pRotation /* i/o : processed rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION *pRotation /* i/o: processed rotation */ ); #endif #ifdef FIX_I109_ORIENTATION_TRACKING ivas_error ivas_orient_trk_Process( - ivas_orient_trk_state_t *pOTR, /* i/o : orientation tracker handle */ - IVAS_QUATERNION absRot, /* i : absolute head rotation */ - float updateRate, /* i : rotation update rate [Hz] */ - IVAS_QUATERNION *pTrkRot /* o : tracked rotation */ + ivas_orient_trk_state_t *pOTR, /* i/o: orientation tracker handle */ + IVAS_QUATERNION absRot, /* i : absolute head rotation */ + float updateRate, /* i : rotation update rate [Hz] */ + IVAS_QUATERNION *pTrkRot /* o : tracked rotation */ ); #else diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 0c991c79e7..3a1d28f6cc 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -55,6 +55,7 @@ ivas_error ivas_headTrack_open( ) { int16_t i; + ivas_error error; /* Allocate Head-Tracking handle */ if ( ( *hHeadTrackData = (HEAD_TRACK_DATA_HANDLE) malloc( sizeof( HEAD_TRACK_DATA ) ) ) == NULL ) @@ -72,7 +73,11 @@ ivas_error ivas_headTrack_open( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } - ivas_orient_trk_Init( ( *hHeadTrackData )->OrientationTracker ); + + if ( ( error = ivas_orient_trk_Init( ( *hHeadTrackData )->OrientationTracker ) ) != IVAS_ERR_OK ) + { + return error; + } #endif /* Initialise Rmat_prev to I, Rmat will be computed later */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a69393e10e..8059c53346 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -910,6 +910,7 @@ static void initHeadRotation( { int16_t i, crossfade_len; float tmp; + ivas_error error; /* Head rotation is enabled by default */ hIvasRend->headRotData.headRotEnabled = 1; @@ -933,7 +934,11 @@ static void initHeadRotation( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } - ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ); + + if ( ( error = ivas_orient_trk_Init( hIvasRend->headRotData.hOrientationTracker ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; #else @@ -3953,13 +3958,21 @@ ivas_error IVAS_REND_SetHeadRotation( return IVAS_ERR_OK; } + #ifdef FIX_I109_ORIENTATION_TRACKING +/*-------------------------------------------------------------------* + * IVAS_REND_SetOrientationTrackingMode() + * + * + *-------------------------------------------------------------------*/ + ivas_error IVAS_REND_SetOrientationTrackingMode( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const uint8_t otrMode /* i : Orientation tracking mode */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const uint8_t otrMode /* i : Orientation tracking mode */ ) { OTR_TRACKING_T mode; + ivas_error error; if ( hIvasRend == NULL ) { @@ -3988,59 +4001,97 @@ ivas_error IVAS_REND_SetOrientationTrackingMode( break; } - ivas_orient_trk_SetTrackingType( hIvasRend->headRotData.hOrientationTracker, mode ); + if ( ( error = ivas_orient_trk_SetTrackingType( hIvasRend->headRotData.hOrientationTracker, mode ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } + +/*-------------------------------------------------------------------* + * IVAS_REND_SetReferenceRotation() + * + * + *-------------------------------------------------------------------*/ + ivas_error IVAS_REND_SetReferenceRotation( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_QUATERNION refRot /* i : Reference rotation */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_QUATERNION refRot /* i : Reference rotation */ ) { - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ + ivas_error error; + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - ivas_orient_trk_SetReferenceRotation( hIvasRend->headRotData.hOrientationTracker, refRot ); + + if ( ( error = ivas_orient_trk_SetReferenceRotation( hIvasRend->headRotData.hOrientationTracker, refRot ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } + +/*-------------------------------------------------------------------* + * IVAS_REND_GetMainOrientation() + * + * + *-------------------------------------------------------------------*/ + ivas_error IVAS_REND_GetMainOrientation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ IVAS_QUATERNION *pOrientation /* i/o: Quaternion pointer for main orientation */ ) { + ivas_error error; + if ( hIvasRend == NULL || pOrientation == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - ivas_orient_trk_GetMainOrientation( hIvasRend->headRotData.hOrientationTracker, pOrientation ); + if ( ( error = ivas_orient_trk_GetMainOrientation( hIvasRend->headRotData.hOrientationTracker, pOrientation ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } + +/*-------------------------------------------------------------------* + * IVAS_REND_GetTrackedRotation() + * + * + *-------------------------------------------------------------------*/ + ivas_error IVAS_REND_GetTrackedRotation( IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ IVAS_QUATERNION *pRotation /* i/o: Quaternion pointer processed rotation */ ) { + ivas_error error; + if ( hIvasRend == NULL || pRotation == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - ivas_orient_trk_GetTrackedRotation( hIvasRend->headRotData.hOrientationTracker, pRotation ); + if ( ( error = ivas_orient_trk_GetTrackedRotation( hIvasRend->headRotData.hOrientationTracker, pRotation ) ) != IVAS_ERR_OK ) + { + return error; + } return IVAS_ERR_OK; } + #ifdef OTR_REFERENCE_VECTOR_TRACKING /*---------------------------------------------------------------------* * IVAS_REND_SetReferenceVector( ) @@ -4050,9 +4101,9 @@ ivas_error IVAS_REND_GetTrackedRotation( *---------------------------------------------------------------------*/ ivas_error IVAS_REND_SetReferenceVector( - IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ - const IVAS_VECTOR3 listenerPos, /* i : Listener position */ - const IVAS_VECTOR3 refPos /* i : Reference position */ + IVAS_REND_HANDLE hIvasRend, /* i/o: Renderer handle */ + const IVAS_VECTOR3 listenerPos, /* i : Listener position */ + const IVAS_VECTOR3 refPos /* i : Reference position */ ) { if ( hIvasRend == NULL || hIvasRend->headRotData.hOrientationTracker == NULL ) -- GitLab From c6c0d900c05d1c7ce15b1d9c19a2d72cf242e70e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 11:41:35 +0100 Subject: [PATCH 07/19] fix test warnings --- lib_rend/ivas_orient_trk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 4d32f5606c..af71cbf543 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -118,7 +118,7 @@ static float QuaternionDotProduct( * Divides a quaternion by a scalar *------------------------------------------------------------------------------------------*/ -void QuaternionDivision( +static void QuaternionDivision( const IVAS_QUATERNION q, const float d, IVAS_QUATERNION *const r ) @@ -134,7 +134,7 @@ void QuaternionDivision( /*------------------------------------------------------------------------------------------* * QuaternionNormalize() - * + * * Normalizes a quaternion *------------------------------------------------------------------------------------------*/ -- GitLab From cd731c72aa49fe562c4a5ab971e7c11969055b95 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 16:47:39 +0100 Subject: [PATCH 08/19] more editorial changes within MD5 --- lib_com/ivas_ism_config.c | 2 ++ lib_com/ivas_rom_com.h | 5 ++--- lib_com/ivas_stat_com.h | 4 ++++ lib_dec/ivas_ism_dec.c | 1 - lib_dec/ivas_ism_metadata_dec.c | 1 + lib_dec/lib_dec.h | 2 +- lib_enc/ivas_ism_enc.c | 1 - lib_enc/ivas_ism_metadata_enc.c | 11 ++++++++--- lib_enc/lib_enc.c | 3 +++ lib_rend/ivas_stat_rend.h | 1 + lib_util/ism_file_reader.c | 4 ++-- 11 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index d6b0999f7e..efacf7cca4 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -340,6 +340,7 @@ void ivas_ism_reset_metadata( hIsmMeta->pitch = 0.0f; hIsmMeta->radius = 1.0f; #endif + return; } @@ -348,6 +349,7 @@ void ivas_ism_reset_metadata( * * Reset ISm metadata parameters *-------------------------------------------------------------------*/ + void ivas_ism_reset_metadata_API( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ) diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index f6a9cb6ef1..a095c9e4b4 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -317,9 +317,8 @@ extern const float McMASA_LFEGain_vectors[64]; extern const float ism_azimuth_borders[4]; extern const float ism_elevation_borders[4]; -#ifdef TD5 -extern const float ism_radius_borders[4]; -#endif // TD5 + + /*----------------------------------------------------------------------------------* * Param ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 244ba7ff76..5a45575b0a 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -43,6 +43,7 @@ /*----------------------------------------------------------------------------------* * Declaration of ISm common (encoder & decoder) structure *----------------------------------------------------------------------------------*/ + #ifdef TD5 typedef struct { @@ -50,8 +51,10 @@ typedef struct int16_t azimuth_diff_cnt; /* FEC counter of consecutive differentially azimuth coded frames */ int16_t last_elevation_idx; /* last frame index of coded elevation */ int16_t elevation_diff_cnt; /* FEC counter of consecutive differentially elevation coded frames */ + } ISM_METADATA_ANGLE, *ISM_METADATA_ANGLE_HANDLE; #endif + /* ISM metadata handle (storage for one frame of read ISM metadata) */ typedef struct { @@ -73,6 +76,7 @@ typedef struct int16_t last_elevation_idx; /* last frame index of coded elevation */ int16_t elevation_diff_cnt; /* FEC counter of consecutive differentially elevation coded frames */ #endif + } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 5fd1c879f1..cae696e938 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -240,7 +240,6 @@ static ivas_error ivas_ism_bitrate_switching( * - reconfigure the ISM format decoder *-------------------------------------------------------------------------*/ -/*! r : ISM format mode */ ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t num_obj /* i : number of objects in the bitstream */ diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 4b604c3b8c..372fa15248 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -265,6 +265,7 @@ ivas_error ivas_ism_metadata_dec( hIsmMetaData->azimuth = ism_dequant_meta( idx_azimuth, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ); hIsmMetaData->elevation = ism_dequant_meta( idx_elevation, ism_elevation_borders, 1 << ISM_ELEVATION_NBITS ); + /* radius/raw/pitch dequantization */ if ( ism_extended_metadata_flag ) { decode_angle_indices( st0, &( hIsmMetaData->angle[1] ), &flag_abs_orientation ); diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index e115ecd198..0e7d8042d8 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -215,7 +215,7 @@ ivas_error IVAS_DEC_VoIP_FeedFrame( /*! r: error code */ ivas_error IVAS_DEC_VoIP_GetSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ + uint16_t nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */ int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ const uint32_t systemTimestamp_ms /* i : current system timestamp */ #ifdef SUPPORT_JBM_TRACEFILE diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 42f877aa17..51295cba6e 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -331,7 +331,6 @@ ivas_error ivas_ism_enc( * - reconfigure the ISM format encoder *-------------------------------------------------------------------------*/ -/*! r : ISM format mode */ ivas_error ivas_ism_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index c10eda7640..33ba03a907 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -65,10 +65,12 @@ #define INTER_OBJECT_PARAM_CHECK ( ( ISM_FEC_MAX / 2 ) - 2 ) /* note: constant must be less than (ISM_FEC_MAX / number of coded parameters) */ + #ifdef TD5 /*-----------------------------------------------------------------------* - * Local functions + * Local function declarations *-----------------------------------------------------------------------*/ + static void encode_angle_indices( BSTR_ENC_HANDLE hBstr, ISM_METADATA_ANGLE_HANDLE angle, const int16_t last_ism_metadata_flag, const int16_t ini_frame, const int16_t idx_azimuth_abs, const int16_t idx_elevation_abs, int16_t *flag_abs_azimuth, int16_t *flag_abs_elevation ); static void encode_radius( BSTR_ENC_HANDLE hBstr, int16_t *last_radius_idx, int16_t *radius_diff_cnt, const int16_t last_ism_metadata_flag, const int16_t idx_radius_abs, int16_t *flag_abs_radius ); @@ -412,7 +414,7 @@ ivas_error ivas_ism_metadata_enc( { #ifdef TD5 /*----------------------------------------------------------------* - * Obtain quantizer indices for azimuth and elevation + * Quantize and encode azimuth and elevation *----------------------------------------------------------------*/ if ( ism_mode == ISM_MODE_DISC ) @@ -428,7 +430,10 @@ ivas_error ivas_ism_metadata_enc( encode_angle_indices( hBstr, &( hIsmMetaData->angle[0] ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_azimuth_abs, idx_elevation_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); - /* Encode orientation and radius, if above certain bit rate etc, discrete ISM */ + /*----------------------------------------------------------------* + * Quantize and encode radius, yaw, and pitch + *----------------------------------------------------------------*/ + if ( ism_mode == ISM_MODE_DISC && ism_extended_metadata_flag ) { idx_azimuth_abs = ism_quant_meta( hIsmMetaData->yaw, &valQ, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index a63788356b..a2ea72e9a6 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -2278,6 +2278,9 @@ static void init_encoder_config( hEncoderConfig->stereo_dmx_evs = 0; hEncoderConfig->sba_order = 0; hEncoderConfig->sba_planar = 0; +#ifdef TD5 + hEncoderConfig->ism_extended_metadata_flag = 0; +#endif #ifdef DEBUGGING hEncoderConfig->stereo_mode_cmdl = 0; hEncoderConfig->force = -1; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 9dafb5fb65..96deb7dc37 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -336,6 +336,7 @@ typedef struct ivas_render_config_t #ifdef TD5 float directivity[3]; #endif + } RENDER_CONFIG_DATA, *RENDER_CONFIG_HANDLE; typedef struct ivas_rev_delay_line_t diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index b6166af95b..d25686fd1d 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -95,13 +95,13 @@ IsmFileReader *IsmFileReader_open( /*! r: error code */ ivas_error IsmFileReader_readNextFrame( IsmFileReader *self, /* i/o: IsmFileReader handle */ - IVAS_ISM_METADATA *ismMetadata /* o ISM : metadata read from the opened file */ + IVAS_ISM_METADATA *ismMetadata /* o : ISM metadata read from the opened file */ ) { char char_buff[META_LINE_LENGTH]; float meta_prm[NUM_ISM_METADATA_PER_LINE]; #ifdef TD5 - float meta_prm_default[NUM_ISM_METADATA_PER_LINE] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f }; + const float meta_prm_default[NUM_ISM_METADATA_PER_LINE] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f }; #endif char *char_ptr; int16_t i; -- GitLab From 83c367f3434f4e018e3ceb350bc2f954d8fd965c Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 18:37:23 +0100 Subject: [PATCH 09/19] revision of *_close() functions --- lib_com/ivas_fb_mixer.c | 14 ++- lib_com/ivas_mc_param_com.c | 1 - lib_com/ivas_prot.h | 47 +++++----- lib_com/prot.h | 14 ++- lib_dec/fd_cng_dec.c | 9 +- lib_dec/ivas_agc_dec.c | 24 ++--- lib_dec/ivas_dirac_dec.c | 20 +++-- lib_dec/ivas_dirac_output_synthesis_cov.c | 1 - lib_dec/ivas_init_dec.c | 70 +++++---------- lib_dec/ivas_ism_dec.c | 6 +- lib_dec/ivas_ism_param_dec.c | 15 +++- lib_dec/ivas_lfe_dec.c | 20 +++-- lib_dec/ivas_masa_dec.c | 15 +++- lib_dec/ivas_mc_param_dec.c | 4 +- lib_dec/ivas_mcmasa_dec.c | 5 +- lib_dec/ivas_mct_dec.c | 51 ++--------- lib_dec/ivas_sba_dec.c | 25 ++---- lib_dec/ivas_spar_decoder.c | 50 +++++------ lib_dec/ivas_spar_md_dec.c | 8 +- lib_dec/ivas_stat_dec.h | 1 + lib_dec/ivas_tcx_core_dec.c | 27 +++--- lib_enc/init_enc.c | 5 +- lib_enc/ivas_agc_enc.c | 24 ++--- lib_enc/ivas_corecoder_enc_reconfig.c | 3 +- lib_enc/ivas_dirac_enc.c | 17 +++- lib_enc/ivas_enc_cov_handler.c | 16 ++-- lib_enc/ivas_init_enc.c | 60 +++---------- lib_enc/ivas_ism_enc.c | 3 +- lib_enc/ivas_ism_param_enc.c | 29 +++--- lib_enc/ivas_lfe_enc.c | 22 +++-- lib_enc/ivas_masa_enc.c | 18 ++-- lib_enc/ivas_mc_param_enc.c | 22 +++-- lib_enc/ivas_mcmasa_enc.c | 64 ++++++++------ lib_enc/ivas_mct_enc.c | 93 +++++++------------- lib_enc/ivas_sba_enc.c | 6 +- lib_enc/ivas_spar_encoder.c | 87 +++++++++--------- lib_enc/ivas_spar_md_enc.c | 14 +-- lib_enc/ivas_stereo_dmx_evs.c | 16 ++-- lib_rend/ivas_crend.c | 16 ++-- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 +- lib_rend/ivas_hrtf.c | 1 - lib_rend/ivas_rotation.c | 22 +++-- lib_rend/lib_rend.c | 43 +++------ 43 files changed, 460 insertions(+), 550 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 4543955cee..2bf849b410 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -174,9 +174,8 @@ ivas_error ivas_fb_set_cfg( ivas_error ivas_FB_mixer_open( IVAS_FB_MIXER_HANDLE *hFbMixer_out, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate */ - IVAS_FB_CFG *fb_cfg /* i : FB config. handle */ - , - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { IVAS_FB_MIXER_HANDLE hFbMixer; @@ -361,9 +360,8 @@ ivas_error ivas_FB_mixer_open( void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ - const int32_t sampling_rate /* i : sampling rate in Hz */ - , - const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const int32_t sampling_rate, /* i : sampling rate in Hz */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { IVAS_FB_MIXER_HANDLE hFbMixer; @@ -833,8 +831,8 @@ static int16_t ivas_calculate_abs_fr( float short_stride_nrg = 0.0f; float cldfb_nrg = 0.0f; int16_t short_stride = pFb->fb_bin_to_band.short_stride; - const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); + const int16_t num_bins_per_short_stride_bin = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); + const int16_t num_bins_per_cldfb_band = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); float short_stride_max_per_spar_band = 1e-9f; /*loop over all stored Filter Bank Response MDFT coefficients*/ diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index c6cfe0ed8f..acf7a8eae2 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -141,7 +141,6 @@ void ivas_param_mc_metadata_open( ivas_param_mc_default_icc_map( hMetadataPMC->icc_mapping_conf, hMetadataPMC->icc_mapping[i] ); } - /* init remaining flags and indices */ hMetadataPMC->param_frame_idx = 0; hMetadataPMC->flag_use_adaptive_icc_map = 0; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 194559ee79..4d5b3adc7d 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -124,7 +124,7 @@ void destroy_cpe_enc( ); void ivas_mct_enc_close( - MCT_ENC_HANDLE hMCT /* i/o: MCT encoder structure */ + MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ); ivas_error ivas_corecoder_enc_reconfig( @@ -289,7 +289,7 @@ ivas_error stereo_dmx_evs_init_encoder( ); void stereo_dmx_evs_close_encoder( - STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ ); ivas_error ivas_dec( @@ -499,8 +499,7 @@ void stereo_tcx_core_dec( const int16_t last_element_mode, /* i : last element mode */ const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out /* i : number of output channels */ - , + const int16_t nchan_out, /* i : number of output channels */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const ISM_MODE ism_mode /* i : ISM mode (only needed if format is ISM) */ ); @@ -860,7 +859,7 @@ void ivas_param_ism_enc( ); void ivas_param_ism_enc_close( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); @@ -888,7 +887,7 @@ ivas_error ivas_param_ism_dec_open( ); void ivas_param_ism_dec_close( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + DIRAC_DEC_HANDLE *hDirAC, /* i/o: decoder DirAC handle */ const AUDIO_CONFIG output_config /* i : output audio configuration */ ); @@ -3244,7 +3243,7 @@ ivas_error ivas_dirac_enc_reconfigure( ); void ivas_dirac_enc_close( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ const int32_t input_Fs /* i : input sampling_rate */ ); @@ -3296,7 +3295,7 @@ ivas_error ivas_dirac_dec_config( ); void ivas_dirac_dec_close( - DIRAC_DEC_HANDLE hDirAC /* i/o: decoder DirAC handle */ + DIRAC_DEC_HANDLE *hDirAC /* i/o: decoder DirAC handle */ ); void ivas_dirac_dec_read_BS( @@ -3524,7 +3523,7 @@ ivas_error ivas_param_mc_enc_reconfig( ); void ivas_param_mc_enc_close( - PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ + PARAM_MC_ENC_HANDLE *hParamMC, /* i/o: Parametric MC encoder handle */ const int32_t input_Fs /* i : input sampling rate */ ); @@ -3758,10 +3757,10 @@ ivas_error ivas_spar_enc_open( ); void ivas_spar_enc_close( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder handle */ + SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ const int32_t input_Fs, /* i : input sampling rate */ - const int16_t nchan_inp /* i : number of input channels */ - ,const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ + const int16_t nchan_inp, /* i : number of input channels */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); ivas_error ivas_spar_enc( @@ -3773,15 +3772,13 @@ ivas_error ivas_spar_enc( ); ivas_error ivas_spar_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ - , + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); void ivas_spar_dec_close( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const int32_t output_Fs /* i : output sampling rate */ - , + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const int32_t output_Fs, /* i : output sampling rate */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); @@ -4429,7 +4426,7 @@ ivas_error ivas_masa_dec_open( ); void ivas_masa_dec_close( - MASA_DECODER_HANDLE hMasa /* i/o: MASA metadata structure */ + MASA_DECODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ); ivas_error ivas_masa_decode( @@ -4447,7 +4444,7 @@ ivas_error ivas_masa_enc_open( ); void ivas_masa_enc_close( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA metadata structure */ + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ #ifndef FIX_350_MASA_DELAY_COMP , const int16_t nchan_transport, /* i : Number of transport channels */ @@ -4735,7 +4732,7 @@ ivas_error ivas_mcmasa_enc_open( ); void ivas_mcmasa_enc_close( - MCMASA_ENC_HANDLE hMcMasa, /* i/o: encoder McMASA handle */ + MCMASA_ENC_HANDLE *hMcMasa, /* i/o: encoder McMASA handle */ const int32_t input_Fs /* i : input sampling rate */ ); @@ -4858,7 +4855,7 @@ ivas_error ivas_create_lfe_enc( ); void ivas_lfe_enc_close( - LFE_ENC_HANDLE hLFE /* i/o: LFE encoder handle */ + LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ); void ivas_lfe_enc( @@ -4875,7 +4872,7 @@ ivas_error ivas_create_lfe_dec( ); void ivas_lfe_dec_close( - LFE_DEC_HANDLE hLFE /* i/o: LFE encoder handle */ + LFE_DEC_HANDLE *hLFE /* i/o: LFE encoder handle */ ); void ivas_lfe_dec( @@ -4950,15 +4947,13 @@ ivas_error ivas_fb_set_cfg( ivas_error ivas_FB_mixer_open( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ const int32_t sampling_rate, /* i : sampling rate */ - IVAS_FB_CFG *fb_cfg /* i : FB config. handle */ - , + IVAS_FB_CFG *fb_cfg, /* i : FB config. handle */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); void ivas_FB_mixer_close( IVAS_FB_MIXER_HANDLE *hFbMixer, /* i/o: FB mixer handle */ - const int32_t sampling_rate /* i : sampling rate in Hz */ - , + const int32_t sampling_rate, /* i : sampling rate in Hz */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); diff --git a/lib_com/prot.h b/lib_com/prot.h index 69cc4e0d32..4c20c392d4 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2228,9 +2228,8 @@ ivas_error init_encoder( const int16_t idchan, /* i : channel ID */ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ const int16_t interval_SID, /* i : interval for SID update */ - const int16_t vad_only_flag /* i : flag to indicate front-VAD structure */ - , - const ISM_MODE ism_mode /* i : ISM mode */ + const int16_t vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode /* i : ISM mode */ ); void LPDmem_enc_init( @@ -8519,11 +8518,10 @@ void generate_comfort_noise_dec( ); void generate_comfort_noise_dec_hf( - float **bufferReal, /* o : Real part of input bands */ - float **bufferImag, /* o : Imaginary part of input bands */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ - , - const int16_t cng_flag /*i : CNG Flag */ + float **bufferReal, /* o : Real part of input bands */ + float **bufferImag, /* o : Imaginary part of input bands */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const int16_t cng_flag /*i : CNG Flag */ ); void generate_masking_noise( diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 0620b09d5f..1d4b2ccf90 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -1328,11 +1328,10 @@ void generate_comfort_noise_dec( *-------------------------------------------------------------------*/ void generate_comfort_noise_dec_hf( - float **bufferReal, /* o : Real part of input bands */ - float **bufferImag, /* o : Imaginary part of input bands */ - HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ - , - const int16_t cng_coh_flag /* i : CNG Flag for coherence handling */ + float **bufferReal, /* o : Real part of input bands */ + float **bufferImag, /* o : Imaginary part of input bands */ + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + const int16_t cng_coh_flag /* i : CNG Flag for coherence handling */ ) { int16_t i, j; diff --git a/lib_dec/ivas_agc_dec.c b/lib_dec/ivas_agc_dec.c index 1397ce1111..c874b297be 100644 --- a/lib_dec/ivas_agc_dec.c +++ b/lib_dec/ivas_agc_dec.c @@ -142,22 +142,24 @@ void ivas_spar_agc_dec_close( { ivas_agc_dec_state_t *hAgc; + if ( hAgcDec != NULL || *hAgcDec != NULL ) + { + return; + } + hAgc = *hAgcDec; - if ( hAgc != NULL ) - { - free( hAgc->agc_com.winFunc ); - hAgc->agc_com.winFunc = NULL; + free( hAgc->agc_com.winFunc ); + hAgc->agc_com.winFunc = NULL; - free( hAgc->gain_state ); - hAgc->gain_state = NULL; + free( hAgc->gain_state ); + hAgc->gain_state = NULL; - free( hAgc->gain_data ); - hAgc->gain_data = NULL; + free( hAgc->gain_data ); + hAgc->gain_data = NULL; - free( hAgc ); - *hAgcDec = NULL; - } + free( hAgc ); + *hAgcDec = NULL; return; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1f8de9cb38..4d3d1adb3c 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -593,10 +593,11 @@ ivas_error ivas_dirac_dec_config( if ( hDirAC->panningConf == DIRAC_PANNING_VBAP ) { - if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata ) + if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { vbap_free_data( &( st_ivas->hVBAPdata ) ); } + if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE ) ) != IVAS_ERR_OK ) { return error; @@ -604,13 +605,13 @@ ivas_error ivas_dirac_dec_config( } else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata ) + if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { vbap_free_data( &( st_ivas->hVBAPdata ) ); } hDirAC->hoa_decoder = NULL; } - else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata ) + else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { vbap_free_data( &( st_ivas->hVBAPdata ) ); } @@ -1002,10 +1003,18 @@ ivas_error ivas_dirac_dec_config( *------------------------------------------------------------------------*/ void ivas_dirac_dec_close( - DIRAC_DEC_HANDLE hDirAC /* i/o: decoder DirAC handle */ + DIRAC_DEC_HANDLE *hDirAC_out /* i/o: decoder DirAC handle */ ) { int16_t i, j; + DIRAC_DEC_HANDLE hDirAC; + + if ( hDirAC_out == NULL || *hDirAC_out == NULL ) + { + return; + } + + hDirAC = *hDirAC_out; /* Config & CLDFB */ if ( hDirAC->hConfig != NULL ) @@ -1225,7 +1234,8 @@ void ivas_dirac_dec_close( ivas_dirac_free_mem( &( hDirAC->stack_mem ) ); - free( hDirAC ); + free( *hDirAC_out ); + *hDirAC_out = NULL; return; } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 6a79d4563a..a2fc9ee821 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -190,7 +190,6 @@ void ivas_dirac_dec_output_synthesis_cov_close( DIRAC_OUTPUT_SYNTHESIS_COV_STATE *h_dirac_output_synthesis_state /* i/o: handle for the covariance synthesis state */ ) { - int16_t idx; /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index db95d1ee4e..ff90170946 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -753,6 +753,10 @@ ivas_error ivas_init_decoder( } #ifdef FIX_I109_ORIENTATION_TRACKING + /*-----------------------------------------------------------------* + * Set head/orientation tracking + *-----------------------------------------------------------------*/ + if ( st_ivas->hDecoderConfig->Opt_Headrotation ) { if ( st_ivas->hDecoderConfig->orientation_tracking == IVAS_ORIENT_TRK_NONE ) @@ -1644,7 +1648,6 @@ void ivas_destroy_dec( if ( st_ivas->cldfbAnaDec[i] != NULL ) { deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); - st_ivas->cldfbAnaDec[i] = NULL; } } @@ -1653,7 +1656,6 @@ void ivas_destroy_dec( if ( st_ivas->cldfbSynDec[i] != NULL ) { deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); - st_ivas->cldfbSynDec[i] = NULL; } } @@ -1684,11 +1686,7 @@ void ivas_destroy_dec( } /* LFE handle */ - if ( st_ivas->hLFE != NULL ) - { - ivas_lfe_dec_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; - } + ivas_lfe_dec_close( &( st_ivas->hLFE ) ); /* HP20 filter handles */ if ( st_ivas->mem_hp20_out != NULL ) @@ -1712,7 +1710,7 @@ void ivas_destroy_dec( } } - /* ISm renderer handle */ + /* ISM renderer handle */ if ( st_ivas->hIsmRendererData != NULL ) { free( st_ivas->hIsmRendererData ); @@ -1720,26 +1718,18 @@ void ivas_destroy_dec( } /* DirAC handle */ - if ( st_ivas->hDirAC != NULL ) + if ( st_ivas->ivas_format == ISM_FORMAT ) { - if ( st_ivas->ivas_format == ISM_FORMAT ) - { - ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); - } - else - { - ivas_dirac_dec_close( st_ivas->hDirAC ); - } - st_ivas->hDirAC = NULL; + ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config ); } - - /* Spar handle */ - if ( st_ivas->hSpar != NULL ) + else { - ivas_spar_dec_close( st_ivas->hSpar, st_ivas->hDecoderConfig->output_Fs, 0 ); - st_ivas->hSpar = NULL; + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); } + /* SPAR handle */ + ivas_spar_dec_close( &( st_ivas->hSpar ), st_ivas->hDecoderConfig->output_Fs, 0 ); + /* HOA decoder matrix */ if ( st_ivas->hoa_dec_mtx != NULL ) { @@ -1747,6 +1737,9 @@ void ivas_destroy_dec( st_ivas->hoa_dec_mtx = NULL; } + /* MASA decoder structure */ + ivas_masa_dec_close( &( st_ivas->hMasa ) ); + /* Qmetadata handle */ ivas_qmetadata_close( &st_ivas->hQMetaData ); @@ -1770,6 +1763,7 @@ void ivas_destroy_dec( /* Crend handle */ ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); + /* Reverb handle */ ivas_reverb_close( &st_ivas->hReverb ); @@ -1783,13 +1777,6 @@ void ivas_destroy_dec( st_ivas->hLsSetupCustom = NULL; } - /* MASA decoder structure */ - if ( st_ivas->hMasa != NULL ) - { - ivas_masa_dec_close( st_ivas->hMasa ); - st_ivas->hMasa = NULL; - } - /* Downmix structure */ if ( st_ivas->hMonoDmxRenderer != NULL ) { @@ -1798,15 +1785,15 @@ void ivas_destroy_dec( } /* Head track data handle */ - if ( st_ivas->hHeadTrackData != NULL ) - { #ifdef FIX_I109_ORIENTATION_TRACKING - ivas_headTrack_close( &st_ivas->hHeadTrackData ); + ivas_headTrack_close( &st_ivas->hHeadTrackData ); #else + if ( st_ivas->hHeadTrackData != NULL ) + { free( st_ivas->hHeadTrackData ); st_ivas->hHeadTrackData = NULL; -#endif } +#endif /* Time Domain binaural renderer handle */ if ( st_ivas->hBinRendererTd != NULL ) @@ -1821,22 +1808,13 @@ void ivas_destroy_dec( } /* CRend binaural renderer handle */ - if ( st_ivas->hSetOfHRTF != NULL ) - { - ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); - } + ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); /* Fastconv HRTF filters */ - if ( st_ivas->hHrtfFastConv != NULL ) - { - ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); - } + ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); /* Parametric binauralizer HRTF filters */ - if ( st_ivas->hHrtfParambin != NULL ) - { - ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); - } + ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); /* Config. Renderer */ ivas_render_config_close( &( st_ivas->hRenderConfig ) ); diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index cae696e938..51ea82bfe1 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -113,11 +113,7 @@ static ivas_error ivas_ism_bitrate_switching( if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* Deallocate the ParamISM struct */ - if ( st_ivas->hDirAC != NULL ) - { - ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); - st_ivas->hDirAC = NULL; - } + ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config ); if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL ) { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index f34aa023f6..acf62ba1a7 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -621,11 +621,19 @@ ivas_error ivas_param_ism_dec_open( *-------------------------------------------------------------------------*/ void ivas_param_ism_dec_close( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - AUDIO_CONFIG output_config /* i : output audio configuration */ + DIRAC_DEC_HANDLE *hDirAC_out, /* i/o: decoder DirAC handle */ + AUDIO_CONFIG output_config /* i : output audio configuration */ ) { int16_t i; + DIRAC_DEC_HANDLE hDirAC; + + if ( hDirAC_out == NULL || *hDirAC_out == NULL ) + { + return; + } + + hDirAC = *hDirAC_out; /* Config & CLDFB */ if ( hDirAC->hParamIsm != NULL ) @@ -782,7 +790,8 @@ void ivas_param_ism_dec_close( hDirAC->hParamIsmRendering = NULL; } - free( hDirAC ); + free( *hDirAC_out ); + *hDirAC_out = NULL; return; } diff --git a/lib_dec/ivas_lfe_dec.c b/lib_dec/ivas_lfe_dec.c index 55a68d892b..5c250286ee 100644 --- a/lib_dec/ivas_lfe_dec.c +++ b/lib_dec/ivas_lfe_dec.c @@ -477,19 +477,25 @@ ivas_error ivas_create_lfe_dec( *-------------------------------------------------------------------------*/ void ivas_lfe_dec_close( - LFE_DEC_HANDLE hLFE /* i/o: LFE decoder handle */ + LFE_DEC_HANDLE *hLFE /* i/o: LFE decoder handle */ ) { - free( hLFE->pWindow_state ); - hLFE->pWindow_state = NULL; + if ( hLFE == NULL || *hLFE == NULL ) + { + return; + } - if ( hLFE->lfe_delay_buf != NULL ) + free( ( *hLFE )->pWindow_state ); + ( *hLFE )->pWindow_state = NULL; + + if ( ( *hLFE )->lfe_delay_buf != NULL ) { - free( hLFE->lfe_delay_buf ); - hLFE->lfe_delay_buf = NULL; + free( ( *hLFE )->lfe_delay_buf ); + ( *hLFE )->lfe_delay_buf = NULL; } - free( hLFE ); + free( ( *hLFE ) ); + ( *hLFE ) = NULL; return; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b8b7b74ffc..e28b317408 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -392,9 +392,18 @@ ivas_error ivas_masa_dec_open( *-----------------------------------------------------------------------*/ void ivas_masa_dec_close( - MASA_DECODER_HANDLE hMasa /* i/o: MASA metadata structure */ + MASA_DECODER_HANDLE *hMasa_out /* i/o: MASA metadata structure */ ) { + MASA_DECODER_HANDLE hMasa; + + if ( hMasa_out == NULL || *hMasa_out == NULL ) + { + return; + } + + hMasa = *hMasa_out; + /* Free spherical grid memory if in use */ if ( hMasa->data.sph_grid16 != NULL ) { @@ -436,8 +445,8 @@ void ivas_masa_dec_close( hMasa->hMasaLfeSynth = NULL; } - free( hMasa ); - hMasa = NULL; + free( *hMasa_out ); + *hMasa_out = NULL; return; } diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 6bfddc78e6..a6637ed1f2 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -1124,8 +1124,8 @@ void ivas_param_mc_dec_close( hParamMC->hoa_encoder = NULL; } - free( hParamMC ); - hParamMC = NULL; + free( *hParamMC_out ); + *hParamMC_out = NULL; return; } diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index f6d159083b..3ef12f3094 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -58,10 +58,7 @@ ivas_error ivas_mcmasa_dec_reconfig( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* close the old MASA instance */ - if ( st_ivas->hMasa != NULL ) - { - ivas_masa_dec_close( st_ivas->hMasa ); - } + ivas_masa_dec_close( &( st_ivas->hMasa ) ); /* get new McMASA settings */ ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 96a535f427..553cdf2a1b 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -728,24 +728,14 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hParamMC != NULL ) { ivas_param_mc_dec_close( &st_ivas->hParamMC ); - st_ivas->hParamMC = NULL; /* remove ls conversion if it was allocated by ParamMC */ ivas_ls_setup_conversion_close( &st_ivas->hLsSetUpConversion ); } /* De-allocate McMasa-related handles */ - if ( st_ivas->hMasa != NULL ) - { - ivas_masa_dec_close( st_ivas->hMasa ); - st_ivas->hMasa = NULL; - } - - if ( st_ivas->hQMetaData != NULL ) - { - ivas_qmetadata_close( &st_ivas->hQMetaData ); - st_ivas->hQMetaData = NULL; - } + ivas_masa_dec_close( &( st_ivas->hMasa ) ); + ivas_qmetadata_close( &st_ivas->hQMetaData ); /* init LS conversion if the renderer type asks for it */ if ( st_ivas->renderer_type == RENDERER_MC && st_ivas->hLsSetUpConversion == NULL ) @@ -781,32 +771,18 @@ static ivas_error ivas_mc_dec_reconfig( } /* De-allocate McMasa-related handles */ - if ( st_ivas->hMasa != NULL ) - { - ivas_masa_dec_close( st_ivas->hMasa ); - st_ivas->hMasa = NULL; - } - - if ( st_ivas->hQMetaData != NULL ) - { - ivas_qmetadata_close( &st_ivas->hQMetaData ); - st_ivas->hQMetaData = NULL; - } + ivas_masa_dec_close( &( st_ivas->hMasa ) ); + ivas_qmetadata_close( &st_ivas->hQMetaData ); if ( last_mc_mode == MC_MODE_MCT ) { if ( st_ivas->hMCT != NULL && st_ivas->nchan_transport <= CPE_CHANNELS ) { ivas_mct_dec_close( &st_ivas->hMCT ); - st_ivas->hMCT = NULL; } /* LFE handle */ - if ( st_ivas->hLFE != NULL ) - { - ivas_lfe_dec_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; - } + ivas_lfe_dec_close( &( st_ivas->hLFE ) ); } } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) @@ -840,18 +816,10 @@ static ivas_error ivas_mc_dec_reconfig( if ( last_mc_mode == MC_MODE_MCT ) { - if ( st_ivas->hMCT != NULL ) - { - ivas_mct_dec_close( &st_ivas->hMCT ); - st_ivas->hMCT = NULL; - } + ivas_mct_dec_close( &st_ivas->hMCT ); /* LFE handle */ - if ( st_ivas->hLFE != NULL ) - { - ivas_lfe_dec_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; - } + ivas_lfe_dec_close( &( st_ivas->hLFE ) ); } } @@ -1046,10 +1014,9 @@ static ivas_error ivas_mc_dec_reconfig( } } } - else if ( ( st_ivas->renderer_type == RENDERER_DISABLE ) && ( st_ivas->hDirAC != NULL ) ) + else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL ) { - ivas_dirac_dec_close( st_ivas->hDirAC ); - st_ivas->hDirAC = NULL; + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 76ac3578f9..745ea1b9ba 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -47,7 +47,7 @@ #include "wmc_auto.h" /*-------------------------------------------------------------------* - * ivas_sba_dec_decoder() + * ivas_sba_dec_reconfigure() * * Reconfigure IVAS SBA decoder *-------------------------------------------------------------------*/ @@ -110,8 +110,7 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->sba_mode != SBA_MODE_SPAR ) { - ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs, 0 ); - st_ivas->hSpar = NULL; + ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 0 ); if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, st_ivas->sba_mode, -1 ) ) != IVAS_ERR_OK ) { @@ -138,13 +137,14 @@ ivas_error ivas_sba_dec_reconfigure( if ( nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) { - ivas_spar_dec_close( st_ivas->hSpar, hDecoderConfig->output_Fs, 1 ); + ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); if ( ( error = ivas_spar_dec_open( st_ivas, 1 ) ) != IVAS_ERR_OK ) { return error; } } + ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); } else @@ -253,11 +253,7 @@ ivas_error ivas_sba_dec_reconfigure( if ( ( ( hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_STEREO ) || ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO ) ) && ( ( sba_mode_old != st_ivas->sba_mode ) && ( st_ivas->sba_mode == SBA_MODE_SPAR ) ) ) { - if ( st_ivas->hDirAC != NULL ) - { - ivas_dirac_dec_close( st_ivas->hDirAC ); - st_ivas->hDirAC = NULL; - } + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); @@ -267,16 +263,9 @@ ivas_error ivas_sba_dec_reconfigure( else if ( st_ivas->renderer_type == RENDERER_DISABLE || ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->sba_mode != SBA_MODE_SPAR ) ) { - if ( st_ivas->hDirAC != NULL ) - { - ivas_dirac_dec_close( st_ivas->hDirAC ); - st_ivas->hDirAC = NULL; - } + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); - if ( st_ivas->hVBAPdata != NULL ) - { - vbap_free_data( &( st_ivas->hVBAPdata ) ); - } + vbap_free_data( &( st_ivas->hVBAPdata ) ); } if ( st_ivas->hDirAC != NULL && st_ivas->sba_mode == SBA_MODE_SPAR ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 53c60c3d34..01e4db2ed4 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -61,8 +61,7 @@ static void ivas_spar_dec_MD( Decoder_Struct *st_ivas, Decoder_State *st0 ); *------------------------------------------------------------------------*/ ivas_error ivas_spar_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ - , + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { @@ -187,38 +186,39 @@ ivas_error ivas_spar_dec_open( *------------------------------------------------------------------------*/ void ivas_spar_dec_close( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - const int32_t output_Fs /* i : output sampling rate */ - , + SPAR_DEC_HANDLE *hSpar, /* i/o: SPAR decoder handle */ + const int32_t output_Fs, /* i : output sampling rate */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { - if ( hSpar != NULL ) + if ( *hSpar == NULL || hSpar == NULL ) { - /* MD handle */ - ivas_spar_md_dec_close( &hSpar->hMdDec ); + return; + } - /* TD decorrelator handle */ - ivas_td_decorr_dec_close( &hSpar->hTdDecorr ); + /* MD handle */ + ivas_spar_md_dec_close( &( *hSpar )->hMdDec ); - /* FB mixer handle */ - ivas_FB_mixer_close( &hSpar->hFbMixer, output_Fs, spar_reconfig_flag ); + /* TD decorrelator handle */ + ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr ); - /* AGC */ - ivas_spar_agc_dec_close( &hSpar->hAgcDec ); + /* FB mixer handle */ + ivas_FB_mixer_close( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); - /* PCA */ - if ( hSpar->hPCA != NULL ) - { - free( hSpar->hPCA ); - hSpar->hPCA = NULL; - } + /* AGC */ + ivas_spar_agc_dec_close( &( *hSpar )->hAgcDec ); - if ( !spar_reconfig_flag ) - { - free( hSpar ); - hSpar = NULL; - } + /* PCA */ + if ( ( *hSpar )->hPCA != NULL ) + { + free( ( *hSpar )->hPCA ); + ( *hSpar )->hPCA = NULL; + } + + if ( !spar_reconfig_flag ) + { + free( ( *hSpar ) ); + ( *hSpar ) = NULL; } return; diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index ff6f858d31..3b47d6500e 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -305,6 +305,7 @@ static void ivas_spar_md_dec_matrix_close( free( hMdDecoder->spar_md.band_coeffs ); hMdDecoder->spar_md.band_coeffs = NULL; } + if ( hMdDecoder->mixer_mat != NULL ) { for ( i = 0; i < num_channels; i++ ) @@ -418,11 +419,8 @@ void ivas_spar_md_dec_close( ivas_spar_md_dec_matrix_close( hMdDecoder, num_channels ); - if ( *hMdDec != NULL ) - { - free( *hMdDec ); - *hMdDec = NULL; - } + free( *hMdDec ); + *hMdDec = NULL; return; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 51d825c0fb..a2becebe42 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -805,6 +805,7 @@ typedef struct ivas_spar_md_dec_state_t int16_t table_idx; int16_t dtx_vad; int16_t spar_hoa_md_flag; + } ivas_spar_md_dec_state_t; diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index b8d96233db..fc3e1db99d 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -150,20 +150,19 @@ void stereo_tcx_init_dec( *-------------------------------------------------------------------*/ void stereo_tcx_core_dec( - Decoder_State *st, /* i/o: decoder state structure */ - const FRAME_MODE frameMode, /* i : Decoder frame mode */ - float *signal_out, /* o : synthesis @internal_Fs */ - float *signal_outFB, /* o : synthesis @output_Fs */ - float pitch_buf[], /* o : floating pitch for each subframe */ - const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ - STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const int16_t last_element_mode, /* i : last element mode */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ - STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out /* i : number of output channels */ - , - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const ISM_MODE ism_mode /* i : ISM mode (only needed if format is ISM) */ + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + float *signal_out, /* o : synthesis @internal_Fs */ + float *signal_outFB, /* o : synthesis @output_Fs */ + float pitch_buf[], /* o : floating pitch for each subframe */ + const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const int16_t last_element_mode, /* i : last element mode */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const int16_t nchan_out, /* i : number of output channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const ISM_MODE ism_mode /* i : ISM mode (only needed if format is ISM)*/ ) { int16_t i, k; diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 7019beca8e..ed927f0f13 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -58,9 +58,8 @@ ivas_error init_encoder( const int16_t idchan, /* i : channel ID */ const int16_t var_SID_rate_flag, /* i : flag for variable SID update rate */ const int16_t interval_SID, /* i : interval for SID update */ - const int16_t vad_only_flag /* i : flag to indicate front-VAD structure */ - , - const ISM_MODE ism_mode /* i : ISM mode */ + const int16_t vad_only_flag, /* i : flag to indicate front-VAD structure */ + const ISM_MODE ism_mode /* i : ISM mode */ ) { int16_t i; diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index f98c22b97e..83dbdad1e1 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -195,22 +195,24 @@ void ivas_spar_agc_enc_close( { ivas_agc_enc_state_t *hAgc; + if ( hAgcEnc == NULL || *hAgcEnc == NULL ) + { + return; + } + hAgc = *hAgcEnc; - if ( hAgc != NULL ) - { - free( hAgc->agc_com.winFunc ); - hAgc->agc_com.winFunc = NULL; + free( hAgc->agc_com.winFunc ); + hAgc->agc_com.winFunc = NULL; - free( hAgc->gain_state ); - hAgc->gain_state = NULL; + free( hAgc->gain_state ); + hAgc->gain_state = NULL; - free( hAgc->gain_data ); - hAgc->gain_data = NULL; + free( hAgc->gain_data ); + hAgc->gain_data = NULL; - free( hAgc ); - hAgc = NULL; - } + free( *hAgcEnc ); + *hAgcEnc = NULL; return; } diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index f419425104..e9d6968f1b 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -221,8 +221,7 @@ ivas_error ivas_corecoder_enc_reconfig( if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL ) { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; + ivas_mct_enc_close( &( st_ivas->hMCT ) ); } /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 61edd0b9a9..43bc94fb04 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -245,15 +245,23 @@ ivas_error ivas_dirac_enc_reconfigure( /*------------------------------------------------------------------------- * ivas_dirac_enc_close() * - * Close DirAC + * Close DirAC encoder handle *------------------------------------------------------------------------*/ void ivas_dirac_enc_close( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - const int32_t input_Fs /* i : input sampling rate */ + DIRAC_ENC_HANDLE *hDirAC_out, /* i/o: encoder DirAC handle */ + const int32_t input_Fs /* i : input sampling rate */ ) { int16_t i, j; + DIRAC_ENC_HANDLE hDirAC; + + if ( hDirAC_out == NULL || *hDirAC_out == NULL ) + { + return; + } + + hDirAC = *hDirAC_out; if ( hDirAC->hFbMixer != NULL ) { @@ -303,7 +311,8 @@ void ivas_dirac_enc_close( hDirAC->hConfig = NULL; } - free( hDirAC ); + free( *hDirAC_out ); + *hDirAC_out = NULL; return; } diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 23d0bdd0e5..e117cfc5a5 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -117,17 +117,19 @@ void ivas_spar_covar_enc_close( { ivas_enc_cov_handler_state_t *hCovState; + if ( hCovEnc == NULL || *hCovEnc == NULL ) + { + return; + } + hCovState = *hCovEnc; - if ( hCovState != NULL ) - { - ivas_spar_covar_smooth_enc_close( &hCovState->pCov_state, nchan_inp ); + ivas_spar_covar_smooth_enc_close( &hCovState->pCov_state, nchan_inp ); - ivas_spar_covar_smooth_enc_close( &hCovState->pCov_dtx_state, nchan_inp ); + ivas_spar_covar_smooth_enc_close( &hCovState->pCov_dtx_state, nchan_inp ); - free( hCovState ); - hCovState = NULL; - } + free( *hCovEnc ); + *hCovEnc = NULL; return; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 766caa1519..b51e5d597c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -936,71 +936,39 @@ void ivas_destroy_enc( ivas_qmetadata_close( &( st_ivas->hQMetaData ) ); /* DirAC handle */ - if ( st_ivas->hDirAC != NULL ) + if ( ivas_format == ISM_FORMAT ) { - if ( ivas_format == ISM_FORMAT ) - { - ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); - } - else - { - ivas_dirac_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); - } - st_ivas->hDirAC = NULL; + ivas_param_ism_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); } - - /* SPAR handle */ - if ( st_ivas->hSpar != NULL ) + else { - ivas_spar_enc_close( st_ivas->hSpar, st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); - st_ivas->hSpar = NULL; + ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); } + /* SPAR handle */ + ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 ); + /* MASA handle */ - if ( st_ivas->hMasa != NULL ) - { #ifdef FIX_350_MASA_DELAY_COMP - ivas_masa_enc_close( st_ivas->hMasa ); + ivas_masa_enc_close( &( st_ivas->hMasa ) ); #else - ivas_masa_enc_close( st_ivas->hMasa, st_ivas->nchan_transport, ivas_format ); + ivas_masa_enc_close( &( st_ivas->hMasa ), st_ivas->nchan_transport, ivas_format ); #endif - st_ivas->hMasa = NULL; - } /* MCT handle */ - if ( st_ivas->hMCT != NULL ) - { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; - } + ivas_mct_enc_close( &( st_ivas->hMCT ) ); /* Parametric MC handle */ - if ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hParamMC = NULL; - } + ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); /* Multi-channel MASA handle */ - if ( st_ivas->hMcMasa != NULL ) - { - ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hMcMasa = NULL; - } + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); /* Stereo downmix for EVS encoder handle */ - if ( st_ivas->hStereoDmxEVS != NULL ) - { - stereo_dmx_evs_close_encoder( st_ivas->hStereoDmxEVS ); - st_ivas->hStereoDmxEVS = NULL; - } + stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); /* LFE handle */ - if ( st_ivas->hLFE != NULL ) - { - ivas_lfe_enc_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; - } + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); /* Encoder configuration handle */ if ( st_ivas->hEncoderConfig != NULL ) diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 51295cba6e..ead873af0c 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -390,8 +390,7 @@ ivas_error ivas_ism_enc_config( if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* Deallocate the memory used by ParamISM when switch to Discrete ISM */ - ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hDirAC = NULL; + ivas_param_ism_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs ); } } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index fb69537bc2..cde2327968 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -312,23 +312,29 @@ ivas_error ivas_param_ism_enc_open( /*-------------------------------------------------------------------------* * ivas_param_ism_enc_close() * - * Close Param ISM handle + * Close Param ISM encoder handle *-------------------------------------------------------------------------*/ void ivas_param_ism_enc_close( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - const int32_t input_Fs /* i : input sampling_rate */ + DIRAC_ENC_HANDLE *hDirAC, /* i/o: encoder DirAC handle */ + const int32_t input_Fs /* i : input sampling_rate */ ) { - ivas_FB_mixer_close( &hDirAC->hFbMixer, input_Fs, 0 ); + if ( hDirAC == NULL || *hDirAC == NULL ) + { + return; + } - if ( hDirAC->hParamIsm != NULL ) + ivas_FB_mixer_close( &( *hDirAC )->hFbMixer, input_Fs, 0 ); + + if ( ( *hDirAC )->hParamIsm != NULL ) { - free( hDirAC->hParamIsm ); - hDirAC->hParamIsm = NULL; + free( ( *hDirAC )->hParamIsm ); + ( *hDirAC )->hParamIsm = NULL; } - free( hDirAC ); + free( ( *hDirAC ) ); + ( *hDirAC ) = NULL; return; } @@ -388,6 +394,7 @@ void ivas_param_ism_enc( } } } + /* Quantize DOAs */ ivas_param_ism_enc_quantize_DOA( st_ivas->hIsmMetaData, hParamIsm ); @@ -465,10 +472,10 @@ static void ivas_param_ism_enc_quantize_DOA_dtx( *-------------------------------------------------------------------------*/ void ivas_param_ism_metadata_dtx_enc( - BSTR_ENC_HANDLE hBstr, /* i/o : bitstream handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i : ISM metadata handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i : ISM metadata handles */ ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ - PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ + PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ ) { int16_t i, nBits, nBits_unused; diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index fc16c279ee..a14424774f 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -460,21 +460,27 @@ ivas_error ivas_create_lfe_enc( *-------------------------------------------------------------------------*/ void ivas_lfe_enc_close( - LFE_ENC_HANDLE hLFE /* i/o: LFE encoder handle */ + LFE_ENC_HANDLE *hLFE /* i/o: LFE encoder handle */ ) { - if ( hLFE->old_wtda_audio != NULL ) + if ( hLFE == NULL || *hLFE == NULL ) { - free( hLFE->old_wtda_audio ); - hLFE->old_wtda_audio = NULL; + return; } - if ( hLFE->pWindow_state ) + + if ( ( *hLFE )->old_wtda_audio != NULL ) + { + free( ( *hLFE )->old_wtda_audio ); + ( *hLFE )->old_wtda_audio = NULL; + } + if ( ( *hLFE )->pWindow_state ) { - free( hLFE->pWindow_state ); - hLFE->pWindow_state = NULL; + free( ( *hLFE )->pWindow_state ); + ( *hLFE )->pWindow_state = NULL; } - free( hLFE ); + free( ( *hLFE ) ); + ( *hLFE ) = NULL; return; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index dca9be4010..b930714017 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -149,7 +149,7 @@ ivas_error ivas_masa_enc_open( *-----------------------------------------------------------------------*/ void ivas_masa_enc_close( - MASA_ENCODER_HANDLE hMasa /* i/o: MASA metadata structure */ + MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ #ifndef FIX_350_MASA_DELAY_COMP , const int16_t nchan_transport, /* i : Number of transport channels */ @@ -159,9 +159,14 @@ void ivas_masa_enc_close( { int16_t i; - for ( i = 0; i < hMasa->data.num_Cldfb_instances; i++ ) + if ( hMasa == NULL || *hMasa == NULL ) + { + return; + } + + for ( i = 0; i < ( *hMasa )->data.num_Cldfb_instances; i++ ) { - deleteCldfb( &( hMasa->data.cldfbAnaEnc[i] ) ); + deleteCldfb( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); } #ifndef FIX_350_MASA_DELAY_COMP @@ -169,13 +174,14 @@ void ivas_masa_enc_close( { for ( i = 0; i < nchan_transport; i++ ) { - free( hMasa->data.delay_buffer[i] ); - hMasa->data.delay_buffer[i] = NULL; + free( ( *hMasa )->data.delay_buffer[i] ); + ( *hMasa )->data.delay_buffer[i] = NULL; } } #endif - free( hMasa ); + free( ( *hMasa ) ); + ( *hMasa ) = NULL; return; } diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index e51887d455..db9945d0ce 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -360,14 +360,20 @@ ivas_error ivas_param_mc_enc_reconfig( *------------------------------------------------------------------------*/ void ivas_param_mc_enc_close( - PARAM_MC_ENC_HANDLE hParamMC, /* i/o: Parametric MC encoder handle */ + PARAM_MC_ENC_HANDLE *hParamMC, /* i/o: Parametric MC encoder handle */ const int32_t sampling_rate ) { - ivas_param_mc_metadata_close( &hParamMC->hMetadataPMC ); + if ( hParamMC == NULL || *hParamMC == NULL ) + { + return; + } + + ivas_param_mc_metadata_close( &( *hParamMC )->hMetadataPMC ); - ivas_FB_mixer_close( &hParamMC->hFbMixer, sampling_rate, 0 ); + ivas_FB_mixer_close( &( *hParamMC )->hFbMixer, sampling_rate, 0 ); - free( hParamMC ); + free( ( *hParamMC ) ); + ( *hParamMC ) = NULL; return; } @@ -380,10 +386,10 @@ void ivas_param_mc_enc_close( *------------------------------------------------------------------------*/ void ivas_param_mc_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ - 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 */ + Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + 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 */ ) { int16_t k; diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index b79f4b62e4..866e4e176c 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -451,11 +451,11 @@ ivas_error ivas_mcmasa_enc_reconfig( /* brute-force solution: close McMASA and re-instantiate with new settings */ #ifdef FIX_350_MASA_DELAY_COMP - ivas_masa_enc_close( st_ivas->hMasa ); + ivas_masa_enc_close( &( st_ivas->hMasa ) ); #else - ivas_masa_enc_close( st_ivas->hMasa, st_ivas->nchan_transport, st_ivas->hEncoderConfig->ivas_format ); + ivas_masa_enc_close( &( st_ivas->hMasa ), st_ivas->nchan_transport, st_ivas->hEncoderConfig->ivas_format ); #endif - ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); /* Determine if to separate some channels from the analysis */ ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), ivas_total_brate ); @@ -483,28 +483,33 @@ ivas_error ivas_mcmasa_enc_reconfig( *--------------------------------------------------------------------------*/ void ivas_mcmasa_enc_close( - MCMASA_ENC_HANDLE hMcMasa, /* i/o: encoder McMASA handle */ - const int32_t input_Fs /* i : input sampling rate */ + MCMASA_ENC_HANDLE *hMcMasa, /* i/o: encoder McMASA handle */ + const int32_t input_Fs /* i : input sampling rate */ ) { int16_t i, j; - if ( hMcMasa->separateChannelEnabled ) + if ( hMcMasa == NULL || *hMcMasa == NULL ) { - free( hMcMasa->delay_buffer_lfe[0] ); - free( hMcMasa->delay_buffer_lfe[1] ); + return; + } + + if ( ( *hMcMasa )->separateChannelEnabled ) + { + free( ( *hMcMasa )->delay_buffer_lfe[0] ); + free( ( *hMcMasa )->delay_buffer_lfe[1] ); for ( i = 0; i < 2; i++ ) { - free( hMcMasa->lfeAnaRingBuffer[i] ); + free( ( *hMcMasa )->lfeAnaRingBuffer[i] ); } } - ivas_FB_mixer_close( &hMcMasa->hFbMixer, input_Fs, 0 ); + ivas_FB_mixer_close( &( *hMcMasa )->hFbMixer, input_Fs, 0 ); - if ( !hMcMasa->separateChannelEnabled ) + if ( !( *hMcMasa )->separateChannelEnabled ) { - ivas_FB_mixer_close( &hMcMasa->hFbMixerLfe, input_Fs, 0 ); + ivas_FB_mixer_close( &( *hMcMasa )->hFbMixerLfe, input_Fs, 0 ); } /* intensity 3-dim */ @@ -512,35 +517,36 @@ void ivas_mcmasa_enc_close( { for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - free( hMcMasa->direction_vector_m[i][j] ); - hMcMasa->direction_vector_m[i][j] = NULL; + free( ( *hMcMasa )->direction_vector_m[i][j] ); + ( *hMcMasa )->direction_vector_m[i][j] = NULL; } - for ( j = 0; j < hMcMasa->no_col_avg_diff; j++ ) + for ( j = 0; j < ( *hMcMasa )->no_col_avg_diff; j++ ) { - free( hMcMasa->buffer_intensity_real[i][j] ); - hMcMasa->buffer_intensity_real[i][j] = NULL; + free( ( *hMcMasa )->buffer_intensity_real[i][j] ); + ( *hMcMasa )->buffer_intensity_real[i][j] = NULL; } - free( hMcMasa->buffer_intensity_real[i] ); - hMcMasa->buffer_intensity_real[i] = NULL; + free( ( *hMcMasa )->buffer_intensity_real[i] ); + ( *hMcMasa )->buffer_intensity_real[i] = NULL; - free( hMcMasa->direction_vector_m[i] ); - hMcMasa->direction_vector_m[i] = NULL; + free( ( *hMcMasa )->direction_vector_m[i] ); + ( *hMcMasa )->direction_vector_m[i] = NULL; } - for ( j = 0; j < hMcMasa->no_col_avg_diff; j++ ) + for ( j = 0; j < ( *hMcMasa )->no_col_avg_diff; j++ ) { - free( hMcMasa->buffer_intensity_real_vert[j] ); - hMcMasa->buffer_intensity_real_vert[j] = NULL; + free( ( *hMcMasa )->buffer_intensity_real_vert[j] ); + ( *hMcMasa )->buffer_intensity_real_vert[j] = NULL; } - free( hMcMasa->buffer_intensity_real_vert ); - hMcMasa->buffer_intensity_real_vert = NULL; + free( ( *hMcMasa )->buffer_intensity_real_vert ); + ( *hMcMasa )->buffer_intensity_real_vert = NULL; - free( hMcMasa->buffer_energy ); - hMcMasa->buffer_energy = NULL; + free( ( *hMcMasa )->buffer_energy ); + ( *hMcMasa )->buffer_energy = NULL; - free( hMcMasa ); + free( ( *hMcMasa ) ); + ( *hMcMasa ) = NULL; return; } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 707e74e329..a9ce8e3aba 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -499,29 +499,35 @@ ivas_error mct_enc_reconfigure( *-------------------------------------------------------------------------*/ void ivas_mct_enc_close( - MCT_ENC_HANDLE hMCT /* i/o: MCT encoder structure */ + MCT_ENC_HANDLE *hMCT /* i/o: MCT encoder structure */ ) { int16_t n, maxBlocks; - maxBlocks = hMCT->nchan_out_woLFE / 2; + if ( hMCT == NULL || *hMCT == NULL ) + { + return; + } + + maxBlocks = ( *hMCT )->nchan_out_woLFE / 2; for ( n = 0; n < maxBlocks; n++ ) { - if ( hMCT->hBlockData[n] != NULL ) + if ( ( *hMCT )->hBlockData[n] != NULL ) { - if ( hMCT->hBlockData[n]->hStereoMdct != NULL ) + if ( ( *hMCT )->hBlockData[n]->hStereoMdct != NULL ) { - free( hMCT->hBlockData[n]->hStereoMdct ); - hMCT->hBlockData[n]->hStereoMdct = NULL; + free( ( *hMCT )->hBlockData[n]->hStereoMdct ); + ( *hMCT )->hBlockData[n]->hStereoMdct = NULL; } - free( hMCT->hBlockData[n] ); - hMCT->hBlockData[n] = NULL; + free( ( *hMCT )->hBlockData[n] ); + ( *hMCT )->hBlockData[n] = NULL; } } - free( hMCT ); + free( ( *hMCT ) ); + ( *hMCT ) = NULL; return; } @@ -608,34 +614,18 @@ static ivas_error ivas_mc_enc_reconfig( } /*De-allocate handles for other MC modes*/ - if ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hParamMC = NULL; - } + ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); /* De-allocate McMasa-related handles */ - if ( st_ivas->hMcMasa != NULL ) - { - ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hMcMasa = NULL; - } + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); - if ( st_ivas->hMasa != NULL ) - { #ifdef FIX_350_MASA_DELAY_COMP - ivas_masa_enc_close( st_ivas->hMasa ); + ivas_masa_enc_close( &( st_ivas->hMasa ) ); #else - ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); + ivas_masa_enc_close( &( st_ivas->hMasa ), nchan_transport_old, MC_FORMAT ); #endif - st_ivas->hMasa = NULL; - } - if ( st_ivas->hQMetaData != NULL ) - { - ivas_qmetadata_close( &st_ivas->hQMetaData ); - st_ivas->hQMetaData = NULL; - } + ivas_qmetadata_close( &st_ivas->hQMetaData ); } } else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) @@ -656,39 +646,30 @@ static ivas_error ivas_mc_enc_reconfig( } /* De-allocate McMasa-related handles */ - if ( st_ivas->hMcMasa != NULL ) - { - ivas_mcmasa_enc_close( st_ivas->hMcMasa, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hMcMasa = NULL; - } + ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); + if ( st_ivas->hMasa != NULL ) { #ifdef FIX_350_MASA_DELAY_COMP - ivas_masa_enc_close( st_ivas->hMasa ); + ivas_masa_enc_close( &( st_ivas->hMasa ) ); #else - ivas_masa_enc_close( st_ivas->hMasa, nchan_transport_old, MC_FORMAT ); + ivas_masa_enc_close( &( st_ivas->hMasa ), nchan_transport_old, MC_FORMAT ); #endif st_ivas->hMasa = NULL; } - if ( st_ivas->hQMetaData != NULL ) - { - ivas_qmetadata_close( &st_ivas->hQMetaData ); - st_ivas->hQMetaData = NULL; - } + ivas_qmetadata_close( &st_ivas->hQMetaData ); /* De-allocate MCT handle if last mode was MCT */ - if ( last_mc_mode == MC_MODE_MCT && st_ivas->hMCT != NULL && st_ivas->nchan_transport <= CPE_CHANNELS ) + if ( last_mc_mode == MC_MODE_MCT && st_ivas->nchan_transport <= CPE_CHANNELS ) { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; + ivas_mct_enc_close( &( st_ivas->hMCT ) ); } if ( last_mc_mode == MC_MODE_MCT && st_ivas->hLFE != NULL ) { /* LFE handle */ - ivas_lfe_enc_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); } } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) @@ -721,26 +702,14 @@ static ivas_error ivas_mc_enc_reconfig( } } - if ( st_ivas->hParamMC != NULL ) - { - ivas_param_mc_enc_close( st_ivas->hParamMC, st_ivas->hEncoderConfig->input_Fs ); - st_ivas->hParamMC = NULL; - } + ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); if ( last_mc_mode == MC_MODE_MCT ) { /* LFE handle */ - if ( st_ivas->hLFE != NULL ) - { - ivas_lfe_enc_close( st_ivas->hLFE ); - st_ivas->hLFE = NULL; - } + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); - if ( st_ivas->hMCT != NULL ) - { - ivas_mct_enc_close( st_ivas->hMCT ); - st_ivas->hMCT = NULL; - } + ivas_mct_enc_close( &( st_ivas->hMCT ) ); } } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 11d9c3540f..d3aab0a6e8 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -225,9 +225,7 @@ ivas_error ivas_sba_enc_reconfigure( } else { - ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); - - st_ivas->hSpar = NULL; + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); } hSpar = st_ivas->hSpar; @@ -255,7 +253,7 @@ ivas_error ivas_sba_enc_reconfigure( if ( sba_mode_old == SBA_MODE_SPAR ) { spar_reconfig_flag = 1; - ivas_spar_enc_close( st_ivas->hSpar, hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); + ivas_spar_enc_close( &( st_ivas->hSpar ), hEncoderConfig->input_Fs, hEncoderConfig->nchan_inp, spar_reconfig_flag ); if ( ( error = ivas_spar_enc_open( st_ivas, spar_reconfig_flag ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 7b2155d767..c659979d2b 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -58,8 +58,7 @@ static ivas_error ivas_spar_enc_process( Encoder_Struct *st_ivas, const ENCODER_ *------------------------------------------------------------------------*/ ivas_error ivas_spar_enc_open( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ - , + Encoder_Struct *st_ivas, /* i/o: IVAS encoder handle */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { @@ -232,65 +231,67 @@ ivas_error ivas_spar_enc_open( *------------------------------------------------------------------------*/ void ivas_spar_enc_close( - SPAR_ENC_HANDLE hSpar, /* i/o: SPAR encoder handle */ - const int32_t input_Fs, /* i : input sampling rate */ - const int16_t nchan_inp /* i : number of input channels */ - , + SPAR_ENC_HANDLE *hSpar, /* i/o: SPAR encoder handle */ + const int32_t input_Fs, /* i : input sampling rate */ + const int16_t nchan_inp, /* i : number of input channels */ const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ ) { int16_t num_chans; - if ( hSpar != NULL ) + if ( hSpar == NULL || *hSpar == NULL ) { - if ( !spar_reconfig_flag ) + return; + } + + if ( !spar_reconfig_flag ) + { + /* core-coder-VAD handle */ + if ( ( *hSpar )->hCoreCoderVAD != NULL ) { - /* core-coder-VAD handle */ - if ( hSpar->hCoreCoderVAD != NULL ) - { - destroy_core_enc( hSpar->hCoreCoderVAD ); - hSpar->hCoreCoderVAD = NULL; - } + destroy_core_enc( ( *hSpar )->hCoreCoderVAD ); + ( *hSpar )->hCoreCoderVAD = NULL; + } - /* front-VAD handle */ - if ( hSpar->hFrontVad != NULL ) - { - front_vad_destroy( &hSpar->hFrontVad ); - hSpar->hFrontVad = NULL; - } + /* front-VAD handle */ + if ( ( *hSpar )->hFrontVad != NULL ) + { + front_vad_destroy( &( *hSpar )->hFrontVad ); + ( *hSpar )->hFrontVad = NULL; } + } - num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; - assert( num_chans <= nchan_inp ); + num_chans = ( *hSpar )->hFbMixer->fb_cfg->num_in_chans; + assert( num_chans <= nchan_inp ); - /* MD handle */ - ivas_spar_md_enc_close( &hSpar->hMdEnc ); + /* MD handle */ + ivas_spar_md_enc_close( &( *hSpar )->hMdEnc ); - /* Covar. State handle */ - ivas_spar_covar_enc_close( &hSpar->hCovEnc, num_chans ); + /* Covar. State handle */ + ivas_spar_covar_enc_close( &( *hSpar )->hCovEnc, num_chans ); - /* FB mixer handle */ - ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs, spar_reconfig_flag ); + /* FB mixer handle */ + ivas_FB_mixer_close( &( *hSpar )->hFbMixer, input_Fs, spar_reconfig_flag ); - /* AGC */ - ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); + /* AGC */ + ivas_spar_agc_enc_close( &( *hSpar )->hAgcEnc ); - /* PCA */ - if ( hSpar->hPCA != NULL ) - { - free( hSpar->hPCA ); - hSpar->hPCA = NULL; - } + /* PCA */ + if ( ( *hSpar )->hPCA != NULL ) + { + free( ( *hSpar )->hPCA ); + ( *hSpar )->hPCA = NULL; + } - if ( !spar_reconfig_flag ) - { - /* Trans Det handle */ - ivas_transient_det_close( &hSpar->hTranDet ); - free( hSpar ); - hSpar = NULL; - } + if ( !spar_reconfig_flag ) + { + /* Trans Det handle */ + ivas_transient_det_close( &( *hSpar )->hTranDet ); + free( ( *hSpar ) ); + ( *hSpar ) = NULL; } + return; } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index bcc6718e9a..645f690ac0 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -225,6 +225,11 @@ void ivas_spar_md_enc_close( int16_t num_channels, i, j; ivas_spar_md_enc_state_t *hMdEnc; + if ( hMdEnc_in == NULL || *hMdEnc_in == NULL ) + { + return; + } + hMdEnc = *hMdEnc_in; num_channels = hMdEnc->num_umx_ch; @@ -250,7 +255,6 @@ void ivas_spar_md_enc_close( { for ( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) { free( hMdEnc->cov_real[i][j] ); @@ -264,7 +268,6 @@ void ivas_spar_md_enc_close( { for ( i = 0; i < num_channels; i++ ) { - for ( j = 0; j < num_channels; j++ ) { free( hMdEnc->cov_dtx_real[i][j] ); @@ -288,11 +291,8 @@ void ivas_spar_md_enc_close( free( hMdEnc->mixer_mat_local ); } - if ( hMdEnc != NULL ) - { - free( hMdEnc ); - hMdEnc = NULL; - } + free( *hMdEnc_in ); + *hMdEnc_in = NULL; return; } diff --git a/lib_enc/ivas_stereo_dmx_evs.c b/lib_enc/ivas_stereo_dmx_evs.c index 052970fa70..a5c0fe147f 100644 --- a/lib_enc/ivas_stereo_dmx_evs.c +++ b/lib_enc/ivas_stereo_dmx_evs.c @@ -946,16 +946,22 @@ ivas_error stereo_dmx_evs_init_encoder( *-------------------------------------------------------------------*/ void stereo_dmx_evs_close_encoder( - STEREO_DMX_EVS_ENC_HANDLE hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ + STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS /* i/o: Stereo downmix for EVS encoder handle */ ) { - if ( hStereoDmxEVS->hPOC != NULL ) + if ( hStereoDmxEVS == NULL || *hStereoDmxEVS == NULL ) { - free( hStereoDmxEVS->hPOC ); - hStereoDmxEVS->hPOC = NULL; + return; } - free( hStereoDmxEVS ); + if ( ( *hStereoDmxEVS )->hPOC != NULL ) + { + free( ( *hStereoDmxEVS )->hPOC ); + ( *hStereoDmxEVS )->hPOC = NULL; + } + + free( ( *hStereoDmxEVS ) ); + ( *hStereoDmxEVS ) = NULL; return; } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index f9673656f1..c4941b610c 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -831,11 +831,7 @@ ivas_error ivas_rend_openCrend( if ( ( hRendCfg != NULL ) && ( hRendCfg->roomAcoustics.late_reverb_on ) ) { - if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), - inConfig, - ( *pCrend )->hHrtfCrend, - hRendCfg, - output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), inConfig, ( *pCrend )->hHrtfCrend, hRendCfg, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -853,6 +849,7 @@ ivas_error ivas_rend_openCrend( return IVAS_ERR_OK; } + /*------------------------------------------------------------------------- * ivas_crend_close() * @@ -864,12 +861,7 @@ void ivas_rend_closeCrend( { int16_t i; - if ( pCrend == NULL ) - { - return; - } - - if ( *pCrend == NULL ) + if ( pCrend == NULL || *pCrend == NULL ) { return; } @@ -935,9 +927,11 @@ void ivas_rend_closeCrend( free( *pCrend ); *pCrend = NULL; } + return; } + /*-----------------------------------------------------------------------------------------* * Function ivas_crend_convolver() * diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index ebd7c737a2..58de4819e8 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -284,7 +284,7 @@ void ivas_dirac_dec_close_binaural_data( DIRAC_DEC_BIN_HANDLE *hBinaural /* i/o: decoder DirAC binaural data handle */ ) { - if ( *hBinaural == NULL ) + if ( hBinaural == NULL || *hBinaural == NULL ) { return; } diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index e411d3bbbf..2b1f16d025 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -116,7 +116,6 @@ void ivas_HRTF_CRend_binary_close( return; } - free( *hSetOfHRTF ); *hSetOfHRTF = NULL; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 3a1d28f6cc..9b3c741ceb 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -90,6 +90,7 @@ ivas_error ivas_headTrack_open( return IVAS_ERR_OK; } + #ifdef FIX_I109_ORIENTATION_TRACKING /*-----------------------------------------------------------------------* * ivas_headTrack_close() @@ -101,18 +102,25 @@ void ivas_headTrack_close( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ) { - if ( hHeadTrackData != NULL ) + if ( hHeadTrackData != NULL || *hHeadTrackData != NULL ) { - if ( ( *hHeadTrackData )->OrientationTracker != NULL ) - { - free( ( *hHeadTrackData )->OrientationTracker ); - } - free( ( *hHeadTrackData ) ); - *hHeadTrackData = NULL; + return; + } + + if ( ( *hHeadTrackData )->OrientationTracker != NULL ) + { + free( ( *hHeadTrackData )->OrientationTracker ); + ( *hHeadTrackData )->OrientationTracker = NULL; } + + free( ( *hHeadTrackData ) ); + *hHeadTrackData = NULL; + + return; } #endif + /*---------------------------------------------------------------------------------- * QuatToRotMat() * diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 8059c53346..eda2982689 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -1165,15 +1165,10 @@ static void clearInputIsm( initRendInputBase( &inputIsm->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx ); /* Free input's internal handles */ - if ( inputIsm->crendWrapper != NULL ) - { - ivas_rend_closeCrend( &inputIsm->crendWrapper ); - } - if ( inputIsm->reverb != NULL ) - { - ivas_reverb_close( &inputIsm->reverb ); - } + ivas_rend_closeCrend( &inputIsm->crendWrapper ); + + ivas_reverb_close( &inputIsm->reverb ); if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { @@ -1812,15 +1807,9 @@ static ivas_error initMcBinauralRendering( inputMc->tdRendWrapper.hHrtfTD = NULL; } - if ( inputMc->crendWrapper != NULL ) - { - ivas_rend_closeCrend( &inputMc->crendWrapper ); - } + ivas_rend_closeCrend( &inputMc->crendWrapper ); - if ( inputMc->reverb != NULL ) - { - ivas_reverb_close( &inputMc->reverb ); - } + ivas_reverb_close( &inputMc->reverb ); if ( inputMc->efapInWrapper.hEfap != NULL ) { @@ -2008,15 +1997,9 @@ static void clearInputMc( efap_free_data( &inputMc->efapInWrapper.hEfap ); } - if ( inputMc->crendWrapper != NULL ) - { - ivas_rend_closeCrend( &inputMc->crendWrapper ); - } + ivas_rend_closeCrend( &inputMc->crendWrapper ); - if ( inputMc->reverb != NULL ) - { - ivas_reverb_close( &inputMc->reverb ); - } + ivas_reverb_close( &inputMc->reverb ); if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) { @@ -2227,10 +2210,7 @@ static void clearInputSba( initRendInputBase( &inputSba->base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, rendCtx ); /* Free input's internal handles */ - if ( inputSba->crendWrapper != NULL ) - { - ivas_rend_closeCrend( &inputSba->crendWrapper ); - } + ivas_rend_closeCrend( &inputSba->crendWrapper ); return; } @@ -2608,6 +2588,7 @@ static void freeDecoderDummy( { free( pDecDummy->hDecoderConfig ); } + if ( pDecDummy->hHeadTrackData != NULL ) { #ifdef FIX_I109_ORIENTATION_TRACKING @@ -2640,11 +2621,7 @@ static void freeDecoderDummy( } /* DirAC handle */ - if ( pDecDummy->hDirAC != NULL ) - { - ivas_dirac_dec_close( pDecDummy->hDirAC ); - pDecDummy->hDirAC = NULL; - } + ivas_dirac_dec_close( &( pDecDummy->hDirAC ) ); /* Qmetadata handle */ ivas_qmetadata_close( &pDecDummy->hQMetaData ); -- GitLab From bcd461391c00769702031d1c8143e4c84c8ac149 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 18:44:40 +0100 Subject: [PATCH 10/19] introduce function ivas_ism_metadata_close( ) --- lib_com/ivas_ism_config.c | 32 ++++++++++++++++++++++++++++++++ lib_com/ivas_prot.h | 4 ++++ lib_dec/ivas_init_dec.c | 11 ++--------- lib_enc/ivas_init_enc.c | 9 +-------- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index d6b0999f7e..88c3f10dac 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -37,6 +37,7 @@ #include "rom_com.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_stat_com.h" #include "ivas_rom_com.h" #ifdef DEBUGGING #include "debug.h" @@ -348,6 +349,7 @@ void ivas_ism_reset_metadata( * * Reset ISm metadata parameters *-------------------------------------------------------------------*/ + void ivas_ism_reset_metadata_API( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ) @@ -500,3 +502,33 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } + + +/*--------------------------------------------------------------- + * ivas_ism_metadata_close() + * + * Deallocate ISM metadata handles + * ---------------------------------------------------------------*/ + +void ivas_ism_metadata_close( + ISM_METADATA_HANDLE hIsmMetaData[] /* i/o : object metadata handles */ +) +{ + int16_t n; + + if ( hIsmMetaData == NULL || hIsmMetaData == NULL ) + { + return; + } + + for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) + { + if ( hIsmMetaData[n] != NULL ) + { + free( hIsmMetaData[n] ); + hIsmMetaData[n] = NULL; + } + } + + return; +} diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 194559ee79..6a099204cf 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -864,6 +864,10 @@ void ivas_param_ism_enc_close( const int32_t input_Fs /* i : input sampling_rate */ ); +void ivas_ism_metadata_close( + ISM_METADATA_HANDLE hIsmMetaData[] /* i/o : object metadata handles */ +); + void ivas_param_ism_stereo_dmx( Encoder_Struct *st_ivas, /* i : IVAS encoder structure */ float data[MAX_NUM_OBJECTS][L_FRAME48k], /* i/o: input signal/stereo dmx */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index db95d1ee4e..dea66168f4 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1636,7 +1636,7 @@ void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { - int16_t i, n; + int16_t i; /* CLDFB handles */ for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) @@ -1703,14 +1703,7 @@ void ivas_destroy_dec( } /* ISM metadata handles */ - for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) - { - if ( st_ivas->hIsmMetaData[n] != NULL ) - { - free( st_ivas->hIsmMetaData[n] ); - st_ivas->hIsmMetaData[n] = NULL; - } - } + ivas_ism_metadata_close( st_ivas->hIsmMetaData ); /* ISm renderer handle */ if ( st_ivas->hIsmRendererData != NULL ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 766caa1519..9acdf0d30a 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -916,14 +916,7 @@ void ivas_destroy_enc( } /* ISM metadata handles */ - for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) - { - if ( st_ivas->hIsmMetaData[n] != NULL ) - { - free( st_ivas->hIsmMetaData[n] ); - st_ivas->hIsmMetaData[n] = NULL; - } - } + ivas_ism_metadata_close( st_ivas->hIsmMetaData ); /* ISM DTX Handle */ if ( st_ivas->hISMDTX != NULL ) -- GitLab From af94597efd4bbdb1b84465feebf2f0bebcb8a143 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 18:45:58 +0100 Subject: [PATCH 11/19] rename file --- lib_com/{ivas_ism_config.c => ivas_ism_com.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib_com/{ivas_ism_config.c => ivas_ism_com.c} (100%) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_com.c similarity index 100% rename from lib_com/ivas_ism_config.c rename to lib_com/ivas_ism_com.c -- GitLab From 0bd10c431e8693961104cda1e2c035566e4ad1f9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 18:46:44 +0100 Subject: [PATCH 12/19] rename file --- Workspace_msvc/lib_com.vcxproj | 2 +- Workspace_msvc/lib_com.vcxproj.filters | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index d55896b03c..23aa2ae3f0 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -244,9 +244,9 @@ + - diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index baa1700361..7b6854e718 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -379,9 +379,6 @@ common_evs_c - - common_ivas_c - common_ivas_c @@ -466,6 +463,9 @@ common_ivas_c + + common_ivas_c + -- GitLab From c59c4f16a4c07ee8a4065a13b060ae2ee8c29533 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 18:55:34 +0100 Subject: [PATCH 13/19] remove obsolete assignments --- lib_com/cldfb.c | 17 ++++++++++------- lib_com/prot.h | 4 ++-- lib_dec/init_dec.c | 4 ++-- lib_dec/ivas_corecoder_dec_reconfig.c | 3 --- lib_dec/ivas_init_dec.c | 8 ++++---- lib_enc/init_enc.c | 24 +++++++----------------- lib_enc/ivas_init_enc.c | 8 ++++---- lib_rend/lib_rend.c | 2 -- 8 files changed, 29 insertions(+), 41 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 931fbc723b..1490703aee 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -883,16 +883,19 @@ void deleteCldfb( { HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; - if ( hs ) + if ( h_cldfb == NULL || *h_cldfb == NULL ) { - if ( hs->cldfb_state ) - { - free( hs->cldfb_state ); - } - free( hs ); - *h_cldfb = NULL; + return; } + if ( hs->cldfb_state ) + { + free( hs->cldfb_state ); + } + + free( hs ); + *h_cldfb = NULL; + return; } diff --git a/lib_com/prot.h b/lib_com/prot.h index 4c20c392d4..de6c521048 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2236,7 +2236,7 @@ void LPDmem_enc_init( LPD_state_HANDLE hLPDmem /* i/o: LP memories */ ); -void destroy_encoder( +void destroy_cldfb_encoder( Encoder_State *st /* i/o: state structure */ ); ivas_error evs_enc( @@ -5120,7 +5120,7 @@ ivas_error init_decoder( const MC_MODE mc_mode /* i : MC mode */ ); -void destroy_decoder( +void destroy_cldfb_decoder( Decoder_State *st /* o : Decoder static variables structure */ ); diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index ca3c88b8d1..a8c24a11f5 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -770,12 +770,12 @@ void reset_preecho_dec( /*----------------------------------------------------------------------* - * destroy_decoder() + * destroy_cldfb_decoder() * * Free memory which was allocated in init_decoder() *----------------------------------------------------------------------*/ -void destroy_decoder( +void destroy_cldfb_decoder( Decoder_State *st /* o : Decoder static variables structure */ ) { diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 492339d6d6..a066164da4 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -453,7 +453,6 @@ ivas_error ivas_cldfb_dec_reconfig( if ( st_ivas->ivas_format == SBA_FORMAT && nchan_transport_old == 1 && numCldfbAnalyses_old == 2 && st_ivas->nchan_transport > 1 ) { deleteCldfb( &( st_ivas->cldfbAnaDec[1] ) ); - st_ivas->cldfbAnaDec[1] = NULL; numCldfbAnalyses_old--; } @@ -473,7 +472,6 @@ ivas_error ivas_cldfb_dec_reconfig( for ( i = numCldfbAnalyses; i < numCldfbAnalyses_old; i++ ) { deleteCldfb( &( st_ivas->cldfbAnaDec[i] ) ); - st_ivas->cldfbAnaDec[i] = NULL; } } else if ( numCldfbAnalyses_old < numCldfbAnalyses ) @@ -495,7 +493,6 @@ ivas_error ivas_cldfb_dec_reconfig( for ( i = numCldfbSyntheses; i < numCldfbSyntheses_old; i++ ) { deleteCldfb( &( st_ivas->cldfbSynDec[i] ) ); - st_ivas->cldfbSynDec[i] = NULL; } } else if ( numCldfbSyntheses_old < numCldfbSyntheses ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d392bdd912..c57b33e6d2 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1420,7 +1420,7 @@ void destroy_core_dec( DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ) { - destroy_decoder( hCoreCoder ); + destroy_cldfb_decoder( hCoreCoder ); if ( hCoreCoder->hGSCDec != NULL ) { @@ -1685,9 +1685,6 @@ void ivas_destroy_dec( } } - /* LFE handle */ - ivas_lfe_dec_close( &( st_ivas->hLFE ) ); - /* HP20 filter handles */ if ( st_ivas->mem_hp20_out != NULL ) { @@ -1739,6 +1736,9 @@ void ivas_destroy_dec( /* MCT handle */ ivas_mct_dec_close( &st_ivas->hMCT ); + /* LFE handle */ + ivas_lfe_dec_close( &( st_ivas->hLFE ) ); + /* Parametric MC handle */ ivas_param_mc_dec_close( &st_ivas->hParamMC ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index ed927f0f13..d3cc3f1743 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -862,32 +862,22 @@ void LPDmem_enc_init( return; } + + /*-----------------------------------------------------------------------* - * destroy_encoder() + * destroy_cldfb_encoder() * * Free memory which was allocated in init_encoder() *-----------------------------------------------------------------------*/ -void destroy_encoder( +void destroy_cldfb_encoder( Encoder_State *st /* i/o: Encoder static variables structure */ ) { - if ( st->cldfbSynTd != NULL ) - { - deleteCldfb( &st->cldfbSynTd ); - } - - if ( st->cldfbAnaEnc != NULL ) - { - deleteCldfb( &st->cldfbAnaEnc ); - } - - if ( st->hFdCngEnc != NULL ) - { - deleteFdCngEnc( &st->hFdCngEnc ); - } + deleteCldfb( &st->cldfbSynTd ); + deleteCldfb( &st->cldfbAnaEnc ); - /* Close Core */ + deleteFdCngEnc( &st->hFdCngEnc ); return; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2f6c5199d8..80f58bd99f 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -725,7 +725,7 @@ void destroy_core_enc( ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */ ) { - destroy_encoder( hCoreCoder ); + destroy_cldfb_encoder( hCoreCoder ); if ( hCoreCoder->hSignalBuf != NULL ) { @@ -951,6 +951,9 @@ void ivas_destroy_enc( /* MCT handle */ ivas_mct_enc_close( &( st_ivas->hMCT ) ); + /* LFE handle */ + ivas_lfe_enc_close( &( st_ivas->hLFE ) ); + /* Parametric MC handle */ ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs ); @@ -960,9 +963,6 @@ void ivas_destroy_enc( /* Stereo downmix for EVS encoder handle */ stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) ); - /* LFE handle */ - ivas_lfe_enc_close( &( st_ivas->hLFE ) ); - /* Encoder configuration handle */ if ( st_ivas->hEncoderConfig != NULL ) { diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index eda2982689..95e87ec4ef 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2607,7 +2607,6 @@ static void freeDecoderDummy( if ( pDecDummy->cldfbAnaDec[i] != NULL ) { deleteCldfb( &( pDecDummy->cldfbAnaDec[i] ) ); - pDecDummy->cldfbAnaDec[i] = NULL; } } @@ -2616,7 +2615,6 @@ static void freeDecoderDummy( if ( pDecDummy->cldfbSynDec[i] != NULL ) { deleteCldfb( &( pDecDummy->cldfbSynDec[i] ) ); - pDecDummy->cldfbSynDec[i] = NULL; } } -- GitLab From 53af49c3227de71e070cf785bd52422ced14ef6e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 19:13:24 +0100 Subject: [PATCH 14/19] clang-format --- lib_com/ivas_fb_mixer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 2bf849b410..3e0d68049a 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -831,8 +831,8 @@ static int16_t ivas_calculate_abs_fr( float short_stride_nrg = 0.0f; float cldfb_nrg = 0.0f; int16_t short_stride = pFb->fb_bin_to_band.short_stride; - const int16_t num_bins_per_short_stride_bin = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); - const int16_t num_bins_per_cldfb_band = (const int16_t) ( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); + const int16_t num_bins_per_short_stride_bin = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / short_stride ); + const int16_t num_bins_per_cldfb_band = ( const int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / pFb->fb_bin_to_band.num_cldfb_bands ); float short_stride_max_per_spar_band = 1e-9f; /*loop over all stored Filter Bank Response MDFT coefficients*/ -- GitLab From fb2788bc69fda14c84f8f33941deac92d8f9b9e5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 20 Mar 2023 19:28:48 +0100 Subject: [PATCH 15/19] fix ASAN failures --- lib_dec/ivas_agc_dec.c | 4 ++-- lib_rend/ivas_rotation.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_agc_dec.c b/lib_dec/ivas_agc_dec.c index c874b297be..72ae68a57b 100644 --- a/lib_dec/ivas_agc_dec.c +++ b/lib_dec/ivas_agc_dec.c @@ -142,7 +142,7 @@ void ivas_spar_agc_dec_close( { ivas_agc_dec_state_t *hAgc; - if ( hAgcDec != NULL || *hAgcDec != NULL ) + if ( hAgcDec == NULL || *hAgcDec == NULL ) { return; } @@ -158,7 +158,7 @@ void ivas_spar_agc_dec_close( free( hAgc->gain_data ); hAgc->gain_data = NULL; - free( hAgc ); + free( *hAgcDec ); *hAgcDec = NULL; return; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 9b3c741ceb..2a45c6d61a 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -102,7 +102,7 @@ void ivas_headTrack_close( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ) { - if ( hHeadTrackData != NULL || *hHeadTrackData != NULL ) + if ( hHeadTrackData == NULL || *hHeadTrackData == NULL ) { return; } -- GitLab From aa6aa774ba98e154c277b9aa33a28d858a0421e3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Mar 2023 13:32:57 +0100 Subject: [PATCH 16/19] rename remaining comments 'ISm' -> 'ISM' --- apps/decoder.c | 2 +- apps/encoder.c | 2 +- apps/renderer.c | 2 +- lib_com/ivas_cnst.h | 6 +++--- lib_com/ivas_ism_com.c | 32 ++++++++++++++++-------------- lib_com/ivas_prot.h | 8 ++++---- lib_com/ivas_stat_com.h | 2 +- lib_dec/ivas_decision_matrix_dec.c | 4 ++-- lib_dec/ivas_init_dec.c | 2 +- lib_dec/ivas_ism_metadata_dec.c | 14 ++++++------- lib_dec/ivas_sce_dec.c | 2 +- lib_dec/lib_dec.c | 5 ++--- lib_dec/lib_dec.h | 5 ++--- lib_enc/ivas_decision_matrix_enc.c | 4 ++-- lib_enc/ivas_init_enc.c | 2 +- lib_enc/ivas_ism_metadata_enc.c | 14 ++++++------- lib_enc/lib_enc.c | 4 ++-- lib_rend/ivas_objectRenderer.c | 12 +++++------ lib_rend/ivas_prot_rend.h | 8 ++++---- lib_rend/ivas_rom_rend.c | 2 +- lib_rend/ivas_stat_rend.h | 2 +- lib_util/ism_file_reader.c | 2 +- lib_util/ism_file_writer.c | 2 +- lib_util/ism_file_writer.h | 2 +- 24 files changed, 69 insertions(+), 71 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 9c4329f32f..cdfa57ff0b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1714,7 +1714,7 @@ static ivas_error decodeG192( } } - /* Write ISm metadata to external file(s) */ + /* Write ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { if ( bsFormat == IVAS_DEC_BS_OBJ ) diff --git a/apps/encoder.c b/apps/encoder.c index 17cec67a34..ff6f461838 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -706,7 +706,7 @@ int main( } #endif - /* Read ISm input metadata */ + /* Read ISM input metadata */ for ( i = 0; i < numIsmInputs; ++i ) { if ( ismReaders[i] == NULL ) diff --git a/apps/renderer.c b/apps/renderer.c index 9a3986a77c..5e8ca98e9c 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1918,7 +1918,7 @@ void getMetadataFromFileReader( if ( ( error = IsmFileReader_readNextFrame( ismReader, &ismMetadata ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError (%s) while reading ism metadata from: %s\n\n", ivas_error_to_string( error ), IsmFileReader_getFilePath( ismReader ) ); + fprintf( stderr, "\nError (%s) while reading ISM metadata from: %s\n\n", ivas_error_to_string( error ), IsmFileReader_getFilePath( ismReader ) ); exit( -1 ); } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index a1716d0741..60c9b7fdc7 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -293,7 +293,7 @@ typedef enum /*----------------------------------------------------------------------------------* - * ISm Constants + * ISM Constants *----------------------------------------------------------------------------------*/ #define ISM_NB_BITS_METADATA_NOMINAL ( ( SCE_CORE_16k_LOW_LIMIT - ACELP_16k_LOW_LIMIT ) / FRAMES_PER_SEC ) /* nominal number of metadata bits - used for configuration of Core-Coder modules */ @@ -353,13 +353,13 @@ typedef enum } ISM_MODE; -/* ISm metadata bitstream */ +/* ISM metadata bitstream */ enum { IND_ISM_NUM_OBJECTS, #ifdef TD5 IND_ISM_EXTENDED_FLAG = IND_ISM_NUM_OBJECTS + MAX_NUM_OBJECTS, - IND_ISM_METADATA_FLAG = IND_ISM_EXTENDED_FLAG + MAX_NUM_OBJECTS, /* EN2VE: Is this not supposed to be in the loop part below, since it is one per ISm? */ + IND_ISM_METADATA_FLAG = IND_ISM_EXTENDED_FLAG + MAX_NUM_OBJECTS, /* EN2VE: Is this not supposed to be in the loop part below, since it is one per ISM? */ #else IND_ISM_METADATA_FLAG = IND_ISM_NUM_OBJECTS + MAX_NUM_OBJECTS, #endif diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 078cc053b5..f8eaa8d05f 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -51,7 +51,7 @@ #define FRMS_PER_SECOND ( 1000000000 / FRAME_SIZE_NS ) -#define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISm inactive frames */ +#define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRMS_PER_SECOND ) #define BETA_ISM_LOW_IMP 0.6f @@ -88,15 +88,15 @@ static void bitbudget_to_brate( *-------------------------------------------------------------------*/ ivas_error ivas_ism_config( - const int32_t ism_total_brate, /* i : ISms total bitrate */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int16_t num_obj, /* i : number of objects */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - const int16_t localVAD[MAX_NUM_OBJECTS], /* i : local VAD flag */ - const int16_t ism_imp[], /* i : ISM importance flags */ - int32_t element_brate[], /* o : element bitrate per object */ - int32_t total_brate[], /* o : total bitrate per object */ - int16_t nb_bits_metadata[] /* i/o: number of metadata bits */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t num_obj, /* i : number of objects */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t localVAD[MAX_NUM_OBJECTS], /* i : local VAD flag */ + const int16_t ism_imp[], /* i : ISM importance flags */ + int32_t element_brate[], /* o : element bitrate per object */ + int32_t total_brate[], /* o : total bitrate per object */ + int16_t nb_bits_metadata[] /* i/o: number of metadata bits */ ) { int16_t ch; @@ -129,7 +129,7 @@ ivas_error ivas_ism_config( bits_element[n_ISms - 1] += bits_ism % n_ISms; bitbudget_to_brate( bits_element, element_brate, n_ISms ); - /* count ISm common signaling bits */ + /* count ISM common signaling bits */ if ( hIsmMeta != NULL ) { #ifdef TD5 @@ -296,7 +296,7 @@ ivas_error ivas_ism_config( #ifdef DEBUGGING if ( bits_CoreCoder[ch] == SID_2k40 / FRAMES_PER_SEC ) { - printf( "\nWarning: ISm bitbudget equal to SID!\n" ); + printf( "\nWarning: ISM bitbudget equal to SID!\n" ); } #endif break; @@ -315,7 +315,7 @@ ivas_error ivas_ism_config( tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRMS_PER_SECOND; if ( sum_l( element_brate, n_ISms ) != tmpL ) { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISm bit-budget distribution. Exiting!\n" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISM bit-budget distribution. Exiting!\n" ); } } #endif @@ -327,7 +327,7 @@ ivas_error ivas_ism_config( /*-------------------------------------------------------------------* * ivas_ism_reset_metadata() * - * Reset ISm metadata parameters + * Reset ISM metadata parameters *-------------------------------------------------------------------*/ void ivas_ism_reset_metadata( @@ -345,10 +345,11 @@ void ivas_ism_reset_metadata( return; } + /*-------------------------------------------------------------------* * ivas_ism_reset_metadata_API() * - * Reset ISm metadata parameters + * Reset ISM metadata parameters *-------------------------------------------------------------------*/ void ivas_ism_reset_metadata_API( @@ -361,6 +362,7 @@ void ivas_ism_reset_metadata_API( return; } + /*-------------------------------------------------------------------* * ism_quant_meta() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c981f51c2c..bdbdf847eb 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -739,11 +739,11 @@ void dtx_read_padding_bits( /*----------------------------------------------------------------------------------* - * ISm prototypes + * ISM prototypes *----------------------------------------------------------------------------------*/ ivas_error ivas_ism_config( - const int32_t ism_total_brate, /* i : ISms total bitrate */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ const int16_t num_trans_ch, /* i : number of trans channels */ const int16_t num_obj, /* i : number of objects */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ @@ -810,7 +810,7 @@ ivas_error ivas_ism_enc( ); ivas_error ivas_ism_metadata_enc( - const int32_t ism_total_brate, /* i : ISms total bitrate */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ const int16_t nchan_transport, /* i : number of transport channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ @@ -827,7 +827,7 @@ ivas_error ivas_ism_metadata_enc( ); ivas_error ivas_ism_metadata_dec( - const int32_t ism_total_brate, /* i : ISms total bitrate */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ int16_t *nchan_transport, /* o : number of transport channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder handles */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 5a45575b0a..7e3326af23 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -41,7 +41,7 @@ /*----------------------------------------------------------------------------------* - * Declaration of ISm common (encoder & decoder) structure + * Declaration of ISM common (encoder & decoder) structure *----------------------------------------------------------------------------------*/ #ifdef TD5 diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 2a99953d23..e5be65ae24 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -134,7 +134,7 @@ void ivas_decision_matrix_dec( } else if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) { - /* ISm Low-rate mode -> always WB, ACELP core, IC coder_type */ + /* ISM Low-rate mode -> always WB, ACELP core, IC coder_type */ st->core = ACELP_CORE; } else if ( st->element_mode == IVAS_CPE_MDCT ) @@ -167,7 +167,7 @@ void ivas_decision_matrix_dec( { if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) { - /* ISm Low-rate mode */ + /* ISM Low-rate mode */ st->bwidth = WB; st->coder_type = INACTIVE; *sharpFlag = 0; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index c57b33e6d2..aeddb3b1b0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2038,7 +2038,7 @@ static ivas_error doSanityChecks_IVAS( /* Verify ISM output configuration */ if ( output_config == AUDIO_CONFIG_INVALID ) { - return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISm" ); + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for ISM" ); } } else if ( st_ivas->ivas_format == SBA_FORMAT ) diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 372fa15248..49161c5d44 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -56,11 +56,11 @@ static int16_t decode_radius( DEC_CORE_HANDLE st0, int16_t *last_radius_idx, int /*-------------------------------------------------------------------------* * ivas_ism_metadata_dec() * - * decode and dequantize ISm metadata + * decode and dequantize ISM metadata *-------------------------------------------------------------------------*/ ivas_error ivas_ism_metadata_dec( - const int32_t ism_total_brate, /* i : ISms total bitrate */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ int16_t *nchan_transport, /* o : number of transport channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_DEC_HANDLE hSCE[], /* i/o: SCE decoder handles */ @@ -148,7 +148,7 @@ ivas_error ivas_ism_metadata_dec( if ( !bfi ) { /*----------------------------------------------------------------* - * Read ISm common signaling + * Read ISM common signaling *----------------------------------------------------------------*/ /* read number of objects */ @@ -183,7 +183,7 @@ ivas_error ivas_ism_metadata_dec( } #endif - /* Read ISm present flags (one per object) */ + /* Read ISM present flags (one per object) */ for ( ch = 0; ch < *nchan_transport; ch++ ) { ism_imp[ch] = get_next_indice( st0, ISM_METADATA_FLAG_BITS ); @@ -575,7 +575,7 @@ ivas_error ivas_ism_metadata_dec( st0->bit_stream = bstr_orig; st0->next_bit_pos = next_bit_pos_orig; - /* set bitstream pointers for each ISm */ + /* set bitstream pointers for each ISM */ for ( ch = 1; ch < *nchan_transport; ch++ ) { hSCE[ch]->hCoreCoder[0]->bit_stream = hSCE[ch - 1]->hCoreCoder[0]->bit_stream + ( hSCE[ch - 1]->hCoreCoder[0]->total_brate / FRAMES_PER_SEC ); @@ -607,12 +607,12 @@ ivas_error ivas_ism_metadata_dec_create( int16_t ch; ivas_error error; - /* allocate ISm metadata handles */ + /* allocate ISM metadata handles */ for ( ch = 0; ch < MAX_NUM_OBJECTS; ch++ ) { if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); } st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 228a6e7b3a..87a7659992 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -114,7 +114,7 @@ ivas_error ivas_sce_dec( { if ( st->low_rate_mode ) { - /* ISm Low-rate mode -> always WB */ + /* ISM Low-rate mode -> always WB */ st->bwidth = WB; } else if ( hSCE->element_brate < MIN_BRATE_SWB_SCE ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 3dd712b934..61c9494e30 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -387,9 +387,8 @@ ivas_error IVAS_DEC_Configure( const IVAS_DEC_AUDIO_CONFIG outputFormat, /* i : output format */ const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ - const int16_t enableHeadRotation /* i : enable head rotation for binaural output */ - , - const int16_t renderConfigEnabled /* i : enable Renderer config. file for binaural output */ + const int16_t enableHeadRotation, /* i : enable head rotation for binaural output */ + const int16_t renderConfigEnabled /* i : enable Renderer config. file for binaural output */ ) { Decoder_Struct *st_ivas; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 0e7d8042d8..a717e0002e 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -129,9 +129,8 @@ ivas_error IVAS_DEC_Configure( const IVAS_DEC_AUDIO_CONFIG outputFormat, /* i : output format */ const int16_t customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */ const int16_t hrtfReaderEnabled, /* i : enable HRTF binary file input */ - const int16_t enableHeadRotation /* i : enable head rotation for binaural output */ - ,const int16_t renderConfigEnabled /* i : enable Renderer config. file for binaural output */ - + const int16_t enableHeadRotation, /* i : enable head rotation for binaural output */ + const int16_t renderConfigEnabled /* i : enable Renderer config. file for binaural output */ ); void IVAS_DEC_Close( diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 7b4685251f..b894932958 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -114,7 +114,7 @@ void ivas_decision_matrix_enc( if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) { - /* ISm low-rate mode */ + /* ISM low-rate mode */ st->core = ACELP_CORE; st->coder_type = INACTIVE; } @@ -391,7 +391,7 @@ void ivas_signaling_enc( } else if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) { - /* ISm Low-rate mode -> do nothing -> always WB, ACELP core, IC coder_type */ + /* ISM Low-rate mode -> do nothing -> always WB, ACELP core, IC coder_type */ } else if ( ( st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 ) || st->core_brate <= SID_2k40 ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 80f58bd99f..83161e761f 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -266,7 +266,7 @@ void ivas_initialize_handles_enc( st_ivas->mem_hp20_in = NULL; - /* ISm metadata handles */ + /* ISM metadata handles */ for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) { st_ivas->hIsmMetaData[i] = NULL; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 33ba03a907..7ce4132321 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -119,7 +119,7 @@ ivas_error ivas_set_ism_metadata( /*-------------------------------------------------------------------------* * rate_ism_importance() * - * Rate importance of particular ISm streams + * Rate importance of particular ISM streams *-------------------------------------------------------------------------*/ static void rate_ism_importance( @@ -176,7 +176,7 @@ static void rate_ism_importance( *-------------------------------------------------------------------------*/ ivas_error ivas_ism_metadata_enc( - const int32_t ism_total_brate, /* i : ISms total bitrate */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ const int16_t nchan_transport, /* i : number of transport channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ @@ -319,7 +319,7 @@ ivas_error ivas_ism_metadata_enc( } /*----------------------------------------------------------------* - * Rate importance of particular ISm streams + * Rate importance of particular ISM streams *----------------------------------------------------------------*/ rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); @@ -346,7 +346,7 @@ ivas_error ivas_ism_metadata_enc( } #endif /*----------------------------------------------------------------* - * Write ISm common signaling + * Write ISM common signaling *----------------------------------------------------------------*/ /* write number of objects - unary coding */ @@ -364,7 +364,7 @@ ivas_error ivas_ism_metadata_enc( } #endif - /* write ISm metadata flag (one per object) */ + /* write ISM metadata flag (one per object) */ for ( ch = 0; ch < nchan_transport; ch++ ) { push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); @@ -899,12 +899,12 @@ ivas_error ivas_ism_metadata_enc_create( st_ivas->nSCE = nchan_transport; st_ivas->nCPE = 0; - /* allocate ISm metadata handles */ + /* allocate ISM metadata handles */ for ( ch = 0; ch < n_ISms; ch++ ) { if ( ( st_ivas->hIsmMetaData[ch] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM MetaData\n" ) ); } #ifdef TD5 diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index a2ea72e9a6..a7b252c9d8 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1537,11 +1537,11 @@ static ivas_error printConfigInfo_enc( { if ( hEncoderConfig->ivas_total_brate <= ACELP_32k && hEncoderConfig->nchan_inp > 2 ) { - fprintf( stdout, "IVAS format: Param-ISm (%i streams)\n", hEncoderConfig->nchan_inp ); + fprintf( stdout, "IVAS format: Param-ISM (%i streams)\n", hEncoderConfig->nchan_inp ); } else { - fprintf( stdout, "IVAS format: ISm (%i streams)\n", hEncoderConfig->nchan_inp ); + fprintf( stdout, "IVAS format: ISM (%i streams)\n", hEncoderConfig->nchan_inp ); } } else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 270da74b5c..0c1b219fe5 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -65,7 +65,7 @@ ivas_error ivas_td_binaural_open_unwrap( const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ #ifdef TD5 - const float *directivity, /* i : Directivity pattern (used for ISm) */ + const float *directivity, /* i : Directivity pattern (used for ISM) */ #endif const IVAS_OUTPUT_SETUP hTransSetup, /* i : Loudspeaker layout */ BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o : TD renderer handle */ @@ -267,10 +267,10 @@ void ivas_td_binaural_close( *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - REVERB_HANDLE hReverb, /* i : reverb handle */ + REVERB_HANDLE hReverb, /* i : reverb handle */ AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const int16_t nchan_transport, /* i : Transport channels (ISms) */ + const int16_t nchan_transport, /* i : Transport channels (ISMs) */ const int16_t lfe_idx, /* i : LFE channel index */ IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ @@ -304,9 +304,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( if ( ( hReverb != NULL ) && ( hReverb->pConfig.roomAcoustics.late_reverb_on ) ) { - if ( ( error = ivas_reverb_process( - hReverb, - transport_config, 0, output, reverb_signal, subframe_idx ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_process( hReverb, transport_config, 0, output, reverb_signal, subframe_idx ) ) != IVAS_ERR_OK ) { return error; } @@ -339,7 +337,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - float output[][L_FRAME48k], /* i/o: ISm object synth / rendered output in 0,1 */ + float output[][L_FRAME48k], /* i/o: ISM object synth / rendered output in 0,1 */ const int16_t subframe_length, /* i/o: subframe length */ const int16_t subframe_idx /* i : Subframe index to 5 ms subframe */ ) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 33359eee8c..7fe1a4858f 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -212,10 +212,10 @@ void ivas_HRTF_CRend_binary_close( *----------------------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - REVERB_HANDLE hReverb, /* i : reverb handle */ + REVERB_HANDLE hReverb, /* i : reverb handle */ AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const int16_t nchan_transport, /* i : Transport channels (ISms) */ + const int16_t nchan_transport, /* i : Transport channels (ISMs) */ const int16_t lfe_idx, /* i : LFE channel index */ IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ @@ -246,7 +246,7 @@ ivas_error ivas_td_binaural_open_unwrap( const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ #ifdef TD5 - const float *directivity, /* i : Directivity pattern (used for ISm) */ + const float *directivity, /* i : Directivity pattern (used for ISM) */ #endif const IVAS_OUTPUT_SETUP hTransSetup, /* i : Loudspeaker layout */ BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o : TD renderer handle */ @@ -270,7 +270,7 @@ void ivas_td_binaural_close( ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - float output[][L_FRAME48k], /* i/o: ISm object synth / rendered output in 0,1 */ + float output[][L_FRAME48k], /* i/o: ISM object synth / rendered output in 0,1 */ const int16_t subframe_length, /* i/o: subframe length */ const int16_t subframe_idx /* i : Subframe index to 5 ms subframe */ ); diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 0dfdaf0d28..dd8ca99d80 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -104,7 +104,7 @@ const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS] /*----------------------------------------------------------------------------------* - * TD ISm binaural renderer ROM tables + * TD ISM binaural renderer ROM tables *----------------------------------------------------------------------------------*/ const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS] = diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 96deb7dc37..13c6084b2d 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -419,7 +419,7 @@ typedef struct ivas_reverb_state_t /*----------------------------------------------------------------------------------* - * TD ISm Object Renderer structure + * TD ISM Object Renderer structure *----------------------------------------------------------------------------------*/ typedef struct diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index d25686fd1d..d60a7c1984 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -59,7 +59,7 @@ struct IsmFileReader *---------------------------------------------------------------------*/ IsmFileReader *IsmFileReader_open( - const char *filePath /* i : path to ism metadata file */ + const char *filePath /* i : path to ISM metadata file */ ) { IsmFileReader *self; diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index 7c9227a65c..870cf33586 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -56,7 +56,7 @@ struct IsmFileWriter /*! r: error code */ ivas_error IsmFileWriter_open( const char *filePathWav, /* i : path to output file */ - const int16_t obj_num, /* i : ISm number */ + const int16_t obj_num, /* i : number of ISM channels */ IsmFileWriter **ismWriter /* o : IsmFileWriter handle */ ) { diff --git a/lib_util/ism_file_writer.h b/lib_util/ism_file_writer.h index 24b4c58bd4..d9f731e87e 100644 --- a/lib_util/ism_file_writer.h +++ b/lib_util/ism_file_writer.h @@ -43,7 +43,7 @@ typedef struct IsmFileWriter IsmFileWriter; /*! r: error code */ ivas_error IsmFileWriter_open( const char *filePathWav, /* i : path to output file */ - const int16_t obj_num, /* i : ISm number */ + const int16_t obj_num, /* i : number of ISM channels */ IsmFileWriter **ismWriter /* o : IsmFileReader handle */ ); -- GitLab From 107abba5f19d9baa12d46afa21acaceea2645236 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Mar 2023 14:03:35 +0100 Subject: [PATCH 17/19] editorial improvements in reverb module --- lib_rend/ivas_objectRenderer.c | 6 +- lib_rend/ivas_prot_rend.h | 10 +- lib_rend/ivas_reverb.c | 175 +++++++++++++++++---------------- 3 files changed, 96 insertions(+), 95 deletions(-) diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 0c1b219fe5..99b61c5f69 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -267,12 +267,12 @@ void ivas_td_binaural_close( *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - REVERB_HANDLE hReverb, /* i : reverb handle */ - AUDIO_CONFIG transport_config, /* i : Transport configuration */ + const REVERB_HANDLE hReverb, /* i : reverb handle */ + const AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ const int16_t nchan_transport, /* i : Transport channels (ISMs) */ const int16_t lfe_idx, /* i : LFE channel index */ - IVAS_FORMAT ivas_format, /* i : IVAS format */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ const int16_t Opt_Headrotation, /* i : Head rotation flag */ const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 7fe1a4858f..5bbdea22dd 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -212,12 +212,12 @@ void ivas_HRTF_CRend_binary_close( *----------------------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - REVERB_HANDLE hReverb, /* i : reverb handle */ - AUDIO_CONFIG transport_config, /* i : Transport configuration */ + const REVERB_HANDLE hReverb, /* i : reverb handle */ + const AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ const int16_t nchan_transport, /* i : Transport channels (ISMs) */ const int16_t lfe_idx, /* i : LFE channel index */ - IVAS_FORMAT ivas_format, /* i : IVAS format */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ const int16_t Opt_Headrotation, /* i : Head rotation flag */ const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ @@ -581,12 +581,12 @@ void ivas_reverb_close( ); ivas_error ivas_reverb_process( - REVERB_HANDLE hReverb, /* i/o: reverb state */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const AUDIO_CONFIG input_audio_config, /* i : reverb. input audio configuration */ const int16_t mix_signals, /* i : add reverb to output signal */ float pcm_in[][L_FRAME48k], /* i : the PCM audio to apply reverb on */ float pcm_out[][L_FRAME48k], /* o : the PCM audio with reverb applied */ - const int16_t i_ts + const int16_t i_ts /* i : subframe index */ ); void ivas_rev_delay_line_init( diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index ec5bd928d2..7dc05cff09 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -675,34 +675,34 @@ static ivas_error calc_jot_t60_coeffs( *-----------------------------------------------------------------------------------------*/ static ivas_error initialize_reverb_filters( - REVERB_HANDLE pState ) + REVERB_HANDLE hReverb ) { ivas_error error; error = IVAS_ERR_OK; /* init correlation and coloration filters */ - if ( ( error = ivas_reverb_t2f_f2t_init( &pState->fft_filter_ols, pState->fft_size, pState->fft_subblock_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_t2f_f2t_init( &hReverb->fft_filter_ols, hReverb->fft_size, hReverb->fft_subblock_size ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_reverb_fft_filter_init( &pState->fft_filter_correl_0, pState->fft_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_fft_filter_init( &hReverb->fft_filter_correl_0, hReverb->fft_size ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_reverb_fft_filter_init( &pState->fft_filter_correl_1, pState->fft_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_fft_filter_init( &hReverb->fft_filter_correl_1, hReverb->fft_size ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_reverb_fft_filter_init( &pState->fft_filter_color_0, pState->fft_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_fft_filter_init( &hReverb->fft_filter_color_0, hReverb->fft_size ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_reverb_fft_filter_init( &pState->fft_filter_color_1, pState->fft_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_fft_filter_init( &hReverb->fft_filter_color_1, hReverb->fft_size ) ) != IVAS_ERR_OK ) { return error; } @@ -718,13 +718,13 @@ static ivas_error initialize_reverb_filters( *-----------------------------------------------------------------------------------------*/ static ivas_error set_t60_filter( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t branch, const uint16_t nr_taps, const float coefA[], const float coefB[] ) { - if ( branch >= pState->nr_of_branches ) + if ( branch >= hReverb->nr_of_branches ) { return IVAS_ERR_INTERNAL; } @@ -734,7 +734,7 @@ static ivas_error set_t60_filter( return IVAS_ERR_INTERNAL; } - ivas_reverb_iir_filt_set( &( pState->t60[branch] ), nr_taps, coefA, coefB ); + ivas_reverb_iir_filt_set( &( hReverb->t60[branch] ), nr_taps, coefA, coefB ); return IVAS_ERR_OK; } @@ -747,16 +747,16 @@ static ivas_error set_t60_filter( *-----------------------------------------------------------------------------------------*/ static ivas_error set_feedback_delay( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t branch, const int16_t fb_delay ) { - if ( branch >= pState->nr_of_branches ) + if ( branch >= hReverb->nr_of_branches ) { return IVAS_ERR_INTERNAL; } - pState->delay_line[branch].Delay = fb_delay; + hReverb->delay_line[branch].Delay = fb_delay; return IVAS_ERR_OK; } @@ -769,19 +769,19 @@ static ivas_error set_feedback_delay( *-----------------------------------------------------------------------------------------*/ static ivas_error set_feedback_gain( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t branch, const float *pGain ) { uint16_t gain_idx; - if ( branch >= pState->nr_of_branches ) + if ( branch >= hReverb->nr_of_branches ) { return IVAS_ERR_INTERNAL; } - for ( gain_idx = 0; gain_idx < pState->nr_of_branches; gain_idx++ ) + for ( gain_idx = 0; gain_idx < hReverb->nr_of_branches; gain_idx++ ) { - pState->gain_matrix[branch][gain_idx] = pGain[gain_idx]; + hReverb->gain_matrix[branch][gain_idx] = pGain[gain_idx]; } return IVAS_ERR_OK; @@ -795,7 +795,7 @@ static ivas_error set_feedback_gain( *-----------------------------------------------------------------------------------------*/ static ivas_error set_correl_fft_filter( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t channel, rv_fftwf_type_complex *pSpectrum ) { @@ -806,11 +806,11 @@ static ivas_error set_correl_fft_filter( if ( channel == 0 ) { - ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, pState->fft_filter_correl_0.fft_spectrum, pState->fft_filter_correl_0.fft_size ); + ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, hReverb->fft_filter_correl_0.fft_spectrum, hReverb->fft_filter_correl_0.fft_size ); } else { - ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, pState->fft_filter_correl_1.fft_spectrum, pState->fft_filter_correl_1.fft_size ); + ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, hReverb->fft_filter_correl_1.fft_spectrum, hReverb->fft_filter_correl_1.fft_size ); } return IVAS_ERR_OK; @@ -824,7 +824,7 @@ static ivas_error set_correl_fft_filter( *-----------------------------------------------------------------------------------------*/ static ivas_error set_color_fft_filter( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t channel, rv_fftwf_type_complex *pSpectrum ) { @@ -835,11 +835,11 @@ static ivas_error set_color_fft_filter( if ( channel == 0 ) { - ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, pState->fft_filter_color_0.fft_spectrum, pState->fft_filter_color_0.fft_size ); + ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, hReverb->fft_filter_color_0.fft_spectrum, hReverb->fft_filter_color_0.fft_size ); } else { - ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, pState->fft_filter_color_1.fft_spectrum, pState->fft_filter_color_1.fft_size ); + ivas_reverb_fft_filter_ConvertFFTWF_2_FFTR( pSpectrum, hReverb->fft_filter_color_1.fft_spectrum, hReverb->fft_filter_color_1.fft_size ); } return IVAS_ERR_OK; @@ -853,7 +853,7 @@ static ivas_error set_color_fft_filter( *-----------------------------------------------------------------------------------------*/ static ivas_error set_mixer_level( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const uint16_t channel, const float level[] ) { @@ -863,9 +863,9 @@ static ivas_error set_mixer_level( return IVAS_ERR_INTERNAL; } - for ( branch_idx = 0; branch_idx < pState->nr_of_branches; branch_idx++ ) + for ( branch_idx = 0; branch_idx < hReverb->nr_of_branches; branch_idx++ ) { - pState->mixer[channel][branch_idx] = level[branch_idx]; + hReverb->mixer[channel][branch_idx] = level[branch_idx]; } return IVAS_ERR_OK; @@ -879,7 +879,7 @@ static ivas_error set_mixer_level( *-----------------------------------------------------------------------------------------*/ static void clear_buffers( - REVERB_HANDLE pState ) + REVERB_HANDLE hReverb ) { int16_t branch_idx; ivas_rev_iir_filter_t *iirFilter; @@ -887,15 +887,15 @@ static void clear_buffers( for ( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) { - delay_line = &( pState->delay_line[branch_idx] ); + delay_line = &( hReverb->delay_line[branch_idx] ); set_f( delay_line->pBuffer, 0, delay_line->MaxDelay ); delay_line->BufferPos = 0; - iirFilter = &( pState->t60[branch_idx] ); + iirFilter = &( hReverb->t60[branch_idx] ); set_f( iirFilter->pBuffer, 0, iirFilter->MaxTaps ); } - ivas_reverb_t2f_f2t_ClearHistory( &pState->fft_filter_ols ); + ivas_reverb_t2f_f2t_ClearHistory( &hReverb->fft_filter_ols ); return; } @@ -908,31 +908,31 @@ static void clear_buffers( *-----------------------------------------------------------------------------------------*/ static void set_fft_and_datablock_sizes( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, const int16_t subframe_len ) { - pState->full_block_size = subframe_len; + hReverb->full_block_size = subframe_len; if ( subframe_len == L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES ) { - pState->fft_size = IVAS_REVERB_FFT_SIZE_48K; - pState->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_48K; + hReverb->fft_size = IVAS_REVERB_FFT_SIZE_48K; + hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_48K; } else if ( subframe_len == L_FRAME32k / MAX_PARAM_SPATIAL_SUBFRAMES ) { - pState->fft_size = IVAS_REVERB_FFT_SIZE_32K; - pState->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_32K; + hReverb->fft_size = IVAS_REVERB_FFT_SIZE_32K; + hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_32K; } else if ( subframe_len == L_FRAME16k / MAX_PARAM_SPATIAL_SUBFRAMES ) { - pState->fft_size = IVAS_REVERB_FFT_SIZE_16K; - pState->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_16K; + hReverb->fft_size = IVAS_REVERB_FFT_SIZE_16K; + hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_16K; } else { assert( 0 ); /* unsupported block size */ } - pState->fft_subblock_size = subframe_len / pState->num_fft_subblocks; + hReverb->fft_subblock_size = subframe_len / hReverb->num_fft_subblocks; return; } @@ -1030,7 +1030,7 @@ static void set_reverb_acoustic_data( *-----------------------------------------------------------------------------------------*/ static ivas_error setup_FDN_branches( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, ivas_reverb_params_t *pParams ) { int16_t nr_coefs, branch_idx, channel_idx; @@ -1041,12 +1041,12 @@ static ivas_error setup_FDN_branches( /* initialize feedback branches */ for ( branch_idx = 0; branch_idx < IVAS_REV_MAX_NR_BRANCHES; branch_idx++ ) { - ivas_rev_delay_line_init( &( pState->delay_line[branch_idx] ), pState->loop_delay_buffer[branch_idx], init_loop_delay[branch_idx], pParams->pLoop_delays[branch_idx] ); - ivas_reverb_iir_filt_init( &( pState->t60[branch_idx] ), IVAS_REV_MAX_IIR_FILTER_LENGTH ); - pState->mixer[0][branch_idx] = 0.0f; - pState->mixer[1][branch_idx] = 0.0f; + ivas_rev_delay_line_init( &( hReverb->delay_line[branch_idx] ), hReverb->loop_delay_buffer[branch_idx], init_loop_delay[branch_idx], pParams->pLoop_delays[branch_idx] ); + ivas_reverb_iir_filt_init( &( hReverb->t60[branch_idx] ), IVAS_REV_MAX_IIR_FILTER_LENGTH ); + hReverb->mixer[0][branch_idx] = 0.0f; + hReverb->mixer[1][branch_idx] = 0.0f; } - clear_buffers( pState ); + clear_buffers( hReverb ); nr_coefs = pParams->t60_filter_order + 1; if ( IVAS_REV_MAX_IIR_FILTER_LENGTH < nr_coefs ) @@ -1060,17 +1060,17 @@ static ivas_error setup_FDN_branches( pCoef_a = &pParams->pT60_filter_coeff[2 * nr_coefs * branch_idx + nr_coefs]; pCoef_b = &pParams->pT60_filter_coeff[2 * nr_coefs * branch_idx]; - if ( ( error = set_t60_filter( pState, branch_idx, nr_coefs, pCoef_a, pCoef_b ) ) != IVAS_ERR_OK ) + if ( ( error = set_t60_filter( hReverb, branch_idx, nr_coefs, pCoef_a, pCoef_b ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = set_feedback_delay( pState, branch_idx, pParams->pLoop_delays[branch_idx] ) ) != IVAS_ERR_OK ) + if ( ( error = set_feedback_delay( hReverb, branch_idx, pParams->pLoop_delays[branch_idx] ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = set_feedback_gain( pState, branch_idx, &( pParams->pLoop_feedback_matrix[branch_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) + if ( ( error = set_feedback_gain( hReverb, branch_idx, &( pParams->pLoop_feedback_matrix[branch_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1079,7 +1079,7 @@ static ivas_error setup_FDN_branches( for ( channel_idx = 0; channel_idx < pParams->nr_outputs; channel_idx++ ) { - if ( ( error = set_mixer_level( pState, channel_idx, &( pParams->pLoop_extract_matrix[channel_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) + if ( ( error = set_mixer_level( hReverb, channel_idx, &( pParams->pLoop_extract_matrix[channel_idx * pParams->nr_loops] ) ) ) != IVAS_ERR_OK ) { return error; } @@ -1310,27 +1310,27 @@ void ivas_reverb_close( *-----------------------------------------------------------------------------------------*/ static void post_fft_filter( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, float *p0, float *p1, float *pBuffer_0, float *pBuffer_1 ) { - if ( pState->do_corr_filter ) + if ( hReverb->do_corr_filter ) { - ivas_reverb_t2f_f2t_in( &pState->fft_filter_ols, p0, p1, pBuffer_0, pBuffer_1 ); - ivas_reverb_fft_filter_ComplexMul( &pState->fft_filter_correl_0, pBuffer_0 ); - ivas_reverb_fft_filter_ComplexMul( &pState->fft_filter_correl_1, pBuffer_1 ); - ivas_reverb_fft_filter_CrossMix( pBuffer_0, pBuffer_1, pState->fft_filter_correl_0.fft_size ); + ivas_reverb_t2f_f2t_in( &hReverb->fft_filter_ols, p0, p1, pBuffer_0, pBuffer_1 ); + ivas_reverb_fft_filter_ComplexMul( &hReverb->fft_filter_correl_0, pBuffer_0 ); + ivas_reverb_fft_filter_ComplexMul( &hReverb->fft_filter_correl_1, pBuffer_1 ); + ivas_reverb_fft_filter_CrossMix( pBuffer_0, pBuffer_1, hReverb->fft_filter_correl_0.fft_size ); } else { - ivas_reverb_t2f_f2t_in( &pState->fft_filter_ols, p0, p1, pBuffer_0, pBuffer_1 ); + ivas_reverb_t2f_f2t_in( &hReverb->fft_filter_ols, p0, p1, pBuffer_0, pBuffer_1 ); } - ivas_reverb_fft_filter_ComplexMul( &pState->fft_filter_color_0, pBuffer_0 ); - ivas_reverb_fft_filter_ComplexMul( &pState->fft_filter_color_1, pBuffer_1 ); - ivas_reverb_t2f_f2t_out( &pState->fft_filter_ols, pBuffer_0, pBuffer_1, p0, p1 ); + ivas_reverb_fft_filter_ComplexMul( &hReverb->fft_filter_color_0, pBuffer_0 ); + ivas_reverb_fft_filter_ComplexMul( &hReverb->fft_filter_color_1, pBuffer_1 ); + ivas_reverb_t2f_f2t_out( &hReverb->fft_filter_ols, pBuffer_0, pBuffer_1, p0, p1 ); return; } @@ -1343,14 +1343,14 @@ static void post_fft_filter( *-----------------------------------------------------------------------------------------*/ static void reverb_block( - REVERB_HANDLE pState, + REVERB_HANDLE hReverb, float *pInput, float *pOut0, float *pOut1 ) { - uint16_t nr_branches = pState->nr_of_branches; - uint16_t bsize = pState->full_block_size; + uint16_t nr_branches = hReverb->nr_of_branches; + uint16_t bsize = hReverb->full_block_size; uint16_t inner_bsize = INNER_BLK_SIZE; uint16_t i, j, k, ns, branch_idx, blk_idx, start_sample_idx; @@ -1382,12 +1382,12 @@ static void reverb_block( for ( i = 0; i < nr_branches; i++ ) { float *pOutput_i = &ppOutput[i][0]; - float mixer_0_i = pState->mixer[0][i]; - float mixer_1_i = pState->mixer[1][i]; + float mixer_0_i = hReverb->mixer[0][i]; + float mixer_1_i = hReverb->mixer[1][i]; /* output and feedback are same, get sample from delay line ... */ - ivas_rev_delay_line_get_sample_blk( &( pState->delay_line[i] ), inner_bsize, pTemp ); - ivas_reverb_iir_filt_2taps_feed_blk( &( pState->t60[i] ), inner_bsize, pTemp, ppOutput[i] ); + ivas_rev_delay_line_get_sample_blk( &( hReverb->delay_line[i] ), inner_bsize, pTemp ); + ivas_reverb_iir_filt_2taps_feed_blk( &( hReverb->t60[i] ), inner_bsize, pTemp, ppOutput[i] ); for ( ns = 0; ns < inner_bsize; ns++ ) { pO0[ns] += pOutput_i[ns] * mixer_0_i; /* mixer ch 0 */ @@ -1406,7 +1406,7 @@ static void reverb_block( for ( j = 0; j < nr_branches; j++ ) { - float gain_matrix_j_i = pState->gain_matrix[j][i]; + float gain_matrix_j_i = hReverb->gain_matrix[j][i]; float *pOutput = &ppOutput[j][0]; for ( ns = 0; ns < inner_bsize; ns++ ) { @@ -1414,15 +1414,15 @@ static void reverb_block( } } - ivas_rev_delay_line_feed_sample_blk( &( pState->delay_line[i] ), inner_bsize, pFeedback_input ); + ivas_rev_delay_line_feed_sample_blk( &( hReverb->delay_line[i] ), inner_bsize, pFeedback_input ); } } /* Applying FFT filter to each sub-frame */ - for ( blk_idx = 0; blk_idx < pState->num_fft_subblocks; blk_idx++ ) + for ( blk_idx = 0; blk_idx < hReverb->num_fft_subblocks; blk_idx++ ) { - start_sample_idx = blk_idx * pState->fft_subblock_size; - post_fft_filter( pState, pOut0 + start_sample_idx, pOut1 + start_sample_idx, pFFT_buf[0], pFFT_buf[1] ); + start_sample_idx = blk_idx * hReverb->fft_subblock_size; + post_fft_filter( hReverb, pOut0 + start_sample_idx, pOut1 + start_sample_idx, pFFT_buf[0], pFFT_buf[1] ); } return; @@ -1436,14 +1436,14 @@ static void reverb_block( *-----------------------------------------------------------------------------------------*/ static ivas_error downmix_input_block( - REVERB_HANDLE pState, + const REVERB_HANDLE hReverb, float pcm_in[][L_FRAME48k], const AUDIO_CONFIG input_audio_config, float *pPcm_out, const int16_t input_offset ) { int16_t i, s, nchan_transport; - float dmx_gain = pState->dmx_gain; + float dmx_gain = hReverb->dmx_gain; switch ( input_audio_config ) { @@ -1459,7 +1459,7 @@ static ivas_error downmix_input_block( case AUDIO_CONFIG_ISM4: { nchan_transport = audioCfg2channels( input_audio_config ); - for ( s = 0; s < pState->full_block_size; s++ ) + for ( s = 0; s < hReverb->full_block_size; s++ ) { float temp = pcm_in[0][input_offset + s]; for ( i = 1; i < nchan_transport; i++ ) @@ -1475,7 +1475,7 @@ static ivas_error downmix_input_block( case AUDIO_CONFIG_HOA2: case AUDIO_CONFIG_HOA3: { - for ( s = 0; s < pState->full_block_size; s++ ) + for ( s = 0; s < hReverb->full_block_size; s++ ) { pPcm_out[s] = dmx_gain * pcm_in[0][input_offset + s]; } @@ -1497,35 +1497,35 @@ static ivas_error downmix_input_block( *-----------------------------------------------------------------------------------------*/ static void predelay_block( - REVERB_HANDLE pState, + const REVERB_HANDLE hReverb, float *pInput, float *pOutput ) { uint16_t i, idx, n_samples, blk_size; - uint16_t max_blk_size = (uint16_t) pState->predelay_line.Delay; + uint16_t max_blk_size = (uint16_t) hReverb->predelay_line.Delay; if ( max_blk_size < 2 ) { if ( max_blk_size == 0 ) /* zero-length delay line: just copy the data from input to output */ { - for ( i = 0; i < pState->full_block_size; i++ ) + for ( i = 0; i < hReverb->full_block_size; i++ ) { pOutput[i] = pInput[i]; } } else /* 1-sample length delay line: feed the data sample-by-sample */ { - for ( i = 0; i < pState->full_block_size; i++ ) + for ( i = 0; i < hReverb->full_block_size; i++ ) { - pOutput[i] = ivas_rev_delay_line_get_sample( &( pState->predelay_line ) ); - ivas_rev_delay_line_feed_sample( &( pState->predelay_line ), pInput[i] ); + pOutput[i] = ivas_rev_delay_line_get_sample( &( hReverb->predelay_line ) ); + ivas_rev_delay_line_feed_sample( &( hReverb->predelay_line ), pInput[i] ); } } } else /* multiple-sample length delay line: use block processing */ { idx = 0; - n_samples = pState->full_block_size; + n_samples = hReverb->full_block_size; while ( n_samples > 0 ) { blk_size = n_samples; @@ -1533,8 +1533,8 @@ static void predelay_block( { blk_size = max_blk_size; } - ivas_rev_delay_line_get_sample_blk( &( pState->predelay_line ), blk_size, &pOutput[idx] ); - ivas_rev_delay_line_feed_sample_blk( &( pState->predelay_line ), blk_size, &pInput[idx] ); + ivas_rev_delay_line_get_sample_blk( &( hReverb->predelay_line ), blk_size, &pOutput[idx] ); + ivas_rev_delay_line_feed_sample_blk( &( hReverb->predelay_line ), blk_size, &pInput[idx] ); idx += blk_size; n_samples -= blk_size; } @@ -1551,7 +1551,7 @@ static void predelay_block( *-----------------------------------------------------------------------------------------*/ static void mix_output_block( - REVERB_HANDLE pState, + const REVERB_HANDLE hReverb, const float *pInL, const float *pInR, float *pOutL, @@ -1559,7 +1559,7 @@ static void mix_output_block( { uint16_t i; - for ( i = 0; i < pState->full_block_size; i++ ) + for ( i = 0; i < hReverb->full_block_size; i++ ) { pOutL[i] += pInL[i]; pOutR[i] += pInR[i]; @@ -1576,12 +1576,13 @@ static void mix_output_block( *-----------------------------------------------------------------------------------------*/ ivas_error ivas_reverb_process( - REVERB_HANDLE hReverb, /* i/o: reverb state */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const AUDIO_CONFIG input_audio_config, /* i : reverb. input audio configuration */ const int16_t mix_signals, /* i : add reverb to output signal */ float pcm_in[][L_FRAME48k], /* i : the PCM audio to apply reverb on */ float pcm_out[][L_FRAME48k], /* o : the PCM audio with reverb applied */ - const int16_t i_ts ) + const int16_t i_ts /* i : subframe index */ +) { float tmp0[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES], tmp1[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES], tmp2[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; ivas_error error; -- GitLab From 39bb0e61e852d6ae7e437be391e29957c0bcc082 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Mar 2023 14:39:42 +0100 Subject: [PATCH 18/19] harmonize handle/parameter name --- lib_dec/ivas_stat_dec.h | 2 +- lib_rend/ivas_objectRenderer.c | 18 ++--- lib_rend/ivas_prot_rend.h | 8 +- lib_rend/lib_rend.c | 132 +++++++++++---------------------- 4 files changed, 59 insertions(+), 101 deletions(-) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a2becebe42..d8c0f65349 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1051,7 +1051,7 @@ typedef struct ivas_binaural_rendering_struct /* Convolution module structure */ BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; - /* Variables related to reverb module */ + /* Variables related to reverberator module */ float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; REVERB_STRUCT_HANDLE hReverb; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 99b61c5f69..67b73db6a6 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -267,10 +267,10 @@ void ivas_td_binaural_close( *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - const REVERB_HANDLE hReverb, /* i : reverb handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const int16_t nchan_transport, /* i : Transport channels (ISMs) */ + const int16_t num_src, /* i : number of sources to render */ const int16_t lfe_idx, /* i : LFE channel index */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ @@ -291,7 +291,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( subframe_length = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; /* Update object position(s) */ - TDREND_Update_object_positions( hBinRendererTd, nchan_transport, lfe_idx, ivas_format, hIsmMetaData, output ); + TDREND_Update_object_positions( hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, output ); for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) { @@ -302,7 +302,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( TDREND_Update_listener_orientation( hBinRendererTd, Opt_Headrotation, ( Quaternions != NULL ) ? &Quaternions[subframe_idx] : NULL ); #endif - if ( ( hReverb != NULL ) && ( hReverb->pConfig.roomAcoustics.late_reverb_on ) ) + if ( hReverb != NULL && hReverb->pConfig.roomAcoustics.late_reverb_on ) { if ( ( error = ivas_reverb_process( hReverb, transport_config, 0, output, reverb_signal, subframe_idx ) ) != IVAS_ERR_OK ) { @@ -318,7 +318,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( } - if ( ( hReverb != NULL ) && ( hReverb->pConfig.roomAcoustics.late_reverb_on ) ) + if ( hReverb != NULL && hReverb->pConfig.roomAcoustics.late_reverb_on ) { /* add reverb to rendered signals */ v_add( reverb_signal[0], output[0], output[0], output_frame ); @@ -426,7 +426,7 @@ static void TDREND_Clear_Update_flags( void TDREND_Update_object_positions( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o : TD Renderer handle */ - const int16_t numSources, /* i : Number of sources to render */ + const int16_t num_src, /* i : number of sources to render */ const int16_t lfe_idx, /* i : Input LFE index */ const IVAS_FORMAT in_format, /* i : Format of input sources */ const ISM_METADATA_HANDLE *hIsmMetaData, /* i : Input metadata for ISM objects */ @@ -443,7 +443,7 @@ void TDREND_Update_object_positions( /* For each source, write the frame data to the source object*/ c_indx = 0; - for ( nS = 0; nS < numSources; nS++ ) + for ( nS = 0; nS < num_src; nS++ ) { if ( !( in_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { @@ -636,7 +636,7 @@ ivas_error ivas_td_binaural_renderer_ext( const LSSETUP_CUSTOM_STRUCT *customLsInput, /* i : Input custom loudspeaker layout */ const IVAS_REND_HeadRotData *headRotData, /* i : Input head positions */ const IVAS_REND_AudioObjectPosition *currentPos, /* i : Object position */ - const REVERB_HANDLE reverb, /* i : reverb handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const int16_t output_frame, /* i : output frame length */ float output[][L_FRAME48k] /* i/o: SCE channels / Binaural synthesis */ ) @@ -688,7 +688,7 @@ ivas_error ivas_td_binaural_renderer_ext( #endif } - if ( ( error = ivas_td_binaural_renderer_unwrap( reverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, headRotData->headRotEnabled, + if ( ( error = ivas_td_binaural_renderer_unwrap( hReverb, transport_config, pTDRend->hBinRendererTd, num_src, lfe_idx, ivas_format, hIsmMetaData, headRotData->headRotEnabled, ( headRotData != NULL ) ? headRotData->headPositions : NULL, #ifdef TD5 ( headRotData != NULL ) ? headRotData->Pos : NULL, output, output_frame ) ) != IVAS_ERR_OK ) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 5bbdea22dd..4c79280a86 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -212,10 +212,10 @@ void ivas_HRTF_CRend_binary_close( *----------------------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_unwrap( - const REVERB_HANDLE hReverb, /* i : reverb handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD binaural object renderer handle */ - const int16_t nchan_transport, /* i : Transport channels (ISMs) */ + const int16_t num_src, /* i : number of sources to render */ const int16_t lfe_idx, /* i : LFE channel index */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ ISM_METADATA_HANDLE *hIsmMetaData, /* i : ISM metadata handle */ @@ -234,7 +234,7 @@ ivas_error ivas_td_binaural_renderer_ext( const LSSETUP_CUSTOM_STRUCT *customLsInput, /* i : Input custom loudspeaker layout */ const IVAS_REND_HeadRotData *headRotData, /* i : Input head positions */ const IVAS_REND_AudioObjectPosition *currentPos, /* i : Object position */ - const REVERB_HANDLE reverb, /* i : reverb handle */ + const REVERB_HANDLE hReverb, /* i : Reverberator handle */ const int16_t output_frame, /* i : output frame length */ float output[][L_FRAME48k] /* i/o: SCE channels / Binaural synthesis */ ); @@ -288,7 +288,7 @@ void TDREND_Update_listener_orientation( void TDREND_Update_object_positions( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o : TD Renderer handle */ - const int16_t numSources, /* i : Number of sources to render */ + const int16_t num_src, /* i : number of sources to render */ const int16_t lfe_idx, /* i : Input LFE index */ const IVAS_FORMAT in_format, /* i : Format of input sources */ const ISM_METADATA_HANDLE *hIsmMetaData, /* i : Input metadata for ISM objects */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 95e87ec4ef..919eddb52a 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -116,7 +116,7 @@ typedef struct IVAS_REND_AudioObjectPosition previousPos; TDREND_WRAPPER tdRendWrapper; CREND_WRAPPER_HANDLE crendWrapper; - REVERB_HANDLE reverb; + REVERB_HANDLE hReverb; rotation_matrix rot_mat_prev; } input_ism; @@ -142,7 +142,7 @@ typedef struct EFAP_WRAPPER efapInWrapper; TDREND_WRAPPER tdRendWrapper; CREND_WRAPPER_HANDLE crendWrapper; - REVERB_HANDLE reverb; + REVERB_HANDLE hReverb; rotation_gains rot_gains_prev; lfe_routing lfeRouting; } input_mc; @@ -1103,7 +1103,7 @@ static ivas_error setRendInputActiveIsm( inputIsm->currentPos = defaultObjectPosition(); inputIsm->previousPos = defaultObjectPosition(); inputIsm->crendWrapper = NULL; - inputIsm->reverb = NULL; + inputIsm->hReverb = NULL; inputIsm->tdRendWrapper = defaultTdRendWrapper(); initRotMatrix( inputIsm->rot_mat_prev ); @@ -1132,16 +1132,14 @@ static ivas_error setRendInputActiveIsm( return error; } - if ( ( error = ivas_reverb_open( &( inputIsm->reverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &( inputIsm->hReverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } } else { - if ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, AUDIO_CONFIG_7_1_4, - getIvasAudioConfigFromRendAudioConfig( outConfig ), - hRendCfg, + if ( ( error = ivas_rend_openCrend( &inputIsm->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), hRendCfg, #ifndef FIX_I109_ORIENTATION_TRACKING 0, #endif @@ -1168,7 +1166,7 @@ static void clearInputIsm( ivas_rend_closeCrend( &inputIsm->crendWrapper ); - ivas_reverb_close( &inputIsm->reverb ); + ivas_reverb_close( &inputIsm->hReverb ); if ( inputIsm->tdRendWrapper.hBinRendererTd != NULL ) { @@ -1809,7 +1807,7 @@ static ivas_error initMcBinauralRendering( ivas_rend_closeCrend( &inputMc->crendWrapper ); - ivas_reverb_close( &inputMc->reverb ); + ivas_reverb_close( &inputMc->hReverb ); if ( inputMc->efapInWrapper.hEfap != NULL ) { @@ -1847,7 +1845,7 @@ static ivas_error initMcBinauralRendering( if ( hRendCfg != NULL && hRendCfg->roomAcoustics.use_brir == 0 && hRendCfg->roomAcoustics.late_reverb_on ) { - if ( ( error = ivas_reverb_open( &( inputMc->reverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &( inputMc->hReverb ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, hRendCfg, outSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -1855,9 +1853,7 @@ static ivas_error initMcBinauralRendering( } { - if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, - ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : getIvasAudioConfigFromRendAudioConfig( inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), - hRendCfg, + if ( ( error = ivas_rend_openCrend( &inputMc->crendWrapper, ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) ? AUDIO_CONFIG_7_1_4 : getIvasAudioConfigFromRendAudioConfig( inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), hRendCfg, #ifndef FIX_I109_ORIENTATION_TRACKING 0, #endif @@ -1962,7 +1958,7 @@ static ivas_error setRendInputActiveMc( inputMc->customLsInput = defaultCustomLs(); inputMc->tdRendWrapper = defaultTdRendWrapper(); inputMc->crendWrapper = NULL; - inputMc->reverb = NULL; + inputMc->hReverb = NULL; initRotGains( inputMc->rot_gains_prev ); inputMc->lfeRouting = defaultLfeRouting( inConfig, inputMc->customLsInput, outConfig, *inputMc->base.ctx.pCustomLsOut ); @@ -1999,7 +1995,7 @@ static void clearInputMc( ivas_rend_closeCrend( &inputMc->crendWrapper ); - ivas_reverb_close( &inputMc->reverb ); + ivas_reverb_close( &inputMc->hReverb ); if ( inputMc->tdRendWrapper.hBinRendererTd != NULL ) { @@ -2734,7 +2730,7 @@ ivas_error IVAS_REND_Open( { initRendInputBase( &hIvasRend->inputsIsm[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsIsm[i].crendWrapper = NULL; - hIvasRend->inputsIsm[i].reverb = NULL; + hIvasRend->inputsIsm[i].hReverb = NULL; hIvasRend->inputsIsm[i].tdRendWrapper.hBinRendererTd = NULL; } @@ -2743,7 +2739,7 @@ ivas_error IVAS_REND_Open( initRendInputBase( &hIvasRend->inputsMc[i].base, IVAS_REND_AUDIO_CONFIG_UNKNOWN, 0, getRendCtx( hIvasRend ) ); hIvasRend->inputsMc[i].efapInWrapper.hEfap = NULL; hIvasRend->inputsMc[i].crendWrapper = NULL; - hIvasRend->inputsMc[i].reverb = NULL; + hIvasRend->inputsMc[i].hReverb = NULL; hIvasRend->inputsMc[i].tdRendWrapper.hBinRendererTd = NULL; } @@ -3755,9 +3751,9 @@ ivas_error IVAS_REND_InitConfig( return error; } - if ( ivas_render_config_init_from_rom( &hIvasRend->hRendererConfig, hIvasRend->rendererConfigEnabled ) != IVAS_ERR_OK ) + if ( ( error = ivas_render_config_init_from_rom( &hIvasRend->hRendererConfig, hIvasRend->rendererConfigEnabled ) ) != IVAS_ERR_OK ) { - return IVAS_ERR_INTERNAL_FATAL; + return error; } } else @@ -4434,7 +4430,7 @@ static ivas_error renderIsmToBinaural( NULL, ismInput->base.ctx.pHeadRotData, &ismInput->currentPos, - ismInput->reverb, + ismInput->hReverb, outAudio.config.numSamplesPerChannel, tmpTDRendBuffer ) ) != IVAS_ERR_OK ) { @@ -4471,7 +4467,7 @@ static ivas_error renderIsmToBinauralRoom( headRotData = ismInput->base.ctx.pHeadRotData; rotatedPos = defaultObjectPosition(); - if ( ismInput->reverb != NULL && ismInput->reverb->pConfig.roomAcoustics.use_brir == 0 && ismInput->reverb->pConfig.roomAcoustics.late_reverb_on == 1 && headRotData->headRotEnabled ) + if ( ismInput->hReverb != NULL && ismInput->hReverb->pConfig.roomAcoustics.use_brir == 0 && ismInput->hReverb->pConfig.roomAcoustics.late_reverb_on == 1 && headRotData->headRotEnabled ) { copyBufferTo2dArray( ismInput->base.inputBuffer, tmpRendBuffer ); @@ -4481,7 +4477,7 @@ static ivas_error renderIsmToBinauralRoom( NULL, ismInput->base.ctx.pHeadRotData, &ismInput->currentPos, - ismInput->reverb, + ismInput->hReverb, outAudio.config.numSamplesPerChannel, tmpRendBuffer ) ) != IVAS_ERR_OK ) { @@ -4564,13 +4560,8 @@ static ivas_error renderIsmToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpRendBuffer ); - - if ( ( error = ivas_rend_crendProcess( - ismInput->crendWrapper, - AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM, - NULL, NULL, NULL, NULL, - tmpRendBuffer, - *ismInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( ismInput->crendWrapper, AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM, + NULL, NULL, NULL, NULL, tmpRendBuffer, *ismInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -4657,6 +4648,7 @@ static ivas_error renderIsmToSba( { return error; } + if ( ( error = getAmbisonicsOrder( outConfig, &ambiOrderOut ) ) != IVAS_ERR_OK ) { return error; @@ -4711,7 +4703,6 @@ static ivas_error renderInputIsm( /* Apply input gain to new audio */ v_multc( inAudio.data, ismInput->base.gain, inAudio.data, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); - switch ( getAudioConfigType( outConfig ) ) { case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: @@ -4835,19 +4826,12 @@ static ivas_error renderMcToBinaural( headRotEnabled = mcInput->base.ctx.pHeadRotData->headRotEnabled; inConfig = mcInput->base.inConfig; - if ( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) || - ( headRotEnabled && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) + if ( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) || ( headRotEnabled && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) { copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); - if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->tdRendWrapper, - mcInput->base.inConfig, - &mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - NULL, - mcInput->reverb, - mcInput->base.inputBuffer.config.numSamplesPerChannel, - tmpRendBuffer ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, NULL, + mcInput->hReverb, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer ) ) != IVAS_ERR_OK ) { return error; } @@ -4861,13 +4845,8 @@ static ivas_error renderMcToBinaural( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpRotBuffer.data, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); - if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, - mcInput->base.inConfig, - mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - mcInput->rot_gains_prev, - mcInput->efapInWrapper.hEfap, - tmpRotBuffer ) ) != IVAS_ERR_OK ) + if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, mcInput->base.inConfig, mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, + mcInput->rot_gains_prev, mcInput->efapInWrapper.hEfap, tmpRotBuffer ) ) != IVAS_ERR_OK ) { return error; } @@ -4881,10 +4860,8 @@ static ivas_error renderMcToBinaural( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( - mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, NULL, NULL, NULL, - tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -4919,25 +4896,18 @@ static ivas_error renderMcToBinauralRoom( headRotEnabled = mcInput->base.ctx.pHeadRotData->headRotEnabled; inConfig = mcInput->base.inConfig; - if ( ( mcInput->reverb != NULL && mcInput->reverb->pConfig.roomAcoustics.use_brir == 0 && mcInput->reverb->pConfig.roomAcoustics.late_reverb_on == 1 ) && ( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) || ( headRotEnabled && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) ) + if ( ( mcInput->hReverb != NULL && mcInput->hReverb->pConfig.roomAcoustics.use_brir == 0 && mcInput->hReverb->pConfig.roomAcoustics.late_reverb_on == 1 ) && ( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) || ( headRotEnabled && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) ) { copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); - if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->tdRendWrapper, - mcInput->base.inConfig, - &mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - NULL, - mcInput->reverb, - mcInput->base.inputBuffer.config.numSamplesPerChannel, - tmpRendBuffer ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_renderer_ext( &mcInput->tdRendWrapper, mcInput->base.inConfig, &mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, + NULL, mcInput->hReverb, mcInput->base.inputBuffer.config.numSamplesPerChannel, tmpRendBuffer ) ) != IVAS_ERR_OK ) { return error; } } else { - /* apply rotation */ if ( headRotEnabled ) { @@ -4945,13 +4915,8 @@ static ivas_error renderMcToBinauralRoom( tmpRotBuffer.data = malloc( tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpRotBuffer.data, tmpRotBuffer.config.numSamplesPerChannel * tmpRotBuffer.config.numChannels ); - if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, - mcInput->base.inConfig, - mcInput->customLsInput, - mcInput->base.ctx.pHeadRotData, - mcInput->rot_gains_prev, - mcInput->efapInWrapper.hEfap, - tmpRotBuffer ) ) != IVAS_ERR_OK ) + if ( ( error = rotateFrameMc( mcInput->base.inputBuffer, mcInput->base.inConfig, mcInput->customLsInput, mcInput->base.ctx.pHeadRotData, + mcInput->rot_gains_prev, mcInput->efapInWrapper.hEfap, tmpRotBuffer ) ) != IVAS_ERR_OK ) { return error; } @@ -4965,17 +4930,14 @@ static ivas_error renderMcToBinauralRoom( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( - mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, NULL, NULL, NULL, - tmpRendBuffer, - *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } } - accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); + accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); /* TODO tmu : needs delay compensation */ if ( ( error = renderLfeToBinaural( mcInput, outAudio ) ) != IVAS_ERR_OK ) @@ -5029,7 +4991,7 @@ static ivas_error renderMcCustomLsToBinauralRoom( return error; } - tmpMcBuffer.config.numChannels = (int16_t) tmp; + tmpMcBuffer.config.numChannels = tmp; tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels ); @@ -5041,9 +5003,8 @@ static ivas_error renderMcCustomLsToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ - if ( ( error = ivas_rend_crendProcess( - mcInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, NULL, NULL, NULL, - tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, NULL, NULL, NULL, + tmpCrendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5271,9 +5232,8 @@ static ivas_error renderSbaToBinaural( } /* call CREND */ - if ( ( error = ivas_rend_crendProcess( - sbaInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( sbaInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), NULL, NULL, NULL, NULL, - tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( sbaInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5328,7 +5288,7 @@ static ivas_error renderSbaToBinauralRoom( return error; } - tmpMcBuffer.config.numChannels = (int16_t) tmp; + tmpMcBuffer.config.numChannels = tmp; tmpMcBuffer.data = malloc( tmpMcBuffer.config.numSamplesPerChannel * tmpMcBuffer.config.numChannels * sizeof( float ) ); set_zero( tmpMcBuffer.data, tmpMcBuffer.config.numChannels * tmpMcBuffer.config.numSamplesPerChannel ); @@ -5341,10 +5301,8 @@ static ivas_error renderSbaToBinauralRoom( copyBufferTo2dArray( tmpMcBuffer, tmpCrendBuffer ); /* call CREND */ - if ( ( error = ivas_rend_crendProcess( - sbaInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, NULL, NULL, NULL, - tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_rend_crendProcess( sbaInput->crendWrapper, AUDIO_CONFIG_7_1_4, getIvasAudioConfigFromRendAudioConfig( outConfig ), + NULL, NULL, NULL, NULL, tmpCrendBuffer, *sbaInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } @@ -5592,7 +5550,7 @@ static ivas_error renderActiveInputsMasa( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int32_t i; + int16_t i; input_masa *pCurrentInput; ivas_error error; -- GitLab From 4e9578746c599881fb86924011a89783f920dc2d Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 21 Mar 2023 14:57:27 +0100 Subject: [PATCH 19/19] editorial improvements in lib_rend.c --- lib_rend/lib_rend.c | 104 ++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 75 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 919eddb52a..1dc1c1f956 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -954,6 +954,8 @@ static void closeHeadRotation( { free( hIvasRend->headRotData.hOrientationTracker ); } + + return; } #endif @@ -1065,7 +1067,9 @@ static CREND_WRAPPER defaultCrendWrapper( return w; } -static bool isIoConfigPairSupported( IVAS_REND_AudioConfig inConfig, IVAS_REND_AudioConfig outConfig ) +static bool isIoConfigPairSupported( + IVAS_REND_AudioConfig inConfig, + IVAS_REND_AudioConfig outConfig ) { /* Rendering mono or stereo to binaural is not supported */ if ( ( inConfig == IVAS_REND_AUDIO_CONFIG_MONO || inConfig == IVAS_REND_AUDIO_CONFIG_STEREO ) && @@ -1224,6 +1228,8 @@ static void fillIdentityPanMatrix( { panMatrix[i][i] = 1.0f; } + + return; } static ivas_error initMcPanGainsWithIdentMatrix( @@ -1248,8 +1254,7 @@ static ivas_error initMcPanGainsWithConversionMapping( * Stay with default panning matrix if conversion_matrix is NULL */ for ( i = 0; i < LS_SETUP_CONVERSION_NUM_MAPPINGS; ++i ) { - if ( ls_conversion_mapping[i].input_config == ivasConfigIn && - ls_conversion_mapping[i].output_config == ivasConfigOut ) + if ( ls_conversion_mapping[i].input_config == ivasConfigIn && ls_conversion_mapping[i].output_config == ivasConfigOut ) { /* Mapping found with valid matrix - copy */ if ( ls_conversion_mapping[i].conversion_matrix != NULL ) @@ -1881,7 +1886,7 @@ static lfe_routing defaultLfeRouting( const IVAS_REND_AudioConfig outConfig, const LSSETUP_CUSTOM_STRUCT customLsOut ) { - int32_t i; + int16_t i; lfe_routing routing; /* Set all output gains to zero, then route each input LFE consecutively to the next available output LFE. */ @@ -2473,7 +2478,7 @@ static DecoderDummy *initDecoderDummy( decDummy = malloc( sizeof( DecoderDummy ) ); decDummy->hDecoderConfig = malloc( sizeof( DECODER_CONFIG ) ); decDummy->hDecoderConfig->output_Fs = sampleRate; - decDummy->hDecoderConfig->nchan_out = (int16_t) numOutChannels; + decDummy->hDecoderConfig->nchan_out = numOutChannels; decDummy->hDecoderConfig->Opt_Headrotation = 0; decDummy->hBinRenderer = NULL; @@ -2557,7 +2562,7 @@ static ivas_error setRendInputActiveMasa( { return error; } - inputMasa->decDummy = initDecoderDummy( *rendCtx.pOutSampleRate, (int16_t) numInChannels, outConfig, 0 ); + inputMasa->decDummy = initDecoderDummy( *rendCtx.pOutSampleRate, numInChannels, outConfig, 0 ); inputMasa->metadataHasBeenFed = false; if ( ( error = updateMasaDummyDec( inputMasa, outConfig ) ) != IVAS_ERR_OK ) @@ -2662,10 +2667,7 @@ ivas_error IVAS_REND_Open( ivas_error error; int16_t numOutChannels; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( phIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2824,10 +2826,7 @@ ivas_error IVAS_REND_ConfigureCustomOutputLoudspeakerLayout( input_mc *inputMc; input_sba *inputSba; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -2909,10 +2908,7 @@ ivas_error IVAS_REND_NumOutChannels( { ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || numOutChannels == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3135,10 +3131,7 @@ ivas_error IVAS_REND_AddInput( ivas_error ( *activateInput )( void *, IVAS_REND_AudioConfig, IVAS_REND_InputId, RENDER_CONFIG_DATA * ); int32_t inputIndex; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || inputId == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3207,10 +3200,7 @@ ivas_error IVAS_REND_ConfigureCustomInputLoudspeakerLayout( input_mc *inputMc; ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3276,10 +3266,7 @@ ivas_error IVAS_REND_SetInputGain( input_base *inputBase; ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3313,10 +3300,7 @@ ivas_error IVAS_REND_SetInputLfeMtx( input_mc *pInputMc; ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3367,10 +3351,7 @@ ivas_error IVAS_REND_SetInputLfePos( input_mc *pInputMc; ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3416,10 +3397,7 @@ ivas_error IVAS_REND_RemoveInput( ivas_error error; input_base *inputBase; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3467,10 +3445,7 @@ ivas_error IVAS_REND_GetInputNumChannels( ivas_error error; const input_base *pInput; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || numChannels == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3509,10 +3484,7 @@ ivas_error IVAS_REND_GetDelay( int32_t latency_ns; int32_t max_latency_ns; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || nSamples == NULL || timeScale == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3583,10 +3555,7 @@ ivas_error IVAS_REND_FeedInputAudio( input_base *inputBase; int16_t numInputChannels; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || inputAudio.data == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3650,10 +3619,7 @@ ivas_error IVAS_REND_FeedInputObjectMetadata( input_ism *inputIsm; ivas_error error; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3694,10 +3660,7 @@ ivas_error IVAS_REND_FeedInputMasaMetadata( input_base *inputBase; input_masa *inputMasa; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -3881,10 +3844,7 @@ ivas_error IVAS_REND_SetHeadRotation( IVAS_QUATERNION rotQuat; #endif - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -4224,7 +4184,7 @@ static ivas_error rotateFrameMc( /* initialize gains to passthrough */ for ( ch_in = 0; ch_in < nchan; ch_in++ ) { - set_zero( gains[ch_in], (int16_t) nchan ); + set_zero( gains[ch_in], nchan ); gains[ch_in][ch_in] = 1.f; } @@ -5586,10 +5546,7 @@ ivas_error IVAS_REND_GetSamples( ivas_error error; int16_t numOutChannels; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( hIvasRend == NULL || outAudio.data == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -5667,10 +5624,7 @@ void IVAS_REND_Close( uint16_t i; IVAS_REND_HANDLE hIvasRend; - /*-----------------------------------------------------------------* - * Validate function arguments - *-----------------------------------------------------------------*/ - + /* Validate function arguments */ if ( phIvasRend == NULL || *phIvasRend == NULL ) { return; -- GitLab