From 45cc1b96d208b1dacdca70ddd012a04bfb0fe16d Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 16 Dec 2022 22:56:46 +0200 Subject: [PATCH 001/173] Implementation of contribution 26 - combined objects + MASA (OMASA) input format --- apps/decoder.c | 59 ++ apps/encoder.c | 127 +++ lib_com/ivas_cnst.h | 23 +- lib_com/ivas_ism_config.c | 102 ++- lib_com/ivas_masa_com.c | 249 +++++- lib_com/ivas_prot.h | 166 ++++ lib_com/ivas_rom_com.c | 42 + lib_com/ivas_rom_com.h | 8 + lib_com/ivas_stat_com.h | 4 +- lib_com/options.h | 10 +- lib_dec/ivas_cpe_dec.c | 53 +- lib_dec/ivas_dec.c | 135 ++- lib_dec/ivas_dirac_dec.c | 95 +- lib_dec/ivas_dirac_dec_binaural_functions.c | 388 +++++++- lib_dec/ivas_dirac_output_synthesis_dec.c | 123 ++- lib_dec/ivas_init_dec.c | 175 +++- lib_dec/ivas_ism_metadata_dec.c | 55 +- lib_dec/ivas_ism_param_dec.c | 4 + lib_dec/ivas_ism_renderer.c | 165 ++++ lib_dec/ivas_masa_dec.c | 653 +++++++++++++- lib_dec/ivas_mono_dmx_renderer.c | 17 + lib_dec/ivas_qmetadata_dec.c | 173 +++- lib_dec/ivas_sce_dec.c | 31 +- lib_dec/ivas_stat_dec.h | 55 ++ lib_dec/lib_dec.c | 36 + lib_dec/lib_dec.h | 9 + lib_enc/ivas_cpe_enc.c | 40 +- lib_enc/ivas_enc.c | 96 +- lib_enc/ivas_init_enc.c | 137 ++- lib_enc/ivas_ism_enc.c | 45 +- lib_enc/ivas_ism_metadata_enc.c | 215 ++++- lib_enc/ivas_ism_param_enc.c | 5 + lib_enc/ivas_masa_enc.c | 828 ++++++++++++++++- lib_enc/ivas_omasa_enc.c | 936 ++++++++++++++++++++ lib_enc/ivas_qmetadata_enc.c | 308 ++++++- lib_enc/ivas_sce_enc.c | 10 + lib_enc/ivas_stat_enc.h | 59 ++ lib_enc/lib_enc.c | 97 +- lib_enc/lib_enc.h | 24 + lib_rend/ivas_output_init.c | 20 + 40 files changed, 5663 insertions(+), 114 deletions(-) create mode 100644 lib_enc/ivas_omasa_enc.c diff --git a/apps/decoder.c b/apps/decoder.c index 7f94e19808..79cfb67d4f 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -123,6 +123,12 @@ typedef struct #endif #endif +#ifdef MASAISM_EDIT_OBJECTS + bool editing_ism_enabled; + int16_t index_of_edited_ism; + int16_t azimuth_edited_ism; + int16_t elevation_edited_ism; +#endif } DecArguments; @@ -496,6 +502,17 @@ int main( } } +#ifdef MASAISM_EDIT_OBJECTS + /*------------------------------------------------------------------------------------------* + * Set edited object positions + *------------------------------------------------------------------------------------------*/ + + if ( arg.editing_ism_enabled ) + { + IVAS_DEC_SetEditedIsmPositions( hIvasDec, arg.index_of_edited_ism, arg.azimuth_edited_ism, arg.elevation_edited_ism ); + } +#endif + /*-----------------------------------------------------------------* * Decoding *-----------------------------------------------------------------*/ @@ -690,6 +707,9 @@ static bool parseCmdlIVAS_dec( { int16_t i; char argv_to_upper[FILENAME_MAX]; +#ifdef MASAISM_EDIT_OBJECTS + int32_t tmp; +#endif #ifdef DEBUGGING float ftmp; char stmp[FILENAME_MAX]; @@ -731,6 +751,13 @@ static bool parseCmdlIVAS_dec( arg->inputFormat = IVAS_DEC_INPUT_FORMAT_G192; arg->no_diegetic_pan = 0.f; +#ifdef MASAISM_EDIT_OBJECTS + arg->editing_ism_enabled = false; + arg->index_of_edited_ism = 0; + arg->azimuth_edited_ism = 0; + arg->elevation_edited_ism = 0; +#endif + /*-----------------------------------------------------------------* * Initialization *-----------------------------------------------------------------*/ @@ -958,6 +985,38 @@ static bool parseCmdlIVAS_dec( } i++; } +#ifdef MASAISM_EDIT_OBJECTS + else if ( strcmp( argv_to_upper, "-EDIT_ISM" ) == 0 ) /* Edit ISM position: objectID, azimuth (deg), elevation (deg) */ + { + arg->editing_ism_enabled = true; + i++; + + if ( argc - i <= 6 || argv[i][0] == '-' ) + { + fprintf( stderr, "Error: Edited ISM position parameters not defined! \n\n" ); + usage_dec(); + return false; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + arg->index_of_edited_ism = tmp; + i++; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + arg->azimuth_edited_ism = tmp; + i++; + } + + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + arg->elevation_edited_ism = tmp; + i++; + } + } +#endif /*-----------------------------------------------------------------* * Option not recognized diff --git a/apps/encoder.c b/apps/encoder.c index 0bad34878b..af70f8f0a4 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -98,6 +98,14 @@ typedef union _EncInputFormatConfig /* MC details */ IVAS_ENC_MC_LAYOUT mcLayout; +#ifdef MASA_AND_OBJECTS + struct EncMasaIsmConfig + { + int16_t numObjects; + const char *metadataFiles[IVAS_MAX_NUM_OBJECTS]; + IVAS_ENC_MASA_VARIANT masaVariant; + } masa_ism; +#endif } EncInputFormatConfig; /* Struct for storing cmdln arguments */ @@ -488,6 +496,15 @@ int main( goto cleanup; } break; +#ifdef MASA_AND_OBJECTS + case IVAS_ENC_INPUT_MASA_ISM: + if ( ( error = IVAS_ENC_ConfigureForMASAObjects( hIvasEnc, arg.inputFs, totalBitrate, bandwidth, arg.dtxConfig, arg.inputFormatConfig.masa_ism.numObjects, arg.inputFormatConfig.masa_ism.masaVariant ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_ENC_ConfigureForMASAObjects failed: %s\n\n", IVAS_ENC_GetErrorMessage( error ) ); + exit( -1 ); + } + break; +#endif default: fprintf( stderr, "\nInvalid input type\n\n" ); goto cleanup; @@ -513,7 +530,12 @@ int main( } } + +#ifdef MASA_AND_OBJECTS + const int16_t numIsmInputs = ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_MASA_ISM ) ? arg.inputFormatConfig.ism.numObjects : 0; +#else const int16_t numIsmInputs = arg.inputFormat == IVAS_ENC_INPUT_ISM ? arg.inputFormatConfig.ism.numObjects : 0; +#endif for ( i = 0; i < numIsmInputs; ++i ) { @@ -1446,6 +1468,100 @@ static bool parseCmdlIVAS_enc( return false; } } +#ifdef MASA_AND_OBJECTS + else if ( strcmp( to_upper( argv[i] ), "-ISM_MASA" ) == 0 ) + { + arg->inputFormat = IVAS_ENC_INPUT_MASA_ISM; + i++; + + if ( i < argc - 5 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + if ( tmp <= 0 ) + { + fprintf( stderr, "Error: Too low number of ISM channels specified!\n\n" ); + usage_enc(); + } + else + { + if ( tmp <= IVAS_MAX_NUM_OBJECTS ) /* number of ISM channels */ + { + arg->inputFormatConfig.masa_ism.numObjects = (int16_t) tmp; + } + else + { + fprintf( stderr, "Error: Too high number of ISM channels!\n\n" ); + usage_enc(); + } + } + } + else + { + fprintf( stderr, "Error: Number of ISM channels not specified!\n\n" ); + usage_enc(); + } + if ( i < argc - 4 ) + { + if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + { + i++; + } + + switch ( tmp ) + { + case 1: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_1CH; + break; + case 2: + arg->inputFormatConfig.masa_ism.masaVariant = IVAS_ENC_MASA_2CH; + break; + default: + fprintf( stderr, "Error: MASA channels must for the moment be 1 or 2.\n\n" ); + usage_enc(); + break; + } + } + + /* read input metadata files */ + for ( j = 0; j < arg->inputFormatConfig.masa_ism.numObjects; j++ ) + { + if ( i < argc - 4 ) + { + if ( strcmp( argv[i], "NULL" ) == 0 || strcmp( argv[i], "null" ) == 0 ) + { + /* no metadata input file -> encode only audio streams */ + arg->inputFormatConfig.masa_ism.metadataFiles[j] = NULL; + } + else + { + arg->inputFormatConfig.masa_ism.metadataFiles[j] = argv[i]; + } + + i++; + } + else + { + fprintf( stderr, "Error: not enough arguments\n\n" ); + usage_enc(); + } + } + + if ( i < argc - 4 ) + { + arg->masaMetadataFile = argv[i]; + i++; + } + else + { + fprintf( stderr, "Error: not enough MASA arguments\n\n" ); + usage_enc(); + } + } +#endif else if ( strcmp( argv_to_upper, "-STEREO_DMX_EVS" ) == 0 ) { arg->inputFormat = IVAS_ENC_INPUT_MONO; @@ -1621,6 +1737,10 @@ static void usage_enc( void ) fprintf( stdout, " 96000, 128000, 160000, 192000, 256000) \n" ); fprintf( stdout, " for IVAS SBA, MASA, MC R=(13200, 16400, 24400, 32000, 48000, 64000, 80000, \n" ); fprintf( stdout, " 96000, 128000, 160000, 192000, 256000, 384000, 512000) \n" ); +#ifdef MASA_AND_OBJECTS + fprintf( stdout, " for IVAS MASA and objects R = (13200, 16400, 24400, 32000, 48000, 64000, 96000, 128000, \n" ); + fprintf( stdout, " 160000, 192000, 256000, 384000, 512000)\n" ); +#endif fprintf( stdout, " Alternatively, R can be a bitrate switching file which consists of R values\n" ); fprintf( stdout, " indicating the bitrate for each frame in bps. These values are stored in\n" ); fprintf( stdout, " binary format using 4 bytes per value\n" ); @@ -1644,6 +1764,13 @@ static void usage_enc( void ) fprintf( stdout, "-masa Ch File : MASA format \n" ); fprintf( stdout, " where Ch specifies the number of input/transport channels (1 or 2): \n" ); fprintf( stdout, " and File specifies input file containing parametric metadata \n" ); +#ifdef MASA_AND_OBJECTS + fprintf( stdout, "-ism_masa IsmChannels MasaChannels IsmFiles MasaFile : MASA and objects format \n" ); + fprintf( stdout, " where IsmChannels specifies the number of ISms (1-4)\n" ); + fprintf( stdout, " and MasaChannels specifies the number of MASA input/transport channels (1 or 2) \n" ); + fprintf( stdout, " and IsmFiles specify input files containing metadata, one file per object \n" ); + fprintf( stdout, " and MasaFile specifies MASA input file containing parametric metadata \n" ); +#endif fprintf( stdout, "-mc InputConf : Multi-channel format\n" ); fprintf( stdout, " where InputConf specifies the channel configuration: 5_1, 7_1, 5_1_2, 5_1_4, 7_1_4\n" ); fprintf( stdout, " Loudspeaker positions are assumed to have azimuth and elevation as per \n" ); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 7306216378..0e1aa45572 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -70,7 +70,9 @@ typedef enum SBA_FORMAT, /* IVAS SBA (ambisonics) format */ MASA_FORMAT, /* IVAS MASA format */ MC_FORMAT, /* IVAS multi-channel format */ - +#ifdef MASA_AND_OBJECTS + MASA_ISM_FORMAT, /* IVAS combined MASA + objects format*/ +#endif } IVAS_FORMAT; @@ -179,7 +181,11 @@ typedef enum #define MAX_CPE ( MAX_TRANSPORT_CHANNELS / CPE_CHANNELS ) /* max. number of CPEs */ #define MAX_BITS_METADATA 2640 /* max. bit-budget of metadata, one channel */ /* IVAS_fmToDo: to be confirmed for final value once mature */ +#ifdef MASA_AND_OBJECTS +#define MAX_NUM_METADATA max( 2, MAX_NUM_OBJECTS + 2 ) /* number of max. metadata (now only 2 for DirAC) */ +#else #define MAX_NUM_METADATA max( 2, MAX_NUM_OBJECTS ) /* number of max. metadata (now only 2 for DirAC) */ +#endif #define IVAS_ENC_DELAY_NS ACELP_LOOK_NS @@ -345,6 +351,12 @@ typedef enum ISM_MODE_NONE, ISM_MODE_DISC, /* discrete ISM */ ISM_MODE_PARAM /* parametric ISM */ +#ifdef MASA_AND_OBJECTS + , + ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ + ISM_MASA_MODE_ONE_OBJ, /* MASA ISM mode when one object is encoded separarately */ + ISM_MASA_MODE_DISC +#endif } ISM_MODE; @@ -1088,6 +1100,12 @@ enum #define MASA_DELTA_AZI_DCT 10 #define MASA_TRANSP_BITS 1 +#ifdef MASA_AND_OBJECTS +#define MASA_ISM_FORMAT_BITS 1 +#define NO_BITS_MASA_ISM_NO_OBJ 2 +#define MASA2TOTAL_THR 0.98f +#define BITS_MASA2TOTTAL_DCT0 6 +#endif #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 @@ -1143,6 +1161,9 @@ enum #define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f #define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f #define MASA_STEREO_MIN_BITRATE IVAS_24k4 +#ifdef MASA_AND_OBJECTS +#define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ +#endif #define MASA_BIT_REDUCT_PARAM 10 #define MASA_MAXIMUM_TWO_DIR_BANDS 18 diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index fc4be3127e..4869de36ce 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -96,6 +96,10 @@ ivas_error ivas_ism_config( 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 */ +#ifdef MASA_AND_OBJECTS + , + int16_t masa_ism_flag /* i : flag indicating ISM MASA format */ +#endif ) { int16_t ch; @@ -107,9 +111,20 @@ ivas_error ivas_ism_config( int16_t n_ISms; ivas_error error; - error = IVAS_ERR_OK; - n_ISms = nchan_transport; + error = IVAS_ERR_OK; +#ifdef MASA_AND_OBJECTS + if ( masa_ism_flag == 1 ) + { + n_ISms = num_obj; + } + else + { +#endif + n_ISms = nchan_transport; +#ifdef MASA_AND_OBJECTS + } +#endif /* initialization */ ism_metadata_flag_global = 0; @@ -131,7 +146,16 @@ ivas_error ivas_ism_config( /* count ISm common signaling bits */ if ( hIsmMeta != NULL ) { +#ifdef MASA_AND_OBJECTS + nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS; + if ( masa_ism_flag == 0 ) + { + /* the bits for writing the number of objects are counted here for pure ISM modes */ + nb_bits_metadata[0] += num_obj; + } +#else nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + num_obj; +#endif for ( ch = 0; ch < n_ISms; ch++ ) { @@ -490,3 +514,77 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } +#ifdef MASA_AND_OBJECTS +/*--------------------------------------------------------------- + * ivas_omasa_ism_mode_select() + * + * selects the ISM mode base on bit-rate and number of objects in the combined ISM MASA format mode + * ---------------------------------------------------------------*/ + +/*! r : ISM format mode */ +ISM_MODE ivas_omasa_ism_mode_select( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t no_obj /* i : number of objects */ +) +{ + ISM_MODE ism_mode = ISM_MODE_NONE; + + switch ( no_obj ) + { + case 1: + if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_48k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 2: + if ( ivas_total_brate >= IVAS_80k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + else if ( ivas_total_brate >= IVAS_48k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 3: + + case 4: + if ( ivas_total_brate >= IVAS_160k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_80k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + else if ( ivas_total_brate >= IVAS_48k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_NONE; + } + break; + } + + return ism_mode; +} +#endif diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index f98dcd8414..bf08a0b229 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -66,6 +66,12 @@ void ivas_masa_set_elements( int16_t *element_mode, /* o : element mode */ int16_t *nSCE, /* o : number of SCEs */ int16_t *nCPE /* o : number of CPEs */ +#ifdef MASA_AND_OBJECTS + , + int16_t ivas_format, + const ISM_MODE ism_mode, + int32_t sce_brate +#endif ) { if ( nchan_transport == 2 ) @@ -78,16 +84,43 @@ void ivas_masa_set_elements( *element_mode = IVAS_SCE; /* This is needed for the initialization phase to initialize codec mode to SCE, since it is written first to the file*/ } else +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) + { + + *nCPE = 1; + + if ( *element_mode == -1 ) + { + *element_mode = IVAS_CPE_DFT; /* To have it initialized in case it was not already. */ + } + if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO ) + { + *element_mode = IVAS_CPE_MDCT; + if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_ONE_OBJ ) && ( ivas_total_brate - sce_brate < MIN_BRATE_MDCT_STEREO ) ) + { + *element_mode = IVAS_CPE_DFT; + } + } + } + else +#endif { *nCPE = 1; *nSCE = 0; - if ( ivas_total_brate > IVAS_48k ) + if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO ) { *element_mode = IVAS_CPE_MDCT; } } hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ); +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) + { + hQMetaData->bits_frame_nominal -= (int16_t) ( sce_brate / FRAMES_PER_SEC ); + } +#endif } else if ( nchan_transport == 1 ) { @@ -388,3 +421,217 @@ void masa_sample_rate_band_correction( return; } + +#ifdef MASA_AND_OBJECTS +/*--------------------------------------------------------------- + * valid() + * + * Checking validity of the index of an ISM ratio index vector, + * within the indexing function. + *---------------------------------------------------------------*/ +int16_t valid( /* o: valid or not 1/0 */ + int16_t index, /* i: index to be checked */ + int16_t K, /* i: L1 norm to check against */ + int16_t len /* i: vector length */ +) +{ + int16_t out; + int16_t i, sum, elem; + int16_t base[4]; + + sum = 0; + set_s( base, 1, len ); + + + for ( i = 1; i < len; i++ ) + { + base[i] = base[i - 1] * 10; + } + sum = 0; + for ( i = len - 1; i >= 0; i-- ) + { + elem = index / base[i]; + sum += elem; + index -= elem * base[i]; + } + if ( sum <= K ) + { + out = 1; + } + else + { + out = 0; + } + return out; +} + +/*--------------------------------------------------------------- + * reconstruct_ism_ratios() + * + * Obtains ISM ratio values from the quantized indexes + *---------------------------------------------------------------*/ +void reconstruct_ism_ratios( + int16_t *ratio_ism_idx, /* i: index vector */ + int16_t n_ism, /* i: number of components/objects */ + float step, /* i: quantization step */ + float *q_energy_ratio_ism /* o: reconstructed ISM values */ +) +{ + int16_t i; + float sum; + sum = 0; + for ( i = 0; i < n_ism - 1; i++ ) + { + q_energy_ratio_ism[i] = ratio_ism_idx[i] * step; + sum += q_energy_ratio_ism[i]; + } + q_energy_ratio_ism[n_ism - 1] = 1.0f - sum; + return; +} + +/*--------------------------------------------------------------- + * modify_masa_energy_ratios() + * + * Updates energy ratios by taking into account the MASA content contribution + * to the total audio scene + *---------------------------------------------------------------*/ +void modify_masa_energy_ratios( + IVAS_QMETADATA_HANDLE hQMetaData /* i/o: Metadata handle */ +) +{ + int16_t i, m, d, b; + for ( m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES; m++ ) + { + if ( hQMetaData->q_direction[0].cfg.nblocks == 1 ) + { + i = 0; + } + else + { + i = m; + } + + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + for ( d = 0; d < hQMetaData->no_directions; d++ ) + { + hQMetaData->q_direction[d].band_data[b].energy_ratio[m] = hQMetaData->q_direction[d].band_data[b].energy_ratio[m] * hQMetaData->masa_to_total_energy_ratio[i][b]; + } + } + } +} + +/*--------------------------------------------------------------- + * ivas_get_stereo_panning_gains() + * + * + *---------------------------------------------------------------*/ +void ivas_get_stereo_panning_gains( + float aziDeg, + float eleDeg, + float panningGains[2] ) +{ + float aziRad, eleRad; + float y, mappedX, aziRadMapped, A, A2, A3; + const float LsAngleRad = 30.0f * PI_OVER_180; + /* Convert azi and ele to an azi value of the cone of confusion */ + aziRad = aziDeg * PI_OVER_180; + eleRad = eleDeg * PI_OVER_180; + y = ( sinf( aziRad ) * cosf( eleRad ) ); + mappedX = sqrtf( max( 0.0f, 1.0f - ( y * y ) ) ); + aziRadMapped = atan2f( y, mappedX ); + + if ( aziRadMapped >= LsAngleRad ) + { /* Left side */ + panningGains[0] = 1.0f; + panningGains[1] = 0.0f; + } + else if ( aziRadMapped <= -LsAngleRad ) + { /* Right side */ + panningGains[0] = 0.0f; + panningGains[1] = 1.0f; + } + else /* Tangent panning law */ + { + A = tanf( aziRadMapped ) / tanf( LsAngleRad ); + A2 = ( A - 1.0f ) / max( 0.001f, A + 1.0f ); + A3 = 1.0f / ( A2 * A2 + 1.0f ); + panningGains[0] = sqrtf( A3 ); + panningGains[1] = sqrtf( 1.0f - A3 ); + } +} + +/*--------------------------------------------------------------- + * distribute_evenly_ism() + * + * Obtain ISM ratio indexes for even content distribution bbetween objects + *---------------------------------------------------------------*/ +void distribute_evenly_ism( + int16_t *idx, /* o: index values */ + int16_t K, /* i: sum of indexes */ + int16_t no_ism /* i: number of objects */ +) +{ + int16_t i; + int16_t sum; + sum = 0; + for ( i = 0; i < no_ism; i++ ) + { + idx[i] = (int16_t) ( K / no_ism ); + sum += idx[i]; + } + assert( sum <= K ); + i = 0; + while ( sum < K ) + { + if ( i == no_ism ) + { + i = 0; + } + idx[i]++; + sum++; + i++; + } +} + +/*--------------------------------------------------------------- + * calculate_cpe_brate_MASA_ISM() + * + * Calculates bitrate for MASA_ISM mode that is not used for separated objects, + * * but for the CPE part (metadata included) + *---------------------------------------------------------------*/ +int32_t /* o: cpe bitrate value */ +calculate_cpe_brate_MASA_ISM( + ISM_MODE ism_mode, /* i: ism mode */ + int32_t ivas_total_brate, /* i: total bit rate for IVAS */ + int16_t n_ism ) /* i: number of objects */ +{ + int32_t cpe_brate; + int16_t k, sce_id; + + k = 0; + + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + cpe_brate = ivas_total_brate - sep_object_brate[k - 2][0]; /* take data from the first column */ + } + else if ( ism_mode == ISM_MASA_MODE_DISC ) + { + cpe_brate = ivas_total_brate; + + for ( sce_id = 0; sce_id < n_ism; sce_id++ ) + { + cpe_brate -= sep_object_brate[k - 2][n_ism - 1]; + } + } + else + { + cpe_brate = ivas_total_brate; + } + return cpe_brate; +} +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7b2ad0a798..8bd1d65bfb 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -741,6 +741,9 @@ ivas_error ivas_ism_config( 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 */ +#ifdef MASA_AND_OBJECTS + , int16_t masa_ism_flag /* i : flag indicating ISM MASA format */ +#endif ); void ivas_ism_reset_metadata( @@ -801,6 +804,10 @@ ivas_error ivas_ism_metadata_enc( const int16_t localVAD[], /* i : VAD flag */ const int16_t ism_mode, /* i : ISM mode */ const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Config Handle */ +#ifdef MASA_AND_OBJECTS + , + int16_t n_ism /* i : number of ism-s */ +#endif ); ivas_error ivas_ism_metadata_dec( @@ -3267,6 +3274,10 @@ void ivas_dirac_dec_binaural( const int16_t nchan_transport /* i : number of transport channels */ ); +#ifdef MASA_AND_OBJECTS +void ivas_get_stereo_panning_gains( float aziDeg, float eleDeg, float panningGains[2] ); +#endif + ivas_error ivas_binaural_reverb_open( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ const int16_t numBins, /* i : number of CLDFB bins */ @@ -3455,6 +3466,9 @@ void ivas_dirac_dec_compute_directional_responses( DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ +#ifdef MASA_AND_OBJECTS + MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ +#endif const int16_t direction_idx, /* i : index for direction (azi and ele) */ const int16_t subframe_idx, /* i : subframe index */ const float *surCohRatio, @@ -4406,6 +4420,13 @@ void ivas_masa_encode( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t Opt_DTX_ON, /* i : DTX on flag */ const int16_t element_mode /* i : element mode */ +#ifdef MASA_AND_OBJECTS + , + ISM_MODE ism_mode, /* i : ISM format mode */ + int16_t nchan_ism, /* i : number of ism channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + int16_t idx_separated_object /* i : index of the separated object */ +#endif ); void ivas_masa_estimate_energy( @@ -4427,8 +4448,59 @@ void ivas_masa_set_elements( int16_t *element_mode, /* o : element mode */ int16_t *nSCE, /* o : number of SCEs */ int16_t *nCPE /* o : number of CPEs */ +#ifdef MASA_AND_OBJECTS + , + int16_t ivas_format, /* i : IVAS format */ + const ISM_MODE ism_mode, /* i : ISM mode */ + int32_t sce_brate /* i : bitrate of SCE */ +#endif +); + +#ifdef MASA_AND_OBJECTS +int16_t valid( + int16_t index, + int16_t K, + int16_t len +); + +void reconstruct_ism_ratios( + int16_t *ratio_ism_idx, + int16_t n_ism, + float step, + float *q_energy_ratio_ism ); +void distribute_evenly_ism( + int16_t *idx, + int16_t K, + int16_t no_ism +); + +int16_t ivas_qmetadata_DecodeExtendedGR( + uint16_t* bitstream, + int16_t* index, + const int16_t alph_size, + const int16_t gr_param +); + +int16_t ivas_qmetadata_encode_extended_gr_length( + const uint16_t value, + const uint16_t alphabet_size, + const int16_t gr_param); + +void ivas_qmetadata_encode_extended_gr( + BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */ + const uint16_t value, /* i : value to be encoded */ + const uint16_t alphabet_size, /* i : alphabet size */ + const int16_t gr_param); /* i : GR order */ + +int32_t /* o: cpe bitrate value */ +calculate_cpe_brate_MASA_ISM( + ISM_MODE ism_mode, /* i: ism mode */ + int32_t ivas_total_brate, /* i: total bit rate for IVAS */ + int16_t n_ism ); /* i: number of objects */ +#endif + void ivas_masa_set_coding_config( MASA_CODEC_CONFIG* config, /* i/o: MASA coding config structure */ int16_t* band_mapping, /* o : Band mapping used */ @@ -4961,6 +5033,100 @@ void ivas_filter_process( const int16_t length /* i : filter order */ ); +#ifdef MASA_AND_OBJECTS +/* ----------------------------------------------------------------------------------* +* OMASA prototypes +* ----------------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_enc_open( + Encoder_Struct* st_ivas /* i/o: IVAS encoder handle */ +); + +void ivas_omasa_enc_close( + OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ + const int16_t nchan_ism /* i : number of objects */ +); + +void ivas_omasa_set_config( + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ + const int32_t input_Fs /* i : Input sample rate */ +); + +void ivas_omasa_enc( + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + float data_in_f[][L_FRAME48k], /* i : Input audio signals for parameter analysis */ + float data_out_f[][L_FRAME48k], /* o : Transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t nchan_transport, /* i : Number of transport channels */ + const int16_t nchan_inp, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ + int16_t* idx_separated_object /* o : Index of the separated object */ +); + +ISM_MODE ivas_omasa_ism_mode_select( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t no_obj /* i : number of input ISM's */ +); + +void ivas_merge_masa_transports( + float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ + float data_in_f2[][L_FRAME48k], /* i : Transport audio signals 2 */ + float data_out_f[][L_FRAME48k], /* o : Merged transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t num_transport_channels /* i : Number of transport audio signals */ +); + +void ivas_masa_ism_data_open( + Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ +); + + +void preProcessStereoTransportsForMovedObjects( + Decoder_Struct* st_ivas, + float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + uint8_t nBins, + uint8_t firstSubframe, + uint8_t nSubframes +); + +ivas_error ivas_masa_ism_separate_object_renderer_open( + Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ +); + +void ivas_masa_ism_separate_object_render( + Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ + float input_f[][L_FRAME48k], /* i : separated object signal */ + float output_f[][L_FRAME48k], /* i/o: output signals */ + const int16_t output_frame /* i : output frame length per channel */ +); + +void ivas_masa_ism_set_edited_objects( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +void encode_masa_to_total( + IVAS_QMETADATA_HANDLE hQMetaData, + BSTR_ENC_HANDLE hMetaData +); + +void decode_masa_to_total( + uint16_t* bit_stream, + int16_t* index, + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + int16_t nbands +); + +void modify_masa_energy_ratios( + IVAS_QMETADATA_HANDLE hQMetaData +); + +#endif /*----------------------------------------------------------------------------------* * TD Binaural Object renderer diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index c824c94a40..7c28e6b4f6 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2779,6 +2779,48 @@ const float McMASA_LFEGain_vectors[64] = -2.14f, 0.26f, 0.84f, 1.02f }; +#ifdef MASA_AND_OBJECTS + +int32_t sep_object_brate[][MAX_NUM_OBJECTS] ={ + {0, 0, 0, 0}, /* 13k2 */ + {0, 0, 0, 0}, /* 16k4 */ + {0, 0, 0, 0}, /* 24k4 */ + {0, 0, 0, 0}, /* 32k */ + {0, 0, 0, 0}, /* 48k */ + {16000, 0, 0, 0}, /* 64k */ + {20000, 16000, 0, 0}, /* 80k */ + {IVAS_32k, 20000, 0, 0}, /* 96k */ + {IVAS_32k, IVAS_24k4, 0, 0}, /* 128k */ + {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ + {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ + {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ + {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ + {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */ +}; +/* column wise DCT matrices for 4 5, and 8 dim */ + float dct4[] = { + 0.5000f, 0.6533f, 0.5000f, 0.2706f, + 0.5000f, 0.2706f, -0.5000f, -0.6533f, + 0.5000f, -0.2706f, -0.5000f, 0.6533f, + 0.5000f, -0.6533f, 0.5000f, -0.2706f + }; + + float dct5[] = { + 0.4472f, 0.6015f, 0.5117f, 0.3717f, 0.1954f, + 0.4472f, 0.3717f, -0.1954f, -0.6015f, -0.5117f, + 0.4472f, 0.0000f, -0.6325f, -0.0000f, 0.6325f, + 0.4472f, -0.3717f, -0.1954f, 0.6015f, -0.5117f, + 0.4472f, -0.6015f, 0.5117f, -0.3717f, 0.1954f + }; + float dct8[] = { + 0.3536f, 0.4904f, 0.4619f, 0.4157f, 0.3536f, 0.2778f, 0.1913f, 0.0975f, 0.3536f, 0.4157f, + 0.1913f, -0.0975f, -0.3536f, -0.4904f, -0.4619f, -0.2778f, 0.3536f, 0.2778f, -0.1913f, -0.4904f, + -0.3536f, 0.0975f, 0.4619f, 0.4157f, 0.3536f, 0.0975f, -0.4619f, -0.2778f, 0.3536f, 0.4157f, + -0.1913f, -0.4904f, 0.3536f, -0.0975f, -0.4619f, 0.2778f, 0.3536f, -0.4157f, -0.1913f, 0.4904f, + 0.3536f, -0.2778f, -0.1913f, 0.4904f, -0.3536f, -0.0975f, 0.4619f, -0.4157f, 0.3536f, -0.4157f, + 0.1913f, 0.0975f, -0.3536f, 0.4904f, -0.4619f, 0.2778f, 0.3536f, -0.4904f, 0.4619f, -0.4157f, + 0.3536f, -0.2778f, 0.1913f, -0.0975f }; +#endif /*----------------------------------------------------------------------------------* * ISM ROM tables diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 2b3755087c..acf2a80924 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -312,6 +312,14 @@ extern const float cb_azi_chan[]; extern const float McMASA_LFEGain_vectors[64]; +#ifdef MASA_AND_OBJECTS +/* MASA and ISM combined format */ +extern int32_t sep_object_brate[][MAX_NUM_OBJECTS]; +extern float dct4[]; +extern float dct5[]; +extern float dct8[]; +#endif + /*----------------------------------------------------------------------------------* * ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 2ec890b57d..ff2606ee62 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -526,7 +526,9 @@ typedef struct ivas_masa_qmetadata_frame_struct int16_t ec_flag; float dir_comp_ratio; uint8_t is_masa_ivas_format; - +#ifdef MASA_AND_OBJECTS + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: This should be moved to some other place and reserved only when needed. */ +#endif } IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index 8a35f4f6f4..528e348ff4 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -61,11 +61,11 @@ /*#define MEM_COUNT_DETAILS*/ /* RAM counting tool: print per sub-structure details */ -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO */ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ -/*#define DEBUG_MODE_DFT*/ /* output most important DFT stereo parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_DFT */ /* output most important DFT stereo parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ /*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ @@ -174,6 +174,12 @@ #define FIX_GET_DELAY_RETURN /* Issue 223: change return data type in function get_delay() */ +#define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ +#ifdef MASA_AND_OBJECTS +#define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ +#endif + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 12b8fcb899..34d3584f7a 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -77,7 +77,9 @@ ivas_error ivas_cpe_dec( Decoder_State **sts; int32_t ivas_total_brate; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t cpe_brate; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ivas_cpe_dec" ); @@ -218,15 +220,33 @@ ivas_error ivas_cpe_dec( /* read DFT Stereo side info */ nb_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); - sts[1]->bit_stream = sts[0]->bit_stream + ivas_total_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; - +#ifdef MASA_AND_OBJECTS + cpe_brate = ivas_total_brate; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + sts[1]->bit_stream = sts[0]->bit_stream + cpe_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; + } + else + { +#endif + sts[1]->bit_stream = sts[0]->bit_stream + ivas_total_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; +#ifdef MASA_AND_OBJECTS + } +#endif if ( ivas_total_brate == IVAS_SID_5k2 ) { nb_bits -= SID_FORMAT_NBITS; sts[1]->bit_stream -= SID_FORMAT_NBITS; } +#ifdef MASA_AND_OBJECTS + if ( ( ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) || + ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) ) ) && + ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) +#endif { sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */ } @@ -543,7 +563,9 @@ ivas_error create_cpe_dec( Decoder_State *st; int32_t output_Fs; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t cpe_brate; +#endif error = IVAS_ERR_OK; /*-----------------------------------------------------------------* @@ -581,7 +603,11 @@ ivas_error create_cpe_dec( hCPE->lt_es_em = 0.0f; /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) +#else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) +#endif { hCPE->nchan_out = CPE_CHANNELS; } @@ -589,8 +615,21 @@ ivas_error create_cpe_dec( { hCPE->nchan_out = min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out ); } - +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + cpe_brate = element_brate; + } + else + { + cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate; + } + if ( ( ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) || + ( st_ivas->ivas_format == MASA_ISM_FORMAT && cpe_brate < MASA_STEREO_MIN_BITRATE ) ) && + st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) +#endif { hCPE->nchan_out = 1; } @@ -607,7 +646,11 @@ ivas_error create_cpe_dec( for ( i = 0; i < CPE_CHANNELS; i++ ) { +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == STEREO_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || +#else if ( st_ivas->ivas_format == STEREO_FORMAT || st_ivas->ivas_format == MASA_FORMAT || +#endif ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || st_ivas->sba_dirac_stereo_flag ) { if ( ( hCPE->input_mem[i] = (float *) count_malloc( sizeof( float ) * NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 5d3a5a10f9..9ceaa52f68 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -60,11 +60,17 @@ ivas_error ivas_dec( float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; /* 'float' buffer for output synthesis, MAX_OUTPUT_CHANNELS channels */ /* IVAS_fmToDo: buffer can be allocated dynamically based on the actual number of output channels */ int16_t nchan_remapped; float output_lfe_ch[L_FRAME48k]; +#ifdef MASA_AND_OBJECTS + int16_t nb_bits_metadata[MAX_SCE + 1]; +#else int16_t nb_bits_metadata[MAX_SCE]; +#endif int32_t output_Fs, ivas_total_brate; AUDIO_CONFIG output_config; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t ism_brate; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ivas_dec" ); @@ -541,7 +547,134 @@ ivas_error ivas_dec( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + ism_brate = 0; + st = st_ivas->hCPE[0]->hCoreCoder[0]; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + st->bit_stream = &( st_ivas->bit_stream[( st_ivas->hSCE[0]->element_brate / FRAMES_PER_SEC )] ); + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + ism_brate += st_ivas->hSCE[n]->element_brate; + } + st->bit_stream = &( st_ivas->bit_stream[( ism_brate / FRAMES_PER_SEC )] ); + } + + nb_bits_metadata[0] = 0; + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /* Set the number of objects for the parametric rendering */ + if ( st_ivas->hDirAC != NULL ) + { + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; + } + else + { + st_ivas->hDirAC->numIsmDirections = 0; + } + } + + /* MASA decoding */ + if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Audio signal decoding */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + if ( st_ivas->nSCE == 1 ) + { + ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ); + } + else + { +#ifdef DEBUGGING + assert( ( st_ivas->nSCE <= 1 ) && "nSCE should be 1 if not in ISM_MASA_MODE_DISC." ); +#endif + } + } + else + { + /* decode ISM format */ + ivas_ism_metadata_dec( ism_brate, &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL ); + + for ( n = 0; n < st_ivas->nSCE - 1; n++ ) + { + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + } + } + if ( st_ivas->nCPE == 1 ) + { + ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ); + } + + /* HP filtering */ + for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + } + + /* Set edited object positions, if editing enabled */ + ivas_masa_ism_set_edited_objects( st_ivas ); + + /* Rendering */ + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); + } + else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); + } + else if ( st_ivas->hDirAC ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + mvr2r( output[2], data_separated_objects[0], output_frame ); + } + else + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + } + } + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); + } + else + { + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + } + } + } +#endif /*----------------------------------------------------------------* * Write IVAS output channels diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 5f9e908481..b689109ae7 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -300,12 +300,20 @@ ivas_error ivas_dirac_dec_config( hDirAC->panningConf = DIRAC_PANNING_HOA3; nchan_out_woLFE = 1; } +#ifdef MASA_AND_OBJECTS + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.is_loudspeaker_setup ) +#else else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.is_loudspeaker_setup ) +#endif { hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; hDirAC->panningConf = DIRAC_PANNING_VBAP; } +#ifdef MASA_AND_OBJECTS + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && !hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) +#else else if ( st_ivas->ivas_format == MASA_FORMAT && !hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) +#endif { hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; hDirAC->panningConf = DIRAC_PANNING_HOA3; @@ -342,6 +350,10 @@ ivas_error ivas_dirac_dec_config( hDirAC->masa_stereo_type_detect = NULL; } +#ifdef MASA_AND_OBJECTS + hDirAC->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ +#endif + /*-----------------------------------------------------------------* * (re)configure sub-modules *-----------------------------------------------------------------*/ @@ -789,12 +801,18 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { + hDirAC->dirac_md_buffer_length = 0; hDirAC->dirac_bs_md_write_idx = 0; hDirAC->dirac_read_idx = 0; hDirAC->spar_to_dirac_write_idx = 0; + +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) +#else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) +#endif { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; } @@ -836,6 +854,7 @@ ivas_error ivas_dirac_dec_config( hDirAC->diffuseness_vector[i] = (float *) count_malloc( hDirAC->num_freq_bands * sizeof( float ) ); set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands ); + hDirAC->energy_ratio1[i] = (float *) count_malloc( hDirAC->num_freq_bands * sizeof( float ) ); set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); hDirAC->spreadCoherence[i] = (float *) count_malloc( hDirAC->num_freq_bands * sizeof( float ) ); @@ -843,8 +862,11 @@ ivas_error ivas_dirac_dec_config( hDirAC->surroundingCoherence[i] = (float *) count_malloc( hDirAC->num_freq_bands * sizeof( float ) ); set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); } - +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) +#else if ( st_ivas->ivas_format == MASA_FORMAT ) +#endif { hDirAC->azimuth2 = (int16_t **) count_malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); hDirAC->elevation2 = (int16_t **) count_malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ); @@ -1563,7 +1585,12 @@ void ivas_qmetadata_to_dirac( int16_t qBand_idx; q_direction = &( hQMetaData->q_direction[0] ); +#ifdef MASA_AND_OBJECTS + hDirAC->numParametricDirections = hQMetaData->no_directions; + hDirAC->numSimultaneousDirections = hDirAC->numParametricDirections + hDirAC->numIsmDirections; +#else hDirAC->numSimultaneousDirections = hQMetaData->no_directions; +#endif if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) { @@ -1873,6 +1900,10 @@ void ivas_dirac_dec( float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +#ifdef MASA_AND_OBJECTS + float Cldfb_RealBuffer_Temp[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ + float Cldfb_ImagBuffer_Temp[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ +#endif int16_t index, num_freq_bands; DIRAC_DEC_STACK_MEM DirAC_mem; @@ -2016,6 +2047,9 @@ void ivas_dirac_dec( ivas_dirac_dec_compute_directional_responses( hDirAC, st_ivas->hVBAPdata, st_ivas->hMasa, +#ifdef MASA_AND_OBJECTS + st_ivas->hMasaIsmData, +#endif subframe_idx, subframe_idx, surCohRatio, @@ -2027,6 +2061,9 @@ void ivas_dirac_dec( ivas_dirac_dec_compute_directional_responses( hDirAC, st_ivas->hVBAPdata, st_ivas->hMasa, +#ifdef MASA_AND_OBJECTS + st_ivas->hMasaIsmData, +#endif subframe_idx, subframe_idx, surCohRatio, @@ -2035,6 +2072,36 @@ void ivas_dirac_dec( } } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) + { + for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots; slot_idx++ ) + { + index_slot = subframe_idx * hDirAC->subframe_nbslots + slot_idx; + + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + cldfbAnalysis_ts( &( output_f[sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), + Cldfb_RealBuffer_Temp[ch][index_slot], + Cldfb_ImagBuffer_Temp[ch][index_slot], + hDirAC->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); + } + } + + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + preProcessStereoTransportsForMovedObjects( st_ivas, + Cldfb_RealBuffer_Temp, + Cldfb_ImagBuffer_Temp, + hDirAC->num_freq_bands, + subframe_idx, + 1 ); + } + } +#endif + for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots; slot_idx++ ) { index_slot = subframe_idx * hDirAC->subframe_nbslots + slot_idx; @@ -2047,6 +2114,16 @@ void ivas_dirac_dec( mvr2r( pppQMfFrame_ts_im[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) + { + for ( ch = 0; ch < nchan_transport; ch++ ) + { + mvr2r( Cldfb_RealBuffer_Temp[ch][index_slot], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands ); + mvr2r( Cldfb_ImagBuffer_Temp[ch][index_slot], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); + } + } +#endif else { /* CLDFB Analysis*/ @@ -2649,19 +2726,35 @@ static void initDiffuseResponses( set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) +#else else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) +#endif { mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_2 ) && ( num_channels == 7 ) ) +#else else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) +#endif { mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) +#else else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) +#endif { mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) +#else else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) +#endif { if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) { diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index ee02a1bfe1..fc60732864 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -52,6 +52,9 @@ #define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#ifdef MASA_AND_OBJECTS +#define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) +#endif /*------------------------------------------------------------------------- * Local function prototypes @@ -121,7 +124,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { +#ifdef MASA_AND_OBJECTS + for ( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) +#else for ( k = 0; k < BINAURAL_CHANNELS + 1; k++ ) +#endif { set_zero( hBinaural->processMtxRe[j][k], nBins ); set_zero( hBinaural->processMtxIm[j][k], nBins ); @@ -366,8 +373,13 @@ static void ivas_dirac_dec_binaural_internal( { DIRAC_DEC_HANDLE hDirAC; uint8_t slot, ch, nBins, numInChannels; +#ifdef MASA_AND_OBJECTS + float Cldfb_RealBuffer_in[6][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_in[6][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#else float Cldfb_RealBuffer_in[4][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_in[4][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#endif float Rmat[3][3]; uint8_t firstSlot, slotEnd; int16_t max_band_decorr; @@ -381,10 +393,24 @@ static void ivas_dirac_dec_binaural_internal( /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) + { + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + numInChannels += (uint8_t) st_ivas->nchan_ism; + } + else + { + numInChannels++; + } + } +#else if ( st_ivas->hOutSetup.separateChannelEnabled ) { numInChannels++; } +#endif Rmat[0][0] = 1.0f; Rmat[0][1] = 0.0f; @@ -502,6 +528,18 @@ static void ivas_dirac_dec_binaural_internal( ivas_sba_prototype_renderer( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, firstSubframe, nSubframes ); } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + preProcessStereoTransportsForMovedObjects( st_ivas, + Cldfb_RealBuffer_in, + Cldfb_ImagBuffer_in, + nBins, + firstSubframe, + nSubframes ); + } +#endif + if ( st_ivas->hHeadTrackData && st_ivas->hHeadTrackData->num_quaternions >= 0 ) { QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[firstSubframe], Rmat ); @@ -717,7 +755,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Determine target covariance matrix containing target binaural properties */ for ( bin = 0; bin < nBins; bin++ ) { - float diffuseness = 1.0f; /* ratio1 and ratio2 are subtracted from diffuseness further below */ + float diffuseness = 1.0f; /* ratio1 and ratio2 are subtracted from diffuseness further below */ +#ifdef MASA_AND_OBJECTS + float diffusenessValForDecorrelationReduction = 1.0f; + float diffEneValForDecorrelationReduction; +#endif float surCoh = 0.0f, spreadCoh = 0.0f; /* Default values if spreadSurroundCoherenceApplied == false */ float diffEne, dirEne, meanEnePerCh; uint16_t dirIndex; @@ -736,7 +778,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric float lRealp, lImagp, rRealp, rImagp; float lRealpTmp, lImagpTmp, rRealpTmp, rImagpTmp; float hrtfEne[BINAURAL_CHANNELS], hrtfCrossRe, hrtfCrossIm, ratio; - +#ifdef MASA_AND_OBJECTS + uint8_t isIsmDirection = 0; +#endif if ( dirIndex == 0 ) /* For first of the two simultaneous directions */ { aziDeg = hDirAC->azimuth[dirac_read_idx][bin]; @@ -744,15 +788,55 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric ratio = hDirAC->energy_ratio1[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence[dirac_read_idx][bin]; } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format != MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_ISM_FORMAT && dirIndex < hDirAC->numParametricDirections ) ) /* For second of the two simultaneous directions */ +#else else /* For second of the two simultaneous directions */ +#endif { aziDeg = hDirAC->azimuth2[dirac_read_idx][bin]; eleDeg = hDirAC->elevation2[dirac_read_idx][bin]; ratio = hDirAC->energy_ratio2[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence2[dirac_read_idx][bin]; } +#ifdef MASA_AND_OBJECTS + else /* For object directions of MASA_ISM_FORMAT */ + { + isIsmDirection = 1; + uint16_t ismDirIndex; + ismDirIndex = dirIndex - hDirAC->numParametricDirections; + if ( st_ivas->hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + aziDeg = st_ivas->hMasaIsmData->azimuth_ism_edited[ismDirIndex]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism_edited[ismDirIndex]; + } + else + { + aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex]; + } + ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; + spreadCoh = 0.0f; + } +#endif diffuseness -= ratio; /* diffuseness = 1 - ratio1 - ratio2 */ +#ifdef MASA_AND_OBJECTS + if ( diffuseness < 0.0f ) + { + diffuseness = 0.0f; + } + if ( isIsmDirection ) + { + /* Objects cause lesser decorrelation reduction, to avoid removing all decorrelation when only objects are present */ + diffusenessValForDecorrelationReduction -= ratio * 0.5f; + } + else + { + diffusenessValForDecorrelationReduction -= ratio; + } +#endif + if ( separateCenterChannelRendering ) { /* In masa + mono rendering mode, the center directions originate from phantom sources, so the @@ -886,13 +970,31 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Add diffuse / ambient part covariance matrix */ diffuseness = max( 0.0f, diffuseness ); diffEne = diffuseness * meanEnePerCh; + surCoh = hDirAC->surroundingCoherence[dirac_read_idx][bin]; + +#ifdef MASA_AND_OBJECTS + diffusenessValForDecorrelationReduction = max( 0.0f, diffusenessValForDecorrelationReduction ); + diffEneValForDecorrelationReduction = diffusenessValForDecorrelationReduction * meanEnePerCh; +#endif + if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { if ( !h->renderStereoOutputInsteadOfBinaural ) { /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ +#ifdef MASA_AND_OBJECTS + float spectrumModVal; + /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ + spectrumModVal = ( 1.0f - surCoh ) + surCoh * surCohEne[min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 )]; + diffEne *= spectrumModVal; +#else diffEne *= ( 1.0f - surCoh ) + surCoh * surCohEne[min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 )]; +#endif +#ifdef MASA_AND_OBJECTS + /* Modify also the value for decorrelation reduction */ + diffEneValForDecorrelationReduction *= spectrumModVal; +#endif } } h->ChEneOut[0][bin] += diffEne; /* Diff ene part*/ @@ -918,7 +1020,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } /* Store parameters for formulating average diffuseness over frame */ +#ifdef MASA_AND_OBJECTS + h->frameMeanDiffuseness[bin] += diffEneValForDecorrelationReduction; +#else h->frameMeanDiffuseness[bin] += diffEne; +#endif frameMeanDiffusenessEneWeight[bin] += meanEnePerCh; } @@ -1004,10 +1110,27 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { uint8_t chA, chB, bin; uint8_t separateCenterChannelRendering; +#ifdef MASA_AND_OBJECTS + uint8_t nchanSeparateChannels; +#endif int16_t nBins; DIRAC_DEC_BIN_HANDLE h; h = st_ivas->hDiracDecBin; +#ifdef MASA_AND_OBJECTS + separateCenterChannelRendering = 0; + nchanSeparateChannels = 0; + if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) + { + separateCenterChannelRendering = 1; + nchanSeparateChannels = 1; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; + } + } +#else separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; +#endif nBins = st_ivas->hDirAC->num_freq_bands; /* Actually bins */ for ( bin = 0; bin < nBins; bin++ ) @@ -1144,6 +1267,50 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( float gainFactor; int16_t aziDeg = 0; int16_t eleDeg = 0; +#ifdef MASA_AND_OBJECTS + uint8_t instantChange = 0; + + gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); + for ( chB = 0; chB < nchanSeparateChannels; chB++ ) + { + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB]; + } + else + { + aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism; + eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; + instantChange = 1; + } + } + + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + h->processMtxRePrev[chA][chB + 2][bin] = h->processMtxRe[chA][chB + 2][bin]; + h->processMtxImPrev[chA][chB + 2][bin] = h->processMtxIm[chA][chB + 2][bin]; + } + + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat ); + + h->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; + h->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; + h->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; + h->processMtxIm[1][chB + 2][bin] = rImagp * gainFactor; + + if ( instantChange ) + { + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + h->processMtxRePrev[chA][chB + 2][bin] = h->processMtxRe[chA][chB + 2][bin]; + h->processMtxImPrev[chA][chB + 2][bin] = h->processMtxIm[chA][chB + 2][bin]; + } + } + } +#else gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) @@ -1158,6 +1325,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( h->processMtxIm[0][2][bin] = lImagp * gainFactor; h->processMtxRe[1][2][bin] = rRealp * gainFactor; h->processMtxIm[1][2][bin] = rImagp * gainFactor; +#endif } } @@ -1814,3 +1982,219 @@ static void hrtfShGetHrtf( return; } + +#ifdef MASA_AND_OBJECTS +void preProcessStereoTransportsForMovedObjects( + Decoder_Struct *st_ivas, + float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], + uint8_t nBins, + uint8_t firstSubframe, + uint8_t nSubframes ) +{ + int16_t subframe, bin, ch, inCh, outCh, ismDirIndex, slot; + DIRAC_DEC_HANDLE hDirAC; + MASA_ISM_DATA_HANDLE hMasaIsmData; + uint8_t enableCentering; + + hDirAC = st_ivas->hDirAC; + hMasaIsmData = st_ivas->hMasaIsmData; + + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_HOA2 || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_HOA3 ) + { + enableCentering = 0; + } + else + { + enableCentering = 1; + } + + /* Bypass processing until first object is moved */ + if ( hMasaIsmData->objectsMoved == 0 ) + { + for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) + { + if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + hMasaIsmData->objectsMoved = 1; + } + } + if ( hMasaIsmData->objectsMoved == 0 ) + { + /* No objects have moved so far */ + return; + } + } + + /* Perform object-movement based processing */ + for ( subframe = firstSubframe; subframe < ( firstSubframe + nSubframes ); subframe++ ) + { + for ( bin = 0; bin < nBins; bin++ ) + { + float ismPreprocMtxNew[2][2]; + float ismPreprocMtxIncrement[2][2]; + float eneMove[2]; + float enePreserve[2]; + float ismRatioAcc; + float subframeEne; + float normEnes[2]; + float remainderNormEne; + + set_zero( ismPreprocMtxNew[0], 2 ); + set_zero( ismPreprocMtxNew[1], 2 ); + set_zero( ismPreprocMtxIncrement[0], 2 ); + set_zero( ismPreprocMtxIncrement[1], 2 ); + set_zero( eneMove, 2 ); + set_zero( enePreserve, 2 ); + ismRatioAcc = 0.0f; + subframeEne = 0.0f; + set_zero( normEnes, 2 ); + + /* Determine transport normalized energies and subframe energy */ + for ( slot = subframe * hDirAC->subframe_nbslots; slot < (int16_t) ( ( subframe + 1 ) * hDirAC->subframe_nbslots ); slot++ ) + { + for ( ch = 0; ch < 2; ch++ ) + { + normEnes[ch] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; + normEnes[ch] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; + } + } + subframeEne = normEnes[0] + normEnes[1]; + normEnes[0] /= fmaxf( 1e-12f, subframeEne ); + normEnes[1] /= fmaxf( 1e-12f, subframeEne ); + + /* For each ismDir, formulate a mix-matrix that moves object audio signals between + * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ + for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) + { + float panGainsOut[2]; + float panGainsIn[2]; + float ratio; + float panEnesOut[2]; + float panEnesIn[2]; + float centeringFactor; + + ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; + ismRatioAcc += ratio; + + /* Get input and output panning gains */ + ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex], + hMasaIsmData->elevation_ism[ismDirIndex], + panGainsIn ); + if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism_edited[ismDirIndex], + hMasaIsmData->elevation_ism_edited[ismDirIndex], + panGainsOut ); + } + else + { + /* When not edited, input and output pan gains are the same */ + for ( ch = 0; ch < 2; ch++ ) + { + panGainsOut[ch] = panGainsIn[ch]; + } + } + + /* Determine pan enes */ + for ( ch = 0; ch < 2; ch++ ) + { + panEnesOut[ch] = panGainsOut[ch] * panGainsOut[ch]; + panEnesIn[ch] = panGainsIn[ch] * panGainsIn[ch]; + } + + if ( enableCentering ) + { + centeringFactor = fmaxf( 0.0f, 2.0f * fabsf( panEnesIn[0] - panEnesOut[0] ) - 1.0f ); + for ( ch = 0; ch < 2; ch++ ) + { + panEnesOut[ch] *= ( 1.0f - centeringFactor ); + panEnesOut[ch] += 0.5f * centeringFactor; + } + } + + for ( ch = 0; ch < 2; ch++ ) + { + float eneMoveThis; + float enePreserveThis; + eneMoveThis = fmaxf( 0.0f, panEnesIn[ch] - panEnesOut[ch] ); + enePreserveThis = panEnesIn[ch] - eneMoveThis; + + eneMove[ch] += ratio * eneMoveThis; + enePreserve[ch] += ratio * enePreserveThis; + + /* Subtract object parts from normEnes */ + normEnes[ch] -= panEnesIn[ch] * ratio; + } + } + /* Any remaining (non-object) energy is set to be preserved at both channels */ + remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); + for ( ch = 0; ch < 2; ch++ ) + { + enePreserve[ch] += fmaxf( 0.0f, normEnes[ch] + remainderNormEne / 2.0f ); + } + + /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix */ + for ( ch = 0; ch < 2; ch++ ) + { + float normVal; + hMasaIsmData->eneMoveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->eneMoveIIR[ch][bin] += eneMove[ch] * subframeEne; + hMasaIsmData->enePreserveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->enePreserveIIR[ch][bin] += enePreserve[ch] * subframeEne; + normVal = fmaxf( EPSILON, hMasaIsmData->eneMoveIIR[ch][bin] + hMasaIsmData->enePreserveIIR[ch][bin] ); + ismPreprocMtxNew[ch][ch] = sqrtf( hMasaIsmData->enePreserveIIR[ch][bin] / normVal ); + ismPreprocMtxNew[1 - ch][ch] = sqrtf( hMasaIsmData->eneMoveIIR[ch][bin] / normVal ); + } + + + /* Get increment value for temporal interpolation */ + for ( inCh = 0; inCh < 2; inCh++ ) + { + for ( outCh = 0; outCh < 2; outCh++ ) + { + ismPreprocMtxIncrement[outCh][inCh] = ( ismPreprocMtxNew[outCh][inCh] - hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] ) / (float) hDirAC->subframe_nbslots; + } + } + + /* Mix signals */ + for ( slot = subframe * hDirAC->subframe_nbslots; slot < (int16_t) ( ( subframe + 1 ) * hDirAC->subframe_nbslots ); slot++ ) + { + float eqVal; + float outSlotRe[2]; + float outSlotIm[2]; + + set_zero( outSlotRe, 2 ); + set_zero( outSlotIm, 2 ); + + for ( outCh = 0; outCh < 2; outCh++ ) + { + for ( inCh = 0; inCh < 2; inCh++ ) + { + hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] += ismPreprocMtxIncrement[outCh][inCh]; + outSlotRe[outCh] += inRe[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; + outSlotIm[outCh] += inIm[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; + } + } + + /* IIR average the energy measures and determine and apply energy-preserving equalizer */ + hMasaIsmData->preprocEneTarget[bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->preprocEneRealized[bin] *= STEREO_PREPROCESS_IIR_FACTOR; + for ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->preprocEneTarget[bin] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; + hMasaIsmData->preprocEneTarget[bin] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; + hMasaIsmData->preprocEneRealized[bin] += outSlotRe[ch] * outSlotRe[ch]; + hMasaIsmData->preprocEneRealized[bin] += outSlotIm[ch] * outSlotIm[ch]; + } + eqVal = fminf( 4.0f, sqrtf( hMasaIsmData->preprocEneTarget[bin] / fmaxf( 1e-12f, hMasaIsmData->preprocEneRealized[bin] ) ) ); + for ( ch = 0; ch < 2; ch++ ) + { + inRe[ch][slot][bin] = outSlotRe[ch] * eqVal; + inIm[ch][slot][bin] = outSlotIm[ch] * eqVal; + } + } + } + } +} +#endif diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 79c04f824b..91d6435c78 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -499,6 +499,9 @@ void ivas_dirac_dec_output_synthesis_process_slot( ivas_dirac_dec_compute_directional_responses( hDirAC, hVBAPdata, NULL, +#ifdef MASA_AND_OBJECTS + NULL, +#endif index_slot, index_slot / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, 2, @@ -1427,8 +1430,11 @@ void ivas_dirac_dec_compute_directional_responses( DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ - const int16_t direction_idx, /* i : index for direction (azi and ele), can slot index (>2TCs) or subrame index (<=2TCs) */ - const int16_t subframe_idx, /* i : subframe index */ +#ifdef MASA_AND_OBJECTS + MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ +#endif + const int16_t direction_idx, /* i : index for direction (azi and ele), can slot index (>2TCs) or subrame index (<=2TCs) */ + const int16_t subframe_idx, /* i : subframe index */ const float *surCohRatio, const int16_t shd_rot_max_order, /* i : split-order rotation method */ const float *p_Rmat /* i : rotation matrix */ @@ -1463,7 +1469,11 @@ void ivas_dirac_dec_compute_directional_responses( num_channels_dir = hDirAC->num_outputs_dir; azimuth = hDirAC->azimuth[hDirAC->dirac_read_idx]; elevation = hDirAC->elevation[hDirAC->dirac_read_idx]; +#ifdef MASA_AND_OBJECTS + if ( hDirAC->numParametricDirections == 2 ) +#else if ( hDirAC->numSimultaneousDirections == 2 ) +#endif { azimuth2 = hDirAC->azimuth2[direction_idx]; elevation2 = hDirAC->elevation2[direction_idx]; @@ -1521,7 +1531,11 @@ void ivas_dirac_dec_compute_directional_responses( spreadCoherencePanningHoa( azimuth[k], elevation[k], hDirAC->spreadCoherence[subframe_idx][k], direct_response_hoa, num_channels_dir, hDirAC->hOutSetup.ambisonics_order ); /* Synthesize the second direction and combine the gains */ +#ifdef MASA_AND_OBJECTS + if ( hDirAC->numParametricDirections == 2 ) +#else if ( hDirAC->numSimultaneousDirections == 2 ) +#endif { spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[subframe_idx][k], direct_response_dir2, num_channels_dir, hDirAC->hOutSetup.ambisonics_order ); @@ -1536,6 +1550,56 @@ void ivas_dirac_dec_compute_directional_responses( } } +#ifdef MASA_AND_OBJECTS + if ( hDirAC->numIsmDirections > 0 ) + { + int16_t dir; + float direct_response_temp[MAX_OUTPUT_CHANNELS]; + float direct_response_ism[MAX_OUTPUT_CHANNELS]; + float masaDirect; + float ismDirect; + + set_zero( direct_response_ism, num_channels_dir ); + + for ( dir = 0; dir < hDirAC->numIsmDirections; dir++ ) + { + if ( hMasaIsm->ism_is_edited[dir] ) + { + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); + } + else + { + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); + } + + for ( l = 0; l < num_channels_dir; l++ ) + { + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; + } + } + + masaDirect = hDirAC->energy_ratio1[subframe_idx][k] + EPSILON; + if ( hDirAC->numParametricDirections == 2 ) + { + masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; + } + ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; + for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) + { + ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; + } + + totalDirect = masaDirect + ismDirect; + directRatio[0] = masaDirect / totalDirect; + directRatio[1] = ismDirect / totalDirect; + for ( l = 0; l < num_channels_dir; l++ ) + { + direct_response_hoa[l] *= directRatio[0]; + direct_response_hoa[l] += directRatio[1] * direct_response_ism[l]; + } + } +#endif + /* Synthesize surrounding coherence */ if ( surCohRatio != NULL && surCohRatio[k] > 0.f ) { @@ -1580,7 +1644,12 @@ void ivas_dirac_dec_compute_directional_responses( normalizePanningGains( direct_response_ls, num_channels_dir ); /* Synthesize the second direction and combine the gains */ +#ifdef MASA_AND_OBJECTS + if ( hDirAC->numParametricDirections == 2 ) +#else if ( hDirAC->numSimultaneousDirections == 2 ) +#endif + { spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[subframe_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata ); @@ -1597,7 +1666,57 @@ void ivas_dirac_dec_compute_directional_responses( } normalizePanningGains( direct_response_ls, num_channels_dir ); } +#ifdef MASA_AND_OBJECTS + if ( hDirAC->numIsmDirections > 0 ) + { + int16_t dir; + float direct_response_temp[MAX_OUTPUT_CHANNELS]; + float direct_response_ism[MAX_OUTPUT_CHANNELS]; + float masaDirect; + float ismDirect; + set_zero( direct_response_ism, num_channels_dir ); + + for ( dir = 0; dir < hDirAC->numIsmDirections; dir++ ) + { + if ( hMasaIsm->ism_is_edited[dir] ) + { + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir] ); + } + else + { + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir] ); + } + + for ( l = 0; l < num_channels_dir; l++ ) + { + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; + } + } + normalizePanningGains( direct_response_ism, num_channels_dir ); + + masaDirect = hDirAC->energy_ratio1[subframe_idx][k] + EPSILON; + if ( hDirAC->numParametricDirections == 2 ) + { + masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; + } + ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; + for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) + { + ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; + } + + totalDirect = masaDirect + ismDirect; + directRatio[0] = masaDirect / totalDirect; + directRatio[1] = ismDirect / totalDirect; + for ( l = 0; l < num_channels_dir; l++ ) + { + direct_response_ls[l] *= directRatio[0]; + direct_response_ls[l] += directRatio[1] * direct_response_ism[l]; + } + normalizePanningGains( direct_response_ls, num_channels_dir ); + } +#endif /* Synthesize surrounding coherence */ if ( surCohRatio != NULL && surCohRatio[k] > 0.f ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e51b46779c..7da5528fb0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -69,6 +69,9 @@ ivas_error ivas_dec_setup( Decoder_State *st; int32_t ivas_total_brate; ivas_error error; +#ifdef MASA_AND_OBJECTS + int32_t cpe_brate; +#endif error = IVAS_ERR_OK; num_bits_read = 0; @@ -183,6 +186,33 @@ ivas_error ivas_dec_setup( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + st_ivas->nchan_transport = 2; + /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata*/ + st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 3] + 1; + + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + + if ( st_ivas->ini_frame > 0 ) + { + /* reconfigure in case a change of operation mode is detected */ + if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) + { + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 ) + { + st_ivas->hCPE[0]->nchan_out = 1; + } + else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { /* read MC configuration */ @@ -350,15 +380,24 @@ static ivas_error ivas_read_format( case 3: if ( st_ivas->bit_stream[*num_bits_read] ) { + ( *num_bits_read )++; st_ivas->ivas_format = MASA_FORMAT; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->bit_stream[*num_bits_read] ) + { + st_ivas->ivas_format = MASA_ISM_FORMAT; + } + ( *num_bits_read )++; +#endif } else { + ( *num_bits_read )++; st_ivas->ivas_format = SBA_FORMAT; st_ivas->sba_mode = ivas_sba_mode_select( ivas_total_brate ); } - ( *num_bits_read )++; + break; } } @@ -615,7 +654,9 @@ ivas_error ivas_init_decoder( AUDIO_CONFIG output_config; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t sce_brate; +#endif error = IVAS_ERR_OK; output_Fs = st_ivas->hDecoderConfig->output_Fs; @@ -931,6 +972,77 @@ ivas_error ivas_init_decoder( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); + + k = 0; + sce_brate = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + /* one separated object */ + st_ivas->nSCE = 1; + + sce_brate = sep_object_brate[k - 2][0]; + create_sce_dec( st_ivas, 0, sce_brate ); + + reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + int32_t temp_brate[MAX_SCE]; + st_ivas->nSCE = st_ivas->nchan_ism; /* number of objects */ + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + + temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; + sce_brate += temp_brate[sce_id]; + + if ( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK ) + { + return error; + } + reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); + } + + + if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nSCE, temp_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ivas_masa_dec_open( st_ivas ); + ivas_masa_ism_data_open( st_ivas ); + + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) + { + ivas_dirac_dec_open( st_ivas ); + } + + st_ivas->nCPE = 1; + create_cpe_dec( st_ivas, 0, ( ( ivas_total_brate - sce_brate ) / st_ivas->nchan_transport ) * CPE_CHANNELS ); + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] ); + } + + if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { if ( st_ivas->mc_mode == MC_MODE_MCT ) @@ -1492,6 +1604,9 @@ void ivas_initialize_handles_dec( st_ivas->hCrend = NULL; st_ivas->hHrtf = NULL; st_ivas->hoa_dec_mtx = NULL; +#ifdef MASA_AND_OBJECTS + st_ivas->hMasaIsmData = NULL; +#endif st_ivas->hHeadTrackData = NULL; st_ivas->hHrtfTD = NULL; @@ -1670,7 +1785,23 @@ void ivas_destroy_dec( count_free( st_ivas->hMonoDmxRenderer ); st_ivas->hMonoDmxRenderer = NULL; } - +#ifdef MASA_AND_OBJECTS + /* MASA ISM structure */ + if ( st_ivas->hMasaIsmData != NULL ) + { + if ( st_ivas->hMasaIsmData->delayBuffer != NULL ) + { + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { + count_free( st_ivas->hMasaIsmData->delayBuffer[i] ); + } + count_free( st_ivas->hMasaIsmData->delayBuffer ); + st_ivas->hMasaIsmData->delayBuffer = NULL; + } + count_free( st_ivas->hMasaIsmData ); + st_ivas->hMasaIsmData = NULL; + } +#endif /* Head track data handle */ if ( st_ivas->hHeadTrackData != NULL ) { @@ -1736,6 +1867,43 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: +#ifdef MASA_AND_OBJECTS + if ( st_ivas->nchan_transport == 1 ) + { + *numCldfbAnalyses = st_ivas->nchan_transport + 1; + } + + if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hOutSetup.separateChannelEnabled ) + { + *numCldfbAnalyses = st_ivas->nchan_transport + 1; + } + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + *numCldfbAnalyses += st_ivas->nchan_ism; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + *numCldfbAnalyses = st_ivas->nchan_transport + 1; + } + } + + if ( st_ivas->hDiracDecBin->useTdDecorr ) + { + *numCldfbAnalyses += 2; + } + break; + case RENDERER_MONO_DOWNMIX: + if ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + /* CLDFB not used in rendering */ + *numCldfbAnalyses = 0; + *numCldfbSyntheses = 0; + } + break; +#else if ( st_ivas->nchan_transport == 1 ) { *numCldfbAnalyses = st_ivas->nchan_transport + 1; @@ -1759,6 +1927,7 @@ void ivas_init_dec_get_num_cldfb_instances( *numCldfbSyntheses = 0; } break; +#endif case RENDERER_DIRAC: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 6b9f8ec8ba..f2c67c7301 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -126,13 +126,25 @@ ivas_error ivas_ism_metadata_dec( *----------------------------------------------------------------*/ /* read number of objects */ - num_obj = 1; - while ( get_next_indice( st0, 1 ) == 1 && num_obj < MAX_NUM_OBJECTS ) +#ifdef MASA_AND_OBJECTS + if ( ism_mode != ISM_MASA_MODE_DISC ) { - ( num_obj )++; +#endif + num_obj = 1; + while ( get_next_indice( st0, 1 ) == 1 && num_obj < MAX_NUM_OBJECTS ) + { + ( num_obj )++; + } + ism_mode = ivas_ism_mode_select( num_obj, ism_total_brate ); +#ifdef MASA_AND_OBJECTS } + else + { + num_obj = *nchan_transport; + } + +#endif - ism_mode = ivas_ism_mode_select( num_obj, ism_total_brate ); if ( ism_mode == ISM_MODE_PARAM ) { @@ -202,7 +214,11 @@ ivas_error ivas_ism_metadata_dec( for ( ch = 0; ch < num_obj; ch++ ) { hIsmMetaData = hIsmMeta[ch]; +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { nb_bits_start = st0->next_bit_pos; } @@ -362,7 +378,11 @@ ivas_error ivas_ism_metadata_dec( } /* save number of metadata bits read */ +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { nb_bits_metadata[ch] = st0->next_bit_pos - nb_bits_start; } @@ -455,13 +475,29 @@ ivas_error ivas_ism_metadata_dec( if ( !bfi ) { - ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); +#ifdef MASA_AND_OBJECTS + int16_t masa_ism_flag = 0; + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) + { + masa_ism_flag = 1; + } +#endif + + ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata +#ifdef MASA_AND_OBJECTS + , + masa_ism_flag +#endif + ); for ( ch = 0; ch < *nchan_transport; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; - +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; if ( hIsmMeta[ch]->ism_metadata_flag == 0 && localVAD[ch] == 0 && ism_metadata_flag_global ) @@ -534,7 +570,12 @@ ivas_error create_ism_metadata_dec( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL +#ifdef MASA_AND_OBJECTS + , + 0 +#endif + ); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 8ebf27afb5..61d8f9ebf0 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1022,7 +1022,11 @@ static ivas_error ivas_ism_bitrate_switching( error = IVAS_ERR_OK; +#ifdef MASA_AND_OBJECTS + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ); +#else ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); +#endif st_ivas->nSCE = st_ivas->nchan_transport; ivas_corecoder_dec_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old, 0 ); diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index f27d49b111..b7ec828d2f 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -222,3 +222,168 @@ void ivas_ism_render( } return; } + +#ifdef MASA_AND_OBJECTS +/*-------------------------------------------------------------------------* + * ivas_masa_ism_separate_object_renderer_open() + * + * Open structures, reserve memory, and init values. + *-------------------------------------------------------------------------*/ + +ivas_error ivas_masa_ism_separate_object_renderer_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t interpolator_length; + int16_t i; + + if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) count_malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer \n" ) ); + } + + + for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); + } + + interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / 50 ); + for ( i = 0; i < interpolator_length; i++ ) + { + st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length ); + } + + st_ivas->hMasaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + st_ivas->hMasaIsmData->delayBuffer_nchan = 1; + } + else + { + st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; + } + + if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) count_malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + } + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { + if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) count_malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + } + set_zero( st_ivas->hMasaIsmData->delayBuffer[i], st_ivas->hMasaIsmData->delayBuffer_size ); + } + + return IVAS_ERR_OK; +} + + +/*-------------------------------------------------------------------------* + * ivas_masa_ism_separate_object_render() + * + * Rendering separated objects and mixing them to the parametrically rendered signals + *-------------------------------------------------------------------------*/ + +void ivas_masa_ism_separate_object_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float input_f[][L_FRAME48k], /* i : separated object signal */ + float output_f[][L_FRAME48k], /* i/o: output signals */ + const int16_t output_frame /* i : output frame length per channel */ +) +{ + VBAP_HANDLE hVBAPdata; + AUDIO_CONFIG output_config; + int16_t nchan_out_woLFE; + ISM_RENDERER_HANDLE hRendererData; + int16_t j, k, j2; + int16_t obj; + float gains[MAX_OUTPUT_CHANNELS]; + float g1, g2; + int16_t lfe_index; + int16_t azimuth, elevation; + int16_t num_objects; + uint8_t single_separated; + + hVBAPdata = st_ivas->hVBAPdata; + output_config = st_ivas->hDecoderConfig->output_config; + nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + hRendererData = st_ivas->hIsmRendererData; + lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + single_separated = 1; + num_objects = 1; + } + else + { + single_separated = 0; + num_objects = st_ivas->nchan_ism; + } + + for ( obj = 0; obj < num_objects; obj++ ) + { + delay_signal( input_f[obj], output_frame, st_ivas->hMasaIsmData->delayBuffer[obj], st_ivas->hMasaIsmData->delayBuffer_size ); /* Delay the signal to match CLDFB delay */ + + if ( single_separated ) + { + azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; + elevation = st_ivas->hMasaIsmData->elevation_separated_ism; + } + else + { + azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; + elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; + } + + if ( output_config != AUDIO_CONFIG_7_1_4 && output_config != AUDIO_CONFIG_5_1_4 ) + { + /* If no elevation support in output format, then rendering should be done with zero elevation */ + elevation = 0; + } + else if ( output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_4 ) + { + /* For no negative elevations, it's better to map them to zero */ + elevation = elevation < 0 ? 0 : elevation; + } + + if ( hVBAPdata != NULL ) + { + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); + } + else + { + ivas_dirac_dec_get_response( azimuth, elevation, gains, st_ivas->hDirAC->hOutSetup.ambisonics_order ); + } + + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( st_ivas->hDirAC->hOutSetup.num_lfe > 0 ) + { + j2 = j + ( j >= lfe_index ); + } + else + { + j2 = j; + } + + if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) + { + for ( k = 0; k < output_frame; k++ ) + { + g1 = hRendererData->interpolator[k]; + g2 = 1.0f - g1; + output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; + } + } + hRendererData->prev_gains[obj][j] = gains[j]; + } + } + + return; +} +#endif diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 3df3784405..dcb70abf57 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -70,6 +70,10 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); +#ifdef MASA_AND_OBJECTS +static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos ); +static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, int16_t no_ism, int16_t K ); +#endif /*-----------------------------------------------------------------------* * ivas_masa_decode() @@ -91,13 +95,20 @@ ivas_error ivas_masa_decode( IVAS_FORMAT ivas_format; int16_t low_bitrate_mode, tmp_elem_mode; ivas_error error; +#ifdef MASA_AND_OBJECTS + int16_t obj; +#endif error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; low_bitrate_mode = -1; /* This means that LBR mode is not used. */ +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hOutSetup.separateChannelEnabled || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->hOutSetup.separateChannelEnabled ) +#endif { masa_brate = st_ivas->hCPE[0]->element_brate; } @@ -131,6 +142,24 @@ ivas_error ivas_masa_decode( /* the number of MASA transport channels was read in ivas_dec_setup() */ st->next_bit_pos -= MASA_TRANSP_BITS; *nb_bits_read += MASA_TRANSP_BITS; +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) + { + /* the number of objects was read */ + st->next_bit_pos -= NO_BITS_MASA_ISM_NO_OBJ; + *nb_bits_read += NO_BITS_MASA_ISM_NO_OBJ; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + /* read index of separated object */ + /* no_ism should be > 1*/ + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + } + } +#endif /* Placeholder for descriptive metadata content */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; byteBuffer += st->bit_stream[( st->next_bit_pos )--]; @@ -191,8 +220,39 @@ ivas_error ivas_masa_decode( /* Remove already read bits from the bit budget */ hQMetaData->metadata_max_bits -= *nb_bits_read; + +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos ); + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) + { + if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) + { + st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->hMasaIsmData->azimuth_ism[obj]; + st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->hMasaIsmData->elevation_ism[obj]; + } + } + } + } +#endif + + *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos ); +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Modify spatial metadata based on the MASA-to-total energy ratios */ + modify_masa_energy_ratios( hQMetaData ); + } +#endif /* Get direction decoding quality. EC 1 and 2 are handled by the default value. */ if ( hQMetaData->ec_flag == 2 ) { @@ -227,7 +287,12 @@ ivas_error ivas_masa_decode( } ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, - hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); + hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE +#ifdef MASA_AND_OBJECTS + , + st_ivas->ivas_format, st_ivas->ism_mode, 0 +#endif + ); hQMetaData->metadata_max_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; @@ -279,17 +344,74 @@ ivas_error ivas_masa_decode( ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, SBA_MODE_NONE, 0 ); } - st->next_bit_pos = next_bit_pos_orig; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( hQMetaData->q_direction == NULL ) + { + if ( ( error = ivas_masa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + if ( st_ivas->hDirAC != NULL ) + { + int16_t i; + int16_t b; + int16_t block; - if ( ivas_format == MASA_FORMAT && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + for ( i = 0; i < st_ivas->hDirAC->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ + { + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) + { + st_ivas->hDirAC->diffuseness_vector[block][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b]; + } + } + } + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) + { + st_ivas->hDirAC->diffuseness_vector[block][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[block][b] ); + } + } + } + } +#endif + st->next_bit_pos = next_bit_pos_orig; +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT ) { - st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ivas_total_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; + int32_t cpe_brate; + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); - if ( ivas_total_brate <= IVAS_SID_5k2 ) + if ( st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) { - st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = cpe_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; + + if ( ivas_total_brate <= IVAS_SID_5k2 ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; + } } } + else + { +#endif + if ( ivas_format == MASA_FORMAT && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ivas_total_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; + + if ( ivas_total_brate <= IVAS_SID_5k2 ) + { + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; + } + } +#ifdef MASA_AND_OBJECTS + } +#endif if ( ivas_format == MASA_FORMAT && st_ivas->nCPE == 1 ) { @@ -321,13 +443,30 @@ ivas_error ivas_masa_dec_open( ) { MASA_DECODER_HANDLE hMasa; - +#ifdef MASA_AND_OBJECTS + int16_t i; + int32_t sce_brate; +#endif if ( ( hMasa = (MASA_DECODER_HANDLE) count_malloc( sizeof( MASA_DECODER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } - - ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); +#ifdef MASA_AND_OBJECTS + sce_brate = 0; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + sce_brate += st_ivas->hSCE[i]->element_brate; + } + } +#endif + ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE +#ifdef MASA_AND_OBJECTS + , + st_ivas->ivas_format, st_ivas->ism_mode, sce_brate +#endif + ); mvs2s( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); @@ -359,7 +498,46 @@ ivas_error ivas_masa_dec_open( return IVAS_ERR_OK; } +#ifdef MASA_AND_OBJECTS +/*-------------------------------------------------------------------* + * ivas_masa_ism_data_open() + * + * + *-------------------------------------------------------------------*/ + +void ivas_masa_ism_data_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +) +{ + MASA_ISM_DATA_HANDLE hMasaIsmData; + int16_t bin; + int16_t ch; + if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) count_malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) + { + fprintf( stderr, "Can not allocate memory for MASA_ISM data\n" ); + exit( -1 ); + } + + for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) + { + for ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->ismPreprocMatrix[ch][ch][bin] = 1.0f; + hMasaIsmData->ismPreprocMatrix[1 - ch][ch][bin] = 0.0f; + hMasaIsmData->eneMoveIIR[ch][bin] = 0.0f; + hMasaIsmData->enePreserveIIR[ch][bin] = 0.0f; + } + hMasaIsmData->preprocEneTarget[bin] = 0.0f; + hMasaIsmData->preprocEneRealized[bin] = 0.0f; + } + hMasaIsmData->objectsMoved = 0; + hMasaIsmData->delayBuffer = NULL; + st_ivas->hMasaIsmData = hMasaIsmData; + + return; +} +#endif /*-----------------------------------------------------------------------* * ivas_masa_dec_close() * @@ -423,14 +601,40 @@ static ivas_error ivas_masa_dec_config( int16_t i; MASA_DECODER_HANDLE hMasa; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t ivas_total_brate; + int32_t sce_brate; +#endif error = IVAS_ERR_OK; hMasa = st_ivas->hMasa; - ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); +#ifdef MASA_AND_OBJECTS + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + sce_brate = 0; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + sce_brate += st_ivas->hSCE[i]->element_brate; + } + } + + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, sce_brate ); + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); + } + else + { + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); + } +#else + ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); +#endif st_ivas->hQMetaData->metadata_max_bits = hMasa->config.max_metadata_bits; st_ivas->hQMetaData->bandMap = hMasa->data.band_mapping; st_ivas->hQMetaData->nchan_transport = st_ivas->nchan_transport; @@ -1024,6 +1228,9 @@ ivas_error ivas_masa_dec_reconfigure( Decoder_State **sts; int32_t ivas_total_brate, last_ivas_total_brate; ivas_error error; +#ifdef MASA_AND_OBJECTS + int32_t sce_brate; +#endif error = IVAS_ERR_OK; @@ -1059,7 +1266,7 @@ ivas_error ivas_masa_dec_reconfigure( sts = st_ivas->hCPE[cpe_id]->hCoreCoder; sts[0]->bit_stream = bit_stream + num_bits; num_bits += (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); - + /* Todo: Nokia make for MASA_ISM*/ if ( ( ivas_total_brate < MASA_STEREO_MIN_BITRATE && last_ivas_total_brate >= MASA_STEREO_MIN_BITRATE ) || ( ivas_total_brate < MASA_STEREO_MIN_BITRATE && last_ivas_total_brate == FRAME_NO_DATA ) ) { @@ -1086,8 +1293,22 @@ ivas_error ivas_masa_dec_reconfigure( } } } - - ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp ); +#ifdef MASA_AND_OBJECTS + sce_brate = 0; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( n = 0; n < st_ivas->nSCE; n++ ) + { + sce_brate += st_ivas->hSCE[n]->element_brate; + } + } +#endif + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp +#ifdef MASA_AND_OBJECTS + , + st_ivas->ivas_format, st_ivas->ism_mode, sce_brate +#endif + ); return error; } @@ -1357,3 +1578,407 @@ static void compute_foa_cov_matrix( return; } + +#ifdef MASA_AND_OBJECTS + +static void decode_index_slice( + int16_t index, + int16_t *ratio_idx_ism, + int16_t no_ism, + int16_t K ) +{ + int16_t i, j, sum, elem; + int16_t base[MAX_NUM_OBJECTS]; + + switch ( no_ism ) + { + case 2: + ratio_idx_ism[0] = index; + ratio_idx_ism[1] = K - ratio_idx_ism[0]; + break; + case 3: + case 4: + { + j = 0; + while ( index >= 0 ) + { + if ( valid( j, K, no_ism - 1 ) ) + { + index--; + } + j++; + } + j--; + base[0] = 1; + for ( i = 1; i < no_ism - 1; i++ ) + { + base[i] = base[i - 1] * 10; + } + sum = 0; + for ( i = no_ism - 2; i >= 0; i-- ) + { + elem = j / base[i]; + ratio_idx_ism[no_ism - i - 2] = elem; + sum += elem; + j -= elem * base[i]; + } + ratio_idx_ism[no_ism - 1] = K - sum; + } + + default: + break; + } +} + +static void read_ism_ratio_index( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t no_ism, + int16_t numCodingBands, + int16_t sf, + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + uint16_t *bit_stream, + int16_t *next_bit_pos, + float *masa_to_total_energy_ratio ) +{ + int16_t b, i; + int16_t index; + int16_t GR_order, differential_subframe; + int16_t buf; + int16_t no_levels_ratio_ism; + no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); + if ( sf == 0 ) + { + switch ( no_ism ) + { + case 2: + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = 0; + for ( i = 0; i < 3; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + + decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + break; + case 3: + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + /* read first 5 bits */ + index = 0; + for ( i = 0; i < 5; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + if ( index == 31 ) + { + index = 0; + for ( i = 0; i < 3; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + index += 31; + } + + decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + break; + case 4: + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + /* read 7 bits */ + index = 0; + for ( i = 0; i < 7; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + + decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + break; + default: + assert( ( no_ism >= 2 && no_ism <= 4 ) && "Wrong number of objects for MASA_ISM." ); + break; + } + } + else + { + /* read prediciton type */ + differential_subframe = bit_stream[( *next_bit_pos )--]; + /* read GR order */ + GR_order = bit_stream[( *next_bit_pos )--]; + for ( b = 0; b < numCodingBands; b++ ) + { + for ( i = 0; i < no_ism - 1; i++ ) + { + buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); + if ( ( buf % 2 ) == 0 ) + { + ratio_ism_idx[b][i] = -( buf >> 1 ); + } + else + { + ratio_ism_idx[b][i] = ( ( buf + 1 ) >> 1 ); + } + } + } + if ( differential_subframe ) + { + /* differential to previous subframe */ + for ( b = 0; b < numCodingBands; b++ ) + { + ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx_prev_sf[b][i]; + ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; + } + } + } + else + { + /* difference to previous subband */ + ratio_ism_idx[0][no_ism - 1] = no_levels_ratio_ism; + /* first subband - differential to previous subframe */ + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[0][i] = ratio_ism_idx[0][i] + ratio_ism_idx_prev_sf[0][i]; + ratio_ism_idx[0][no_ism - 1] -= ratio_ism_idx[0][i]; + } + /* rest of subbands differential to previous subband */ + for ( b = 1; b < numCodingBands; b++ ) + { + ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx[b - 1][i]; + ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; + } + } + } + } +} + +static void decode_ism_ratios( + uint16_t *bit_stream, + int16_t *next_bit_pos, + IVAS_QMETADATA_HANDLE hQMetaData, + float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t n_ism ) +{ + int16_t sf, band; + int16_t nbands, numSf; + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + + nbands = hQMetaData->q_direction->cfg.nbands; + numSf = hQMetaData->q_direction->cfg.nblocks; + for ( sf = 0; sf < numSf; sf++ ) + { + /* read ism ratio indexes */ + read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf] ); + + /* save previous subframe index values */ + if ( sf < numSf - 1 ) + { + /* Todo Nokia: can be moved to the read_ism_ratio ... function */ + for ( band = 0; band < nbands; band++ ) + { + mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], n_ism ); + } + } + + /* reconstructed values */ + for ( band = 0; band < nbands; band++ ) + { + reconstruct_ism_ratios( ratio_ism_idx[band], n_ism, 1.0f / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ), ratio_ism[sf][band] ); + } + } +} + +static int16_t ivas_decode_masaism_metadata( + IVAS_QMETADATA_HANDLE hQMetaData, + MASA_DECODER_HANDLE hMasa, + MASA_ISM_DATA_HANDLE hMasaIsmData, + const int16_t nchan_ism, + uint16_t *bit_stream, + int16_t *next_bit_pos ) +{ + int16_t sf, band, dir, nbands, nblocks, obj, i; + + float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + int16_t *band_mapping; + int16_t b; + float priority[MAX_NUM_OBJECTS]; + int16_t bits_ism[MAX_NUM_OBJECTS], index; + uint16_t idx_el, idx_az; + float azimuth, elevation; + int16_t nb_bits_read; + + nb_bits_read = *next_bit_pos; + nbands = hQMetaData->q_direction->cfg.nbands; + nblocks = hQMetaData->q_direction->cfg.nblocks; + + + /* Read MASA-to-total energy ratios */ + decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands ); + if ( nchan_ism > 1 ) + { + /* read ISM ratios */ + decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism ); + + /* calculate priority */ + set_f( priority, 0.0f, nchan_ism ); + for ( sf = 0; sf < nblocks; sf++ ) + { + for ( band = 0; band < nbands; band++ ) + { + for ( obj = 0; obj < nchan_ism; obj++ ) + { + priority[obj] = max( priority[obj], ( energy_ratio_ism[sf][band][obj] * hQMetaData->masa_to_total_energy_ratio[sf][band] ) ); + } + } + } + } + else + { + for ( sf = 0; sf < nblocks; sf++ ) + { + for ( band = 0; band < nbands; band++ ) + { + energy_ratio_ism[sf][band][0] = 1.0f; + } + } + priority[0] = 1; + } + + /* read ISM metadata */ + for ( obj = 0; obj < nchan_ism; obj++ ) + { + bits_ism[obj] = 11 - (int16_t) ( ( 1 - priority[obj] ) * 7 ); + } + + for ( obj = 0; obj < nchan_ism; obj++ ) + { + index = 0; + for ( i = 0; i < bits_ism[obj]; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + hMasaIsmData->azimuth_ism[obj] = (int16_t) rint( azimuth ); + hMasaIsmData->elevation_ism[obj] = (int16_t) rint( elevation ); + } + + /* Modify ISM metadata based on the MASA-to-total energy ratios */ + for ( sf = 0; sf < nblocks; sf++ ) + { + for ( band = 0; band < nbands; band++ ) + { + for ( dir = 0; dir < nchan_ism; dir++ ) + { + energy_ratio_ism[sf][band][dir] *= ( 1.0f - hQMetaData->masa_to_total_energy_ratio[sf][band] ); + } + } + } + + /* Set data to struct in bins */ + band_mapping = hMasa->data.band_mapping; + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + { + if ( nblocks == 1 ) + { + i = 0; + } + else + { + i = sf; + } + + for ( dir = 0; dir < nchan_ism; dir++ ) + { + hMasaIsmData->energy_ratio_ism[dir][sf][b] = energy_ratio_ism[i][band][dir]; + } + } + } + } + + return ( nb_bits_read - *next_bit_pos ); +} + +void ivas_masa_ism_set_edited_objects( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t dir; + MASA_ISM_DATA_HANDLE hMasaIsmData; + + hMasaIsmData = st_ivas->hMasaIsmData; + + /* Set positions of the edited objects */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + if ( st_ivas->editing_ism_enabled ) + { + hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism] = st_ivas->azimuth_edited; + hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism] = st_ivas->elevation_edited; + } + } + else + { + for ( dir = 0; dir < MAX_NUM_OBJECTS; dir++ ) + { + if ( dir == st_ivas->index_of_edited_ism && st_ivas->editing_ism_enabled ) + { + hMasaIsmData->ism_is_edited[dir] = 1; + hMasaIsmData->azimuth_ism_edited[dir] = st_ivas->azimuth_edited; + hMasaIsmData->elevation_ism_edited[dir] = st_ivas->elevation_edited; + } + else + { + hMasaIsmData->ism_is_edited[dir] = 0; + } + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st_ivas->editing_ism_enabled ) + { + if ( st_ivas->hMasaIsmData->idx_separated_ism == st_ivas->index_of_edited_ism ) + { + st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->azimuth_edited; + st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->elevation_edited; + } + } + } +} + + +#endif diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 20b677075e..6edad11925 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -94,6 +94,23 @@ void ivas_mono_downmix_render_passive( MONO_DOWNMIX_RENDERER_HANDLE hDownmix; numInputChannels = st_ivas->nSCE; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) + { + numInputChannels = st_ivas->nchan_transport; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + numInputChannels = st_ivas->nchan_transport + 1; + } + else + { + numInputChannels = st_ivas->nchan_transport + st_ivas->nchan_ism; + } + } +#endif hDownmix = st_ivas->hMonoDmxRenderer; set_zero( proto_signal, output_frame ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 059ba752e7..b5b145a30f 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -55,7 +55,9 @@ static int16_t ivas_qmetadata_raw_decode_dir( IVAS_QDIRECTION *q_direction, uint static uint16_t ivas_qmetadata_DecodeQuasiUniform( const uint16_t *bitstream, int16_t *index, const uint16_t alphabet_size ); +#ifndef MASA_AND_OBJECTS static int16_t ivas_qmetadata_DecodeExtendedGR( uint16_t *bitstream, int16_t *index, const int16_t alph_size, const int16_t gr_param ); +#endif static int16_t ivas_qmetadata_ReorderElevationDecoded( const int16_t elev_dist, const int16_t elev_avg, const int16_t elev_alph ); @@ -91,6 +93,10 @@ static int16_t read_GR_min_removed_data( uint16_t *bitstream, int16_t *p_bit_pos static int16_t decode_fixed_rate_composed_index_coherence( uint16_t *bitstream, int16_t *p_bit_pos, const int16_t no_bands, int16_t *no_cv_vec, uint16_t *decoded_index, const int16_t no_symb ); +#ifdef MASA_AND_OBJECTS +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, int16_t len_stream, uint16_t *bit_stream, int16_t *index, int16_t first_line ); +#endif + /*-----------------------------------------------------------------------* * Global function definitions *-----------------------------------------------------------------------*/ @@ -557,6 +563,7 @@ int16_t ivas_qmetadata_dec_decode( bits_dir_target += bits_dir_raw; bits_dir_used += bits_dir; + #ifdef DEBUG_MODE_QMETADATA fprintf( pF, "frame %d: diff %d coh %d surcoh %d ", frame, bits_diff, bits_coherence, bits_sur_coherence ); fprintf( pF, "dir %d %d,%d,%d\n", ec_flag, start_index_0 - *index, total_bits_1dir, bits_dir_raw ); @@ -1573,12 +1580,16 @@ static uint16_t ivas_qmetadata_DecodeQuasiUniform( *------------------------------------------------------------------------*/ /* !r: Value decoded from the bitstream */ -static int16_t ivas_qmetadata_DecodeExtendedGR( - uint16_t *bitstream, /* i : pointer to the bitstream to read */ - int16_t *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ - const int16_t alph_size, /* i : size of the alphabet, used to calculate the number of bits needed */ - const int16_t gr_param /* i : GR parameter that indicates the limit for the most significant bits (msb) */ -) +#ifndef MASA_AND_OBJECTS +static +#endif + int16_t + ivas_qmetadata_DecodeExtendedGR( + uint16_t *bitstream, /* i : pointer to the bitstream to read */ + int16_t *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ + const int16_t alph_size, /* i : size of the alphabet, used to calculate the number of bits needed */ + const int16_t gr_param /* i : GR parameter that indicates the limit for the most significant bits (msb) */ + ) { int16_t i, msb_size; uint16_t value; @@ -3289,3 +3300,153 @@ static void decode_combined_index( return; } + +#ifdef MASA_AND_OBJECTS +static void read_stream_dct_coeffs_omasa( + int16_t *q_idx, + float *q_dct_data, + int16_t len_stream, + uint16_t *bit_stream, + int16_t *index, + int16_t first_line ) +{ + int16_t sign, nbits; + int16_t i, j, i_min; + int16_t last_non_null; + float step = 0.1f; + + nbits = 0; + sign = 1; + if ( first_line == 0 ) + { + /* read sign */ + sign = bit_stream[( *index )--]; + if ( sign == 0 ) + { + sign = -1; + } + nbits++; + } + + set_s( q_idx, 0, len_stream ); + /* read DCT 0 component */ + for ( i = 0; i < BITS_MASA2TOTTAL_DCT0; i++ ) + { + q_idx[0] = ( q_idx[0] << 1 ) + bit_stream[( *index )--]; + } + q_idx[0] *= sign; + + if ( q_idx[0] != 0 ) + { + /* read last non null position */ + last_non_null = 0; + j = (int16_t) ceilf( log2f( (float) ( len_stream ) ) ); + for ( i = 0; i < j; i++ ) + { + last_non_null = ( last_non_null << 1 ) + bit_stream[( *index )--]; + } + + nbits += j; + if ( last_non_null > 0 ) + { + /* read index of last index encoded with GR2 */ + i_min = 0; + j = (int16_t) ceilf( log2f( (float) ( last_non_null + 1 ) ) ); + for ( i = 0; i < j; i++ ) + { + i_min = ( i_min << 1 ) + bit_stream[( *index )--]; + } + + nbits += j; + + /* read GR data */ + for ( i = 1; i <= i_min; i++ ) + { + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, 2 ); + } + for ( i = i_min + 1; i <= last_non_null; i++ ) + { + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, 0 ); + } + } + } + /* deindex */ + q_dct_data[0] = q_idx[0] * step; + for ( i = 1; i < len_stream; i++ ) + { + if ( ( q_idx[i] % 2 ) == 0 ) + { + q_dct_data[i] = -( q_idx[i] >> 1 ) * step; + } + else + { + q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; + } + } + return; +} + +void decode_masa_to_total( + uint16_t *bit_stream, + int16_t *index, + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + int16_t nbands ) +{ + int16_t i, j, k; + + int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + + float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], + dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + + + int16_t n_streams, len_stream; + /* Setup coding parameters */ + if ( nbands == 5 ) + { + n_streams = 1; + len_stream = nbands * 4; + } + else if ( nbands == 8 ) + { + n_streams = 4; + len_stream = 8; + } + else + { + n_streams = 4; + len_stream = nbands; + printf( "Unrecognized number of bands!" ); /* To do: finalize this */ + exit( -1 ); + } + set_s( q_idx, 0, nbands * MAX_PARAM_SPATIAL_SUBFRAMES ); + for ( i = 0; i < n_streams; i++ ) + { + read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], &q_dct_data[i * len_stream], len_stream, bit_stream, index, i == 0 ); + } + + + /* inverse DCT2 transform */ + if ( nbands == 5 ) + { + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); /* reuse of variable*/ + } + else + { + assert( nbands == 8 ); + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); + } + k = 0; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); + k++; + } + } +} +#endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 97ee2e8336..45fc95f4c2 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -142,7 +142,15 @@ ivas_error ivas_sce_dec( if ( ( st_ivas->hQMetaData != NULL ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); + } + else if ( ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) || ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#else if ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) +#endif { st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC ); } @@ -160,6 +168,7 @@ ivas_error ivas_sce_dec( st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } + /* set "total_brate" */ if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_5k2 ) ) { @@ -169,17 +178,31 @@ ivas_error ivas_sce_dec( { st->total_brate = ivas_total_brate; } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + /* one separated object */ + st->total_brate = hSCE->element_brate; + } + } +#endif else if ( st_ivas->ivas_format != ISM_FORMAT ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ { st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; } - /*----------------------------------------------------------------* - * Core codec configuration - *----------------------------------------------------------------*/ +/*----------------------------------------------------------------* + * Core codec configuration + *----------------------------------------------------------------*/ - /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ +/* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ +#ifdef MASA_AND_OBJECTS + if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) +#else if ( st_ivas->ivas_format == ISM_FORMAT && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) +#endif { st->flag_ACELP16k = 0; } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 2393a41f2f..c85e9ef9fb 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -657,7 +657,13 @@ typedef struct ivas_dirac_dec_data_structure int16_t spar_to_dirac_write_idx; int16_t dirac_md_buffer_length; +#ifdef MASA_AND_OBJECTS + int16_t numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ + int16_t numParametricDirections; /* 1 or 2 */ + int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ +#else int16_t numSimultaneousDirections; /* 1 or 2 */ +#endif DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; /*Parameter estimation*/ @@ -1172,6 +1178,35 @@ typedef struct ivas_masa_decoder_struct } MASA_DECODER, *MASA_DECODER_HANDLE; +#ifdef MASA_AND_OBJECTS +/* Data structure for MASA_ISM rendering */ +typedef struct ivas_masa_ism_data_structure +{ + int16_t azimuth_ism[MAX_NUM_OBJECTS]; + int16_t elevation_ism[MAX_NUM_OBJECTS]; + float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + + int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; + int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; + uint8_t ism_is_edited[MAX_NUM_OBJECTS]; + + int16_t idx_separated_ism; + int16_t azimuth_separated_ism; + int16_t elevation_separated_ism; + + float ismPreprocMatrix[2][2][CLDFB_NO_CHANNELS_MAX]; + uint8_t objectsMoved; + float eneMoveIIR[2][CLDFB_NO_CHANNELS_MAX]; + float enePreserveIIR[2][CLDFB_NO_CHANNELS_MAX]; + float preprocEneTarget[CLDFB_NO_CHANNELS_MAX]; + float preprocEneRealized[CLDFB_NO_CHANNELS_MAX]; + + float **delayBuffer; + int16_t delayBuffer_size; + int16_t delayBuffer_nchan; + +} MASA_ISM_DATA, *MASA_ISM_DATA_HANDLE; +#endif /*----------------------------------------------------------------------------------* * Binaural Rendering structure @@ -1230,8 +1265,13 @@ typedef struct ivas_dirac_dec_binaural_data_structure float ChEneOut[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float ChCrossReOut[CLDFB_NO_CHANNELS_MAX]; float ChCrossImOut[CLDFB_NO_CHANNELS_MAX]; +#ifdef MASA_AND_OBJECTS + float processMtxRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + float processMtxIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; +#else float processMtxRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; /* +1 refers to SeparateChannel */ float processMtxIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; +#endif float processMtxDecRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float diffuseFieldCoherence[CLDFB_NO_CHANNELS_MAX]; @@ -1242,8 +1282,13 @@ typedef struct ivas_dirac_dec_binaural_data_structure REVERB_STRUCT_HANDLE hReverb; uint8_t renderStereoOutputInsteadOfBinaural; float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; +#ifdef MASA_AND_OBJECTS + float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; +#else float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; +#endif float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; uint16_t useSubframeMode; /* 0 = process in 20 ms frames, 1 = process in 5 ms subframes */ @@ -1961,6 +2006,16 @@ typedef struct Decoder_Struct HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ int32_t binaural_latency_ns; /* HRTF binauralization latency in ns */ +#ifdef MASA_AND_OBJECTS + int16_t nchan_ism; /* number of ism channels in combined input format mode */ + MASA_ISM_DATA_HANDLE hMasaIsmData; /* MASA_ISM rendering structure */ + + uint8_t editing_ism_enabled; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t index_of_edited_ism; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t azimuth_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t elevation_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ +#endif + #ifdef DEBUGGING int32_t noClipping; /* number of clipped samples */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 70e0384839..8016e4f75f 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -197,6 +197,13 @@ ivas_error IVAS_DEC_Open( st_ivas->sba_planar = 0; st_ivas->sba_analysis_order = 0; +#ifdef MASA_AND_OBJECTS + hIvasDec->st_ivas->editing_ism_enabled = 0; + hIvasDec->st_ivas->index_of_edited_ism = 0; + hIvasDec->st_ivas->azimuth_edited = 0; + hIvasDec->st_ivas->elevation_edited = 0; +#endif + return IVAS_ERR_OK; } @@ -940,6 +947,35 @@ ivas_error IVAS_DEC_GetHrtfHandle( } +#ifdef MASAISM_EDIT_OBJECTS +/*---------------------------------------------------------------------* + * IVAS_DEC_SetEditedIsmPositions( ) + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_SetEditedIsmPositions( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t index_of_edited_ism, /* i : Index of edited ISM */ + int16_t azimuth_edited_ism, /* i : Azimuth */ + int16_t elevation_edited_ism /* i : Elevation */ +) +{ + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + hIvasDec->st_ivas->editing_ism_enabled = 1; + hIvasDec->st_ivas->index_of_edited_ism = index_of_edited_ism; + hIvasDec->st_ivas->azimuth_edited = azimuth_edited_ism; + hIvasDec->st_ivas->elevation_edited = elevation_edited_ism; + + return IVAS_ERR_OK; +} +#endif + + /*---------------------------------------------------------------------* * IVAS_DEC_GetRenderConfig( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index f43034c885..7231ccf3da 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -278,6 +278,15 @@ ivas_error IVAS_DEC_GetHrtfHandle( IVAS_DEC_HRTF_HANDLE *hHrtfTD /* o : HRTF handle */ ); +#ifdef MASAISM_EDIT_OBJECTS +ivas_error IVAS_DEC_SetEditedIsmPositions( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + int16_t index_of_edited_ism, /* i : Index of edited ISM */ + int16_t azimuth_edited_ism, /* i : Azimuth */ + int16_t elevation_edited_ism /* i : Elevation */ +); +#endif + /*! r: error code*/ ivas_error IVAS_DEC_GetRenderConfig( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 5c4011fe0c..e5c83ffb20 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -101,6 +101,9 @@ ivas_error ivas_cpe_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; int32_t ivas_total_brate; ivas_error error; +#ifdef MASA_AND_OBJECTS + int32_t cpe_brate; +#endif error = IVAS_ERR_OK; @@ -547,7 +550,9 @@ ivas_error ivas_cpe_enc( * DFT Stereo residual coding * DFT Stereo parameters writing into the bitstream *----------------------------------------------------------------*/ - +#ifdef MASA_AND_OBJECTS + cpe_brate = 0; +#endif if ( hCPE->element_mode == IVAS_CPE_DFT ) { if ( hEncoderConfig->Opt_DTX_ON ) @@ -578,6 +583,33 @@ ivas_error ivas_cpe_enc( } /* Write stereo bitstream */ +#ifdef MASA_AND_OBJECTS + cpe_brate = ivas_total_brate; + + if ( ivas_format == MASA_ISM_FORMAT ) + { + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + } + + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && cpe_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) + { + nb_bits = 0; /* Only mono downmix is transmitted in this case */ + } + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) + { + nb_bits = hCPE->hMetaData->nb_bits_tot; + } + else + { + stereo_dft_enc_write_BS( hCPE, &nb_bits ); + } + + if ( !( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) ) + { + /* Residual coding in MDCT domain */ + stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal - ( ( ivas_format == MASA_FORMAT ) ? nb_bits_metadata : 0 ) ) ); + } +#else if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) { nb_bits = 0; /* Only mono downmix is transmitted in this case */ @@ -596,7 +628,7 @@ ivas_error ivas_cpe_enc( /* Residual coding in MDCT domain */ stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal - ( ( ivas_format == MASA_FORMAT ) ? nb_bits_metadata : 0 ) ) ); } - +#endif if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 ) { assert( ( nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); @@ -762,7 +794,11 @@ ivas_error create_cpe_enc( for ( n = 0; n < CPE_CHANNELS; n++ ) { +#ifdef MASA_AND_OBJECTS + if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == STEREO_FORMAT || ivas_format == MASA_FORMAT || ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) +#endif { if ( ( hCPE->input_mem[n] = (float *) count_malloc( sizeof( float ) * NS2SA( input_Fs, STEREO_DFT_OVL_NS ) ) ) == NULL ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 7be1f11c49..bc2b6d33a0 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -61,7 +61,11 @@ ivas_error ivas_enc( ENCODER_CONFIG_HANDLE hEncoderConfig; BSTR_ENC_HANDLE hMetaData; Encoder_State *st; /* used for bitstream handling */ +#ifdef MASA_AND_OBJECTS + int16_t nb_bits_metadata[MAX_SCE + 1]; +#else int16_t nb_bits_metadata[MAX_SCE]; +#endif float data_f[MAX_INPUT_CHANNELS][L_FRAME48k]; /* IVAS_fmToDo: buffer can be allocated dynamically based on the number of analysed channels */ int32_t ivas_total_brate; ivas_error error; @@ -250,7 +254,12 @@ ivas_error ivas_enc( ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, - ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 ); + ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 +#ifdef MASA_AND_OBJECTS + , + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0 +#endif + ); } } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) @@ -289,6 +298,83 @@ ivas_error ivas_enc( } } } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_ISM_FORMAT ) + { + float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; + float data_separated_object[L_FRAME48k]; + int16_t idx_separated_object; + + ivas_masa_enc_reconfigure( st_ivas ); + + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - st_ivas->nchan_ism ) == 1 ) + { + v_multc( data_f[st_ivas->nchan_ism], 1.0f / SQRT2, data_f[st_ivas->nchan_ism], input_frame ); + mvr2r( data_f[st_ivas->nchan_ism], data_f[st_ivas->nchan_ism + 1], input_frame ); + } + + /* nb_bits_metadata[0] = 0; */ + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + if ( st_ivas->hQMetaData != NULL ) + { + /* Configure MASA encoder based on frame parameters */ + ivas_masa_enc_config( st_ivas ); + idx_separated_object = 0; + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Configure oMASA analysis based on MASA config */ + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs ); + } + else + { + st_ivas->nSCE = st_ivas->nchan_ism; + } + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[st_ivas->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, data_transport_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, + data_separated_object, &idx_separated_object ); + } + + /* Encode MASA parameters and write MASA metadata bitstream */ + ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object ); + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Merge transport signals */ + ivas_merge_masa_transports( data_transport_f, &( data_f[st_ivas->nchan_ism] ), data_f, input_frame, st_ivas->nchan_transport ); + } + } + + /* Encode transport signals */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ); /* there are no metadata bits in SCE in this mode */ + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + n = st_ivas->nchan_ism; + } + + if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ + { + ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); + } + } +#endif else if ( ivas_format == MC_FORMAT ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ @@ -339,7 +425,13 @@ ivas_error ivas_enc( ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp ); - ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 ); + ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 +#ifdef MASA_AND_OBJECTS + , + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0 +#endif + ); + if ( st_ivas->hMcMasa->separateChannelEnabled ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 18280a60e2..b5ed592a34 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -37,6 +37,9 @@ #include "prot.h" #include "ivas_prot.h" #include "ivas_stat_enc.h" +#ifdef MASA_AND_OBJECTS +#include "ivas_rom_com.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -74,10 +77,31 @@ void ivas_write_format( ind = 6; nBits += extra_bits; break; +#ifdef MASA_AND_OBJECTS + case MASA_FORMAT: + ind = 14; + nBits += extra_bits + MASA_ISM_FORMAT_BITS; + break; +#else case MASA_FORMAT: ind = 7; nBits += extra_bits; break; +#endif +#ifdef MASA_AND_OBJECTS + case MASA_ISM_FORMAT: + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + ind = 14; /* send MASA format */ + nBits += extra_bits + MASA_ISM_FORMAT_BITS; + } + else + { + ind = 15; + nBits += extra_bits + MASA_ISM_FORMAT_BITS; + } + break; +#endif default: assert( !"Invalid format. Aborting." ); break; @@ -156,7 +180,11 @@ void ivas_write_format_sid( ind = SID_MASA_2TC; } break; - +#ifdef MASA_AND_OBJECTS + case MASA_ISM_FORMAT: /* TODO Nokia: Finalize for SID case */ + ind = 8; + break; +#endif default: assert( !"Reserved SID format symbol written." ); break; @@ -194,7 +222,12 @@ int16_t getNumChanAnalysis( { n = st_ivas->hEncoderConfig->nchan_inp; } - +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + n = st_ivas->hEncoderConfig->nchan_inp; + } +#endif return n; } @@ -299,6 +332,11 @@ void ivas_initialize_handles_enc( /* LFE handle */ st_ivas->hLFE = NULL; +#ifdef MASA_AND_OBJECTS + /* Object MASA handle */ + st_ivas->hOMasa = NULL; +#endif + return; } @@ -519,6 +557,93 @@ ivas_error ivas_init_encoder( } } } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_ISM_FORMAT ) + { + int32_t element_brate_tmp[MAX_NUM_OBJECTS]; + int32_t sce_brate; + int16_t k; + + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->nchan_transport = 2; + create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ); + /* the values of element_brate_tmp will be re-written in MASA_ISM_FORMAT because they are taken from sep_object_brate[][]*/ + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + st_ivas->nSCE = st_ivas->nchan_ism; + } + + k = 0; + sce_brate = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + /* use the bitrate for one object */ + sce_brate = sep_object_brate[k - 2][0]; + create_sce_enc( st_ivas, 0, sce_brate ); + + /* prepare bitstream buffers */ + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list[0]; + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); + + st_ivas->hSCE[0]->hMetaData->ind_list = ind_list_metadata[0]; + reset_indices_enc( st_ivas->hSCE[0]->hMetaData, MAX_BITS_METADATA ); + } + else + { + sce_brate = 0; + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sce_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + + /* prepare bitstream buffers */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); + + st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata[sce_id]; + reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); + } + } + ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); + ivas_masa_enc_open( st_ivas ); + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + ivas_omasa_enc_open( st_ivas ); + } + if ( ivas_total_brate - sce_brate >= MIN_BRATE_MDCT_STEREO ) + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + else + { + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - sce_brate ); + + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[st_ivas->nSCE + cpe_id * CPE_CHANNELS + n]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); + } + + /* Metadata only initialized for the last cpe index*/ + if ( cpe_id == st_ivas->nCPE - 1 ) + { + st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; + reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); + } + } + } +#endif else if ( ivas_format == MC_FORMAT ) { st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); @@ -978,6 +1103,14 @@ void ivas_destroy_enc( st_ivas->hMcMasa = NULL; } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hOMasa != NULL ) + { + ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->nchan_ism ); + st_ivas->hOMasa = NULL; + } +#endif + /* Stereo downmix for EVS encoder handle */ if ( st_ivas->hStereoDmxEVS != NULL ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 8e6c059c7b..4c8709ad0a 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -88,7 +88,9 @@ ivas_error ivas_ism_enc( int16_t localVAD_HE_SAD[1]; /* local HE VAD */ int16_t i, nBits; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int16_t n; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ivas_ism_enc" ); @@ -98,7 +100,11 @@ ivas_error ivas_ism_enc( *-----------------------------------------------------------------*/ /* in ISM format: st_ivas->nchan_transport = st_ivas->nSCE */ +#ifdef MASA_AND_OBJECTS + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) +#else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) +#endif { hSCE = st_ivas->hSCE[sce_id]; st = hSCE->hCoreCoder[0]; @@ -205,11 +211,34 @@ ivas_error ivas_ism_enc( st_ivas->hDirAC->hParamIsm->flag_noisy_speech = st_ivas->hDirAC->hParamIsm->flag_noisy_speech && st_ivas->hDirAC->hParamIsm->noisy_speech_buffer[i]; } - ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm ); + ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm +#ifdef MASA_AND_OBJECTS + , + st_ivas->nSCE +#endif + ); } else /* ISM_MODE_DISC */ { +#ifdef MASA_AND_OBJECTS + int32_t ism_total_brate; + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + ism_total_brate = 0; + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + ism_total_brate += st_ivas->hSCE[i]->element_brate; + } + } + else + { + ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + } + + ivas_ism_metadata_enc( ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE ); +#else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL ); +#endif } /*----------------------------------------------------------------* @@ -235,8 +264,20 @@ ivas_error ivas_ism_enc( /*------------------------------------------------------------------* * CoreCoders encoding *-----------------------------------------------------------------*/ +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n = st_ivas->nSCE; + } + else + { + n = st_ivas->nchan_transport; + } + for ( sce_id = 0; sce_id < n; sce_id++ ) +#else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) +#endif { hSCE = st_ivas->hSCE[sce_id]; st = hSCE->hCoreCoder[0]; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 60550bca0b..139b7806a9 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -142,6 +142,10 @@ ivas_error ivas_ism_metadata_enc( const int16_t localVAD[], /* i : VAD flag */ const int16_t ism_mode, /* i : ISM mode */ const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ +#ifdef MASA_AND_OBJECTS + , + int16_t n_ism /* i : number of ism-s */ +#endif ) { int16_t i, ch, nb_bits_start = 0, diff; @@ -154,7 +158,9 @@ ivas_error ivas_ism_metadata_enc( int16_t ism_imp[MAX_NUM_OBJECTS]; int16_t num_obj, nbands, nblocks; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int16_t n_ch; +#endif error = IVAS_ERR_OK; wmops_sub_start( "ism_meta_enc" ); @@ -167,12 +173,21 @@ ivas_error ivas_ism_metadata_enc( { num_obj = nchan_transport; } +#ifdef MASA_AND_OBJECTS + else if ( ism_mode == ISM_MASA_MODE_DISC ) + { + num_obj = n_ism; + } +#endif else { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: incorrect ISM mode" ); } - +#ifdef MASA_AND_OBJECTS + if ( num_obj == 1 && ( hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 || hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA ) && ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( num_obj == 1 && ( hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 || hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA ) && ( ism_mode == ISM_MODE_DISC ) ) +#endif { /* no metadata encoding in CNG */ wmops_sub_end(); @@ -196,7 +211,11 @@ ivas_error ivas_ism_metadata_enc( { hIsmMeta[ch]->ism_metadata_flag = 1; } +#ifdef MASA_AND_OBJECTS + else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else else if ( ism_mode == ISM_MODE_DISC ) +#endif { hIsmMeta[ch]->ism_metadata_flag = localVAD[ch]; @@ -223,11 +242,28 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Rate importance of particular ISm streams *----------------------------------------------------------------*/ +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + n_ch = num_obj; + } + else + { + n_ch = nchan_transport; + } + rate_ism_importance( n_ch, hIsmMeta, hSCE, ism_imp ); + +#else rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); +#endif /* relax the importance decision in "stereo" coding for noisy audio */ +#ifdef MASA_AND_OBJECTS + if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && num_obj == 2 ) +#else if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) +#endif { float diff_F; @@ -250,28 +286,47 @@ ivas_error ivas_ism_metadata_enc( * Write ISm common signaling *----------------------------------------------------------------*/ - /* write number of objects - unary coding */ - for ( ch = 1; ch < num_obj; ch++ ) + /*Todo: Nokia check where we transmit the number of objects */ +#ifdef MASA_AND_OBJECTS + if ( ism_mode != ISM_MASA_MODE_DISC ) { - push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); +#endif + /* write number of objects - unary coding */ + for ( ch = 1; ch < num_obj; ch++ ) + { + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); + } + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); +#ifdef MASA_AND_OBJECTS } - push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); - +#endif /* write ISm metadata flag (one per object) */ +#ifdef MASA_AND_OBJECTS + for ( ch = 0; ch < n_ch; ch++ ) +#else for ( ch = 0; ch < nchan_transport; ch++ ) +#endif { push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); } + for ( ch = 0; ch < num_obj; ch++ ) { ism_metadata_flag_global |= hIsmMeta[ch]->ism_metadata_flag; } - +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { /* write VAD flag */ +#ifdef MASA_AND_OBJECTS + for ( ch = 0; ch < n_ch; ch++ ) +#else for ( ch = 0; ch < nchan_transport; ch++ ) +#endif { if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { @@ -298,7 +353,11 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < num_obj; ch++ ) { hIsmMetaData = hIsmMeta[ch]; +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { nb_bits_start = hBstr->nb_bits_tot; } @@ -310,7 +369,11 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ /* Azimuth quantization (quantize azimuth to the AZIMUTH_NBITS-bit index */ +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { idx_azimuth_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ); } @@ -416,7 +479,11 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ /* Elevation quantization (quantize azimuth to the ELEVATION_NBITS-bit index */ +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { idx_elevation_abs = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, 1 << ISM_ELEVATION_NBITS ); } @@ -545,7 +612,11 @@ ivas_error ivas_ism_metadata_enc( hIsmMetaData->last_elevation_idx = idx_elevation_abs; /* save number of metadata bits written */ +#ifdef MASA_AND_OBJECTS + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#else if ( ism_mode == ISM_MODE_DISC ) +#endif { nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; } @@ -676,14 +747,39 @@ ivas_error ivas_ism_metadata_enc( /*----------------------------------------------------------------* * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ - +#ifdef MASA_AND_OBJECTS + ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, + ( ism_mode == ISM_MASA_MODE_DISC ) ); +#else ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); +#endif for ( ch = 0; ch < num_obj; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; } +#ifdef MASA_AND_OBJECTS + for ( ch = 0; ch < n_ch; ch++ ) + { + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; + if ( hIsmMeta[ch]->ism_metadata_flag == 0 && localVAD[ch] == 0 && ism_metadata_flag_global ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + } + } + + hSCE[ch]->element_brate = element_brate[ch]; + hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; + /* write metadata only in active frames */ + if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) + { + reset_indices_enc( hSCE[ch]->hMetaData, MAX_BITS_METADATA ); + } + } +#else for ( ch = 0; ch < nchan_transport; ch++ ) { if ( ism_mode == ISM_MODE_DISC ) @@ -704,6 +800,7 @@ ivas_error ivas_ism_metadata_enc( reset_indices_enc( hSCE[ch]->hMetaData, MAX_BITS_METADATA ); } } +#endif wmops_sub_end(); @@ -723,20 +820,77 @@ ivas_error create_ism_metadata_enc( ) { int16_t ch, nchan_transport; - - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) +#ifdef MASA_AND_OBJECTS + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { - nchan_transport = 2; + switch ( st_ivas->ism_mode ) + { + case ISM_MASA_MODE_PARAM: + st_ivas->nCPE = 1; + st_ivas->nSCE = 0; + break; + case ISM_MASA_MODE_ONE_OBJ: + st_ivas->nCPE = 1; + st_ivas->nSCE = 1; + break; + case ISM_MODE_DISC: + st_ivas->nCPE = 1; + st_ivas->nSCE = n_ISms; + break; + case ISM_MASA_MODE_DISC: + st_ivas->nCPE = 1; + st_ivas->nSCE = n_ISms; + break; + case ISM_MODE_NONE: + if ( nchan_transport == 1 ) + { + st_ivas->nSCE = 1; + st_ivas->nCPE = 0; + } + else + { + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; + } + break; + default: + break; + } } else { - nchan_transport = n_ISms; - } +#endif + if ( st_ivas->ism_mode == ISM_MODE_NONE ) + { + nchan_transport = st_ivas->nchan_transport; - st_ivas->nchan_transport = nchan_transport; - st_ivas->nSCE = nchan_transport; - st_ivas->nCPE = 0; + if ( nchan_transport == 1 ) + { + st_ivas->nSCE = 1; + st_ivas->nCPE = 0; + } + else + { + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; + } + } + else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + nchan_transport = 2; + } + else + { + nchan_transport = n_ISms; + } + st_ivas->nchan_transport = nchan_transport; + st_ivas->nSCE = nchan_transport; + st_ivas->nCPE = 0; +#ifdef MASA_AND_OBJECTS + } +#endif /* allocate ISm metadata handles */ for ( ch = 0; ch < n_ISms; ch++ ) { @@ -753,8 +907,29 @@ ivas_error create_ism_metadata_enc( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - - ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); - +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ); + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ); + } + } + else + { +#endif + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL +#ifdef MASA_AND_OBJECTS + , + 0 +#endif + ); +#ifdef MASA_AND_OBJECTS + } +#endif return IVAS_ERR_OK; } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 8dcdef30b5..7cb259b7f7 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -274,6 +274,7 @@ ivas_error ivas_param_ism_enc_open( /* Assign the number of objects */ hDirAC->hParamIsm->num_obj = st_ivas->hEncoderConfig->nchan_inp; + /* set FB config. */ if ( ( error = ivas_fb_set_cfg( &fb_cfg, ISM_FORMAT, SBA_MODE_NONE, st_ivas->hEncoderConfig->nchan_inp, 0, 0, input_Fs ) ) != IVAS_ERR_OK ) { @@ -442,7 +443,11 @@ ivas_error ivas_ism_enc_config( st_ivas->nSCE = st_ivas->nchan_transport; st_ivas->nCPE = 0; +#ifdef MASA_AND_OBJECTS + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ); +#else ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); +#endif ivas_corecoder_enc_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c2649adc56..05f5892005 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -58,7 +58,26 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); +#ifdef MASA_AND_OBJECTS +static void ivas_merge_masa_metadatas( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); + +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[] /* i/o: ISM metadata handles */ +); + +static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); + + +static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t no_ism, float masa_to_total_energy_ratio ); + +static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); + +static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio ); +#else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); +#endif /*-----------------------------------------------------------------------* @@ -85,7 +104,9 @@ ivas_error ivas_masa_enc_open( MASA_ENCODER_HANDLE hMasa; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t sce_brate; +#endif error = IVAS_ERR_OK; if ( ( hMasa = (MASA_ENCODER_HANDLE) count_malloc( sizeof( MASA_ENCODER ) ) ) == NULL ) @@ -94,9 +115,14 @@ ivas_error ivas_masa_enc_open( } hEncoderConfig = st_ivas->hEncoderConfig; + generate_gridEq( &( hMasa->data.Sph_Grid16 ) ); +#ifdef MASA_AND_OBJECTS + if ( hEncoderConfig->ivas_format == MASA_FORMAT || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) +#else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) +#endif { hMasa->data.num_Cldfb_instances = st_ivas->nchan_transport; } @@ -112,14 +138,31 @@ ivas_error ivas_masa_enc_open( return error; } } - +#ifdef MASA_AND_OBJECTS + sce_brate = 0; + if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + sce_brate += st_ivas->hSCE[i]->element_brate; + } + } +#endif ivas_masa_set_elements( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, - st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); + st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE +#ifdef MASA_AND_OBJECTS + , + hEncoderConfig->ivas_format, st_ivas->ism_mode, sce_brate +#endif + ); mvs2s( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); - +#ifdef MASA_AND_OBJECTS + if ( hEncoderConfig->ivas_format == MASA_FORMAT || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) +#else if ( hEncoderConfig->ivas_format == MASA_FORMAT ) +#endif { for ( i = 0; i < st_ivas->nchan_transport; i++ ) { @@ -158,8 +201,11 @@ void ivas_masa_enc_close( { deleteCldfb( &( hMasa->data.cldfbAnaEnc[i] ) ); } - +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { for ( i = 0; i < nchan_transport; i++ ) { @@ -190,16 +236,27 @@ void ivas_masa_encode( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t Opt_DTX_ON, /* i : DTX on flag */ const int16_t element_mode /* i : element mode */ +#ifdef MASA_AND_OBJECTS + , + ISM_MODE ism_mode, /* i : ISM format mode */ + int16_t nchan_ism, /* i : number of ism channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + int16_t idx_separated_object /* i : index of the separated object */ +#endif ) { MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; int16_t i, j; int16_t masa_sid_descriptor; + masa_sid_descriptor = -1; h_orig_metadata = NULL; - +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { /* Create the MASA SID descriptor for the metadata and CPE mode, in order to have the SID frame self-contained. */ if ( Opt_DTX_ON && hQMetaData != NULL ) @@ -234,8 +291,11 @@ void ivas_masa_encode( /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes( hMasa ); } - +#ifdef MASA_AND_OBJECTS + if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) +#else if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ivas_format == MASA_FORMAT ) +#endif { /* Combine directions */ combine_directions( hMasa ); @@ -251,12 +311,30 @@ void ivas_masa_encode( /* Reset qmetadata bit budget */ hQMetaData->metadata_max_bits = hMasa->config.max_metadata_bits; - +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { /* write the number of MASA transport channels */ push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) + { + /* always write the number of objects in ISM_MASA format*/ + push_next_indice( hMetaData, nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + + /* write index of separated object if needed */ + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ && hMasa->data.nchan_ism > 1 ) + { + push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + } + } +#endif /* write placeholder data for descriptive metadata */ push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); @@ -279,23 +357,55 @@ void ivas_masa_encode( } /* Move data from encoder to qmetadata */ +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { move_metadata_to_qmetadata( hMasa, hQMetaData ); } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_ISM_FORMAT ) + { + ivas_merge_masa_metadatas( hMasa, hQMetaData ); + } +#endif if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) { +#ifdef MASA_AND_OBJECTS + reduce_metadata_further( hMasa, hQMetaData, ivas_format, ism_mode ); +#else reduce_metadata_further( hMasa, hQMetaData, ivas_format ); - +#endif /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; } +#ifdef MASA_AND_OBJECTS + /* Encode MASA+ISM metadata */ + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + /* encode MASA/ISM energy ratios */ + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData ); + } + else + { + hQMetaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ + } +#endif /* Encode metadata */ ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + /* Modify spatial metadata based on the MASA-to-total energy ratios */ + modify_masa_energy_ratios( hQMetaData ); + } +#endif *nb_bits_metadata = hMetaData->nb_bits_tot; if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) @@ -466,19 +576,40 @@ ivas_error ivas_masa_enc_config( uint8_t isActualTwoDir; /* Flag to tell that when there are two directions present in metadata, they both contain meaningful information. */ int32_t ivas_total_brate; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t sce_brate; +#endif error = IVAS_ERR_OK; hMasa = st_ivas->hMasa; hQMetaData = st_ivas->hQMetaData; ivas_format = st_ivas->hEncoderConfig->ivas_format; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; - +#ifdef MASA_AND_OBJECTS + sce_brate = 0; + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + sce_brate += st_ivas->hSCE[i]->element_brate; + } + } +#endif ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, - hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); + hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE +#ifdef MASA_AND_OBJECTS + , + ivas_format, st_ivas->ism_mode, sce_brate +#endif + ); hQMetaData->is_masa_ivas_format = 1; + +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { /* Inspect metadata for parameter changes that affect coding. */ detect_metadata_composition( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); @@ -493,8 +624,18 @@ ivas_error ivas_masa_enc_config( hMasa->config.numberOfDirections = 1; } - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); - +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT ) + { + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); + } + else + { +#endif + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); +#ifdef MASA_AND_OBJECTS + } +#endif /* Setup importance weights for two-direction band selection. */ if ( hMasa->config.numberOfDirections == 2 ) { @@ -572,9 +713,17 @@ ivas_error ivas_masa_enc_config( masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, st_ivas->hEncoderConfig->input_Fs ); /* Transmit stereo signals using a mono downmix at lowest bitrates */ +#ifdef MASA_AND_OBJECTS + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) +#else if ( ivas_format == MASA_FORMAT && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) +#endif { +#ifdef MASA_AND_OBJECTS + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - sce_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; +#else st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ivas_total_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; +#endif } return error; @@ -1276,7 +1425,12 @@ static void compensate_energy_ratios( static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, - const IVAS_FORMAT ivas_format ) + const IVAS_FORMAT ivas_format +#ifdef MASA_AND_OBJECTS + , + const ISM_MODE ism_mode +#endif +) { int16_t sf; int16_t band; @@ -1299,7 +1453,11 @@ static void reduce_metadata_further( /* Get energy for the input data in 4-subframe, 5-band format */ totalEnergySum = 0.0f; +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) /* Energy data is in 4-subframe, 24-band format */ +#else if ( ivas_format == MASA_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ +#endif { for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { @@ -1678,8 +1836,21 @@ void ivas_masa_enc_reconfigure( int16_t n, tmp; int16_t sce_id, cpe_id; int32_t ivas_total_brate; - ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; +#ifdef MASA_AND_OBJECTS + int32_t sce_brate; +#endif + ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; +#ifdef MASA_AND_OBJECTS + sce_brate = 0; + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) + { + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + sce_brate += st_ivas->hSCE[sce_id]->element_brate; + } + } +#endif if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) @@ -1699,7 +1870,16 @@ void ivas_masa_enc_reconfigure( copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } - +#ifdef MASA_AND_OBJECTS + if ( ivas_total_brate - sce_brate < MASA_STEREO_MIN_BITRATE || ivas_total_brate - sce_brate < MIN_BRATE_MDCT_STEREO ) + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; + } + else + { + st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; + } +#else if ( ivas_total_brate < MASA_STEREO_MIN_BITRATE ) { st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; @@ -1712,10 +1892,622 @@ void ivas_masa_enc_reconfigure( { st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_MDCT; } +#endif } - ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp ); + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp +#ifdef MASA_AND_OBJECTS + , + st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, sce_brate +#endif + ); } return; } + +#ifdef MASA_AND_OBJECTS +static void ivas_merge_masa_metadatas( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMeta ) +{ + int16_t sf, band; + uint8_t numCodingBands; + uint8_t numDirections; + uint8_t numSf; + MASA_METADATA_HANDLE hMeta; + float energyTimesRatio1, energyTimesRatio2; + int16_t brange[2]; + float eneBand; + float energyMerged[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + int16_t bin; + + numCodingBands = hMasa->config.numCodingBands; + numDirections = hMasa->config.numberOfDirections; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + hMeta = &( hMasa->masaMetadata ); + + assert( numDirections == 1 && "MASA metadata merging currently implemented only for 1-direction metadata" ); /* Currently only 1-direction metadata is fed to merging */ + + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + + /* Compute energies */ + /* MASA energy is in the full 24 band resolution, whereas the ISM energy is already in the coding band resolution */ + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + energyMerged[sf][band] = eneBand + hMasa->data.energy_ism[sf][band]; + + /* Compute weights */ + energyTimesRatio1 = hMasa->data.energy_ism[sf][band] * hQMeta->q_direction[0].band_data[band].energy_ratio[sf]; + energyTimesRatio2 = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; + + /* Determine combined metadata based on the weights */ + if ( energyTimesRatio2 > energyTimesRatio1 ) + { + hQMeta->q_direction[0].band_data[band].azimuth[sf] = hMeta->directional_meta[0].azimuth[sf][band]; + hQMeta->q_direction[0].band_data[band].elevation[sf] = hMeta->directional_meta[0].elevation[sf][band]; + hQMeta->q_direction[0].band_data[band].energy_ratio[sf] = hMeta->directional_meta[0].energy_ratio[sf][band]; + if ( hQMeta->q_direction[0].coherence_band_data != NULL ) + { + hQMeta->q_direction[0].coherence_band_data[band].spread_coherence[sf] = (uint8_t) roundf( hMeta->directional_meta[0].spread_coherence[sf][band] * UINT8_MAX ); + } + if ( hQMeta->surcoh_band_data != NULL ) + { + hQMeta->surcoh_band_data[band].surround_coherence[sf] = (uint8_t) roundf( hMeta->common_meta.surround_coherence[sf][band] * UINT8_MAX ); + } + } + } + } + + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + hMasa->data.energy[sf][band] = energyMerged[sf][band]; + } + } +} + + +static void quantize_ratio_ism_vector( + float *ratio_ism, + int16_t *idx, + int16_t no_ism, + float masa_to_total_energy_ratio ) +{ + int16_t i, j, best_i, best_i2; + + float dist, div, tmp, dist2, best_dist; + int16_t part_idx_sum, max_sum_idx; + max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; + if ( no_ism > 1 ) + { + + if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) + { + distribute_evenly_ism( idx, max_sum_idx, no_ism ); + } + else + { + dist = 0.0f; + div = 1.0f / (float) ( max_sum_idx ); + + part_idx_sum = 0; + + for ( i = 0; i < no_ism; i++ ) + { + idx[i] = (int16_t) ( ( ratio_ism[i] ) * ( max_sum_idx ) ); + part_idx_sum += idx[i]; + + tmp = ( ratio_ism[i] - ( idx[i] * div ) ); + dist += ( tmp * tmp ); + } + best_dist = dist; + best_i2 = -1; + while ( part_idx_sum < max_sum_idx ) + { + best_i = -1; + /* check which index to increase by 1 for a possible improvement */ + + for ( i = 0; i < no_ism; i++ ) + { + idx[i]++; + dist2 = 0.0f; + + + for ( j = 0; j < no_ism; j++ ) + { + tmp = ( ratio_ism[i] - ( idx[i] * div ) ); + dist2 += ( tmp * tmp ); + } + + if ( dist2 < best_dist ) + { + best_i2 = best_i; + best_i = i; + best_dist = dist2; + } + idx[i]--; + } + if ( best_i > -1 ) + { + idx[best_i]++; + part_idx_sum++; + } + else + { + if ( best_i2 > -1 ) + { + idx[best_i2]++; + part_idx_sum++; + } + else + { + idx[no_ism - 1] += max_sum_idx - part_idx_sum; + part_idx_sum = max_sum_idx; + } + } + } + assert( sum_s( idx, no_ism ) == max_sum_idx ); + } + } + else + { + idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); + } + + + return; +} + + +static int16_t index_slice_enum( + const int16_t *ratio_ism_idx, + int16_t no_ism ) +{ + int16_t i; + int16_t x, index; + int16_t base; + + if ( no_ism == 2 ) + { + index = ratio_ism_idx[0]; + } + else + { + x = ratio_ism_idx[no_ism - 2]; + base = 10; + for ( i = no_ism - 3; i >= 0; i-- ) + { + x += ratio_ism_idx[i] * base; + base *= 10; + } + + index = 0; + i = 0; + while ( i <= x ) + { + if ( valid( i, 7, no_ism - 1 ) ) + { + index++; + } + i++; + } + index--; + } + + return index; +} + +static int16_t encode_ratio_ism_subframe( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t no_ism, + int16_t numCodingBands, + int16_t sf, + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + BSTR_ENC_HANDLE hMetaData, + const float *masa_to_total_energy_ratio ) +{ + int16_t b, i; + int16_t diff_idx[MAX_NUM_OBJECTS], index; + int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb, bits_pos0; + int16_t differential_subframe; + + nbits = 0; + nbits0 = 0; + nbits1 = 0; + + bits_pos0 = hMetaData->nb_bits_tot; + differential_subframe = 1; /* the differences are taken with respect to previous subframe */ + if ( sf == 0 ) /* first subframe */ + { + if ( no_ism == 2 ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = index_slice_enum( ratio_ism_idx[b], no_ism ); + + push_next_indice( hMetaData, index, 3 ); + nbits += 3; + } + } + } + else if ( no_ism == 3 ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = index_slice_enum( ratio_ism_idx[b], no_ism ); + /* there are 36 indices and part of them use 5 bits; 31 is special code to + signal that there are indices larger than 31, represented on extra 3 bits */ + if ( index < 31 ) + { + push_next_indice( hMetaData, index, 5 ); + nbits += 5; + } + else + { + push_next_indice( hMetaData, 31, 5 ); + nbits += 5; + + push_next_indice( hMetaData, index - 31, 3 ); + nbits += 3; + } + } + } + } + else + { + if ( no_ism == 4 ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = index_slice_enum( ratio_ism_idx[b], no_ism ); + push_next_indice( hMetaData, index, 7 ); + nbits += 7; + } + } + } + } +#ifdef DEBUGGING + assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); +#endif + } + else + { + nbits0 = 0; + nbits1 = 0; + for ( b = 0; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } + } + if ( nbits0 < nbits1 ) + { + GR_order = 0; + nbits = nbits0; + } + else + { + GR_order = 1; + nbits = nbits1; + } + + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } + for ( b = 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } + } + + if ( nbits0 < nbits1 ) + { + GR_order_sb = 0; + } + else + { + GR_order_sb = 1; + nbits0 = nbits1; + } + + if ( nbits0 < nbits ) + { + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; + } + nbits++; /* for GR_order */ + nbits++; /* for the prediction type */ + + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + /* write data */ + if ( differential_subframe ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + } + } + } + else + { + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + } + for ( b = 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + /* transform difference index into positive */ + for ( i = 0; i < no_ism - 1; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + diff_idx[i] = -2 * diff_idx[i]; + } + else + { + diff_idx[i] = 2 * diff_idx[i] - 1; + } + } + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + } + } + } +#ifdef DEBUGGING + assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); +#endif + } + return nbits; +} + + +static void ivas_encode_masaism_metadata( + MASA_ENCODER_HANDLE hMasa, + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[] /* i/o: ISM metadata handles */ +) +{ + int16_t sf, band; + uint8_t numCodingBands; + uint8_t numSf; + int16_t brange[2]; + float eneBand; + int16_t bin; + int16_t obj; + float priority[MAX_NUM_OBJECTS]; + int16_t bits_ism[MAX_NUM_OBJECTS]; + uint16_t idx_sph; + float theta_q, phi_q; + uint16_t index_theta, index_phi; + float ratio_ism[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + float step; + int16_t inv_step; + + numCodingBands = hMasa->config.numCodingBands; + numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; + + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hMasa->data.energy_ism[sf][band] == 0.0f ) + { + hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + } + else + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hMasa->data.energy_ism[sf][band] + EPSILON ); + } + } + } + + + encode_masa_to_total( hQMetaData, hMetaData ); + /* quantize ism_ratios */ + if ( hMasa->data.nchan_ism > 1 ) + { + + inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); + step = 1.0f / inv_step; + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + assert( ( hMasa->data.energy_ratio_ism[sf][band][obj] >= 0 ) && ( hMasa->data.energy_ratio_ism[sf][band][obj] <= 1 ) ); + ratio_ism[band][obj] = hMasa->data.energy_ratio_ism[sf][band][obj]; + } + /* Quantize power ratios */ + quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band] ); + /* reconstructed values */ + reconstruct_ism_ratios( ratio_ism_idx[band], hMasa->data.nchan_ism, step, hMasa->data.q_energy_ratio_ism[sf][band] ); + /* encode vector */ + } + + /* encode data for current subframe */ + encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf] ); + + /* calculate quantized ISM ratios */ + /* save previous subframe indexes */ + for ( band = 0; band < numCodingBands; band++ ) + { + mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], hMasa->data.nchan_ism ); + } + } + + set_f( priority, 0.0f, hMasa->data.nchan_ism ); + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + priority[obj] = max( priority[obj], ( hMasa->data.q_energy_ratio_ism[sf][band][obj] * hQMetaData->masa_to_total_energy_ratio[sf][band] ) ); + } + } + } + } + else + { + priority[0] = 1; + } + + /* decide parameters for ISM metadata quantization */ + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); + } + /* this is only the first version */ + /* quantize directions */ + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + } +} + + +void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], + float data_in_f2[][L_FRAME48k], + float data_out_f[][L_FRAME48k], + const int16_t input_frame, + const int16_t num_transport_channels ) +{ + int16_t i, j; + + for ( i = 0; i < num_transport_channels; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + data_out_f[i][j] = data_in_f1[i][j] + data_in_f2[i][j]; + } + } +} +#endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c new file mode 100644 index 0000000000..cd1f574346 --- /dev/null +++ b/lib_enc/ivas_omasa_enc.c @@ -0,0 +1,936 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include +#include +#include +#include "string.h" + +#include "ivas_cnst.h" +#include "ivas_prot.h" +#include "options.h" +#include "prot.h" +#include "ivas_rom_com.h" +#include "ivas_rom_enc.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "wmops.h" + +#ifdef MASA_AND_OBJECTS + +/*------------------------------------------------------------------------- + * Local function prototypes + *------------------------------------------------------------------------*/ + +static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); + +static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); + +static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, const int16_t num_transport_channels, const int16_t num_input_channels, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ); + +static void computeIntensityVector_enc( const int16_t *band_grouping, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ); + +static void computeReferencePower_omasa( const int16_t *band_grouping, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float *reference_power, const int16_t enc_param_start_band, const int16_t num_freq_bands ); + + +/*--------------------------------------------------------------------------* + * ivas_omasa_enc_open() + * + * + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_enc_open( + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ +) +{ + int16_t i, j; + float tmp_f; + OMASA_ENC_HANDLE hOMasa; + int16_t numAnalysisChannels; + int16_t input_frame; + ivas_error error; + + error = IVAS_ERR_OK; + + assert( st_ivas->hMasa != NULL && "MASA encoder handle is not present" ); + + if ( ( hOMasa = (OMASA_ENC_HANDLE) count_malloc( sizeof( OMASA_ENC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA encoder\n" ) ); + } + + numAnalysisChannels = st_ivas->nchan_ism; + + /* initialize delay compensation */ + hOMasa->num_samples_delay_comp = NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS ); + tmp_f = ( (float) hOMasa->num_samples_delay_comp ) / (float) ( NS2SA( st_ivas->hEncoderConfig->input_Fs, DIRAC_SLOT_NS ) ); + hOMasa->num_slots_delay_comp = (int16_t) ( tmp_f ); + + if ( tmp_f > hOMasa->num_slots_delay_comp ) + { + hOMasa->num_slots_delay_comp++; + hOMasa->offset_comp = -hOMasa->num_samples_delay_comp; + hOMasa->num_samples_delay_comp = hOMasa->num_slots_delay_comp * NS2SA( st_ivas->hEncoderConfig->input_Fs, DIRAC_SLOT_NS ); + hOMasa->offset_comp += hOMasa->num_samples_delay_comp; + } + else + { + hOMasa->offset_comp = 0; + } + + for ( i = 0; i < numAnalysisChannels; i++ ) + { + hOMasa->delay_buffer[i] = (float *) count_malloc( NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) * sizeof( float ) ); /* Todo Nokia: Return errors if alloc fails */ + set_zero( hOMasa->delay_buffer[i], NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) ); + } + + /* open/initialize CLDFB */ + hOMasa->num_Cldfb_instances = numAnalysisChannels; + for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + { + openCldfb( &( hOMasa->cldfbAnaEnc[i] ), CLDFB_ANALYSIS, st_ivas->hEncoderConfig->input_Fs, CLDFB_PROTOTYPE_5_00MS ); + } + + /* intensity 3-dim */ + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + hOMasa->direction_vector_m[i] = (float **) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float * ) ); + + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + hOMasa->direction_vector_m[i][j] = (float *) count_malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); + set_zero( hOMasa->direction_vector_m[i][j], MAXIMUM_OMASA_FREQ_BANDS ); + } + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + hOMasa->buffer_intensity_real[i][j] = (float *) count_malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); + set_zero( hOMasa->buffer_intensity_real[i][j], MAXIMUM_OMASA_FREQ_BANDS ); + } + } + + set_zero( hOMasa->buffer_energy, DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS ); + + for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) + { + set_f( hOMasa->prev_object_dm_gains[i], (float) sqrt( 0.5 ), MASA_MAX_TRANSPORT_CHANNELS ); + } + set_zero( hOMasa->broadband_energy_sm, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + set_zero( hOMasa->broadband_energy_prev, MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS ); + hOMasa->prev_selected_object = 0; + hOMasa->changing_object = 0; + + input_frame = (int16_t) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); + for ( i = 0; i < input_frame; i++ ) + { + hOMasa->interpolator[i] = ( (float) i ) / ( (float) input_frame ); + hOMasa->fade_out_gain[i] = ( 1.0f + cosf( ( (float) i ) / ( (float) input_frame ) * EVS_PI ) ) / 2.0f; + hOMasa->fade_in_gain[i] = 1.0f - hOMasa->fade_out_gain[i]; + } + + hOMasa->index_buffer_intensity = 0; + + st_ivas->hOMasa = hOMasa; + + return error; +} + + +/*--------------------------------------------------------------------------* + * ivas_omasa_enc_close() + * + O + *--------------------------------------------------------------------------*/ + +void ivas_omasa_enc_close( + OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ + const int16_t nchan_ism /* i : number of objects */ +) +{ + int16_t i, j; + + + for ( i = 0; i < nchan_ism; i++ ) + { + count_free( hOMasa->delay_buffer[i] ); + hOMasa->delay_buffer[i] = NULL; + } + + for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + { + deleteCldfb( &( hOMasa->cldfbAnaEnc[i] ) ); + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + count_free( hOMasa->direction_vector_m[i][j] ); + hOMasa->direction_vector_m[i][j] = NULL; + } + + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + count_free( hOMasa->buffer_intensity_real[i][j] ); + hOMasa->buffer_intensity_real[i][j] = NULL; + } + + count_free( hOMasa->direction_vector_m[i] ); + hOMasa->direction_vector_m[i] = NULL; + } + + count_free( hOMasa ); + + return; +} + + +/*--------------------------------------------------------------------------* + * ivas_omasa_set_config() + * + * Frame-by-frame config for oMASA + *--------------------------------------------------------------------------*/ + +void ivas_omasa_set_config( + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ + const int32_t input_Fs /* i : Input sample rate */ +) +{ + int16_t i, maxBin; + + /* Determine the number of bands */ + hOMasa->nbands = hMasa->config.numCodingBands; + hOMasa->nCodingBands = hMasa->config.numCodingBands; + + /* Determine the number of subframes */ + hOMasa->nSubframes = hMasa->config.joinedSubframes == TRUE ? 1 : MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Determine band grouping */ + if ( hOMasa->nbands == 24 ) + { + mvs2s( MASA_band_grouping_24, hOMasa->band_grouping, 24 + 1 ); + } + else + { + for ( i = 0; i < hOMasa->nbands + 1; i++ ) + { + hOMasa->band_grouping[i] = MASA_band_grouping_24[hMasa->data.band_mapping[i]]; + } + } + + maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + + for ( i = 1; i < hOMasa->nbands + 1; i++ ) + { + if ( hOMasa->band_grouping[i] >= maxBin ) + { + hOMasa->band_grouping[i] = maxBin; + hOMasa->nbands = i; + break; + } + } + + mvs2s( DirAC_block_grouping, hOMasa->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); + if ( hOMasa->nSubframes == 1 ) + { + hOMasa->block_grouping[1] = hOMasa->block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES]; + } +} + + +/*--------------------------------------------------------------------------* + * ivas_omasa_enc() + * + * + *--------------------------------------------------------------------------*/ + +void ivas_omasa_enc( + OMASA_ENC_HANDLE hOMasa, + IVAS_QMETADATA_HANDLE hQMeta, + MASA_ENCODER_HANDLE hMasa, + ISM_METADATA_HANDLE hIsmMeta[], + float data_in_f[][L_FRAME48k], + float data_out_f[][L_FRAME48k], + const int16_t input_frame, + const int16_t nchan_transport, + const int16_t nchan_ism, + const ISM_MODE ism_mode, + float data_separated_object[L_FRAME48k], + int16_t *idx_separated_object ) +{ + int16_t i, j; + + /* Analysis */ + if ( ism_mode == ISM_MODE_NONE ) + { + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float energyRatio[MASA_FREQUENCY_BANDS]; + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float surroundingCoherence[MASA_FREQUENCY_BANDS]; + int16_t nBands, nBlocks; + uint8_t fixedDistance = 0; + + nBands = hOMasa->nbands; + nBlocks = hOMasa->nSubframes; + + /* Estimate MASA parameters from the objects */ + ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, nchan_ism ); + + /* Set analyzed values to the QMeta struct */ + for ( i = 0; i < nBands; i++ ) + { + for ( j = 0; j < nBlocks; j++ ) + { + hQMeta->q_direction[0].band_data[i].azimuth[j] = azimuth_m_values[j][i]; + hQMeta->q_direction[0].band_data[i].elevation[j] = elevation_m_values[j][i]; + hQMeta->q_direction[0].band_data[i].energy_ratio[j] = energyRatio[i]; /* Only one value is transmitted for all subframes */ + hQMeta->q_direction[0].band_data[i].distance[j] = fixedDistance; + + if ( hQMeta->surcoh_band_data != NULL ) + { + hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (uint8_t) roundf( spreadCoherence[j][i] * UINT8_MAX ); + hQMeta->surcoh_band_data[i].surround_coherence[j] = (uint8_t) roundf( surroundingCoherence[i] * UINT8_MAX ); + } + } + } + + /* At lower sampling rates, set zeros for higher bands that were not analyzed */ + if ( nBands < hOMasa->nCodingBands ) + { + for ( i = nBands; i < hOMasa->nCodingBands; i++ ) + { + for ( j = 0; j < nBlocks; j++ ) + { + hQMeta->q_direction[0].band_data[i].azimuth[j] = 0.0f; + hQMeta->q_direction[0].band_data[i].elevation[j] = 0.0f; + hQMeta->q_direction[0].band_data[i].energy_ratio[j] = 0.0f; + hQMeta->q_direction[0].band_data[i].distance[j] = 0; + + if ( hQMeta->surcoh_band_data != NULL ) + { + hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = 0; + hQMeta->surcoh_band_data[i].surround_coherence[j] = 0; + } + } + } + } + } + else if ( ism_mode == ISM_MASA_MODE_PARAM ) + { + /* Estimate energies and ratios */ + ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); + } + else + { + float broadband_energy[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + int16_t loudest_object; + int16_t selected_object; + int16_t nchan_all_inp; + float alpha; + uint8_t fade_out_separate_object; + uint8_t fade_in_separate_object; + + /* Estimate broadband energies */ + nchan_all_inp = nchan_ism + nchan_transport; + set_zero( broadband_energy, nchan_all_inp ); + for ( i = 0; i < nchan_all_inp; i++ ) + { + for ( j = 0; j < input_frame; j++ ) + { + broadband_energy[i] += data_in_f[i][j] * data_in_f[i][j]; + } + } + + /* Temporal averaging */ + alpha = 0.8f; + for ( i = 0; i < nchan_all_inp; i++ ) + { + hOMasa->broadband_energy_sm[i] = ( 1.0f - alpha ) * broadband_energy[i] + alpha * hOMasa->broadband_energy_sm[i]; + } + + /* Determine loudest object */ + loudest_object = 0; + for ( i = 1; i < nchan_ism; i++ ) + { + if ( hOMasa->broadband_energy_sm[i] > hOMasa->broadband_energy_sm[loudest_object] ) + { + loudest_object = i; + } + } + + /* Determine object to separate */ + selected_object = hOMasa->prev_selected_object; + fade_out_separate_object = 0; + fade_in_separate_object = 0; + if ( hOMasa->changing_object ) + { + hOMasa->changing_object = 0; + selected_object = loudest_object; + fade_in_separate_object = 1; + } + else + { + if ( loudest_object != hOMasa->prev_selected_object ) + { + float selected_ene; + float total_ene; + float selected_ratio; + float adaptive_threshold_dB; + float ratio_objects_dB; + float hardswitch_threshold = 0.25f; + + /* Compute the energy of the current and the previous selected object in the current and the previous frame */ + selected_ene = broadband_energy[loudest_object] + broadband_energy[hOMasa->prev_selected_object] + hOMasa->broadband_energy_prev[loudest_object] + hOMasa->broadband_energy_prev[hOMasa->prev_selected_object]; + + /* Compute the energy of all objects and MASA channels in the current and the previous frame */ + total_ene = 0.0f; + for ( i = 0; i < nchan_all_inp; i++ ) + { + total_ene += broadband_energy[i] + hOMasa->broadband_energy_prev[i]; + } + + /* Compute the ratio */ + selected_ratio = selected_ene / ( total_ene + EPSILON ); + + adaptive_threshold_dB = selected_ratio * 9.0f + 1.0f; /* selected ratio = 0 -> 1 dB, selected ratio = 1 -> 10 dB */ + ratio_objects_dB = 10.0f * log10f( hOMasa->broadband_energy_sm[loudest_object] / ( hOMasa->broadband_energy_sm[hOMasa->prev_selected_object] + EPSILON ) ); + + /* Adaptively determine whether to change the separated object. If they are quiet compared to the total energy, change easier, as other signals mask the change. */ + if ( ratio_objects_dB > adaptive_threshold_dB ) + { + if ( selected_ratio < hardswitch_threshold ) /* If low level compared to all audio channels, perform hardswitch */ + { + selected_object = loudest_object; + } + else /* If high level compared to all audio channels, perform switch via fade out fade in */ + { + hOMasa->changing_object = 1; + fade_out_separate_object = 1; + } + } + } + } + + /* Set values for next frame */ + for ( i = 0; i < nchan_all_inp; i++ ) + { + hOMasa->broadband_energy_prev[i] = broadband_energy[i]; + } + hOMasa->prev_selected_object = selected_object; + + /* Separate the selected object */ + *idx_separated_object = selected_object; + mvr2r( data_in_f[selected_object], data_separated_object, input_frame ); + if ( fade_out_separate_object ) + { + v_mult( data_separated_object, hOMasa->fade_out_gain, data_separated_object, input_frame ); + v_mult( data_in_f[selected_object], hOMasa->fade_in_gain, data_in_f[selected_object], input_frame ); + } + else if ( fade_in_separate_object ) + { + v_mult( data_separated_object, hOMasa->fade_in_gain, data_separated_object, input_frame ); + v_mult( data_in_f[selected_object], hOMasa->fade_out_gain, data_in_f[selected_object], input_frame ); + } + else + { + set_zero( data_in_f[selected_object], input_frame ); + } + + /* Estimate energies and ratios */ + ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); + } + + + /* Downmix */ + ivas_omasa_dmx( data_in_f, data_out_f, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains, hOMasa->interpolator ); + + return; +} + + +/*--------------------------------------------------------------------------* + * Local functions + *--------------------------------------------------------------------------*/ + +/* Estimate MASA parameters from the objects */ +static void ivas_omasa_param_est_enc( + OMASA_ENC_HANDLE hOMasa, + MASA_ENCODER_HANDLE hMasa, + ISM_METADATA_HANDLE hIsmMeta[], + float data_f[][L_FRAME48k], + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float energyRatio[MASA_FREQUENCY_BANDS], + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float surroundingCoherence[MASA_FREQUENCY_BANDS], + const int16_t input_frame, + const int16_t nchan_inp ) +{ + float reference_power[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + int16_t ts, i, j, d, k; + int16_t num_freq_bins, num_freq_bands, index; + float dir_v[DIRAC_NUM_DIMS]; + int16_t l_ts; + float Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Chnl_ImagBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Foa_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Foa_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float diffuseness_vector[MASA_FREQUENCY_BANDS]; + float diffuseness_m[MASA_FREQUENCY_BANDS]; + int16_t band_m_idx, block_m_idx; + float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; + float norm_tmp; + int16_t mrange[2], brange[2]; + + num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; + num_freq_bands = hOMasa->nbands; + l_ts = input_frame / CLDFB_NO_COL_MAX; + + + /* Need to initialize renormalization_factors, and variables to be normalized */ + set_zero( renormalization_factor_diff, hOMasa->nbands ); + set_zero( diffuseness_m, hOMasa->nbands ); + + /* Copy current frame to memory for delay compensation */ + for ( i = 0; i < nchan_inp; i++ ) + { + mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); + } + + /* Compute ISM to FOA matrices */ + for ( i = 0; i < nchan_inp; i++ ) + { + hOMasa->chnlToFoaMtx[0][i] = 1.0f; + hOMasa->chnlToFoaMtx[1][i] = sinf( ( hIsmMeta[i]->azimuth / 180.0f * EVS_PI ) ) * cosf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + hOMasa->chnlToFoaMtx[2][i] = sinf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + hOMasa->chnlToFoaMtx[3][i] = cosf( ( hIsmMeta[i]->azimuth / 180.0f * EVS_PI ) ) * cosf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + } + + /* do processing over all CLDFB time slots */ + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + mrange[0] = hOMasa->block_grouping[block_m_idx]; + mrange[1] = hOMasa->block_grouping[block_m_idx + 1]; + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = 0.0f; + hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = 0.0f; + hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = 0.0f; + } + + set_zero( hMasa->data.energy_ism[block_m_idx], num_freq_bands ); + + for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + for ( i = 0; i < nchan_inp; i++ ) + { + if ( ts < hOMasa->num_slots_delay_comp ) + { + cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); + } + else + { + cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); + } + } + + /* Compute energy */ + for ( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = hOMasa->band_grouping[i]; + brange[1] = hOMasa->band_grouping[i + 1]; + for ( j = brange[0]; j < brange[1]; j++ ) + { + for ( k = 0; k < nchan_inp; k++ ) + { + hMasa->data.energy_ism[block_m_idx][i] += Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; + } + } + } + + /* Compute FOA */ + /* W */ + mvr2r( Chnl_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); + mvr2r( Chnl_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); + for ( i = 1; i < nchan_inp; i++ ) + { + v_add( Chnl_RealBuffer[i], Foa_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); + v_add( Chnl_ImagBuffer[i], Foa_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); + } + + /* Y */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_RealBuffer[1], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_ImagBuffer[1], num_freq_bins ); + for ( i = 1; i < nchan_inp; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_RealBuffer[1], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_ImagBuffer[1], num_freq_bins ); + } + + /* Z */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_RealBuffer[2], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_ImagBuffer[2], num_freq_bins ); + for ( i = 1; i < nchan_inp; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_RealBuffer[2], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_ImagBuffer[2], num_freq_bins ); + } + + /* X */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_RealBuffer[3], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_ImagBuffer[3], num_freq_bins ); + for ( i = 1; i < nchan_inp; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_RealBuffer[3], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_ImagBuffer[3], num_freq_bins ); + } + + /* Direction estimation */ + computeIntensityVector_enc( hOMasa->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, num_freq_bands, intensity_real ); + computeDirectionVectors( intensity_real[0], intensity_real[1], intensity_real[2], 0, num_freq_bands, direction_vector[0], direction_vector[1], direction_vector[2] ); + + /* Power estimation for diffuseness */ + computeReferencePower_omasa( hOMasa->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, reference_power[ts], 0, num_freq_bands ); + + /* Fill buffers of length "averaging_length" time slots for intensity and energy */ + hOMasa->index_buffer_intensity = ( hOMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ + index = hOMasa->index_buffer_intensity; + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + /* only real part needed */ + mvr2r( intensity_real[i], &( hOMasa->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + } + mvr2r( reference_power[ts], &( hOMasa->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + + computeDiffuseness( hOMasa->buffer_intensity_real, hOMasa->buffer_energy, num_freq_bands, diffuseness_vector ); + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); + + hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; + hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; + hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; + + diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; + renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + } + } + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + dir_v[d] = hOMasa->direction_vector_m[d][block_m_idx][band_m_idx]; + } + ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); + } + + /* Set coherences to zero, as this mode is used at lowest bit rates where the coherences are not transmitted */ + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + spreadCoherence[block_m_idx][band_m_idx] = 0.0f; + surroundingCoherence[band_m_idx] = 0.0f; + } + } + + /* Determine energy ratios */ + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + { + diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + } + else + { + diffuseness_m[band_m_idx] = 0.0f; + } + + energyRatio[band_m_idx] = 1.0f - diffuseness_m[band_m_idx]; + } + + /* Update memory */ + for ( i = 0; i < nchan_inp; i++ ) + { + mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); + } + + return; +} + + +/* Estimate energies and ratios */ +static void ivas_omasa_energy_and_ratio_est( + OMASA_ENC_HANDLE hOMasa, + MASA_ENCODER_HANDLE hMasa, + float data_f[][L_FRAME48k], + const int16_t input_frame, + const int16_t nchan_inp ) +{ + int16_t ts, i, j, k; + int16_t num_freq_bands; + int16_t l_ts; + float Chnl_RealBuffer[MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + float Chnl_ImagBuffer[MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + int16_t block_m_idx; + int16_t mrange[2], brange[2]; + float tftile_energy; + float ism_ratio_sum; + + num_freq_bands = hOMasa->nbands; + l_ts = input_frame / CLDFB_NO_COL_MAX; + + + /* Copy current frame to memory for delay compensation */ + for ( i = 0; i < nchan_inp; i++ ) + { + mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); + } + + /* do processing over all CLDFB time slots */ + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + mrange[0] = hOMasa->block_grouping[block_m_idx]; + mrange[1] = hOMasa->block_grouping[block_m_idx + 1]; + + /* Reset variable */ + for ( i = 0; i < hOMasa->nbands; i++ ) + { + set_zero( hMasa->data.energy_ratio_ism[block_m_idx][i], nchan_inp ); + } + set_zero( hMasa->data.energy_ism[block_m_idx], num_freq_bands ); + + /* Compute CLDFB */ + for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + for ( i = 0; i < nchan_inp; i++ ) + { + if ( ts < hOMasa->num_slots_delay_comp ) + { + cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); + } + else + { + cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); + } + } + + /* Compute energy */ + for ( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = hOMasa->band_grouping[i]; + brange[1] = hOMasa->band_grouping[i + 1]; + for ( j = brange[0]; j < brange[1]; j++ ) + { + for ( k = 0; k < nchan_inp; k++ ) + { + tftile_energy = Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; + hMasa->data.energy_ism[block_m_idx][i] += tftile_energy; + hMasa->data.energy_ratio_ism[block_m_idx][i][k] += tftile_energy; + } + } + } + } + + /* Compute ISM energy ratios */ + for ( i = 0; i < num_freq_bands; i++ ) + { + ism_ratio_sum = 0.0f; + for ( j = 0; j < nchan_inp; j++ ) + { + hMasa->data.energy_ratio_ism[block_m_idx][i][j] /= ( hMasa->data.energy_ism[block_m_idx][i] + EPSILON ); + ism_ratio_sum += hMasa->data.energy_ratio_ism[block_m_idx][i][j]; + } + + if ( ism_ratio_sum == 0.0f ) + { + float temp_ism_ratio = 1.0f / ( (float) nchan_inp ); + for ( j = 0; j < nchan_inp; j++ ) + { + hMasa->data.energy_ratio_ism[block_m_idx][i][j] = temp_ism_ratio; + } + } + } + hMasa->data.nchan_ism = nchan_inp; + } + + /* Update memory */ + for ( i = 0; i < nchan_inp; i++ ) + { + mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); + } + + return; +} + + +/* Compute downmix */ +static void ivas_omasa_dmx( + float data_in_f[][L_FRAME48k], + float data_out_f[][L_FRAME48k], + const int16_t input_frame, + const int16_t num_transport_channels, + const int16_t num_input_channels, + ISM_METADATA_HANDLE hIsmMeta[], + float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], + const float interpolator[L_FRAME48k] ) +{ + int16_t i, j, k; + float azimuth, elevation; + float gains[MASA_MAX_TRANSPORT_CHANNELS]; + float g1, g2; + + if ( num_transport_channels == 2 ) + { + for ( i = 0; i < num_transport_channels; i++ ) + { + set_zero( data_out_f[i], input_frame ); + } + + for ( i = 0; i < num_input_channels; i++ ) + { + azimuth = hIsmMeta[i]->azimuth; + elevation = hIsmMeta[i]->elevation; + + ivas_get_stereo_panning_gains( azimuth, elevation, gains ); + + /* Downmix using the panning gains */ + for ( j = 0; j < num_transport_channels; j++ ) + { + if ( fabsf( gains[j] ) > 0.0 || fabsf( prev_gains[i][j] ) > 0.0 ) + { + for ( k = 0; k < input_frame; k++ ) + { + g1 = interpolator[k]; + g2 = 1.0f - g1; + data_out_f[j][k] += ( g1 * gains[j] + g2 * prev_gains[i][j] ) * data_in_f[i][k]; + } + } + prev_gains[i][j] = gains[j]; + } + } + } + else if ( num_transport_channels == 1 ) + { + for ( i = 0; i < input_frame; i++ ) + { + data_out_f[0][i] = 0.0f; + for ( j = 0; j < num_input_channels; j++ ) + { + data_out_f[0][i] += data_in_f[j][i]; + } + } + } +} + + +static void computeIntensityVector_enc( + const int16_t *band_grouping, + float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], + const int16_t num_frequency_bands, + float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ) +{ + /* Reminder + * X = a + ib; Y = c + id + * X*Y = ac - bd + i(ad +bc) + */ + int16_t i, j; + float real, img; + int16_t brange[2]; + + for ( i = 0; i < num_frequency_bands; i++ ) + { + brange[0] = band_grouping[i]; + brange[1] = band_grouping[i + 1]; + + intensity_real[0][i] = 0; + intensity_real[1][i] = 0; + intensity_real[2][i] = 0; + + for ( j = brange[0]; j < brange[1]; j++ ) + { + real = Cldfb_RealBuffer[0][j]; + img = Cldfb_ImagBuffer[0][j]; + intensity_real[0][i] += Cldfb_RealBuffer[3][j] * real + Cldfb_ImagBuffer[3][j] * img; /* Intensity is XYZ order, audio is WYZX order. */ + intensity_real[1][i] += Cldfb_RealBuffer[1][j] * real + Cldfb_ImagBuffer[1][j] * img; + intensity_real[2][i] += Cldfb_RealBuffer[2][j] * real + Cldfb_ImagBuffer[2][j] * img; + } + } + + return; +} + +static void computeReferencePower_omasa( + const int16_t *band_grouping, /* i : Band grouping for estimation */ + float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ + float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ + float *reference_power, /* o : Estimated power */ + const int16_t enc_param_start_band, /* i : first band to process */ + const int16_t num_freq_bands /* i : Number of frequency bands */ +) +{ + int16_t brange[2]; + int16_t ch_idx, i, j; + + for ( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = band_grouping[i + enc_param_start_band]; + brange[1] = band_grouping[i + enc_param_start_band + 1]; + reference_power[i] = 0; + + for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) + { + /* abs()^2 */ + for ( j = brange[0]; j < brange[1]; j++ ) + { + reference_power[i] += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); + } + } + } + + v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); + + return; +} + +#endif /* MASA_AND_OBJECTS */ diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index c9f0bd70ff..1c9eef86e8 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -64,9 +64,15 @@ static int16_t ivas_qmetadata_entropy_encode_dir( BSTR_ENC_HANDLE hMetaData, IVA static int16_t ivas_qmetadata_raw_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, const int16_t nbands, const int16_t start_band ); -static int16_t ivas_qmetadata_encode_extended_gr_length( const uint16_t value, const uint16_t alphabet_size, const int16_t gr_param ); +#ifndef MASA_AND_OBJECTS +static +#endif + int16_t + ivas_qmetadata_encode_extended_gr_length( const uint16_t value, const uint16_t alphabet_size, const int16_t gr_param ); +#ifndef MASA_AND_OBJECTS static void ivas_qmetadata_encode_extended_gr( BSTR_ENC_HANDLE hMetaData, const uint16_t value, const uint16_t alphabet_size, const int16_t gr_param ); +#endif static int16_t ivas_qmetadata_get_optimal_gr_param( uint16_t *unsigned_data, const int16_t count, const int16_t gr_param_count, int16_t *opt_gr_size ); @@ -118,6 +124,10 @@ static void transform_azimuth_dir2( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *d static int16_t calc_var_azi( const IVAS_QDIRECTION *q_direction, const int16_t diffuseness_index_max_ec_frame, const float avg_azimuth, float *avg_azimuth_out ); +#ifdef MASA_AND_OBJECTS +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line ); +#endif + /*-----------------------------------------------------------------------* * ivas_qmetadata_enc_encode() * @@ -2408,11 +2418,14 @@ static int16_t ivas_qmetadata_get_optimal_gr_param( * * *------------------------------------------------------------------------*/ - -static int16_t ivas_qmetadata_encode_extended_gr_length( - const uint16_t value, - const uint16_t alphabet_size, - const int16_t gr_param ) +#ifndef MASA_AND_OBJECTS +static +#endif + int16_t + ivas_qmetadata_encode_extended_gr_length( + const uint16_t value, + const uint16_t alphabet_size, + const int16_t gr_param ) { uint16_t msb_alphabet_size; int16_t bits; @@ -2551,12 +2564,15 @@ static int16_t ivas_qmetadata_reorder_azimuth_index( * * *------------------------------------------------------------------------*/ - -static void ivas_qmetadata_encode_extended_gr( - BSTR_ENC_HANDLE hMetaData, - const uint16_t value, - const uint16_t alphabet_size, - const int16_t gr_param ) +#ifndef MASA_AND_OBJECTS +static +#endif + void + ivas_qmetadata_encode_extended_gr( + BSTR_ENC_HANDLE hMetaData, + const uint16_t value, + const uint16_t alphabet_size, + const int16_t gr_param ) { uint16_t msb_alphabet_size; uint16_t msb, lsb, cnt; @@ -4905,3 +4921,271 @@ static float direction_distance( return d / (float) ( dim1 * dim2 ); } #endif +#ifdef MASA_AND_OBJECTS +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line ) +{ + int16_t nb_bits = 0, bits_pos; + int16_t last_non_null; + uint16_t nb_GR_min, i_min, nb_GR; + int16_t i, j; + + bits_pos = hMetaData->nb_bits_tot; + /* write DCT 0 component */ + /* write sign only if not the very first DCT coeff */ + if ( first_line == 0 ) + { + if ( q_idx[0] > 0 ) + { + push_next_indice( hMetaData, 1, 1 ); + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); /* Todo : define constant */ + } + else + { + push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, -q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + } + nb_bits += BITS_MASA2TOTTAL_DCT0 + 1; + } + else + { + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); + nb_bits += BITS_MASA2TOTTAL_DCT0; + } + + + /* find last non-null position */ + last_non_null = -1; + if ( q_idx[0] != 0 ) + { + last_non_null = len_stream - 1; + while ( ( q_idx[last_non_null] == 0 ) && ( last_non_null >= 0 ) ) + { + last_non_null--; + } + } + if ( last_non_null == -1 ) + { + /* all values are zero; no need to send anything else */ + assert( q_idx[0] == 0 ); + } + else + { + assert( q_idx[0] != 0 ); + /*last_non_null = max(4, last_non_null); */ + + /* write index of last non null index on log2(len_stream) bits */ + j = (int16_t) ceilf( log2f( (float) ( len_stream ) ) ); + push_next_indice( hMetaData, last_non_null, j ); + nb_bits += j; + if ( last_non_null > 0 ) + { + /* find optimum length of the part encoded with GR2 */ + nb_GR_min = 1000; + i_min = 0; + for ( i = 1; i <= last_non_null; i++ ) + { + nb_GR = 0; + for ( j = 1; j <= i; j++ ) + { + nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 2 ); + } + for ( j = i + 1; j <= last_non_null; j++ ) + { + nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ); + } + if ( nb_GR < nb_GR_min ) + { + nb_GR_min = nb_GR; + i_min = i; + } + } + + assert( nb_GR_min < 1000 ); + + + /* write number of indexes encoded with GR2 */ + j = (int16_t) ceilf( log2f( (float) ( last_non_null + 1 ) ) ); + assert( i_min < ( 1 << j ) ); + push_next_indice( hMetaData, i_min, j ); + nb_bits += j; + + /* write GR data */ + for ( i = 1; i <= i_min; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, 2 ); + } + for ( i = i_min + 1; i <= last_non_null; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, 0 ); + } + nb_bits += nb_GR_min; + } + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + } + return nb_bits; +} + +void encode_masa_to_total( + IVAS_QMETADATA_HANDLE hQMetaData, + BSTR_ENC_HANDLE hMetaData ) +{ + int16_t i, j, k; + float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + + + float step = 0.1f; + int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + float dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + int16_t nbands; + + int16_t bits_pos, nb_bits; + int16_t n_streams, len_stream; + + nbands = hQMetaData->numCodingBands; +#ifdef DEBUG_MODE_QMETADATA + static FILE *pF = NULL; + static FILE *pF_ratio = NULL; + + if ( pF == NULL ) + pF = fopen( "./res/qmetadata_ism_qidx__enc.txt", "w" ); + if ( pF_ratio == NULL ) + pF_ratio = fopen( "./res/qmetadata_masa2tot_enc.txt", "w" ); + +#endif + +#ifdef DEBUGGING + assert( ( nbands == 5 || nbands == 8 ) && "Number of subbands in parametric MASA_ISM should be 5 or 8 " ); +#endif + bits_pos = hMetaData->nb_bits_tot; + k = 0; + for ( i = 0; i < nbands; i++ ) + { + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + data[k] = hQMetaData->masa_to_total_energy_ratio[j][i]; + k++; + } + } + + + /* DCT2 transform */ + if ( nbands == 5 ) + { + matrix_product( dct5, nbands, nbands, 0, data, MAX_PARAM_SPATIAL_SUBFRAMES, nbands, 1, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 1, dct_data ); + } + else + { + matrix_product( dct8, nbands, nbands, 0, data, MAX_PARAM_SPATIAL_SUBFRAMES, nbands, 1, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 1, dct_data ); + } + + /* Setup coding parameters */ + if ( nbands == 5 ) + { + n_streams = 1; + len_stream = nbands * MAX_PARAM_SPATIAL_SUBFRAMES; + } + else + { + n_streams = MAX_PARAM_SPATIAL_SUBFRAMES; + len_stream = 8; + } + + for ( k = 0; k < n_streams; k++ ) + { + j = k * len_stream; + /* quantize with fixed common step */ + q_idx[j] = (int16_t) rintf( dct_data[j] / step ); + + if ( q_idx[j] > ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ) ) /* limit DCT0 to BITS_MASA2TOTTAL_DCT0 bit representation */ + { + q_idx[j] = ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ); + } + q_dct_data[j] = step * q_idx[j]; + if ( q_idx[j] == 0 ) + { + set_s( &q_idx[j], 0, len_stream ); + set_zero( &q_dct_data[j], len_stream ); + } + else + { + for ( i = 1; i < len_stream; i++ ) + { + q_idx[j + i] = (int16_t) rintf( dct_data[j + i] / step ); + q_dct_data[j + i] = step * q_idx[j + i]; + if ( q_idx[j + i] <= 0 ) + { + q_idx[j + i] = -2 * q_idx[j + i]; + } + else + { + q_idx[j + i] = 2 * q_idx[j + i] - 1; + } + } + } + } + + + /* reconstruct masa2total */ + /* inverse DCT2 transform */ + if ( nbands == 5 ) + { + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); /* reuse of variable*/ + } + else + { + assert( nbands == 8 ); + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); + } + k = 0; + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + hQMetaData->masa_to_total_energy_ratio[i][j] = max( 0.0f, q_dct_data[k] ); + hQMetaData->masa_to_total_energy_ratio[i][j] = min( 1.0f, hQMetaData->masa_to_total_energy_ratio[i][j] ); + k++; + } + } + + /* write data */ + nb_bits = 0; + for ( i = 0; i < n_streams; i++ ) + { + nb_bits += write_stream_dct_coeffs_omasa( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ) ); + } + + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); + +#ifdef DEBUG_MODE_QMETADATA + { + + fprintf( pF, "frame %d: ", frame ); + fprintf( pF_ratio, "frame %d: ", frame ); + + + /* direction_distance( elevation_orig, azimuth_orig, q_direction, nbands, nblocks, mat_dist );*/ + for ( i = 0; i < nbands; i++ ) + { + for ( j = 0; j < 4; j++ ) + { + fprintf( pF_ratio, " %5.2f ", hQMetaData->masa_to_total_energy_ratio[j][i] ); + } + } + for ( i = 0; i < 20; i++ ) + { + fprintf( pF, " %4d ", q_idx[i] ); + } + fprintf( pF, "\n" ); + fprintf( pF_ratio, "\n" ); + } +#endif + + return; +} +#endif diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index ba0c27ddd1..e33bdbb078 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -144,7 +144,11 @@ ivas_error ivas_sce_enc( /* set "bits_frame_nominal" */ if ( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL ) { +#ifdef MASA_AND_OBJECTS + if ( ( ( st_ivas->mc_mode == MC_MODE_MCMASA ) && ( st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) ) || ( st_ivas->ism_mode >= ISM_MASA_MODE_ONE_OBJ ) ) +#else if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) +#endif { st->bits_frame_nominal = (int16_t) ( hSCE->element_brate / FRAMES_PER_SEC ); } @@ -330,6 +334,12 @@ ivas_error create_sce_enc( } copy_encoder_config( st_ivas, st, 1 ); +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ism_mode >= ISM_MASA_MODE_PARAM ) + { + st->element_mode = IVAS_SCE; /* To do: Nokia check as this is not optimal and verify if it influences other SCE modes */ + } +#endif st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0644fcd918..a76ddf692a 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -713,6 +713,13 @@ typedef struct ivas_param_mc_enc_data_structure typedef struct ivas_masa_encoder_data_struct { float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#ifdef MASA_AND_OBJECTS + float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: Make an own MASAISM struct for these, and reserve it only for OMASA */ + float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + int16_t nchan_ism; + +#endif int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; float *delay_buffer[MASA_MAX_TRANSPORT_CHANNELS]; @@ -796,6 +803,52 @@ typedef struct ivas_mcmasa_enc_data_structure } MCMASA_ENC_DATA, *MCMASA_ENC_HANDLE; +#ifdef MASA_AND_OBJECTS +/*----------------------------------------------------------------------------------* + * Object MASA (OMASA) encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_omasa_enc_data_structure +{ + int16_t nbands; + int16_t nCodingBands; + int16_t nSubframes; + + /* delay compensation */ + float *delay_buffer[MAX_NUM_OBJECTS]; /* Delay buffer for parameter estimation */ + int16_t num_samples_delay_comp; + int16_t num_slots_delay_comp; + int16_t offset_comp; + + /* CLDFB analysis */ + int16_t num_Cldfb_instances; + HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; + + /* DirAC parameter estimation */ + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; + int16_t block_grouping[5]; + + /* diffuseness */ + int16_t index_buffer_intensity; + float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; + + float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; + + float interpolator[L_FRAME48k]; + + float prev_object_dm_gains[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; + float broadband_energy_sm[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + float broadband_energy_prev[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + int16_t prev_selected_object; + uint8_t changing_object; + float fade_out_gain[L_FRAME48k]; + float fade_in_gain[L_FRAME48k]; + +} OMASA_ENC_DATA, *OMASA_ENC_HANDLE; +#endif + /*----------------------------------------------------------------------------------* * Stereo CNG handle @@ -1027,6 +1080,9 @@ typedef struct /* high-level encoder parameters */ int16_t nchan_transport; /* number of transport channels */ +#ifdef MASA_AND_OBJECTS + int16_t nchan_ism; +#endif int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ int16_t codec_mode; /* Mode1 or Mode2 of core codec */ int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ @@ -1048,6 +1104,9 @@ typedef struct MCT_ENC_HANDLE hMCT; /* MCT handle */ PARAM_MC_ENC_HANDLE hParamMC; /* Parametric MC handle */ MCMASA_ENC_HANDLE hMcMasa; /* Multi-channel MASA data handle */ +#ifdef MASA_AND_OBJECTS + OMASA_ENC_HANDLE hOMasa; /* Object MASA data handle */ +#endif LFE_ENC_HANDLE hLFE; /* LFE data handle */ ISM_MODE ism_mode; /* ISM format mode */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index b3f8dc478d..c3b526f1b2 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -351,6 +351,64 @@ ivas_error IVAS_ENC_ConfigureForStereo( return error; } +#ifdef MASA_AND_OBJECTS +/*---------------------------------------------------------------------* + * IVAS_ENC_ConfigureForMASAObjects() + * + * Configure and initialize the combined MASA and ISM encoder. + *---------------------------------------------------------------------*/ + +ivas_error IVAS_ENC_ConfigureForMASAObjects( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const int32_t inputFs, /* i : input sampling frequency */ + const int32_t bitrate, /* i : requested bitrate of the ouput bitstream */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const uint16_t numObjects, /* i : number of objects to be encoded */ + const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ +) +{ + Encoder_Struct *st_ivas; + ivas_error error; + + if ( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( numObjects > MAX_NUM_OBJECTS ) + { + return IVAS_ERR_TOO_MANY_INPUTS; + } + st_ivas = hIvasEnc->st_ivas; + switch ( masaVariant ) + { + case IVAS_ENC_MASA_1CH: + st_ivas->hEncoderConfig->nchan_inp = 1 + numObjects; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + break; + case IVAS_ENC_MASA_2CH: + st_ivas->hEncoderConfig->nchan_inp = 2 + numObjects; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + break; + default: + return IVAS_ERR_INVALID_MASA_CONFIG; + break; + } + + st_ivas = hIvasEnc->st_ivas; + + /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ + st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp - numObjects; + + + st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT; + + st_ivas->nchan_ism = numObjects; + + return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); +} +#endif /*---------------------------------------------------------------------* * IVAS_ENC_ConfigureForObjects() @@ -418,8 +476,11 @@ ivas_error IVAS_ENC_FeedObjectMetadata( { return IVAS_ERR_NOT_CONFIGURED; } - +#ifdef MASA_AND_OBJECTS + if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != ISM_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) +#else if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != ISM_FORMAT ) +#endif { return IVAS_ERR_METADATA_NOT_EXPECTED; } @@ -574,8 +635,11 @@ ivas_error IVAS_ENC_FeedMasaMetadata( { return IVAS_ERR_NOT_CONFIGURED; } - +#ifdef MASA_AND_OBJECTS + if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) +#else if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT ) +#endif { return IVAS_ERR_METADATA_NOT_EXPECTED; } @@ -662,7 +726,9 @@ static ivas_error configureEncoder( Encoder_Struct *st_ivas; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; - +#ifdef MASA_AND_OBJECTS + int32_t cpe_brate; +#endif error = IVAS_ERR_OK; st_ivas = hIvasEnc->st_ivas; @@ -803,6 +869,24 @@ static ivas_error configureEncoder( } } } + +#ifdef MASA_AND_OBJECTS + else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_ism ); + + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_ism ); + + /*adapt element_mode according to the bit-rate*/ + if ( hEncoderConfig->element_mode_init != IVAS_SCE ) + { + if ( cpe_brate >= IVAS_48k ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + } + } +#endif } else /* EVS mono */ { @@ -1576,7 +1660,12 @@ static ivas_error printConfigInfo_enc( fprintf( stdout, "IVAS mode: Multi-Channel 7.1+4\n" ); } } - +#ifdef MASA_AND_OBJECTS + else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + fprintf( stdout, "IVAS format: MASA and objects format\n" ); + } +#endif /*-----------------------------------------------------------------* * Print CNG update interval, if DTX is activated *-----------------------------------------------------------------*/ diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index dbcb21c989..d66e58e1dd 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -52,6 +52,9 @@ typedef enum _IVAS_ENC_INPUT_FORMAT IVAS_ENC_INPUT_SBA, IVAS_ENC_INPUT_MASA, IVAS_ENC_INPUT_MC, +#ifdef MASA_AND_OBJECTS + IVAS_ENC_INPUT_MASA_ISM, +#endif IVAS_DEC_INPUT_UNKNOWN = 0xffff } IVAS_ENC_INPUT_FORMAT; @@ -96,6 +99,14 @@ typedef enum _IVAS_ENC_MASA_VARIANT IVAS_ENC_MASA_UNDEFINED = 0xffff } IVAS_ENC_MASA_VARIANT; +#ifdef MASA_AND_OBJECTS +typedef enum _IVAS_ENC_COMBINED_FORMAT +{ + IVAS_ENC_MASA_ISM = 1, + IVAS_ENC_COMBINED_UNDEFINED = 0xffff +} IVAS_ENC_COMBINED_FORMAT; +#endif + #ifdef DEBUGGING typedef enum _IVAS_ENC_STEREO_MODE { @@ -185,6 +196,19 @@ ivas_error IVAS_ENC_ConfigureForObjects( const uint16_t numObjects /* i : number of objects to be encoded */ ); +#ifdef MASA_AND_OBJECTS +/*! r: encoder error code */ +ivas_error IVAS_ENC_ConfigureForMASAObjects( + IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ + const int32_t inputFs, /* i : input sampling frequency */ + const int32_t bitrate, /* i : requested bitrate of the ouput bitstream */ + const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ + const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ + const uint16_t numObjects, /* i : number of objects to be encoded */ + const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ +); +#endif + /*! r: error code */ ivas_error IVAS_ENC_ConfigureForAmbisonics( IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */ diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index e5407abff4..a69b72f9ce 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -330,8 +330,13 @@ void ivas_renderer_select( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport <= 2 ) ) +#else else if ( st_ivas->ivas_format == MASA_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport <= 2 ) ) +#endif { + *internal_config = output_config; if ( output_config == AUDIO_CONFIG_BINAURAL ) { @@ -565,6 +570,21 @@ void ivas_renderer_select( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + *renderer_type = RENDERER_DIRAC; + + if ( output_config == AUDIO_CONFIG_MONO ) + { + *renderer_type = RENDERER_MONO_DOWNMIX; + } + else if ( output_config == AUDIO_CONFIG_STEREO ) + { + *renderer_type = RENDERER_STEREO_PARAMETRIC; + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { *internal_config = transport_config; -- GitLab From bf339f0d98f5bda084b23be4bb5155882625ee98 Mon Sep 17 00:00:00 2001 From: advasila Date: Mon, 16 Jan 2023 09:36:44 +0200 Subject: [PATCH 002/173] update project files --- Workspace_msvc/lib_enc.vcxproj | 1 + Workspace_msvc/lib_enc.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index a2d1e13ae7..21973c8968 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -213,6 +213,7 @@ + diff --git a/Workspace_msvc/lib_enc.vcxproj.filters b/Workspace_msvc/lib_enc.vcxproj.filters index 8fe608e0a6..a0fb055f48 100644 --- a/Workspace_msvc/lib_enc.vcxproj.filters +++ b/Workspace_msvc/lib_enc.vcxproj.filters @@ -584,6 +584,9 @@ enc_ivas_c + + enc_ivas_c + -- GitLab From 55d707f438693d635e549342c7ca2e3953ec61ea Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Sun, 22 Jan 2023 16:57:15 +0200 Subject: [PATCH 003/173] Updates to contribution 26. --- apps/decoder.c | 14 +- lib_com/ivas_cnst.h | 1 + lib_com/ivas_ism_config.c | 28 ++- lib_com/ivas_prot.h | 11 +- lib_com/ivas_rom_com.c | 10 +- lib_dec/ivas_cpe_dec.c | 14 +- lib_dec/ivas_dec.c | 4 + lib_dec/ivas_init_dec.c | 4 +- lib_dec/ivas_masa_dec.c | 58 +++-- lib_dec/ivas_qmetadata_dec.c | 123 +++++++---- lib_enc/ivas_cpe_enc.c | 14 +- lib_enc/ivas_enc.c | 10 +- lib_enc/ivas_masa_enc.c | 387 ++++++++++++++++++++------------- lib_enc/ivas_qmetadata_enc.c | 403 ++++++++++++++++++++++++++--------- 14 files changed, 756 insertions(+), 325 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 79cfb67d4f..7f50bcda88 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -708,7 +708,7 @@ static bool parseCmdlIVAS_dec( int16_t i; char argv_to_upper[FILENAME_MAX]; #ifdef MASAISM_EDIT_OBJECTS - int32_t tmp; + int32_t tmp1; #endif #ifdef DEBUGGING float ftmp; @@ -998,21 +998,21 @@ static bool parseCmdlIVAS_dec( return false; } - if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) { - arg->index_of_edited_ism = tmp; + arg->index_of_edited_ism = (int16_t) tmp1; i++; } - if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) { - arg->azimuth_edited_ism = tmp; + arg->azimuth_edited_ism = (int16_t) tmp1; i++; } - if ( sscanf( argv[i], "%d", &tmp ) > 0 ) + if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) { - arg->elevation_edited_ism = tmp; + arg->elevation_edited_ism = (int16_t) tmp1; i++; } } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 0e1aa45572..339d665031 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1105,6 +1105,7 @@ enum #define NO_BITS_MASA_ISM_NO_OBJ 2 #define MASA2TOTAL_THR 0.98f #define BITS_MASA2TOTTAL_DCT0 6 +#define STEP_M2T 0.1f #endif #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 4869de36ce..2f4279a73c 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -532,11 +532,11 @@ ISM_MODE ivas_omasa_ism_mode_select( switch ( no_obj ) { case 1: - if ( ivas_total_brate >= IVAS_64k ) + if ( ivas_total_brate >= IVAS_24k4 ) { ism_mode = ISM_MASA_MODE_DISC; } - else if ( ivas_total_brate >= IVAS_48k ) + else if ( ivas_total_brate >= IVAS_24k4 ) { ism_mode = ISM_MASA_MODE_PARAM; } @@ -546,7 +546,25 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 2: - if ( ivas_total_brate >= IVAS_80k ) + if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + /* else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } */ + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 3: + if ( ivas_total_brate >= IVAS_128k ) { ism_mode = ISM_MASA_MODE_DISC; } @@ -563,14 +581,12 @@ ISM_MODE ivas_omasa_ism_mode_select( ism_mode = ISM_MODE_NONE; } break; - case 3: - case 4: if ( ivas_total_brate >= IVAS_160k ) { ism_mode = ISM_MASA_MODE_DISC; } - else if ( ivas_total_brate >= IVAS_80k ) + else if ( ivas_total_brate >= IVAS_64k ) { ism_mode = ISM_MASA_MODE_ONE_OBJ; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8bd1d65bfb..8bcd60e1d5 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4425,7 +4425,8 @@ void ivas_masa_encode( ISM_MODE ism_mode, /* i : ISM format mode */ int16_t nchan_ism, /* i : number of ism channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - int16_t idx_separated_object /* i : index of the separated object */ + int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ #endif ); @@ -5112,14 +5113,18 @@ void ivas_masa_ism_set_edited_objects( void encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, - BSTR_ENC_HANDLE hMetaData + BSTR_ENC_HANDLE hMetaData, + int16_t low_bitrate_mode, + int16_t nbands, + int16_t nblocks ); void decode_masa_to_total( uint16_t* bit_stream, int16_t* index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - int16_t nbands + int16_t nbands, + int16_t nblocks ); void modify_masa_energy_ratios( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 7c28e6b4f6..81c03f4791 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2784,13 +2784,13 @@ const float McMASA_LFEGain_vectors[64] = int32_t sep_object_brate[][MAX_NUM_OBJECTS] ={ {0, 0, 0, 0}, /* 13k2 */ {0, 0, 0, 0}, /* 16k4 */ - {0, 0, 0, 0}, /* 24k4 */ - {0, 0, 0, 0}, /* 32k */ - {0, 0, 0, 0}, /* 48k */ - {16000, 0, 0, 0}, /* 64k */ + {9600, 0, 0, 0}, /* 24k4 */ + {9600, 0, 0, 0}, /* 32k */ + {IVAS_13k2, 0, 0, 0}, /* 48k */ + {16000, IVAS_13k2, 0, 0}, /* 64k */ {20000, 16000, 0, 0}, /* 80k */ {IVAS_32k, 20000, 0, 0}, /* 96k */ - {IVAS_32k, IVAS_24k4, 0, 0}, /* 128k */ + {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 34d3584f7a..1ed3e91c35 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -164,7 +164,19 @@ ivas_error ivas_cpe_dec( { if ( st_ivas->hQMetaData != NULL && ivas_total_brate > IVAS_SID_5k2 ) { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.7f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + else + { + +#endif + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#ifdef MASA_AND_OBJECTS + } +#endif } else { diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 9ceaa52f68..998de0c8a6 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -630,6 +630,10 @@ ivas_error ivas_dec( ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ); } + if ( st_ivas->hCPE[0]->nchan_out == 1 ) + { + mvr2r( output[0], output[1], output_frame ); /* Copy mono signal to stereo output channels */ + } /* HP filtering */ for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 7da5528fb0..4e77e6bf5a 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -189,10 +189,10 @@ ivas_error ivas_dec_setup( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - st_ivas->nchan_transport = 2; + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata*/ - st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 3] + 1; + st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); if ( st_ivas->ini_frame > 0 ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index dcb70abf57..b6d416819d 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -73,6 +73,7 @@ static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos ); static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, int16_t no_ism, int16_t K ); +static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t n_ism, int16_t nbands, int16_t nblocks ); #endif /*-----------------------------------------------------------------------* @@ -139,9 +140,17 @@ ivas_error ivas_masa_decode( { if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { - /* the number of MASA transport channels was read in ivas_dec_setup() */ - st->next_bit_pos -= MASA_TRANSP_BITS; - *nb_bits_read += MASA_TRANSP_BITS; +#ifdef MASA_AND_OBJECTS + if ( ivas_format != MASA_ISM_FORMAT ) + { + /* number of transport channels is always 2 for MASA_ISM format */ +#endif + /* the number of MASA transport channels was read in ivas_dec_setup() */ + st->next_bit_pos -= MASA_TRANSP_BITS; + *nb_bits_read += MASA_TRANSP_BITS; +#ifdef MASA_AND_OBJECTS + } +#endif #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) { @@ -1728,8 +1737,15 @@ static void read_ism_ratio_index( } else { - /* read prediciton type */ - differential_subframe = bit_stream[( *next_bit_pos )--]; + if ( numCodingBands > 1 ) + { + /* read prediction type */ + differential_subframe = bit_stream[( *next_bit_pos )--]; + } + else + { + differential_subframe = 1; + } /* read GR order */ GR_order = bit_stream[( *next_bit_pos )--]; for ( b = 0; b < numCodingBands; b++ ) @@ -1789,15 +1805,16 @@ static void decode_ism_ratios( int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - int16_t n_ism ) + int16_t n_ism, + int16_t nbands, + int16_t numSf ) { int16_t sf, band; - int16_t nbands, numSf; int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - nbands = hQMetaData->q_direction->cfg.nbands; - numSf = hQMetaData->q_direction->cfg.nblocks; + + /* hQMetaData->q_direction->cfg.nblocks; */ for ( sf = 0; sf < numSf; sf++ ) { /* read ism ratio indexes */ @@ -1818,6 +1835,23 @@ static void decode_ism_ratios( { reconstruct_ism_ratios( ratio_ism_idx[band], n_ism, 1.0f / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ), ratio_ism[sf][band] ); } + if ( nbands == 1 ) + { + for ( band = 1; band < 5; band++ ) + { + mvr2r( ratio_ism[sf][0], ratio_ism[sf][band], n_ism ); + } + } + } + if ( numSf == 1 ) + { + for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + for ( band = 0; band < nbands; band++ ) + { + mvr2r( ratio_ism[0][band], ratio_ism[sf][band], n_ism ); + } + } } } @@ -1842,15 +1876,15 @@ static int16_t ivas_decode_masaism_metadata( nb_bits_read = *next_bit_pos; nbands = hQMetaData->q_direction->cfg.nbands; - nblocks = hQMetaData->q_direction->cfg.nblocks; + nblocks = hQMetaData->q_direction->cfg.nblocks; /* To do: what if other value than 4? */ /* Read MASA-to-total energy ratios */ - decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands ); + decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands, nblocks ); if ( nchan_ism > 1 ) { /* read ISM ratios */ - decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism ); + decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks ); /* calculate priority */ set_f( priority, 0.0f, nchan_ism ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index b5b145a30f..e26850f737 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -3312,9 +3312,11 @@ static void read_stream_dct_coeffs_omasa( { int16_t sign, nbits; int16_t i, j, i_min; - int16_t last_non_null; - float step = 0.1f; + float step; + int16_t GR1, GR2; + + step = STEP_M2T; nbits = 0; sign = 1; if ( first_line == 0 ) @@ -3338,35 +3340,44 @@ static void read_stream_dct_coeffs_omasa( if ( q_idx[0] != 0 ) { - /* read last non null position */ - last_non_null = 0; - j = (int16_t) ceilf( log2f( (float) ( len_stream ) ) ); - for ( i = 0; i < j; i++ ) - { - last_non_null = ( last_non_null << 1 ) + bit_stream[( *index )--]; - } - - nbits += j; - if ( last_non_null > 0 ) + if ( len_stream >= 8 ) { /* read index of last index encoded with GR2 */ i_min = 0; - j = (int16_t) ceilf( log2f( (float) ( last_non_null + 1 ) ) ); + j = 4; for ( i = 0; i < j; i++ ) { i_min = ( i_min << 1 ) + bit_stream[( *index )--]; } - nbits += j; + /* read GR orders */ + GR1 = bit_stream[( *index )--] + 1; + if ( GR1 == 2 ) + { + GR2 = bit_stream[( *index )--]; + } + else + { + GR2 = 0; + } /* read GR data */ for ( i = 1; i <= i_min; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, 2 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + } + for ( i = i_min + 1; i < len_stream; i++ ) + { + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); } - for ( i = i_min + 1; i <= last_non_null; i++ ) + } + else + { + /* read GR order (only one) */ + GR1 = bit_stream[( *index )--]; + for ( i = 1; i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, 0 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); } } } @@ -3390,7 +3401,8 @@ void decode_masa_to_total( uint16_t *bit_stream, int16_t *index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - int16_t nbands ) + int16_t nbands, + int16_t nblocks ) { int16_t i, j, k; @@ -3402,24 +3414,16 @@ void decode_masa_to_total( int16_t n_streams, len_stream; /* Setup coding parameters */ - if ( nbands == 5 ) - { - n_streams = 1; - len_stream = nbands * 4; - } - else if ( nbands == 8 ) + n_streams = 1; + len_stream = nbands * nblocks; + if ( len_stream == 32 ) { n_streams = 4; len_stream = 8; } - else - { - n_streams = 4; - len_stream = nbands; - printf( "Unrecognized number of bands!" ); /* To do: finalize this */ - exit( -1 ); - } - set_s( q_idx, 0, nbands * MAX_PARAM_SPATIAL_SUBFRAMES ); + + + set_s( q_idx, 0, nbands * nblocks ); for ( i = 0; i < n_streams; i++ ) { read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], &q_dct_data[i * len_stream], len_stream, bit_stream, index, i == 0 ); @@ -3427,19 +3431,34 @@ void decode_masa_to_total( /* inverse DCT2 transform */ - if ( nbands == 5 ) + switch ( len_stream ) { - matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); /* reuse of variable*/ - } - else - { - assert( nbands == 8 ); - matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); + case 4: + matrix_product( dct4, nblocks, nblocks, 1, q_dct_data, nblocks, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nblocks ); + break; + case 5: + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; + case 8: + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; + case 20: + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); /* reuse of variable*/ + break; + case 32: + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); + break; + default: + break; } + k = 0; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < nblocks; i++ ) { for ( j = 0; j < nbands; j++ ) { @@ -3448,5 +3467,25 @@ void decode_masa_to_total( k++; } } + if ( nblocks == 1 ) + { + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; + } + } + } + if ( nbands == 1 ) + { + for ( j = 1; j < 5; j++ ) + { + for ( i = 0; i < nblocks; i++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; + } + } + } } #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e5c83ffb20..a2675ba1d8 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -271,7 +271,19 @@ ivas_error ivas_cpe_enc( { if ( st_ivas->hQMetaData != NULL ) { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) + { + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.7f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + else + { + +#endif + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#ifdef MASA_AND_OBJECTS + } +#endif } else { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index bc2b6d33a0..b24233b6eb 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -90,7 +90,11 @@ ivas_error ivas_enc( input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); n_samples_chan = n_samples / nchan_inp; +#ifdef MASA_AND_OBJECTS + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); +#else set_s( nb_bits_metadata, 0, MAX_SCE ); +#endif #ifdef SBA_BR_SWITCHING sba_reinit_flag = 0; if ( ivas_format == SBA_FORMAT ) @@ -257,7 +261,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0 + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0, NULL #endif ); } @@ -345,7 +349,7 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object ); + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Merge transport signals */ @@ -428,7 +432,7 @@ ivas_error ivas_enc( ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0 + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0, NULL #endif ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 05f5892005..fadf8e9fb8 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -64,7 +64,11 @@ static void ivas_merge_masa_metadatas( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - ISM_METADATA_HANDLE hIsmMeta[] /* i/o: ISM metadata handles */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + int16_t low_bitrate_mode, /* i: is low bitrate more? 1/0 */ + int16_t omasa_nbands, + int16_t omasa_nblocks + ); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); @@ -75,6 +79,8 @@ static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t n static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio ); +static void transform_index_and_GR_encode( int16_t *diff_idx, int16_t len, int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); +static void transform_difference_index( int16_t *diff_idx, int16_t *idx, int16_t len ); #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif @@ -241,7 +247,8 @@ void ivas_masa_encode( ISM_MODE ism_mode, /* i : ISM format mode */ int16_t nchan_ism, /* i : number of ism channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - int16_t idx_separated_object /* i : index of the separated object */ + int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa /* i: OMASA encoder handle */ #endif ) { @@ -249,10 +256,14 @@ void ivas_masa_encode( int16_t i, j; int16_t masa_sid_descriptor; +#ifdef MASA_AND_OBJECTS + int16_t low_bitrate_mode; +#endif masa_sid_descriptor = -1; h_orig_metadata = NULL; #ifdef MASA_AND_OBJECTS + low_bitrate_mode = 0; if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else if ( ivas_format == MASA_FORMAT ) @@ -317,13 +328,16 @@ void ivas_masa_encode( if ( ivas_format == MASA_FORMAT ) #endif { + +#ifndef MASA_AND_OBJECTS /* write the number of MASA transport channels */ push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; +#endif #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) { - /* always write the number of objects in ISM_MASA format*/ + /* write the number of objects in ISM_MASA format*/ push_next_indice( hMetaData, nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; @@ -334,6 +348,12 @@ void ivas_masa_encode( hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; } } + else + { + /* write the number of MASA transport channels */ + push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); + hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; + } #endif /* write placeholder data for descriptive metadata */ @@ -376,6 +396,7 @@ void ivas_masa_encode( { #ifdef MASA_AND_OBJECTS reduce_metadata_further( hMasa, hQMetaData, ivas_format, ism_mode ); + low_bitrate_mode = ( ivas_total_brate <= 32000 ); #else reduce_metadata_further( hMasa, hQMetaData, ivas_format ); #endif @@ -389,7 +410,7 @@ void ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData ); + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes ); } else { @@ -397,7 +418,9 @@ void ivas_masa_encode( } #endif /* Encode metadata */ + ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); + #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { @@ -2107,6 +2130,47 @@ static int16_t index_slice_enum( return index; } +static void transform_difference_index( + int16_t *diff_idx, + int16_t *idx, + int16_t len ) +{ + int16_t i; + for ( i = 0; i < len; i++ ) + { + if ( diff_idx[i] <= 0 ) + { + idx[i] = -2 * diff_idx[i]; + } + else + { + idx[i] = 2 * diff_idx[i] - 1; + } + } + return; +} + + +static void transform_index_and_GR_encode( + int16_t *diff_idx, /* i: differenc eindex to encode */ + int16_t len, /*i: input length */ + int16_t GR_order, /* i: GR order */ + BSTR_ENC_HANDLE hMetaData /* i/o: bitstream */ +) +{ + int16_t i; + int16_t idx[IVAS_MAX_NUM_OBJECTS]; + /* transform difference index into positive */ + transform_difference_index( diff_idx, idx, len ); + /* GR encoding */ + + for ( i = 0; i < len; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, idx[i], 100, GR_order ); + } + return; +} + static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, @@ -2194,20 +2258,8 @@ static int16_t encode_ratio_ism_subframe( { /* take difference with respect to previous subframe */ v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); - /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) - { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } - } - /* GR encoding */ - + transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); + /* GR encoding estimate length */ for ( i = 0; i < no_ism - 1; i++ ) { nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); @@ -2224,151 +2276,100 @@ static int16_t encode_ratio_ism_subframe( GR_order = 1; nbits = nbits1; } - - /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ - /* take difference with respect to previous subframe only for first subband */ - nbits0 = 0; - nbits1 = 0; - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) + if ( numCodingBands > 1 ) { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } - } - /* GR encoding */ - - for ( i = 0; i < no_ism - 1; i++ ) - { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - for ( b = 1; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) - { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } - } + transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); /* GR encoding */ - for ( i = 0; i < no_ism - 1; i++ ) { nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); } - } - - if ( nbits0 < nbits1 ) - { - GR_order_sb = 0; - } - else - { - GR_order_sb = 1; - nbits0 = nbits1; - } - - if ( nbits0 < nbits ) - { - differential_subframe = 0; - nbits = nbits0; - GR_order = GR_order_sb; - } - nbits++; /* for GR_order */ - nbits++; /* for the prediction type */ - - /* write prediction type */ - push_next_indice( hMetaData, differential_subframe, 1 ); - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - /* write data */ - if ( differential_subframe ) - { - for ( b = 0; b < numCodingBands; b++ ) + for ( b = 1; b < numCodingBands; b++ ) { /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) - { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } - } + transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); /* GR encoding */ for ( i = 0; i < no_ism - 1; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); } } - } - else - { - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) + + if ( nbits0 < nbits1 ) { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } + GR_order_sb = 0; + } + else + { + GR_order_sb = 1; + nbits0 = nbits1; } - /* GR encoding */ - for ( i = 0; i < no_ism - 1; i++ ) + if ( nbits0 < nbits ) { - ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; } - for ( b = 1; b < numCodingBands; b++ ) + nbits++; /* for GR_order */ + nbits++; /* for the prediction type */ + + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + /* write data */ + if ( differential_subframe ) { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); - /* transform difference index into positive */ - for ( i = 0; i < no_ism - 1; i++ ) + for ( b = 0; b < numCodingBands; b++ ) { - if ( diff_idx[i] <= 0 ) - { - diff_idx[i] = -2 * diff_idx[i]; - } - else - { - diff_idx[i] = 2 * diff_idx[i] - 1; - } + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); } - /* GR encoding */ + } + else + { + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - for ( i = 0; i < no_ism - 1; i++ ) + for ( b = 1; b < numCodingBands; b++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, diff_idx[i], 100, GR_order ); + /* take difference with respect to previous subband */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); } } } + else + { + /* only differential wrt previous subframe is possible */ + /* write the differential to subframe case and no bit to signal the difference type */ + + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits++; /* for GR_order */ + /* write data */ + + for ( b = 0; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); + } + } + #ifdef DEBUGGING assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); #endif @@ -2379,10 +2380,12 @@ static int16_t encode_ratio_ism_subframe( static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - ISM_METADATA_HANDLE hIsmMeta[] /* i/o: ISM metadata handles */ -) + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + int16_t low_bitrate_mode, /* i: is low bitrate more? 1/0 */ + int16_t omasa_nbands, + int16_t omasa_nblocks ) { int16_t sf, band; uint8_t numCodingBands; @@ -2400,35 +2403,127 @@ static void ivas_encode_masaism_metadata( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float step; int16_t inv_step; + float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; - numCodingBands = hMasa->config.numCodingBands; - numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; - for ( sf = 0; sf < numSf; sf++ ) + /* use the values from hQMetaData */ + numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; + numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; + + + if ( numCodingBands != omasa_nbands ) + { + assert( numCodingBands == 1 ); + + for ( sf = 0; sf < numSf; sf++ ) + { + if ( sum_f( hMasa->data.energy_ism[sf], omasa_nbands ) == 0.0f ) + { + hQMetaData->masa_to_total_energy_ratio[sf][0] = 1.0f; + } + else + { + brange[0] = hMasa->data.band_mapping[0]; + brange[1] = hMasa->data.band_mapping[omasa_nbands]; + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + energy_ism = 0.0f; + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + energy_ism_ind[obj] = 0.0f; + } + for ( band = 0; band < omasa_nbands; band++ ) + { + energy_ism += hMasa->data.energy_ism[sf][band]; + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + energy_ism_ind[obj] += hMasa->data.energy_ism[sf][band] * hMasa->data.energy_ratio_ism[sf][band][obj]; + } + } + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + hMasa->data.energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; + } + hQMetaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); + } + } + } + else if ( numSf != omasa_nblocks ) { + assert( numSf == 1 ); + for ( band = 0; band < numCodingBands; band++ ) { - if ( hMasa->data.energy_ism[sf][band] == 0.0f ) + energy_ism = 0.0f; /* ISM energy for current subband */ + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + energy_ism_ind[obj] = 0.0f; + } + for ( sf = 0; sf < omasa_nblocks; sf++ ) + { + energy_ism += hMasa->data.energy_ism[sf][band]; + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + energy_ism_ind[obj] += hMasa->data.energy_ism[sf][band] * hMasa->data.energy_ratio_ism[sf][band][obj]; + } + } + if ( energy_ism == 0.0f ) { - hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; } else { + for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + { + hMasa->data.energy_ratio_ism[0][band][obj] = energy_ism_ind[obj] / energy_ism; + } brange[0] = hMasa->data.band_mapping[band]; brange[1] = hMasa->data.band_mapping[band + 1]; eneBand = 0.0f; - for ( bin = brange[0]; bin < brange[1]; bin++ ) + for ( sf = 0; sf < omasa_nblocks; sf++ ) { - eneBand += hMasa->data.energy[sf][bin]; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } } - hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hMasa->data.energy_ism[sf][band] + EPSILON ); + hQMetaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); } } } + else + { + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hMasa->data.energy_ism[sf][band] == 0.0f ) + { + hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + } + else + { + brange[0] = hMasa->data.band_mapping[band]; + brange[1] = hMasa->data.band_mapping[band + 1]; + + eneBand = 0.0f; + for ( bin = brange[0]; bin < brange[1]; bin++ ) + { + eneBand += hMasa->data.energy[sf][bin]; + } + hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hMasa->data.energy_ism[sf][band] + EPSILON ); + } + } + } + } + + encode_masa_to_total( hQMetaData, hMetaData, low_bitrate_mode, numCodingBands, numSf ); - encode_masa_to_total( hQMetaData, hMetaData ); /* quantize ism_ratios */ if ( hMasa->data.nchan_ism > 1 ) { diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 1c9eef86e8..fbc98dbe21 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -125,7 +125,9 @@ static void transform_azimuth_dir2( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *d static int16_t calc_var_azi( const IVAS_QDIRECTION *q_direction, const int16_t diffuseness_index_max_ec_frame, const float avg_azimuth, float *avg_azimuth_out ); #ifdef MASA_AND_OBJECTS -static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line ); +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line, int16_t low_bitrate_mode ); +static int16_t find_optimal_GR_order( int16_t *q_idx, int16_t len, int16_t *GR ); +static int16_t find_optimal_GR_orders( int16_t *q_idx, int16_t len, int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); #endif /*-----------------------------------------------------------------------* @@ -4922,14 +4924,138 @@ static float direction_distance( } #endif #ifdef MASA_AND_OBJECTS -static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line ) + +static int16_t divide_GR_orders( + int16_t *q_idx, + int16_t GR1, + int16_t GR2, + int16_t len, + int16_t len_max_GR1, + int16_t *i_min ) +{ + int16_t nb_GR_min; + int16_t i, j, nb_GR; + nb_GR_min = 1000; + *i_min = -1; + for ( i = 0; i < min( len_max_GR1, len ); i++ ) + { + nb_GR = 0; + + for ( j = 0; j <= i; j++ ) + { + nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ); + } + for ( j = i + 1; j < len; j++ ) + { + nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ); + } + + if ( nb_GR < nb_GR_min ) + { + nb_GR_min = nb_GR; + *i_min = i + 1; + } + } + return nb_GR_min; +} +static int16_t +find_optimal_GR_order( + int16_t *q_idx, + int16_t len, + int16_t *GR ) +{ + int16_t nb_GR_0, nb_GR_1; + int16_t i; + /* find optimum length of the part encoded with GR2 */ + nb_GR_0 = 0; + nb_GR_1 = 0; + for ( i = 0; i < len; i++ ) + { + nb_GR_0 += ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 0 ); + nb_GR_1 += ivas_qmetadata_encode_extended_gr_length( q_idx[i], 100, 1 ); + } + + if ( nb_GR_0 < nb_GR_1 ) + { + *GR = 0; + return nb_GR_0; + } + else + { + *GR = 1; + return nb_GR_1; + } +} + + +static int16_t +find_optimal_GR_orders( + int16_t *q_idx, + int16_t len, + int16_t len_max_GR1, + int16_t *GR1, + int16_t *GR2, + int16_t *i_min ) +{ + int16_t nb_GR_20, nb_GR_21, nb_GR_10, nb_GR_min; + int16_t i_min_20, i_min_21, i_min_10; + /* find optimum length of the part encoded with GR2 */ + nb_GR_20 = divide_GR_orders( q_idx, 2, 0, len, len_max_GR1, &i_min_20 ); + nb_GR_21 = divide_GR_orders( q_idx, 2, 1, len, len_max_GR1, &i_min_21 ); + nb_GR_10 = divide_GR_orders( q_idx, 1, 0, len, len_max_GR1, &i_min_10 ); + + if ( nb_GR_20 < nb_GR_21 && nb_GR_20 < nb_GR_10 ) + { + *GR1 = 2; + *GR2 = 0; + nb_GR_min = nb_GR_20; + *i_min = i_min_20; + } + else + { + if ( nb_GR_21 < nb_GR_20 && nb_GR_21 < nb_GR_10 ) + { + *GR1 = 2; + *GR2 = 1; + nb_GR_min = nb_GR_21; + *i_min = i_min_21; + } + else + { + *GR1 = 1; + *GR2 = 0; + nb_GR_min = nb_GR_10; + *i_min = i_min_10; + } + } + return nb_GR_min; +} + +static int16_t write_stream_dct_coeffs_omasa( + int16_t *q_idx, /* i: array of indexes to be written */ + int16_t len_stream, /* i: array length */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream */ + int16_t first_line, /* i: is first line of the matrix? 1/0*/ + int16_t low_bitrate_mode /* i: is low bitrate mode? if yes, limit the number of bits written */ +) { int16_t nb_bits = 0, bits_pos; - int16_t last_non_null; - uint16_t nb_GR_min, i_min, nb_GR; + uint16_t nb_GR_min; int16_t i, j; + int16_t changed, update_needed; + + int16_t GR1, GR2, i_min; + int16_t max_bits; bits_pos = hMetaData->nb_bits_tot; + if ( low_bitrate_mode == 1 ) + { + max_bits = 50; /* To do : find optimal allowed value*/ + } + else + { + max_bits = 1000; + } /* write DCT 0 component */ /* write sign only if not the very first DCT coeff */ if ( first_line == 0 ) @@ -4937,7 +5063,7 @@ static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream if ( q_idx[0] > 0 ) { push_next_indice( hMetaData, 1, 1 ); - push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); /* Todo : define constant */ + push_next_indice( hMetaData, q_idx[0], BITS_MASA2TOTTAL_DCT0 ); } else { @@ -4953,73 +5079,113 @@ static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream } - /* find last non-null position */ - last_non_null = -1; if ( q_idx[0] != 0 ) { - last_non_null = len_stream - 1; - while ( ( q_idx[last_non_null] == 0 ) && ( last_non_null >= 0 ) ) + i_min = 1; + GR2 = 0; + if ( len_stream >= 8 ) { - last_non_null--; + nb_GR_min = find_optimal_GR_orders( &q_idx[1], len_stream - 1, 15, &GR1, &GR2, &i_min ); + } + else + { + nb_GR_min = find_optimal_GR_order( &q_idx[1], len_stream - 1, &GR1 ); } - } - if ( last_non_null == -1 ) - { - /* all values are zero; no need to send anything else */ - assert( q_idx[0] == 0 ); - } - else - { - assert( q_idx[0] != 0 ); - /*last_non_null = max(4, last_non_null); */ - /* write index of last non null index on log2(len_stream) bits */ - j = (int16_t) ceilf( log2f( (float) ( len_stream ) ) ); - push_next_indice( hMetaData, last_non_null, j ); - nb_bits += j; - if ( last_non_null > 0 ) + assert( nb_GR_min < 1000 ); + changed = 1; + update_needed = 0; + while ( len_stream >= 8 && nb_GR_min > max_bits && changed >= 1 ) { - /* find optimum length of the part encoded with GR2 */ - nb_GR_min = 1000; - i_min = 0; - for ( i = 1; i <= last_non_null; i++ ) + update_needed = 1; + changed = 0; + for ( j = len_stream - 1; j > 6; j-- ) { - nb_GR = 0; - for ( j = 1; j <= i; j++ ) + if ( q_idx[j] >= 2 ) { - nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 2 ); + + if ( j > i_min ) + { + changed = 1; + nb_GR_min -= ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ); + q_idx[j] -= 2; + nb_GR_min += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ); + } + else + { + changed = 1; + nb_GR_min -= ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ); + q_idx[j] -= 2; + nb_GR_min += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ); + } } - for ( j = i + 1; j <= last_non_null; j++ ) + else if ( q_idx[j] == 1 ) { - nb_GR += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ); + if ( j > i_min ) + { + changed = 1; + nb_GR_min -= ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ); + q_idx[j] -= 1; + + nb_GR_min += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR2 ); + } + else + { + changed = 1; + nb_GR_min -= ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, GR1 ); + q_idx[j] -= 1; + nb_GR_min += ivas_qmetadata_encode_extended_gr_length( q_idx[j], 100, 0 ); + } } - if ( nb_GR < nb_GR_min ) + if ( nb_GR_min < max_bits ) { - nb_GR_min = nb_GR; - i_min = i; + break; } } - - assert( nb_GR_min < 1000 ); - - - /* write number of indexes encoded with GR2 */ - j = (int16_t) ceilf( log2f( (float) ( last_non_null + 1 ) ) ); - assert( i_min < ( 1 << j ) ); - push_next_indice( hMetaData, i_min, j ); - nb_bits += j; - + } + if ( update_needed == 1 ) + { + /* re-calculate */ + /* find optimum length of the part encoded with GR2 */ + nb_GR_min = find_optimal_GR_orders( &q_idx[1], len_stream - 1, 15, &GR1, &GR2, &i_min ); + } + if ( len_stream >= 8 ) + { + /* write number of indexes encoded with GR2 on 4 bits */ + push_next_indice( hMetaData, i_min, 4 ); + nb_bits += 4; + /* write GR orders */ + push_next_indice( hMetaData, GR1 - 1, 1 ); + nb_bits += 1; + if ( GR1 == 2 ) + { + push_next_indice( hMetaData, GR2, 1 ); + nb_bits += 1; + } /* write GR data */ for ( i = 1; i <= i_min; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, 2 ); + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); + } + for ( i = i_min + 1; i < len_stream; i++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR2 ); } - for ( i = i_min + 1; i <= last_non_null; i++ ) + } + else + { + /* len_stream <= 8 */ + /* write GR order */ + push_next_indice( hMetaData, GR1, 1 ); + nb_bits += 1; + for ( i = 1; i < len_stream; i++ ) { - ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, 0 ); + ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); } - nb_bits += nb_GR_min; } + + nb_bits += nb_GR_min; + assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); } return nb_bits; @@ -5027,23 +5193,27 @@ static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream void encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, - BSTR_ENC_HANDLE hMetaData ) + BSTR_ENC_HANDLE hMetaData, + int16_t low_bitrate_mode, + int16_t nbands, + int16_t nblocks ) { int16_t i, j, k; float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - float step = 0.1f; + float step = STEP_M2T; + int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - int16_t nbands; + int16_t bits_pos, nb_bits; int16_t n_streams, len_stream; - nbands = hQMetaData->numCodingBands; + #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_ratio = NULL; @@ -5055,44 +5225,55 @@ void encode_masa_to_total( #endif -#ifdef DEBUGGING - assert( ( nbands == 5 || nbands == 8 ) && "Number of subbands in parametric MASA_ISM should be 5 or 8 " ); -#endif + bits_pos = hMetaData->nb_bits_tot; k = 0; for ( i = 0; i < nbands; i++ ) { - for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + for ( j = 0; j < nblocks; j++ ) { data[k] = hQMetaData->masa_to_total_energy_ratio[j][i]; k++; } } - /* DCT2 transform */ - if ( nbands == 5 ) - { - matrix_product( dct5, nbands, nbands, 0, data, MAX_PARAM_SPATIAL_SUBFRAMES, nbands, 1, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 1, dct_data ); - } - else - { - matrix_product( dct8, nbands, nbands, 0, data, MAX_PARAM_SPATIAL_SUBFRAMES, nbands, 1, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 1, dct_data ); + n_streams = 1; + len_stream = nbands * nblocks; + switch ( len_stream ) + { + case 4: + matrix_product( dct4, nblocks, nblocks, 0, data, 1, nblocks, 1, dct_data ); + n_streams = 1; + len_stream = 4; + break; + case 5: + matrix_product( dct5, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); + n_streams = 1; + len_stream = nbands; + break; + case 8: + matrix_product( dct8, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); + n_streams = 1; + len_stream = nbands; + break; + break; + case 20: + matrix_product( dct5, nbands, nbands, 0, data, nblocks, nbands, 1, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 1, dct_data ); + n_streams = 1; + len_stream = nbands * nblocks; + break; + case 32: + matrix_product( dct8, nbands, nbands, 0, data, nblocks, nbands, 1, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 1, dct_data ); + n_streams = nblocks; + len_stream = nbands; + break; + default: + break; } - /* Setup coding parameters */ - if ( nbands == 5 ) - { - n_streams = 1; - len_stream = nbands * MAX_PARAM_SPATIAL_SUBFRAMES; - } - else - { - n_streams = MAX_PARAM_SPATIAL_SUBFRAMES; - len_stream = 8; - } for ( k = 0; k < n_streams; k++ ) { @@ -5129,21 +5310,57 @@ void encode_masa_to_total( } + /* write data */ + nb_bits = 0; + for ( i = 0; i < n_streams; i++ ) + { + nb_bits += write_stream_dct_coeffs_omasa( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ), low_bitrate_mode ); + } + + /* reconstruct masa2total */ - /* inverse DCT2 transform */ - if ( nbands == 5 ) + q_dct_data[0] = q_idx[0] * step; + for ( i = 1; i < len_stream; i++ ) { - matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); /* reuse of variable*/ + if ( ( q_idx[i] % 2 ) == 0 ) + { + q_dct_data[i] = -( q_idx[i] >> 1 ) * step; + } + else + { + q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; + } } - else + /* inverse DCT2 transform */ + switch ( len_stream ) { - assert( nbands == 8 ); - matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct_data_tmp ); - matrix_product( dct_data_tmp, nbands, MAX_PARAM_SPATIAL_SUBFRAMES, 0, dct4, MAX_PARAM_SPATIAL_SUBFRAMES, MAX_PARAM_SPATIAL_SUBFRAMES, 0, q_dct_data ); + case 4: + matrix_product( dct4, nblocks, nblocks, 1, q_dct_data, nblocks, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nblocks ); + break; + case 5: + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; + case 8: + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; + case 20: + matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); /* reuse of variable*/ + break; + case 32: + matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); + matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); + break; + default: + break; } + + k = 0; - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + for ( i = 0; i < nblocks; i++ ) { for ( j = 0; j < nbands; j++ ) { @@ -5152,14 +5369,6 @@ void encode_masa_to_total( k++; } } - - /* write data */ - nb_bits = 0; - for ( i = 0; i < n_streams; i++ ) - { - nb_bits += write_stream_dct_coeffs_omasa( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ) ); - } - assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); #ifdef DEBUG_MODE_QMETADATA -- GitLab From b843c21ad535d2143ebb12ac8572d531bd406b83 Mon Sep 17 00:00:00 2001 From: advasila Date: Sun, 22 Jan 2023 20:49:18 +0200 Subject: [PATCH 004/173] 1obj DISC from 32k --- lib_com/ivas_ism_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 473491f8fd..7a9dedfc9f 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -532,7 +532,7 @@ ISM_MODE ivas_omasa_ism_mode_select( switch ( no_obj ) { case 1: - if ( ivas_total_brate >= IVAS_24k4 ) + if ( ivas_total_brate >= IVAS_32k ) { ism_mode = ISM_MASA_MODE_DISC; } -- GitLab From 90fc193be972d0d82208b81f8533b64f9dead81a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Jan 2023 12:09:39 +0100 Subject: [PATCH 005/173] initial branch --- lib_dec/ivas_masa_dec.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 986829a015..0eec565504 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1798,6 +1798,8 @@ static void read_ism_ratio_index( } } } + + return; } static void decode_ism_ratios( @@ -1835,6 +1837,7 @@ static void decode_ism_ratios( { reconstruct_ism_ratios( ratio_ism_idx[band], n_ism, 1.0f / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ), ratio_ism[sf][band] ); } + if ( nbands == 1 ) { for ( band = 1; band < 5; band++ ) @@ -1843,6 +1846,7 @@ static void decode_ism_ratios( } } } + if ( numSf == 1 ) { for ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) @@ -1853,6 +1857,8 @@ static void decode_ism_ratios( } } } + + return; } static int16_t ivas_decode_masaism_metadata( @@ -1969,6 +1975,13 @@ static int16_t ivas_decode_masaism_metadata( return ( nb_bits_read - *next_bit_pos ); } + +/*-------------------------------------------------------------------* + * ivas_masa_ism_set_edited_objects() + * + * + *-------------------------------------------------------------------*/ + void ivas_masa_ism_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) @@ -2012,6 +2025,8 @@ void ivas_masa_ism_set_edited_objects( } } } + + return; } -- GitLab From 4cef93cda89c12301f5774db0e48a9674005c468 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Jan 2023 12:12:24 +0100 Subject: [PATCH 006/173] add returns --- lib_enc/ivas_masa_enc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 4d70e7688f..0dbecbcb83 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2171,6 +2171,7 @@ static void transform_index_and_GR_encode( return; } + static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, @@ -2579,6 +2580,7 @@ static void ivas_encode_masaism_metadata( { bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); } + /* this is only the first version */ /* quantize directions */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) @@ -2586,14 +2588,23 @@ static void ivas_encode_masaism_metadata( idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); } + + return; } -void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], - float data_in_f2[][L_FRAME48k], - float data_out_f[][L_FRAME48k], - const int16_t input_frame, - const int16_t num_transport_channels ) +/*-------------------------------------------------------------------* + * ivas_merge_masa_transports() + * + * Merge MASA transport channels + *-------------------------------------------------------------------*/ + +void ivas_merge_masa_transports( + float data_in_f1[][L_FRAME48k], + float data_in_f2[][L_FRAME48k], + float data_out_f[][L_FRAME48k], + const int16_t input_frame, + const int16_t num_transport_channels ) { int16_t i, j; @@ -2604,5 +2615,7 @@ void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], data_out_f[i][j] = data_in_f1[i][j] + data_in_f2[i][j]; } } + + return; } #endif -- GitLab From 902f4b4735514b7ab8e016986fc5bef1694981e8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Jan 2023 16:39:04 +0100 Subject: [PATCH 007/173] Transfer defines: - #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs - #define OMASA_BRATE /* VA: combined format bit-budget distribution */ - #define OMASA_BRATE_FIX - #define DEBUG_VA --- Workspace_msvc/lib_dec.vcxproj | 1 + Workspace_msvc/lib_dec.vcxproj.filters | 3 + lib_com/bitstream.c | 34 +++ lib_com/ivas_cnst.h | 5 +- lib_com/ivas_ism_config.c | 182 ++++++++++++++- lib_com/ivas_prot.h | 124 +++++++--- lib_com/ivas_rom_com.c | 29 ++- lib_com/ivas_stat_com.h | 5 + lib_com/options.h | 6 + lib_dec/ivas_cpe_dec.c | 46 +++- lib_dec/ivas_dec.c | 25 ++- lib_dec/ivas_init_dec.c | 11 +- lib_dec/ivas_ism_metadata_dec.c | 55 ++++- lib_dec/ivas_masa_dec.c | 43 ++++ lib_dec/ivas_omasa_dec.c | 106 +++++++++ lib_dec/ivas_sce_dec.c | 11 +- lib_dec/ivas_stat_dec.h | 6 +- lib_dec/lib_dec.c | 11 + lib_enc/ivas_cpe_enc.c | 32 +++ lib_enc/ivas_enc.c | 102 ++++++++- lib_enc/ivas_init_enc.c | 12 +- lib_enc/ivas_ism_enc.c | 28 ++- lib_enc/ivas_ism_metadata_enc.c | 300 ++++++++++++++++++++----- lib_enc/ivas_masa_enc.c | 50 ++++- lib_enc/ivas_omasa_enc.c | 32 +++ lib_enc/ivas_sce_enc.c | 22 +- lib_enc/ivas_stat_enc.h | 10 +- lib_enc/ivas_stereo_mdct_core_enc.c | 4 + lib_enc/lib_enc.c | 7 +- 29 files changed, 1159 insertions(+), 143 deletions(-) create mode 100644 lib_dec/ivas_omasa_dec.c diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index 34b63eba78..a89d964e86 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -290,6 +290,7 @@ + diff --git a/Workspace_msvc/lib_dec.vcxproj.filters b/Workspace_msvc/lib_dec.vcxproj.filters index 4dcff8d503..4effb44669 100644 --- a/Workspace_msvc/lib_dec.vcxproj.filters +++ b/Workspace_msvc/lib_dec.vcxproj.filters @@ -503,6 +503,9 @@ dec_ivas_c + + dec_ivas_c + diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index e9d9cd13c5..b90c6d4ac7 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1812,6 +1812,12 @@ ivas_error preview_indices( else { st_ivas->ivas_format = MASA_FORMAT; +#ifdef MASA_AND_OBJECTS_VE + if ( bit_stream[3] ) + { + st_ivas->ivas_format = MASA_ISM_FORMAT; + } +#endif } break; } @@ -1968,6 +1974,34 @@ ivas_error preview_indices( ivas_sba_config( total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &( st_ivas->nSCE ), &( st_ivas->nCPE ), &( st_ivas->element_mode_init ) ); } +#ifdef MASA_AND_OBJECTS_VE + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + /* read number of objects from the bitstream */ + st_ivas->nchan_transport = 0; + + if ( total_brate != SID_2k40 && total_brate != FRAME_NO_DATA ) + { + st_ivas->ism_mode = ivas_omasa_ism_mode_select( total_brate, st_ivas->nchan_ism ); + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + st_ivas->nchan_transport = 0; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + st_ivas->nchan_transport = 2 * st_ivas->bit_stream[total_brate / FRAMES_PER_SEC - 2] + st_ivas->bit_stream[total_brate / FRAMES_PER_SEC - 3] + 1; + } + + k = (int16_t) ( ( total_brate / FRAMES_PER_SEC ) - 1 ); + + { + st_ivas->nchan_transport++; + k--; + } + } + } +#endif } st_ivas->hDecoderConfig->ivas_total_brate = total_brate; diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index fd1f3f10a4..3e36ec27db 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -300,7 +300,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 */ @@ -308,6 +308,9 @@ typedef enum #define ISM_METADATA_VAD_FLAG_BITS 1 #define ISM_METADATA_FLAG_BITS 2 +#ifdef OMASA_BRATE +#define ISM_INACTIVE_IMP 0 /* == ISM_NO_META */ +#endif #define ISM_NO_META 0 #define ISM_LOW_IMP 1 #define ISM_MEDIUM_IMP 2 diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 7a9dedfc9f..b5d12c0da2 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -63,7 +63,11 @@ * Convert bit-budget to bitrate *-------------------------------------------------------------------*/ +#ifdef OMASA_BRATE +void bitbudget_to_brate( +#else static void bitbudget_to_brate( +#endif const int16_t x[], /* i : bitbudgets */ int32_t y[], /* o : bitrates */ const int16_t N /* i : number of entries to be converted */ @@ -98,7 +102,7 @@ ivas_error ivas_ism_config( int16_t nb_bits_metadata[] /* i/o: number of metadata bits */ #ifdef MASA_AND_OBJECTS , - int16_t masa_ism_flag /* i : flag indicating ISM MASA format */ + const int16_t combined_format_flag /* i : flag indicating combined format */ #endif ) { @@ -114,7 +118,7 @@ ivas_error ivas_ism_config( error = IVAS_ERR_OK; #ifdef MASA_AND_OBJECTS - if ( masa_ism_flag == 1 ) + if ( combined_format_flag == 1 ) { n_ISms = num_obj; } @@ -137,6 +141,40 @@ ivas_error ivas_ism_config( } } +#ifdef OMASA_BRATE + /* decision about bitrates per channel */ + if ( combined_format_flag ) + { + /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */ + bits_ism = (int16_t) ( ism_total_brate / FRMS_PER_SECOND ); + set_s( bits_element, bits_ism / n_ISms, n_ISms ); + bits_element[n_ISms - 1] += bits_ism % n_ISms; + + /* ISM common signaling bits are counted in MASA MD bit-budget */ + } + else + { + /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */ + bits_ism = (int16_t) ( ism_total_brate / FRMS_PER_SECOND ); + set_s( bits_element, bits_ism / n_ISms, n_ISms ); + bits_element[n_ISms - 1] += bits_ism % n_ISms; + bitbudget_to_brate( bits_element, element_brate, n_ISms ); + + /* count ISm common signaling bits */ + if ( hIsmMeta != NULL ) + { + nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + num_obj; + + for ( ch = 0; ch < n_ISms; ch++ ) + { + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + nb_bits_metadata[0] += ISM_METADATA_VAD_FLAG_BITS; + } + } + } + } +#else /* decision about bitrates per channel - constant during the session (at one ivas_total_brate) */ bits_ism = (int16_t) ( ism_total_brate / FRMS_PER_SECOND ); set_s( bits_element, bits_ism / n_ISms, n_ISms ); @@ -148,7 +186,7 @@ ivas_error ivas_ism_config( { #ifdef MASA_AND_OBJECTS nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS; - if ( masa_ism_flag == 0 ) + if ( combined_format_flag == 0 ) { /* the bits for writing the number of objects are counted here for pure ISM modes */ nb_bits_metadata[0] += num_obj; @@ -165,6 +203,7 @@ ivas_error ivas_ism_config( } } } +#endif /* split metadata bitbudget equally between channels */ if ( nb_bits_metadata != NULL ) @@ -322,6 +361,31 @@ ivas_error ivas_ism_config( } } +#ifdef OMASA_BRATE + if ( combined_format_flag == 1 ) + { + if ( diff > 0 ) + { + for ( ch = 0; ch < n_ISms; ch++ ) + { + if ( ism_imp[ch] <= ISM_MEDIUM_IMP ) + { + if ( diff > limit_high ) + { + diff += bits_CoreCoder[ch] - limit_high; + bits_CoreCoder[ch] = limit_high; + } + else + { + bits_CoreCoder[ch] += diff; + break; + } + } + } + } + } +#endif + bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); } @@ -330,7 +394,11 @@ ivas_error ivas_ism_config( { int32_t tmpL; tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRMS_PER_SECOND; +#ifdef OMASA_BRATE + if ( ism_total_brate != tmpL ) +#else if ( sum_l( element_brate, n_ISms ) != tmpL ) +#endif { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISm bit-budget distribution. Exiting!\n" ); } @@ -603,4 +671,112 @@ ISM_MODE ivas_omasa_ism_mode_select( return ism_mode; } + + +#ifdef OMASA_BRATE +/*--------------------------------------------------------------- + * ivas_interformat_brate() + * + * Bit-budget distribution in case of combined-format coding + * ---------------------------------------------------------------*/ + +#define GAMMA_ISM_LOW_IMP 0.8f +#define GAMMA_ISM_MEDIUM_IMP 1.2f +#define GAMMA_ISM_HIGH_IMP 1.4f + +/*! r: adjusted bitrate */ +int32_t ivas_interformat_brate( + const int32_t element_brate, /* i : element bitrate */ + const int16_t ism_imp /* i : ISM importance flag */ +) +{ + int32_t element_brate_out; + int16_t nBits, limit_low, limit_high; + + nBits = (int16_t) ( element_brate / FRAMES_PER_SEC ); + + if ( ism_imp == ISM_INACTIVE_IMP ) + { + nBits = BITS_ISM_INACTIVE; + } + else if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP ); + } + + limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC; + if ( ism_imp == ISM_INACTIVE_IMP ) + { + limit_low = BITS_ISM_INACTIVE; + } + else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT ) + { + limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC; + } + + limit_high = IVAS_512k / FRAMES_PER_SEC; + if ( element_brate < SCE_CORE_16k_LOW_LIMIT ) + { + limit_high = ACELP_12k8_HIGH_LIMIT / FRMS_PER_SECOND; + } + + nBits = check_bounds_s( nBits, limit_low, limit_high ); + + element_brate_out = nBits * FRAMES_PER_SEC; + + return element_brate_out; +} +#endif + + +#ifdef OMASA_BRATE_FIX +/*--------------------------------------------------------------- + * ivas_combined_format_brate_sanity() + * + * + * ---------------------------------------------------------------*/ + +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int32_t brate_surplus, /* i : surplus bitrate */ + int16_t nb_bits_metadata[], /* i/o: number of metadata bits */ + const int16_t nchan_ism, /* i : number of objects */ + int16_t *diff_nBits /* o : number of differential bits */ +) +{ + /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by + low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget + for core-coding @12.8 kHz is too high => increase the ISM low-rate mode bit-rate */ + + int16_t nBits_CPE; + nBits_CPE = (int16_t) ( element_brate / FRAMES_PER_SEC ); + nBits_CPE -= nb_bits_metadata[0]; + nBits_CPE += (int16_t) ( brate_surplus / FRAMES_PER_SEC ); + nBits_CPE -= ( WB_TBE_0k35 / FRAMES_PER_SEC ); + nBits_CPE -= nb_bits_metadata[1]; + nBits_CPE -= 14; + + *diff_nBits = 0; + if ( nchan_ism == 1 && element_brate < ACELP_12k8_HIGH_LIMIT ) + { + int16_t limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; + + *diff_nBits = nBits_CPE - limit_high; + if ( *diff_nBits > 0 ) + { + nb_bits_metadata[0] += *diff_nBits; + } + } + + return; +} +#endif #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a9e1540ef4..00298890bd 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -797,10 +797,18 @@ ivas_error ivas_ism_config( int32_t total_brate[], /* o : total bitrate per object */ int16_t nb_bits_metadata[] /* i/o: number of metadata bits */ #ifdef MASA_AND_OBJECTS - , int16_t masa_ism_flag /* i : flag indicating ISM MASA format */ + , const int16_t combined_format_flag /* i : flag indicating combined format */ #endif ); +#ifdef OMASA_BRATE +void bitbudget_to_brate( + const int16_t x[], /* i : bitbudgets */ + int32_t y[], /* o : bitrates */ + const int16_t N /* i : number of entries to be converted */ +); +#endif + void ivas_ism_reset_metadata( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ ); @@ -850,7 +858,11 @@ ivas_error ivas_ism_enc( ); ivas_error ivas_ism_metadata_enc( +#ifdef OMASA_BRATE + int32_t *ism_total_brate, /* i/o: ISms total bitrate */ +#else const int32_t ism_total_brate, /* i : ISms total bitrate */ +#endif 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 */ @@ -861,7 +873,10 @@ ivas_error ivas_ism_metadata_enc( const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Config Handle */ #ifdef MASA_AND_OBJECTS , - int16_t n_ism /* i : number of ism-s */ + const int16_t n_ism /* i : number of objects */ +#ifdef OMASA_BRATE + ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ +#endif #endif ); @@ -4484,10 +4499,10 @@ void ivas_masa_encode( const int16_t element_mode /* i : element mode */ #ifdef MASA_AND_OBJECTS , - ISM_MODE ism_mode, /* i : ISM format mode */ - int16_t nchan_ism, /* i : number of ism channels */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const int16_t nchan_ism, /* i : number of ism channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - int16_t idx_separated_object, /* i : index of the separated object */ + const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ #endif ); @@ -5102,56 +5117,93 @@ void ivas_filter_process( const int16_t length /* i : filter order */ ); + #ifdef MASA_AND_OBJECTS /* ----------------------------------------------------------------------------------* * OMASA prototypes * ----------------------------------------------------------------------------------*/ ivas_error ivas_omasa_enc_open( - Encoder_Struct* st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct* st_ivas /* i/o: IVAS encoder handle */ ); void ivas_omasa_enc_close( - OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ - const int16_t nchan_ism /* i : number of objects */ + OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ + const int16_t nchan_ism /* i : number of objects */ ); void ivas_omasa_set_config( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ - const int32_t input_Fs /* i : Input sample rate */ + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ + const int32_t input_Fs /* i : Input sample rate */ ); void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - float data_in_f[][L_FRAME48k], /* i : Input audio signals for parameter analysis */ - float data_out_f[][L_FRAME48k], /* o : Transport audio signals */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_transport, /* i : Number of transport channels */ - const int16_t nchan_inp, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ - int16_t* idx_separated_object /* o : Index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + float data_in_f[][L_FRAME48k], /* i : Input audio signals for parameter analysis */ + float data_out_f[][L_FRAME48k], /* o : Transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t nchan_transport, /* i : Number of transport channels */ + const int16_t nchan_inp, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ + int16_t* idx_separated_object /* o : Index of the separated object */ +); + +#ifdef OMASA_BRATE +void ivas_set_surplus_brate_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +void ivas_set_surplus_brate_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + int32_t *ism_total_brate /* i : ISM total bit-rate */ +); + +void set_ism_importance_interformat( + const int32_t ism_total_brate, /* i/o: ISms total bitrate */ + const int16_t nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const float lp_noise_CPE, /* i : LP filtered total noise estimation */ + int16_t ism_imp[] /* o : ISM importance flags */ +); + +/*! r: adjusted bitrate */ +int32_t ivas_interformat_brate( + const int32_t element_brate, /* i : element bitrate */ + const int16_t ism_imp /* i : ISM importance flag */ ); +#ifdef OMASA_BRATE_FIX +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int32_t brate_surplus, /* i : surplus bitrate */ + int16_t nb_bits_metadata[], /* i/o: number of metadata bits */ + const int16_t nchan_ism, /* i : number of objects */ + int16_t *diff_nBits /* o : number of differential bits */ +); +#endif +#endif + ISM_MODE ivas_omasa_ism_mode_select( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t no_obj /* i : number of input ISM's */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t no_obj /* i : number of input ISM's */ ); void ivas_merge_masa_transports( - float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ - float data_in_f2[][L_FRAME48k], /* i : Transport audio signals 2 */ - float data_out_f[][L_FRAME48k], /* o : Merged transport audio signals */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t num_transport_channels /* i : Number of transport audio signals */ + float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ + float data_in_f2[][L_FRAME48k], /* i : Transport audio signals 2 */ + float data_out_f[][L_FRAME48k], /* o : Merged transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t num_transport_channels /* i : Number of transport audio signals */ ); void ivas_masa_ism_data_open( - Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); @@ -5165,14 +5217,14 @@ void preProcessStereoTransportsForMovedObjects( ); ivas_error ivas_masa_ism_separate_object_renderer_open( - Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ ); void ivas_masa_ism_separate_object_render( - Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ - float input_f[][L_FRAME48k], /* i : separated object signal */ - float output_f[][L_FRAME48k], /* i/o: output signals */ - const int16_t output_frame /* i : output frame length per channel */ + Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ + float input_f[][L_FRAME48k], /* i : separated object signal */ + float output_f[][L_FRAME48k], /* i/o: output signals */ + const int16_t output_frame /* i : output frame length per channel */ ); void ivas_masa_ism_set_edited_objects( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 2464229096..d7e3bd208f 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2780,18 +2780,23 @@ const float McMASA_LFEGain_vectors[64] = }; #ifdef MASA_AND_OBJECTS - -int32_t sep_object_brate[][MAX_NUM_OBJECTS] ={ - {0, 0, 0, 0}, /* 13k2 */ - {0, 0, 0, 0}, /* 16k4 */ - {9600, 0, 0, 0}, /* 24k4 */ - {9600, 0, 0, 0}, /* 32k */ - {IVAS_13k2, 0, 0, 0}, /* 48k */ - {16000, IVAS_13k2, 0, 0}, /* 64k */ - {20000, 16000, 0, 0}, /* 80k */ - {IVAS_32k, 20000, 0, 0}, /* 96k */ - {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ - {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ +// VE2Nokia: add "const" to the arrays +int32_t sep_object_brate[][MAX_NUM_OBJECTS] = +{ + {0, 0, 0, 0}, /* 13k2 */ + {0, 0, 0, 0}, /* 16k4 */ + {9600, 0, 0, 0}, /* 24k4 */ + {9600, 0, 0, 0}, /* 32k */ + {IVAS_13k2, 0, 0, 0}, /* 48k */ +#ifdef OMASA_BRATE_FIX + {16000, 12500, 0, 0}, /* 64k */ +#else + {16000, IVAS_13k2, 0, 0}, /* 64k */ +#endif + {20000, 16000, 0, 0}, /* 80k */ + {IVAS_32k, 20000, 0, 0}, /* 96k */ + {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ + {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index da715a482e..57420ceea8 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -58,6 +58,11 @@ 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 */ +#ifdef OMASA_BRATE + int16_t ism_imp; /* ISM importance flag */ + int16_t ism_vad_flag; +#endif + } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index 7b3e297d78..6845dbbcaa 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,6 +160,12 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ + +#define MASA_AND_OBJECTS_VE // VA: improve codec print-outs +#define OMASA_BRATE /* VA: combined format bit-budget distribution */ +#define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more work needed +#define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files + #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 8c24412dce..45b9ae6b0d 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -233,19 +233,27 @@ ivas_error ivas_cpe_dec( /* read DFT Stereo side info */ nb_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); #ifdef MASA_AND_OBJECTS +#ifdef OMASA_BRATE + cpe_brate = st_ivas->hCPE[0]->element_brate; +#else cpe_brate = ivas_total_brate; +#endif if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifndef OMASA_BRATE cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); +#endif sts[1]->bit_stream = sts[0]->bit_stream + cpe_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; +#ifdef OMASA_BRATE + sts[1]->bit_stream += hCPE->brate_surplus / FRAMES_PER_SEC; +#endif } else - { #endif + { sts[1]->bit_stream = sts[0]->bit_stream + ivas_total_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; -#ifdef MASA_AND_OBJECTS } -#endif + if ( ivas_total_brate == IVAS_SID_5k2 ) { nb_bits -= SID_FORMAT_NBITS; @@ -269,6 +277,14 @@ ivas_error ivas_cpe_dec( /* subtract metadata bitbudget */ sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); + +#ifdef OMASA_BRATE + /* subtract bit-rate for combined format coding */ + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + sts[0]->total_brate += hCPE->brate_surplus; + } +#endif } else { @@ -287,6 +303,16 @@ ivas_error ivas_cpe_dec( } else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { +#ifdef OMASA_BRATE + /* compute bit-rate surplus per channel in combined format coding */ + int32_t brate_surplus[CPE_CHANNELS]; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; + brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; + } +#endif + if ( is_DTXrate( ivas_total_brate ) == 1 && ( sts[0]->first_CNG == 0 || sts[1]->first_CNG == 0 ) ) { if ( ( error = initMdctStereoDtxData( hCPE ) ) != IVAS_ERR_OK ) @@ -311,6 +337,15 @@ ivas_error ivas_cpe_dec( } sts[n]->bits_frame_nominal = (int16_t) ( sts[n]->total_brate / FRAMES_PER_SEC ); sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_channels ); + +#ifdef OMASA_BRATE + /* subtract bit-rate for combined format coding */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); + sts[n]->total_brate += brate_surplus[n]; + } +#endif } if ( !st_ivas->hMCT ) @@ -579,6 +614,7 @@ ivas_error create_cpe_dec( #ifdef MASA_AND_OBJECTS int32_t cpe_brate; #endif + error = IVAS_ERR_OK; /*-----------------------------------------------------------------* @@ -617,7 +653,7 @@ ivas_error create_cpe_dec( /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ #ifdef MASA_AND_OBJECTS - if (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MC_FORMAT ) + if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MC_FORMAT ) #else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MC_FORMAT ) #endif @@ -628,6 +664,7 @@ ivas_error create_cpe_dec( { hCPE->nchan_out = min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out ); } + #ifdef MASA_AND_OBJECTS if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -637,6 +674,7 @@ ivas_error create_cpe_dec( { cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate; } + if ( ( ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) || ( st_ivas->ivas_format == MASA_ISM_FORMAT && cpe_brate < MASA_STEREO_MIN_BITRATE ) ) && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index d950153165..d0e134f727 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -69,7 +69,7 @@ ivas_error ivas_dec( AUDIO_CONFIG output_config; ivas_error error; #ifdef MASA_AND_OBJECTS - int32_t ism_brate; + int32_t ism_total_brate; #endif error = IVAS_ERR_OK; @@ -550,9 +550,12 @@ ivas_error ivas_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - ism_brate = 0; +#ifndef OMASA_BRATE + ism_total_brate = 0; +#endif st = st_ivas->hCPE[0]->hCoreCoder[0]; +#ifndef OMASA_BRATE if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { st->bit_stream = &( st_ivas->bit_stream[( st_ivas->hSCE[0]->element_brate / FRAMES_PER_SEC )] ); @@ -561,10 +564,11 @@ ivas_error ivas_dec( { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - ism_brate += st_ivas->hSCE[n]->element_brate; + ism_total_brate += st_ivas->hSCE[n]->element_brate; } - st->bit_stream = &( st_ivas->bit_stream[( ism_brate / FRAMES_PER_SEC )] ); + st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); } +#endif nb_bits_metadata[0] = 0; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -588,6 +592,16 @@ ivas_error ivas_dec( return error; } +#ifdef OMASA_BRATE + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); + + st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); +#endif +#ifdef OMASA_BRATE_FIX + ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &n /* temp */ ); +#endif + /* Audio signal decoding */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { @@ -605,7 +619,7 @@ ivas_error ivas_dec( else { /* decode ISM format */ - ivas_ism_metadata_dec( ism_brate, &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL ); + ivas_ism_metadata_dec( ism_total_brate, &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL ); for ( n = 0; n < st_ivas->nSCE - 1; n++ ) { @@ -634,6 +648,7 @@ ivas_error ivas_dec( { mvr2r( output[0], output[1], output_frame ); /* Copy mono signal to stereo output channels */ } + /* HP filtering */ for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 53d103abe1..dcaf13dbd1 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -982,6 +982,13 @@ ivas_error ivas_init_decoder( create_sce_dec( st_ivas, 0, sce_brate ); reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); + +#ifdef OMASA_BRATE // VE: just 'ism_imp' parameter is needed - what about the other parameters? -> TBV + if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); + } +#endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -998,10 +1005,10 @@ ivas_error ivas_init_decoder( { return error; } + reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nSCE, temp_brate ) ) != IVAS_ERR_OK ) { return error; @@ -1017,7 +1024,7 @@ ivas_error ivas_init_decoder( } st_ivas->nCPE = 1; - create_cpe_dec( st_ivas, 0, ( ( ivas_total_brate - sce_brate ) / st_ivas->nchan_transport ) * CPE_CHANNELS ); + create_cpe_dec( st_ivas, 0, ( ( ivas_total_brate - sce_brate ) / st_ivas->nchan_transport ) * CPE_CHANNELS ); // VE2Nokia: could be simplified - nchan_transport is always 2 here for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 658dcaca4b..0d3b5fa572 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -164,7 +164,17 @@ ivas_error ivas_ism_metadata_dec( /* 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 ); +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + /* ISM importance flag is already read in ivas_masa_decode() */ + ism_imp[ch] = hIsmMeta[ch]->ism_imp; + } + else +#endif + { + ism_imp[ch] = get_next_indice( st0, ISM_METADATA_FLAG_BITS ); + } if ( ism_imp[ch] > ISM_NO_META ) { @@ -189,7 +199,17 @@ ivas_error ivas_ism_metadata_dec( { if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - localVAD[ch] = get_next_indice( st0, ISM_METADATA_VAD_FLAG_BITS ); +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + /* VAD flag is already read in ivas_masa_decode() */ + localVAD[ch] = hIsmMeta[ch]->ism_vad_flag; + } + else +#endif + { + localVAD[ch] = get_next_indice( st0, ISM_METADATA_VAD_FLAG_BITS ); + } } else { @@ -469,6 +489,13 @@ ivas_error ivas_ism_metadata_dec( } } +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + ism_metadata_flag_global = 1; + } +#endif + /*----------------------------------------------------------------* * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ @@ -477,12 +504,22 @@ ivas_error ivas_ism_metadata_dec( { #ifdef MASA_AND_OBJECTS int16_t masa_ism_flag = 0; - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) // VE2Nokia: ISM_MASA_MODE_ONE_OBJ looks obsolete here { masa_ism_flag = 1; } #endif +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + for ( ch = 0; ch < *nchan_transport; ch++ ) + { + element_brate[ch] = hSCE[ch]->element_brate; + } + } +#endif + ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata #ifdef MASA_AND_OBJECTS , @@ -506,7 +543,12 @@ ivas_error ivas_ism_metadata_dec( } } - hSCE[ch]->element_brate = element_brate[ch]; +#ifdef OMASA_BRATE + if ( ism_mode != ISM_MASA_MODE_DISC ) +#endif + { + hSCE[ch]->element_brate = element_brate[ch]; + } hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; } @@ -567,6 +609,11 @@ ivas_error create_ism_metadata_dec( st_ivas->hIsmMetaData[ch]->last_azimuth_idx = 0; st_ivas->hIsmMetaData[ch]->last_elevation_idx = 1 << ( ISM_ELEVATION_NBITS - 1 ); +#ifdef OMASA_BRATE + st_ivas->hIsmMetaData[ch]->ism_imp = -1; + st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; +#endif + ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 0eec565504..db86d97fd9 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -98,6 +98,9 @@ ivas_error ivas_masa_decode( ivas_error error; #ifdef MASA_AND_OBJECTS int16_t obj; +#ifdef OMASA_BRATE + int16_t i, ch, ism_imp; +#endif #endif error = IVAS_ERR_OK; @@ -167,6 +170,44 @@ ivas_error ivas_masa_decode( st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; } + +#ifdef OMASA_BRATE + /* read ISM importance flag (one per object) */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + ism_imp = 0; + for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + ism_imp = ( ism_imp << 1 ) + byteBuffer; + } + st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + { + ism_imp = 0; + for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + ism_imp = ( ism_imp << 1 ) + byteBuffer; + } + st_ivas->hIsmMetaData[ch]->ism_imp = ism_imp; + + /* reset */ + st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; + if ( st_ivas->hIsmMetaData[ch]->ism_imp == ISM_NO_META ) + { + /* read VAD flag */ + st_ivas->hIsmMetaData[ch]->ism_vad_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += ISM_METADATA_VAD_FLAG_BITS; + } + } + } +#endif } #endif /* Placeholder for descriptive metadata content */ @@ -365,7 +406,9 @@ ivas_error ivas_masa_decode( } if ( st_ivas->hDirAC != NULL ) { +#ifndef OMASA_BRATE int16_t i; +#endif int16_t b; int16_t block; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c new file mode 100644 index 0000000000..eacc84ef46 --- /dev/null +++ b/lib_dec/ivas_omasa_dec.c @@ -0,0 +1,106 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "options.h" +#include +#include "ivas_cnst.h" +#include "ivas_prot.h" +#include "prot.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + + +#ifdef OMASA_BRATE +/*--------------------------------------------------------------------------* + * ivas_set_surplus_brate_dec() + * + * set bit-rate surplus in combined format coding + *--------------------------------------------------------------------------*/ + +void ivas_set_surplus_brate_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + int32_t *ism_total_brate /* i/o: ISM total bit-rate */ +) +{ + int16_t n, bits_ism, bits_element[MAX_NUM_OBJECTS]; + int32_t ism_total_brate_ref, element_brate[MAX_NUM_OBJECTS]; + + *ism_total_brate = 0; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + *ism_total_brate = ivas_interformat_brate( st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; + + /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_ONE_OBJ mode */ + st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate; + + st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0; + if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 1; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + ism_total_brate_ref = 0; + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + ism_total_brate_ref += st_ivas->hSCE[n]->element_brate; + } + + bits_ism = (int16_t) ( ism_total_brate_ref / FRAMES_PER_SEC ); + set_s( bits_element, bits_ism / st_ivas->nchan_ism, st_ivas->nchan_ism ); + bits_element[st_ivas->nchan_ism - 1] += bits_ism % st_ivas->nchan_ism; + bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); + + *ism_total_brate = 0; + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + st_ivas->hSCE[n]->element_brate = element_brate[n]; + + *ism_total_brate += ivas_interformat_brate( st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); + } + st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; + + /* 'st->total_brate' is set in ivas_ism_config */ + } + else + { + st_ivas->hCPE[0]->brate_surplus = 0; + } + + return; +} +#endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 9a360f22a2..4cd2565a32 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -178,6 +178,9 @@ ivas_error ivas_sce_dec( { st->total_brate = ivas_total_brate; } +#ifdef OMASA_BRATE + else if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT ) /* note: total_brate[] is set in ivas_ism_config() or ivas_set_surplus_brate_dec() */ +#else #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { @@ -189,6 +192,7 @@ ivas_error ivas_sce_dec( } #endif else if ( st_ivas->ivas_format != ISM_FORMAT ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ +#endif { st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; } @@ -199,7 +203,12 @@ ivas_error ivas_sce_dec( /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ #ifdef MASA_AND_OBJECTS - if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) + if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC +#ifdef OMASA_BRATE + || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ +#endif + ) && + st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) #else if ( st_ivas->ivas_format == ISM_FORMAT && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) #endif diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e028cc6843..30191abcb0 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -670,7 +670,7 @@ typedef struct ivas_dirac_dec_data_structure int16_t numParametricDirections; /* 1 or 2 */ int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ #else - int16_t numSimultaneousDirections; /* 1 or 2 */ + int16_t numSimultaneousDirections; /* 1 or 2 */ #endif DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; @@ -963,6 +963,10 @@ typedef struct cpe_dec_data_structure float old_out_mdct[STEREO_MDCT2DFT_FADE_LEN_48k]; float old_outLB_mdct[2 * STEREO_MDCT2DFT_FADE_LEN_48k]; +#ifdef OMASA_BRATE + int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ +#endif + } CPE_DEC_DATA, *CPE_DEC_HANDLE; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 3c4a1b1a5c..fab25168be 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1880,7 +1880,11 @@ static ivas_error printConfigInfo_dec( { fprintf( stdout, "Input configuration: MASA - %d channel(s)\n", st_ivas->nchan_transport ); } +#ifdef MASA_AND_OBJECTS_VE + else if ( st_ivas->ivas_format == MC_FORMAT ) +#else else /* MC_FORMAT */ +#endif { if ( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ) != IVAS_ERR_OK ) { @@ -1889,7 +1893,14 @@ static ivas_error printConfigInfo_dec( fprintf( stdout, "Input configuration: %s\n", config_str ); } +#ifdef MASA_AND_OBJECTS_VE + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + fprintf( stdout, "Input configuration: combined ISM and MASA (%i separated ISM stream(s)) \n", st_ivas->nchan_transport ); + } +#endif } + get_channel_config( st_ivas->hDecoderConfig->output_config, &config_str[0] ); fprintf( stdout, "Output configuration: %s\n", config_str ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 3332855cd7..ac489f0f1f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -306,6 +306,16 @@ ivas_error ivas_cpe_enc( if ( hCPE->element_mode == IVAS_CPE_MDCT ) { +#ifdef OMASA_BRATE + /* compute bit-rate surplus per channel in combined format coding */ + int32_t brate_surplus[CPE_CHANNELS]; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; + brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; + } +#endif + /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */ for ( n = 0; n < n_CoreChannels; n++ ) { @@ -323,6 +333,15 @@ ivas_error ivas_cpe_enc( sts[n]->bits_frame_nominal = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_CoreChannels ); sts[n]->total_brate = hCPE->element_brate / n_CoreChannels; + +#ifdef OMASA_BRATE + /* subtract bit-rate for combined format coding */ + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); + sts[n]->total_brate += brate_surplus[n]; + } +#endif } } @@ -562,6 +581,7 @@ ivas_error ivas_cpe_enc( * DFT Stereo residual coding * DFT Stereo parameters writing into the bitstream *----------------------------------------------------------------*/ + #ifdef MASA_AND_OBJECTS cpe_brate = 0; #endif @@ -596,12 +616,16 @@ ivas_error ivas_cpe_enc( /* Write stereo bitstream */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_BRATE + cpe_brate = st_ivas->hCPE[0]->element_brate; +#else cpe_brate = ivas_total_brate; if ( ivas_format == MASA_ISM_FORMAT ) { cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); } +#endif if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && cpe_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) { @@ -655,6 +679,14 @@ ivas_error ivas_cpe_enc( /* subtract metadata bitbudget */ sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); + +#ifdef OMASA_BRATE + /* subtract bit-rate for combined format coding */ + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + sts[0]->total_brate += hCPE->brate_surplus; + } +#endif } /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 16e4080040..3bfa8bcfcc 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -310,7 +310,12 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS else if ( ivas_format == MASA_ISM_FORMAT ) { +#ifndef OMASA_BRATE float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; +#endif +#ifdef OMASA_BRATE_FIX + int16_t diff_nBits = 0; +#endif float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; @@ -327,6 +332,61 @@ ivas_error ivas_enc( /* nb_bits_metadata[0] = 0; */ set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + +#ifdef OMASA_BRATE + /* Configure MASA encoder based on frame parameters */ + ivas_masa_enc_config( st_ivas ); // VE2Nokia: this function should return an error code + idx_separated_object = 0; + + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Configure oMASA analysis based on MASA config */ + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs ); + } + + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[st_ivas->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + + /* put audio object data in SCE's */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + // VE2Nokia: merge the following to one function in order to save some stack memory + float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; + + /* Estimate MASA parameters for the objects */ + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, data_transport_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + + /* Merge transport signals */ + ivas_merge_masa_transports( data_transport_f, &( data_f[st_ivas->nchan_ism] ), data_f, input_frame, st_ivas->nchan_transport ); + } + + /* Encode ISMs transport channels */ + n = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ); /* there are no metadata bits in SCE in this mode */ // VE2Nokia: this function should return an error code + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + /* Analysis, decision about bitrates per channel & core coding */ + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + n = st_ivas->nchan_ism; + } + + /* Encode MASA parameters and write MASA metadata bitstream */ + ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); + + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_enc( st_ivas ); + +#ifdef OMASA_BRATE_FIX + ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &diff_nBits ); +#endif +#else if ( st_ivas->hQMetaData != NULL ) { /* Configure MASA encoder based on frame parameters */ @@ -377,11 +437,49 @@ ivas_error ivas_enc( } n = st_ivas->nchan_ism; } +#endif /* OMASA_BRATE */ + + /* Encode MASA transport channels */ + if ( st_ivas->nCPE == 1 ) // VE2Nokia: this condition is not necessary + { + ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); // VE2Nokia: this condition is unnecessary + } + +#ifdef OMASA_BRATE_FIX + if ( st_ivas->nchan_ism == 1 && st_ivas->hCPE[0]->element_brate < ACELP_12k8_HIGH_LIMIT && diff_nBits > 0 ) + { + while ( diff_nBits > 0 ) + { + i = min( diff_nBits, 16 ); + push_indice( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, IND_UNUSED, 0, i ); + diff_nBits -= i; + } + } +#endif - if ( st_ivas->nCPE == 1 ) /* Stereo DMX */ +#ifdef DEBUG_VA + if ( st_ivas->hSCE[0] != NULL ) { - ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); + float tmpF = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); + } + else + { + for ( i = 0; i < st_ivas->nchan_ism; i++ ) + { + tmpF += st_ivas->hSCE[i]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[i + 1] * 50 ); + } + } + tmpF /= 1000.f; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_ISM" ); + tmpF = ivas_total_brate / 1000.0f - tmpF; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MASA" ); + tmpF = nb_bits_metadata[0] * 50 / 1000.0f; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MD" ); } +#endif } #endif else if ( ivas_format == MC_FORMAT ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 42c4cec050..cb8217d556 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -570,7 +570,8 @@ ivas_error ivas_init_encoder( st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); st_ivas->nchan_transport = 2; - create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ); + + create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ); // VE2Nokia: this function should return an error code /* the values of element_brate_tmp will be re-written in MASA_ISM_FORMAT because they are taken from sep_object_brate[][]*/ if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) @@ -589,7 +590,7 @@ ivas_error ivas_init_encoder( { /* use the bitrate for one object */ sce_brate = sep_object_brate[k - 2][0]; - create_sce_enc( st_ivas, 0, sce_brate ); + create_sce_enc( st_ivas, 0, sce_brate ); // VE2Nokia: this function should return an error code /* prepare bitstream buffers */ st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list[0]; @@ -604,7 +605,7 @@ ivas_error ivas_init_encoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { sce_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); + create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); // VE2Nokia: this function should return an error code /* prepare bitstream buffers */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; @@ -614,8 +615,12 @@ ivas_error ivas_init_encoder( reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); } } + + // VE2Nokia: following functions should return an error code ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); + ivas_masa_enc_open( st_ivas ); + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { ivas_omasa_enc_open( st_ivas ); @@ -628,6 +633,7 @@ ivas_error ivas_init_encoder( { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; } + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - sce_brate ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 4a8a2b181f..8e89ed31ee 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -202,10 +202,20 @@ ivas_error ivas_ism_enc( st_ivas->hDirAC->hParamIsm->flag_noisy_speech = st_ivas->hDirAC->hParamIsm->flag_noisy_speech && st_ivas->hDirAC->hParamIsm->noisy_speech_buffer[i]; } - ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm + ivas_ism_metadata_enc( +#ifdef OMASA_BRATE + &st_ivas->hEncoderConfig->ivas_total_brate, +#else + st_ivas->hEncoderConfig->ivas_total_brate, +#endif + st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm #ifdef MASA_AND_OBJECTS - , - st_ivas->nSCE + , + st_ivas->nSCE +#ifdef OMASA_BRATE + , + -1 +#endif #endif ); } @@ -226,7 +236,19 @@ ivas_error ivas_ism_enc( ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; } +#ifdef OMASA_BRATE + int32_t ism_total_brate_ref = ism_total_brate; + + // VE: change the interface of the following function and call it with 'st_ivas' only + ivas_ism_metadata_enc( &ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ); + + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate; + } +#else ivas_ism_metadata_enc( ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE ); +#endif #else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL ); #endif diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index fa2c4a1bd9..78997e6e79 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -138,6 +138,75 @@ static void rate_ism_importance( return; } + +#ifdef OMASA_BRATE +/*-------------------------------------------------------------------------* + * set_ism_importance_interformat() + * + * Set the importance of particular ISM streams in combined-format coding + *-------------------------------------------------------------------------*/ + +void set_ism_importance_interformat( + const int32_t ism_total_brate, /* i/o: ISms total bitrate */ + const int16_t nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const float lp_noise_CPE, /* i : LP filtered total noise estimation */ + int16_t ism_imp[] /* o : ISM importance flags */ +) +{ + Encoder_State *st; + int16_t ch, ctype, active_flag; + + for ( ch = 0; ch < nchan_transport; ch++ ) + { + st = hSCE[ch]->hCoreCoder[0]; + + active_flag = st->vad_flag; + + if ( active_flag == 0 ) + { + if ( st->lp_noise > 15 || lp_noise_CPE - st->lp_noise < 30 ) + { + active_flag = 1; + } + } + + /* do not use the low-rate core-coder mode at highest bit-rates */ + if ( ism_total_brate / nchan_transport > IVAS_48k ) + { + active_flag = 1; + } + + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + st->low_rate_mode = 0; + if ( active_flag == 0 ) + { + ism_imp[ch] = ISM_INACTIVE_IMP; + st->low_rate_mode = 1; + } + else if ( ctype == INACTIVE || ctype == UNVOICED ) + { + ism_imp[ch] = ISM_LOW_IMP; + } + else if ( ctype == VOICED ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + } + else /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + } + + hIsmMeta[ch]->ism_metadata_flag = active_flag; /* flag is needed for the MD coding */ + } + + return; +} +#endif + + /*-------------------------------------------------------------------------* * ivas_ism_metadata_enc() * @@ -145,7 +214,11 @@ static void rate_ism_importance( *-------------------------------------------------------------------------*/ ivas_error ivas_ism_metadata_enc( - const int32_t ism_total_brate, /* i : ISms total bitrate */ +#ifdef OMASA_BRATE + int32_t *ism_total_brate, /* i/o: ISms total bitrate */ +#else + const int32_t ism_total_brate, /* i : ISms total bitrate */ +#endif 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 */ @@ -156,7 +229,11 @@ ivas_error ivas_ism_metadata_enc( const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ #ifdef MASA_AND_OBJECTS , - int16_t n_ism /* i : number of ism-s */ + const int16_t n_ism /* i : number of objects */ +#ifdef OMASA_BRATE + , + const float lp_noise_CPE +#endif #endif ) { @@ -213,82 +290,104 @@ ivas_error ivas_ism_metadata_enc( set_s( flag_abs_azimuth, 0, num_obj ); set_s( flag_abs_elevation, 0, num_obj ); - /*----------------------------------------------------------------* - * Set Metadata presence / importance flag - *----------------------------------------------------------------*/ +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + n_ch = num_obj; + } + else + { + n_ch = nchan_transport; + } - for ( ch = 0; ch < num_obj; ch++ ) + if ( ism_mode == ISM_MASA_MODE_DISC ) { - if ( ism_mode == ISM_MODE_PARAM ) + /*----------------------------------------------------------------* + * Rate importance of particular ISm streams in combined format coding + *----------------------------------------------------------------*/ + + set_ism_importance_interformat( *ism_total_brate, n_ch, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + } + else +#endif + { + /*----------------------------------------------------------------* + * Set Metadata presence / importance flag + *----------------------------------------------------------------*/ + + for ( ch = 0; ch < num_obj; ch++ ) { - hIsmMeta[ch]->ism_metadata_flag = 1; - } + if ( ism_mode == ISM_MODE_PARAM ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + } #ifdef MASA_AND_OBJECTS - else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) + else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) #else - else if ( ism_mode == ISM_MODE_DISC ) + else if ( ism_mode == ISM_MODE_DISC ) #endif - { - hIsmMeta[ch]->ism_metadata_flag = localVAD[ch]; - - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - /* send metadata even in inactive segments when noise is audible and metadata are changing */ - diff = (int16_t) fabsf( hIsmMeta[ch]->azimuth - ism_dequant_meta( hIsmMeta[ch]->last_azimuth_idx, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ) ); - diff = max( diff, (int16_t) fabsf( hIsmMeta[ch]->elevation - ism_dequant_meta( hIsmMeta[ch]->last_elevation_idx, ism_elevation_borders, 1 << ISM_ELEVATION_NBITS ) ) ); + hIsmMeta[ch]->ism_metadata_flag = localVAD[ch]; - if ( hSCE[ch]->hCoreCoder[0]->lp_noise > 15 && diff >= 10 ) + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - hIsmMeta[ch]->ism_metadata_flag = 1; + /* send metadata even in inactive segments when noise is audible and metadata are changing */ + diff = (int16_t) fabsf( hIsmMeta[ch]->azimuth - ism_dequant_meta( hIsmMeta[ch]->last_azimuth_idx, ism_azimuth_borders, 1 << ISM_AZIMUTH_NBITS ) ); + diff = max( diff, (int16_t) fabsf( hIsmMeta[ch]->elevation - ism_dequant_meta( hIsmMeta[ch]->last_elevation_idx, ism_elevation_borders, 1 << ISM_ELEVATION_NBITS ) ) ); + + if ( hSCE[ch]->hCoreCoder[0]->lp_noise > 15 && diff >= 10 ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + } } - } - if ( hSCE[ch]->hCoreCoder[0]->tcxonly ) - { - /* at highest bitrates (with TCX core only) metadata are sent in every frame */ - hIsmMeta[ch]->ism_metadata_flag = 1; + if ( hSCE[ch]->hCoreCoder[0]->tcxonly ) + { + /* at highest bitrates (with TCX core only) metadata are sent in every frame */ + hIsmMeta[ch]->ism_metadata_flag = 1; + } } } - } - /*----------------------------------------------------------------* - * Rate importance of particular ISm streams - *----------------------------------------------------------------*/ + /*----------------------------------------------------------------* + * Rate importance of particular ISm streams + *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - if ( ism_mode == ISM_MASA_MODE_DISC ) - { - n_ch = num_obj; - } - else - { - n_ch = nchan_transport; - } + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + n_ch = num_obj; + } + else + { + n_ch = nchan_transport; + } - rate_ism_importance( n_ch, hIsmMeta, hSCE, ism_imp ); + rate_ism_importance( n_ch, hIsmMeta, hSCE, ism_imp ); #else - rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); + rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); #endif - /* relax the importance decision in "stereo" coding for noisy audio */ + /* relax the importance decision in "stereo" coding for noisy audio */ #ifdef MASA_AND_OBJECTS - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && num_obj == 2 ) + if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && num_obj == 2 ) #else - if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) + if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) #endif - { - float diff_F; - - if ( hIsmMeta[0]->ism_metadata_flag ^ hIsmMeta[1]->ism_metadata_flag ) { - for ( ch = 0; ch < num_obj; ch++ ) - { - diff_F = hSCE[ch]->hCoreCoder[0]->lp_speech - hSCE[ch]->hCoreCoder[0]->lp_noise; + float diff_F; - if ( hIsmMeta[ch]->ism_metadata_flag == 0 && diff_F < 25.0f ) + if ( hIsmMeta[0]->ism_metadata_flag ^ hIsmMeta[1]->ism_metadata_flag ) + { + for ( ch = 0; ch < num_obj; ch++ ) { - hIsmMeta[ch]->ism_metadata_flag = 1; - ism_imp[ch] = ISM_LOW_IMP; + diff_F = hSCE[ch]->hCoreCoder[0]->lp_speech - hSCE[ch]->hCoreCoder[0]->lp_noise; + + if ( hIsmMeta[ch]->ism_metadata_flag == 0 && diff_F < 25.0f ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + ism_imp[ch] = ISM_LOW_IMP; + } } } } @@ -312,6 +411,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS } #endif + /* write ISm metadata flag (one per object) */ #ifdef MASA_AND_OBJECTS for ( ch = 0; ch < n_ch; ch++ ) @@ -319,7 +419,17 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_transport; ch++ ) #endif { - push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + /* ISM importance flag will be written in ivas_masa_encode() */ + hIsmMeta[ch]->ism_imp = ism_imp[ch]; + } + else +#endif + { + push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); + } } @@ -340,10 +450,28 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_transport; ch++ ) #endif { +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + /* reset */ + hIsmMeta[ch]->ism_vad_flag = 1; + } +#endif + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { /* this flag distinguishes between coding of inactive frame and active frame w/o. metadata */ - push_indice( hBstr, IND_ISM_VAD_FLAG, localVAD[ch], ISM_METADATA_VAD_FLAG_BITS ); +#ifdef OMASA_BRATE + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + /* VAD flag will be written in ivas_masa_encode() */ + hIsmMeta[ch]->ism_vad_flag = localVAD[ch]; + } + else +#endif + { + push_indice( hBstr, IND_ISM_VAD_FLAG, localVAD[ch], ISM_METADATA_VAD_FLAG_BITS ); + } } } } @@ -756,12 +884,40 @@ ivas_error ivas_ism_metadata_enc( } } +#ifdef OMASA_BRATE + /*----------------------------------------------------------------* + * Take into account the combined format bit-budget distribution + *----------------------------------------------------------------*/ + + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; + + bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); + set_s( bits_element, bits_ism / num_obj, num_obj ); + bits_element[num_obj - 1] += bits_ism % num_obj; + bitbudget_to_brate( bits_element, element_brate, num_obj ); + + *ism_total_brate = 0; + for ( ch = 0; ch < num_obj; ch++ ) + { + *ism_total_brate += ivas_interformat_brate( hSCE[ch]->element_brate, ism_imp[ch] ); + } + ism_metadata_flag_global = 1; + } +#endif + /*----------------------------------------------------------------* * Configuration and decision about bitrates per channel *----------------------------------------------------------------*/ + #ifdef MASA_AND_OBJECTS - ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, - ( ism_mode == ISM_MASA_MODE_DISC ) ); +#ifdef OMASA_BRATE + ivas_ism_config( *ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, ism_mode == ISM_MASA_MODE_DISC ); // VE: this funtion should return an error +#else + + ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, ( ism_mode == ISM_MASA_MODE_DISC ) ); +#endif #else ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); #endif @@ -770,9 +926,31 @@ ivas_error ivas_ism_metadata_enc( { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; } + #ifdef MASA_AND_OBJECTS for ( ch = 0; ch < n_ch; ch++ ) { +#ifdef OMASA_BRATE + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; + if ( ism_mode == ISM_MODE_DISC ) + { + if ( hIsmMeta[ch]->ism_metadata_flag == 0 && localVAD[ch] == 0 && ism_metadata_flag_global ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + } + + hSCE[ch]->element_brate = element_brate[ch]; + } + else if ( ism_mode == ISM_MASA_MODE_DISC ) + { + if ( ism_imp[ch] == ISM_INACTIVE_IMP ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + } + } + + hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; @@ -784,6 +962,7 @@ ivas_error ivas_ism_metadata_enc( hSCE[ch]->element_brate = element_brate[ch]; hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; +#endif /* write metadata only in active frames */ if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) @@ -846,7 +1025,7 @@ ivas_error create_ism_metadata_enc( st_ivas->nCPE = 1; st_ivas->nSCE = 1; break; - case ISM_MODE_DISC: + case ISM_MODE_DISC: // VE2Nokia: this cannot happen st_ivas->nCPE = 1; st_ivas->nSCE = n_ISms; break; @@ -855,7 +1034,7 @@ ivas_error create_ism_metadata_enc( st_ivas->nSCE = n_ISms; break; case ISM_MODE_NONE: - if ( nchan_transport == 1 ) + if ( nchan_transport == 1 ) // VE2Nokia: this cannot happen { st_ivas->nSCE = 1; st_ivas->nCPE = 0; @@ -917,6 +1096,11 @@ ivas_error create_ism_metadata_enc( st_ivas->hIsmMetaData[ch]->elevation_diff_cnt = ISM_FEC_MAX - 1; st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; +#ifdef OMASA_BRATE + st_ivas->hIsmMetaData[ch]->ism_imp = -1; + st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; +#endif + ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } #ifdef MASA_AND_OBJECTS diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 0dbecbcb83..5ae88cead3 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -183,6 +183,10 @@ ivas_error ivas_masa_enc_open( set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); hMasa->data.prevq_lfeToTotalEnergyRatio = 0.0f; hMasa->data.prevq_lfeIndex = 0; +#ifdef OMASA_BRATE + hMasa->data.lp_noise_CPE = -1; +#endif + st_ivas->hMasa = hMasa; return error; @@ -244,11 +248,11 @@ void ivas_masa_encode( const int16_t element_mode /* i : element mode */ #ifdef MASA_AND_OBJECTS , - ISM_MODE ism_mode, /* i : ISM format mode */ - int16_t nchan_ism, /* i : number of ism channels */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const int16_t nchan_ism, /* i : number of ism channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - int16_t idx_separated_object, /* i : index of the separated object */ - OMASA_ENC_HANDLE hOMasa /* i: OMASA encoder handle */ + const int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ #endif ) { @@ -347,6 +351,30 @@ void ivas_masa_encode( push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; } + +#ifdef OMASA_BRATE + /* write ISM importance flag (one per object) */ + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + } + else if ( ism_mode == ISM_MASA_MODE_DISC ) + { + for ( i = 0; i < nchan_ism; i++ ) + { + push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + + if ( hIsmMetaData[i]->ism_metadata_flag == 0 ) + { + /* write VAD flag */ + push_next_indice( hMetaData, hIsmMetaData[i]->ism_vad_flag, ISM_METADATA_VAD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_VAD_FLAG_BITS; + } + } + } +#endif } else { @@ -749,6 +777,20 @@ ivas_error ivas_masa_enc_config( #endif } +#ifdef OMASA_BRATE + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) + { + st_ivas->hMasa->data.lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + } + else + { + st_ivas->hMasa->data.lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; + } + } +#endif + return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index ae8e49d1a6..b7258bff9f 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -270,6 +270,8 @@ void ivas_omasa_set_config( { hOMasa->block_grouping[1] = hOMasa->block_grouping[MAX_PARAM_SPATIAL_SUBFRAMES]; } + + return; } @@ -484,6 +486,36 @@ void ivas_omasa_enc( } +#ifdef OMASA_BRATE +/*--------------------------------------------------------------------------* + * ivas_set_surplus_brate_enc() + * + * set bit-rate surplus in combined format coding + *--------------------------------------------------------------------------*/ + +void ivas_set_surplus_brate_enc( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + /* note: ISM st->total_brate is iset in ivas_sce_enc() */ + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + /* it is already set in ivas_ism_enc() */ + } + else + { + st_ivas->hCPE[0]->brate_surplus = 0; + } + + return; +} +#endif + + /*--------------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index f322c3ad3e..7b986c61f8 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -211,6 +211,19 @@ ivas_error ivas_sce_enc( reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode ); +#ifdef OMASA_BRATE + /*----------------------------------------------------------------* + * Combined format coding: get the ISM importance and the bit-rate + *----------------------------------------------------------------*/ + + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); + + st->total_brate = ivas_interformat_brate( hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; + } +#endif + /*----------------------------------------------------------------* * Write IVAS format signaling in SID frames *----------------------------------------------------------------*/ @@ -229,6 +242,12 @@ ivas_error ivas_sce_enc( { st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); } +#ifdef OMASA_BRATE + else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st->low_rate_mode ) + { + st->flag_ACELP16k = 0; + } +#endif else { st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); @@ -329,8 +348,9 @@ ivas_error create_sce_enc( } copy_encoder_config( st_ivas, st, 1 ); + #ifdef MASA_AND_OBJECTS - if ( st_ivas->ism_mode >= ISM_MASA_MODE_PARAM ) + if ( st_ivas->ism_mode >= ISM_MASA_MODE_PARAM ) // VE2Nokia: ??? { st->element_mode = IVAS_SCE; /* To do: Nokia check as this is not optimal and verify if it influences other SCE modes */ } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index f715d1f5f5..bf574dbfcb 100755 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -731,8 +731,11 @@ typedef struct ivas_masa_encoder_data_struct float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t nchan_ism; - +#ifdef OMASA_BRATE + float lp_noise_CPE; /* LP filterend total noise estimation */ +#endif #endif + int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; float *delay_buffer[MASA_MAX_TRANSPORT_CHANNELS]; @@ -930,6 +933,9 @@ typedef struct cpe_enc_data_structure float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ +#ifdef OMASA_BRATE + int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ +#endif #ifdef DEBUGGING int16_t stereo_mode_cmdl; /* stereo mode forced from the commaand-line */ #endif @@ -1095,7 +1101,7 @@ typedef struct /* high-level encoder parameters */ int16_t nchan_transport; /* number of transport channels */ #ifdef MASA_AND_OBJECTS - int16_t nchan_ism; + int16_t nchan_ism; // VE2Nokia: move it under hEncoderConfig, or remove it and replace it by "nchan_inp - 2" in the code #endif int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ int16_t codec_mode; /* Mode1 or Mode2 of core codec */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 1b8460cf07..f97d80e823 100755 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -436,7 +436,11 @@ void stereo_mdct_core_enc( sts[ch]->total_brate = ( sts[ch]->bits_frame_channel + sts[ch]->side_bits_frame_channel ) * FRAMES_PER_SEC; } stereo_bits += SMDCT_NBBITS_SPLIT_RATIO; +#ifdef OMASA_BRATE + assert( ( sts[0]->total_brate + sts[1]->total_brate + ( stereo_bits + signal_bits + meta_bits ) * FRAMES_PER_SEC ) == hCPE->element_brate + hCPE->brate_surplus ); +#else assert( ( sts[0]->total_brate + sts[1]->total_brate + ( stereo_bits + signal_bits + meta_bits ) * FRAMES_PER_SEC ) == hCPE->element_brate ); +#endif assert( hStereoMdct->split_ratio > 0 && hStereoMdct->split_ratio < SMDCT_BITRATE_RATIO_RANGE ); push_next_indice( hBstr, hStereoMdct->split_ratio, SMDCT_NBBITS_SPLIT_RATIO ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index e163b4810f..09e4b1e03f 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -384,7 +384,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( st_ivas = hIvasEnc->st_ivas; switch ( masaVariant ) { - case IVAS_ENC_MASA_1CH: + case IVAS_ENC_MASA_1CH: // VE2Nokia: seems not needeed st_ivas->hEncoderConfig->nchan_inp = 1 + numObjects; st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ break; @@ -1638,9 +1638,14 @@ static ivas_error printConfigInfo_enc( #ifdef MASA_AND_OBJECTS else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { +#ifdef MASA_AND_OBJECTS_VE + fprintf( stdout, "IVAS format: combined ISM and MASA (%i ISM stream(s))\n", hEncoderConfig->nchan_inp - 2 ); +#else fprintf( stdout, "IVAS format: MASA and objects format\n" ); +#endif } #endif + /*-----------------------------------------------------------------* * Print CNG update interval, if DTX is activated *-----------------------------------------------------------------*/ -- GitLab From 190a901b579b2e157d0b1fe7ba3b7cdb4dd0a845 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Jan 2023 20:02:52 +0100 Subject: [PATCH 008/173] two fixes --- lib_com/ivas_rom_com.c | 12 ++++++++---- lib_dec/core_switching_dec.c | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index d7e3bd208f..d9b341460d 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2786,7 +2786,11 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {0, 0, 0, 0}, /* 13k2 */ {0, 0, 0, 0}, /* 16k4 */ {9600, 0, 0, 0}, /* 24k4 */ +#ifdef OMASA_BRATE_FIX + {11000, 0, 0, 0}, /* 32k */ +#else {9600, 0, 0, 0}, /* 32k */ +#endif {IVAS_13k2, 0, 0, 0}, /* 48k */ #ifdef OMASA_BRATE_FIX {16000, 12500, 0, 0}, /* 64k */ @@ -2794,10 +2798,10 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif {20000, 16000, 0, 0}, /* 80k */ - {IVAS_32k, 20000, 0, 0}, /* 96k */ - {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ - {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ - {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ + {IVAS_32k, 20000, 0, 0}, /* 96k */ + {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ + {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ + {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */ diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 2d0e26b52c..46bb05f7aa 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -1039,7 +1039,11 @@ void bandwidth_switching_detect( { st->bws_cnt1 = 0; } - else if ( st->total_brate > ACELP_9k60 && st->last_core_brate < ACELP_9k60 && st->bwidth == SWB && st->last_bwidth == WB ) + else if ( st->total_brate > ACELP_9k60 && st->last_core_brate < ACELP_9k60 && st->bwidth == SWB && st->last_bwidth == WB +#ifdef OMASA_BRATE // VE: !!!!! TBV // VE: this likely breaks BE in pure ISM !!! + && st->last_core_brate != 2450 +#endif + ) { st->bws_cnt1++; } -- GitLab From c9f90ac8595ebb48a2f52d756032f886ab285a14 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Jan 2023 20:21:43 +0100 Subject: [PATCH 009/173] - comments - fix uninitialized value --- lib_com/options.h | 2 +- lib_dec/core_switching_dec.c | 2 +- lib_dec/ivas_cpe_dec.c | 4 ++++ lib_enc/ivas_cpe_enc.c | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 6845dbbcaa..e84936ec19 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,7 @@ #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs #define OMASA_BRATE /* VA: combined format bit-budget distribution */ -#define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more work needed +#define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more verification/tuning needed #define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 46bb05f7aa..3692d7653f 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -1040,7 +1040,7 @@ void bandwidth_switching_detect( st->bws_cnt1 = 0; } else if ( st->total_brate > ACELP_9k60 && st->last_core_brate < ACELP_9k60 && st->bwidth == SWB && st->last_bwidth == WB -#ifdef OMASA_BRATE // VE: !!!!! TBV // VE: this likely breaks BE in pure ISM !!! +#ifdef OMASA_BRATE // VE: !!!!! this breaks BE in pure ISM && st->last_core_brate != 2450 #endif ) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 45b9ae6b0d..99f68de6fc 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -691,6 +691,10 @@ ivas_error create_cpe_dec( set_f( hCPE->prev_synth[n], 0, NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ) ); } +#ifdef OMASA_BRATE + hCPE->brate_surplus = 0; +#endif + /*-----------------------------------------------------------------* * DFT stereo I/O Buffers: allocate and initialize *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index ac489f0f1f..b106ac72ad 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -843,6 +843,10 @@ ivas_error create_cpe_enc( hCPE->hFrontVad[0] = NULL; hCPE->hFrontVad[1] = NULL; +#ifdef OMASA_BRATE + hCPE->brate_surplus = 0; +#endif + /*-----------------------------------------------------------------* * Input memory buffer: allocate and initialize *-----------------------------------------------------------------*/ -- GitLab From 6711b5640735a7707cee13848e0582150a33023c Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 10:54:58 +0100 Subject: [PATCH 010/173] - introduce OMASA_BRATE_FIX_ALT --- lib_com/ivas_ism_config.c | 44 +++++++++++++++++++++++++++++++++++++-- lib_com/ivas_prot.h | 9 ++++++++ lib_com/options.h | 3 ++- lib_dec/ivas_core_dec.c | 12 +++++++++++ lib_dec/ivas_dec.c | 2 ++ lib_enc/ivas_core_enc.c | 40 +++++++++++++++++++++++++++++++++++ lib_enc/ivas_enc.c | 8 +++++++ 7 files changed, 115 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index b5d12c0da2..62f7b4bf4b 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -741,9 +741,47 @@ int32_t ivas_interformat_brate( /*--------------------------------------------------------------- * ivas_combined_format_brate_sanity() * - * + * Sanity check in combined format coding * ---------------------------------------------------------------*/ +#ifdef OMASA_BRATE_FIX_ALT +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int16_t core, /* i : core */ + int32_t *core_brate, /* i/o: core bitrate */ + int16_t *diff_nBits /* o : number of differential bits */ +) +{ + int16_t limit_high, nBits; + + /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by + low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget + for ACELP core-coding @12.8 kHz is too high */ + + if ( element_brate < ACELP_12k8_HIGH_LIMIT ) + { + limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; + nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC ); + + *diff_nBits = nBits - limit_high; + if ( *diff_nBits > 0 ) + { + if ( core == TCX_20_CORE || core == TCX_10_CORE ) + { + *diff_nBits = 0; + } + else /* ACELP core */ + { + *core_brate -= ( *diff_nBits * FRAMES_PER_SEC ); + } + } + } + + return; +} + +#else + void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int32_t brate_surplus, /* i : surplus bitrate */ @@ -762,7 +800,8 @@ void ivas_combined_format_brate_sanity( nBits_CPE += (int16_t) ( brate_surplus / FRAMES_PER_SEC ); nBits_CPE -= ( WB_TBE_0k35 / FRAMES_PER_SEC ); nBits_CPE -= nb_bits_metadata[1]; - nBits_CPE -= 14; + nBits_CPE -= ( IVAS_FORMAT_SIGNALING_NBITS_SBA + 1 ); + nBits_CPE -= 10; *diff_nBits = 0; if ( nchan_ism == 1 && element_brate < ACELP_12k8_HIGH_LIMIT ) @@ -780,3 +819,4 @@ void ivas_combined_format_brate_sanity( } #endif #endif +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 00298890bd..2308525dc6 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5179,6 +5179,14 @@ int32_t ivas_interformat_brate( ); #ifdef OMASA_BRATE_FIX +#ifdef OMASA_BRATE_FIX_ALT +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int16_t core, /* i : core */ + int32_t *core_brate, /* i/o: core bitrate */ + int16_t *diff_nBits /* o : number of differential bits */ +); +#else void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int32_t brate_surplus, /* i : surplus bitrate */ @@ -5188,6 +5196,7 @@ void ivas_combined_format_brate_sanity( ); #endif #endif +#endif ISM_MODE ivas_omasa_ism_mode_select( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ diff --git a/lib_com/options.h b/lib_com/options.h index e84936ec19..02f5388612 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -164,6 +164,7 @@ #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more verification/tuning needed +#define OMASA_BRATE_FIX_ALT #define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index e5cc40cd47..a9f3d1cb85 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -265,6 +265,18 @@ ivas_error ivas_core_dec( } } + +#ifdef OMASA_BRATE_FIX_ALT + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, &( sts[0]->core_brate ), &tmps ); + } +#endif + /*------------------------------------------------------------------* * Core Decoding *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index d0e134f727..b12aadc91d 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -598,8 +598,10 @@ ivas_error ivas_dec( st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); #endif +#ifndef OMASA_BRATE_FIX_ALT #ifdef OMASA_BRATE_FIX ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &n /* temp */ ); +#endif #endif /* Audio signal decoding */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 1ee672efed..78a9f2af1b 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -102,6 +102,9 @@ ivas_error ivas_core_enc( float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; int32_t element_brate, last_element_brate, input_Fs; +#ifdef OMASA_BRATE_FIX_ALT + int16_t diff_nBits; +#endif ivas_error error; push_wmops( "ivas_core_enc" ); @@ -187,6 +190,27 @@ ivas_error ivas_core_enc( } } + +#ifdef OMASA_BRATE_FIX_ALT + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + diff_nBits = 0; + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, &( sts[0]->core_brate ), &diff_nBits ); + } + +#ifdef DEBUG_VA + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT ) + { + diff_nBits = max( diff_nBits, 0 ); + dbgwrite( &diff_nBits, 2, 1, 960, "res/_diff" ); + } +#endif +#endif + /*---------------------------------------------------------------------* * Core Encoding *---------------------------------------------------------------------*/ @@ -405,6 +429,22 @@ ivas_error ivas_core_enc( } } +#ifdef OMASA_BRATE_FIX_ALT + /*------------------------------------------------------------------* + * Write potentially unused bits in combined format coding + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + while ( diff_nBits > 0 ) + { + n = min( diff_nBits, 16 ); + push_indice( sts[0]->hBstr, IND_UNUSED, 0, n ); + diff_nBits -= n; + } + } +#endif + #ifdef DEBUG_MODE_INFO for ( n = 0; n < n_CoreChannels; n++ ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 3bfa8bcfcc..554a6bb8d6 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -313,8 +313,10 @@ ivas_error ivas_enc( #ifndef OMASA_BRATE float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; #endif +#ifndef OMASA_BRATE_FIX_ALT #ifdef OMASA_BRATE_FIX int16_t diff_nBits = 0; +#endif #endif float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; @@ -383,9 +385,11 @@ ivas_error ivas_enc( /* Configuration of combined-format bit-budget distribution */ ivas_set_surplus_brate_enc( st_ivas ); +#ifndef OMASA_BRATE_FIX_ALT #ifdef OMASA_BRATE_FIX ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &diff_nBits ); #endif +#endif #else if ( st_ivas->hQMetaData != NULL ) { @@ -445,7 +449,10 @@ ivas_error ivas_enc( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); // VE2Nokia: this condition is unnecessary } +#ifndef OMASA_BRATE_FIX_ALT #ifdef OMASA_BRATE_FIX + diff_nBits = max( diff_nBits, 0 ); + //dbgwrite( &diff_nBits, 2, 1, 960, "res/_diff" ); if ( st_ivas->nchan_ism == 1 && st_ivas->hCPE[0]->element_brate < ACELP_12k8_HIGH_LIMIT && diff_nBits > 0 ) { while ( diff_nBits > 0 ) @@ -456,6 +463,7 @@ ivas_error ivas_enc( } } #endif +#endif #ifdef DEBUG_VA if ( st_ivas->hSCE[0] != NULL ) -- GitLab From 751cc3904f07bbe09069ea2416f6c8c0e19da552 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 14:01:32 +0100 Subject: [PATCH 011/173] - introduce OMASA_BRATE_TD - fix for 2ISM @64 kbps in ROM table --- lib_com/ivas_rom_com.c | 2 +- lib_com/options.h | 3 ++- lib_dec/ivas_cpe_dec.c | 3 +++ lib_dec/ivas_stereo_switching_dec.c | 4 +++ lib_dec/ivas_stereo_td_dec.c | 42 +++++++++++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 11 ++++++++ lib_enc/ivas_stereo_td_enc.c | 7 +++++ 7 files changed, 70 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index d9b341460d..90c962158d 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2793,7 +2793,7 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = #endif {IVAS_13k2, 0, 0, 0}, /* 48k */ #ifdef OMASA_BRATE_FIX - {16000, 12500, 0, 0}, /* 64k */ + {16000, 12000, 0, 0}, /* 64k */ #else {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif diff --git a/lib_com/options.h b/lib_com/options.h index 02f5388612..033be97812 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -165,6 +165,7 @@ #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more verification/tuning needed #define OMASA_BRATE_FIX_ALT +#define OMASA_BRATE_TD // support of bitrate adaptation n TD stereo - work in progress #define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 99f68de6fc..356789d07f 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -296,6 +296,9 @@ ivas_error ivas_cpe_dec( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); +#ifdef OMASA_BRATE_TD + sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); +#endif if ( st_ivas->hQMetaData != NULL ) { sts[1]->bits_frame_channel -= st_ivas->hQMetaData->metadata_max_bits; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 73ca81c997..bed57060a1 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -767,7 +767,11 @@ ivas_error stereo_memory_dec( if ( hCPE->hCoreCoder[0]->bfi == 0 ) { st = hCPE->hCoreCoder[1]; +#ifdef OMASA_BRATE_TD + hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); +#else hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); +#endif if ( hCPE->hStereoTD->tdm_LRTD_flag ) { diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index d636d12bd7..5ed7a4ed4b 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -94,10 +94,19 @@ void tdm_configure_dec( int16_t tdm_tmp_SM_LRTD_flag; int16_t mod_ct, core, bits_offset; int16_t idx_LRTD_pri_side, tdm_inst_ratio_idx; +#ifdef OMASA_BRATE_TD + int32_t element_brate_adapt; + int16_t bstr_last_pos; +#endif hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; +#ifdef OMASA_BRATE_TD + element_brate_adapt = hCPE->element_brate + hCPE->brate_surplus; + bstr_last_pos = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); +#endif + /*----------------------------------------------------------------* * Decode CoreCoder signaling *----------------------------------------------------------------*/ @@ -123,7 +132,11 @@ void tdm_configure_dec( /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ +#ifdef OMASA_BRATE_TD + sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - nb_bits_metadata - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); +#else sts[1]->coder_type = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); +#endif /* Get the LRTD config flag: 1 = LRTD configuration, favor closer bitrate per channel; 0 = Pri/Sec configuration, bitrates linked wrt. the mono */ @@ -151,19 +164,31 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ /* Get the correlation ratio */ +#ifdef OMASA_BRATE_TD + *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, (int16_t) ( bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); +#else *tdm_ratio_idx = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); +#endif hStereoTD->tdm_use_IAWB_Ave_lpc = 0; if ( sts[1]->coder_type == INACTIVE ) { /* Get the flag on the LPC reusage type (primary channel of ave LPC */ +#ifdef OMASA_BRATE_TD + hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); +#else hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); +#endif hStereoTD->tdm_lp_reuse_flag = 1; } else { /* Get the flag on the LPC reusage */ +#ifdef OMASA_BRATE_TD + hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); +#else hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); +#endif } sts[0]->tdm_LRTD_flag = hStereoTD->tdm_LRTD_flag; /* the flag was already read in function stereo_memory_dec() */ @@ -219,7 +244,11 @@ void tdm_configure_dec( int16_t tmpS = 20; if ( hStereoTD->tdm_LRTD_flag == 0 ) { +#ifdef OMASA_BRATE_TD + tmpS = get_indice_st( sts[0], element_brate_adapt, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); +#else tmpS = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); +#endif } hCPE->hStereoDftDmx->targetGain = usdequant( tmpS, STEREO_TCA_GDMIN, STEREO_TCA_GDSTEP ); hCPE->hStereoDftDmx->targetGain = powf( 10, hCPE->hStereoDftDmx->targetGain ); @@ -228,9 +257,15 @@ void tdm_configure_dec( { if ( hStereoTD->tdm_LRTD_flag == 0 ) { +#ifdef OMASA_BRATE_TD + hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS, STEREO_BITS_TCA_CHAN ); + hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN, STEREO_BITS_TCA_CORRSTATS ); + hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); +#else hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS ), STEREO_BITS_TCA_CHAN ); hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN ), STEREO_BITS_TCA_CORRSTATS ); hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); +#endif } else { @@ -265,7 +300,14 @@ void tdm_configure_dec( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ +#ifdef OMASA_BRATE_TD + tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); +#else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); +#endif return; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b106ac72ad..518b5262bf 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -166,6 +166,14 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { + +#ifdef OMASA_BRATE_TD // VE: !!!!! temp hack only + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + hCPE->stereo_mode_cmdl = IVAS_CPE_DFT; + } +#endif + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } @@ -396,6 +404,9 @@ ivas_error ivas_cpe_enc( /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); +#ifdef OMASA_BRATE_TD + sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); +#endif if ( st_ivas->hQMetaData != NULL ) { sts[1]->bits_frame_channel -= st_ivas->hQMetaData->metadata_max_bits; diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 4823e2b5f1..4858131c34 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -452,7 +452,14 @@ void tdm_configure_enc( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ +#ifdef OMASA_BRATE_TD + tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); +#else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); +#endif if ( sts[0]->GSC_IVAS_mode > 0 && sts[0]->total_brate <= STEREO_GSC_BIT_RATE_ALLOC ) { -- GitLab From 3f8246afb1a1616ac64b390de954f4dee22f08cd Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 14:43:30 +0100 Subject: [PATCH 012/173] debugging code to force TD stereo --- lib_enc/ivas_cpe_enc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 518b5262bf..5e87ea5247 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -171,6 +171,7 @@ ivas_error ivas_cpe_enc( if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { hCPE->stereo_mode_cmdl = IVAS_CPE_DFT; + //hCPE->stereo_mode_cmdl = IVAS_CPE_TD; } #endif -- GitLab From a40cb66218a9a26240a7cb123033aa7e1a05c44b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 16:08:14 +0100 Subject: [PATCH 013/173] - patch for MDCT stereo 2 x TCX10_CORE (deactivated) --- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_stereo_mdct_core_enc.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 5ae88cead3..7986196a08 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2160,7 +2160,7 @@ static int16_t index_slice_enum( i = 0; while ( i <= x ) { - if ( valid( i, 7, no_ism - 1 ) ) + if ( valid_ratio_index( i, 7, no_ism - 1 ) ) { index++; } diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index f97d80e823..46f524fa4b 100755 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -175,6 +175,15 @@ void stereo_mdct_core_enc( sts[0]->hTcxEnc->tfm_mem = sts[1]->hTcxEnc->tfm_mem = sqrtf( 0.5f * ( sts[0]->hTcxEnc->tfm_mem * sts[0]->hTcxEnc->tfm_mem + sts[1]->hTcxEnc->tfm_mem * sts[1]->hTcxEnc->tfm_mem ) ); /* RMS */ sts[0]->hTcxEnc->tcxltp_norm_corr_past = sts[1]->hTcxEnc->tcxltp_norm_corr_past = 0.5f * ( sts[0]->hTcxEnc->tcxltp_norm_corr_past + sts[1]->hTcxEnc->tcxltp_norm_corr_past ); + +#if 0 + if ( sts[0]->bits_frame_channel + sts[1]->bits_frame_channel - meta_bits < 495 ) + { + sts[0]->hTranDet->transientDetector.bIsAttackPresent = 0; + sts[1]->hTranDet->transientDetector.bIsAttackPresent = 0; + } +#endif + for ( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; -- GitLab From 7972e6ea96fe1d3a9c2af88749d4d1413cded808 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 16:10:20 +0100 Subject: [PATCH 014/173] - add 'ism_mode' parameter to the ivas_interformat_brate() - remove patch for MDCT stereo 2 x TCX10_CORE (deactivated) - rename function valid() to valid_ratio_index() + formatting --- lib_com/ivas_ism_config.c | 11 ++++++- lib_com/ivas_masa_com.c | 57 +++++++++++++++++++++++++-------- lib_com/ivas_prot.h | 31 ++++++++++-------- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 4 +-- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 2 +- 8 files changed, 76 insertions(+), 35 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 62f7b4bf4b..8774bd9105 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -683,9 +683,11 @@ ISM_MODE ivas_omasa_ism_mode_select( #define GAMMA_ISM_LOW_IMP 0.8f #define GAMMA_ISM_MEDIUM_IMP 1.2f #define GAMMA_ISM_HIGH_IMP 1.4f +#define GAMMA_ISM_HIGH_IMP2 1.35f /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( + const ISM_MODE ism_mode, /* i : ISM mode */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ ) @@ -709,7 +711,14 @@ int32_t ivas_interformat_brate( } else /* ISM_HIGH_IMP */ { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP ); + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 ); + } + else + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP ); + } } limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC; diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 920985e81d..9211ec057d 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -422,17 +422,20 @@ void masa_sample_rate_band_correction( return; } + #ifdef MASA_AND_OBJECTS /*--------------------------------------------------------------- - * valid() + * valid_ratio_index() * * Checking validity of the index of an ISM ratio index vector, * within the indexing function. *---------------------------------------------------------------*/ -int16_t valid( /* o: valid or not 1/0 */ - int16_t index, /* i: index to be checked */ - int16_t K, /* i: L1 norm to check against */ - int16_t len /* i: vector length */ + +/*! r: valid or not 1/0 */ +int16_t valid_ratio_index( + int16_t index, /* i : index to be checked */ + const int16_t K, /* i : L1 norm to check against */ + const int16_t len /* i : vector length */ ) { int16_t out; @@ -462,39 +465,47 @@ int16_t valid( /* o: valid or not 1/0 */ { out = 0; } + return out; } + /*--------------------------------------------------------------- * reconstruct_ism_ratios() * * Obtains ISM ratio values from the quantized indexes *---------------------------------------------------------------*/ + void reconstruct_ism_ratios( - int16_t *ratio_ism_idx, /* i: index vector */ - int16_t n_ism, /* i: number of components/objects */ - float step, /* i: quantization step */ - float *q_energy_ratio_ism /* o: reconstructed ISM values */ + int16_t *ratio_ism_idx, /* i : index vector */ + int16_t n_ism, /* i : number of components/objects */ + float step, /* i : quantization step */ + float *q_energy_ratio_ism /* o : reconstructed ISM values */ ) { int16_t i; float sum; + sum = 0; for ( i = 0; i < n_ism - 1; i++ ) { q_energy_ratio_ism[i] = ratio_ism_idx[i] * step; sum += q_energy_ratio_ism[i]; } + q_energy_ratio_ism[n_ism - 1] = 1.0f - sum; + return; } + /*--------------------------------------------------------------- * modify_masa_energy_ratios() * * Updates energy ratios by taking into account the MASA content contribution * to the total audio scene *---------------------------------------------------------------*/ + void modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData /* i/o: Metadata handle */ ) @@ -519,13 +530,18 @@ void modify_masa_energy_ratios( } } } + + return; } + /*--------------------------------------------------------------- * ivas_get_stereo_panning_gains() * * + *---------------------------------------------------------------*/ + void ivas_get_stereo_panning_gains( float aziDeg, float eleDeg, @@ -559,13 +575,17 @@ void ivas_get_stereo_panning_gains( panningGains[0] = sqrtf( A3 ); panningGains[1] = sqrtf( 1.0f - A3 ); } + + return; } + /*--------------------------------------------------------------- * distribute_evenly_ism() * * Obtain ISM ratio indexes for even content distribution bbetween objects *---------------------------------------------------------------*/ + void distribute_evenly_ism( int16_t *idx, /* o: index values */ int16_t K, /* i: sum of indexes */ @@ -574,13 +594,16 @@ void distribute_evenly_ism( { int16_t i; int16_t sum; + sum = 0; for ( i = 0; i < no_ism; i++ ) { idx[i] = (int16_t) ( K / no_ism ); sum += idx[i]; } + assert( sum <= K ); + i = 0; while ( sum < K ) { @@ -592,19 +615,24 @@ void distribute_evenly_ism( sum++; i++; } + + return; } + /*--------------------------------------------------------------- * calculate_cpe_brate_MASA_ISM() * * Calculates bitrate for MASA_ISM mode that is not used for separated objects, * * but for the CPE part (metadata included) *---------------------------------------------------------------*/ -int32_t /* o: cpe bitrate value */ -calculate_cpe_brate_MASA_ISM( - ISM_MODE ism_mode, /* i: ism mode */ - int32_t ivas_total_brate, /* i: total bit rate for IVAS */ - int16_t n_ism ) /* i: number of objects */ + +/*! r: CPE bitrate value */ +int32_t calculate_cpe_brate_MASA_ISM( + const ISM_MODE ism_mode, /* i : ism mode */ + const int32_t ivas_total_brate, /* i : total bit rate for IVAS */ + const int16_t n_ism /* i : number of objects */ +) { int32_t cpe_brate; int16_t k, sce_id; @@ -632,6 +660,7 @@ calculate_cpe_brate_MASA_ISM( { cpe_brate = ivas_total_brate; } + return cpe_brate; } #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 2308525dc6..d2101fe446 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4535,10 +4535,11 @@ void ivas_masa_set_elements( ); #ifdef MASA_AND_OBJECTS -int16_t valid( - int16_t index, - int16_t K, - int16_t len +/*! r: valid or not 1/0 */ +int16_t valid_ratio_index( + int16_t index, /* i : index to be checked */ + const int16_t K, /* i : L1 norm to check against */ + const int16_t len /* i : vector length */ ); void reconstruct_ism_ratios( @@ -4567,16 +4568,17 @@ int16_t ivas_qmetadata_encode_extended_gr_length( const int16_t gr_param); void ivas_qmetadata_encode_extended_gr( - BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */ - const uint16_t value, /* i : value to be encoded */ - const uint16_t alphabet_size, /* i : alphabet size */ - const int16_t gr_param); /* i : GR order */ - -int32_t /* o: cpe bitrate value */ -calculate_cpe_brate_MASA_ISM( - ISM_MODE ism_mode, /* i: ism mode */ - int32_t ivas_total_brate, /* i: total bit rate for IVAS */ - int16_t n_ism ); /* i: number of objects */ + BSTR_ENC_HANDLE hMetaData, /* i/o: q_metadata handle */ + const uint16_t value, /* i : value to be encoded */ + const uint16_t alphabet_size, /* i : alphabet size */ + const int16_t gr_param); /* i : GR order */ + +/*! r: CPE bitrate value */ +int32_t calculate_cpe_brate_MASA_ISM( + const ISM_MODE ism_mode, /* i : ism mode */ + const int32_t ivas_total_brate, /* i : total bit rate for IVAS */ + const int16_t n_ism /* i : number of objects */ +); #endif void ivas_masa_set_coding_config( @@ -5174,6 +5176,7 @@ void set_ism_importance_interformat( /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( + const ISM_MODE ism_mode, /* i : ISM mode */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ ); diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index db86d97fd9..83c194dbd2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1654,7 +1654,7 @@ static void decode_index_slice( j = 0; while ( index >= 0 ) { - if ( valid( j, K, no_ism - 1 ) ) + if ( valid_ratio_index( j, K, no_ism - 1 ) ) { index--; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index eacc84ef46..133369e94c 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -59,7 +59,7 @@ void ivas_set_surplus_brate_dec( if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - *ism_total_brate = ivas_interformat_brate( st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; @@ -90,7 +90,7 @@ void ivas_set_surplus_brate_dec( { st_ivas->hSCE[n]->element_brate = element_brate[n]; - *ism_total_brate += ivas_interformat_brate( st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); + *ism_total_brate += ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 78997e6e79..d2a073d2b8 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -901,7 +901,7 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < num_obj; ch++ ) { - *ism_total_brate += ivas_interformat_brate( hSCE[ch]->element_brate, ism_imp[ch] ); + *ism_total_brate += ivas_interformat_brate( ism_mode, hSCE[ch]->element_brate, ism_imp[ch] ); } ism_metadata_flag_global = 1; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index b7258bff9f..8ef74b4e3a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -499,7 +499,7 @@ void ivas_set_surplus_brate_enc( { if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 7b986c61f8..de1c0466ce 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -220,7 +220,7 @@ ivas_error ivas_sce_enc( { set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); - st->total_brate = ivas_interformat_brate( hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; + st->total_brate = ivas_interformat_brate( st_ivas->ism_mode, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; } #endif -- GitLab From fc2c6e4cba44208ab658396285775e2fb0cbdd6d Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 17:14:54 +0100 Subject: [PATCH 015/173] - debug code --- lib_com/options.h | 2 +- lib_enc/ivas_omasa_enc.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 033be97812..faa13745cd 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,7 +165,7 @@ #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more verification/tuning needed #define OMASA_BRATE_FIX_ALT -#define OMASA_BRATE_TD // support of bitrate adaptation n TD stereo - work in progress +#define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo - work in progress #define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 8ef74b4e3a..5ea2b75a3e 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -476,8 +476,11 @@ void ivas_omasa_enc( /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); - } +#ifdef DEBUG_VA + dbgwrite( &selected_object, 2, 1, input_frame, "res/selected_object" ); +#endif + } /* Downmix */ ivas_omasa_dmx( data_in_f, data_out_f, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains, hOMasa->interpolator ); -- GitLab From 433c2e2f68aaec05ee753fe6c0836ca4ebcfa9b6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 19:59:55 +0100 Subject: [PATCH 016/173] - updates within OMASA_BRATE_TD - remove the encoder hack within OMASA_BRATE_TD --- lib_dec/ivas_stereo_td_dec.c | 8 ++++++-- lib_enc/ivas_cpe_enc.c | 9 --------- lib_enc/ivas_stereo_td_enc.c | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 5ed7a4ed4b..2e6e447bd7 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -133,7 +133,7 @@ void tdm_configure_dec( /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ #ifdef OMASA_BRATE_TD - sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - nb_bits_metadata - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); + sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); #else sts[1]->coder_type = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); #endif @@ -245,7 +245,7 @@ void tdm_configure_dec( if ( hStereoTD->tdm_LRTD_flag == 0 ) { #ifdef OMASA_BRATE_TD - tmpS = get_indice_st( sts[0], element_brate_adapt, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); + tmpS = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); #else tmpS = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); #endif @@ -285,7 +285,11 @@ void tdm_configure_dec( #endif /* set the BW of the secondary channel */ +#ifdef OMASA_BRATE_TD + if ( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel > IVAS_16k4 / FRAMES_PER_SEC ) +#else if ( hStereoTD->tdm_LRTD_flag && hCPE->element_brate > IVAS_13k2 ) +#endif { /* set BW of the secondary channel in LRTD stereo mode as the BW of the primary channel at higher bitrates */ sts[1]->bwidth = sts[0]->bwidth; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 5e87ea5247..536272a94c 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -166,15 +166,6 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { - -#ifdef OMASA_BRATE_TD // VE: !!!!! temp hack only - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) - { - hCPE->stereo_mode_cmdl = IVAS_CPE_DFT; - //hCPE->stereo_mode_cmdl = IVAS_CPE_TD; - } -#endif - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 4858131c34..c42b2fe748 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -419,6 +419,23 @@ void tdm_configure_enc( sts[1]->coder_type = GENERIC; } +#ifdef OMASA_BRATE_TD + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) + { + sts[1]->coder_type = INACTIVE; + hStereoTD->tdm_Pitch_reuse_flag = 0; + hStereoTD->tdm_lp_reuse_flag = 1; + } + + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 14700 ) + { + if ( sts[0]->coder_type == TRANSITION ) + { + sts[0]->coder_type = GENERIC; + } + } +#endif + mod_ct = AUDIO; if ( hCPE->element_brate < IVAS_24k4 ) { @@ -830,4 +847,6 @@ void stereo_tdm_prep_dwnmx( } } } + + return; } -- GitLab From b8248b67c42e26e39528109e3bfb1b982d1ea498 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 20:18:37 +0100 Subject: [PATCH 017/173] merge OMASA_BRATE_FIX and OMASA_BRATE_FIX_ALT into OMASA_BRATE --- lib_com/ivas_ism_config.c | 41 ------------------------------------ lib_com/ivas_prot.h | 13 ------------ lib_com/ivas_rom_com.c | 4 ++-- lib_com/options.h | 4 +--- lib_dec/core_switching_dec.c | 2 +- lib_dec/ivas_core_dec.c | 3 +-- lib_dec/ivas_dec.c | 5 ----- lib_dec/ivas_init_dec.c | 2 +- lib_enc/ivas_core_enc.c | 7 +++--- lib_enc/ivas_enc.c | 26 ----------------------- 10 files changed, 9 insertions(+), 98 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 8774bd9105..215c553168 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -743,17 +743,14 @@ int32_t ivas_interformat_brate( return element_brate_out; } -#endif -#ifdef OMASA_BRATE_FIX /*--------------------------------------------------------------- * ivas_combined_format_brate_sanity() * * Sanity check in combined format coding * ---------------------------------------------------------------*/ -#ifdef OMASA_BRATE_FIX_ALT void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int16_t core, /* i : core */ @@ -789,43 +786,5 @@ void ivas_combined_format_brate_sanity( return; } -#else - -void ivas_combined_format_brate_sanity( - const int32_t element_brate, /* i : element bitrate */ - const int32_t brate_surplus, /* i : surplus bitrate */ - int16_t nb_bits_metadata[], /* i/o: number of metadata bits */ - const int16_t nchan_ism, /* i : number of objects */ - int16_t *diff_nBits /* o : number of differential bits */ -) -{ - /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by - low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget - for core-coding @12.8 kHz is too high => increase the ISM low-rate mode bit-rate */ - - int16_t nBits_CPE; - nBits_CPE = (int16_t) ( element_brate / FRAMES_PER_SEC ); - nBits_CPE -= nb_bits_metadata[0]; - nBits_CPE += (int16_t) ( brate_surplus / FRAMES_PER_SEC ); - nBits_CPE -= ( WB_TBE_0k35 / FRAMES_PER_SEC ); - nBits_CPE -= nb_bits_metadata[1]; - nBits_CPE -= ( IVAS_FORMAT_SIGNALING_NBITS_SBA + 1 ); - nBits_CPE -= 10; - - *diff_nBits = 0; - if ( nchan_ism == 1 && element_brate < ACELP_12k8_HIGH_LIMIT ) - { - int16_t limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; - - *diff_nBits = nBits_CPE - limit_high; - if ( *diff_nBits > 0 ) - { - nb_bits_metadata[0] += *diff_nBits; - } - } - - return; -} -#endif #endif #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d2101fe446..135c3a6321 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5181,24 +5181,12 @@ int32_t ivas_interformat_brate( const int16_t ism_imp /* i : ISM importance flag */ ); -#ifdef OMASA_BRATE_FIX -#ifdef OMASA_BRATE_FIX_ALT void ivas_combined_format_brate_sanity( const int32_t element_brate, /* i : element bitrate */ const int16_t core, /* i : core */ int32_t *core_brate, /* i/o: core bitrate */ int16_t *diff_nBits /* o : number of differential bits */ ); -#else -void ivas_combined_format_brate_sanity( - const int32_t element_brate, /* i : element bitrate */ - const int32_t brate_surplus, /* i : surplus bitrate */ - int16_t nb_bits_metadata[], /* i/o: number of metadata bits */ - const int16_t nchan_ism, /* i : number of objects */ - int16_t *diff_nBits /* o : number of differential bits */ -); -#endif -#endif #endif ISM_MODE ivas_omasa_ism_mode_select( @@ -5218,7 +5206,6 @@ void ivas_masa_ism_data_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); - void preProcessStereoTransportsForMovedObjects( Decoder_Struct* st_ivas, float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 90c962158d..b42fb64fc4 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2786,13 +2786,13 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {0, 0, 0, 0}, /* 13k2 */ {0, 0, 0, 0}, /* 16k4 */ {9600, 0, 0, 0}, /* 24k4 */ -#ifdef OMASA_BRATE_FIX +#ifdef OMASA_BRATE {11000, 0, 0, 0}, /* 32k */ #else {9600, 0, 0, 0}, /* 32k */ #endif {IVAS_13k2, 0, 0, 0}, /* 48k */ -#ifdef OMASA_BRATE_FIX +#ifdef OMASA_BRATE {16000, 12000, 0, 0}, /* 64k */ #else {16000, IVAS_13k2, 0, 0}, /* 64k */ diff --git a/lib_com/options.h b/lib_com/options.h index faa13745cd..9ce2430088 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,9 +163,7 @@ #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs #define OMASA_BRATE /* VA: combined format bit-budget distribution */ -#define OMASA_BRATE_FIX // fix at lowest bitrates and 1 inactive ISM - more verification/tuning needed -#define OMASA_BRATE_FIX_ALT -#define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo - work in progress +#define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo #define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 3692d7653f..8818e0b3ff 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -1040,7 +1040,7 @@ void bandwidth_switching_detect( st->bws_cnt1 = 0; } else if ( st->total_brate > ACELP_9k60 && st->last_core_brate < ACELP_9k60 && st->bwidth == SWB && st->last_bwidth == WB -#ifdef OMASA_BRATE // VE: !!!!! this breaks BE in pure ISM +#ifdef OMASA_BRATE // VE: !!!!! this breaks BE in pure ISM unless FIX_299_ISM_BWS is activated && st->last_core_brate != 2450 #endif ) diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index a9f3d1cb85..777cc74beb 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -265,8 +265,7 @@ ivas_error ivas_core_dec( } } - -#ifdef OMASA_BRATE_FIX_ALT +#ifdef OMASA_BRATE /*------------------------------------------------------------------* * Sanity check in combined format coding *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index b12aadc91d..df5cfb4253 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -597,11 +597,6 @@ ivas_error ivas_dec( ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); -#endif -#ifndef OMASA_BRATE_FIX_ALT -#ifdef OMASA_BRATE_FIX - ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &n /* temp */ ); -#endif #endif /* Audio signal decoding */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index dcaf13dbd1..2c2a26b315 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -983,7 +983,7 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); -#ifdef OMASA_BRATE // VE: just 'ism_imp' parameter is needed - what about the other parameters? -> TBV +#ifdef OMASA_BRATE if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 78a9f2af1b..c4f4b376c6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -102,7 +102,7 @@ ivas_error ivas_core_enc( float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; int32_t element_brate, last_element_brate, input_Fs; -#ifdef OMASA_BRATE_FIX_ALT +#ifdef OMASA_BRATE int16_t diff_nBits; #endif ivas_error error; @@ -190,8 +190,7 @@ ivas_error ivas_core_enc( } } - -#ifdef OMASA_BRATE_FIX_ALT +#ifdef OMASA_BRATE /*------------------------------------------------------------------* * Sanity check in combined format coding *-----------------------------------------------------------------*/ @@ -429,7 +428,7 @@ ivas_error ivas_core_enc( } } -#ifdef OMASA_BRATE_FIX_ALT +#ifdef OMASA_BRATE /*------------------------------------------------------------------* * Write potentially unused bits in combined format coding *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 554a6bb8d6..be021a9493 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -312,11 +312,6 @@ ivas_error ivas_enc( { #ifndef OMASA_BRATE float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; -#endif -#ifndef OMASA_BRATE_FIX_ALT -#ifdef OMASA_BRATE_FIX - int16_t diff_nBits = 0; -#endif #endif float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; @@ -385,11 +380,6 @@ ivas_error ivas_enc( /* Configuration of combined-format bit-budget distribution */ ivas_set_surplus_brate_enc( st_ivas ); -#ifndef OMASA_BRATE_FIX_ALT -#ifdef OMASA_BRATE_FIX - ivas_combined_format_brate_sanity( st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->brate_surplus, nb_bits_metadata, st_ivas->nchan_ism, &diff_nBits ); -#endif -#endif #else if ( st_ivas->hQMetaData != NULL ) { @@ -449,22 +439,6 @@ ivas_error ivas_enc( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); // VE2Nokia: this condition is unnecessary } -#ifndef OMASA_BRATE_FIX_ALT -#ifdef OMASA_BRATE_FIX - diff_nBits = max( diff_nBits, 0 ); - //dbgwrite( &diff_nBits, 2, 1, 960, "res/_diff" ); - if ( st_ivas->nchan_ism == 1 && st_ivas->hCPE[0]->element_brate < ACELP_12k8_HIGH_LIMIT && diff_nBits > 0 ) - { - while ( diff_nBits > 0 ) - { - i = min( diff_nBits, 16 ); - push_indice( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, IND_UNUSED, 0, i ); - diff_nBits -= i; - } - } -#endif -#endif - #ifdef DEBUG_VA if ( st_ivas->hSCE[0] != NULL ) { -- GitLab From cb723a90e022e1675c1f977824de7ed691ca658e Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Jan 2023 23:39:10 +0100 Subject: [PATCH 018/173] - FIX_24k4_ISM1_MODE - activate DISC mode at 24.4 kbps 1 object --- lib_com/ivas_ism_config.c | 16 +++++++++++++++- lib_com/options.h | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 215c553168..dc715e8c69 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -600,14 +600,20 @@ ISM_MODE ivas_omasa_ism_mode_select( switch ( no_obj ) { case 1: +#ifdef FIX_24k4_ISM1_MODE + if ( ivas_total_brate >= IVAS_24k4 ) +#else if ( ivas_total_brate >= IVAS_32k ) +#endif { ism_mode = ISM_MASA_MODE_DISC; } +#ifndef FIX_24k4_ISM1_MODE else if ( ivas_total_brate >= IVAS_24k4 ) { ism_mode = ISM_MASA_MODE_PARAM; } +#endif else { ism_mode = ISM_MODE_NONE; @@ -681,6 +687,7 @@ ISM_MODE ivas_omasa_ism_mode_select( * ---------------------------------------------------------------*/ #define GAMMA_ISM_LOW_IMP 0.8f +#define GAMMA_ISM_LOW_IMP2 0.9f #define GAMMA_ISM_MEDIUM_IMP 1.2f #define GAMMA_ISM_HIGH_IMP 1.4f #define GAMMA_ISM_HIGH_IMP2 1.35f @@ -703,7 +710,14 @@ int32_t ivas_interformat_brate( } else if ( ism_imp == ISM_LOW_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); + if ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 ); + } + else + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); + } } else if ( ism_imp == ISM_MEDIUM_IMP ) { diff --git a/lib_com/options.h b/lib_com/options.h index 9ce2430088..e7ec2bf9ae 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -161,6 +161,7 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ +#define FIX_24k4_ISM1_MODE // activate DISC mode at 24.4 kbps 1 object #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo -- GitLab From ae50cf1e2fb2741053f2b9f3156bfc754033873c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Jan 2023 10:23:33 +0100 Subject: [PATCH 019/173] - tuning for 24.4 kbps 1-Obj - introduce file ivas_omasa_com.c - editorial improvements (formatting, 'const', comments) --- Workspace_msvc/lib_com.vcxproj | 3 +- Workspace_msvc/lib_com.vcxproj.filters | 3 + lib_com/ivas_cnst.h | 11 +- lib_com/ivas_ism_config.c | 134 +------------- lib_com/ivas_omasa_com.c | 182 ++++++++++++++++++++ lib_com/ivas_prot.h | 18 +- lib_com/ivas_rom_com.c | 6 + lib_com/options.h | 2 +- lib_dec/ivas_dirac_dec_binaural_functions.c | 25 ++- lib_dec/ivas_qmetadata_dec.c | 30 ++-- lib_enc/ivas_ism_metadata_enc.c | 68 -------- lib_enc/ivas_omasa_enc.c | 124 +++++++++---- lib_enc/ivas_qmetadata_enc.c | 84 +++++---- 13 files changed, 396 insertions(+), 294 deletions(-) create mode 100644 lib_com/ivas_omasa_com.c diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index 994b1ec429..43f7d56fe6 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -254,6 +254,7 @@ + @@ -358,4 +359,4 @@ - + \ No newline at end of file diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index f9d7920ca2..5b96c4d130 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -463,6 +463,9 @@ common_ivas_c + + common_ivas_c + diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 3e36ec27db..ae19110407 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -316,6 +316,11 @@ typedef enum #define ISM_MEDIUM_IMP 2 #define ISM_HIGH_IMP 3 +#ifdef OMASA_BRATE +#define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM no meta / inactive frames */ +#define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) +#endif + #define ISM_AZIMUTH_NBITS 7 #define ISM_AZIMUTH_MIN -180.0f #define ISM_AZIMUTH_MAX 180.0f @@ -350,9 +355,9 @@ typedef enum ISM_MODE_PARAM /* parametric ISM */ #ifdef MASA_AND_OBJECTS , - ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ - ISM_MASA_MODE_ONE_OBJ, /* MASA ISM mode when one object is encoded separarately */ - ISM_MASA_MODE_DISC + ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ + ISM_MASA_MODE_ONE_OBJ, /* MASA ISM mode when one object is encoded separarately */ + ISM_MASA_MODE_DISC /* MASA ISM mode when all objects are encoded separarately */ #endif } ISM_MODE; diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index dc715e8c69..5a44c7de09 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -50,8 +50,10 @@ #define FRMS_PER_SECOND ( 1000000000 / FRAME_SIZE_NS ) +#ifndef OMASA_BRATE #define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISm inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRMS_PER_SECOND ) +#endif #define BETA_ISM_LOW_IMP 0.6f #define BETA_ISM_MEDIUM_IMP 0.8f @@ -115,7 +117,6 @@ ivas_error ivas_ism_config( int16_t n_ISms; ivas_error error; - error = IVAS_ERR_OK; #ifdef MASA_AND_OBJECTS if ( combined_format_flag == 1 ) @@ -425,11 +426,13 @@ void ivas_ism_reset_metadata( return; } + /*-------------------------------------------------------------------* * ivas_ism_reset_metadata_API() * * Reset ISm metadata parameters *-------------------------------------------------------------------*/ + void ivas_ism_reset_metadata_API( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ) @@ -440,6 +443,7 @@ void ivas_ism_reset_metadata_API( return; } + /*-------------------------------------------------------------------* * ism_quant_meta() * @@ -582,7 +586,9 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } -#ifdef MASA_AND_OBJECTS + + +#ifdef MASA_AND_OBJECTS // VE2Nokia: move this function to the new file ivas_omasa_com.c (?) /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() * @@ -677,128 +683,4 @@ ISM_MODE ivas_omasa_ism_mode_select( return ism_mode; } - - -#ifdef OMASA_BRATE -/*--------------------------------------------------------------- - * ivas_interformat_brate() - * - * Bit-budget distribution in case of combined-format coding - * ---------------------------------------------------------------*/ - -#define GAMMA_ISM_LOW_IMP 0.8f -#define GAMMA_ISM_LOW_IMP2 0.9f -#define GAMMA_ISM_MEDIUM_IMP 1.2f -#define GAMMA_ISM_HIGH_IMP 1.4f -#define GAMMA_ISM_HIGH_IMP2 1.35f - -/*! r: adjusted bitrate */ -int32_t ivas_interformat_brate( - const ISM_MODE ism_mode, /* i : ISM mode */ - const int32_t element_brate, /* i : element bitrate */ - const int16_t ism_imp /* i : ISM importance flag */ -) -{ - int32_t element_brate_out; - int16_t nBits, limit_low, limit_high; - - nBits = (int16_t) ( element_brate / FRAMES_PER_SEC ); - - if ( ism_imp == ISM_INACTIVE_IMP ) - { - nBits = BITS_ISM_INACTIVE; - } - else if ( ism_imp == ISM_LOW_IMP ) - { - if ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */ - { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 ); - } - else - { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); - } - } - else if ( ism_imp == ISM_MEDIUM_IMP ) - { - nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP ); - } - else /* ISM_HIGH_IMP */ - { - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 ); - } - else - { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP ); - } - } - - limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC; - if ( ism_imp == ISM_INACTIVE_IMP ) - { - limit_low = BITS_ISM_INACTIVE; - } - else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT ) - { - limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC; - } - - limit_high = IVAS_512k / FRAMES_PER_SEC; - if ( element_brate < SCE_CORE_16k_LOW_LIMIT ) - { - limit_high = ACELP_12k8_HIGH_LIMIT / FRMS_PER_SECOND; - } - - nBits = check_bounds_s( nBits, limit_low, limit_high ); - - element_brate_out = nBits * FRAMES_PER_SEC; - - return element_brate_out; -} - - -/*--------------------------------------------------------------- - * ivas_combined_format_brate_sanity() - * - * Sanity check in combined format coding - * ---------------------------------------------------------------*/ - -void ivas_combined_format_brate_sanity( - const int32_t element_brate, /* i : element bitrate */ - const int16_t core, /* i : core */ - int32_t *core_brate, /* i/o: core bitrate */ - int16_t *diff_nBits /* o : number of differential bits */ -) -{ - int16_t limit_high, nBits; - - /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by - low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget - for ACELP core-coding @12.8 kHz is too high */ - - if ( element_brate < ACELP_12k8_HIGH_LIMIT ) - { - limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; - nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC ); - - *diff_nBits = nBits - limit_high; - if ( *diff_nBits > 0 ) - { - if ( core == TCX_20_CORE || core == TCX_10_CORE ) - { - *diff_nBits = 0; - } - else /* ACELP core */ - { - *core_brate -= ( *diff_nBits * FRAMES_PER_SEC ); - } - } - } - - return; -} - -#endif #endif diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c new file mode 100644 index 0000000000..121ea78076 --- /dev/null +++ b/lib_com/ivas_omasa_com.c @@ -0,0 +1,182 @@ +/****************************************************************************************************** + + (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include "options.h" +#include +#include "ivas_cnst.h" +#include "ivas_prot.h" +#include "prot.h" +#ifdef DEBUGGING +#include "debug.h" +#endif + + +#ifdef OMASA_BRATE +/*--------------------------------------------------------------- + * Local constants + * ---------------------------------------------------------------*/ + + +#define GAMMA_ISM_LOW_IMP 0.8f +#define GAMMA_ISM_MEDIUM_IMP 1.2f +#define GAMMA_ISM_HIGH_IMP 1.4f + +#define GAMMA_ISM_LOW_IMP2 0.9f +#define GAMMA_ISM_MEDIUM_IMP2 1.2f +#define GAMMA_ISM_HIGH_IMP2 1.35f + + +/*--------------------------------------------------------------- + * ivas_interformat_brate() + * + * Bit-budget distribution in case of combined-format coding + * ---------------------------------------------------------------*/ + +/*! r: adjusted bitrate */ +int32_t ivas_interformat_brate( + const ISM_MODE ism_mode, /* i : ISM mode */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t ism_imp /* i : ISM importance flag */ +) +{ + int32_t element_brate_out; + int16_t nBits, limit_low, limit_high; + + nBits = (int16_t) ( element_brate / FRAMES_PER_SEC ); + + + if ( ism_imp == ISM_INACTIVE_IMP ) + { + nBits = BITS_ISM_INACTIVE; + } + else + { + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || + ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */ + ) + { + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP2 ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 ); + } + } + else + { + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP ); + } + } + } + + limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC; + if ( ism_imp == ISM_INACTIVE_IMP ) + { + limit_low = BITS_ISM_INACTIVE; + } + else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT ) + { + limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC; + } + + limit_high = IVAS_512k / FRAMES_PER_SEC; + if ( element_brate < SCE_CORE_16k_LOW_LIMIT ) + { + limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; + } + + nBits = check_bounds_s( nBits, limit_low, limit_high ); + + element_brate_out = nBits * FRAMES_PER_SEC; + + return element_brate_out; +} + + +/*--------------------------------------------------------------- + * ivas_combined_format_brate_sanity() + * + * Sanity check in combined format coding + * ---------------------------------------------------------------*/ + +void ivas_combined_format_brate_sanity( + const int32_t element_brate, /* i : element bitrate */ + const int16_t core, /* i : core */ + int32_t *core_brate, /* i/o: core bitrate */ + int16_t *diff_nBits /* o : number of differential bits */ +) +{ + int16_t limit_high, nBits; + + /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by + low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget + for ACELP core-coding @12.8 kHz is too high */ + + if ( element_brate < ACELP_12k8_HIGH_LIMIT ) + { + limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; + nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC ); + + *diff_nBits = nBits - limit_high; + if ( *diff_nBits > 0 ) + { + if ( core == TCX_20_CORE || core == TCX_10_CORE ) + { + *diff_nBits = 0; + } + else /* ACELP core */ + { + *core_brate -= ( *diff_nBits * FRAMES_PER_SEC ); + } + } + } + + return; +} + +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 135c3a6321..7b7edd2f34 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5210,9 +5210,9 @@ void preProcessStereoTransportsForMovedObjects( Decoder_Struct* st_ivas, float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - uint8_t nBins, - uint8_t firstSubframe, - uint8_t nSubframes + const uint8_t nBins, + const uint8_t firstSubframe, + const uint8_t nSubframes ); ivas_error ivas_masa_ism_separate_object_renderer_open( @@ -5227,23 +5227,23 @@ void ivas_masa_ism_separate_object_render( ); void ivas_masa_ism_set_edited_objects( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, - int16_t low_bitrate_mode, - int16_t nbands, - int16_t nblocks + const int16_t low_bitrate_mode, + const int16_t nbands, + const int16_t nblocks ); void decode_masa_to_total( uint16_t* bit_stream, int16_t* index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - int16_t nbands, - int16_t nblocks + const int16_t nbands, + const int16_t nblocks ); void modify_masa_energy_ratios( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index b42fb64fc4..641a5f5c84 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2780,6 +2780,10 @@ const float McMASA_LFEGain_vectors[64] = }; #ifdef MASA_AND_OBJECTS +/*----------------------------------------------------------------------------------* + * OMASA ROM tables + *----------------------------------------------------------------------------------*/ + // VE2Nokia: add "const" to the arrays int32_t sep_object_brate[][MAX_NUM_OBJECTS] = { @@ -2806,6 +2810,7 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */ }; + /* column wise DCT matrices for 4 5, and 8 dim */ float dct4[] = { 0.5000f, 0.6533f, 0.5000f, 0.2706f, @@ -2821,6 +2826,7 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = 0.4472f, -0.3717f, -0.1954f, 0.6015f, -0.5117f, 0.4472f, -0.6015f, 0.5117f, -0.3717f, 0.1954f }; + float dct8[] = { 0.3536f, 0.4904f, 0.4619f, 0.4157f, 0.3536f, 0.2778f, 0.1913f, 0.0975f, 0.3536f, 0.4157f, 0.1913f, -0.0975f, -0.3536f, -0.4904f, -0.4619f, -0.2778f, 0.3536f, 0.2778f, -0.1913f, -0.4904f, diff --git a/lib_com/options.h b/lib_com/options.h index e7ec2bf9ae..d73306ae58 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ diff --git a/lib_dec/ivas_dirac_dec_binaural_functions.c b/lib_dec/ivas_dirac_dec_binaural_functions.c index 7f4511c9c3..af97a8ba78 100644 --- a/lib_dec/ivas_dirac_dec_binaural_functions.c +++ b/lib_dec/ivas_dirac_dec_binaural_functions.c @@ -973,7 +973,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric #ifdef MASA_AND_OBJECTS float spectrumModVal; /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ - spectrumModVal = (1.0f - surCoh) + surCoh * surCohEne[min(bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1)]; + spectrumModVal = ( 1.0f - surCoh ) + surCoh * surCohEne[min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 )]; diffEne *= spectrumModVal; #else idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); @@ -1952,10 +1952,7 @@ static void hrtfShGetHrtf( int16_t k; float shVec[HRTF_SH_CHANNELS]; - ivas_dirac_dec_get_response( aziDeg, - eleDeg, - shVec, - HRTF_SH_ORDER ); + ivas_dirac_dec_get_response( aziDeg, eleDeg, shVec, HRTF_SH_ORDER ); *lRealp = 0.0f; *lImagp = 0.0f; @@ -1972,14 +1969,21 @@ static void hrtfShGetHrtf( return; } + #ifdef MASA_AND_OBJECTS +/*-------------------------------------------------------------------* + * preProcessStereoTransportsForMovedObjects() + * + * + *-------------------------------------------------------------------*/ + void preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - uint8_t nBins, - uint8_t firstSubframe, - uint8_t nSubframes ) + const uint8_t nBins, + const uint8_t firstSubframe, + const uint8_t nSubframes ) { int16_t subframe, bin, ch, inCh, outCh, ismDirIndex, slot; DIRAC_DEC_HANDLE hDirAC; @@ -2070,6 +2074,7 @@ void preProcessStereoTransportsForMovedObjects( ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex], hMasaIsmData->elevation_ism[ismDirIndex], panGainsIn ); + if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) { ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism_edited[ismDirIndex], @@ -2116,6 +2121,7 @@ void preProcessStereoTransportsForMovedObjects( normEnes[ch] -= panEnesIn[ch] * ratio; } } + /* Any remaining (non-object) energy is set to be preserved at both channels */ remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); for ( ch = 0; ch < 2; ch++ ) @@ -2136,7 +2142,6 @@ void preProcessStereoTransportsForMovedObjects( ismPreprocMtxNew[1 - ch][ch] = sqrtf( hMasaIsmData->eneMoveIIR[ch][bin] / normVal ); } - /* Get increment value for temporal interpolation */ for ( inCh = 0; inCh < 2; inCh++ ) { @@ -2185,5 +2190,7 @@ void preProcessStereoTransportsForMovedObjects( } } } + + return; } #endif diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 1c8c7b88da..fc12917b8f 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -94,7 +94,7 @@ static int16_t read_GR_min_removed_data( uint16_t *bitstream, int16_t *p_bit_pos static int16_t decode_fixed_rate_composed_index_coherence( uint16_t *bitstream, int16_t *p_bit_pos, const int16_t no_bands, int16_t *no_cv_vec, uint16_t *decoded_index, const int16_t no_symb ); #ifdef MASA_AND_OBJECTS -static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, int16_t len_stream, uint16_t *bit_stream, int16_t *index, int16_t first_line ); +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); #endif /*-----------------------------------------------------------------------* @@ -3302,14 +3302,15 @@ static void decode_combined_index( return; } + #ifdef MASA_AND_OBJECTS static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, - int16_t len_stream, + const int16_t len_stream, uint16_t *bit_stream, int16_t *index, - int16_t first_line ) + const int16_t first_line ) { int16_t sign, nbits; int16_t i, j, i_min; @@ -3382,6 +3383,7 @@ static void read_stream_dct_coeffs_omasa( } } } + /* deindex */ q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) @@ -3395,25 +3397,29 @@ static void read_stream_dct_coeffs_omasa( q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; } } + return; } + +/*------------------------------------------------------------------------- + * decode_masa_to_total() + * + *------------------------------------------------------------------------*/ + void decode_masa_to_total( uint16_t *bit_stream, int16_t *index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - int16_t nbands, - int16_t nblocks ) + const int16_t nbands, + const int16_t nblocks ) { int16_t i, j, k; - int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - - int16_t n_streams, len_stream; + /* Setup coding parameters */ n_streams = 1; len_stream = nbands * nblocks; @@ -3423,14 +3429,12 @@ void decode_masa_to_total( len_stream = 8; } - set_s( q_idx, 0, nbands * nblocks ); for ( i = 0; i < n_streams; i++ ) { read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], &q_dct_data[i * len_stream], len_stream, bit_stream, index, i == 0 ); } - /* inverse DCT2 transform */ switch ( len_stream ) { @@ -3468,6 +3472,7 @@ void decode_masa_to_total( k++; } } + if ( nblocks == 1 ) { for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) @@ -3478,6 +3483,7 @@ void decode_masa_to_total( } } } + if ( nbands == 1 ) { for ( j = 1; j < 5; j++ ) @@ -3488,5 +3494,7 @@ void decode_masa_to_total( } } } + + return; } #endif diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index d2a073d2b8..bd9183f92f 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -139,74 +139,6 @@ static void rate_ism_importance( } -#ifdef OMASA_BRATE -/*-------------------------------------------------------------------------* - * set_ism_importance_interformat() - * - * Set the importance of particular ISM streams in combined-format coding - *-------------------------------------------------------------------------*/ - -void set_ism_importance_interformat( - const int32_t ism_total_brate, /* i/o: ISms total bitrate */ - const int16_t nchan_transport, /* i : number of transported channels */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ - const float lp_noise_CPE, /* i : LP filtered total noise estimation */ - int16_t ism_imp[] /* o : ISM importance flags */ -) -{ - Encoder_State *st; - int16_t ch, ctype, active_flag; - - for ( ch = 0; ch < nchan_transport; ch++ ) - { - st = hSCE[ch]->hCoreCoder[0]; - - active_flag = st->vad_flag; - - if ( active_flag == 0 ) - { - if ( st->lp_noise > 15 || lp_noise_CPE - st->lp_noise < 30 ) - { - active_flag = 1; - } - } - - /* do not use the low-rate core-coder mode at highest bit-rates */ - if ( ism_total_brate / nchan_transport > IVAS_48k ) - { - active_flag = 1; - } - - ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; - - st->low_rate_mode = 0; - if ( active_flag == 0 ) - { - ism_imp[ch] = ISM_INACTIVE_IMP; - st->low_rate_mode = 1; - } - else if ( ctype == INACTIVE || ctype == UNVOICED ) - { - ism_imp[ch] = ISM_LOW_IMP; - } - else if ( ctype == VOICED ) - { - ism_imp[ch] = ISM_MEDIUM_IMP; - } - else /* GENERIC */ - { - ism_imp[ch] = ISM_HIGH_IMP; - } - - hIsmMeta[ch]->ism_metadata_flag = active_flag; /* flag is needed for the MD coding */ - } - - return; -} -#endif - - /*-------------------------------------------------------------------------* * ivas_ism_metadata_enc() * diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 5ea2b75a3e..0f50eecd54 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -30,15 +30,12 @@ *******************************************************************************************************/ +#include "options.h" +#include #include #include -#include -#include -#include "string.h" - #include "ivas_cnst.h" #include "ivas_prot.h" -#include "options.h" #include "prot.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" @@ -57,7 +54,7 @@ static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HAND static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); -static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, const int16_t num_transport_channels, const int16_t num_input_channels, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ); +static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_transport, const int16_t nchan_ism, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ); static void computeIntensityVector_enc( const int16_t *band_grouping, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ); @@ -67,7 +64,7 @@ static void computeReferencePower_omasa( const int16_t *band_grouping, float Cld /*--------------------------------------------------------------------------* * ivas_omasa_enc_open() * - * + * Allocate and initialize OMASA handle *--------------------------------------------------------------------------*/ ivas_error ivas_omasa_enc_open( @@ -173,7 +170,7 @@ ivas_error ivas_omasa_enc_open( /*--------------------------------------------------------------------------* * ivas_omasa_enc_close() * - O + * Close OMASA handle *--------------------------------------------------------------------------*/ void ivas_omasa_enc_close( @@ -183,7 +180,6 @@ void ivas_omasa_enc_close( { int16_t i, j; - for ( i = 0; i < nchan_ism; i++ ) { free( hOMasa->delay_buffer[i] ); @@ -278,7 +274,7 @@ void ivas_omasa_set_config( /*--------------------------------------------------------------------------* * ivas_omasa_enc() * - * + * Main OMASA encoding function *--------------------------------------------------------------------------*/ void ivas_omasa_enc( @@ -490,6 +486,73 @@ void ivas_omasa_enc( #ifdef OMASA_BRATE + +/*-------------------------------------------------------------------------* + * set_ism_importance_interformat() + * + * Set the importance of particular ISM streams in combined-format coding + *-------------------------------------------------------------------------*/ + +void set_ism_importance_interformat( + const int32_t ism_total_brate, /* i/o: ISms total bitrate */ + const int16_t nchan_transport, /* i : number of transported channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + const float lp_noise_CPE, /* i : LP filtered total noise estimation */ + int16_t ism_imp[] /* o : ISM importance flags */ +) +{ + Encoder_State *st; + int16_t ch, ctype, active_flag; + + for ( ch = 0; ch < nchan_transport; ch++ ) + { + st = hSCE[ch]->hCoreCoder[0]; + + active_flag = st->vad_flag; + + if ( active_flag == 0 ) + { + if ( st->lp_noise > 15 || lp_noise_CPE - st->lp_noise < 30 ) + { + active_flag = 1; + } + } + + /* do not use the low-rate core-coder mode at highest bit-rates */ + if ( ism_total_brate / nchan_transport > IVAS_48k ) + { + active_flag = 1; + } + + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + st->low_rate_mode = 0; + if ( active_flag == 0 ) + { + ism_imp[ch] = ISM_INACTIVE_IMP; + st->low_rate_mode = 1; + } + else if ( ctype == INACTIVE || ctype == UNVOICED ) + { + ism_imp[ch] = ISM_LOW_IMP; + } + else if ( ctype == VOICED ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + } + else /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + } + + hIsmMeta[ch]->ism_metadata_flag = active_flag; /* flag is needed for the MD coding */ + } + + return; +} + + /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() * @@ -535,7 +598,7 @@ static void ivas_omasa_param_est_enc( float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], const int16_t input_frame, - const int16_t nchan_inp ) + const int16_t nchan_ism ) { float reference_power[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; int16_t ts, i, j, d, k; @@ -565,13 +628,13 @@ static void ivas_omasa_param_est_enc( set_zero( diffuseness_m, hOMasa->nbands ); /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_inp; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); } /* Compute ISM to FOA matrices */ - for ( i = 0; i < nchan_inp; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { hOMasa->chnlToFoaMtx[0][i] = 1.0f; hOMasa->chnlToFoaMtx[1][i] = sinf( ( hIsmMeta[i]->azimuth / 180.0f * EVS_PI ) ) * cosf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); @@ -596,7 +659,7 @@ static void ivas_omasa_param_est_enc( for ( ts = mrange[0]; ts < mrange[1]; ts++ ) { - for ( i = 0; i < nchan_inp; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { if ( ts < hOMasa->num_slots_delay_comp ) { @@ -615,7 +678,7 @@ static void ivas_omasa_param_est_enc( brange[1] = hOMasa->band_grouping[i + 1]; for ( j = brange[0]; j < brange[1]; j++ ) { - for ( k = 0; k < nchan_inp; k++ ) + for ( k = 0; k < nchan_ism; k++ ) { hMasa->data.energy_ism[block_m_idx][i] += Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; } @@ -626,7 +689,7 @@ static void ivas_omasa_param_est_enc( /* W */ mvr2r( Chnl_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); mvr2r( Chnl_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); - for ( i = 1; i < nchan_inp; i++ ) + for ( i = 1; i < nchan_ism; i++ ) { v_add( Chnl_RealBuffer[i], Foa_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); v_add( Chnl_ImagBuffer[i], Foa_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); @@ -635,7 +698,7 @@ static void ivas_omasa_param_est_enc( /* Y */ v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_RealBuffer[1], num_freq_bins ); v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_ImagBuffer[1], num_freq_bins ); - for ( i = 1; i < nchan_inp; i++ ) + for ( i = 1; i < nchan_ism; i++ ) { v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_RealBuffer[1], num_freq_bins ); v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_ImagBuffer[1], num_freq_bins ); @@ -644,7 +707,7 @@ static void ivas_omasa_param_est_enc( /* Z */ v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_RealBuffer[2], num_freq_bins ); v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_ImagBuffer[2], num_freq_bins ); - for ( i = 1; i < nchan_inp; i++ ) + for ( i = 1; i < nchan_ism; i++ ) { v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_RealBuffer[2], num_freq_bins ); v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_ImagBuffer[2], num_freq_bins ); @@ -653,7 +716,7 @@ static void ivas_omasa_param_est_enc( /* X */ v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_RealBuffer[3], num_freq_bins ); v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_ImagBuffer[3], num_freq_bins ); - for ( i = 1; i < nchan_inp; i++ ) + for ( i = 1; i < nchan_ism; i++ ) { v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_RealBuffer[3], num_freq_bins ); v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_ImagBuffer[3], num_freq_bins ); @@ -724,7 +787,7 @@ static void ivas_omasa_param_est_enc( } /* Update memory */ - for ( i = 0; i < nchan_inp; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); } @@ -843,8 +906,8 @@ static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, - const int16_t num_transport_channels, - const int16_t num_input_channels, + const int16_t nchan_transport, + const int16_t nchan_ism, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ) @@ -854,14 +917,14 @@ static void ivas_omasa_dmx( float gains[MASA_MAX_TRANSPORT_CHANNELS]; float g1, g2; - if ( num_transport_channels == 2 ) + if ( nchan_transport == 2 ) { - for ( i = 0; i < num_transport_channels; i++ ) + for ( i = 0; i < nchan_transport; i++ ) { set_zero( data_out_f[i], input_frame ); } - for ( i = 0; i < num_input_channels; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { azimuth = hIsmMeta[i]->azimuth; elevation = hIsmMeta[i]->elevation; @@ -869,9 +932,9 @@ static void ivas_omasa_dmx( ivas_get_stereo_panning_gains( azimuth, elevation, gains ); /* Downmix using the panning gains */ - for ( j = 0; j < num_transport_channels; j++ ) + for ( j = 0; j < nchan_transport; j++ ) { - if ( fabsf( gains[j] ) > 0.0 || fabsf( prev_gains[i][j] ) > 0.0 ) + if ( fabsf( gains[j] ) > 0.0 || fabsf( prev_gains[i][j] ) > 0.0f ) { for ( k = 0; k < input_frame; k++ ) { @@ -884,17 +947,19 @@ static void ivas_omasa_dmx( } } } - else if ( num_transport_channels == 1 ) + else if ( nchan_transport == 1 ) // VE2Nokia: is ti relevant? { for ( i = 0; i < input_frame; i++ ) { data_out_f[0][i] = 0.0f; - for ( j = 0; j < num_input_channels; j++ ) + for ( j = 0; j < nchan_ism; j++ ) { data_out_f[0][i] += data_in_f[j][i]; } } } + + return; } @@ -935,6 +1000,7 @@ static void computeIntensityVector_enc( return; } + static void computeReferencePower_omasa( const int16_t *band_grouping, /* i : Band grouping for estimation */ float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index d140dc79e6..5fb5427ebe 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -125,11 +125,14 @@ static void transform_azimuth_dir2( IVAS_QMETADATA_HANDLE hQMetaData, int16_t *d static int16_t calc_var_azi( const IVAS_QDIRECTION *q_direction, const int16_t diffuseness_index_max_ec_frame, const float avg_azimuth, float *avg_azimuth_out ); #ifdef MASA_AND_OBJECTS -static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, int16_t len_stream, BSTR_ENC_HANDLE hMetaData, int16_t first_line, int16_t low_bitrate_mode ); -static int16_t find_optimal_GR_order( int16_t *q_idx, int16_t len, int16_t *GR ); -static int16_t find_optimal_GR_orders( int16_t *q_idx, int16_t len, int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); +static int16_t write_stream_dct_coeffs_omasa( int16_t *q_idx, const int16_t len_stream, BSTR_ENC_HANDLE hMetaData, const int16_t first_line, const int16_t low_bitrate_mode ); + +static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, int16_t *GR ); + +static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); #endif + /*-----------------------------------------------------------------------* * ivas_qmetadata_enc_encode() * @@ -2769,7 +2772,7 @@ static int16_t truncGR0( *-------------------------------------------------------------------*/ static int16_t truncGR0_chan( - float *data, + const float *data, float *data_hat, uint16_t *data_idx, const int16_t len, @@ -4918,14 +4921,15 @@ static float direction_distance( return d / (float) ( dim1 * dim2 ); } #endif + #ifdef MASA_AND_OBJECTS static int16_t divide_GR_orders( - int16_t *q_idx, - int16_t GR1, - int16_t GR2, - int16_t len, - int16_t len_max_GR1, + const int16_t *q_idx, + const int16_t GR1, + const int16_t GR2, + const int16_t len, + const int16_t len_max_GR1, int16_t *i_min ) { int16_t nb_GR_min; @@ -4951,12 +4955,14 @@ static int16_t divide_GR_orders( *i_min = i + 1; } } + return nb_GR_min; } -static int16_t -find_optimal_GR_order( - int16_t *q_idx, - int16_t len, + + +static int16_t find_optimal_GR_order( + const int16_t *q_idx, + const int16_t len, int16_t *GR ) { int16_t nb_GR_0, nb_GR_1; @@ -4978,16 +4984,16 @@ find_optimal_GR_order( else { *GR = 1; + return nb_GR_1; } } -static int16_t -find_optimal_GR_orders( - int16_t *q_idx, - int16_t len, - int16_t len_max_GR1, +static int16_t find_optimal_GR_orders( + const int16_t *q_idx, + const int16_t len, + const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ) @@ -5023,15 +5029,17 @@ find_optimal_GR_orders( *i_min = i_min_10; } } + return nb_GR_min; } + static int16_t write_stream_dct_coeffs_omasa( - int16_t *q_idx, /* i: array of indexes to be written */ - int16_t len_stream, /* i: array length */ - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream */ - int16_t first_line, /* i: is first line of the matrix? 1/0*/ - int16_t low_bitrate_mode /* i: is low bitrate mode? if yes, limit the number of bits written */ + int16_t *q_idx, /* i: array of indexes to be written */ + const int16_t len_stream, /* i: array length */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream */ + const int16_t first_line, /* i: is first line of the matrix? 1/0*/ + const int16_t low_bitrate_mode /* i: is low bitrate mode? if yes, limit the number of bits written */ ) { int16_t nb_bits = 0, bits_pos; @@ -5144,6 +5152,7 @@ static int16_t write_stream_dct_coeffs_omasa( /* find optimum length of the part encoded with GR2 */ nb_GR_min = find_optimal_GR_orders( &q_idx[1], len_stream - 1, 15, &GR1, &GR2, &i_min ); } + if ( len_stream >= 8 ) { /* write number of indexes encoded with GR2 on 4 bits */ @@ -5157,11 +5166,13 @@ static int16_t write_stream_dct_coeffs_omasa( push_next_indice( hMetaData, GR2, 1 ); nb_bits += 1; } + /* write GR data */ for ( i = 1; i <= i_min; i++ ) { ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR1 ); } + for ( i = i_min + 1; i < len_stream; i++ ) { ivas_qmetadata_encode_extended_gr( hMetaData, q_idx[i], 100, GR2 ); @@ -5183,32 +5194,33 @@ static int16_t write_stream_dct_coeffs_omasa( assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); } + return nb_bits; } + +/*------------------------------------------------------------------------- + * encode_masa_to_total() + * + *------------------------------------------------------------------------*/ + void encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, - int16_t low_bitrate_mode, - int16_t nbands, - int16_t nblocks ) + const int16_t low_bitrate_mode, + const int16_t nbands, + const int16_t nblocks ) { int16_t i, j, k; float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - - float step = STEP_M2T; - int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; - - int16_t bits_pos, nb_bits; int16_t n_streams, len_stream; - #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_ratio = NULL; @@ -5220,7 +5232,6 @@ void encode_masa_to_total( #endif - bits_pos = hMetaData->nb_bits_tot; k = 0; for ( i = 0; i < nbands; i++ ) @@ -5269,7 +5280,6 @@ void encode_masa_to_total( break; } - for ( k = 0; k < n_streams; k++ ) { j = k * len_stream; @@ -5280,7 +5290,9 @@ void encode_masa_to_total( { q_idx[j] = ( ( 1 << BITS_MASA2TOTTAL_DCT0 ) - 1 ); } + q_dct_data[j] = step * q_idx[j]; + if ( q_idx[j] == 0 ) { set_s( &q_idx[j], 0, len_stream ); @@ -5304,7 +5316,6 @@ void encode_masa_to_total( } } - /* write data */ nb_bits = 0; for ( i = 0; i < n_streams; i++ ) @@ -5312,7 +5323,6 @@ void encode_masa_to_total( nb_bits += write_stream_dct_coeffs_omasa( &q_idx[i * len_stream], len_stream, hMetaData, ( i == 0 ), low_bitrate_mode ); } - /* reconstruct masa2total */ q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) @@ -5326,6 +5336,7 @@ void encode_masa_to_total( q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; } } + /* inverse DCT2 transform */ switch ( len_stream ) { @@ -5353,7 +5364,6 @@ void encode_masa_to_total( break; } - k = 0; for ( i = 0; i < nblocks; i++ ) { -- GitLab From 7fa3c751e4358bee8405d1024451007c49812489 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 10:45:26 +0100 Subject: [PATCH 020/173] move DEBUG_VA to ivas_set_surplus_brate_enc() --- lib_com/ivas_prot.h | 4 ++++ lib_enc/ivas_enc.c | 29 ++++------------------------- lib_enc/ivas_omasa_enc.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7b7edd2f34..beb170708e 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5158,6 +5158,10 @@ void ivas_omasa_enc( #ifdef OMASA_BRATE void ivas_set_surplus_brate_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +#ifdef DEBUG_VA + , + const int16_t *nb_bits_metadata /* i : number of metadata bits */ +#endif ); void ivas_set_surplus_brate_dec( diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index be021a9493..d5ed2963c3 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -378,8 +378,11 @@ ivas_error ivas_enc( st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); /* Configuration of combined-format bit-budget distribution */ +#ifdef DEBUG_VA + ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); +#else ivas_set_surplus_brate_enc( st_ivas ); - +#endif #else if ( st_ivas->hQMetaData != NULL ) { @@ -438,30 +441,6 @@ ivas_error ivas_enc( { ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); // VE2Nokia: this condition is unnecessary } - -#ifdef DEBUG_VA - if ( st_ivas->hSCE[0] != NULL ) - { - float tmpF = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); - } - else - { - for ( i = 0; i < st_ivas->nchan_ism; i++ ) - { - tmpF += st_ivas->hSCE[i]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[i + 1] * 50 ); - } - } - tmpF /= 1000.f; - dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_ISM" ); - tmpF = ivas_total_brate / 1000.0f - tmpF; - dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MASA" ); - tmpF = nb_bits_metadata[0] * 50 / 1000.0f; - dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MD" ); - } -#endif } #endif else if ( ivas_format == MC_FORMAT ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 0f50eecd54..16758a4d77 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -561,6 +561,10 @@ void set_ism_importance_interformat( void ivas_set_surplus_brate_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +#ifdef DEBUG_VA + , + const int16_t *nb_bits_metadata /* i : number of metadata bits */ +#endif ) { if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) @@ -577,6 +581,31 @@ void ivas_set_surplus_brate_enc( st_ivas->hCPE[0]->brate_surplus = 0; } +#ifdef DEBUG_VA + if ( st_ivas->hSCE[0] != NULL ) + { + int16_t input_frame = (int16_t) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); + float tmpF = 0; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); + } + else + { + for ( int16_t i = 0; i < st_ivas->nchan_ism; i++ ) + { + tmpF += st_ivas->hSCE[i]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[i + 1] * 50 ); + } + } + tmpF /= 1000.f; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_ISM" ); /* == ism_total_brate incl. ISM MD */ + tmpF = st_ivas->hEncoderConfig->ivas_total_brate / 1000.0f - tmpF; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MASA" ); /* == masa_total_brate incl. MASA MD */ + tmpF = nb_bits_metadata[0] * FRAMES_PER_SEC / 1000.0f; + dbgwrite( &tmpF, 4, 1, input_frame, "res/brate_MASA_MD" ); /* == MASA MD bitrate */ + } +#endif + return; } #endif -- GitLab From 49117d2e5355274ca61962fbdd0d89fabca81b57 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 11:16:24 +0100 Subject: [PATCH 021/173] address "VE2Nokia" comments, part 1 --- lib_com/ivas_masa_com.c | 10 +- lib_com/ivas_prot.h | 33 +++-- lib_dec/ivas_dec.c | 287 ++++++++++++++++++++------------------- lib_dec/ivas_init_dec.c | 12 +- lib_dec/ivas_masa_dec.c | 27 ++-- lib_enc/ivas_enc.c | 22 +-- lib_enc/ivas_init_enc.c | 16 +-- lib_enc/ivas_masa_enc.c | 34 +++-- lib_enc/ivas_omasa_enc.c | 29 ++-- 9 files changed, 239 insertions(+), 231 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 9211ec057d..867f9512e8 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -68,9 +68,9 @@ void ivas_masa_set_elements( int16_t *nCPE /* o : number of CPEs */ #ifdef MASA_AND_OBJECTS , - int16_t ivas_format, - const ISM_MODE ism_mode, - int32_t sce_brate + const int16_t ivas_format, /* i : IVAS format */ + const ISM_MODE ism_mode, /* i : ISM mode */ + const int32_t ism_total_brate /* i : initial ISM total bitrate */ #endif ) { @@ -97,7 +97,7 @@ void ivas_masa_set_elements( if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO ) { *element_mode = IVAS_CPE_MDCT; - if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_ONE_OBJ ) && ( ivas_total_brate - sce_brate < MIN_BRATE_MDCT_STEREO ) ) + if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) ) { *element_mode = IVAS_CPE_DFT; } @@ -118,7 +118,7 @@ void ivas_masa_set_elements( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) { - hQMetaData->bits_frame_nominal -= (int16_t) ( sce_brate / FRAMES_PER_SEC ); + hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); } #endif } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index beb170708e..b861e3aa1d 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4528,18 +4528,18 @@ void ivas_masa_set_elements( int16_t *nCPE /* o : number of CPEs */ #ifdef MASA_AND_OBJECTS , - int16_t ivas_format, /* i : IVAS format */ + const int16_t ivas_format, /* i : IVAS format */ const ISM_MODE ism_mode, /* i : ISM mode */ - int32_t sce_brate /* i : bitrate of SCE */ + const int32_t ism_total_brate /* i : initial ISM total bitrate */ #endif ); #ifdef MASA_AND_OBJECTS /*! r: valid or not 1/0 */ int16_t valid_ratio_index( - int16_t index, /* i : index to be checked */ - const int16_t K, /* i : L1 norm to check against */ - const int16_t len /* i : vector length */ + int16_t index, /* i : index to be checked */ + const int16_t K, /* i : L1 norm to check against */ + const int16_t len /* i : vector length */ ); void reconstruct_ism_ratios( @@ -5141,18 +5141,17 @@ void ivas_omasa_set_config( ); void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ - MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - float data_in_f[][L_FRAME48k], /* i : Input audio signals for parameter analysis */ - float data_out_f[][L_FRAME48k], /* o : Transport audio signals */ - const int16_t input_frame, /* i : Input frame size */ - const int16_t nchan_transport, /* i : Number of transport channels */ - const int16_t nchan_inp, /* i : Number of objects for parameter analysis */ - const ISM_MODE ism_mode, /* i : ISM mode */ - float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ - int16_t* idx_separated_object /* o : Index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t nchan_transport, /* i : Number of transport channels */ + const int16_t nchan_ism, /* i : Number of objects for parameter analysis*/ + const ISM_MODE ism_mode, /* i : ISM mode */ + float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ + int16_t* idx_separated_object /* o : Index of the separated object */ ); #ifdef OMASA_BRATE diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index df5cfb4253..a964c53a6c 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -355,6 +355,150 @@ ivas_error ivas_dec( ivas_sba_upmixer_renderer( st_ivas, output, output_frame ); /* Note: ivas_sba_linear_renderer() or ivas_dirac_dec() are called internally */ } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { +#ifndef OMASA_BRATE + ism_total_brate = 0; +#endif + st = st_ivas->hCPE[0]->hCoreCoder[0]; + +#ifndef OMASA_BRATE + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + st->bit_stream = &( st_ivas->bit_stream[( st_ivas->hSCE[0]->element_brate / FRAMES_PER_SEC )] ); + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + ism_total_brate += st_ivas->hSCE[n]->element_brate; + } + st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); + } +#endif + + nb_bits_metadata[0] = 0; + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /* Set the number of objects for the parametric rendering */ + if ( st_ivas->hDirAC != NULL ) + { + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; + } + else + { + st_ivas->hDirAC->numIsmDirections = 0; + } + } + + /* MASA decoding */ + if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + +#ifdef OMASA_BRATE + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); + + st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); +#endif + + /* Audio signal decoding */ + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + if ( st_ivas->nSCE == 1 ) + { + ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ); + } + else + { +#ifdef DEBUGGING + assert( ( st_ivas->nSCE <= 1 ) && "nSCE should be 1 if not in ISM_MASA_MODE_DISC." ); +#endif + } + } + else + { + /* decode ISM format */ + ivas_ism_metadata_dec( ism_total_brate, &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL ); + + for ( n = 0; n < st_ivas->nSCE - 1; n++ ) + { + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + } + } + if ( st_ivas->nCPE == 1 ) + { + ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ); + } + + if ( st_ivas->hCPE[0]->nchan_out == 1 ) + { + mvr2r( output[0], output[1], output_frame ); /* Copy mono signal to stereo output channels */ + } + + /* HP filtering */ + for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + } + + /* Set edited object positions, if editing enabled */ + ivas_masa_ism_set_edited_objects( st_ivas ); + + /* Rendering */ + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); + } + else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); + } + else if ( st_ivas->hDirAC ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + mvr2r( output[2], data_separated_objects[0], output_frame ); + } + else + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + } + } + + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); + } + else + { + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + } + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -547,150 +691,7 @@ ivas_error ivas_dec( } } } -#ifdef MASA_AND_OBJECTS - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) - { -#ifndef OMASA_BRATE - ism_total_brate = 0; -#endif - st = st_ivas->hCPE[0]->hCoreCoder[0]; - -#ifndef OMASA_BRATE - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - st->bit_stream = &( st_ivas->bit_stream[( st_ivas->hSCE[0]->element_brate / FRAMES_PER_SEC )] ); - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - ism_total_brate += st_ivas->hSCE[n]->element_brate; - } - st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - } -#endif - - nb_bits_metadata[0] = 0; - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); - - /* Set the number of objects for the parametric rendering */ - if ( st_ivas->hDirAC != NULL ) - { - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; - } - else - { - st_ivas->hDirAC->numIsmDirections = 0; - } - } - - /* MASA decoding */ - if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) - { - return error; - } - -#ifdef OMASA_BRATE - /* Configuration of combined-format bit-budget distribution */ - ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); - - st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); -#endif - - /* Audio signal decoding */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - if ( st_ivas->nSCE == 1 ) - { - ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ); - } - else - { -#ifdef DEBUGGING - assert( ( st_ivas->nSCE <= 1 ) && "nSCE should be 1 if not in ISM_MASA_MODE_DISC." ); -#endif - } - } - else - { - /* decode ISM format */ - ivas_ism_metadata_dec( ism_total_brate, &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL ); - for ( n = 0; n < st_ivas->nSCE - 1; n++ ) - { - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - } - } - if ( st_ivas->nCPE == 1 ) - { - ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ); - } - - if ( st_ivas->hCPE[0]->nchan_out == 1 ) - { - mvr2r( output[0], output[1], output_frame ); /* Copy mono signal to stereo output channels */ - } - - /* HP filtering */ - for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) - { - hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); - } - - /* Set edited object positions, if editing enabled */ - ivas_masa_ism_set_edited_objects( st_ivas ); - - /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); - } - else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) - { - ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); - } - else if ( st_ivas->hDirAC ) - { - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - mvr2r( output[2], data_separated_objects[0], output_frame ); - } - else - { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - mvr2r( output[n + 2], data_separated_objects[n], output_frame ); - } - } - - ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); - ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); - } - else - { - ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); - } - } - } -#endif /*----------------------------------------------------------------* * Write IVAS output channels diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 2c2a26b315..f20dbf1f09 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -664,7 +664,7 @@ ivas_error ivas_init_decoder( DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; #ifdef MASA_AND_OBJECTS - int32_t sce_brate; + int32_t ism_total_brate; #endif error = IVAS_ERR_OK; @@ -968,7 +968,7 @@ ivas_error ivas_init_decoder( ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); k = 0; - sce_brate = 0; + ism_total_brate = 0; while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) { k++; @@ -978,8 +978,8 @@ ivas_error ivas_init_decoder( /* one separated object */ st_ivas->nSCE = 1; - sce_brate = sep_object_brate[k - 2][0]; - create_sce_dec( st_ivas, 0, sce_brate ); + ism_total_brate = sep_object_brate[k - 2][0]; + create_sce_dec( st_ivas, 0, ism_total_brate ); reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); @@ -999,7 +999,7 @@ ivas_error ivas_init_decoder( { temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; - sce_brate += temp_brate[sce_id]; + ism_total_brate += temp_brate[sce_id]; if ( ( error = create_sce_dec( st_ivas, sce_id, temp_brate[sce_id] ) ) != IVAS_ERR_OK ) { @@ -1024,7 +1024,7 @@ ivas_error ivas_init_decoder( } st_ivas->nCPE = 1; - create_cpe_dec( st_ivas, 0, ( ( ivas_total_brate - sce_brate ) / st_ivas->nchan_transport ) * CPE_CHANNELS ); // VE2Nokia: could be simplified - nchan_transport is always 2 here + create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ); for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 83c194dbd2..06646b2ab9 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -497,26 +497,27 @@ ivas_error ivas_masa_dec_open( MASA_DECODER_HANDLE hMasa; #ifdef MASA_AND_OBJECTS int16_t i; - int32_t sce_brate; + int32_t ism_total_brate; #endif + if ( ( hMasa = (MASA_DECODER_HANDLE) malloc( sizeof( MASA_DECODER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } #ifdef MASA_AND_OBJECTS - sce_brate = 0; + ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( i = 0; i < st_ivas->nSCE; i++ ) { - sce_brate += st_ivas->hSCE[i]->element_brate; + ism_total_brate += st_ivas->hSCE[i]->element_brate; } } #endif ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE #ifdef MASA_AND_OBJECTS , - st_ivas->ivas_format, st_ivas->ism_mode, sce_brate + st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); @@ -655,7 +656,7 @@ static ivas_error ivas_masa_dec_config( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t ivas_total_brate; - int32_t sce_brate; + int32_t ism_total_brate; #endif error = IVAS_ERR_OK; @@ -664,16 +665,16 @@ static ivas_error ivas_masa_dec_config( #ifdef MASA_AND_OBJECTS ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; - sce_brate = 0; + ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( i = 0; i < st_ivas->nSCE; i++ ) { - sce_brate += st_ivas->hSCE[i]->element_brate; + ism_total_brate += st_ivas->hSCE[i]->element_brate; } } - ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, sce_brate ); + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { @@ -696,7 +697,6 @@ static ivas_error ivas_masa_dec_config( return error; } - st_ivas->hQMetaData->numTwoDirBands = st_ivas->hMasa->config.numTwoDirBands; st_ivas->hQMetaData->useLowerRes = 0; @@ -1281,7 +1281,7 @@ ivas_error ivas_masa_dec_reconfigure( int32_t ivas_total_brate, last_ivas_total_brate; ivas_error error; #ifdef MASA_AND_OBJECTS - int32_t sce_brate; + int32_t ism_total_brate; #endif error = IVAS_ERR_OK; @@ -1346,19 +1346,20 @@ ivas_error ivas_masa_dec_reconfigure( } } #ifdef MASA_AND_OBJECTS - sce_brate = 0; + ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( n = 0; n < st_ivas->nSCE; n++ ) { - sce_brate += st_ivas->hSCE[n]->element_brate; + ism_total_brate += st_ivas->hSCE[n]->element_brate; } } #endif + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp #ifdef MASA_AND_OBJECTS , - st_ivas->ivas_format, st_ivas->ism_mode, sce_brate + st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index d5ed2963c3..070554b9e2 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -332,7 +332,10 @@ ivas_error ivas_enc( #ifdef OMASA_BRATE /* Configure MASA encoder based on frame parameters */ - ivas_masa_enc_config( st_ivas ); // VE2Nokia: this function should return an error code + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } idx_separated_object = 0; if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) @@ -347,21 +350,18 @@ ivas_error ivas_enc( /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { - // VE2Nokia: merge the following to one function in order to save some stack memory - float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; - /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, data_transport_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); - - /* Merge transport signals */ - ivas_merge_masa_transports( data_transport_f, &( data_f[st_ivas->nchan_ism] ), data_f, input_frame, st_ivas->nchan_transport ); + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); } /* Encode ISMs transport channels */ n = 0; if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ); /* there are no metadata bits in SCE in this mode */ // VE2Nokia: this function should return an error code + if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ + { + return error; + } } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -437,9 +437,9 @@ ivas_error ivas_enc( #endif /* OMASA_BRATE */ /* Encode MASA transport channels */ - if ( st_ivas->nCPE == 1 ) // VE2Nokia: this condition is not necessary + if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ); // VE2Nokia: this condition is unnecessary + return error; } } #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index cb8217d556..63bba1d337 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -565,7 +565,7 @@ ivas_error ivas_init_encoder( else if ( ivas_format == MASA_ISM_FORMAT ) { int32_t element_brate_tmp[MAX_NUM_OBJECTS]; - int32_t sce_brate; + int32_t ism_total_brate; int16_t k; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); @@ -580,7 +580,6 @@ ivas_error ivas_init_encoder( } k = 0; - sce_brate = 0; while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) { k++; @@ -589,8 +588,8 @@ ivas_error ivas_init_encoder( if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { /* use the bitrate for one object */ - sce_brate = sep_object_brate[k - 2][0]; - create_sce_enc( st_ivas, 0, sce_brate ); // VE2Nokia: this function should return an error code + ism_total_brate = sep_object_brate[k - 2][0]; + create_sce_enc( st_ivas, 0, ism_total_brate ); // VE2Nokia: this function should return an error code /* prepare bitstream buffers */ st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list[0]; @@ -601,10 +600,10 @@ ivas_error ivas_init_encoder( } else { - sce_brate = 0; + ism_total_brate = 0; for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - sce_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); // VE2Nokia: this function should return an error code /* prepare bitstream buffers */ @@ -625,7 +624,8 @@ ivas_error ivas_init_encoder( { ivas_omasa_enc_open( st_ivas ); } - if ( ivas_total_brate - sce_brate >= MIN_BRATE_MDCT_STEREO ) + + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } @@ -636,7 +636,7 @@ ivas_error ivas_init_encoder( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - sce_brate ); + create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - ism_total_brate ); /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7986196a08..5fca4c2222 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -111,8 +111,9 @@ ivas_error ivas_masa_enc_open( ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; #ifdef MASA_AND_OBJECTS - int32_t sce_brate; + int32_t ism_total_brate; #endif + error = IVAS_ERR_OK; if ( ( hMasa = (MASA_ENCODER_HANDLE) malloc( sizeof( MASA_ENCODER ) ) ) == NULL ) @@ -145,12 +146,12 @@ ivas_error ivas_masa_enc_open( } } #ifdef MASA_AND_OBJECTS - sce_brate = 0; + ism_total_brate = 0; if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( i = 0; i < st_ivas->nSCE; i++ ) { - sce_brate += st_ivas->hSCE[i]->element_brate; + ism_total_brate += st_ivas->hSCE[i]->element_brate; } } #endif @@ -158,12 +159,13 @@ ivas_error ivas_masa_enc_open( st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE #ifdef MASA_AND_OBJECTS , - hEncoderConfig->ivas_format, st_ivas->ism_mode, sce_brate + hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); mvs2s( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); + #ifdef MASA_AND_OBJECTS if ( hEncoderConfig->ivas_format == MASA_FORMAT || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) #else @@ -628,21 +630,23 @@ ivas_error ivas_masa_enc_config( int32_t ivas_total_brate; ivas_error error; #ifdef MASA_AND_OBJECTS - int32_t sce_brate; + int32_t ism_total_brate; #endif + error = IVAS_ERR_OK; hMasa = st_ivas->hMasa; hQMetaData = st_ivas->hQMetaData; ivas_format = st_ivas->hEncoderConfig->ivas_format; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + #ifdef MASA_AND_OBJECTS - sce_brate = 0; + ism_total_brate = 0; if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( i = 0; i < st_ivas->nSCE; i++ ) { - sce_brate += st_ivas->hSCE[i]->element_brate; + ism_total_brate += st_ivas->hSCE[i]->element_brate; } } #endif @@ -650,12 +654,11 @@ ivas_error ivas_masa_enc_config( hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE #ifdef MASA_AND_OBJECTS , - ivas_format, st_ivas->ism_mode, sce_brate + ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); hQMetaData->is_masa_ivas_format = 1; - #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else @@ -771,7 +774,7 @@ ivas_error ivas_masa_enc_config( #endif { #ifdef MASA_AND_OBJECTS - st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - sce_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; + st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE ) ? 1 : 0; #else st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ivas_total_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; #endif @@ -1902,17 +1905,17 @@ void ivas_masa_enc_reconfigure( int16_t sce_id, cpe_id; int32_t ivas_total_brate; #ifdef MASA_AND_OBJECTS - int32_t sce_brate; + int32_t ism_total_brate; #endif ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; #ifdef MASA_AND_OBJECTS - sce_brate = 0; + ism_total_brate = 0; if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - sce_brate += st_ivas->hSCE[sce_id]->element_brate; + ism_total_brate += st_ivas->hSCE[sce_id]->element_brate; } } #endif @@ -1935,8 +1938,9 @@ void ivas_masa_enc_reconfigure( copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 ); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } + #ifdef MASA_AND_OBJECTS - if ( ivas_total_brate - sce_brate < MASA_STEREO_MIN_BITRATE || ivas_total_brate - sce_brate < MIN_BRATE_MDCT_STEREO ) + if ( ivas_total_brate - ism_total_brate < MASA_STEREO_MIN_BITRATE || ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) { st_ivas->hCPE[cpe_id]->element_mode = IVAS_CPE_DFT; } @@ -1963,7 +1967,7 @@ void ivas_masa_enc_reconfigure( ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp #ifdef MASA_AND_OBJECTS , - st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, sce_brate + st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 16758a4d77..d756f063e7 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -278,20 +278,21 @@ void ivas_omasa_set_config( *--------------------------------------------------------------------------*/ void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, - IVAS_QMETADATA_HANDLE hQMeta, - MASA_ENCODER_HANDLE hMasa, - ISM_METADATA_HANDLE hIsmMeta[], - float data_in_f[][L_FRAME48k], - float data_out_f[][L_FRAME48k], - const int16_t input_frame, - const int16_t nchan_transport, - const int16_t nchan_ism, - const ISM_MODE ism_mode, - float data_separated_object[L_FRAME48k], - int16_t *idx_separated_object ) + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ + IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ + float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t nchan_transport, /* i : Number of transport channels */ + const int16_t nchan_ism, /* i : Number of objects for parameter analysis */ + const ISM_MODE ism_mode, /* i : ISM mode */ + float data_separated_object[L_FRAME48k], /* o : Separated object audio signal */ + int16_t *idx_separated_object /* o : Index of the separated object */ +) { int16_t i, j; + float data_out_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; /* Analysis */ if ( ism_mode == ISM_MODE_NONE ) @@ -481,12 +482,14 @@ void ivas_omasa_enc( /* Downmix */ ivas_omasa_dmx( data_in_f, data_out_f, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains, hOMasa->interpolator ); + /* Merge transport signals */ + ivas_merge_masa_transports( data_out_f, &( data_in_f[nchan_ism] ), data_in_f, input_frame, nchan_transport ); + return; } #ifdef OMASA_BRATE - /*-------------------------------------------------------------------------* * set_ism_importance_interformat() * -- GitLab From d4c50f64dd8e853c6d1fc208792586c5b8c92238 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 11:49:23 +0100 Subject: [PATCH 022/173] address "VE2Nokia" comments, part 2 --- lib_com/ivas_ism_config.c | 98 --------------------------------- lib_com/ivas_masa_com.c | 5 +- lib_com/ivas_omasa_com.c | 98 +++++++++++++++++++++++++++++++++ lib_com/ivas_prot.h | 10 +++- lib_dec/ivas_ism_metadata_dec.c | 2 +- lib_enc/ivas_init_enc.c | 62 ++++++++++----------- lib_enc/ivas_ism_metadata_enc.c | 20 ++----- lib_enc/ivas_omasa_enc.c | 50 +++++++---------- lib_enc/ivas_sce_enc.c | 4 +- 9 files changed, 166 insertions(+), 183 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 5a44c7de09..109e77e5cc 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -586,101 +586,3 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } - - -#ifdef MASA_AND_OBJECTS // VE2Nokia: move this function to the new file ivas_omasa_com.c (?) -/*--------------------------------------------------------------- - * ivas_omasa_ism_mode_select() - * - * selects the ISM mode base on bit-rate and number of objects in the combined ISM MASA format mode - * ---------------------------------------------------------------*/ - -/*! r : ISM format mode */ -ISM_MODE ivas_omasa_ism_mode_select( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t no_obj /* i : number of objects */ -) -{ - ISM_MODE ism_mode = ISM_MODE_NONE; - - switch ( no_obj ) - { - case 1: -#ifdef FIX_24k4_ISM1_MODE - if ( ivas_total_brate >= IVAS_24k4 ) -#else - if ( ivas_total_brate >= IVAS_32k ) -#endif - { - ism_mode = ISM_MASA_MODE_DISC; - } -#ifndef FIX_24k4_ISM1_MODE - else if ( ivas_total_brate >= IVAS_24k4 ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } -#endif - else - { - ism_mode = ISM_MODE_NONE; - } - break; - case 2: - if ( ivas_total_brate >= IVAS_64k ) - { - ism_mode = ISM_MASA_MODE_DISC; - } - else if ( ivas_total_brate >= IVAS_32k ) - { - ism_mode = ISM_MASA_MODE_ONE_OBJ; - } - /* else if ( ivas_total_brate >= IVAS_32k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } */ - else - { - ism_mode = ISM_MODE_NONE; - } - break; - case 3: - if ( ivas_total_brate >= IVAS_128k ) - { - ism_mode = ISM_MASA_MODE_DISC; - } - else if ( ivas_total_brate >= IVAS_64k ) - { - ism_mode = ISM_MASA_MODE_ONE_OBJ; - } - else if ( ivas_total_brate >= IVAS_48k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } - else - { - ism_mode = ISM_MODE_NONE; - } - break; - case 4: - if ( ivas_total_brate >= IVAS_160k ) - { - ism_mode = ISM_MASA_MODE_DISC; - } - else if ( ivas_total_brate >= IVAS_64k ) - { - ism_mode = ISM_MASA_MODE_ONE_OBJ; - } - else if ( ivas_total_brate >= IVAS_48k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } - else - { - ism_mode = ISM_MODE_NONE; - } - break; - } - - return ism_mode; -} -#endif diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 867f9512e8..c8c8f2c3e6 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -511,6 +511,7 @@ void modify_masa_energy_ratios( ) { int16_t i, m, d, b; + for ( m = 0; m < MAX_PARAM_SPATIAL_SUBFRAMES; m++ ) { if ( hQMetaData->q_direction[0].cfg.nblocks == 1 ) @@ -543,8 +544,8 @@ void modify_masa_energy_ratios( *---------------------------------------------------------------*/ void ivas_get_stereo_panning_gains( - float aziDeg, - float eleDeg, + const float aziDeg, + const float eleDeg, float panningGains[2] ) { float aziRad, eleRad; diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 121ea78076..59dc45abbc 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -55,6 +55,104 @@ #define GAMMA_ISM_HIGH_IMP2 1.35f +#ifdef MASA_AND_OBJECTS +/*--------------------------------------------------------------- + * ivas_omasa_ism_mode_select() + * + * selects the ISM mode base on bit-rate and number of objects in the combined ISM MASA format mode + * ---------------------------------------------------------------*/ + +/*! r : ISM format mode */ +ISM_MODE ivas_omasa_ism_mode_select( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t no_obj /* i : number of objects */ +) +{ + ISM_MODE ism_mode = ISM_MODE_NONE; + + switch ( no_obj ) + { + case 1: +#ifdef FIX_24k4_ISM1_MODE + if ( ivas_total_brate >= IVAS_24k4 ) +#else + if ( ivas_total_brate >= IVAS_32k ) +#endif + { + ism_mode = ISM_MASA_MODE_DISC; + } +#ifndef FIX_24k4_ISM1_MODE + else if ( ivas_total_brate >= IVAS_24k4 ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } +#endif + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 2: + if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + /* else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } */ + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 3: + if ( ivas_total_brate >= IVAS_128k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + else if ( ivas_total_brate >= IVAS_48k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_NONE; + } + break; + case 4: + if ( ivas_total_brate >= IVAS_160k ) + { + ism_mode = ISM_MASA_MODE_DISC; + } + else if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_ONE_OBJ; + } + else if ( ivas_total_brate >= IVAS_48k ) + { + ism_mode = ISM_MASA_MODE_PARAM; + } + else + { + ism_mode = ISM_MODE_NONE; + } + break; + } + + return ism_mode; +} +#endif + + /*--------------------------------------------------------------- * ivas_interformat_brate() * diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b861e3aa1d..018c68eab7 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3346,7 +3346,11 @@ void ivas_dirac_dec_binaural( ); #ifdef MASA_AND_OBJECTS -void ivas_get_stereo_panning_gains( float aziDeg, float eleDeg, float panningGains[2] ); +void ivas_get_stereo_panning_gains( + const float aziDeg, + const float eleDeg, + float panningGains[2] +); #endif ivas_error ivas_binaural_reverb_open( @@ -5121,9 +5125,9 @@ void ivas_filter_process( #ifdef MASA_AND_OBJECTS -/* ----------------------------------------------------------------------------------* +/*----------------------------------------------------------------------------------* * OMASA prototypes -* ----------------------------------------------------------------------------------*/ +*---------------------------------------------------------------------------------*/ ivas_error ivas_omasa_enc_open( Encoder_Struct* st_ivas /* i/o: IVAS encoder handle */ diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 0d3b5fa572..b5fa185a18 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -504,7 +504,7 @@ ivas_error ivas_ism_metadata_dec( { #ifdef MASA_AND_OBJECTS int16_t masa_ism_flag = 0; - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) // VE2Nokia: ISM_MASA_MODE_ONE_OBJ looks obsolete here + if ( ism_mode == ISM_MASA_MODE_DISC ) { masa_ism_flag = 1; } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 63bba1d337..0e5114bfbe 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -571,12 +571,9 @@ ivas_error ivas_init_encoder( st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); st_ivas->nchan_transport = 2; - create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ); // VE2Nokia: this function should return an error code - /* the values of element_brate_tmp will be re-written in MASA_ISM_FORMAT because they are taken from sep_object_brate[][]*/ - - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + if ( ( error = create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) { - st_ivas->nSCE = st_ivas->nchan_ism; + return error; } k = 0; @@ -585,44 +582,42 @@ ivas_error ivas_init_encoder( k++; } - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - /* use the bitrate for one object */ - ism_total_brate = sep_object_brate[k - 2][0]; - create_sce_enc( st_ivas, 0, ism_total_brate ); // VE2Nokia: this function should return an error code + ism_total_brate = 0; - /* prepare bitstream buffers */ - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list = ind_list[0]; - reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - st_ivas->hSCE[0]->hMetaData->ind_list = ind_list_metadata[0]; - reset_indices_enc( st_ivas->hSCE[0]->hMetaData, MAX_BITS_METADATA ); - } - else + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = 0; - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + if ( ( error = create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK ) { - ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); // VE2Nokia: this function should return an error code + return error; + } - /* prepare bitstream buffers */ - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; - reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); + /* prepare bitstream buffers */ + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata[sce_id]; - reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); - } + st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata[sce_id]; + reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); } - // VE2Nokia: following functions should return an error code - ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); - ivas_masa_enc_open( st_ivas ); + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { - ivas_omasa_enc_open( st_ivas ); + if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) @@ -636,7 +631,10 @@ ivas_error ivas_init_encoder( for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - ism_total_brate ); + if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index bd9183f92f..131a2e3bfc 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -943,6 +943,8 @@ ivas_error create_ism_metadata_enc( ) { int16_t ch, nchan_transport; + + // VE: this part of the code is better to be moved to a separate function, e.g. ivas_set_omasa_TC() #ifdef MASA_AND_OBJECTS nchan_transport = st_ivas->nchan_transport; if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) @@ -957,25 +959,14 @@ ivas_error create_ism_metadata_enc( st_ivas->nCPE = 1; st_ivas->nSCE = 1; break; - case ISM_MODE_DISC: // VE2Nokia: this cannot happen - st_ivas->nCPE = 1; - st_ivas->nSCE = n_ISms; - break; case ISM_MASA_MODE_DISC: st_ivas->nCPE = 1; st_ivas->nSCE = n_ISms; break; case ISM_MODE_NONE: - if ( nchan_transport == 1 ) // VE2Nokia: this cannot happen - { - st_ivas->nSCE = 1; - st_ivas->nCPE = 0; - } - else - { - st_ivas->nSCE = 0; - st_ivas->nCPE = 1; - } + st_ivas->nSCE = 0; + st_ivas->nCPE = 1; + break; default: break; @@ -1014,6 +1005,7 @@ ivas_error create_ism_metadata_enc( #ifdef MASA_AND_OBJECTS } #endif + /* allocate ISm metadata handles */ for ( ch = 0; ch < n_ISms; ch++ ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index d756f063e7..96490893c7 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -949,48 +949,36 @@ static void ivas_omasa_dmx( float gains[MASA_MAX_TRANSPORT_CHANNELS]; float g1, g2; - if ( nchan_transport == 2 ) + + for ( i = 0; i < nchan_transport; i++ ) { - for ( i = 0; i < nchan_transport; i++ ) - { - set_zero( data_out_f[i], input_frame ); - } + set_zero( data_out_f[i], input_frame ); + } - for ( i = 0; i < nchan_ism; i++ ) - { - azimuth = hIsmMeta[i]->azimuth; - elevation = hIsmMeta[i]->elevation; + for ( i = 0; i < nchan_ism; i++ ) + { + azimuth = hIsmMeta[i]->azimuth; + elevation = hIsmMeta[i]->elevation; - ivas_get_stereo_panning_gains( azimuth, elevation, gains ); + ivas_get_stereo_panning_gains( azimuth, elevation, gains ); - /* Downmix using the panning gains */ - for ( j = 0; j < nchan_transport; j++ ) + /* Downmix using the panning gains */ + for ( j = 0; j < nchan_transport; j++ ) + { + if ( fabsf( gains[j] ) > 0.0 || fabsf( prev_gains[i][j] ) > 0.0f ) { - if ( fabsf( gains[j] ) > 0.0 || fabsf( prev_gains[i][j] ) > 0.0f ) + for ( k = 0; k < input_frame; k++ ) { - for ( k = 0; k < input_frame; k++ ) - { - g1 = interpolator[k]; - g2 = 1.0f - g1; - data_out_f[j][k] += ( g1 * gains[j] + g2 * prev_gains[i][j] ) * data_in_f[i][k]; - } + g1 = interpolator[k]; + g2 = 1.0f - g1; + data_out_f[j][k] += ( g1 * gains[j] + g2 * prev_gains[i][j] ) * data_in_f[i][k]; } - prev_gains[i][j] = gains[j]; - } - } - } - else if ( nchan_transport == 1 ) // VE2Nokia: is ti relevant? - { - for ( i = 0; i < input_frame; i++ ) - { - data_out_f[0][i] = 0.0f; - for ( j = 0; j < nchan_ism; j++ ) - { - data_out_f[0][i] += data_in_f[j][i]; } + prev_gains[i][j] = gains[j]; } } + return; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index de1c0466ce..1bfe4773a1 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -350,9 +350,9 @@ ivas_error create_sce_enc( copy_encoder_config( st_ivas, st, 1 ); #ifdef MASA_AND_OBJECTS - if ( st_ivas->ism_mode >= ISM_MASA_MODE_PARAM ) // VE2Nokia: ??? + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { - st->element_mode = IVAS_SCE; /* To do: Nokia check as this is not optimal and verify if it influences other SCE modes */ + st->element_mode = IVAS_SCE; } #endif -- GitLab From af4fb067d299fb6c73ea2b150286f3c8f94ff97c Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 12:17:33 +0100 Subject: [PATCH 023/173] address "VE2Nokia" comments, part 3/3 --- lib_com/ivas_rom_com.c | 54 +++++++++++++++++++++------------------- lib_com/ivas_rom_com.h | 15 +++++------ lib_enc/ivas_enc.c | 19 +++++++------- lib_enc/ivas_init_enc.c | 9 +++---- lib_enc/ivas_omasa_enc.c | 4 +-- lib_enc/ivas_stat_enc.h | 6 ++--- lib_enc/lib_enc.c | 17 ++++--------- lib_enc/lib_enc.h | 2 +- 8 files changed, 60 insertions(+), 66 deletions(-) diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 641a5f5c84..4e2ef7b596 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2784,8 +2784,7 @@ const float McMASA_LFEGain_vectors[64] = * OMASA ROM tables *----------------------------------------------------------------------------------*/ -// VE2Nokia: add "const" to the arrays -int32_t sep_object_brate[][MAX_NUM_OBJECTS] = +const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = { {0, 0, 0, 0}, /* 13k2 */ {0, 0, 0, 0}, /* 16k4 */ @@ -2812,29 +2811,34 @@ int32_t sep_object_brate[][MAX_NUM_OBJECTS] = }; /* column wise DCT matrices for 4 5, and 8 dim */ - float dct4[] = { - 0.5000f, 0.6533f, 0.5000f, 0.2706f, - 0.5000f, 0.2706f, -0.5000f, -0.6533f, - 0.5000f, -0.2706f, -0.5000f, 0.6533f, - 0.5000f, -0.6533f, 0.5000f, -0.2706f - }; - - float dct5[] = { - 0.4472f, 0.6015f, 0.5117f, 0.3717f, 0.1954f, - 0.4472f, 0.3717f, -0.1954f, -0.6015f, -0.5117f, - 0.4472f, 0.0000f, -0.6325f, -0.0000f, 0.6325f, - 0.4472f, -0.3717f, -0.1954f, 0.6015f, -0.5117f, - 0.4472f, -0.6015f, 0.5117f, -0.3717f, 0.1954f - }; - - float dct8[] = { - 0.3536f, 0.4904f, 0.4619f, 0.4157f, 0.3536f, 0.2778f, 0.1913f, 0.0975f, 0.3536f, 0.4157f, - 0.1913f, -0.0975f, -0.3536f, -0.4904f, -0.4619f, -0.2778f, 0.3536f, 0.2778f, -0.1913f, -0.4904f, - -0.3536f, 0.0975f, 0.4619f, 0.4157f, 0.3536f, 0.0975f, -0.4619f, -0.2778f, 0.3536f, 0.4157f, - -0.1913f, -0.4904f, 0.3536f, -0.0975f, -0.4619f, 0.2778f, 0.3536f, -0.4157f, -0.1913f, 0.4904f, - 0.3536f, -0.2778f, -0.1913f, 0.4904f, -0.3536f, -0.0975f, 0.4619f, -0.4157f, 0.3536f, -0.4157f, - 0.1913f, 0.0975f, -0.3536f, 0.4904f, -0.4619f, 0.2778f, 0.3536f, -0.4904f, 0.4619f, -0.4157f, - 0.3536f, -0.2778f, 0.1913f, -0.0975f }; +const float dct4[4*4] = +{ + 0.5000f, 0.6533f, 0.5000f, 0.2706f, + 0.5000f, 0.2706f, -0.5000f, -0.6533f, + 0.5000f, -0.2706f, -0.5000f, 0.6533f, + 0.5000f, -0.6533f, 0.5000f, -0.2706f +}; + +const float dct5[5*5] = +{ + 0.4472f, 0.6015f, 0.5117f, 0.3717f, 0.1954f, + 0.4472f, 0.3717f, -0.1954f, -0.6015f, -0.5117f, + 0.4472f, 0.0000f, -0.6325f, -0.0000f, 0.6325f, + 0.4472f, -0.3717f, -0.1954f, 0.6015f, -0.5117f, + 0.4472f, -0.6015f, 0.5117f, -0.3717f, 0.1954f +}; + +const float dct8[8*8] = +{ + 0.3536f, 0.4904f, 0.4619f, 0.4157f, 0.3536f, 0.2778f, 0.1913f, 0.0975f, + 0.3536f, 0.4157f, 0.1913f, -0.0975f, -0.3536f, -0.4904f, -0.4619f, -0.2778f, + 0.3536f, 0.2778f, -0.1913f, -0.4904f, -0.3536f, 0.0975f, 0.4619f, 0.4157f, + 0.3536f, 0.0975f, -0.4619f, -0.2778f, 0.3536f, 0.4157f, -0.1913f, -0.4904f, + 0.3536f, -0.0975f, -0.4619f, 0.2778f, 0.3536f, -0.4157f, -0.1913f, 0.4904f, + 0.3536f, -0.2778f, -0.1913f, 0.4904f, -0.3536f, -0.0975f, 0.4619f, -0.4157f, + 0.3536f, -0.4157f, 0.1913f, 0.0975f, -0.3536f, 0.4904f, -0.4619f, 0.2778f, + 0.3536f, -0.4904f, 0.4619f, -0.4157f, 0.3536f, -0.2778f, 0.1913f, -0.0975f +}; #endif /*----------------------------------------------------------------------------------* diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index acf2a80924..036538a032 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -256,7 +256,6 @@ extern const uint16_t ivas_param_mc_sym_freq_icc_combined_48_16bits[PARAM_MC_SZ_ extern const uint16_t ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER]; extern const uint16_t ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[2 * PARAM_MC_SZ_ICC_QUANTIZER - 1]; - /*----------------------------------------------------------------------------------* * MASA ROM tables *----------------------------------------------------------------------------------*/ @@ -313,11 +312,14 @@ extern const float cb_azi_chan[]; extern const float McMASA_LFEGain_vectors[64]; #ifdef MASA_AND_OBJECTS -/* MASA and ISM combined format */ -extern int32_t sep_object_brate[][MAX_NUM_OBJECTS]; -extern float dct4[]; -extern float dct5[]; -extern float dct8[]; +/*----------------------------------------------------------------------------------* + * MASA and ISM (OMASA) combined format ROM tables + *----------------------------------------------------------------------------------*/ + +extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS]; +extern const float dct4[]; +extern const float dct5[]; +extern const float dct8[]; #endif /*----------------------------------------------------------------------------------* @@ -333,7 +335,6 @@ extern const float ism_elevation_borders[4]; extern const int16_t Param_ISM_band_grouping[MAX_PARAM_ISM_NBANDS + 1]; - /*----------------------------------------------------------------------------------* * LFE coding ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 070554b9e2..a9e459bc81 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -266,7 +266,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0, NULL + ISM_MODE_NONE, -1, NULL, -1, NULL #endif ); } @@ -321,10 +321,10 @@ ivas_error ivas_enc( hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ - if ( ( st_ivas->hEncoderConfig->nchan_inp - st_ivas->nchan_ism ) == 1 ) + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) { - v_multc( data_f[st_ivas->nchan_ism], 1.0f / SQRT2, data_f[st_ivas->nchan_ism], input_frame ); - mvr2r( data_f[st_ivas->nchan_ism], data_f[st_ivas->nchan_ism + 1], input_frame ); + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } /* nb_bits_metadata[0] = 0; */ @@ -345,13 +345,13 @@ ivas_error ivas_enc( } /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[st_ivas->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); } /* Encode ISMs transport channels */ @@ -370,12 +370,12 @@ ivas_error ivas_enc( { return error; } - n = st_ivas->nchan_ism; + n = st_ivas->hEncoderConfig->nchan_ism; } /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); /* Configuration of combined-format bit-budget distribution */ #ifdef DEBUG_VA @@ -496,11 +496,10 @@ ivas_error ivas_enc( ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, 0, NULL + ISM_MODE_NONE, -1, NULL, -1, NULL #endif ); - if ( st_ivas->hMcMasa->separateChannelEnabled ) { if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 0e5114bfbe..909115d63e 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -568,10 +568,10 @@ ivas_error ivas_init_encoder( int32_t ism_total_brate; int16_t k; - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); st_ivas->nchan_transport = 2; - if ( ( error = create_ism_metadata_enc( st_ivas, st_ivas->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) + if ( ( error = create_ism_metadata_enc( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) { return error; } @@ -583,8 +583,6 @@ ivas_error ivas_init_encoder( } ism_total_brate = 0; - - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; @@ -601,7 +599,6 @@ ivas_error ivas_init_encoder( reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); } - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; @@ -1103,7 +1100,7 @@ void ivas_destroy_enc( #ifdef MASA_AND_OBJECTS if ( st_ivas->hOMasa != NULL ) { - ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->nchan_ism ); + ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); st_ivas->hOMasa = NULL; } #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 96490893c7..edc2f77cbf 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -87,7 +87,7 @@ ivas_error ivas_omasa_enc_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA encoder\n" ) ); } - numAnalysisChannels = st_ivas->nchan_ism; + numAnalysisChannels = st_ivas->hEncoderConfig->nchan_ism; /* initialize delay compensation */ hOMasa->num_samples_delay_comp = NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS ); @@ -595,7 +595,7 @@ void ivas_set_surplus_brate_enc( } else { - for ( int16_t i = 0; i < st_ivas->nchan_ism; i++ ) + for ( int16_t i = 0; i < st_ivas->hEncoderConfig->nchan_ism; i++ ) { tmpF += st_ivas->hSCE[i]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[i + 1] * 50 ); } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index bf574dbfcb..ed07d884bd 100755 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1057,6 +1057,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 MASA_AND_OBJECTS + int16_t nchan_ism; /* number of ISM input channels in combined format coding */ +#endif int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ @@ -1100,9 +1103,6 @@ typedef struct /* high-level encoder parameters */ int16_t nchan_transport; /* number of transport channels */ -#ifdef MASA_AND_OBJECTS - int16_t nchan_ism; // VE2Nokia: move it under hEncoderConfig, or remove it and replace it by "nchan_inp - 2" in the code -#endif int16_t sba_analysis_order; /* Ambisonic (SBA) order used for analysis and coding */ int16_t codec_mode; /* Mode1 or Mode2 of core codec */ int16_t last_codec_mode; /* previous frame Mode 1 or 2 */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 09e4b1e03f..3aaddb3c33 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -366,7 +366,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const uint16_t numObjects, /* i : number of objects to be encoded */ - const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ + const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ ) { Encoder_Struct *st_ivas; @@ -384,12 +384,8 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( st_ivas = hIvasEnc->st_ivas; switch ( masaVariant ) { - case IVAS_ENC_MASA_1CH: // VE2Nokia: seems not needeed - st_ivas->hEncoderConfig->nchan_inp = 1 + numObjects; - st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ - break; case IVAS_ENC_MASA_2CH: - st_ivas->hEncoderConfig->nchan_inp = 2 + numObjects; + st_ivas->hEncoderConfig->nchan_inp = CPE_CHANNELS + numObjects; st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ break; default: @@ -401,11 +397,8 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */ st_ivas->nchan_transport = st_ivas->hEncoderConfig->nchan_inp - numObjects; - - st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT; - - st_ivas->nchan_ism = numObjects; + st_ivas->hEncoderConfig->nchan_ism = numObjects; return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() ); } @@ -870,9 +863,9 @@ static ivas_error configureEncoder( #ifdef MASA_AND_OBJECTS else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { - st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); - cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_ism ); + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); /*adapt element_mode according to the bit-rate*/ if ( hEncoderConfig->element_mode_init != IVAS_SCE ) diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index d66e58e1dd..06b89f85fc 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -205,7 +205,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */ const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */ const uint16_t numObjects, /* i : number of objects to be encoded */ - const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ + const int16_t masaVariant /* i : index specifying the number of MASA transport channels */ ); #endif -- GitLab From 57e03bab9d039f7f3365c906cc8e0513d5230d52 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 12:30:21 +0100 Subject: [PATCH 024/173] add error code to return of ivas_masa_ism_data_open() --- lib_com/ivas_omasa_com.c | 3 ++- lib_com/ivas_prot.h | 2 +- lib_dec/ivas_init_dec.c | 13 ++++++++++--- lib_dec/ivas_masa_dec.c | 12 ++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 59dc45abbc..43f6344daa 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -59,7 +59,8 @@ /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() * - * selects the ISM mode base on bit-rate and number of objects in the combined ISM MASA format mode + * selects the ISM mode base on IVAS total bit-rate and + * the number of objects in the combined ISM MASA format mode * ---------------------------------------------------------------*/ /*! r : ISM format mode */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 018c68eab7..7057d8d350 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5209,7 +5209,7 @@ void ivas_merge_masa_transports( const int16_t num_transport_channels /* i : Number of transport audio signals */ ); -void ivas_masa_ism_data_open( +ivas_error ivas_masa_ism_data_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f20dbf1f09..eb02830150 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1009,14 +1009,21 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nSCE, temp_brate ) ) != IVAS_ERR_OK ) + if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) { return error; } } - ivas_masa_dec_open( st_ivas ); - ivas_masa_ism_data_open( st_ivas ); + if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_ism_data_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 06646b2ab9..09aff57be9 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -558,18 +558,16 @@ ivas_error ivas_masa_dec_open( * *-------------------------------------------------------------------*/ -void ivas_masa_ism_data_open( +ivas_error ivas_masa_ism_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { MASA_ISM_DATA_HANDLE hMasaIsmData; - int16_t bin; - int16_t ch; + int16_t ch, bin; if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) { - fprintf( stderr, "Can not allocate memory for MASA_ISM data\n" ); - exit( -1 ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) ); } for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) @@ -588,9 +586,11 @@ void ivas_masa_ism_data_open( hMasaIsmData->delayBuffer = NULL; st_ivas->hMasaIsmData = hMasaIsmData; - return; + return IVAS_ERR_OK; } #endif + + /*-----------------------------------------------------------------------* * ivas_masa_dec_close() * -- GitLab From bf1c0053a26de0a838e570a7e26478c6f3253397 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 13:02:51 +0100 Subject: [PATCH 025/173] remove DEBUG_MODE_INFO --- lib_com/ivas_prot.h | 2 +- lib_com/options.h | 1 - lib_enc/ivas_core_enc.c | 8 -------- lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 8 ++------ 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7057d8d350..637adbda6e 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5161,7 +5161,7 @@ void ivas_omasa_enc( #ifdef OMASA_BRATE void ivas_set_surplus_brate_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -#ifdef DEBUG_VA +#ifdef DEBUG_MODE_INFO , const int16_t *nb_bits_metadata /* i : number of metadata bits */ #endif diff --git a/lib_com/options.h b/lib_com/options.h index d73306ae58..bf239e537c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -165,7 +165,6 @@ #define MASA_AND_OBJECTS_VE // VA: improve codec print-outs #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo -#define DEBUG_VA // output 'res/brate_ism' and 'res_brate_masa' bit-rates debugging files #endif diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index c4f4b376c6..a55d6bab69 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -200,14 +200,6 @@ ivas_error ivas_core_enc( { ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, &( sts[0]->core_brate ), &diff_nBits ); } - -#ifdef DEBUG_VA - if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT ) - { - diff_nBits = max( diff_nBits, 0 ); - dbgwrite( &diff_nBits, 2, 1, 960, "res/_diff" ); - } -#endif #endif /*---------------------------------------------------------------------* diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a9e459bc81..a452b6dbf1 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -378,7 +378,7 @@ ivas_error ivas_enc( st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); /* Configuration of combined-format bit-budget distribution */ -#ifdef DEBUG_VA +#ifdef DEBUG_MODE_INFO ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata ); #else ivas_set_surplus_brate_enc( st_ivas ); diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index edc2f77cbf..bb2e898af4 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -473,10 +473,6 @@ void ivas_omasa_enc( /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); - -#ifdef DEBUG_VA - dbgwrite( &selected_object, 2, 1, input_frame, "res/selected_object" ); -#endif } /* Downmix */ @@ -564,7 +560,7 @@ void set_ism_importance_interformat( void ivas_set_surplus_brate_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ -#ifdef DEBUG_VA +#ifdef DEBUG_MODE_INFO , const int16_t *nb_bits_metadata /* i : number of metadata bits */ #endif @@ -584,7 +580,7 @@ void ivas_set_surplus_brate_enc( st_ivas->hCPE[0]->brate_surplus = 0; } -#ifdef DEBUG_VA +#ifdef DEBUG_MODE_INFO if ( st_ivas->hSCE[0] != NULL ) { int16_t input_frame = (int16_t) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); -- GitLab From 78b6266d59957ac09914d915f3f4599c8dd7872b Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 13:06:12 +0100 Subject: [PATCH 026/173] accept MASA_AND_OBJECTS and FIX_24k4_ISM1_MODE --- lib_com/bitstream.c | 4 ++-- lib_com/ivas_omasa_com.c | 10 ---------- lib_com/options.h | 3 +-- lib_dec/lib_dec.c | 4 ++-- lib_enc/lib_enc.c | 4 ---- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index b90c6d4ac7..42df9966de 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1812,7 +1812,7 @@ ivas_error preview_indices( else { st_ivas->ivas_format = MASA_FORMAT; -#ifdef MASA_AND_OBJECTS_VE +#ifdef MASA_AND_OBJECTS if ( bit_stream[3] ) { st_ivas->ivas_format = MASA_ISM_FORMAT; @@ -1974,7 +1974,7 @@ ivas_error preview_indices( ivas_sba_config( total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &( st_ivas->nSCE ), &( st_ivas->nCPE ), &( st_ivas->element_mode_init ) ); } -#ifdef MASA_AND_OBJECTS_VE +#ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { /* read number of objects from the bitstream */ diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 43f6344daa..46ebcc6e9d 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -74,20 +74,10 @@ ISM_MODE ivas_omasa_ism_mode_select( switch ( no_obj ) { case 1: -#ifdef FIX_24k4_ISM1_MODE if ( ivas_total_brate >= IVAS_24k4 ) -#else - if ( ivas_total_brate >= IVAS_32k ) -#endif { ism_mode = ISM_MASA_MODE_DISC; } -#ifndef FIX_24k4_ISM1_MODE - else if ( ivas_total_brate >= IVAS_24k4 ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } -#endif else { ism_mode = ISM_MODE_NONE; diff --git a/lib_com/options.h b/lib_com/options.h index bf239e537c..9c1f24fd93 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -161,8 +161,7 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define FIX_24k4_ISM1_MODE // activate DISC mode at 24.4 kbps 1 object -#define MASA_AND_OBJECTS_VE // VA: improve codec print-outs + #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index fab25168be..e0dbdc1a75 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1880,7 +1880,7 @@ static ivas_error printConfigInfo_dec( { fprintf( stdout, "Input configuration: MASA - %d channel(s)\n", st_ivas->nchan_transport ); } -#ifdef MASA_AND_OBJECTS_VE +#ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MC_FORMAT ) #else else /* MC_FORMAT */ @@ -1893,7 +1893,7 @@ static ivas_error printConfigInfo_dec( fprintf( stdout, "Input configuration: %s\n", config_str ); } -#ifdef MASA_AND_OBJECTS_VE +#ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { fprintf( stdout, "Input configuration: combined ISM and MASA (%i separated ISM stream(s)) \n", st_ivas->nchan_transport ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 3aaddb3c33..f600d0fa91 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1631,11 +1631,7 @@ static ivas_error printConfigInfo_enc( #ifdef MASA_AND_OBJECTS else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { -#ifdef MASA_AND_OBJECTS_VE fprintf( stdout, "IVAS format: combined ISM and MASA (%i ISM stream(s))\n", hEncoderConfig->nchan_inp - 2 ); -#else - fprintf( stdout, "IVAS format: MASA and objects format\n" ); -#endif } #endif -- GitLab From c2d2b14e5e1d284da22a2f3641494fa524075fd0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 13:10:38 +0100 Subject: [PATCH 027/173] merge OMASA_BRATE_TD into OMASA_BRATE --- lib_com/options.h | 11 ++++------- lib_dec/ivas_cpe_dec.c | 4 +--- lib_dec/ivas_stereo_switching_dec.c | 2 +- lib_dec/ivas_stereo_td_dec.c | 20 ++++++++++---------- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_stereo_td_enc.c | 4 ++-- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9c1f24fd93..eae524fed2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,14 +157,11 @@ #define FIX_268 /* Issue 268: Add low cost dry-run of memory analysis */ #define LOW_RATE_TRANS_FIX /* Eri: Fix for critical item during transitions */ -#define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ -#ifdef MASA_AND_OBJECTS -#define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ - - -#define OMASA_BRATE /* VA: combined format bit-budget distribution */ -#define OMASA_BRATE_TD // support of bitrate adaptation in TD stereo +#define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ +#ifdef MASA_AND_OBJECTS +#define OMASA_BRATE /* VA: combined format bit-budget distribution */ +#define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 356789d07f..3311e1e501 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -171,7 +171,6 @@ ivas_error ivas_cpe_dec( } else { - #endif stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); #ifdef MASA_AND_OBJECTS @@ -296,7 +295,7 @@ ivas_error ivas_cpe_dec( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif if ( st_ivas->hQMetaData != NULL ) @@ -361,7 +360,6 @@ ivas_error ivas_cpe_dec( } } else - { /* subtract metadata bitbudget */ /* IVAS_fmToDo: TBC whether it is not better to distribute the metadata bits equally between 2 channels */ sts[0]->bits_frame_channel -= nb_bits_metadata; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index bed57060a1..eeb53ff011 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -767,7 +767,7 @@ ivas_error stereo_memory_dec( if ( hCPE->hCoreCoder[0]->bfi == 0 ) { st = hCPE->hCoreCoder[1]; -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); #else hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 2e6e447bd7..0c6fe6213d 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -94,7 +94,7 @@ void tdm_configure_dec( int16_t tdm_tmp_SM_LRTD_flag; int16_t mod_ct, core, bits_offset; int16_t idx_LRTD_pri_side, tdm_inst_ratio_idx; -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE int32_t element_brate_adapt; int16_t bstr_last_pos; #endif @@ -102,7 +102,7 @@ void tdm_configure_dec( hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE element_brate_adapt = hCPE->element_brate + hCPE->brate_surplus; bstr_last_pos = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif @@ -132,7 +132,7 @@ void tdm_configure_dec( /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); #else sts[1]->coder_type = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); @@ -164,7 +164,7 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ /* Get the correlation ratio */ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, (int16_t) ( bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); #else *tdm_ratio_idx = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); @@ -174,7 +174,7 @@ void tdm_configure_dec( if ( sts[1]->coder_type == INACTIVE ) { /* Get the flag on the LPC reusage type (primary channel of ave LPC */ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); #else hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); @@ -184,7 +184,7 @@ void tdm_configure_dec( else { /* Get the flag on the LPC reusage */ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); #else hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); @@ -244,7 +244,7 @@ void tdm_configure_dec( int16_t tmpS = 20; if ( hStereoTD->tdm_LRTD_flag == 0 ) { -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE tmpS = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); #else tmpS = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); @@ -257,7 +257,7 @@ void tdm_configure_dec( { if ( hStereoTD->tdm_LRTD_flag == 0 ) { -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS, STEREO_BITS_TCA_CHAN ); hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN, STEREO_BITS_TCA_CORRSTATS ); hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); @@ -285,7 +285,7 @@ void tdm_configure_dec( #endif /* set the BW of the secondary channel */ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE if ( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel > IVAS_16k4 / FRAMES_PER_SEC ) #else if ( hStereoTD->tdm_LRTD_flag && hCPE->element_brate > IVAS_13k2 ) @@ -304,7 +304,7 @@ void tdm_configure_dec( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 536272a94c..013e1a2abd 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -396,7 +396,7 @@ ivas_error ivas_cpe_enc( /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif if ( st_ivas->hQMetaData != NULL ) diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index c42b2fe748..8a7c10f5f3 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -419,7 +419,7 @@ void tdm_configure_enc( sts[1]->coder_type = GENERIC; } -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) { sts[1]->coder_type = INACTIVE; @@ -469,7 +469,7 @@ void tdm_configure_enc( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ -#ifdef OMASA_BRATE_TD +#ifdef OMASA_BRATE tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, -- GitLab From cfe0a8b7a20c893f841f6a3d07a13d5caec283a4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Jan 2023 13:30:42 +0100 Subject: [PATCH 028/173] fix for 64 kbps 2 obj; under OMASA_BRATE --- lib_com/ivas_rom_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 4e2ef7b596..6d8d255aed 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2796,7 +2796,7 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = #endif {IVAS_13k2, 0, 0, 0}, /* 48k */ #ifdef OMASA_BRATE - {16000, 12000, 0, 0}, /* 64k */ + {16000, 11700, 0, 0}, /* 64k */ #else {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif -- GitLab From 5d295d691207e93e0e325e76950c09f708a3d922 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Jan 2023 11:46:50 +0100 Subject: [PATCH 029/173] fix compilation when OMASA_BRATE is disabled --- lib_com/ivas_omasa_com.c | 9 ++++----- lib_com/options.h | 2 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_enc.c | 18 +++++------------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 46ebcc6e9d..38733ff97e 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -39,7 +39,7 @@ #include "debug.h" #endif - +#ifdef MASA_AND_OBJECTS #ifdef OMASA_BRATE /*--------------------------------------------------------------- * Local constants @@ -53,9 +53,8 @@ #define GAMMA_ISM_LOW_IMP2 0.9f #define GAMMA_ISM_MEDIUM_IMP2 1.2f #define GAMMA_ISM_HIGH_IMP2 1.35f +#endif - -#ifdef MASA_AND_OBJECTS /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() * @@ -141,9 +140,9 @@ ISM_MODE ivas_omasa_ism_mode_select( return ism_mode; } -#endif +#ifdef OMASA_BRATE /*--------------------------------------------------------------- * ivas_interformat_brate() * @@ -267,5 +266,5 @@ void ivas_combined_format_brate_sanity( return; } - +#endif #endif diff --git a/lib_com/options.h b/lib_com/options.h index eae524fed2..a6c9939967 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS -#define OMASA_BRATE /* VA: combined format bit-budget distribution */ +//#define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 013e1a2abd..b4d54d397f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -626,7 +626,7 @@ ivas_error ivas_cpe_enc( if ( ivas_format == MASA_ISM_FORMAT ) { - cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, hEncoderConfig->nchan_ism ); } #endif diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a452b6dbf1..68d0bcb873 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -310,9 +310,6 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS else if ( ivas_format == MASA_ISM_FORMAT ) { -#ifndef OMASA_BRATE - float data_transport_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; -#endif float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; @@ -396,27 +393,22 @@ ivas_error ivas_enc( } else { - st_ivas->nSCE = st_ivas->nchan_ism; + st_ivas->nSCE = hEncoderConfig->nchan_ism; } /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[st_ivas->nchan_ism] ), input_frame, st_ivas->nchan_transport ); + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, data_transport_f, input_frame, st_ivas->nchan_transport, st_ivas->nchan_ism, st_ivas->ism_mode, + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); } /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, st_ivas->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Merge transport signals */ - ivas_merge_masa_transports( data_transport_f, &( data_f[st_ivas->nchan_ism] ), data_f, input_frame, st_ivas->nchan_transport ); - } + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); } /* Encode transport signals */ @@ -432,7 +424,7 @@ ivas_error ivas_enc( { return error; } - n = st_ivas->nchan_ism; + n = hEncoderConfig->nchan_ism; } #endif /* OMASA_BRATE */ -- GitLab From 7514365119a609914da2913f5c4c19d6f4c54562 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Jan 2023 12:22:39 +0100 Subject: [PATCH 030/173] fix crash due to too high 'max_bits' for residual coding in DFT stereo --- lib_enc/ivas_cpe_enc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index b4d54d397f..6c33d77650 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -630,6 +630,7 @@ ivas_error ivas_cpe_enc( } #endif + /* DFT stereo side bits */ if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && cpe_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) { nb_bits = 0; /* Only mono downmix is transmitted in this case */ @@ -643,10 +644,19 @@ ivas_error ivas_cpe_enc( stereo_dft_enc_write_BS( hCPE, &nb_bits ); } + /* Residual coding in MDCT domain */ if ( !( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) ) ) { - /* Residual coding in MDCT domain */ - stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal - ( ( ivas_format == MASA_FORMAT ) ? nb_bits_metadata : 0 ) ) ); + int16_t max_bits = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + max_bits -= nb_bits_metadata; +#ifdef OMASA_BRATE + max_bits += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); +#endif + } + + stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); } #else if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) -- GitLab From e2bca22e00c922f277a1c76f9098ac040d1dadd7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Jan 2023 12:28:03 +0100 Subject: [PATCH 031/173] formatting --- lib_com/options.h | 2 +- lib_enc/ivas_masa_enc.c | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index a6c9939967..eae524fed2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS -//#define OMASA_BRATE /* VA: combined format bit-budget distribution */ +#define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 5fca4c2222..466b422a85 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -61,25 +61,18 @@ static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR #ifdef MASA_AND_OBJECTS static void ivas_merge_masa_metadatas( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); -static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ - int16_t low_bitrate_mode, /* i: is low bitrate more? 1/0 */ - int16_t omasa_nbands, - int16_t omasa_nblocks - -); +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], int16_t low_bitrate_mode, int16_t omasa_nbands, int16_t omasa_nblocks ); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); - static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t no_ism, float masa_to_total_energy_ratio ); static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio ); + static void transform_index_and_GR_encode( int16_t *diff_idx, int16_t len, int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); + static void transform_difference_index( int16_t *diff_idx, int16_t *idx, int16_t len ); #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); -- GitLab From d4ded142c6fab96d83cecdd190f64be9c551f0f8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 28 Jan 2023 14:38:38 +0100 Subject: [PATCH 032/173] add TUNING_96kbps_3obj --- lib_com/ivas_omasa_com.c | 39 ++++++++++++++++++++++++++++----- lib_com/ivas_prot.h | 5 +++-- lib_com/ivas_rom_com.c | 4 ++++ lib_com/options.h | 3 +++ lib_dec/ivas_omasa_dec.c | 4 ++-- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 2 +- lib_enc/ivas_sce_enc.c | 2 +- 9 files changed, 49 insertions(+), 14 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 38733ff97e..7729929c96 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -53,6 +53,10 @@ #define GAMMA_ISM_LOW_IMP2 0.9f #define GAMMA_ISM_MEDIUM_IMP2 1.2f #define GAMMA_ISM_HIGH_IMP2 1.35f + +#define GAMMA_ISM_LOW_IMP3 0.85f +#define GAMMA_ISM_MEDIUM_IMP3 1.15f +#define GAMMA_ISM_HIGH_IMP3 1.3f #endif /*--------------------------------------------------------------- @@ -64,13 +68,13 @@ /*! r : ISM format mode */ ISM_MODE ivas_omasa_ism_mode_select( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t no_obj /* i : number of objects */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t nchan_ism /* i : number of input ISM's */ ) { ISM_MODE ism_mode = ISM_MODE_NONE; - switch ( no_obj ) + switch ( nchan_ism ) { case 1: if ( ivas_total_brate >= IVAS_24k4 ) @@ -101,7 +105,11 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 3: +#ifdef TUNING_96kbps_3obj + if ( ivas_total_brate >= IVAS_96k ) +#else if ( ivas_total_brate >= IVAS_128k ) +#endif { ism_mode = ISM_MASA_MODE_DISC; } @@ -152,6 +160,7 @@ ISM_MODE ivas_omasa_ism_mode_select( /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ ) @@ -168,9 +177,27 @@ int32_t ivas_interformat_brate( } else { - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || - ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 9600 and 1 object */ - ) +#ifdef TUNING_96kbps_3obj + if ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism == 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ + { + if ( ism_imp == ISM_LOW_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); + } + else if ( ism_imp == ISM_MEDIUM_IMP ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); + } + else /* ISM_HIGH_IMP */ + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); + } + } + else +#endif + if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || + ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ + ) { if ( ism_imp == ISM_LOW_IMP ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 784000dbed..557bb7e01b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4525,7 +4525,7 @@ void ivas_masa_encode( #ifdef MASA_AND_OBJECTS , const ISM_MODE ism_mode, /* i : ISM format mode */ - const int16_t nchan_ism, /* i : number of ism channels */ + const int16_t nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ @@ -5223,6 +5223,7 @@ void set_ism_importance_interformat( /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ ); @@ -5237,7 +5238,7 @@ void ivas_combined_format_brate_sanity( ISM_MODE ivas_omasa_ism_mode_select( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const int16_t no_obj /* i : number of input ISM's */ + const int16_t nchan_ism /* i : number of input ISM's */ ); void ivas_merge_masa_transports( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 7cf193b0fe..bb4b888665 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2801,7 +2801,11 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif {20000, 16000, 0, 0}, /* 80k */ +#ifdef TUNING_96kbps_3obj + {IVAS_32k, 20000, 16000, 0}, /* 96k */ +#else {IVAS_32k, 20000, 0, 0}, /* 96k */ +#endif {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ diff --git a/lib_com/options.h b/lib_com/options.h index 4fb3b2b7e1..28e854a482 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,6 +169,9 @@ #ifdef MASA_AND_OBJECTS #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ + +#define TUNING_96kbps_3obj + #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 133369e94c..fa976ea5d0 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -59,7 +59,7 @@ void ivas_set_surplus_brate_dec( if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + *ism_total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; @@ -90,7 +90,7 @@ void ivas_set_surplus_brate_dec( { st_ivas->hSCE[n]->element_brate = element_brate[n]; - *ism_total_brate += ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); + *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 1ff51395cb..9126db68cb 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -833,7 +833,7 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < num_obj; ch++ ) { - *ism_total_brate += ivas_interformat_brate( ism_mode, hSCE[ch]->element_brate, ism_imp[ch] ); + *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, num_obj, hSCE[ch]->element_brate, ism_imp[ch] ); } ism_metadata_flag_global = 1; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e041a9bd9e..2f568fb3a3 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -244,7 +244,7 @@ void ivas_masa_encode( #ifdef MASA_AND_OBJECTS , const ISM_MODE ism_mode, /* i : ISM format mode */ - const int16_t nchan_ism, /* i : number of ism channels */ + const int16_t nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index bb2e898af4..b2587cd902 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -568,7 +568,7 @@ void ivas_set_surplus_brate_enc( { if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( st_ivas->ism_mode, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 1d5959c21a..7da0110a2c 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -220,7 +220,7 @@ ivas_error ivas_sce_enc( { set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); - st->total_brate = ivas_interformat_brate( st_ivas->ism_mode, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; + st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; } #endif -- GitLab From c621abbb2a0d4ae9775c3ed05d87d58af66af075 Mon Sep 17 00:00:00 2001 From: advasila Date: Mon, 30 Jan 2023 13:09:53 +0200 Subject: [PATCH 033/173] DISC 3 obj at 96 and DISC 4obj at 128 --- lib_com/ivas_omasa_com.c | 4 ++-- lib_com/ivas_rom_com.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 7729929c96..666fa45e60 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -127,7 +127,7 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 4: - if ( ivas_total_brate >= IVAS_160k ) + if ( ivas_total_brate >= IVAS_128k ) { ism_mode = ISM_MASA_MODE_DISC; } @@ -178,7 +178,7 @@ int32_t ivas_interformat_brate( else { #ifdef TUNING_96kbps_3obj - if ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism == 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ + if ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ { if ( ism_imp == ISM_LOW_IMP ) { diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index bb4b888665..16fa9d2c4d 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2806,7 +2806,7 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = #else {IVAS_32k, 20000, 0, 0}, /* 96k */ #endif - {IVAS_32k, IVAS_24k4, 20000, 0}, /* 128k */ + {IVAS_32k, IVAS_24k4, 20000, 16000}, /* 128k */ {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ -- GitLab From 73d4bc3dc1ebed9d80589a9b6ca5177458309c36 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 13:26:44 +0100 Subject: [PATCH 034/173] - add TUNING_48kbps_2obj --- lib_com/ivas_omasa_com.c | 4 ++++ lib_com/ivas_rom_com.c | 38 +++++++++++++++++++++----------------- lib_com/options.h | 1 + 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 666fa45e60..9dfb05bdbe 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -87,7 +87,11 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 2: +#ifdef TUNING_48kbps_2obj + if ( ivas_total_brate >= IVAS_48k ) +#else if ( ivas_total_brate >= IVAS_64k ) +#endif { ism_mode = ISM_MASA_MODE_DISC; } diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 16fa9d2c4d..66f08492f6 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2786,32 +2786,36 @@ const float McMASA_LFEGain_vectors[64] = const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = { - {0, 0, 0, 0}, /* 13k2 */ - {0, 0, 0, 0}, /* 16k4 */ - {9600, 0, 0, 0}, /* 24k4 */ + {0, 0, 0, 0}, /* 13k2 */ + {0, 0, 0, 0}, /* 16k4 */ + {9600, 0, 0, 0}, /* 24k4 */ #ifdef OMASA_BRATE - {11000, 0, 0, 0}, /* 32k */ + {11000, 0, 0, 0}, /* 32k */ #else - {9600, 0, 0, 0}, /* 32k */ + {9600, 0, 0, 0}, /* 32k */ +#endif +#ifdef TUNING_48kbps_2obj + {IVAS_13k2, 9600, 0, 0}, /* 48k */ +#else + {IVAS_13k2, 0, 0, 0}, /* 48k */ #endif - {IVAS_13k2, 0, 0, 0}, /* 48k */ #ifdef OMASA_BRATE - {16000, 11700, 0, 0}, /* 64k */ + {16000, 11700, 0, 0}, /* 64k */ #else - {16000, IVAS_13k2, 0, 0}, /* 64k */ + {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif - {20000, 16000, 0, 0}, /* 80k */ + {20000, 16000, 0, 0}, /* 80k */ #ifdef TUNING_96kbps_3obj - {IVAS_32k, 20000, 16000, 0}, /* 96k */ + {IVAS_32k, 20000, 16000, 0}, /* 96k */ #else - {IVAS_32k, 20000, 0, 0}, /* 96k */ + {IVAS_32k, 20000, 0, 0}, /* 96k */ #endif - {IVAS_32k, IVAS_24k4, 20000, 16000}, /* 128k */ - {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ - {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ - {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ - {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ - {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */ + {IVAS_32k, IVAS_24k4, 20000, 16000}, /* 128k */ + {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ + {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ + {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ + {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ + {IVAS_128k, IVAS_96k, IVAS_80k, IVAS_64k} /* 512k */ }; /* column wise DCT matrices for 4 5, and 8 dim */ diff --git a/lib_com/options.h b/lib_com/options.h index 28e854a482..7ecfb224a3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,7 @@ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define TUNING_96kbps_3obj +#define TUNING_48kbps_2obj #endif -- GitLab From 66176058699af08bacbad30ef74b047fca92ce68 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 13:27:32 +0100 Subject: [PATCH 035/173] fix debugging outpu files output.[sce,cpe] --- lib_dec/ivas_cpe_dec.c | 10 +++++++--- lib_dec/ivas_sce_dec.c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index c94997536e..ade4764a21 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -583,9 +583,13 @@ ivas_error ivas_cpe_dec( { dbgwrite( output[j], sizeof( float ), output_frame, 1, fname( debug_dir, "output.cpe", j, cpe_id, DEC ) ); } - tmpF = 0; - dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) ); - dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) ); + + if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) + { + tmpF = 0; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) ); + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) ); + } } } #endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 1ca5e01865..9ae6f59abf 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -309,9 +309,13 @@ ivas_error ivas_sce_dec( dbgwrite( &st->element_mode, sizeof( int16_t ), 1, output_frame, fname( debug_dir, "element_mode", 0, sce_id, DEC ) ); dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); - tmpF = 0; - dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); - dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); + + if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) + { + tmpF = 0; + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); + dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); + } } } #endif -- GitLab From dccd851103a11300e587b01ff53eb7407f44644e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 13:28:35 +0100 Subject: [PATCH 036/173] correct (C) headers in OMASA added files --- lib_com/ivas_omasa_com.c | 2 +- lib_dec/ivas_omasa_dec.c | 2 +- lib_enc/ivas_omasa_enc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 9dfb05bdbe..b5b3e09f3e 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index fa976ea5d0..6e95f0710f 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index b2587cd902..cd2548701a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -1,6 +1,6 @@ /****************************************************************************************************** - (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other -- GitLab From 086dbba2db06cba86b0e5bcfdafd3c2602247c48 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 13:44:08 +0100 Subject: [PATCH 037/173] add 'error' returns --- lib_dec/ivas_dec.c | 6 ++++-- lib_dec/ivas_init_dec.c | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index c1d6ab32c4..0bdbeb2d1b 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -459,9 +459,10 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); } } - if ( st_ivas->nCPE == 1 ) + + if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { - ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ); + return error; } if ( st_ivas->hCPE[0]->nchan_out == 1 ) @@ -505,6 +506,7 @@ ivas_error ivas_dec( } ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); } else diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index cc5252e02d..4aef38566b 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1047,7 +1047,10 @@ ivas_error ivas_init_decoder( } st_ivas->nCPE = 1; - create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ); + if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } for ( n = 0; n < CPE_CHANNELS; n++ ) { -- GitLab From 6a83c01b239a65d5047fbb4e35f6a5ef53605a85 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 13:59:34 +0100 Subject: [PATCH 038/173] fix merging issue between FIX_197_CREND_INTERFACE into MASA_AND_OBJECTS --- lib_rend/ivas_stat_rend.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 1b6ca5f75b..4db55ba025 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -241,8 +241,13 @@ typedef struct ivas_dirac_dec_binaural_data_structure float ChEneOut[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float ChCrossReOut[CLDFB_NO_CHANNELS_MAX]; float ChCrossImOut[CLDFB_NO_CHANNELS_MAX]; +#ifdef MASA_AND_OBJECTS + float processMtxRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + float processMtxIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; +#else float processMtxRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; /* +1 refers to SeparateChannel */ float processMtxIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; +#endif float processMtxDecRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float diffuseFieldCoherence[CLDFB_NO_CHANNELS_MAX]; @@ -253,8 +258,13 @@ typedef struct ivas_dirac_dec_binaural_data_structure REVERB_STRUCT_HANDLE hReverb; uint8_t renderStereoOutputInsteadOfBinaural; float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; +#ifdef MASA_AND_OBJECTS + float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; + float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; +#else float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + 1][CLDFB_NO_CHANNELS_MAX]; +#endif float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; uint16_t useSubframeMode; /* 0 = process in 20 ms frames, 1 = process in 5 ms subframes */ -- GitLab From 242310b429e5dc4e5a199500a24bf26e3452b9d9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 14:00:40 +0100 Subject: [PATCH 039/173] cleaning + formatting --- lib_com/ivas_masa_com.c | 1 - lib_dec/ivas_init_dec.c | 2 -- lib_dec/ivas_masa_dec.c | 1 + 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index c1e8d23656..289bf1e2c6 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -87,7 +87,6 @@ void ivas_masa_set_elements( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) { - *nCPE = 1; if ( *element_mode == -1 ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 4aef38566b..e5b51d9451 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1013,7 +1013,6 @@ ivas_error ivas_init_decoder( for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - temp_brate[sce_id] = sep_object_brate[k - 2][st_ivas->nSCE - 1]; ism_total_brate += temp_brate[sce_id]; @@ -1046,7 +1045,6 @@ ivas_error ivas_init_decoder( ivas_dirac_dec_open( st_ivas ); } - st_ivas->nCPE = 1; if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b33b591684..3ffa921385 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -504,6 +504,7 @@ ivas_error ivas_masa_dec_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA decoder\n" ) ); } + #ifdef MASA_AND_OBJECTS ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -- GitLab From 7433066a75658207401b3b5879bc977e1f4ea514 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 14:10:01 +0100 Subject: [PATCH 040/173] cleaning + comments --- lib_dec/ivas_init_dec.c | 10 +++++----- lib_enc/ivas_init_enc.c | 42 +++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e5b51d9451..8ff3f19fd7 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -915,7 +915,7 @@ ivas_error ivas_init_decoder( } } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { @@ -1116,7 +1116,7 @@ ivas_error ivas_init_decoder( return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { @@ -1129,7 +1129,7 @@ ivas_error ivas_init_decoder( } } - if ( st_ivas->nCPE > 1 ) + if ( st_ivas->nCPE > 1 ) // VE: TBV - is this needed? { if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1179,7 +1179,7 @@ ivas_error ivas_init_decoder( ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { @@ -1189,7 +1189,7 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? { st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ if ( ( error = create_cpe_dec( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index d2c6ab278a..4eea31458c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -506,7 +506,7 @@ ivas_error ivas_init_encoder( } } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { @@ -626,27 +626,20 @@ ivas_error ivas_init_encoder( st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { - if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* prepare bitstream buffers */ - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[st_ivas->nSCE + cpe_id * CPE_CHANNELS + n]; - reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); - } + return error; + } - /* Metadata only initialized for the last cpe index*/ - if ( cpe_id == st_ivas->nCPE - 1 ) - { - st_ivas->hCPE[cpe_id]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; - reset_indices_enc( st_ivas->hCPE[cpe_id]->hMetaData, MAX_BITS_METADATA ); - } + /* prepare bitstream buffers */ + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[0]->hCoreCoder[n]->hBstr->ind_list = ind_list[st_ivas->nSCE + n]; + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); } + + st_ivas->hCPE[0]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; + reset_indices_enc( st_ivas->hCPE[0]->hMetaData, MAX_BITS_METADATA ); } #endif else if ( ivas_format == MC_FORMAT ) @@ -654,11 +647,10 @@ ivas_error ivas_init_encoder( st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels( hEncoderConfig->mc_input_setup ); - if ( st_ivas->mc_mode == MC_MODE_MCT ) { st_ivas->nSCE = 0; - st_ivas->nCPE = hEncoderConfig->nchan_inp / 2; + st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS; for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { @@ -674,6 +666,7 @@ ivas_error ivas_init_encoder( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list[cpe_id * CPE_CHANNELS + n]; reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); } + /* Metadata only initialized for the last CPE index*/ if ( cpe_id == st_ivas->nCPE - 1 ) { @@ -701,14 +694,13 @@ ivas_error ivas_init_encoder( return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) { return error; } - /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -755,7 +747,7 @@ ivas_error ivas_init_encoder( ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? { if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { @@ -770,7 +762,7 @@ ivas_error ivas_init_encoder( reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; -- GitLab From 8f9cb78d270a4b4f6563b16cadeb4d63b3f5d518 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 17:23:39 +0100 Subject: [PATCH 041/173] tuning within TUNING_48kbps_2obj --- lib_com/ivas_omasa_com.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index b5b3e09f3e..fd09a8adda 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -182,7 +182,11 @@ int32_t ivas_interformat_brate( else { #ifdef TUNING_96kbps_3obj - if ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ + if ( ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ +#ifdef TUNING_48kbps_2obj + || ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism == 2 && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 48000 and 2 objects */ +#endif + ) { if ( ism_imp == ISM_LOW_IMP ) { -- GitLab From ac2065bc7e5fb107aa1e75f09d82886c3576194d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 30 Jan 2023 17:25:37 +0100 Subject: [PATCH 042/173] correction of one comment --- lib_com/ivas_omasa_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index fd09a8adda..ff81d8ccd6 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -182,7 +182,7 @@ int32_t ivas_interformat_brate( else { #ifdef TUNING_96kbps_3obj - if ( ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ + if ( ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects and 128 kbps and 4 objects */ #ifdef TUNING_48kbps_2obj || ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism == 2 && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 48000 and 2 objects */ #endif -- GitLab From b86192005e8e305f7041a28d91e5f563c062a96c Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Mon, 27 Feb 2023 11:41:29 +0200 Subject: [PATCH 043/173] Diffuseness-preserving MASA and ISM metadata merge in low-bitrate OMASA. OMASA metadata bitrate reduction and allocation update. --- lib_com/ivas_masa_com.c | 6 + lib_com/ivas_omasa_com.c | 127 +++++- lib_com/ivas_prot.h | 34 ++ lib_com/ivas_rom_com.c | 8 +- lib_com/ivas_stat_com.h | 11 + lib_com/options.h | 8 +- lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_masa_dec.c | 393 +++++++++++++++-- lib_enc/ivas_cpe_enc.c | 5 +- lib_enc/ivas_enc.c | 28 +- lib_enc/ivas_ism_enc.c | 5 +- lib_enc/ivas_masa_enc.c | 925 ++++++++++++++++++++++++++++++++++++--- lib_enc/ivas_omasa_enc.c | 106 ++++- 13 files changed, 1549 insertions(+), 109 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 289bf1e2c6..44d316ed88 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -493,6 +493,12 @@ void reconstruct_ism_ratios( } q_energy_ratio_ism[n_ism - 1] = 1.0f - sum; +#ifdef REDUCE_OMASA_META_BITS + if ( q_energy_ratio_ism[n_ism - 1] < 0 ) + { + q_energy_ratio_ism[n_ism - 1] = 0.0f; + } +#endif return; } diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index ff81d8ccd6..f825b41252 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -35,6 +35,9 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" +#ifdef REDUCE_OMASA_META_BITS +#include "ivas_rom_com.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -57,6 +60,11 @@ #define GAMMA_ISM_LOW_IMP3 0.85f #define GAMMA_ISM_MEDIUM_IMP3 1.15f #define GAMMA_ISM_HIGH_IMP3 1.3f +#ifdef TUNING_DISC_3_4obj +#define GAMMA_ISM_LOW_IMP4 0.6f +#define GAMMA_ISM_MEDIUM_IMP4 0.8f +#define GAMMA_ISM_HIGH_IMP4 1.0f +#endif #endif /*--------------------------------------------------------------- @@ -99,17 +107,13 @@ ISM_MODE ivas_omasa_ism_mode_select( { ism_mode = ISM_MASA_MODE_ONE_OBJ; } - /* else if ( ivas_total_brate >= IVAS_32k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } */ else { ism_mode = ISM_MODE_NONE; } break; case 3: -#ifdef TUNING_96kbps_3obj +#ifdef TUNING_DISC_3_4obj if ( ivas_total_brate >= IVAS_96k ) #else if ( ivas_total_brate >= IVAS_128k ) @@ -131,7 +135,11 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 4: + #ifdef TUNING_DISC_3_4obj if ( ivas_total_brate >= IVAS_128k ) +#else + if ( ivas_total_brate >= IVAS_160k ) + #endif { ism_mode = ISM_MASA_MODE_DISC; } @@ -181,24 +189,20 @@ int32_t ivas_interformat_brate( } else { -#ifdef TUNING_96kbps_3obj - if ( ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism >= 3 && element_brate == 16000 ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects and 128 kbps and 4 objects */ -#ifdef TUNING_48kbps_2obj - || ( ism_mode == ISM_MASA_MODE_DISC && nchan_ism == 2 && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 48000 and 2 objects */ -#endif - ) +#ifdef TUNING_DISC_3_4obj + if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) ) ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ { if ( ism_imp == ISM_LOW_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); } else if ( ism_imp == ISM_MEDIUM_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 ); } else /* ISM_HIGH_IMP */ { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 ); } } else @@ -209,15 +213,15 @@ int32_t ivas_interformat_brate( { if ( ism_imp == ISM_LOW_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP2 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 ); } else if ( ism_imp == ISM_MEDIUM_IMP ) { - nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP2 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 ); } else /* ISM_HIGH_IMP */ { - nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP2 ); + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 ); } } else @@ -302,4 +306,93 @@ void ivas_combined_format_brate_sanity( return; } #endif + +#ifdef REDUCE_OMASA_META_BITS +int16_t bits_index_ism_ratio( + int16_t no_ism +) +{ + int16_t bits_index; + + bits_index = 0; + if ( no_ism == 2 ) + { + bits_index = 3; + } + else if ( no_ism == 3 ) + { + bits_index = 6; + } + else if ( no_ism == 4 ) + { + bits_index = 7; + } + else + { + assert( ( no_ism >= 2 && no_ism <= 4 ) && "Wrong number of objects for MASA_ISM." ); + } + return bits_index; +} +#endif + +#ifdef REDUCE_OMASA_META_BITS +void calculate_nbits_meta( + int16_t n_ism, + float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + int16_t numSf, + int16_t numCodingBands, + int16_t *bits_ism, + int16_t idx_sep_obj, + int16_t ism_imp +) +{ + int16_t sf, band, obj; + float priority[MAX_NUM_OBJECTS], max_p; + + + if ( n_ism > 1 ) + { + set_f( priority, 0.0f, n_ism ); + for ( sf = 0; sf < numSf; sf++ ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + for ( obj = 0; obj < n_ism; obj++ ) + { + priority[obj] = max( priority[obj], ( q_energy_ratio_ism[sf][band][obj] * ( 1 - masa_to_total_energy_ratio[sf][band] ) ) ); + } + } + } + } + else + { + priority[0] = 1; + } + + + /* decide parameters for ISM metadata quantization */ + maximum( priority, n_ism, &max_p ); + for ( obj = 0; obj < n_ism; obj++ ) + { + if ( obj == idx_sep_obj ) + { + if ( ism_imp == 3 ) + { + priority[obj] = 1; + } + else if ( ism_imp == 2 ) + { + priority[obj] = ( 1 + max_p ) * 0.5f; + } + else + { + priority[obj] = max_p; + } + } + bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); + } + return; +} +#endif #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 557bb7e01b..4e700a7abe 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4529,6 +4529,10 @@ void ivas_masa_encode( ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ +#ifdef REDUCE_OMASA_META_BITS + , + int16_t ism_imp /* i: importance of separated object */ +#endif #endif ); @@ -4604,6 +4608,32 @@ int32_t calculate_cpe_brate_MASA_ISM( const int32_t ivas_total_brate, /* i : total bit rate for IVAS */ const int16_t n_ism /* i : number of objects */ ); +#ifdef OMASA_DIFFUSE_ISM_MERGE +void ivas_merge_masa_metadatas( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ + OMASA_SPATIAL_META_HANDLE hMasaMeta /* i: ISM-object metadata to be merged with the MASA metadata */ +); +void ivas_masa_combine_directions( + MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ +); +#endif /* OMASA_DIFFUSE_ISM_MERGE */ + +#ifdef REDUCE_OMASA_META_BITS +int16_t bits_index_ism_ratio( /* o : number of bits for ISM ratio index */ + int16_t no_ism /* i : number of objects */ +); + +void calculate_nbits_meta( + int16_t n_ism, + float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + int16_t numSf, + int16_t numCodingBands, + int16_t* bits_ism, + int16_t idx_sep_obj, + int16_t ism_imp +); +#endif #endif void ivas_masa_set_coding_config( @@ -5181,6 +5211,10 @@ void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs /* i : Input sample rate */ +#ifdef OMASA_DIFFUSE_ISM_MERGE + , + ISM_MODE ismMode /* i : ISM mode */ +#endif ); void ivas_omasa_enc( diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 66f08492f6..ec2b6c5b93 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2805,12 +2805,16 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {16000, IVAS_13k2, 0, 0}, /* 64k */ #endif {20000, 16000, 0, 0}, /* 80k */ -#ifdef TUNING_96kbps_3obj - {IVAS_32k, 20000, 16000, 0}, /* 96k */ +#ifdef TUNING_DISC_3_4obj + {IVAS_32k, 20000, 20000, 0}, /* 96k */ #else {IVAS_32k, 20000, 0, 0}, /* 96k */ #endif +#ifdef TUNING_DISC_3_4obj + {IVAS_32k, IVAS_24k4, 20000, 24000}, /* 128k */ +#else {IVAS_32k, IVAS_24k4, 20000, 16000}, /* 128k */ +#endif {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 9966630d43..d0a79ed586 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -419,6 +419,17 @@ typedef struct ivas_masa_common_spatial_meta_struct } MASA_COMMON_SPATIAL_META; +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE +typedef struct ivas_omasa_meta_struct +{ + uint8_t num_dirs; + MASA_DIRECTIONAL_SPATIAL_META directional_meta[MASA_MAXIMUM_DIRECTIONS]; + MASA_COMMON_SPATIAL_META common_meta; +} OMASA_SPATIAL_META, *OMASA_SPATIAL_META_HANDLE; +#endif +#endif + typedef struct ivas_masa_metadata_frame_struct { MASA_DECRIPTIVE_META descriptive_meta; diff --git a/lib_com/options.h b/lib_com/options.h index 7ecfb224a3..92cbca2b9f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -170,10 +170,14 @@ #define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define TUNING_96kbps_3obj + #define TUNING_48kbps_2obj -#endif +#define TUNING_DISC_3_4obj /* Nokia: increase bitrate for objects in DISC mode at 128k 4obj and 96k 3 obj */ +#define REDUCE_OMASA_META_BITS /* Nokia: reduce metadata number of bits and fix directional metadata bit allocation */ +#define OMASA_DIFFUSE_ISM_MERGE /* Nokia: Diffuse-energy retaining merging of ISM and MASA */ + +#endif /* MASA_AND_OBJECTS */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index ade4764a21..c2f3aa7ed9 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -176,6 +176,7 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS } #endif + } else { @@ -370,7 +371,6 @@ ivas_error ivas_cpe_dec( /*----------------------------------------------------------------* * Core codec configuration *----------------------------------------------------------------*/ - for ( n = 0; n < n_channels; n++ ) { /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 3ffa921385..6ac0c3d63f 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -71,9 +71,24 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS -static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos ); +static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object, int16_t ism_imp +#endif +); static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, int16_t no_ism, int16_t K ); -static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t n_ism, int16_t nbands, int16_t nblocks ); +static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t n_ism, int16_t nbands, int16_t nblocks +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object +#endif +); +#endif +#ifdef REDUCE_OMASA_META_BITS +static void read_ism_ratio_index(int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], uint16_t *bit_stream, int16_t *next_bit_pos, float *masa_to_total_energy_ratio, + int16_t idx_sep_obj, int16_t *num_zeros ); #endif /*-----------------------------------------------------------------------* @@ -100,6 +115,9 @@ ivas_error ivas_masa_decode( int16_t obj; #ifdef OMASA_BRATE int16_t i, ch, ism_imp; +#ifdef REDUCE_OMASA_META_BITS + ism_imp = 0; +#endif #endif #endif @@ -170,6 +188,12 @@ ivas_error ivas_masa_decode( st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; } +#ifdef REDUCE_OMASA_META_BITS + else + { + st_ivas->hMasaIsmData->idx_separated_ism = -1; + } +#endif #ifdef OMASA_BRATE /* read ISM importance flag (one per object) */ @@ -276,7 +300,12 @@ ivas_error ivas_masa_decode( { if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { - *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos ); + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos +#ifdef REDUCE_OMASA_META_BITS + , + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp +#endif + ); } if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) @@ -293,7 +322,6 @@ ivas_error ivas_masa_decode( } #endif - *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos ); #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) @@ -1635,11 +1663,11 @@ static void compute_foa_cov_matrix( #ifdef MASA_AND_OBJECTS -static void decode_index_slice( - int16_t index, - int16_t *ratio_idx_ism, - int16_t no_ism, - int16_t K ) +static void decode_index_slice( + int16_t index, /* i: index to decode */ + int16_t *ratio_idx_ism, /* o: decodec array of integers */ + int16_t no_ism, /* i: number of elements in array (objects) */ + int16_t K ) /* i: sum of array elements */ { int16_t i, j, sum, elem; int16_t base[MAX_NUM_OBJECTS]; @@ -1684,6 +1712,273 @@ static void decode_index_slice( } } +#ifdef REDUCE_OMASA_META_BITS +static void read_ism_ratio_index( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o: ISM read ratio indexes */ + int16_t no_ism, /* i: number of objects */ + int16_t numCodingBands, /* i: number of subbands */ + int16_t sf, /* i: index of subframe */ + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i: previous subframe ISM ratio indexes */ + uint16_t *bit_stream, /* i: bitstream */ + int16_t *next_bit_pos, /* i/o: position in bitstream */ + float *masa_to_total_energy_ratio, /* i: masa to total ratios */ + int16_t idx_sep_obj, /* i: index of separated index, -1 if none*/ + int16_t *num_zeros /* i/o: number of zero values in first subframe for separated object */ +) +{ + int16_t b, i, b_signif; + int16_t index; + int16_t GR_order, differential_subframe; + int16_t buf; + int16_t no_levels_ratio_ism; + int16_t bits_index; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t idx_sep_obj_local, shift_one; + idx_sep_obj_local = idx_sep_obj; + if ( idx_sep_obj > -1 ) + { + if ( idx_sep_obj == no_ism - 1 && no_ism > 2) + { + idx_sep_obj_local = 0; + } + } + b_signif = 0; + no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); + while ( b_signif < numCodingBands && masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b_signif], no_levels_ratio_ism, no_ism ); + b_signif++; + } + if ( b_signif == numCodingBands ) + { + return; + } + else + { + + if ( sf == 0 ) + { + bits_index = bits_index_ism_ratio( no_ism ); + + /* read coding type */ + if ( bit_stream[( *next_bit_pos )--] == 1 ) + { + /* independent coding*/ + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = 0; + for ( i = 0; i < bits_index; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); + if ( idx_sep_obj > -1 && ratio_ism_idx[b][idx_sep_obj_local] == 0 ) + { + (*num_zeros)++; + } + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + } + else + { + /* differential coding */ + index = 0; + for ( i = 0; i < bits_index; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + decode_index_slice( index, ratio_ism_idx[b_signif], no_ism, no_levels_ratio_ism ); + if ( idx_sep_obj > -1 && ratio_ism_idx[b_signif][idx_sep_obj_local] == 0 ) + { + ( *num_zeros )++; + } + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism ); + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; + for ( i = 0; i < no_ism - 1; i++ ) + { + buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, 0 ); + if ( ( buf % 2 ) == 0 ) + { + ratio_ism_idx[b][i] = -( buf >> 1 ); + } + else + { + ratio_ism_idx[b][i] = ( ( buf + 1 ) >> 1 ); + } + ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx_ref[i]; + ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; + } + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism ); + if ( idx_sep_obj > -1 && ratio_ism_idx[b][idx_sep_obj_local] == 0 ) + { + ( *num_zeros )++; + } + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + } + } + else + { + if ( numCodingBands > 1 ) + { + /* read prediction type */ + differential_subframe = bit_stream[( *next_bit_pos )--]; + } + else + { + differential_subframe = 1; + } + + if ( *num_zeros == numCodingBands ) + { + shift_one = 1; + } + else + { + shift_one = 0; + } + if ( shift_one == 1 && no_ism == 2 ) + { + /* nothing has been sent ; values can be inferred */ + for ( b = b_signif; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + if ( idx_sep_obj_local == 0 ) + { + ratio_ism_idx[b][0] = 0; + ratio_ism_idx[b][1] = 7; + } + else + { + ratio_ism_idx[b][0] = 7; + ratio_ism_idx[b][1] = 0; + } + } + } + } + else + { + /* read GR order */ + GR_order = bit_stream[( *next_bit_pos )--]; + for ( b = b_signif; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + for ( i = 0; i < no_ism - 1 - shift_one; i++ ) + { + buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); + if ( ( buf % 2 ) == 0 ) + { + ratio_ism_idx[b][i] = -( buf >> 1 ); + } + else + { + ratio_ism_idx[b][i] = ( ( buf + 1 ) >> 1 ); + } + } + /* insert separated obj */ + if ( shift_one ) + { + for ( i = no_ism - 1; i > idx_sep_obj_local; i-- ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i - 1]; + } + ratio_ism_idx[b][idx_sep_obj_local] = 0; /* this is only difference; need to pdate later as well */ + } + } + } + if ( differential_subframe ) + { + /* differential to previous subframe */ + for ( b = b_signif; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx_prev_sf[b][i]; + if ( shift_one && i == idx_sep_obj_local ) + { + ratio_ism_idx[b][i] = 0; + } + ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; + } + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + } + else + { + /* difference to previous subband */ + ratio_ism_idx[b_signif][no_ism - 1] = no_levels_ratio_ism; + + /* first significant subband - differential to previous subframe */ + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[b_signif][i] = ratio_ism_idx[b_signif][i] + ratio_ism_idx_prev_sf[b_signif][i]; + if ( shift_one && i == idx_sep_obj_local ) + { + ratio_ism_idx[b_signif][i] = 0; + } + ratio_ism_idx[b_signif][no_ism - 1] -= ratio_ism_idx[b_signif][i]; + } + /* rest of subbands differential to previous subband */ + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism ); + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; + for ( i = 0; i < no_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx_ref[i]; + if ( shift_one && i == idx_sep_obj_local ) + { + ratio_ism_idx[b][i] = 0; + } + ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; + } + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism ); + } + else + { + /* distribute evenly the objects */ + distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); + } + } + } + } + } + + return; + } +} + + +#else static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, @@ -1846,26 +2141,40 @@ static void read_ism_ratio_index( return; } - +#endif static void decode_ism_ratios( - uint16_t *bit_stream, - int16_t *next_bit_pos, - IVAS_QMETADATA_HANDLE hQMetaData, - float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - int16_t n_ism, - int16_t nbands, - int16_t numSf ) + uint16_t *bit_stream, /* i: bitstream */ + int16_t *next_bit_pos, /* i/o: position in bitstream */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i: Metadata handle */ + float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o: ISM ratios */ + int16_t n_ism, /* i: number of objects */ + int16_t nbands, /* i: number of subbands */ + int16_t numSf /* i: number of subframes */ +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object /* i: index of separated object */ +#endif +) { int16_t sf, band; int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - - +#ifdef REDUCE_OMASA_META_BITS + float tmp; + int16_t num_zeros; + num_zeros = 0; +#endif /* hQMetaData->q_direction->cfg.nblocks; */ for ( sf = 0; sf < numSf; sf++ ) { /* read ism ratio indexes */ - read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf] ); + read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf] +#ifdef REDUCE_OMASA_META_BITS + , + idx_separated_object, + &num_zeros +#endif + ); /* save previous subframe index values */ if ( sf < numSf - 1 ) @@ -1882,7 +2191,21 @@ static void decode_ism_ratios( { reconstruct_ism_ratios( ratio_ism_idx[band], n_ism, 1.0f / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ), ratio_ism[sf][band] ); } - +#ifdef REDUCE_OMASA_META_BITS + if ( ( n_ism > 2 ) && ( idx_separated_object == n_ism - 1 ) ) + { + /* rotate */ + for ( band = 0; band < nbands; band++ ) + { + if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + tmp = ratio_ism[sf][band][n_ism - 1]; + ratio_ism[sf][band][n_ism - 1] = ratio_ism[sf][band][0]; + ratio_ism[sf][band][0] = tmp; + } + } + } +#endif if ( nbands == 1 ) { for ( band = 1; band < 5; band++ ) @@ -1912,14 +2235,22 @@ static int16_t ivas_decode_masaism_metadata( MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, - int16_t *next_bit_pos ) + int16_t *next_bit_pos +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object, + int16_t ism_imp +#endif +) { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t *band_mapping; int16_t b; +#ifndef REDUCE_OMASA_META_BITS float priority[MAX_NUM_OBJECTS]; +#endif int16_t bits_ism[MAX_NUM_OBJECTS], index; uint16_t idx_el, idx_az; float azimuth, elevation; @@ -1935,8 +2266,13 @@ static int16_t ivas_decode_masaism_metadata( if ( nchan_ism > 1 ) { /* read ISM ratios */ - decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks ); - + decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks +#ifdef REDUCE_OMASA_META_BITS + , + idx_separated_object +#endif + ); +#ifndef REDUCE_OMASA_META_BITS /* calculate priority */ set_f( priority, 0.0f, nchan_ism ); for ( sf = 0; sf < nblocks; sf++ ) @@ -1949,6 +2285,7 @@ static int16_t ivas_decode_masaism_metadata( } } } +#endif } else { @@ -1959,15 +2296,21 @@ static int16_t ivas_decode_masaism_metadata( energy_ratio_ism[sf][band][0] = 1.0f; } } +#ifndef REDUCE_OMASA_META_BITS priority[0] = 1; +#endif } /* read ISM metadata */ +#ifdef REDUCE_OMASA_META_BITS + calculate_nbits_meta( nchan_ism, energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); + +#else for ( obj = 0; obj < nchan_ism; obj++ ) { bits_ism[obj] = 11 - (int16_t) ( ( 1 - priority[obj] ) * 7 ); } - +#endif for ( obj = 0; obj < nchan_ism; obj++ ) { index = 0; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 429d5dac0b..6cd3c43327 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -266,6 +266,7 @@ ivas_error ivas_cpe_enc( sts[n]->element_mode = hCPE->element_mode; } + if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ { @@ -274,7 +275,7 @@ ivas_error ivas_cpe_enc( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) { - stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.7f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } else { @@ -291,6 +292,7 @@ ivas_error ivas_cpe_enc( stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } + if ( hCPE->element_mode == IVAS_CPE_TD ) { if ( hCPE->hStereoTD->tdm_LRTD_flag ) @@ -702,6 +704,7 @@ ivas_error ivas_cpe_enc( #endif } + /*----------------------------------------------------------------* * Core Encoder *----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 7e94041393..c0bf3caa93 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -267,6 +267,10 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS , ISM_MODE_NONE, -1, NULL, -1, NULL +#ifdef REDUCE_OMASA_META_BITS + , + 0 +#endif #endif ); } @@ -338,7 +342,12 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs ); + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs +#ifdef OMASA_DIFFUSE_ISM_MERGE + , + st_ivas->ism_mode +#endif + ); } /* Estimate TF-tile energy for the input MASA stream */ @@ -372,7 +381,11 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa +#ifdef REDUCE_OMASA_META_BITS + ,st_ivas->hIsmMetaData[0]->ism_imp +#endif + ); /* Configuration of combined-format bit-budget distribution */ #ifdef DEBUG_MODE_INFO @@ -389,7 +402,12 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs ); + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, +#ifdef OMASA_DIFFUSE_ISM_MERGE + , + st_ivas->ism_mode +#endif + ); } else { @@ -489,6 +507,10 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS , ISM_MODE_NONE, -1, NULL, -1, NULL +#ifdef REDUCE_OMASA_META_BITS + , + 0 +#endif #endif ); diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 8626d9e050..f18e87d9be 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -222,6 +222,9 @@ ivas_error ivas_ism_enc( else /* ISM_MODE_DISC */ { #ifdef MASA_AND_OBJECTS +#ifdef OMASA_BRATE + int32_t ism_total_brate_ref; +#endif int32_t ism_total_brate; if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -237,7 +240,7 @@ ivas_error ivas_ism_enc( } #ifdef OMASA_BRATE - int32_t ism_total_brate_ref = ism_total_brate; + ism_total_brate_ref = ism_total_brate; // VE: change the interface of the following function and call it with 'st_ivas' only ivas_ism_metadata_enc( &ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ); diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 2f568fb3a3..59b76cdd7c 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -45,8 +45,11 @@ *-----------------------------------------------------------------------*/ static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ); - +#ifdef MASA_AND_OBJECTS +#ifndef OMASA_DIFFUSE_ISM_MERGE static void combine_directions( MASA_ENCODER_HANDLE hMasa ); +#endif +#endif static void find_n_largest( const float *input, int16_t *largestIndices, const int16_t numElements, const int16_t numLargest ); @@ -59,21 +62,47 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); #ifdef MASA_AND_OBJECTS +#ifndef OMASA_DIFFUSE_ISM_MERGE static void ivas_merge_masa_metadatas( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); +#endif -static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], int16_t low_bitrate_mode, int16_t omasa_nbands, int16_t omasa_nblocks ); +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], int16_t low_bitrate_mode, int16_t omasa_nbands, int16_t omasa_nblocks +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object +#endif +#ifdef REDUCE_OMASA_META_BITS + , + int16_t ism_imp +#endif +); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); -static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t no_ism, float masa_to_total_energy_ratio ); +static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t no_ism, float masa_to_total_energy_ratio +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_sep_object +#endif +); static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); -static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio ); +static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], int16_t no_ism, int16_t numCodingBands, int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio +#ifdef REDUCE_OMASA_META_BITS + , int16_t shift_one, int16_t idx_sep_obj +#endif +); static void transform_index_and_GR_encode( int16_t *diff_idx, int16_t len, int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); static void transform_difference_index( int16_t *diff_idx, int16_t *idx, int16_t len ); +#ifdef REDUCE_OMASA_META_BITS +static void independent_coding_ratio_ism_idx( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const float *masa_to_total_energy_ratio, + int16_t no_ism, int16_t numCodingBands, int16_t bits_index, BSTR_ENC_HANDLE hMetaData ); + +static void remove_sep_obj( int16_t *diff_idx, int16_t no_ism, int16_t idx_sep_obj ); +#endif #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif @@ -248,6 +277,10 @@ void ivas_masa_encode( ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ +#ifdef REDUCE_OMASA_META_BITS + , + int16_t ism_imp /* i: importance of separated object */ +#endif #endif ) { @@ -307,9 +340,21 @@ void ivas_masa_encode( if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ivas_format == MASA_FORMAT ) #endif { +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE + if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) || ( ivas_format != MASA_ISM_FORMAT ) ) + { + /* Combine directions */ + ivas_masa_combine_directions( hMasa ); + } +#else /* Combine directions */ combine_directions( hMasa ); - +#endif +#else + /* Combine directions */ + combine_directions( hMasa ); +#endif /* If we joined all bands, then metadata is now one directional. */ if ( hMasa->config.numTwoDirBands == 0 ) { @@ -401,7 +446,11 @@ void ivas_masa_encode( /* Move data from encoder to qmetadata */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) +#endif #else if ( ivas_format == MASA_FORMAT ) #endif @@ -409,10 +458,12 @@ void ivas_masa_encode( move_metadata_to_qmetadata( hMasa, hQMetaData ); } #ifdef MASA_AND_OBJECTS +#ifndef OMASA_DIFFUSE_ISM_MERGE else if ( ivas_format == MASA_ISM_FORMAT ) { ivas_merge_masa_metadatas( hMasa, hQMetaData ); } +#endif #endif if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) @@ -433,7 +484,15 @@ void ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) { /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes ); + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes +#ifdef REDUCE_OMASA_META_BITS + , idx_separated_object +#endif +#ifdef REDUCE_OMASA_META_BITS + , + ism_imp +#endif + ); } else { @@ -441,7 +500,6 @@ void ivas_masa_encode( } #endif /* Encode metadata */ - ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); #ifdef MASA_AND_OBJECTS @@ -485,8 +543,15 @@ void ivas_masa_encode( if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands ) { /* Combine directions */ +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE + ivas_masa_combine_directions( hMasa ); +#else combine_directions( hMasa ); - +#endif +#else + combine_directions( hMasa ); +#endif /* If we joined all bands, then metadata is now one directional. */ if ( hMasa->config.numTwoDirBands == 0 ) { @@ -1021,8 +1086,15 @@ static void combine_freqbands_and_subframes( return; } - +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE +void ivas_masa_combine_directions( +#else static void combine_directions( +#endif +#else +static void combine_directions( +#endif MASA_ENCODER_HANDLE hMasa ) { int16_t i, j, k; @@ -1138,7 +1210,11 @@ static void combine_directions( ambience2dir = 1.0f - ratioSum; hMeta->directional_meta[0].energy_ratio[j][i] = sumVecLen[j][i] / ( hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] + ambience2dir / 2.0f ); - +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE + hMeta->directional_meta[1].energy_ratio[j][i] = 0.0f; +#endif /* OMASA_DIFFUSE_ISM_MERGE */ +#endif /* MASA_AND_OBJECTS */ if ( computeCoherence ) { ambience1dir = 1.0f - hMeta->directional_meta[0].energy_ratio[j][i]; @@ -1969,16 +2045,30 @@ void ivas_masa_enc_reconfigure( } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_DIFFUSE_ISM_MERGE +void ivas_merge_masa_metadatas( + MASA_ENCODER_HANDLE hMasa, + OMASA_SPATIAL_META_HANDLE hOMasaMeta +#else static void ivas_merge_masa_metadatas( MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMeta ) + IVAS_QMETADATA_HANDLE hQMeta +#endif /* OMASA_DIFFUSE_ISM_MERGE */ +) { int16_t sf, band; uint8_t numCodingBands; uint8_t numDirections; uint8_t numSf; MASA_METADATA_HANDLE hMeta; +#ifdef OMASA_DIFFUSE_ISM_MERGE + float energyTimesRatioISM; + float energyTimesRatioMASA[2]; + float total_diff_nrg; +#else float energyTimesRatio1, energyTimesRatio2; +#endif /* OMASA_DIFFUSE_ISM_MERGE */ + int16_t brange[2]; float eneBand; float energyMerged[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -1989,14 +2079,33 @@ static void ivas_merge_masa_metadatas( numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; hMeta = &( hMasa->masaMetadata ); +#ifndef OMASA_DIFFUSE_ISM_MERGE assert( numDirections == 1 && "MASA metadata merging currently implemented only for 1-direction metadata" ); /* Currently only 1-direction metadata is fed to merging */ +#endif for ( sf = 0; sf < numSf; sf++ ) { for ( band = 0; band < numCodingBands; band++ ) { +#ifdef OMASA_DIFFUSE_ISM_MERGE + int16_t merge_dest; + float dir_sum; + uint8_t band_n_dirs; + brange[0] = band; + brange[1] = band + 1; + /* TODO: if this stays, remove the unnecessary range loop from the code */ + if ( numDirections == 1 || ( numDirections == 2 && hMasa->data.twoDirBands[band] == 0 ) ) + { + band_n_dirs = 1; + } + else + { + band_n_dirs = 2; + } +#else brange[0] = hMasa->data.band_mapping[band]; brange[1] = hMasa->data.band_mapping[band + 1]; +#endif /* OMASA_DIFFUSE_ISM_MERGE */ /* Compute energies */ /* MASA energy is in the full 24 band resolution, whereas the ISM energy is already in the coding band resolution */ @@ -2008,6 +2117,66 @@ static void ivas_merge_masa_metadatas( energyMerged[sf][band] = eneBand + hMasa->data.energy_ism[sf][band]; /* Compute weights */ +#ifdef OMASA_DIFFUSE_ISM_MERGE + energyTimesRatioMASA[0] = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; + if ( band_n_dirs == 2 ) + { + energyTimesRatioMASA[1] = eneBand * hMeta->directional_meta[1].energy_ratio[sf][band]; + } + else + { + energyTimesRatioMASA[1] = 0.0f; + } + /* target is original MASA diffuseness */ + total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + /* criterion is mean of ISM ratio and new ratio */ + energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0 * hMasa->data.energy_ism[sf][band]; + + /* Determine combined metadata based on the weights */ + merge_dest = -1; + if ( ( band_n_dirs == 1 && energyTimesRatioMASA[0] < energyTimesRatioISM ) || + ( band_n_dirs == 2 && energyTimesRatioMASA[0] < energyTimesRatioMASA[1] && energyTimesRatioMASA[0] < energyTimesRatioISM ) ) + { + /* 1dir and ISM the most energetic, or 2dir and ISM the more energetic than MASA1 */ + merge_dest = 0; + } + else if ( band_n_dirs == 2 && energyTimesRatioMASA[1] <= energyTimesRatioMASA[0] && energyTimesRatioMASA[1] < energyTimesRatioISM ) + { + /* 2dir and ISM the most energetic and MASA2 the least energetic */ + merge_dest = 1; + } + + if ( merge_dest >= 0 ) /* replace one MASA with ISM */ + { + hMeta->directional_meta[merge_dest].azimuth[sf][band] = hOMasaMeta->directional_meta[0].azimuth[sf][band]; + hMeta->directional_meta[merge_dest].elevation[sf][band] = hOMasaMeta->directional_meta[0].elevation[sf][band]; + /* limit with the earlier direct-energy ratio */ + dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ); /* new dir ratio */ + hMeta->directional_meta[merge_dest].energy_ratio[sf][band] = min( dir_sum, hOMasaMeta->directional_meta[0].energy_ratio[sf][band] ); /* clip with original ISM dir */ + hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f - hMeta->directional_meta[merge_dest].energy_ratio[sf][band]; + + if ( hMasa->config.useCoherence ) /* TODO: is this correct condition? */ + { + hMeta->directional_meta[merge_dest].spread_coherence[sf][band] = hOMasaMeta->directional_meta[0].spread_coherence[sf][band]; + hMeta->common_meta.surround_coherence[sf][band] = hOMasaMeta->common_meta.surround_coherence[sf][band]; + } + + /* recompute direct energy ratios to match the diffuse ratio */ + float direct_quota, direct_scaler; + direct_quota = 1.0f - hMeta->common_meta.diffuse_to_total_ratio[sf][band]; + if ( band_n_dirs == 1 ) + { + hMeta->directional_meta[0].energy_ratio[sf][band] = direct_quota; + } + else + { + dir_sum = hMeta->directional_meta[0].energy_ratio[sf][band] + hMeta->directional_meta[1].energy_ratio[sf][band]; + direct_scaler = direct_quota / ( EPSILON + dir_sum ); + hMeta->directional_meta[0].energy_ratio[sf][band] *= direct_scaler; + hMeta->directional_meta[1].energy_ratio[sf][band] *= direct_scaler; + } + } +#else /* OMASA_DIFFUSE_ISM_MERGE */ energyTimesRatio1 = hMasa->data.energy_ism[sf][band] * hQMeta->q_direction[0].band_data[band].energy_ratio[sf]; energyTimesRatio2 = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; @@ -2026,6 +2195,7 @@ static void ivas_merge_masa_metadatas( hQMeta->surcoh_band_data[band].surround_coherence[sf] = (uint8_t) roundf( hMeta->common_meta.surround_coherence[sf][band] * UINT8_MAX ); } } +#endif /* OMASA_DIFFUSE_ISM_MERGE */ } } @@ -2043,12 +2213,136 @@ static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, int16_t no_ism, - float masa_to_total_energy_ratio ) + float masa_to_total_energy_ratio +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_sep_object +#endif +) { int16_t i, j, best_i, best_i2; float dist, div, tmp, dist2, best_dist; int16_t part_idx_sum, max_sum_idx; + +#ifdef REDUCE_OMASA_META_BITS + float ratio_ism_loc[MAX_NUM_OBJECTS]; + int16_t no_ism_loc; + max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; + if ( idx_sep_object > -1 ) + { + if ( ratio_ism[idx_sep_object] < 1.0f / (float) ( max_sum_idx )) + { + /* take it out from quantize function */ + mvr2r( ratio_ism, ratio_ism_loc, idx_sep_object ); + mvr2r( &ratio_ism[idx_sep_object+1], &ratio_ism_loc[idx_sep_object], no_ism-idx_sep_object-1 ); + no_ism_loc = no_ism - 1; + } + else + { + no_ism_loc = no_ism; + mvr2r( ratio_ism, ratio_ism_loc, no_ism ); + } + } + else + { + no_ism_loc = no_ism; + mvr2r( ratio_ism, ratio_ism_loc, no_ism ); + } + + + if ( no_ism > 1 ) + { + if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) + { + distribute_evenly_ism( idx, max_sum_idx, no_ism ); + } + else + { + if ( no_ism_loc > 1 ) + { + + dist = 0.0f; + div = 1.0f / (float) ( max_sum_idx ); + + part_idx_sum = 0; + + for ( i = 0; i < no_ism_loc; i++ ) + { + idx[i] = (int16_t) ( ( ratio_ism_loc[i] ) * ( max_sum_idx ) ); + part_idx_sum += idx[i]; + + tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); + dist += ( tmp * tmp ); + } + best_dist = dist; + best_i2 = -1; + while ( part_idx_sum < max_sum_idx ) + { + best_i = -1; + /* check which index to increase by 1 for a possible improvement */ + + for ( i = 0; i < no_ism_loc; i++ ) + { + idx[i]++; + dist2 = 0.0f; + + + for ( j = 0; j < no_ism_loc; j++ ) + { + tmp = ( ratio_ism_loc[i] - ( idx[i] * div ) ); + dist2 += ( tmp * tmp ); + } + + if ( dist2 < best_dist ) + { + best_i2 = best_i; + best_i = i; + best_dist = dist2; + } + idx[i]--; + } + if ( best_i > -1 ) + { + idx[best_i]++; + part_idx_sum++; + } + else + { + if ( best_i2 > -1 ) + { + idx[best_i2]++; + part_idx_sum++; + } + else + { + idx[no_ism_loc - 1] += max_sum_idx - part_idx_sum; + part_idx_sum = max_sum_idx; + } + } + } + assert( sum_s( idx, no_ism_loc ) == max_sum_idx ); + } + else + { + idx[0] = max_sum_idx; + } + if ( no_ism_loc < no_ism ) + { + /* insert back the ratio of the separated object */ + for ( i = no_ism - 1; i > idx_sep_object; i-- ) + { + idx[i] = idx[i - 1]; + } + idx[idx_sep_object] = 0; + } + } + } + else + { + idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); + } +#else max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; if ( no_ism > 1 ) { @@ -2126,7 +2420,7 @@ static void quantize_ratio_ism_vector( idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); } - +#endif return; } @@ -2210,6 +2504,401 @@ static void transform_index_and_GR_encode( return; } +static int16_t try_differential( + int16_t numCodingBands, + const float * masa_to_total_energy_ratio, + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t no_ism, + int16_t bits_index, + int16_t * p_b_signif) +{ + int16_t b, i; + int16_t nbits0; + int16_t b_signif; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t diff_idx[MAX_NUM_OBJECTS]; + + + b_signif = 0; + while ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR && b_signif < numCodingBands ) + { + b_signif++; + } + nbits0 = 0; + if ( b_signif < numCodingBands ) + { + nbits0 = bits_index; + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism ); + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, no_ism ); + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism ); + /* transform difference index into positive */ + transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + } + } + } + } + *p_b_signif = b_signif; + return nbits0; +} + +static void differential_coding_first_subframe( + BSTR_ENC_HANDLE hMetaData, + const float *masa_to_total_energy_ratio, + int16_t b_signif, + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t no_ism, + int16_t numCodingBands, + int16_t bits_index + ) +{ + int16_t index, b; + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t diff_idx[MAX_NUM_OBJECTS]; + + /* differential encoding*/ + push_next_indice( hMetaData, 0, 1 ); + if ( b_signif < numCodingBands ) + { + index = index_slice_enum( ratio_ism_idx[b_signif], no_ism ); + push_next_indice( hMetaData, index, bits_index ); + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism ); + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, no_ism ); + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism ); + /* transform difference index into positive */ + transform_index_and_GR_encode( diff_idx, no_ism - 1, 0, hMetaData ); + } + } + } +} +#ifdef REDUCE_OMASA_META_BITS +static void independent_coding_ratio_ism_idx( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i: ISM ratios */ + const float *masa_to_total_energy_ratio, /* i: MASA to total ratios */ + int16_t no_ism, /* i: number of objects */ + int16_t numCodingBands, /* i: number of subbands */ + int16_t bits_index, /* i: number of bits per index */ + BSTR_ENC_HANDLE hMetaData /* i/o: bitstream */ + ) +{ + int16_t b, index; + + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + index = index_slice_enum( ratio_ism_idx[b], no_ism ); + push_next_indice( hMetaData, index, bits_index ); + } + } + +} + +static void remove_sep_obj( + int16_t *diff_idx, /* i/o: array of difference of indexes */ + int16_t no_ism, /* i: number of objects */ + int16_t idx_sep_obj /* i: index of separated object, to be taken out of array */ +) +{ + int16_t i; + for ( i = idx_sep_obj; i < no_ism-1; i++ ) + { + diff_idx[i] = diff_idx[i + 1]; + } + return; +} + +static void estimate_bits_subband_ism_ratio( + int16_t * ratio_ism_idx, + int16_t *ratio_ism_idx_ref, /* ( i/o ) */ + int16_t no_ism, + int16_t shift_one, + int16_t idx_sep_obj, + int16_t * p_nbits0, + int16_t * p_nbits1 +) +{ + int16_t diff_idx[MAX_NUM_OBJECTS]; + int16_t nbits0, nbits1; + int16_t i; + + nbits0 = 0; + nbits1 = 0; + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, no_ism ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, no_ism, idx_sep_obj ); + } + /* transform difference index into positive */ + transform_difference_index( diff_idx, diff_idx, no_ism - 1 - shift_one ); + /* GR encoding */ + + for ( i = 0; i < no_ism - 1 - shift_one; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } + + + *p_nbits0 = nbits0; + *p_nbits1 = nbits1; + return; +} + +static int16_t encode_ratio_ism_subframe( + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t no_ism, + int16_t numCodingBands, + int16_t sf, + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + BSTR_ENC_HANDLE hMetaData, + const float *masa_to_total_energy_ratio, + int16_t shift_one, + int16_t idx_separated_obj +) +{ + int16_t b, b_signif; + int16_t diff_idx[MAX_NUM_OBJECTS]; + int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb, bits_pos0; + int16_t differential_subframe; + + int16_t ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + int16_t bits_index; + int16_t nbits00, nbits11; + int16_t idx_sep_obj_local; + + idx_sep_obj_local = idx_separated_obj; + if ( idx_separated_obj > -1 ) + { + if ( idx_separated_obj == no_ism - 1 ) + { + idx_sep_obj_local = 0; + } + } + nbits = 0; + nbits0 = 0; + nbits1 = 0; + + bits_pos0 = hMetaData->nb_bits_tot; + differential_subframe = 1; /* the differences are taken with respect to previous subframe */ + + /* first subframe */ + bits_index = 0; + if ( sf == 0 ) + { + bits_index = bits_index_ism_ratio( no_ism ); + + nbits = 0; + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + nbits += bits_index; + } + } + + nbits0 = try_differential( numCodingBands, masa_to_total_energy_ratio, ratio_ism_idx, no_ism, bits_index, &b_signif ); + + if ( nbits <= nbits0 && nbits > 0 ) + { + /* independent encoding */ + push_next_indice( hMetaData, 1, 1 ); + independent_coding_ratio_ism_idx( ratio_ism_idx, masa_to_total_energy_ratio, no_ism, numCodingBands, bits_index, hMetaData ); + nbits = nbits + 1; + } + else + { + if ( nbits > 0 ) + { + differential_coding_first_subframe( hMetaData, masa_to_total_energy_ratio, b_signif, ratio_ism_idx, no_ism, numCodingBands, bits_index ); + nbits = nbits0 + 1; + } + } + +#ifdef DEBUGGING + assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); +#endif + } + else + { + /* not first subframe */ + if ( shift_one == 1 && no_ism == 2 ) + { + nbits = 0; + } + else + { + nbits0 = 0; + nbits1 = 0; + + + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], no_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 += nbits00; + nbits1 += nbits11; + } + } + if ( nbits0 < nbits1 ) + { + GR_order = 0; + nbits = nbits0; + } + else + { + GR_order = 1; + nbits = nbits1; + } + if ( numCodingBands > 1 ) + { + /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ + /* take difference with respect to previous subframe only for first subband */ + nbits0 = 0; + nbits1 = 0; + b_signif = 0; + while ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR && b_signif < numCodingBands ) + { + b_signif++; + } + if ( b_signif < numCodingBands ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], no_ism, shift_one, idx_sep_obj_local, &nbits0, &nbits1 ); + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism ); + + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + estimate_bits_subband_ism_ratio( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism, shift_one, idx_sep_obj_local, &nbits00, &nbits11 ); + nbits0 += nbits00; + nbits1 += nbits11; + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism ); + } + } + + if ( nbits0 < nbits1 ) + { + GR_order_sb = 0; + } + else + { + GR_order_sb = 1; + nbits0 = nbits1; + } + + if ( nbits0 < nbits ) + { + differential_subframe = 0; + nbits = nbits0; + GR_order = GR_order_sb; + } + + if ( nbits > 0 ) + { + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits++; /* for the prediction type */ + nbits++; /* for GR_order */ + + /* write data */ + if ( differential_subframe ) + { + for ( b = 0; b < numCodingBands; b++ ) + { + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, no_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode( diff_idx, no_ism - 1 - shift_one, GR_order, hMetaData ); + } + } + } + else + { + v_sub_s( ratio_ism_idx[b_signif], ratio_ism_idx_prev_sf[b_signif], diff_idx, no_ism ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, no_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode( diff_idx, no_ism - 1 - shift_one, GR_order, hMetaData ); + mvs2s( ratio_ism_idx[b_signif], ratio_ism_idx_ref, no_ism - shift_one); + for ( b = b_signif + 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subband */ + if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) + { + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_ref, diff_idx, no_ism ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, no_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode( diff_idx, no_ism - 1 - shift_one, GR_order, hMetaData ); + mvs2s( ratio_ism_idx[b], ratio_ism_idx_ref, no_ism - shift_one ); + } + } + } + } + } + } + else + { + /* only differential wrt previous subframe is possible */ + /* write the differential to subframe case and no bit to signal the difference type */ + + if ( nbits > 0 ) + { + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + nbits++; /* for GR_order */ + /* write data */ + /* only one subband */ + if ( masa_to_total_energy_ratio[0] < MASA2TOTAL_THR ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); + if ( shift_one ) + { + remove_sep_obj( diff_idx, no_ism, idx_sep_obj_local ); + } + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); + } + } + } + + +#ifdef DEBUGGING + assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); +#endif + } + + + } + return nbits; +} + + +#else static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], @@ -2220,7 +2909,7 @@ static int16_t encode_ratio_ism_subframe( BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio ) { - int16_t b, i; + int16_t b, i, b_signif; int16_t diff_idx[MAX_NUM_OBJECTS], index; int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb, bits_pos0; int16_t differential_subframe; @@ -2235,6 +2924,7 @@ static int16_t encode_ratio_ism_subframe( { if ( no_ism == 2 ) { + for ( b = 0; b < numCodingBands; b++ ) { if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) @@ -2245,6 +2935,7 @@ static int16_t encode_ratio_ism_subframe( nbits += 3; } } + } else if ( no_ism == 3 ) { @@ -2322,28 +3013,33 @@ static int16_t encode_ratio_ism_subframe( /* take difference with respect to previous subframe only for first subband */ nbits0 = 0; nbits1 = 0; - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - /* transform difference index into positive */ - transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); - /* GR encoding */ - for ( i = 0; i < no_ism - 1; i++ ) - { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - for ( b = 1; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); /* transform difference index into positive */ transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); /* GR encoding */ - for ( i = 0; i < no_ism - 1; i++ ) { nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); } + + + for ( b = 1; b < numCodingBands; b++ ) + { + + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + /* transform difference index into positive */ + transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); + /* GR encoding */ + + for ( i = 0; i < no_ism - 1; i++ ) + { + nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); + nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); + } + } if ( nbits0 < nbits1 ) @@ -2362,35 +3058,38 @@ static int16_t encode_ratio_ism_subframe( nbits = nbits0; GR_order = GR_order_sb; } - nbits++; /* for GR_order */ - nbits++; /* for the prediction type */ - /* write prediction type */ - push_next_indice( hMetaData, differential_subframe, 1 ); - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - /* write data */ - if ( differential_subframe ) - { - for ( b = 0; b < numCodingBands; b++ ) + nbits++; /* for GR_order */ + nbits++; /* for the prediction type */ + + /* write prediction type */ + push_next_indice( hMetaData, differential_subframe, 1 ); + /* write GR order */ + push_next_indice( hMetaData, GR_order, 1 ); + /* write data */ + if ( differential_subframe ) { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - } - } - else - { - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); + for ( b = 0; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subframe */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - for ( b = 1; b < numCodingBands; b++ ) + } + } + else { - /* take difference with respect to previous subband */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); + + for ( b = 1; b < numCodingBands; b++ ) + { + /* take difference with respect to previous subband */ + v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); + transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); + } } - } + } else { @@ -2408,14 +3107,18 @@ static int16_t encode_ratio_ism_subframe( v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); } + } #ifdef DEBUGGING assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); #endif } + return nbits; } +#endif + static void ivas_encode_masaism_metadata( @@ -2425,7 +3128,13 @@ static void ivas_encode_masaism_metadata( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ int16_t low_bitrate_mode, /* i: is low bitrate more? 1/0 */ int16_t omasa_nbands, - int16_t omasa_nblocks ) + int16_t omasa_nblocks +#ifdef REDUCE_OMASA_META_BITS + , + int16_t idx_separated_object, + int16_t ism_imp +#endif +) { int16_t sf, band; uint8_t numCodingBands; @@ -2434,7 +3143,9 @@ static void ivas_encode_masaism_metadata( float eneBand; int16_t bin; int16_t obj; +#ifndef REDUCE_OMASA_META_BITS float priority[MAX_NUM_OBJECTS]; +#endif int16_t bits_ism[MAX_NUM_OBJECTS]; uint16_t idx_sph; float theta_q, phi_q; @@ -2444,6 +3155,10 @@ static void ivas_encode_masaism_metadata( float step; int16_t inv_step; float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; +#ifdef REDUCE_OMASA_META_BITS + int16_t tmp, rotate; + int16_t n_ism_tmp, i; +#endif /* use the values from hQMetaData */ @@ -2567,9 +3282,12 @@ static void ivas_encode_masaism_metadata( /* quantize ism_ratios */ if ( hMasa->data.nchan_ism > 1 ) { - inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); step = 1.0f / inv_step; +#ifdef REDUCE_OMASA_META_BITS + rotate = 0; + n_ism_tmp = 0; +#endif for ( sf = 0; sf < numSf; sf++ ) { for ( band = 0; band < numCodingBands; band++ ) @@ -2580,23 +3298,112 @@ static void ivas_encode_masaism_metadata( ratio_ism[band][obj] = hMasa->data.energy_ratio_ism[sf][band][obj]; } /* Quantize power ratios */ +#ifdef REDUCE_OMASA_META_BITS + quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); + if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + i = 0; + while ( ratio_ism_idx[band][idx_separated_object] > 0 ) + { + if ( i != idx_separated_object ) + { + ratio_ism_idx[band][i]++; + ratio_ism_idx[band][idx_separated_object]--; + } + i++; + if ( i == hMasa->data.nchan_ism ) + { + i = 0; + } + } + } +#else quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band] ); +#endif /* reconstructed values */ reconstruct_ism_ratios( ratio_ism_idx[band], hMasa->data.nchan_ism, step, hMasa->data.q_energy_ratio_ism[sf][band] ); /* encode vector */ } +#ifdef REDUCE_OMASA_META_BITS + if ( ( hMasa->data.nchan_ism > 2 ) && ( idx_separated_object == hMasa->data.nchan_ism - 1 ) ) + { + /* rotate components */ + rotate = 1; + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + tmp = ratio_ism_idx[band][hMasa->data.nchan_ism - 1]; + ratio_ism_idx[band][hMasa->data.nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; + if ( sf == 0 && tmp == 0 ) + { + n_ism_tmp += 1; + } + + if ( n_ism_tmp == numCodingBands ) + { + assert( tmp == 0 ); + } + } + } + } + else + { + if ( idx_separated_object > -1 ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + if ( ratio_ism_idx[band][idx_separated_object] == 0 && sf == 0 ) + { + n_ism_tmp++; + } + } + } + } + } +#endif /* encode data for current subframe */ + +#ifdef REDUCE_OMASA_META_BITS + if ( sf > 0 && n_ism_tmp == numCodingBands ) + { + encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); + } + else + { + encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); + } +#else encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf] ); +#endif + /* calculate quantized ISM ratios */ /* save previous subframe indexes */ for ( band = 0; band < numCodingBands; band++ ) { mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], hMasa->data.nchan_ism ); } +#ifdef REDUCE_OMASA_META_BITS + if ( rotate ) + { + for ( band = 0; band < numCodingBands; band++ ) + { + if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) + { + tmp = ratio_ism_idx[band][hMasa->data.nchan_ism - 1]; + ratio_ism_idx[band][hMasa->data.nchan_ism - 1] = ratio_ism_idx[band][0]; + ratio_ism_idx[band][0] = tmp; + } + } + } +#endif } - +#ifndef REDUCE_OMASA_META_BITS set_f( priority, 0.0f, hMasa->data.nchan_ism ); for ( sf = 0; sf < numSf; sf++ ) { @@ -2608,19 +3415,25 @@ static void ivas_encode_masaism_metadata( } } } +#endif } +#ifndef REDUCE_OMASA_META_BITS else { priority[0] = 1; } - +#endif +#ifdef REDUCE_OMASA_META_BITS + calculate_nbits_meta( hMasa->data.nchan_ism, hMasa->data.q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#else /* decide parameters for ISM metadata quantization */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) { bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); } +#endif - /* this is only the first version */ + /* quantize directions */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index cd2548701a..db156c61e7 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -50,7 +50,12 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); +static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], +#ifdef OMASA_DIFFUSE_ISM_MERGE + float diffuseness_m[MASA_FREQUENCY_BANDS], +#endif + const int16_t input_frame, + const int16_t nchan_inp ); static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); @@ -126,8 +131,13 @@ ivas_error ivas_omasa_enc_open( for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { +#ifdef OMASA_DIFFUSE_ISM_MERGE + hOMasa->direction_vector_m[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ); + set_zero( hOMasa->direction_vector_m[i][j], MASA_FREQUENCY_BANDS ); +#else hOMasa->direction_vector_m[i][j] = (float *) malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); set_zero( hOMasa->direction_vector_m[i][j], MAXIMUM_OMASA_FREQ_BANDS ); +#endif } } @@ -135,8 +145,13 @@ ivas_error ivas_omasa_enc_open( { for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { +#ifdef OMASA_DIFFUSE_ISM_MERGE + hOMasa->buffer_intensity_real[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ); + set_zero( hOMasa->buffer_intensity_real[i][j], MASA_FREQUENCY_BANDS ); +#else hOMasa->buffer_intensity_real[i][j] = (float *) malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); set_zero( hOMasa->buffer_intensity_real[i][j], MAXIMUM_OMASA_FREQ_BANDS ); +#endif } } @@ -225,12 +240,28 @@ void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs /* i : Input sample rate */ +#ifdef OMASA_DIFFUSE_ISM_MERGE + , + ISM_MODE ismMode /* i : ISM mode */ +#endif ) { int16_t i, maxBin; /* Determine the number of bands */ +#ifdef OMASA_DIFFUSE_ISM_MERGE + if ( ismMode == ISM_MODE_NONE ) + { + /* use full resolution for the ISM+MASA merge and reduce later */ + hOMasa->nbands = 24; + } + else + { + hOMasa->nbands = hMasa->config.numCodingBands; + } +#else hOMasa->nbands = hMasa->config.numCodingBands; +#endif hOMasa->nCodingBands = hMasa->config.numCodingBands; /* Determine the number of subframes */ @@ -297,6 +328,12 @@ void ivas_omasa_enc( /* Analysis */ if ( ism_mode == ISM_MODE_NONE ) { +#ifdef OMASA_DIFFUSE_ISM_MERGE + OMASA_SPATIAL_META OMasaMeta; /* working memory for the ISM-object MASA-parameters */ + OMASA_SPATIAL_META_HANDLE hOMasaMeta; + int16_t n_bands_orig, n_subframes_orig; + uint8_t numCodingBands_orig, joinedSubframes_orig; +#else float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; float energyRatio[MASA_FREQUENCY_BANDS]; @@ -307,9 +344,66 @@ void ivas_omasa_enc( nBands = hOMasa->nbands; nBlocks = hOMasa->nSubframes; +#endif + +#ifdef OMASA_DIFFUSE_ISM_MERGE + hOMasaMeta = &OMasaMeta; + hOMasaMeta->num_dirs = 1; /* TODO: hard-coding for now */ + + /* merge MASA directions before adding ISM to the mixture */ + if ( hMasa->config.numberOfDirections == 2 ) + { + n_bands_orig = hMasa->config.numCodingBands; + hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; + + ivas_masa_combine_directions( hMasa ); + + hMasa->config.numCodingBands = n_bands_orig; + } + + // force computation into high resolution + n_bands_orig = hOMasa->nbands; + n_subframes_orig = hOMasa->nSubframes; + + hOMasa->nbands = MASA_FREQUENCY_BANDS; + hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; + /* Estimate MASA parameters from the objects */ + /* NB: only first direction is populated */ + /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ + ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], + hOMasaMeta->common_meta.diffuse_to_total_ratio[0], + input_frame, nchan_ism ); + + /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + mvr2r( hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].energy_ratio[i], MASA_FREQUENCY_BANDS ); + mvr2r( hOMasaMeta->common_meta.surround_coherence[0], hOMasaMeta->common_meta.surround_coherence[i], MASA_FREQUENCY_BANDS ); + mvr2r( hOMasaMeta->common_meta.diffuse_to_total_ratio[0], hOMasaMeta->common_meta.diffuse_to_total_ratio[i], MASA_FREQUENCY_BANDS ); + } +#else /* Estimate MASA parameters from the objects */ ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, nchan_ism ); +#endif + +#ifdef OMASA_DIFFUSE_ISM_MERGE + /* restore resolution parameters */ + hOMasa->nbands = n_bands_orig; + hOMasa->nSubframes = n_subframes_orig; + + /* perform MASA+ISM merge in full resolution */ + numCodingBands_orig = hMasa->config.numCodingBands; + joinedSubframes_orig = hMasa->config.joinedSubframes; + + hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; + hMasa->config.joinedSubframes = 0; + + ivas_merge_masa_metadatas( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ + + hMasa->config.numCodingBands = numCodingBands_orig; + hMasa->config.joinedSubframes = joinedSubframes_orig; +#else /* Set analyzed values to the QMeta struct */ for ( i = 0; i < nBands; i++ ) @@ -349,9 +443,13 @@ void ivas_omasa_enc( } } } +#endif } else if ( ism_mode == ISM_MASA_MODE_PARAM ) { +#ifdef REDUCE_OMASA_META_BITS + *idx_separated_object = -1; +#endif /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); } @@ -625,6 +723,9 @@ static void ivas_omasa_param_est_enc( float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], +#ifdef OMASA_DIFFUSE_ISM_MERGE + float diffuseness_m[MASA_FREQUENCY_BANDS], +#endif const int16_t input_frame, const int16_t nchan_ism ) { @@ -640,7 +741,10 @@ static void ivas_omasa_param_est_enc( float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float diffuseness_vector[MASA_FREQUENCY_BANDS]; +#ifndef OMASA_DIFFUSE_ISM_MERGE float diffuseness_m[MASA_FREQUENCY_BANDS]; +#endif + int16_t band_m_idx, block_m_idx; float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; float norm_tmp; -- GitLab From e4789fa66bc098a5578f01ddde4a89cf8f31360d Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 6 Mar 2023 15:10:51 +0100 Subject: [PATCH 044/173] fix MSVC compilation warnings --- lib_com/ivas_masa_com.c | 1 - lib_com/ivas_prot.h | 2 ++ lib_enc/ivas_enc.c | 4 ++++ lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 17 +++++++++-------- lib_enc/ivas_stat_enc.h | 6 +++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 8185680d54..c3082f53e1 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -600,7 +600,6 @@ int32_t calculate_cpe_brate_MASA_ISM( int16_t k, sce_id; k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) { k++; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index cf2595f1c4..da7a57efa6 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5036,7 +5036,9 @@ void ivas_omasa_set_config( void ivas_omasa_enc( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ +#ifndef OMASA_DIFFUSE_ISM_MERGE IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ +#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index e5e4f2860b..a3adbda9b6 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -340,7 +340,11 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ +#ifdef OMASA_DIFFUSE_ISM_MERGE + ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); +#else ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); +#endif } /* Encode ISMs transport channels */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index b7c5b7f707..f31badf9b3 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2136,7 +2136,7 @@ static void ivas_merge_masa_metadata( /* target is original MASA diffuseness */ total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; /* criterion is mean of ISM ratio and new ratio */ - energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0 * hMasa->data.energy_ism[sf][band]; + energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.energy_ism[sf][band]; /* Determine combined metadata based on the weights */ merge_dest = -1; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index b82b2c4a4d..8b603c42fc 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -246,7 +246,7 @@ void ivas_omasa_set_config( #endif ) { - int16_t i, maxBin; + uint8_t i, maxBin; /* Determine the number of bands */ #ifdef OMASA_DIFFUSE_ISM_MERGE @@ -280,7 +280,7 @@ void ivas_omasa_set_config( } } - maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + maxBin = (uint8_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); for ( i = 1; i < hOMasa->nbands + 1; i++ ) { @@ -309,8 +309,10 @@ void ivas_omasa_set_config( *--------------------------------------------------------------------------*/ void ivas_omasa_enc( - OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ - IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ + OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ +#ifndef OMASA_DIFFUSE_ISM_MERGE + IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ +#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ @@ -331,7 +333,7 @@ void ivas_omasa_enc( #ifdef OMASA_DIFFUSE_ISM_MERGE OMASA_SPATIAL_META OMasaMeta; /* working memory for the ISM-object MASA-parameters */ OMASA_SPATIAL_META_HANDLE hOMasaMeta; - int16_t n_bands_orig, n_subframes_orig; + uint8_t n_bands_orig, n_subframes_orig; uint8_t numCodingBands_orig, joinedSubframes_orig; #else float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; @@ -361,7 +363,7 @@ void ivas_omasa_enc( hMasa->config.numCodingBands = n_bands_orig; } - // force computation into high resolution + /* force computation into high resolution */ n_bands_orig = hOMasa->nbands; n_subframes_orig = hOMasa->nSubframes; @@ -372,8 +374,7 @@ void ivas_omasa_enc( /* NB: only first direction is populated */ /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], - hOMasaMeta->common_meta.diffuse_to_total_ratio[0], - input_frame, nchan_ism ); + hOMasaMeta->common_meta.diffuse_to_total_ratio[0], input_frame, nchan_ism ); /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index adcbc6b9ba..c1df19f243 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -841,9 +841,9 @@ typedef struct ivas_mcmasa_enc_data_structure typedef struct ivas_omasa_enc_data_structure { - int16_t nbands; - int16_t nCodingBands; - int16_t nSubframes; + uint8_t nbands; + uint8_t nCodingBands; + uint8_t nSubframes; /* delay compensation */ float *delay_buffer[MAX_NUM_OBJECTS]; /* Delay buffer for parameter estimation */ -- GitLab From 57edb8d536825b92cb0a24f409e0e8ecc9731c1b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 6 Mar 2023 15:51:27 +0100 Subject: [PATCH 045/173] fix to 4 ISMs 24 kbps case: when all objects are HIGH_IMP, keep 24 kbps bitrate, otherwise increase the 24 kbps bitrate; under FIX_4OBJ_128 --- lib_com/ivas_omasa_com.c | 20 +++++++++++++++++++- lib_com/ivas_prot.h | 3 +++ lib_com/options.h | 3 +++ lib_dec/ivas_omasa_dec.c | 24 ++++++++++++++++++++++-- lib_enc/ivas_ism_metadata_enc.c | 16 +++++++++++++++- lib_enc/ivas_omasa_enc.c | 7 ++++++- lib_enc/ivas_sce_enc.c | 8 +++++++- 7 files changed, 75 insertions(+), 6 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index bccda612fa..a14b4c908c 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -60,12 +60,19 @@ #define GAMMA_ISM_LOW_IMP3 0.85f #define GAMMA_ISM_MEDIUM_IMP3 1.15f #define GAMMA_ISM_HIGH_IMP3 1.3f + #ifdef TUNING_DISC_3_4obj +#ifdef FIX_4OBJ_128 +#define GAMMA_ISM_LOW_IMP4 0.8f +#define GAMMA_ISM_MEDIUM_IMP4 1.0f +#define GAMMA_ISM_HIGH_IMP4 1.2f +#else #define GAMMA_ISM_LOW_IMP4 0.6f #define GAMMA_ISM_MEDIUM_IMP4 0.8f #define GAMMA_ISM_HIGH_IMP4 1.0f #endif #endif +#endif /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() @@ -175,6 +182,10 @@ int32_t ivas_interformat_brate( const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ +#ifdef FIX_4OBJ_128 + , + const int16_t limit_flag /* i : flag to limit the bitrate increase */ +#endif ) { int32_t element_brate_out; @@ -182,7 +193,6 @@ int32_t ivas_interformat_brate( nBits = (int16_t) ( element_brate / FRAMES_PER_SEC ); - if ( ism_imp == ISM_INACTIVE_IMP ) { nBits = BITS_ISM_INACTIVE; @@ -192,6 +202,14 @@ int32_t ivas_interformat_brate( #ifdef TUNING_DISC_3_4obj if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) ) ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ { + +#ifdef FIX_4OBJ_128 + if ( limit_flag && ( nchan_ism == 4 && element_brate == 24000 ) ) + { + return element_brate; + } +#endif + if ( ism_imp == ISM_LOW_IMP ) { nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index da7a57efa6..b20eb35e3b 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5079,6 +5079,9 @@ int32_t ivas_interformat_brate( const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ +#ifdef FIX_4OBJ_128 + , const int16_t limit_flag /* i : flag to limit the bitrate increase */ +#endif ); void ivas_combined_format_brate_sanity( diff --git a/lib_com/options.h b/lib_com/options.h index bf528b6761..d0fda9cf9f 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,6 +179,9 @@ #define REDUCE_OMASA_META_BITS /* Nokia: reduce metadata number of bits and fix directional metadata bit allocation */ #define OMASA_DIFFUSE_ISM_MERGE /* Nokia: Diffuse-energy retaining merging of ISM and MASA */ +#define FIX_4OBJ_128 /* VA: fix to 4 ISMs 24 kbps case: when all objects are HIGH_IMP, keep 24 kbps bitrate, otherwise increase the 24 kbps bitrate */ + + #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 6e95f0710f..5ca00ff79e 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -59,7 +59,12 @@ void ivas_set_surplus_brate_dec( if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - *ism_total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + *ism_total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp +#ifdef FIX_4OBJ_128 + , + 0 +#endif + ); st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; @@ -74,6 +79,16 @@ void ivas_set_surplus_brate_dec( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { +#ifdef FIX_4OBJ_128 + int16_t brate_limit_flag = 0; + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + brate_limit_flag += st_ivas->hIsmMetaData[n]->ism_imp; + } + brate_limit_flag = brate_limit_flag >= 10 ? 1 : 0; +#endif + ism_total_brate_ref = 0; for ( n = 0; n < st_ivas->nchan_ism; n++ ) { @@ -90,7 +105,12 @@ void ivas_set_surplus_brate_dec( { st_ivas->hSCE[n]->element_brate = element_brate[n]; - *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp ); + *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp +#ifdef FIX_4OBJ_128 + , + brate_limit_flag +#endif + ); } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index aacf3dc0b6..43c498bcd0 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -824,6 +824,15 @@ ivas_error ivas_ism_metadata_enc( if ( ism_mode == ISM_MASA_MODE_DISC ) { int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; +#ifdef FIX_4OBJ_128 + int16_t brate_limit_flag = 0; + + for ( ch = 0; ch < num_obj; ch++ ) + { + brate_limit_flag += ism_imp[ch]; + } + brate_limit_flag = brate_limit_flag >= 10 ? 1 : 0; +#endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); set_s( bits_element, bits_ism / num_obj, num_obj ); @@ -833,7 +842,12 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < num_obj; ch++ ) { - *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, num_obj, hSCE[ch]->element_brate, ism_imp[ch] ); + *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, num_obj, hSCE[ch]->element_brate, ism_imp[ch] +#ifdef FIX_4OBJ_128 + , + brate_limit_flag +#endif + ); } ism_metadata_flag_global = 1; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 8b603c42fc..b7fe8ee27e 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -667,7 +667,12 @@ void ivas_set_surplus_brate_enc( { if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ); + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp +#ifdef FIX_4OBJ_128 + , + 0 +#endif + ); /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index c600aa1436..dde49fb9cd 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -229,7 +229,13 @@ ivas_error ivas_sce_enc( { set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); - st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp ) - nb_bits_metadata * FRAMES_PER_SEC; + st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp +#ifdef FIX_4OBJ_128 + , + 0 +#endif + ) - + nb_bits_metadata * FRAMES_PER_SEC; } #endif -- GitLab From 0cc758c2f085cea8450381c7694060ad7b8bce74 Mon Sep 17 00:00:00 2001 From: advasila Date: Mon, 6 Mar 2023 18:26:09 +0200 Subject: [PATCH 046/173] fix compilation warnings --- lib_com/ivas_prot.h | 2 ++ lib_enc/ivas_enc.c | 6 +++++- lib_enc/ivas_masa_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 4e700a7abe..7adc713c74 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5219,7 +5219,9 @@ void ivas_omasa_set_config( void ivas_omasa_enc( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ +#ifndef OMASA_DIFFUSE_ISM_MERGE IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ +#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c0bf3caa93..793c1a9885 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -357,7 +357,11 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); + ivas_omasa_enc( st_ivas->hOMasa, +#ifndef OMASA_DIFFUSE_ISM_MERGE + st_ivas->hQMetaData, +#endif + st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); } /* Encode ISMs transport channels */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 59b76cdd7c..ecfa7f0edb 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2130,7 +2130,7 @@ static void ivas_merge_masa_metadatas( /* target is original MASA diffuseness */ total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; /* criterion is mean of ISM ratio and new ratio */ - energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0 * hMasa->data.energy_ism[sf][band]; + energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.energy_ism[sf][band]; /* Determine combined metadata based on the weights */ merge_dest = -1; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index db156c61e7..a647ceeb9e 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -310,7 +310,9 @@ void ivas_omasa_set_config( void ivas_omasa_enc( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ +#ifndef OMASA_DIFFUSE_ISM_MERGE IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ +#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ @@ -358,7 +360,7 @@ void ivas_omasa_enc( ivas_masa_combine_directions( hMasa ); - hMasa->config.numCodingBands = n_bands_orig; + hMasa->config.numCodingBands = (int8_t)n_bands_orig; } // force computation into high resolution -- GitLab From 6d5d3f18df800beebf7f05ba73054534b20cbd83 Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 7 Mar 2023 15:17:46 +0200 Subject: [PATCH 047/173] fix fp precision --- lib_com/ivas_omasa_com.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index f825b41252..da3a0cf503 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -390,7 +390,7 @@ void calculate_nbits_meta( priority[obj] = max_p; } } - bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); + bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 7 ); } return; } -- GitLab From aabaaa86e190b40ecd718f9a802b2dbb244e4af6 Mon Sep 17 00:00:00 2001 From: advasila Date: Wed, 8 Mar 2023 11:51:32 +0200 Subject: [PATCH 048/173] remove TUNING_2obj switch --- lib_com/ivas_omasa_com.c | 4 ---- lib_com/ivas_rom_com.c | 4 ---- lib_com/options.h | 1 - 3 files changed, 9 deletions(-) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 0c6c35afab..e248cc5a9d 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -102,11 +102,7 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 2: -#ifdef TUNING_48kbps_2obj if ( ivas_total_brate >= IVAS_48k ) -#else - if ( ivas_total_brate >= IVAS_64k ) -#endif { ism_mode = ISM_MASA_MODE_DISC; } diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index ec2b6c5b93..66db7666f2 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2794,11 +2794,7 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = #else {9600, 0, 0, 0}, /* 32k */ #endif -#ifdef TUNING_48kbps_2obj {IVAS_13k2, 9600, 0, 0}, /* 48k */ -#else - {IVAS_13k2, 0, 0, 0}, /* 48k */ -#endif #ifdef OMASA_BRATE {16000, 11700, 0, 0}, /* 64k */ #else diff --git a/lib_com/options.h b/lib_com/options.h index d0fda9cf9f..4a4fefae31 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -173,7 +173,6 @@ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define TUNING_48kbps_2obj #define TUNING_DISC_3_4obj /* Nokia: increase bitrate for objects in DISC mode at 128k 4obj and 96k 3 obj */ #define REDUCE_OMASA_META_BITS /* Nokia: reduce metadata number of bits and fix directional metadata bit allocation */ -- GitLab From a8f5f41389dcb7c7510fb20aa9ea3cc3a8bd8ee4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 8 Mar 2023 15:17:26 +0100 Subject: [PATCH 049/173] - support of bitrate switching in OMASA format; under OMASA_BRATE_SW --- lib_com/ivas_ism_config.c | 28 ++ lib_com/ivas_omasa_com.c | 41 +++ lib_com/ivas_prot.h | 38 ++- lib_com/options.h | 2 + lib_dec/ivas_corecoder_dec_reconfig.c | 2 + lib_dec/ivas_cpe_dec.c | 4 +- lib_dec/ivas_init_dec.c | 39 ++- lib_dec/ivas_ism_metadata_dec.c | 23 +- lib_dec/ivas_ism_renderer.c | 12 +- lib_dec/ivas_masa_dec.c | 45 +-- lib_dec/ivas_omasa_dec.c | 285 ++++++++++++++++++- lib_dec/ivas_stereo_switching_dec.c | 4 + lib_enc/ivas_corecoder_enc_reconfig.c | 16 +- lib_enc/ivas_cpe_enc.c | 6 +- lib_enc/ivas_enc.c | 11 + lib_enc/ivas_ism_metadata_enc.c | 8 +- lib_enc/ivas_masa_enc.c | 6 + lib_enc/ivas_omasa_enc.c | 121 +++++++- lib_rend/ivas_dirac_dec_binaural_functions.c | 4 +- 19 files changed, 628 insertions(+), 67 deletions(-) diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 06ccd94a31..c329344804 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -586,3 +586,31 @@ ISM_MODE ivas_ism_mode_select( return ism_mode; } + + +#ifdef OMASA_BRATE_SW +/*------------------------------------------------------------------------- + * ivas_ism_metadata_close() + * + * Deallocate ISM metadata handles + *-------------------------------------------------------------------------*/ + +void ivas_ism_metadata_close( + ISM_METADATA_HANDLE *hIsmMetaData, /* i/o: ISM metadata handles */ + const int16_t first_idx /* i : index of first handle to deallocate */ +) +{ + int16_t n; + + for ( n = first_idx; n < MAX_NUM_OBJECTS; n++ ) + { + if ( hIsmMetaData[n] != NULL ) + { + free( hIsmMetaData[n] ); + hIsmMetaData[n] = NULL; + } + } + + return; +} +#endif diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index a14b4c908c..71a452dadd 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -169,6 +169,47 @@ ISM_MODE ivas_omasa_ism_mode_select( } +#ifdef OMASA_BRATE_SW +/*--------------------------------------------------------------- + * ivas_set_omasa_TC() + * + * set number of transport channels in OMASA format + * ---------------------------------------------------------------*/ + +void ivas_set_omasa_TC( + const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of input ISMs */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE /* o : number of CPEs */ +) +{ + switch ( ism_mode ) + { + case ISM_MASA_MODE_PARAM: + *nCPE = 1; + *nSCE = 0; + break; + case ISM_MASA_MODE_ONE_OBJ: + *nCPE = 1; + *nSCE = 1; + break; + case ISM_MASA_MODE_DISC: + *nCPE = 1; + *nSCE = nchan_ism; + break; + case ISM_MODE_NONE: + *nCPE = 1; + *nSCE = 0; + break; + default: + break; + } + + return; +} +#endif + + #ifdef OMASA_BRATE /*--------------------------------------------------------------- * ivas_interformat_brate() diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b20eb35e3b..fb117e8e81 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -799,9 +799,16 @@ float ism_dequant_meta( ivas_error set_ism_metadata( ISM_METADATA_HANDLE hIsmMeta, /* i/o: ISM metadata handle */ float azimuth, /* i : azimuth */ - float elevation /* i : elevation */ + float elevation /* i : elevation */ ); +#ifdef OMASA_BRATE_SW +void ivas_ism_metadata_close( // VE: use it also at the encoder + ISM_METADATA_HANDLE *hIsmMetaData, /* i/o: ISM metadata handles */ + const int16_t first_idx /* i : index of first handle to deallocate */ +); +#endif + ivas_error create_ism_metadata_enc( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const int16_t n_ISms, /* i : number of objects */ @@ -5024,13 +5031,23 @@ void ivas_omasa_enc_close( const int16_t nchan_ism /* i : number of objects */ ); +#ifdef OMASA_BRATE_SW +ivas_error ivas_omasa_enc_config( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); + +ivas_error ivas_omasa_dec_config( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif + void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs /* i : Input sample rate */ #ifdef OMASA_DIFFUSE_ISM_MERGE , - ISM_MODE ismMode /* i : ISM mode */ + const ISM_MODE ismMode /* i : ISM mode */ #endif ); @@ -5061,7 +5078,7 @@ void ivas_set_surplus_brate_enc( void ivas_set_surplus_brate_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - int32_t *ism_total_brate /* i : ISM total bit-rate */ + int32_t *ism_total_brate /* i : ISM total bitrate */ ); void set_ism_importance_interformat( @@ -5097,6 +5114,15 @@ ISM_MODE ivas_omasa_ism_mode_select( const int16_t nchan_ism /* i : number of input ISM's */ ); +#ifdef OMASA_BRATE_SW +void ivas_set_omasa_TC( + const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of input ISMs */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE /* o : number of CPEs */ +); +#endif + void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ float data_in_f2[][L_FRAME48k], /* i : Transport audio signals 2 */ @@ -5109,6 +5135,12 @@ ivas_error ivas_masa_ism_data_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); +#ifdef OMASA_BRATE_SW +void ivas_masa_ism_data_close( + MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ +); +#endif + void preProcessStereoTransportsForMovedObjects( Decoder_Struct* st_ivas, float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], diff --git a/lib_com/options.h b/lib_com/options.h index d0fda9cf9f..710803fcbc 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,6 +181,8 @@ #define FIX_4OBJ_128 /* VA: fix to 4 ISMs 24 kbps case: when all objects are HIGH_IMP, keep 24 kbps bitrate, otherwise increase the 24 kbps bitrate */ +#define OMASA_BRATE_SW /* VA: support of bitrate switching in OMASA format */ + #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index bb2b753181..5317781d55 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -512,10 +512,12 @@ ivas_error ivas_cldfb_dec_reconfig( } } } + /* CLDFB Interpolation weights */ if ( st_ivas->sba_mode == SBA_MODE_SPAR && ( numCldfbAnalyses_old != numCldfbAnalyses || numCldfbSyntheses_old != numCldfbSyntheses || nchan_transport_old != st_ivas->nchan_transport ) ) { ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); } + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index eab7b7c340..545dc8fbb3 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -176,7 +176,6 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS } #endif - } else { @@ -711,10 +710,11 @@ ivas_error create_cpe_dec( { #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == STEREO_FORMAT || st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || + ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || st_ivas->sba_dirac_stereo_flag ) #else if ( st_ivas->ivas_format == STEREO_FORMAT || st_ivas->ivas_format == MASA_FORMAT || -#endif ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || st_ivas->sba_dirac_stereo_flag ) +#endif { if ( ( hCPE->input_mem[i] = (float *) malloc( sizeof( float ) * NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f530e8ecce..2d5a3168f2 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -71,7 +71,9 @@ ivas_error ivas_dec_setup( int32_t ivas_total_brate; ivas_error error; #ifdef MASA_AND_OBJECTS +#ifndef OMASA_BRATE_SW int32_t cpe_brate; +#endif #endif error = IVAS_ERR_OK; @@ -159,6 +161,12 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { +#ifdef OMASA_BRATE_SW + if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->nCPE == 1 ) { st_ivas->hCPE[0]->nchan_out = 1; @@ -170,6 +178,7 @@ ivas_error ivas_dec_setup( return error; } } +#endif } } } @@ -177,8 +186,8 @@ ivas_error ivas_dec_setup( else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ - /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata*/ + /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */ st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); @@ -187,6 +196,12 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { +#ifdef OMASA_BRATE_SW + if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 ) { @@ -196,6 +211,7 @@ ivas_error ivas_dec_setup( { return error; } +#endif } } } @@ -1051,10 +1067,17 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); #ifdef OMASA_BRATE +#ifdef OMASA_BRATE_SW + if ( ( error = create_ism_metadata_dec( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); } +#endif #endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) @@ -1740,7 +1763,11 @@ void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { +#ifdef OMASA_BRATE_SW + int16_t i; +#else int16_t i, n; +#endif /* CLDFB handles */ for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) @@ -1807,6 +1834,9 @@ void ivas_destroy_dec( } /* ISM metadata handles */ +#ifdef OMASA_BRATE_SW + ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); +#else for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) { if ( st_ivas->hIsmMetaData[n] != NULL ) @@ -1815,6 +1845,7 @@ void ivas_destroy_dec( st_ivas->hIsmMetaData[n] = NULL; } } +#endif /* ISm renderer handle */ if ( st_ivas->hIsmRendererData != NULL ) @@ -1902,8 +1933,12 @@ void ivas_destroy_dec( free( st_ivas->hMonoDmxRenderer ); st_ivas->hMonoDmxRenderer = NULL; } + #ifdef MASA_AND_OBJECTS /* MASA ISM structure */ +#ifdef OMASA_BRATE_SW + ivas_masa_ism_data_close( &st_ivas->hMasaIsmData ); +#else if ( st_ivas->hMasaIsmData != NULL ) { if ( st_ivas->hMasaIsmData->delayBuffer != NULL ) @@ -1919,6 +1954,8 @@ void ivas_destroy_dec( st_ivas->hMasaIsmData = NULL; } #endif +#endif + /* Head track data handle */ if ( st_ivas->hHeadTrackData != NULL ) { diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index e72d691768..5e404c0ff9 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -596,10 +596,10 @@ ivas_error ivas_ism_metadata_dec( * Create, allocate, initialize and configure IVAS decoder ISM handles *-------------------------------------------------------------------------*/ -ivas_error create_ism_metadata_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t n_ISms, /* i : number of objects */ - int32_t element_brate_tmp[] /* o : element bitrate per object */ +ivas_error create_ism_metadata_dec( // VE: rename to ivas_ism_metadata_dec_create + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t n_ISms, /* i : number of objects */ + int32_t element_brate_tmp[] /* o : element bitrate per object */ ) { int16_t ch; @@ -624,12 +624,19 @@ ivas_error create_ism_metadata_dec( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL +#ifdef OMASA_BRATE_SW + if ( element_brate_tmp != NULL ) + { +#endif + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL #ifdef MASA_AND_OBJECTS - , - 0 + , + 0 +#endif + ); +#ifdef OMASA_BRATE_SW + } #endif - ); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index ef890a7482..30a32e03a6 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -252,10 +252,10 @@ void ivas_ism_get_stereo_gains( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------------* - * ivas_masa_ism_separate_object_renderer_open() - * - * Open structures, reserve memory, and init values. - *-------------------------------------------------------------------------*/ +* ivas_masa_ism_separate_object_renderer_open() +* + * Open structures, reserve memory, and init values. + *-------------------------------------------------------------------------*/ ivas_error ivas_masa_ism_separate_object_renderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -266,10 +266,9 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer \n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); } - for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) { set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); @@ -296,6 +295,7 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) { if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f45b1527ff..6cd00b03e8 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -419,10 +419,12 @@ ivas_error ivas_masa_decode( } } } + if ( st_ivas->hDirAC != NULL ) { ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, SBA_MODE_NONE, 0 ); } + #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { @@ -433,6 +435,7 @@ ivas_error ivas_masa_decode( return error; } } + if ( st_ivas->hDirAC != NULL ) { #ifndef OMASA_BRATE @@ -461,7 +464,9 @@ ivas_error ivas_masa_decode( } } #endif + st->next_bit_pos = next_bit_pos_orig; + #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { @@ -581,45 +586,6 @@ ivas_error ivas_masa_dec_open( return IVAS_ERR_OK; } -#ifdef MASA_AND_OBJECTS -/*-------------------------------------------------------------------* - * ivas_masa_ism_data_open() - * - * - *-------------------------------------------------------------------*/ - -ivas_error ivas_masa_ism_data_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ -) -{ - MASA_ISM_DATA_HANDLE hMasaIsmData; - int16_t ch, bin; - - if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) ); - } - - for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) - { - for ( ch = 0; ch < 2; ch++ ) - { - hMasaIsmData->ismPreprocMatrix[ch][ch][bin] = 1.0f; - hMasaIsmData->ismPreprocMatrix[1 - ch][ch][bin] = 0.0f; - hMasaIsmData->eneMoveIIR[ch][bin] = 0.0f; - hMasaIsmData->enePreserveIIR[ch][bin] = 0.0f; - } - hMasaIsmData->preprocEneTarget[bin] = 0.0f; - hMasaIsmData->preprocEneRealized[bin] = 0.0f; - } - hMasaIsmData->objectsMoved = 0; - hMasaIsmData->delayBuffer = NULL; - st_ivas->hMasaIsmData = hMasaIsmData; - - return IVAS_ERR_OK; -} -#endif - /*-----------------------------------------------------------------------* * ivas_masa_dec_close() @@ -1374,6 +1340,7 @@ ivas_error ivas_masa_dec_reconfigure( } } } + #ifdef MASA_AND_OBJECTS ism_total_brate = 0; if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 5ca00ff79e..98e7b7eeee 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -35,11 +35,294 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" +#ifdef OMASA_BRATE_SW +#include "ivas_rom_com.h" +#endif #ifdef DEBUGGING #include "debug.h" #endif +#ifdef MASA_AND_OBJECTS +/*-------------------------------------------------------------------* + * ivas_masa_ism_data_open() + * + * Allocate and initialize MASA_ISM rendering handle + *-------------------------------------------------------------------*/ + +ivas_error ivas_masa_ism_data_open( + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ +) +{ + MASA_ISM_DATA_HANDLE hMasaIsmData; + int16_t ch, bin; + + if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA ISM data\n" ) ); + } + + for ( bin = 0; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) + { + for ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->ismPreprocMatrix[ch][ch][bin] = 1.0f; + hMasaIsmData->ismPreprocMatrix[1 - ch][ch][bin] = 0.0f; + hMasaIsmData->eneMoveIIR[ch][bin] = 0.0f; + hMasaIsmData->enePreserveIIR[ch][bin] = 0.0f; + } + hMasaIsmData->preprocEneTarget[bin] = 0.0f; + hMasaIsmData->preprocEneRealized[bin] = 0.0f; + } + + hMasaIsmData->objectsMoved = 0; + hMasaIsmData->delayBuffer = NULL; + st_ivas->hMasaIsmData = hMasaIsmData; + + return IVAS_ERR_OK; +} + + +#ifdef OMASA_BRATE_SW +/*-------------------------------------------------------------------* + * ivas_masa_ism_data_close() + * + * Deallocate MASA_ISM rendering handle + *-------------------------------------------------------------------*/ + +void ivas_masa_ism_data_close( + MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ +) +{ + int16_t i; + + if ( hMasaIsmData == NULL || *hMasaIsmData == NULL ) + { + return; + } + + if ( ( *hMasaIsmData )->delayBuffer != NULL ) + { + for ( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) + { + free( ( *hMasaIsmData )->delayBuffer[i] ); + } + free( ( *hMasaIsmData )->delayBuffer ); + ( *hMasaIsmData )->delayBuffer = NULL; + } + + free( *hMasaIsmData ); + *hMasaIsmData = NULL; + + return; +} +#endif +#endif + + +#ifdef OMASA_BRATE_SW +/*--------------------------------------------------------------------------* + * ivas_omasa_dec_config() + * + * oMASA decoder configuration + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_dec_config( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t k, n, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; + int32_t ivas_total_brate, ism_total_brate, cpe_brate; + IVAS_FORMAT ivas_format_old; + ISM_MODE ism_mode_old; + ivas_error error; + + /* initializations */ + error = IVAS_ERR_OK; + ism_total_brate = 0; + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + + /* save previous frame parameters */ + ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ism_mode_old; + + ivas_format_old = st_ivas->ivas_format; + if ( ism_mode_old == ISM_MASA_MODE_PARAM || ism_mode_old == ISM_MASA_MODE_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_DISC ) + { + st_ivas->ivas_format = MASA_ISM_FORMAT; + } + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + nSCE_old = st_ivas->nSCE; + nchan_hp20_old = getNumChanSynthesis( st_ivas ); + + /* reconstruct parameters */ + st_ivas->ivas_format = ivas_format_old; + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + st_ivas->nchan_ism = 0; + } + + /* set ism_mode of current frame */ + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + + /* MASA reconfig. */ + cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 ) + { + st_ivas->hCPE[0]->nchan_out = 1; + } + else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* OMASA reconfig. */ + if ( st_ivas->hMasaIsmData == NULL && st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( ( error = ivas_masa_ism_data_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ivas_set_omasa_TC( st_ivas->ism_mode, st_ivas->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); + + /* re-configure hp20 memories */ + if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* reconfigure core-coders for ISMs */ + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, -1, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + k = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + } + + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + + if ( ism_mode_old != st_ivas->ism_mode ) + { + /* ISM MD reconfig. */ + n_MD = 0; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + n_MD = 1; + + if ( st_ivas->hIsmMetaData[0] == NULL ) + { + if ( ( error = create_ism_metadata_dec( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n_MD = st_ivas->nchan_ism; + + ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); + + if ( ( error = create_ism_metadata_dec( st_ivas, st_ivas->nchan_ism, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); + + /* CLDFB instances */ + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; + + /* objects renderer reconfig. */ + if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + { + if ( st_ivas->hIsmRendererData == NULL ) + { + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + { + for ( n = 1; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) + { + free( st_ivas->hMasaIsmData->delayBuffer[n] ); + } + + st_ivas->hMasaIsmData->delayBuffer_nchan = 1; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + float tmp[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + + st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; + + mvr2r( st_ivas->hMasaIsmData->delayBuffer[0], tmp, st_ivas->hMasaIsmData->delayBuffer_size ); + free( st_ivas->hMasaIsmData->delayBuffer[0] ); + free( st_ivas->hMasaIsmData->delayBuffer ); + if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + } + + for ( n = 0; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) + { + if ( ( st_ivas->hMasaIsmData->delayBuffer[n] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + } + set_zero( st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); + } + mvr2r( tmp, st_ivas->hMasaIsmData->delayBuffer[0], st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + else if ( st_ivas->ism_mode != ISM_MASA_MODE_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) + { + for ( n = 0; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) + { + free( st_ivas->hMasaIsmData->delayBuffer[n] ); + } + free( st_ivas->hMasaIsmData->delayBuffer ); + st_ivas->hMasaIsmData->delayBuffer = NULL; + + free( st_ivas->hIsmRendererData ); + st_ivas->hIsmRendererData = NULL; + } + } + + return error; +} +#endif + + #ifdef OMASA_BRATE /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_dec() @@ -49,7 +332,7 @@ void ivas_set_surplus_brate_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - int32_t *ism_total_brate /* i/o: ISM total bit-rate */ + int32_t *ism_total_brate /* i/o: ISM total bitrate */ ) { int16_t n, bits_ism, bits_element[MAX_NUM_OBJECTS]; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 20d03915c2..45257627a8 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -880,7 +880,11 @@ ivas_error stereo_memory_dec( * Bitrate switching in MASA format *---------------------------------------------------------------*/ +#ifdef OMASA_BRATE_SW + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && nchan_transport == 2 ) +#else if ( ivas_format == MASA_FORMAT && nchan_transport == 2 ) +#endif { if ( hCPE->nchan_out == 1 ) { diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index e8486d7738..27c855ec6f 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -230,7 +230,7 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[0]->hStereoMdct = NULL; } - /* create missing core coder elements and set element bitrates for alrady existing ones */ + /* create missing core coder elements and set element bitrates for already existing ones */ if ( st_ivas->nSCE > 0 ) { nSCE_existing = min( nSCE_old, st_ivas->nSCE ); @@ -250,7 +250,11 @@ ivas_error ivas_corecoder_enc_reconfig( } /* propagate input audio buffers */ +#ifdef OMASA_BRATE_SW + if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) +#else if ( n_CoreCoder_existing > sce_id ) +#endif { mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory ); } @@ -259,7 +263,11 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ +#ifdef OMASA_BRATE_SW + if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) +#else if ( sce_id > 0 ) +#endif { reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); } @@ -289,7 +297,13 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; +#ifdef OMASA_BRATE_SW + if ( ( cpe_id * CPE_CHANNELS + n > 0 ) || + ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) || + ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) ) +#else if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ) +#endif { reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, MAX_NUM_INDICES ); } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index cf69b1e333..ab4567ad6f 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -268,7 +268,11 @@ ivas_error ivas_cpe_enc( if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || - sts[0]->ini_frame == 0 || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ + sts[0]->ini_frame == 0 || +#ifdef OMASA_BRATE_SW + ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || +#endif + sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ { if ( st_ivas->hQMetaData != NULL ) { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a3adbda9b6..fef6c63211 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -300,7 +300,14 @@ ivas_error ivas_enc( float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; +#ifdef OMASA_BRATE_SW + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else ivas_masa_enc_reconfigure( st_ivas ); +#endif hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; @@ -315,6 +322,9 @@ ivas_error ivas_enc( set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); #ifdef OMASA_BRATE +#ifdef OMASA_BRATE_SW + idx_separated_object = 0; +#else /* Configure MASA encoder based on frame parameters */ if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -332,6 +342,7 @@ ivas_error ivas_enc( #endif ); } +#endif /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 43c498bcd0..88a782ccbe 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -958,11 +958,13 @@ ivas_error create_ism_metadata_enc( { int16_t ch, nchan_transport; - // VE: this part of the code is better to be moved to a separate function, e.g. ivas_set_omasa_TC() #ifdef MASA_AND_OBJECTS nchan_transport = st_ivas->nchan_transport; if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { +#ifdef OMASA_BRATE_SW + ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#else switch ( st_ivas->ism_mode ) { case ISM_MASA_MODE_PARAM: @@ -985,6 +987,7 @@ ivas_error create_ism_metadata_enc( default: break; } +#endif } else { @@ -1041,12 +1044,13 @@ ivas_error create_ism_metadata_enc( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } + #ifdef MASA_AND_OBJECTS if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { - ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ); + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ); // VE: nchan_transport ????? } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index f31badf9b3..ac8380a503 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -707,6 +707,7 @@ ivas_error ivas_masa_enc_config( } } #endif + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE #ifdef MASA_AND_OBJECTS @@ -714,6 +715,7 @@ ivas_error ivas_masa_enc_config( ivas_format, st_ivas->ism_mode, ism_total_brate #endif ); + hQMetaData->is_masa_ivas_format = 1; #ifdef MASA_AND_OBJECTS @@ -747,6 +749,7 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS } #endif + /* Setup importance weights for two-direction band selection. */ if ( hMasa->config.numberOfDirections == 2 ) { @@ -1977,6 +1980,7 @@ void ivas_masa_enc_reconfigure( #endif ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; + #ifdef MASA_AND_OBJECTS ism_total_brate = 0; if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) @@ -1987,6 +1991,7 @@ void ivas_masa_enc_reconfigure( } } #endif + if ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) @@ -2043,6 +2048,7 @@ void ivas_masa_enc_reconfigure( return; } + #ifdef MASA_AND_OBJECTS #ifdef OMASA_DIFFUSE_ISM_MERGE /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index b7fe8ee27e..e739410ffb 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -230,6 +230,123 @@ void ivas_omasa_enc_close( } +#ifdef OMASA_BRATE_SW +/*--------------------------------------------------------------------------* + * ivas_omasa_enc_config() + * + * oMASA encoder configuration + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_enc_config( + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +) +{ + int16_t k, sce_id, nSCE_old; + int32_t ivas_total_brate, ism_total_brate; + ISM_MODE ism_mode_old; + ENCODER_CONFIG_HANDLE hEncoderConfig; + ivas_error error; + + error = IVAS_ERR_OK; + hEncoderConfig = st_ivas->hEncoderConfig; + ivas_total_brate = hEncoderConfig->ivas_total_brate; + + + //ivas_masa_enc_reconfigure( st_ivas ); // VE: might not be needed + + + ism_mode_old = st_ivas->ism_mode; + nSCE_old = st_ivas->nSCE; + + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); + st_ivas->nchan_transport = 2; + + /* reconfiguration in case of bitrate switching */ + if ( hEncoderConfig->last_ivas_total_brate != ivas_total_brate ) + { + ivas_set_omasa_TC( st_ivas->ism_mode, hEncoderConfig->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); + + k = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) + { + k++; + } + + ism_total_brate = 0; + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) // VE!!!!! + { + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, 1, NULL, NULL, NULL, NULL, NULL, NULL, 1 ); + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nSCE, NULL, NULL, NULL, NULL, NULL, NULL, 1 ); + } + + /* reconfigure core-coders for ISMs */ + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, 1, 2, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ + if ( st_ivas->nSCE > 0 ) + { + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->next_ind ); + } + else + { + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->next_ind ); + } + + ivas_write_format( st_ivas ); + + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hOMasa == NULL ) + { + if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hOMasa != NULL ) + { + ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); + st_ivas->hOMasa = NULL; + } + + st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; + + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + { + hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; + } + else + { + hEncoderConfig->element_mode_init = IVAS_CPE_DFT; + } + } + + /* Configure MASA encoder based on frame parameters */ + if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + /* Configure oMASA analysis based on MASA config */ + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); + } + + return error; +} +#endif + + /*--------------------------------------------------------------------------* * ivas_omasa_set_config() * @@ -242,7 +359,7 @@ void ivas_omasa_set_config( const int32_t input_Fs /* i : Input sample rate */ #ifdef OMASA_DIFFUSE_ISM_MERGE , - ISM_MODE ismMode /* i : ISM mode */ + const ISM_MODE ismMode /* i : ISM mode */ #endif ) { @@ -673,7 +790,7 @@ void ivas_set_surplus_brate_enc( 0 #endif ); - /* note: ISM st->total_brate is iset in ivas_sce_enc() */ + /* note: ISM st->total_brate is set in ivas_sce_enc() */ } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 72ac9311c5..89bff9f74a 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1038,8 +1038,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric { #ifdef MASA_AND_OBJECTS float spectrumModVal; + + idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ - spectrumModVal = ( 1.0f - surCoh ) + surCoh * surCohEne[min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 )]; + spectrumModVal = ( 1.0f - surCoh ) + surCoh * surCohEne[idx]; diffEne *= spectrumModVal; #else idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); -- GitLab From 76a671d8df432d6f0b8ed707e6109c412746f337 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 27 Mar 2023 19:58:20 +0200 Subject: [PATCH 050/173] simplify ivas_ism_metadata_enc() --- lib_com/ivas_prot.h | 4 -- lib_enc/ivas_ism_enc.c | 53 ++++++++++++--------- lib_enc/ivas_ism_metadata_enc.c | 84 ++++++++++----------------------- 3 files changed, 55 insertions(+), 86 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 6eb61455e3..020f685d86 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -839,13 +839,9 @@ ivas_error ivas_ism_metadata_enc( #else const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Config Handle */ #endif -#ifdef MASA_AND_OBJECTS - , - const int16_t n_ism /* i : number of objects */ #ifdef OMASA_BRATE ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ #endif -#endif ); ivas_error ivas_ism_metadata_dec( diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index f7e5c8e04b..4d0943b76f 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -89,7 +89,7 @@ ivas_error ivas_ism_enc( int16_t dtx_flag, sid_flag; ivas_error error; #ifdef MASA_AND_OBJECTS - int16_t n; + int16_t nchan_transport; #endif push_wmops( "ivas_ism_enc" ); @@ -102,13 +102,21 @@ ivas_error ivas_ism_enc( dtx_flag = 0; sid_flag = 0; +#ifdef MASA_AND_OBJECTS + nchan_transport = st_ivas->nchan_transport; + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + nchan_transport = st_ivas->hEncoderConfig->nchan_ism; + } +#endif + /*------------------------------------------------------------------* * Preprocesing *-----------------------------------------------------------------*/ /* in ISM format: st_ivas->nchan_transport = st_ivas->nSCE */ #ifdef MASA_AND_OBJECTS - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) #else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) #endif @@ -223,16 +231,16 @@ ivas_error ivas_ism_enc( #else st_ivas->hEncoderConfig->ivas_total_brate, #endif - st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag #ifdef MASA_AND_OBJECTS - , - st_ivas->nSCE + nchan_transport, +#else + st_ivas->nchan_transport, +#endif + st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag #ifdef OMASA_BRATE , -1 #endif -#endif - ) ) != IVAS_ERR_OK ) { return error; @@ -244,7 +252,13 @@ ivas_error ivas_ism_enc( #else st_ivas->hEncoderConfig->ivas_total_brate, #endif - st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm +#ifdef MASA_AND_OBJECTS + nchan_transport, +#else + st_ivas->nchan_transport, +#endif + + st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm #ifdef MASA_AND_OBJECTS , st_ivas->nSCE @@ -284,11 +298,11 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; // VE: change the interface of the following function and call it with 'st_ivas' only - if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, + if ( ( error = ivas_ism_metadata_enc( &ism_total_brate, nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, #ifdef TD5 st_ivas->hEncoderConfig->ism_extended_metadata_flag, #endif - st_ivas->nSCE, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ) ) != IVAS_ERR_OK ) + st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ) ) != IVAS_ERR_OK ) { return error; } @@ -298,7 +312,7 @@ ivas_error ivas_ism_enc( st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate; } #else - if ( ( error = ivas_ism_metadata_enc( ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE, + if ( ( error = ivas_ism_metadata_enc( ism_total_brate, nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, #ifdef TD5 , st_ivas->hEncoderConfig->ism_extended_metadata_flag #endif @@ -313,7 +327,6 @@ ivas_error ivas_ism_enc( , st_ivas->hEncoderConfig->ism_extended_metadata_flag #endif - ) ) != IVAS_ERR_OK ) { return error; @@ -347,17 +360,9 @@ ivas_error ivas_ism_enc( /*------------------------------------------------------------------* * CoreCoders encoding *-----------------------------------------------------------------*/ -#ifdef MASA_AND_OBJECTS - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - n = st_ivas->nSCE; - } - else - { - n = st_ivas->nchan_transport; - } - for ( sce_id = 0; sce_id < n; sce_id++ ) +#ifdef MASA_AND_OBJECTS + for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) #else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) #endif @@ -416,7 +421,11 @@ ivas_error ivas_ism_enc( if ( dtx_flag ) { +#ifdef MASA_AND_OBJECTS + for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) +#else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) +#endif { if ( sce_id != st_ivas->hISMDTX->sce_id_dtx ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index f4138e1b56..72c933c595 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -194,14 +194,10 @@ ivas_error ivas_ism_metadata_enc( #else const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ #endif -#ifdef MASA_AND_OBJECTS - , - const int16_t n_ism /* i : number of objects */ #ifdef OMASA_BRATE , const float lp_noise_CPE #endif -#endif ) { #ifdef TD5 @@ -226,9 +222,7 @@ ivas_error ivas_ism_metadata_enc( int16_t ism_imp[MAX_NUM_OBJECTS]; int16_t num_obj, nbands, nblocks; ivas_error error; -#ifdef MASA_AND_OBJECTS - int16_t n_ch; -#endif + error = IVAS_ERR_OK; push_wmops( "ism_meta_enc" ); @@ -244,7 +238,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS else if ( ism_mode == ISM_MASA_MODE_DISC ) { - num_obj = n_ism; + num_obj = nchan_transport; } #endif else @@ -275,22 +269,13 @@ ivas_error ivas_ism_metadata_enc( #endif #ifdef OMASA_BRATE - if ( ism_mode == ISM_MASA_MODE_DISC ) - { - n_ch = num_obj; - } - else - { - n_ch = nchan_transport; - } - if ( ism_mode == ISM_MASA_MODE_DISC ) { /*----------------------------------------------------------------* * Rate importance of particular ISM streams in combined format coding *----------------------------------------------------------------*/ - set_ism_importance_interformat( *ism_total_brate, n_ch, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); } else #endif @@ -366,53 +351,40 @@ ivas_error ivas_ism_metadata_enc( #endif } } - } - /*----------------------------------------------------------------* - * Rate importance of particular ISM streams - *----------------------------------------------------------------*/ -#ifdef MASA_AND_OBJECTS - if ( ism_mode == ISM_MASA_MODE_DISC ) - { - n_ch = num_obj; - } - else - { - n_ch = nchan_transport; - } - - rate_ism_importance( n_ch, hIsmMeta, hSCE, ism_imp ); + /*----------------------------------------------------------------* + * Rate importance of particular ISM streams + *----------------------------------------------------------------*/ -#else - rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); -#endif + rate_ism_importance( nchan_transport, hIsmMeta, hSCE, ism_imp ); #ifndef TUNE_360_OBJECT_WITH_NOISE - /* relax the importance decision in "stereo" coding for noisy audio */ + /* relax the importance decision in "stereo" coding for noisy audio */ #ifdef MASA_AND_OBJECTS - if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && num_obj == 2 ) + if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && num_obj == 2 ) #else - if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) + if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) #endif - { - float diff_F; - - if ( hIsmMeta[0]->ism_metadata_flag ^ hIsmMeta[1]->ism_metadata_flag ) { - for ( ch = 0; ch < num_obj; ch++ ) - { - diff_F = hSCE[ch]->hCoreCoder[0]->lp_speech - hSCE[ch]->hCoreCoder[0]->lp_noise; + float diff_F; - if ( hIsmMeta[ch]->ism_metadata_flag == 0 && diff_F < 25.0f ) + if ( hIsmMeta[0]->ism_metadata_flag ^ hIsmMeta[1]->ism_metadata_flag ) + { + for ( ch = 0; ch < num_obj; ch++ ) { - hIsmMeta[ch]->ism_metadata_flag = 1; - ism_imp[ch] = ISM_LOW_IMP; + diff_F = hSCE[ch]->hCoreCoder[0]->lp_speech - hSCE[ch]->hCoreCoder[0]->lp_noise; + + if ( hIsmMeta[ch]->ism_metadata_flag == 0 && diff_F < 25.0f ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + ism_imp[ch] = ISM_LOW_IMP; + } } } } - } #endif + } /*----------------------------------------------------------------* * Write ISM common signaling @@ -433,7 +405,7 @@ ivas_error ivas_ism_metadata_enc( #endif #ifdef TD5 -/* write extended metadata presence flag */ + /* write extended metadata presence flag */ #ifdef OMASA_BRATE #ifdef FIX_TD5_IN_OMASA if ( ism_mode == ISM_MODE_DISC && *ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) @@ -449,11 +421,7 @@ ivas_error ivas_ism_metadata_enc( #endif /* write ISM metadata flag (one per object) */ -#ifdef MASA_AND_OBJECTS - for ( ch = 0; ch < n_ch; ch++ ) -#else for ( ch = 0; ch < nchan_transport; ch++ ) -#endif { #ifdef OMASA_BRATE if ( ism_mode == ISM_MASA_MODE_DISC ) @@ -481,11 +449,7 @@ ivas_error ivas_ism_metadata_enc( #endif { /* write VAD flag */ -#ifdef MASA_AND_OBJECTS - for ( ch = 0; ch < n_ch; ch++ ) -#else for ( ch = 0; ch < nchan_transport; ch++ ) -#endif { #ifdef OMASA_BRATE if ( ism_mode == ISM_MASA_MODE_DISC ) @@ -1039,7 +1003,7 @@ ivas_error ivas_ism_metadata_enc( } #ifdef MASA_AND_OBJECTS - for ( ch = 0; ch < n_ch; ch++ ) + for ( ch = 0; ch < nchan_transport; ch++ ) { #ifdef OMASA_BRATE hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; -- GitLab From 57f8d915239a52280a6b2ce400e19bb0667bfa79 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 27 Mar 2023 20:25:34 +0200 Subject: [PATCH 051/173] addition of OMASA_BRATE_SW - solves MSAN error in OMASA bitrate switching --- lib_enc/ivas_init_enc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 89820ff179..bd333e20ea 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -610,6 +610,13 @@ ivas_error ivas_init_encoder( return error; } +#ifdef OMASA_BRATE_SW + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_f( st_ivas->hQMetaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); + } +#endif + if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; -- GitLab From cd76cbd5285f891b99bed2274453b287a25135aa Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Tue, 28 Mar 2023 10:11:43 +0300 Subject: [PATCH 052/173] Updates to OMASA coding and processing addressing quality issues at 48k and 128k 3-4 objects --- lib_com/bitstream.c | 4 + lib_com/ivas_cnst.h | 13 +- lib_com/ivas_ism_config.c | 22 +- lib_com/ivas_masa_com.c | 15 +- lib_com/ivas_omasa_com.c | 107 +++- lib_com/ivas_prot.h | 34 +- lib_com/ivas_rom_com.c | 40 +- lib_com/ivas_rom_com.h | 1 + lib_com/ivas_stat_com.h | 8 +- lib_com/options.h | 12 +- lib_dec/ivas_core_dec.c | 2 +- lib_dec/ivas_cpe_dec.c | 39 +- lib_dec/ivas_dec.c | 88 ++- lib_dec/ivas_dirac_dec.c | 4 + lib_dec/ivas_init_dec.c | 50 +- lib_dec/ivas_ism_metadata_dec.c | 64 +- lib_dec/ivas_ism_renderer.c | 8 + lib_dec/ivas_masa_dec.c | 406 +++++-------- lib_dec/ivas_mono_dmx_renderer.c | 4 + lib_dec/ivas_omasa_dec.c | 26 +- lib_dec/ivas_qmetadata_dec.c | 5 + lib_dec/ivas_sce_dec.c | 24 +- lib_dec/ivas_stat_dec.h | 6 +- lib_dec/ivas_stereo_switching_dec.c | 2 +- lib_dec/ivas_stereo_td_dec.c | 20 +- lib_enc/ivas_core_enc.c | 6 +- lib_enc/ivas_cpe_enc.c | 48 +- lib_enc/ivas_decision_matrix_enc.c | 5 +- lib_enc/ivas_enc.c | 90 +-- lib_enc/ivas_init_enc.c | 7 +- lib_enc/ivas_ism_enc.c | 19 +- lib_enc/ivas_ism_metadata_enc.c | 133 ++++- lib_enc/ivas_masa_enc.c | 598 ++++--------------- lib_enc/ivas_omasa_enc.c | 137 ++++- lib_enc/ivas_qmetadata_enc.c | 10 + lib_enc/ivas_sce_enc.c | 25 +- lib_enc/ivas_stat_enc.h | 4 +- lib_enc/ivas_stereo_classifier.c | 5 +- lib_enc/ivas_stereo_mdct_core_enc.c | 2 +- lib_enc/ivas_stereo_td_enc.c | 4 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 34 ++ lib_rend/ivas_objectRenderer.c | 12 + 42 files changed, 1056 insertions(+), 1087 deletions(-) mode change 100755 => 100644 lib_com/options.h diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 71d7016f12..6cd20c8831 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1984,7 +1984,11 @@ ivas_error preview_indices( { st_ivas->ism_mode = ivas_omasa_ism_mode_select( total_brate, st_ivas->nchan_ism ); +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { st_ivas->nchan_transport = 0; } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 33de8aa6f4..2474eee778 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -307,7 +307,7 @@ typedef enum #define ISM_METADATA_VAD_FLAG_BITS 1 #define ISM_METADATA_FLAG_BITS 2 -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS #define ISM_INACTIVE_IMP 0 /* == ISM_NO_META */ #endif #define ISM_NO_META 0 @@ -315,7 +315,7 @@ typedef enum #define ISM_MEDIUM_IMP 2 #define ISM_HIGH_IMP 3 -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS #define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM no meta / inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) #endif @@ -361,7 +361,12 @@ typedef enum #ifdef MASA_AND_OBJECTS , ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ +#ifdef OMASA_UPDATES + ISM_MASA_MODE_MASA_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using MASA parameters */ + ISM_MASA_MODE_PARAM_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using parametric object model */ +#else ISM_MASA_MODE_ONE_OBJ, /* MASA ISM mode when one object is encoded separarately */ +#endif ISM_MASA_MODE_DISC /* MASA ISM mode when all objects are encoded separarately */ #endif } ISM_MODE; @@ -624,7 +629,11 @@ enum IND_STEREO_DFT_SIDEGAIN_FLAG, IND_STEREO_DFT_SIDEGAINS, + #ifdef OMASA_UPDATES + IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 120, + #else IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 72, + #endif IND_STEREO_DFT_ITD_HUFF, IND_STEREO_DFT_ITD_NEG, diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 06ccd94a31..8a0621509c 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -50,7 +50,7 @@ #define FRMS_PER_SECOND ( 1000000000 / FRAME_SIZE_NS ) -#ifndef OMASA_BRATE +#ifndef MASA_AND_OBJECTS #define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISm inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRMS_PER_SECOND ) #endif @@ -65,7 +65,7 @@ * Convert bit-budget to bitrate *-------------------------------------------------------------------*/ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS void bitbudget_to_brate( #else static void bitbudget_to_brate( @@ -142,7 +142,7 @@ ivas_error ivas_ism_config( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* decision about bitrates per channel */ if ( combined_format_flag ) { @@ -185,17 +185,7 @@ ivas_error ivas_ism_config( /* count ISm common signaling bits */ if ( hIsmMeta != NULL ) { -#ifdef MASA_AND_OBJECTS - nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS; - if ( combined_format_flag == 0 ) - { - /* the bits for writing the number of objects are counted here for pure ISM modes */ - nb_bits_metadata[0] += num_obj; - } -#else nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + num_obj; -#endif - for ( ch = 0; ch < n_ISms; ch++ ) { if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) @@ -362,7 +352,7 @@ ivas_error ivas_ism_config( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS if ( combined_format_flag == 1 ) { if ( diff > 0 ) @@ -390,12 +380,13 @@ ivas_error ivas_ism_config( bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms ); } + #ifdef DEBUGGING if ( nb_bits_metadata != NULL ) { int32_t tmpL; tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRMS_PER_SECOND; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS if ( ism_total_brate != tmpL ) #else if ( sum_l( element_brate, n_ISms ) != tmpL ) @@ -403,6 +394,7 @@ ivas_error ivas_ism_config( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISm bit-budget distribution. Exiting!\n" ); } + } #endif diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index c3082f53e1..d5aa835e8d 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -96,7 +96,11 @@ void ivas_masa_set_elements( if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO ) { *element_mode = IVAS_CPE_MDCT; +#ifdef OMASA_UPDATES + if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) ) +#else if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) ) +#endif { *element_mode = IVAS_CPE_DFT; } @@ -115,7 +119,11 @@ void ivas_masa_set_elements( } hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ); #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); } @@ -494,12 +502,11 @@ void reconstruct_ism_ratios( } q_energy_ratio_ism[nchan_ism - 1] = 1.0f - sum; -#ifdef REDUCE_OMASA_META_BITS + if ( q_energy_ratio_ism[nchan_ism - 1] < 0 ) { q_energy_ratio_ism[nchan_ism - 1] = 0.0f; } -#endif return; } @@ -605,7 +612,11 @@ int32_t calculate_cpe_brate_MASA_ISM( k++; } +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { cpe_brate = ivas_total_brate - sep_object_brate[k - 2][0]; /* take data from the first column */ } diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index e248cc5a9d..175bf22195 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -35,16 +35,13 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" -#ifdef REDUCE_OMASA_META_BITS #include "ivas_rom_com.h" #include -#endif #ifdef DEBUGGING #include "debug.h" #endif #ifdef MASA_AND_OBJECTS -#ifdef OMASA_BRATE /*--------------------------------------------------------------- * Local constants *---------------------------------------------------------------*/ @@ -61,8 +58,7 @@ #define GAMMA_ISM_MEDIUM_IMP3 1.15f #define GAMMA_ISM_HIGH_IMP3 1.3f -#ifdef TUNING_DISC_3_4obj -#ifdef FIX_4OBJ_128 +#ifdef OMASA_UPDATES #define GAMMA_ISM_LOW_IMP4 0.8f #define GAMMA_ISM_MEDIUM_IMP4 1.0f #define GAMMA_ISM_HIGH_IMP4 1.2f @@ -71,8 +67,8 @@ #define GAMMA_ISM_MEDIUM_IMP4 0.8f #define GAMMA_ISM_HIGH_IMP4 1.0f #endif -#endif -#endif + + /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() @@ -108,7 +104,11 @@ ISM_MODE ivas_omasa_ism_mode_select( } else if ( ivas_total_brate >= IVAS_32k ) { +#ifdef OMASA_UPDATES + ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; +#else ism_mode = ISM_MASA_MODE_ONE_OBJ; +#endif } else { @@ -116,36 +116,49 @@ ISM_MODE ivas_omasa_ism_mode_select( } break; case 3: -#ifdef TUNING_DISC_3_4obj if ( ivas_total_brate >= IVAS_96k ) -#else - if ( ivas_total_brate >= IVAS_128k ) -#endif { ism_mode = ISM_MASA_MODE_DISC; } else if ( ivas_total_brate >= IVAS_64k ) { +#ifdef OMASA_UPDATES + ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; +#else ism_mode = ISM_MASA_MODE_ONE_OBJ; +#endif + } +#ifdef OMASA_UPDATES + else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; } +#else else if ( ivas_total_brate >= IVAS_48k ) { ism_mode = ISM_MASA_MODE_PARAM; } +#endif else { ism_mode = ISM_MODE_NONE; } break; case 4: -#ifdef TUNING_DISC_3_4obj if ( ivas_total_brate >= IVAS_128k ) -#else - if ( ivas_total_brate >= IVAS_160k ) -#endif { ism_mode = ISM_MASA_MODE_DISC; } +#ifdef OMASA_UPDATES + else if ( ivas_total_brate >= IVAS_64k ) + { + ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; + } + else if ( ivas_total_brate >= IVAS_32k ) + { + ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; + } +#else else if ( ivas_total_brate >= IVAS_64k ) { ism_mode = ISM_MASA_MODE_ONE_OBJ; @@ -154,6 +167,7 @@ ISM_MODE ivas_omasa_ism_mode_select( { ism_mode = ISM_MASA_MODE_PARAM; } +#endif else { ism_mode = ISM_MODE_NONE; @@ -165,7 +179,7 @@ ISM_MODE ivas_omasa_ism_mode_select( } -#ifdef OMASA_BRATE + /*--------------------------------------------------------------- * ivas_interformat_brate() * @@ -178,7 +192,7 @@ int32_t ivas_interformat_brate( const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ -#ifdef FIX_4OBJ_128 +#ifdef OMASA_UPDATES , const int16_t limit_flag /* i : flag to limit the bitrate increase */ #endif @@ -195,17 +209,16 @@ int32_t ivas_interformat_brate( } else { -#ifdef TUNING_DISC_3_4obj - if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) ) ) /* this condition corresponds to the ivas_total_brate = 96000 and 3 objects */ + if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) + || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */ { -#ifdef FIX_4OBJ_128 - if ( limit_flag && ( nchan_ism == 4 && element_brate == 24000 ) ) +#ifdef OMASA_UPDATES + if ( (limit_flag == 1) && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) { return element_brate; } #endif - if ( ism_imp == ISM_LOW_IMP ) { nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); @@ -213,15 +226,26 @@ int32_t ivas_interformat_brate( else if ( ism_imp == ISM_MEDIUM_IMP ) { nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 ); + if ( limit_flag == -1 ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 ); + } } else /* ISM_HIGH_IMP */ { nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 ); + if ( limit_flag == -1 ) + { + nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 ); + } } } else -#endif +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || +#else if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || +#endif ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ ) { @@ -319,9 +343,8 @@ void ivas_combined_format_brate_sanity( return; } -#endif -#ifdef REDUCE_OMASA_META_BITS + /*--------------------------------------------------------------- * bits_index_ism_ratio() * @@ -414,7 +437,7 @@ void calculate_nbits_meta( priority[obj] = max_p; } } - bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 7 ); + bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 6 ); } return; @@ -463,5 +486,35 @@ void ivas_get_stereo_panning_gains( return; } + +int16_t calculate_brate_limit_flag(int16_t * ism_imp, int16_t num_obj) +{ + int16_t n; + int16_t brate_limit_flag; + int16_t nzeros; + + brate_limit_flag = 0; + nzeros = 0; + for ( n = 0; n < num_obj; n++ ) + { + brate_limit_flag += ism_imp[n]; + if ( ism_imp[n] == 0 ) + { + nzeros++; + } + } + if ( brate_limit_flag >= (int16_t) ( num_obj * 2.5f ) ) + { + brate_limit_flag = 1; + } + else + { + if ( nzeros / (float) num_obj >= 0.5f ) + { + brate_limit_flag = -1; /* there is no limitation, on the contrary */ + } + } + return brate_limit_flag; +} #endif -#endif + diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b20eb35e3b..750e5fc85c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -765,7 +765,7 @@ ivas_error ivas_ism_config( #endif ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS void bitbudget_to_brate( const int16_t x[], /* i : bitbudgets */ int32_t y[], /* o : bitrates */ @@ -822,7 +822,7 @@ ivas_error ivas_ism_enc( ); ivas_error ivas_ism_metadata_enc( -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int32_t *ism_total_brate, /* i/o: ISms total bitrate */ #else const int32_t ism_total_brate, /* i : ISms total bitrate */ @@ -838,7 +838,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS , const int16_t n_ism /* i : number of objects */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ #endif #endif @@ -4471,12 +4471,9 @@ void ivas_masa_encode( const int16_t nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ - OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ -#ifdef REDUCE_OMASA_META_BITS - , + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ int16_t ism_imp /* i: importance of separated object */ #endif -#endif ); void ivas_masa_estimate_energy( @@ -4552,7 +4549,7 @@ int32_t calculate_cpe_brate_MASA_ISM( const int16_t nchan_ism /* i : number of objects */ ); -#ifdef OMASA_DIFFUSE_ISM_MERGE + void ivas_merge_masa_metadata( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ @@ -4561,9 +4558,7 @@ void ivas_merge_masa_metadata( void ivas_masa_combine_directions( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ ); -#endif /* OMASA_DIFFUSE_ISM_MERGE */ -#ifdef REDUCE_OMASA_META_BITS /*!r : number of bits for ISM ratio index */ int16_t bits_index_ism_ratio( const int16_t nchan_ism /* i : number of objects */ @@ -4579,7 +4574,11 @@ void calculate_nbits_meta( const int16_t idx_sep_obj, const int16_t ism_imp ); -#endif + +int16_t calculate_brate_limit_flag( + int16_t * ism_imp, + int16_t num_obj +); void ivas_get_stereo_panning_gains( const float aziDeg, @@ -5027,18 +5026,12 @@ void ivas_omasa_enc_close( void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ - const int32_t input_Fs /* i : Input sample rate */ -#ifdef OMASA_DIFFUSE_ISM_MERGE - , + const int32_t input_Fs, /* i : Input sample rate */ ISM_MODE ismMode /* i : ISM mode */ -#endif ); void ivas_omasa_enc( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ -#ifndef OMASA_DIFFUSE_ISM_MERGE - IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ -#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ @@ -5050,7 +5043,6 @@ void ivas_omasa_enc( int16_t* idx_separated_object /* o : Index of the separated object */ ); -#ifdef OMASA_BRATE void ivas_set_surplus_brate_enc( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ #ifdef DEBUG_MODE_INFO @@ -5079,7 +5071,7 @@ int32_t ivas_interformat_brate( const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ const int16_t ism_imp /* i : ISM importance flag */ -#ifdef FIX_4OBJ_128 +#ifdef OMASA_UPDATES , const int16_t limit_flag /* i : flag to limit the bitrate increase */ #endif ); @@ -5090,7 +5082,7 @@ void ivas_combined_format_brate_sanity( int32_t *core_brate, /* i/o: core bitrate */ int16_t *diff_nBits /* o : number of differential bits */ ); -#endif + ISM_MODE ivas_omasa_ism_mode_select( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 66db7666f2..2f4d9367f3 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2789,29 +2789,13 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = {0, 0, 0, 0}, /* 13k2 */ {0, 0, 0, 0}, /* 16k4 */ {9600, 0, 0, 0}, /* 24k4 */ -#ifdef OMASA_BRATE - {11000, 0, 0, 0}, /* 32k */ -#else - {9600, 0, 0, 0}, /* 32k */ -#endif - {IVAS_13k2, 9600, 0, 0}, /* 48k */ -#ifdef OMASA_BRATE + {IVAS_13k2, 0, 0, 0}, /* 32k */ + {16000, 11000, 0, 0}, /* 48k */ {16000, 11700, 0, 0}, /* 64k */ -#else - {16000, IVAS_13k2, 0, 0}, /* 64k */ -#endif {20000, 16000, 0, 0}, /* 80k */ -#ifdef TUNING_DISC_3_4obj {IVAS_32k, 20000, 20000, 0}, /* 96k */ -#else - {IVAS_32k, 20000, 0, 0}, /* 96k */ -#endif -#ifdef TUNING_DISC_3_4obj - {IVAS_32k, IVAS_24k4, 20000, 24000}, /* 128k */ -#else - {IVAS_32k, IVAS_24k4, 20000, 16000}, /* 128k */ -#endif - {IVAS_48k, IVAS_32k, IVAS_24k4, 20000}, /* 160k */ + {IVAS_32k, IVAS_24k4, 24000, 24000}, /* 128k */ + {IVAS_48k, IVAS_32k, IVAS_24k4, 24000}, /* 160k */ {IVAS_64k, IVAS_48k, IVAS_32k, IVAS_24k4}, /* 192k */ {IVAS_96k, IVAS_64k, IVAS_48k, IVAS_32k}, /* 256k */ {IVAS_128k, IVAS_80k, IVAS_64k, IVAS_48k}, /* 384k */ @@ -2847,6 +2831,22 @@ const float dct8[8*8] = 0.3536f, -0.4157f, 0.1913f, 0.0975f, -0.3536f, 0.4904f, -0.4619f, 0.2778f, 0.3536f, -0.4904f, 0.4619f, -0.4157f, 0.3536f, -0.2778f, 0.1913f, -0.0975f }; + +const float dct12[12*12]= +{ + 0.2887f, 0.4048f, 0.3943f, 0.3772f, 0.3536f, 0.3239f, 0.2887f, 0.2485f, 0.2041f, 0.1562f, 0.1057f, 0.0533f, + 0.2887f, 0.3772f, 0.2887f, 0.1562f, 0.0000f, -0.1562f, -0.2887f, -0.3772f, -0.4082f, -0.3772f, -0.2887f, -0.1562f, + 0.2887f, 0.3239f, 0.1057f, -0.1562f, -0.3536f, -0.4048f, -0.2887f, -0.0533f, 0.2041f, 0.3772f, 0.3943f, 0.2485f, + 0.2887f, 0.2485f, -0.1057f, -0.3772f, -0.3536f, -0.0533f, 0.2887f, 0.4048f, 0.2041f, -0.1562f, -0.3943f, -0.3239f, + 0.2887f, 0.1562f, -0.2887f, -0.3772f, -0.0000f, 0.3772f, 0.2887f, -0.1562f, -0.4082f, -0.1562f, 0.2887f, 0.3772f, + 0.2887f, 0.0533f, -0.3943f, -0.1562f, 0.3536f, 0.2485f, -0.2887f, -0.3239f, 0.2041f, 0.3772f, -0.1057f, -0.4048f, + 0.2887f, -0.0533f, -0.3943f, 0.1562f, 0.3536f, -0.2485f, -0.2887f, 0.3239f, 0.2041f, -0.3772f, -0.1057f, 0.4048f, + 0.2887f, -0.1562f, -0.2887f, 0.3772f, 0.0000f, -0.3772f, 0.2887f, 0.1562f, -0.4082f, 0.1562f, 0.2887f, -0.3772f, + 0.2887f, -0.2485f, -0.1057f, 0.3772f, -0.3536f, 0.0533f, 0.2887f, -0.4048f, 0.2041f, 0.1562f, -0.3943f, 0.3239f, + 0.2887f, -0.3239f, 0.1057f, 0.1562f, -0.3536f, 0.4048f, -0.2887f, 0.0533f, 0.2041f, -0.3772f, 0.3943f, -0.2485f, + 0.2887f, -0.3772f, 0.2887f, -0.1562f, -0.0000f, 0.1562f, -0.2887f, 0.3772f, -0.4082f, 0.3772f, -0.2887f, 0.1562f, + 0.2887f, -0.4048f, 0.3943f, -0.3772f, 0.3536f, -0.3239f, 0.2887f, -0.2485f, 0.2041f, -0.1562f, 0.1057f, -0.0533f +}; #endif /*----------------------------------------------------------------------------------* diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index ce66e4e2a4..41101bd9b1 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -319,6 +319,7 @@ extern const int32_t sep_object_brate[][MAX_NUM_OBJECTS]; extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; +extern const float dct12[]; #endif /*----------------------------------------------------------------------------------* diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index c2cda437a2..c7664a9a41 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -58,9 +58,13 @@ 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 */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int16_t ism_imp; /* ISM importance flag */ int16_t ism_vad_flag; +#ifdef OMASA_UPDATES + float q_azimuth_old; + float q_elevation_old; +#endif #endif } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; @@ -420,7 +424,6 @@ typedef struct ivas_masa_common_spatial_meta_struct } MASA_COMMON_SPATIAL_META; #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE typedef struct ivas_omasa_meta_struct { uint8_t num_dirs; @@ -428,7 +431,6 @@ typedef struct ivas_omasa_meta_struct MASA_COMMON_SPATIAL_META common_meta; } OMASA_SPATIAL_META, *OMASA_SPATIAL_META_HANDLE; #endif -#endif typedef struct ivas_masa_metadata_frame_struct { diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index 4a4fefae31..62011c419e --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,18 +169,8 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS -#define OMASA_BRATE /* VA: combined format bit-budget distribution */ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ - - - -#define TUNING_DISC_3_4obj /* Nokia: increase bitrate for objects in DISC mode at 128k 4obj and 96k 3 obj */ -#define REDUCE_OMASA_META_BITS /* Nokia: reduce metadata number of bits and fix directional metadata bit allocation */ -#define OMASA_DIFFUSE_ISM_MERGE /* Nokia: Diffuse-energy retaining merging of ISM and MASA */ - -#define FIX_4OBJ_128 /* VA: fix to 4 ISMs 24 kbps case: when all objects are HIGH_IMP, keep 24 kbps bitrate, otherwise increase the 24 kbps bitrate */ - - +#define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index e494cf4881..37034da4f8 100755 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -269,7 +269,7 @@ ivas_error ivas_core_dec( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------* * Sanity check in combined format coding *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index eab7b7c340..b093d58805 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -233,20 +233,11 @@ ivas_error ivas_cpe_dec( /* read DFT Stereo side info */ nb_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_BRATE cpe_brate = st_ivas->hCPE[0]->element_brate; -#else - cpe_brate = ivas_total_brate; -#endif if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifndef OMASA_BRATE - cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); -#endif sts[1]->bit_stream = sts[0]->bit_stream + cpe_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; -#ifdef OMASA_BRATE sts[1]->bit_stream += hCPE->brate_surplus / FRAMES_PER_SEC; -#endif } else #endif @@ -278,9 +269,13 @@ ivas_error ivas_cpe_dec( /* subtract metadata bitbudget */ sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { sts[0]->total_brate += hCPE->brate_surplus; } @@ -296,7 +291,7 @@ ivas_error ivas_cpe_dec( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif if ( st_ivas->hQMetaData != NULL ) @@ -306,10 +301,14 @@ ivas_error ivas_cpe_dec( } else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* compute bit-rate surplus per channel in combined format coding */ int32_t brate_surplus[CPE_CHANNELS]; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; @@ -341,9 +340,13 @@ ivas_error ivas_cpe_dec( sts[n]->bits_frame_nominal = (int16_t) ( sts[n]->total_brate / FRAMES_PER_SEC ); sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_channels ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); sts[n]->total_brate += brate_surplus[n]; @@ -674,7 +677,11 @@ ivas_error create_cpe_dec( } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { cpe_brate = element_brate; } @@ -699,7 +706,7 @@ ivas_error create_cpe_dec( set_f( hCPE->prev_synth[n], 0, NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ) ); } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hCPE->brate_surplus = 0; #endif @@ -1108,7 +1115,11 @@ static void read_stereo_mode_and_bwidth( else { /* read stereo technology info */ +#ifdef OMASA_UPDATES + if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k) ) +#else if ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) +#endif { hCPE->element_mode = get_next_indice( sts[0], NBITS_ELEMENT_MODE ) + IVAS_CPE_DFT; } diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 1389193a55..80b5d6edd2 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -399,33 +399,18 @@ ivas_error ivas_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifndef OMASA_BRATE - ism_total_brate = 0; -#endif st = st_ivas->hCPE[0]->hCoreCoder[0]; - -#ifndef OMASA_BRATE - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - st->bit_stream = &( st_ivas->bit_stream[( st_ivas->hSCE[0]->element_brate / FRAMES_PER_SEC )] ); - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - ism_total_brate += st_ivas->hSCE[n]->element_brate; - } - st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - } -#endif - nb_bits_metadata[0] = 0; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); /* Set the number of objects for the parametric rendering */ if ( st_ivas->hDirAC != NULL ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) +#endif { st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; } @@ -441,15 +426,17 @@ ivas_error ivas_dec( return error; } -#ifdef OMASA_BRATE /* Configuration of combined-format bit-budget distribution */ ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); -#endif /* Audio signal decoding */ +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) +#endif { if ( st_ivas->nSCE == 1 ) { @@ -479,11 +466,27 @@ ivas_error ivas_dec( return error; } +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + } + } + else + { + st_ivas->hMasaIsmData->azimuth_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); + st_ivas->hMasaIsmData->elevation_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); + } +#else for ( n = 0; n < st_ivas->nchan_ism; n++ ) { st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); } +#endif } if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) @@ -508,7 +511,42 @@ ivas_error ivas_dec( /* Rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + { + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + float gain = 0.7943f; /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + v_multc( data_separated_objects[n], gain, data_separated_objects[n], output_frame ); + } + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + delay_signal( data_separated_objects[n], output_frame, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); + } + + ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); + ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame,st_ivas->hCrendWrapper, + st_ivas->transport_config,st_ivas->hDecoderConfig->output_Fs, st_ivas->hBinRendererTd, + st_ivas->nchan_ism, LFE_CHANNEL, st_ivas->ivas_format, + st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, + ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, data_separated_objects, output_frame ); + + for ( n = 0; n < BINAURAL_CHANNELS; n++ ) + { + v_add( output[n], data_separated_objects[n], output[n], output_frame ); + } + } + else + { + ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); + } +#else ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); +#endif } else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) { @@ -516,10 +554,18 @@ ivas_error ivas_dec( } else if ( st_ivas->hDirAC ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { mvr2r( output[2], data_separated_objects[0], output_frame ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1cb8e9c1c1..f8e0f98d1b 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2021,7 +2021,11 @@ void ivas_dirac_dec( } } +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) +#endif { preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index f530e8ecce..15519bdee4 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1040,7 +1040,11 @@ ivas_error ivas_init_decoder( { k++; } +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { /* one separated object */ st_ivas->nSCE = 1; @@ -1050,7 +1054,24 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); -#ifdef OMASA_BRATE +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + int32_t temp_brate[MAX_SCE]; + + if ( ( error = create_ism_metadata_dec( st_ivas, 1, temp_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); + } + } +#else if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); @@ -1106,7 +1127,11 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] ); } +#ifdef OMASA_UPDATES + if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1407,6 +1432,25 @@ ivas_error ivas_init_decoder( #endif } +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) + { + /* Use td renderer for the objects in DISC mode */ + error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, + st_ivas->transport_config, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); + if ( ( error ) != IVAS_ERR_OK ) + { + return error; + } + + /* Reserve memory for delay buffer */ + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_DISC && ( st_ivas->renderer_type == RENDERER_TD_PANNING || @@ -2013,7 +2057,11 @@ void ivas_init_dec_get_num_cldfb_instances( { *numCldfbAnalyses += st_ivas->nchan_ism; } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index e72d691768..4066304dab 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -127,7 +127,11 @@ ivas_error ivas_ism_metadata_dec( /* read number of objects */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode != ISM_MASA_MODE_DISC ) +#endif { #endif num_obj = 1; @@ -164,8 +168,12 @@ ivas_error ivas_ism_metadata_dec( /* Read ISm present flags (one per object) */ for ( ch = 0; ch < *nchan_transport; ch++ ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* ISM importance flag is already read in ivas_masa_decode() */ ism_imp[ch] = hIsmMeta[ch]->ism_imp; @@ -199,8 +207,12 @@ ivas_error ivas_ism_metadata_dec( { if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* VAD flag is already read in ivas_masa_decode() */ localVAD[ch] = hIsmMeta[ch]->ism_vad_flag; @@ -235,7 +247,11 @@ ivas_error ivas_ism_metadata_dec( { hIsmMetaData = hIsmMeta[ch]; #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -399,7 +415,11 @@ ivas_error ivas_ism_metadata_dec( /* save number of metadata bits read */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -489,8 +509,12 @@ ivas_error ivas_ism_metadata_dec( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { ism_metadata_flag_global = 1; } @@ -504,34 +528,33 @@ ivas_error ivas_ism_metadata_dec( { #ifdef MASA_AND_OBJECTS int16_t masa_ism_flag = 0; +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { masa_ism_flag = 1; - } -#endif -#ifdef OMASA_BRATE - if ( ism_mode == ISM_MASA_MODE_DISC ) - { for ( ch = 0; ch < *nchan_transport; ch++ ) { element_brate[ch] = hSCE[ch]->element_brate; } } + ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, masa_ism_flag ); +#else + ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); #endif - ivas_ism_config( ism_total_brate, *nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata -#ifdef MASA_AND_OBJECTS - , - masa_ism_flag -#endif - ); - for ( ch = 0; ch < *nchan_transport; ch++ ) { hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -543,8 +566,12 @@ ivas_error ivas_ism_metadata_dec( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode != ISM_MASA_MODE_DISC ) +#endif #endif { hSCE[ch]->element_brate = element_brate[ch]; @@ -616,7 +643,7 @@ ivas_error create_ism_metadata_dec( st_ivas->hIsmMetaData[ch]->last_azimuth_idx = 0; st_ivas->hIsmMetaData[ch]->last_elevation_idx = 1 << ( ISM_ELEVATION_NBITS - 1 ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS st_ivas->hIsmMetaData[ch]->ism_imp = -1; st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; #endif @@ -624,7 +651,8 @@ ivas_error create_ism_metadata_dec( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL + + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL #ifdef MASA_AND_OBJECTS , 0 diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index ef890a7482..043b6f8600 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -283,7 +283,11 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( st_ivas->hMasaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { st_ivas->hMasaIsmData->delayBuffer_nchan = 1; } @@ -341,7 +345,11 @@ void ivas_masa_ism_separate_object_render( hRendererData = st_ivas->hIsmRendererData; lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { single_separated = 1; num_objects = 1; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f45b1527ff..a0fa5cf0b4 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -74,24 +74,12 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS -static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos -#ifdef REDUCE_OMASA_META_BITS - , - const int16_t idx_separated_object, - const int16_t ism_imp -#endif -); +static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp); static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); -static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks -#ifdef REDUCE_OMASA_META_BITS - , - const int16_t idx_separated_object -#endif -); -#endif -#ifdef REDUCE_OMASA_META_BITS +static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object); + static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], uint16_t *bit_stream, int16_t *next_bit_pos, float *masa_to_total_energy_ratio, const int16_t idx_sep_obj, int16_t *num_zeros ); #endif @@ -118,12 +106,8 @@ ivas_error ivas_masa_decode( ivas_error error; #ifdef MASA_AND_OBJECTS int16_t obj; -#ifdef OMASA_BRATE int16_t i, ch, ism_imp; -#ifdef REDUCE_OMASA_META_BITS ism_imp = 0; -#endif -#endif #endif error = IVAS_ERR_OK; @@ -132,7 +116,11 @@ ivas_error ivas_masa_decode( low_bitrate_mode = -1; /* This means that LBR mode is not used. */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->hOutSetup.separateChannelEnabled || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->hOutSetup.separateChannelEnabled || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( st_ivas->hOutSetup.separateChannelEnabled ) #endif @@ -184,7 +172,11 @@ ivas_error ivas_masa_decode( st->next_bit_pos -= NO_BITS_MASA_ISM_NO_OBJ; *nb_bits_read += NO_BITS_MASA_ISM_NO_OBJ; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { /* read index of separated object */ /* nchan_ism should be > 1*/ @@ -193,16 +185,28 @@ ivas_error ivas_masa_decode( st_ivas->hMasaIsmData->idx_separated_ism = 2 * byteBuffer + st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read )++; } -#ifdef REDUCE_OMASA_META_BITS else { st_ivas->hMasaIsmData->idx_separated_ism = -1; } -#endif -#ifdef OMASA_BRATE /* read ISM importance flag (one per object) */ +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + ism_imp = 0; + for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) + { + byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read )++; + ism_imp = ( ism_imp << 1 ) + byteBuffer; + } + st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; + } + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { ism_imp = 0; for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) @@ -212,6 +216,17 @@ ivas_error ivas_masa_decode( ism_imp = ( ism_imp << 1 ) + byteBuffer; } st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; + +#ifdef OMASA_UPDATES + /* reset */ + st_ivas->hIsmMetaData[0]->ism_vad_flag = 1; + if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META ) + { + /* read VAD flag */ + st_ivas->hIsmMetaData[0]->ism_vad_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += ISM_METADATA_VAD_FLAG_BITS; + } +#endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -236,7 +251,6 @@ ivas_error ivas_masa_decode( } } } -#endif } #endif /* Placeholder for descriptive metadata content */ @@ -302,17 +316,21 @@ ivas_error ivas_masa_decode( #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos -#ifdef REDUCE_OMASA_META_BITS - , - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp #endif - ); + { + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp ); } +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { @@ -328,7 +346,11 @@ ivas_error ivas_masa_decode( *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos ); #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) +#endif { /* Modify spatial metadata based on the MASA-to-total energy ratios */ modify_masa_energy_ratios( hQMetaData ); @@ -435,9 +457,6 @@ ivas_error ivas_masa_decode( } if ( st_ivas->hDirAC != NULL ) { -#ifndef OMASA_BRATE - int16_t i; -#endif int16_t b; int16_t block; @@ -536,7 +555,11 @@ ivas_error ivas_masa_dec_open( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -615,6 +638,13 @@ ivas_error ivas_masa_ism_data_open( hMasaIsmData->objectsMoved = 0; hMasaIsmData->delayBuffer = NULL; st_ivas->hMasaIsmData = hMasaIsmData; +#ifdef OMASA_UPDATES + for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) + { + hMasaIsmData->q_elevation_old[ch] = 0.0f; + hMasaIsmData->q_azimuth_old[ch] = 0.0f; + } + #endif return IVAS_ERR_OK; } @@ -695,7 +725,11 @@ static ivas_error ivas_masa_dec_config( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -707,7 +741,18 @@ static ivas_error ivas_masa_dec_config( if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); +#ifdef OMASA_UPDATES + if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) + { + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); + } + else + { +#endif + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); +#ifdef OMASA_UPDATES + } +#endif } else { @@ -1376,7 +1421,11 @@ ivas_error ivas_masa_dec_reconfigure( } #ifdef MASA_AND_OBJECTS ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( n = 0; n < st_ivas->nSCE; n++ ) { @@ -1713,7 +1762,6 @@ static void decode_index_slice( } -#ifdef REDUCE_OMASA_META_BITS static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o: ISM read ratio indexes */ const int16_t nchan_ism, /* i: number of objects */ @@ -1747,7 +1795,7 @@ static void read_ism_ratio_index( b_signif = 0; no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); - while ( b_signif < numCodingBands && masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) + while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) { /* distribute evenly the objects */ distribute_evenly_ism( ratio_ism_idx[b_signif], no_levels_ratio_ism, nchan_ism ); @@ -1985,170 +2033,7 @@ static void read_ism_ratio_index( } -#else -static void read_ism_ratio_index( - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - int16_t no_ism, - int16_t numCodingBands, - int16_t sf, - int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - uint16_t *bit_stream, - int16_t *next_bit_pos, - float *masa_to_total_energy_ratio ) -{ - int16_t b, i; - int16_t index; - int16_t GR_order, differential_subframe; - int16_t buf; - int16_t no_levels_ratio_ism; - no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); - if ( sf == 0 ) - { - switch ( no_ism ) - { - case 2: - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - index = 0; - for ( i = 0; i < 3; i++ ) - { - index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; - } - - decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); - } - else - { - /* distribute evenly the objects */ - distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); - } - } - break; - case 3: - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - /* read first 5 bits */ - index = 0; - for ( i = 0; i < 5; i++ ) - { - index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; - } - if ( index == 31 ) - { - index = 0; - for ( i = 0; i < 3; i++ ) - { - index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; - } - index += 31; - } - - decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); - } - else - { - /* distribute evenly the objects */ - distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); - } - } - break; - case 4: - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - /* read 7 bits */ - index = 0; - for ( i = 0; i < 7; i++ ) - { - index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; - } - - decode_index_slice( index, ratio_ism_idx[b], no_ism, no_levels_ratio_ism ); - } - else - { - /* distribute evenly the objects */ - distribute_evenly_ism( ratio_ism_idx[b], no_levels_ratio_ism, no_ism ); - } - } - break; - default: - assert( ( no_ism >= 2 && no_ism <= 4 ) && "Wrong number of objects for MASA_ISM." ); - break; - } - } - else - { - if ( numCodingBands > 1 ) - { - /* read prediction type */ - differential_subframe = bit_stream[( *next_bit_pos )--]; - } - else - { - differential_subframe = 1; - } - /* read GR order */ - GR_order = bit_stream[( *next_bit_pos )--]; - for ( b = 0; b < numCodingBands; b++ ) - { - for ( i = 0; i < no_ism - 1; i++ ) - { - buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); - if ( ( buf % 2 ) == 0 ) - { - ratio_ism_idx[b][i] = -( buf >> 1 ); - } - else - { - ratio_ism_idx[b][i] = ( ( buf + 1 ) >> 1 ); - } - } - } - if ( differential_subframe ) - { - /* differential to previous subframe */ - for ( b = 0; b < numCodingBands; b++ ) - { - ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; - for ( i = 0; i < no_ism - 1; i++ ) - { - ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx_prev_sf[b][i]; - ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; - } - } - } - else - { - /* difference to previous subband */ - ratio_ism_idx[0][no_ism - 1] = no_levels_ratio_ism; - /* first subband - differential to previous subframe */ - for ( i = 0; i < no_ism - 1; i++ ) - { - ratio_ism_idx[0][i] = ratio_ism_idx[0][i] + ratio_ism_idx_prev_sf[0][i]; - ratio_ism_idx[0][no_ism - 1] -= ratio_ism_idx[0][i]; - } - /* rest of subbands differential to previous subband */ - for ( b = 1; b < numCodingBands; b++ ) - { - ratio_ism_idx[b][no_ism - 1] = no_levels_ratio_ism; - for ( i = 0; i < no_ism - 1; i++ ) - { - ratio_ism_idx[b][i] = ratio_ism_idx[b][i] + ratio_ism_idx[b - 1][i]; - ratio_ism_idx[b][no_ism - 1] -= ratio_ism_idx[b][i]; - } - } - } - } - return; -} -#endif static void decode_ism_ratios( @@ -2158,32 +2043,22 @@ static void decode_ism_ratios( float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ const int16_t n_ism, /* i : number of objects */ const int16_t nbands, /* i : number of subbands */ - const int16_t numSf /* i : number of subframes */ -#ifdef REDUCE_OMASA_META_BITS - , + const int16_t numSf, /* i : number of subframes */ const int16_t idx_separated_object /* i: index of separated object */ -#endif ) { int16_t sf, band; int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; -#ifdef REDUCE_OMASA_META_BITS float tmp; int16_t num_zeros; num_zeros = 0; -#endif + /* hQMetaData->q_direction->cfg.nblocks; */ for ( sf = 0; sf < numSf; sf++ ) { /* read ism ratio indexes */ - read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf] -#ifdef REDUCE_OMASA_META_BITS - , - idx_separated_object, - &num_zeros -#endif - ); + read_ism_ratio_index( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio[sf], idx_separated_object, &num_zeros ); /* save previous subframe index values */ if ( sf < numSf - 1 ) @@ -2200,7 +2075,7 @@ static void decode_ism_ratios( { reconstruct_ism_ratios( ratio_ism_idx[band], n_ism, 1.0f / (float) ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ), ratio_ism[sf][band] ); } -#ifdef REDUCE_OMASA_META_BITS + if ( ( n_ism > 2 ) && ( idx_separated_object == n_ism - 1 ) ) { /* rotate */ @@ -2214,7 +2089,7 @@ static void decode_ism_ratios( } } } -#endif + if ( nbands == 1 ) { for ( band = 1; band < 5; band++ ) @@ -2245,26 +2120,22 @@ static int16_t ivas_decode_masaism_metadata( MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, - int16_t *next_bit_pos -#ifdef REDUCE_OMASA_META_BITS - , + int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp -#endif ) { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t *band_mapping; int16_t b; -#ifndef REDUCE_OMASA_META_BITS - float priority[MAX_NUM_OBJECTS]; -#endif int16_t bits_ism[MAX_NUM_OBJECTS], index; uint16_t idx_el, idx_az; float azimuth, elevation; int16_t nb_bits_read; - +#ifdef OMASA_UPDATES + float delta_phi; +#endif nb_bits_read = *next_bit_pos; nbands = hQMetaData->q_direction->cfg.nbands; nblocks = hQMetaData->q_direction->cfg.nblocks; /* To do: what if other value than 4? */ @@ -2274,26 +2145,7 @@ static int16_t ivas_decode_masaism_metadata( if ( nchan_ism > 1 ) { /* read ISM ratios */ - decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks -#ifdef REDUCE_OMASA_META_BITS - , - idx_separated_object -#endif - ); -#ifndef REDUCE_OMASA_META_BITS - /* calculate priority */ - set_f( priority, 0.0f, nchan_ism ); - for ( sf = 0; sf < nblocks; sf++ ) - { - for ( band = 0; band < nbands; band++ ) - { - for ( obj = 0; obj < nchan_ism; obj++ ) - { - priority[obj] = max( priority[obj], ( energy_ratio_ism[sf][band][obj] * hQMetaData->masa_to_total_energy_ratio[sf][band] ) ); - } - } - } -#endif + decode_ism_ratios( bit_stream, next_bit_pos, hQMetaData, energy_ratio_ism, nchan_ism, nbands, nblocks, idx_separated_object ); } else { @@ -2304,31 +2156,73 @@ static int16_t ivas_decode_masaism_metadata( energy_ratio_ism[sf][band][0] = 1.0f; } } -#ifndef REDUCE_OMASA_META_BITS - priority[0] = 1; -#endif } /* read ISM metadata */ -#ifdef REDUCE_OMASA_META_BITS calculate_nbits_meta( nchan_ism, energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); -#else - for ( obj = 0; obj < nchan_ism; obj++ ) - { - bits_ism[obj] = 11 - (int16_t) ( ( 1 - priority[obj] ) * 7 ); - } -#endif for ( obj = 0; obj < nchan_ism; obj++ ) { index = 0; +#ifdef OMASA_UPDATES + if ( bits_ism[obj] < 8 ) /* if low resolution, can look to the past */ + { + /* read if same as previous */ + if ( bit_stream[( *next_bit_pos )--] ) + { + azimuth = hMasaIsmData->q_azimuth_old[obj]; + elevation = hMasaIsmData->q_elevation_old[obj]; + } + else + { + for ( i = 0; i < bits_ism[obj]; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + + if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) + { + delta_phi = 180.0f / (float) ( no_phi_masa[bits_ism[obj] - 1][idx_el] ); /* 360/2*/ + if ( azimuth - hMasaIsmData->q_azimuth_old[obj] > delta_phi ) + { + azimuth -= delta_phi; + } + else + { + if ( hMasaIsmData->q_azimuth_old[obj] - azimuth > delta_phi ) + { + azimuth += delta_phi; + } + } + } + + hMasaIsmData->q_azimuth_old[obj] = azimuth; + hMasaIsmData->q_elevation_old[obj] = elevation; + } + } + else + { + for ( i = 0; i < bits_ism[obj]; i++ ) + { + index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; + } + deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + hMasaIsmData->q_azimuth_old[obj] = azimuth; + hMasaIsmData->q_elevation_old[obj] = elevation; + } +#else for ( i = 0; i < bits_ism[obj]; i++ ) { index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; } deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + + +#endif hMasaIsmData->azimuth_ism[obj] = (int16_t) rint( azimuth ); hMasaIsmData->elevation_ism[obj] = (int16_t) rint( elevation ); + } /* Modify ISM metadata based on the MASA-to-total energy ratios */ @@ -2396,6 +2290,12 @@ void ivas_masa_ism_set_edited_objects( hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism] = st_ivas->elevation_edited; } } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + /* Directions cannot be edited in this mode */ + } +#endif else { for ( dir = 0; dir < MAX_NUM_OBJECTS; dir++ ) @@ -2412,7 +2312,11 @@ void ivas_masa_ism_set_edited_objects( } } +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->editing_ism_enabled ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st_ivas->editing_ism_enabled ) +#endif { if ( st_ivas->hMasaIsmData->idx_separated_ism == st_ivas->index_of_edited_ism ) { diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index cea03fa185..a0ba899f0d 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -101,7 +101,11 @@ void ivas_mono_downmix_render_passive( { numInputChannels = st_ivas->nchan_transport; } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { numInputChannels = st_ivas->nchan_transport + 1; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 5ca00ff79e..35441360fe 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -40,7 +40,7 @@ #endif -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_dec() * @@ -57,6 +57,11 @@ void ivas_set_surplus_brate_dec( *ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { *ism_total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp @@ -65,10 +70,15 @@ void ivas_set_surplus_brate_dec( 0 #endif ); +#endif st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; +#ifdef OMASA_UPDATES + /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_PARAM_ONE_OBJ mode */ +#else /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_ONE_OBJ mode */ +#endif st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate; st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0; @@ -79,14 +89,16 @@ void ivas_set_surplus_brate_dec( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { -#ifdef FIX_4OBJ_128 - int16_t brate_limit_flag = 0; - +#ifdef OMASA_UPDATES + int16_t brate_limit_flag, ism_imp[MAX_NUM_OBJECTS]; + for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - brate_limit_flag += st_ivas->hIsmMetaData[n]->ism_imp; + ism_imp[n] = st_ivas->hIsmMetaData[n]->ism_imp; } - brate_limit_flag = brate_limit_flag >= 10 ? 1 : 0; + + brate_limit_flag = calculate_brate_limit_flag( ism_imp, st_ivas->nchan_ism ); + #endif ism_total_brate_ref = 0; @@ -106,7 +118,7 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[n]->element_brate = element_brate[n]; *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp -#ifdef FIX_4OBJ_128 +#ifdef OMASA_UPDATES , brate_limit_flag #endif diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 944f185dd1..ab3131d3b3 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -3450,6 +3450,10 @@ void decode_masa_to_total( matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); mvr2r( dct_data_tmp, q_dct_data, nbands ); break; + case 12: + matrix_product( dct12, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; case 20: matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); /* reuse of variable*/ @@ -3459,6 +3463,7 @@ void decode_masa_to_total( matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); break; default: + printf( "Incorrect number of coefficients for OMASA.\n" ); break; } diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 810c7cca66..2072f25460 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -158,11 +158,19 @@ ivas_error ivas_sce_dec( ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } +#ifdef OMASA_UPDATES + else if ( ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) +#else else if ( ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) || ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif #else if ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) #endif @@ -193,19 +201,9 @@ ivas_error ivas_sce_dec( { st->total_brate = ivas_total_brate; } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT ) /* note: total_brate[] is set in ivas_ism_config() or ivas_set_surplus_brate_dec() */ #else -#ifdef MASA_AND_OBJECTS - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) - { - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - /* one separated object */ - st->total_brate = hSCE->element_brate; - } - } -#endif else if ( st_ivas->ivas_format != ISM_FORMAT ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ #endif { @@ -218,11 +216,15 @@ ivas_error ivas_sce_dec( /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) && +#else if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC #ifdef OMASA_BRATE || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ #endif ) && +#endif st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) #else if ( st_ivas->ivas_format == ISM_FORMAT && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 3f48468c42..4316c90677 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -933,7 +933,7 @@ typedef struct cpe_dec_data_structure float old_out_mdct[STEREO_MDCT2DFT_FADE_LEN_48k]; float old_outLB_mdct[2 * STEREO_MDCT2DFT_FADE_LEN_48k]; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ #endif @@ -1138,6 +1138,10 @@ typedef struct ivas_masa_ism_data_structure int16_t idx_separated_ism; int16_t azimuth_separated_ism; int16_t elevation_separated_ism; +#ifdef OMASA_UPDATES + float q_azimuth_old[MAX_NUM_OBJECTS]; + float q_elevation_old[MAX_NUM_OBJECTS]; +#endif float ismPreprocMatrix[2][2][CLDFB_NO_CHANNELS_MAX]; uint8_t objectsMoved; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 20d03915c2..20a7d58bc2 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -768,7 +768,7 @@ ivas_error stereo_memory_dec( if ( hCPE->hCoreCoder[0]->bfi == 0 ) { st = hCPE->hCoreCoder[1]; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); #else hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 9809b759f8..31b66044c6 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -94,7 +94,7 @@ void tdm_configure_dec( int16_t tdm_tmp_SM_LRTD_flag; int16_t mod_ct, core, bits_offset; int16_t idx_LRTD_pri_side, tdm_inst_ratio_idx; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int32_t element_brate_adapt; int16_t bstr_last_pos; #endif @@ -102,7 +102,7 @@ void tdm_configure_dec( hStereoTD = hCPE->hStereoTD; sts = hCPE->hCoreCoder; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS element_brate_adapt = hCPE->element_brate + hCPE->brate_surplus; bstr_last_pos = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif @@ -132,7 +132,7 @@ void tdm_configure_dec( /* Get few parameters needed to decode the bitrate allocated to each channel */ /* Get the coder_type of the secondary channel (last parameter on 2 bits) */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS sts[1]->coder_type = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING, TDM_SECONDARY_SIGNALLING ); #else sts[1]->coder_type = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING ), TDM_SECONDARY_SIGNALLING ); @@ -164,7 +164,7 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ /* Get the correlation ratio */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS *tdm_ratio_idx = get_indice_st( sts[0], element_brate_adapt, (int16_t) ( bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); #else *tdm_ratio_idx = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS ), TDM_RATIO_BITS ); @@ -174,7 +174,7 @@ void tdm_configure_dec( if ( sts[1]->coder_type == INACTIVE ) { /* Get the flag on the LPC reusage type (primary channel of ave LPC */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); #else hStereoTD->tdm_use_IAWB_Ave_lpc = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); @@ -184,7 +184,7 @@ void tdm_configure_dec( else { /* Get the flag on the LPC reusage */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS, TDM_LP_REUSE_BITS ); #else hStereoTD->tdm_lp_reuse_flag = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS ), TDM_LP_REUSE_BITS ); @@ -244,7 +244,7 @@ void tdm_configure_dec( int16_t tmpS = 20; if ( hStereoTD->tdm_LRTD_flag == 0 ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS tmpS = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); #else tmpS = get_indice_st( sts[0], hCPE->element_brate, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS ), STEREO_BITS_TCA_GD ); @@ -257,7 +257,7 @@ void tdm_configure_dec( { if ( hStereoTD->tdm_LRTD_flag == 0 ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hCPE->hStereoTCA->refChanIndx = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS, STEREO_BITS_TCA_CHAN ); hCPE->hStereoTCA->indx_ica_NCShift = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN, STEREO_BITS_TCA_CORRSTATS ); hCPE->hStereoTCA->indx_ica_gD = get_indice_st( sts[0], element_brate_adapt, bstr_last_pos - TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + STEREO_BITS_TCA_CHAN + STEREO_BITS_TCA_CORRSTATS, STEREO_BITS_TCA_GD ); @@ -285,7 +285,7 @@ void tdm_configure_dec( #endif /* set the BW of the secondary channel */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS if ( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel > IVAS_16k4 / FRAMES_PER_SEC ) #else if ( hStereoTD->tdm_LRTD_flag && hCPE->element_brate > IVAS_13k2 ) @@ -304,7 +304,7 @@ void tdm_configure_dec( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 0f6d709fc2..579f74c6d6 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -102,7 +102,7 @@ ivas_error ivas_core_enc( float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; int16_t last_element_mode, tdm_Pitch_reuse_flag; int32_t element_brate, last_element_brate, input_Fs; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int16_t diff_nBits; #endif ivas_error error; @@ -190,7 +190,7 @@ ivas_error ivas_core_enc( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------* * Sanity check in combined format coding *-----------------------------------------------------------------*/ @@ -420,7 +420,7 @@ ivas_error ivas_core_enc( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------* * Write potentially unused bits in combined format coding *-----------------------------------------------------------------*/ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index cf69b1e333..e3b8342896 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -166,7 +166,18 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && ivas_total_brate == IVAS_48k ) + { + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k ); + } + else + { +#endif + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); +#ifdef OMASA_UPDATES + } +#endif } if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) @@ -274,7 +285,7 @@ ivas_error ivas_cpe_enc( { #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) - { + { stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } else @@ -308,10 +319,14 @@ ivas_error ivas_cpe_enc( if ( hCPE->element_mode == IVAS_CPE_MDCT ) { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* compute bit-rate surplus per channel in combined format coding */ int32_t brate_surplus[CPE_CHANNELS]; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; @@ -336,9 +351,13 @@ ivas_error ivas_cpe_enc( sts[n]->bits_frame_channel = (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) / n_CoreChannels ); sts[n]->total_brate = hCPE->element_brate / n_CoreChannels; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); sts[n]->total_brate += brate_surplus[n]; @@ -398,7 +417,7 @@ ivas_error ivas_cpe_enc( /* signal the bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; sts[1]->bits_frame_channel = (int16_t) ( hCPE->element_brate / FRAMES_PER_SEC ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS sts[1]->bits_frame_channel += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); #endif if ( st_ivas->hQMetaData != NULL ) @@ -630,16 +649,7 @@ ivas_error ivas_cpe_enc( /* Write stereo bitstream */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_BRATE cpe_brate = st_ivas->hCPE[0]->element_brate; -#else - cpe_brate = ivas_total_brate; - - if ( ivas_format == MASA_ISM_FORMAT ) - { - cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, hEncoderConfig->nchan_ism ); - } -#endif /* DFT stereo side bits */ if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && cpe_brate < MASA_STEREO_MIN_BITRATE && sts[0]->core_brate != SID_2k40 && sts[0]->core_brate != FRAME_NO_DATA ) @@ -662,9 +672,7 @@ ivas_error ivas_cpe_enc( if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) { max_bits -= nb_bits_metadata; -#ifdef OMASA_BRATE max_bits += (int16_t) ( hCPE->brate_surplus / FRAMES_PER_SEC ); -#endif } stereo_dft_enc_res( hCPE->hStereoDft, old_inp_12k8[1] + L_INP_MEM - STEREO_DFT_OVL_8k, hCPE->hMetaData, &nb_bits, max_bits ); @@ -704,9 +712,13 @@ ivas_error ivas_cpe_enc( /* subtract metadata bitbudget */ sts[0]->total_brate -= ( nb_bits_metadata * FRAMES_PER_SEC ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { sts[0]->total_brate += hCPE->brate_surplus; } @@ -866,7 +878,7 @@ ivas_error create_cpe_enc( hCPE->hFrontVad[0] = NULL; hCPE->hFrontVad[1] = NULL; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hCPE->brate_surplus = 0; #endif diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 7b4685251f..afb4fc8ac7 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -404,8 +404,11 @@ void ivas_signaling_enc( /*-------------------------------------------------------------------------- * Write element mode info *--------------------------------------------------------------------------*/ - +#ifdef OMASA_UPDATES + if ( (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ +#else if ( st->element_mode >= IVAS_CPE_DFT && element_brate < MIN_BRATE_MDCT_STEREO && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ +#endif { ind = st->element_mode - IVAS_CPE_DFT; push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a3adbda9b6..de247c0a56 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -249,11 +249,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL -#ifdef REDUCE_OMASA_META_BITS - , - 0 -#endif + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ); } @@ -314,7 +310,6 @@ ivas_error ivas_enc( /* nb_bits_metadata[0] = 0; */ set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); -#ifdef OMASA_BRATE /* Configure MASA encoder based on frame parameters */ if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -325,12 +320,7 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs -#ifdef OMASA_DIFFUSE_ISM_MERGE - , - st_ivas->ism_mode -#endif - ); + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); } /* Estimate TF-tile energy for the input MASA stream */ @@ -340,22 +330,31 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Estimate MASA parameters for the objects */ -#ifdef OMASA_DIFFUSE_ISM_MERGE ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); -#else - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object ); -#endif } /* Encode ISMs transport channels */ n = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { /* Analysis, decision about bitrates per channel & core coding */ @@ -369,7 +368,7 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa -#ifdef REDUCE_OMASA_META_BITS +#ifdef MASA_AND_OBJECTS , st_ivas->hIsmMetaData[0]->ism_imp #endif @@ -381,58 +380,7 @@ ivas_error ivas_enc( #else ivas_set_surplus_brate_enc( st_ivas ); #endif -#else - if ( st_ivas->hQMetaData != NULL ) - { - /* Configure MASA encoder based on frame parameters */ - ivas_masa_enc_config( st_ivas ); - idx_separated_object = 0; - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, -#ifdef OMASA_DIFFUSE_ISM_MERGE - , - st_ivas->ism_mode -#endif - ); - } - else - { - st_ivas->nSCE = hEncoderConfig->nchan_ism; - } - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); - - /* put audio object data in SCE's */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Estimate MASA parameters for the objects */ - ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hQMetaData, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, - data_separated_object, &idx_separated_object ); - } - /* Encode MASA parameters and write MASA metadata bitstream */ - ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa ); - } - - /* Encode transport signals */ - n = 0; - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ); /* there are no metadata bits in SCE in this mode */ - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) - { - return error; - } - n = hEncoderConfig->nchan_ism; - } -#endif /* OMASA_BRATE */ /* Encode MASA transport channels */ if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) @@ -497,11 +445,7 @@ ivas_error ivas_enc( ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL -#ifdef REDUCE_OMASA_META_BITS - , - 0 -#endif + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 7987431f48..1b6e2bd596 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -630,8 +630,11 @@ ivas_error ivas_init_encoder( return error; } } - - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) +#ifdef OMASA_UPDATES + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM) ) +#else + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) +#endif { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 5505976d05..13f804aba2 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -265,7 +265,7 @@ ivas_error ivas_ism_enc( } #endif ivas_ism_metadata_enc( -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS &st_ivas->hEncoderConfig->ivas_total_brate, #else st_ivas->hEncoderConfig->ivas_total_brate, @@ -274,7 +274,7 @@ ivas_error ivas_ism_enc( #ifdef MASA_AND_OBJECTS , st_ivas->nSCE -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS , -1 #endif @@ -284,11 +284,13 @@ ivas_error ivas_ism_enc( else /* ISM_MODE_DISC */ { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_BRATE int32_t ism_total_brate_ref; -#endif int32_t ism_total_brate; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { ism_total_brate = 0; for ( i = 0; i < st_ivas->nSCE; i++ ) @@ -301,7 +303,6 @@ ivas_error ivas_ism_enc( ism_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; } -#ifdef OMASA_BRATE ism_total_brate_ref = ism_total_brate; // VE: change the interface of the following function and call it with 'st_ivas' only @@ -311,9 +312,7 @@ ivas_error ivas_ism_enc( { st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate; } -#else - ivas_ism_metadata_enc( ism_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->nSCE ); -#endif + #else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL ); #endif @@ -348,7 +347,11 @@ ivas_error ivas_ism_enc( * CoreCoders encoding *-----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { n = st_ivas->nSCE; } diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 43c498bcd0..97b689b5dd 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -146,7 +146,7 @@ static void rate_ism_importance( *-------------------------------------------------------------------------*/ ivas_error ivas_ism_metadata_enc( -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int32_t *ism_total_brate, /* i/o: ISms total bitrate */ #else const int32_t ism_total_brate, /* i : ISms total bitrate */ @@ -161,12 +161,9 @@ ivas_error ivas_ism_metadata_enc( const PARAM_ISM_CONFIG_HANDLE hParamIsm /* i : Param ISM Enc Handle */ #ifdef MASA_AND_OBJECTS , - const int16_t n_ism /* i : number of objects */ -#ifdef OMASA_BRATE - , + const int16_t n_ism, /* i : number of objects */ const float lp_noise_CPE #endif -#endif ) { int16_t i, ch, nb_bits_start = 0, diff; @@ -195,7 +192,11 @@ ivas_error ivas_ism_metadata_enc( num_obj = nchan_transport; } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { num_obj = n_ism; } @@ -205,7 +206,11 @@ ivas_error ivas_ism_metadata_enc( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: incorrect ISM mode" ); } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( num_obj == 1 && ( hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 || hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA ) && ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( num_obj == 1 && ( hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 || hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA ) && ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) ) +#endif #else if ( num_obj == 1 && ( hSCE[0]->hCoreCoder[0]->core_brate == SID_2k40 || hSCE[0]->hCoreCoder[0]->core_brate == FRAME_NO_DATA ) && ism_mode == ISM_MODE_DISC ) #endif @@ -222,8 +227,12 @@ ivas_error ivas_ism_metadata_enc( set_s( flag_abs_azimuth, 0, num_obj ); set_s( flag_abs_elevation, 0, num_obj ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { n_ch = num_obj; } @@ -232,7 +241,11 @@ ivas_error ivas_ism_metadata_enc( n_ch = nchan_transport; } +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /*----------------------------------------------------------------* * Rate importance of particular ISm streams in combined format coding @@ -331,7 +344,11 @@ ivas_error ivas_ism_metadata_enc( /*Todo: Nokia check where we transmit the number of objects */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode != ISM_MASA_MODE_DISC ) +#endif { #endif /* write number of objects - unary coding */ @@ -351,8 +368,12 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_transport; ch++ ) #endif { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* ISM importance flag will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_imp = ism_imp[ch]; @@ -370,7 +391,11 @@ ivas_error ivas_ism_metadata_enc( ism_metadata_flag_global |= hIsmMeta[ch]->ism_metadata_flag; } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -382,8 +407,12 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_transport; ch++ ) #endif { -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* reset */ hIsmMeta[ch]->ism_vad_flag = 1; @@ -393,8 +422,12 @@ ivas_error ivas_ism_metadata_enc( if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { /* this flag distinguishes between coding of inactive frame and active frame w/o. metadata */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* VAD flag will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_vad_flag = localVAD[ch]; @@ -426,7 +459,11 @@ ivas_error ivas_ism_metadata_enc( { hIsmMetaData = hIsmMeta[ch]; #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -442,7 +479,11 @@ ivas_error ivas_ism_metadata_enc( /* Azimuth quantization (quantize azimuth to the AZIMUTH_NBITS-bit index */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -552,7 +593,11 @@ ivas_error ivas_ism_metadata_enc( /* Elevation quantization (quantize azimuth to the ELEVATION_NBITS-bit index */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -685,7 +730,11 @@ ivas_error ivas_ism_metadata_enc( /* save number of metadata bits written */ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) +#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -816,22 +865,22 @@ ivas_error ivas_ism_metadata_enc( } } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*----------------------------------------------------------------* * Take into account the combined format bit-budget distribution *----------------------------------------------------------------*/ +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + +#else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; -#ifdef FIX_4OBJ_128 - int16_t brate_limit_flag = 0; - - for ( ch = 0; ch < num_obj; ch++ ) - { - brate_limit_flag += ism_imp[ch]; - } - brate_limit_flag = brate_limit_flag >= 10 ? 1 : 0; +#ifdef OMASA_UPDATES + int16_t brate_limit_flag; + brate_limit_flag = calculate_brate_limit_flag( ism_imp, num_obj ); #endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); @@ -842,10 +891,14 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < num_obj; ch++ ) { +#ifdef OMASA_UPDATES + *ism_total_brate += ivas_interformat_brate( ism_mode, num_obj, hSCE[ch]->element_brate, ism_imp[ch],brate_limit_flag +#else *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, num_obj, hSCE[ch]->element_brate, ism_imp[ch] #ifdef FIX_4OBJ_128 , brate_limit_flag +#endif #endif ); } @@ -858,12 +911,23 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + ivas_ism_config( *ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ); // VE: this funtion should return an error + } + else + { + ivas_ism_config( *ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ); // VE: this funtion should return an error + } +#else #ifdef OMASA_BRATE ivas_ism_config( *ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, ism_mode == ISM_MASA_MODE_DISC ); // VE: this funtion should return an error #else ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, ( ism_mode == ISM_MASA_MODE_DISC ) ); #endif +#endif #else ivas_ism_config( ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ); #endif @@ -876,7 +940,6 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS for ( ch = 0; ch < n_ch; ch++ ) { -#ifdef OMASA_BRATE hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; if ( ism_mode == ISM_MODE_DISC ) { @@ -887,7 +950,11 @@ ivas_error ivas_ism_metadata_enc( hSCE[ch]->element_brate = element_brate[ch]; } +#ifdef OMASA_UPDATES + else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else else if ( ism_mode == ISM_MASA_MODE_DISC ) +#endif { if ( ism_imp[ch] == ISM_INACTIVE_IMP ) { @@ -896,19 +963,6 @@ ivas_error ivas_ism_metadata_enc( } hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) - { - hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; - if ( hIsmMeta[ch]->ism_metadata_flag == 0 && localVAD[ch] == 0 && ism_metadata_flag_global ) - { - hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; - } - } - - hSCE[ch]->element_brate = element_brate[ch]; - hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; -#endif /* write metadata only in active frames */ if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) @@ -969,7 +1023,12 @@ ivas_error create_ism_metadata_enc( st_ivas->nCPE = 1; st_ivas->nSCE = 0; break; +#ifdef OMASA_UPDATES + case ISM_MASA_MODE_MASA_ONE_OBJ: + case ISM_MASA_MODE_PARAM_ONE_OBJ: +#else case ISM_MASA_MODE_ONE_OBJ: +#endif st_ivas->nCPE = 1; st_ivas->nSCE = 1; break; @@ -1034,9 +1093,13 @@ ivas_error create_ism_metadata_enc( st_ivas->hIsmMetaData[ch]->elevation_diff_cnt = ISM_FEC_MAX - 1; st_ivas->hIsmMetaData[ch]->last_ism_metadata_flag = 0; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS st_ivas->hIsmMetaData[ch]->ism_imp = -1; st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; +#ifdef OMASA_UPDATES + st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; + st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; +#endif #endif ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); @@ -1044,7 +1107,11 @@ ivas_error create_ism_metadata_enc( #ifdef MASA_AND_OBJECTS if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ); } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index f31badf9b3..07c313f002 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -45,11 +45,6 @@ *-----------------------------------------------------------------------*/ static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ); -#ifdef MASA_AND_OBJECTS -#ifndef OMASA_DIFFUSE_ISM_MERGE -static void combine_directions( MASA_ENCODER_HANDLE hMasa ); -#endif -#endif static void find_n_largest( const float *input, int16_t *largestIndices, const int16_t numElements, const int16_t numLargest ); @@ -62,45 +57,25 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); #ifdef MASA_AND_OBJECTS -#ifndef OMASA_DIFFUSE_ISM_MERGE -static void ivas_merge_masa_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); -#endif - -static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks -#ifdef REDUCE_OMASA_META_BITS - , - const int16_t idx_separated_object, - const int16_t ism_imp -#endif -); +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, + const int16_t idx_separated_object, const int16_t ism_imp ); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); -static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, const int16_t nchan_ism, const float masa_to_total_energy_ratio -#ifdef REDUCE_OMASA_META_BITS - , - const int16_t idx_sep_object -#endif -); +static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, const int16_t nchan_ism, const float masa_to_total_energy_ratio, const int16_t idx_sep_object ); static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); -static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio -#ifdef REDUCE_OMASA_META_BITS - , - const int16_t shift_one, - const int16_t idx_sep_obj -#endif -); +static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); static void transform_index_and_GR_encode( int16_t *diff_idx, int16_t len, int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); static void transform_difference_index( int16_t *diff_idx, int16_t *idx, int16_t len ); -#ifdef REDUCE_OMASA_META_BITS + static void independent_coding_ratio_ism_idx( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const float *masa_to_total_energy_ratio, int16_t nchan_ism, int16_t numCodingBands, int16_t bits_index, BSTR_ENC_HANDLE hMetaData ); static void remove_sep_obj( int16_t *diff_idx, int16_t no_ism, int16_t idx_sep_obj ); -#endif + #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif @@ -167,7 +142,11 @@ ivas_error ivas_masa_enc_open( } #ifdef MASA_AND_OBJECTS ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -205,7 +184,7 @@ ivas_error ivas_masa_enc_open( set_zero( hMasa->data.lfeToTotalEnergyRatio, MAX_PARAM_SPATIAL_SUBFRAMES ); hMasa->data.prevq_lfeToTotalEnergyRatio = 0.0f; hMasa->data.prevq_lfeIndex = 0; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS hMasa->data.lp_noise_CPE = -1; #endif @@ -274,11 +253,8 @@ void ivas_masa_encode( const int16_t nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ - OMASA_ENC_HANDLE hOMasa /* i : OMASA encoder handle */ -#ifdef REDUCE_OMASA_META_BITS - , - int16_t ism_imp /* i: importance of separated object */ -#endif + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + int16_t ism_imp /* i: importance of separated object */ #endif ) { @@ -339,16 +315,15 @@ void ivas_masa_encode( #endif { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE +#ifdef OMASA_UPDATES + if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) +#else if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) || ( ivas_format != MASA_ISM_FORMAT ) ) +#endif { /* Combine directions */ ivas_masa_combine_directions( hMasa ); } -#else - /* Combine directions */ - combine_directions( hMasa ); -#endif #else /* Combine directions */ combine_directions( hMasa ); @@ -384,19 +359,40 @@ void ivas_masa_encode( hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; /* write index of separated object if needed */ +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && hMasa->data.nchan_ism > 1 ) +#else if ( ism_mode == ISM_MASA_MODE_ONE_OBJ && hMasa->data.nchan_ism > 1 ) +#endif { push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; } -#ifdef OMASA_BRATE /* write ISM importance flag (one per object) */ +#ifdef OMASA_UPDATES + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif + { + push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + } +#ifdef OMASA_UPDATES + else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + + if ( hIsmMetaData[0]->ism_metadata_flag == 0 ) + { + /* write VAD flag */ + push_next_indice( hMetaData, hIsmMetaData[0]->ism_vad_flag, ISM_METADATA_VAD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_VAD_FLAG_BITS; + } } +#endif else if ( ism_mode == ISM_MASA_MODE_DISC ) { for ( i = 0; i < nchan_ism; i++ ) @@ -412,7 +408,6 @@ void ivas_masa_encode( } } } -#endif } else { @@ -444,25 +439,13 @@ void ivas_masa_encode( /* Move data from encoder to qmetadata */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) -#else - if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) -#endif #else if ( ivas_format == MASA_FORMAT ) #endif { move_metadata_to_qmetadata( hMasa, hQMetaData ); } -#ifdef MASA_AND_OBJECTS -#ifndef OMASA_DIFFUSE_ISM_MERGE - else if ( ivas_format == MASA_ISM_FORMAT ) - { - ivas_merge_masa_metadata( hMasa, hQMetaData ); - } -#endif -#endif if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) { @@ -479,19 +462,15 @@ void ivas_masa_encode( #ifdef MASA_AND_OBJECTS /* Encode MASA+ISM metadata */ +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes -#ifdef REDUCE_OMASA_META_BITS - , - idx_separated_object -#endif -#ifdef REDUCE_OMASA_META_BITS - , - ism_imp -#endif - ); + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, + idx_separated_object, ism_imp ); } else { @@ -502,7 +481,11 @@ void ivas_masa_encode( ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { /* Modify spatial metadata based on the MASA-to-total energy ratios */ modify_masa_energy_ratios( hQMetaData ); @@ -543,11 +526,7 @@ void ivas_masa_encode( { /* Combine directions */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE ivas_masa_combine_directions( hMasa ); -#else - combine_directions( hMasa ); -#endif #else combine_directions( hMasa ); #endif @@ -699,7 +678,11 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -738,7 +721,18 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); +#ifdef OMASA_UPDATES + if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) + { + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); + } + else + { +#endif + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); +#ifdef OMASA_UPDATES + } +#endif } else { @@ -837,8 +831,12 @@ ivas_error ivas_masa_enc_config( #endif } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) { @@ -1086,13 +1084,9 @@ static void combine_freqbands_and_subframes( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE void ivas_masa_combine_directions( #else static void combine_directions( -#endif -#else -static void combine_directions( #endif MASA_ENCODER_HANDLE hMasa ) { @@ -1210,9 +1204,7 @@ static void combine_directions( ambience2dir = 1.0f - ratioSum; hMeta->directional_meta[0].energy_ratio[j][i] = sumVecLen[j][i] / ( hMeta->directional_meta[0].energy_ratio[j][i] + hMeta->directional_meta[1].energy_ratio[j][i] + ambience2dir / 2.0f ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE hMeta->directional_meta[1].energy_ratio[j][i] = 0.0f; -#endif /* OMASA_DIFFUSE_ISM_MERGE */ #endif /* MASA_AND_OBJECTS */ if ( computeCoherence ) { @@ -1590,7 +1582,11 @@ static void reduce_metadata_further( /* Get energy for the input data in 4-subframe, 5-band format */ totalEnergySum = 0.0f; #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ +#else if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) /* Energy data is in 4-subframe, 24-band format */ +#endif #else if ( ivas_format == MASA_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ #endif @@ -1979,7 +1975,11 @@ void ivas_masa_enc_reconfigure( ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; #ifdef MASA_AND_OBJECTS ism_total_brate = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) +#endif { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -2044,7 +2044,6 @@ void ivas_masa_enc_reconfigure( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_DIFFUSE_ISM_MERGE /*-------------------------------------------------------------------* * ivas_merge_masa_metadata() * @@ -2055,25 +2054,16 @@ void ivas_merge_masa_metadata( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ ) -#else -static void ivas_merge_masa_metadata( - MASA_ENCODER_HANDLE hMasa, - IVAS_QMETADATA_HANDLE hQMeta ) -#endif /* OMASA_DIFFUSE_ISM_MERGE */ - { int16_t sf, band; uint8_t numCodingBands; uint8_t numDirections; uint8_t numSf; MASA_METADATA_HANDLE hMeta; -#ifdef OMASA_DIFFUSE_ISM_MERGE float energyTimesRatioISM; float energyTimesRatioMASA[2]; float total_diff_nrg; -#else - float energyTimesRatio1, energyTimesRatio2; -#endif /* OMASA_DIFFUSE_ISM_MERGE */ + int16_t brange[2]; float eneBand; @@ -2085,15 +2075,11 @@ static void ivas_merge_masa_metadata( numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; hMeta = &( hMasa->masaMetadata ); -#ifndef OMASA_DIFFUSE_ISM_MERGE - assert( numDirections == 1 && "MASA metadata merging currently implemented only for 1-direction metadata" ); /* Currently only 1-direction metadata is fed to merging */ -#endif for ( sf = 0; sf < numSf; sf++ ) { for ( band = 0; band < numCodingBands; band++ ) { -#ifdef OMASA_DIFFUSE_ISM_MERGE int16_t merge_dest; float dir_sum; uint8_t band_n_dirs; @@ -2108,10 +2094,6 @@ static void ivas_merge_masa_metadata( { band_n_dirs = 2; } -#else - brange[0] = hMasa->data.band_mapping[band]; - brange[1] = hMasa->data.band_mapping[band + 1]; -#endif /* OMASA_DIFFUSE_ISM_MERGE */ /* Compute energies */ /* MASA energy is in the full 24 band resolution, whereas the ISM energy is already in the coding band resolution */ @@ -2123,7 +2105,6 @@ static void ivas_merge_masa_metadata( energyMerged[sf][band] = eneBand + hMasa->data.energy_ism[sf][band]; /* Compute weights */ -#ifdef OMASA_DIFFUSE_ISM_MERGE energyTimesRatioMASA[0] = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; if ( band_n_dirs == 2 ) { @@ -2182,26 +2163,6 @@ static void ivas_merge_masa_metadata( hMeta->directional_meta[1].energy_ratio[sf][band] *= direct_scaler; } } -#else /* OMASA_DIFFUSE_ISM_MERGE */ - energyTimesRatio1 = hMasa->data.energy_ism[sf][band] * hQMeta->q_direction[0].band_data[band].energy_ratio[sf]; - energyTimesRatio2 = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; - - /* Determine combined metadata based on the weights */ - if ( energyTimesRatio2 > energyTimesRatio1 ) - { - hQMeta->q_direction[0].band_data[band].azimuth[sf] = hMeta->directional_meta[0].azimuth[sf][band]; - hQMeta->q_direction[0].band_data[band].elevation[sf] = hMeta->directional_meta[0].elevation[sf][band]; - hQMeta->q_direction[0].band_data[band].energy_ratio[sf] = hMeta->directional_meta[0].energy_ratio[sf][band]; - if ( hQMeta->q_direction[0].coherence_band_data != NULL ) - { - hQMeta->q_direction[0].coherence_band_data[band].spread_coherence[sf] = (uint8_t) roundf( hMeta->directional_meta[0].spread_coherence[sf][band] * UINT8_MAX ); - } - if ( hQMeta->surcoh_band_data != NULL ) - { - hQMeta->surcoh_band_data[band].surround_coherence[sf] = (uint8_t) roundf( hMeta->common_meta.surround_coherence[sf][band] * UINT8_MAX ); - } - } -#endif /* OMASA_DIFFUSE_ISM_MERGE */ } } @@ -2221,17 +2182,13 @@ static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, const int16_t nchan_ism, - const float masa_to_total_energy_ratio -#ifdef REDUCE_OMASA_META_BITS - , + const float masa_to_total_energy_ratio, const int16_t idx_sep_object -#endif ) { int16_t i, j, best_i, best_i2; float dist, div, tmp, dist2, best_dist; int16_t part_idx_sum, max_sum_idx; -#ifdef REDUCE_OMASA_META_BITS float ratio_ism_loc[MAX_NUM_OBJECTS]; int16_t no_ism_loc; @@ -2350,85 +2307,7 @@ static void quantize_ratio_ism_vector( { idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); } -#else - max_sum_idx = ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1; - if ( no_ism > 1 ) - { - - if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) - { - distribute_evenly_ism( idx, max_sum_idx, no_ism ); - } - else - { - dist = 0.0f; - div = 1.0f / (float) ( max_sum_idx ); - - part_idx_sum = 0; - for ( i = 0; i < no_ism; i++ ) - { - idx[i] = (int16_t) ( ( ratio_ism[i] ) * ( max_sum_idx ) ); - part_idx_sum += idx[i]; - - tmp = ( ratio_ism[i] - ( idx[i] * div ) ); - dist += ( tmp * tmp ); - } - best_dist = dist; - best_i2 = -1; - while ( part_idx_sum < max_sum_idx ) - { - best_i = -1; - /* check which index to increase by 1 for a possible improvement */ - - for ( i = 0; i < no_ism; i++ ) - { - idx[i]++; - dist2 = 0.0f; - - - for ( j = 0; j < no_ism; j++ ) - { - tmp = ( ratio_ism[i] - ( idx[i] * div ) ); - dist2 += ( tmp * tmp ); - } - - if ( dist2 < best_dist ) - { - best_i2 = best_i; - best_i = i; - best_dist = dist2; - } - idx[i]--; - } - if ( best_i > -1 ) - { - idx[best_i]++; - part_idx_sum++; - } - else - { - if ( best_i2 > -1 ) - { - idx[best_i2]++; - part_idx_sum++; - } - else - { - idx[no_ism - 1] += max_sum_idx - part_idx_sum; - part_idx_sum = max_sum_idx; - } - } - } - assert( sum_s( idx, no_ism ) == max_sum_idx ); - } - } - else - { - idx[0] = (int16_t) ( ( ratio_ism[0] ) * ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) + 0.5f ); - } - -#endif return; } @@ -2528,7 +2407,7 @@ static int16_t try_differential( b_signif = 0; - while ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR && b_signif < numCodingBands ) + while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) { b_signif++; } @@ -2590,7 +2469,7 @@ static void differential_coding_first_subframe( } } } -#ifdef REDUCE_OMASA_META_BITS + static void independent_coding_ratio_ism_idx( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i: ISM ratios */ const float *masa_to_total_energy_ratio, /* i: MASA to total ratios */ @@ -2777,7 +2656,7 @@ static int16_t encode_ratio_ism_subframe( nbits0 = 0; nbits1 = 0; b_signif = 0; - while ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR && b_signif < numCodingBands ) + while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) { b_signif++; } @@ -2899,7 +2778,7 @@ static int16_t encode_ratio_ism_subframe( remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); } - transform_index_and_GR_encode( diff_idx, nchan_ism - 1, GR_order, hMetaData ); + transform_index_and_GR_encode( diff_idx, nchan_ism - 1 - shift_one, GR_order, hMetaData ); } } } @@ -2914,221 +2793,7 @@ static int16_t encode_ratio_ism_subframe( } -#else -static int16_t encode_ratio_ism_subframe( - int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - int16_t no_ism, - int16_t numCodingBands, - int16_t sf, - int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], - BSTR_ENC_HANDLE hMetaData, - const float *masa_to_total_energy_ratio ) -{ - int16_t b, i, b_signif; - int16_t diff_idx[MAX_NUM_OBJECTS], index; - int16_t nbits, nbits0, nbits1, GR_order, GR_order_sb, bits_pos0; - int16_t differential_subframe; - - nbits = 0; - nbits0 = 0; - nbits1 = 0; - - bits_pos0 = hMetaData->nb_bits_tot; - differential_subframe = 1; /* the differences are taken with respect to previous subframe */ - if ( sf == 0 ) /* first subframe */ - { - if ( no_ism == 2 ) - { - - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - index = index_slice_enum( ratio_ism_idx[b], no_ism ); - - push_next_indice( hMetaData, index, 3 ); - nbits += 3; - } - } - } - else if ( no_ism == 3 ) - { - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - index = index_slice_enum( ratio_ism_idx[b], no_ism ); - /* there are 36 indices and part of them use 5 bits; 31 is special code to - signal that there are indices larger than 31, represented on extra 3 bits */ - if ( index < 31 ) - { - push_next_indice( hMetaData, index, 5 ); - nbits += 5; - } - else - { - push_next_indice( hMetaData, 31, 5 ); - nbits += 5; - - push_next_indice( hMetaData, index - 31, 3 ); - nbits += 3; - } - } - } - } - else - { - if ( no_ism == 4 ) - { - for ( b = 0; b < numCodingBands; b++ ) - { - if ( masa_to_total_energy_ratio[b] < MASA2TOTAL_THR ) - { - index = index_slice_enum( ratio_ism_idx[b], no_ism ); - push_next_indice( hMetaData, index, 7 ); - nbits += 7; - } - } - } - } -#ifdef DEBUGGING - assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); -#endif - } - else - { - nbits0 = 0; - nbits1 = 0; - for ( b = 0; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); - transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); - /* GR encoding estimate length */ - for ( i = 0; i < no_ism - 1; i++ ) - { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - } - if ( nbits0 < nbits1 ) - { - GR_order = 0; - nbits = nbits0; - } - else - { - GR_order = 1; - nbits = nbits1; - } - if ( numCodingBands > 1 ) - { - /* try the difference from subband to subband; first subband is compared to previous subframe first subband*/ - /* take difference with respect to previous subframe only for first subband */ - nbits0 = 0; - nbits1 = 0; - - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - /* transform difference index into positive */ - transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); - /* GR encoding */ - for ( i = 0; i < no_ism - 1; i++ ) - { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - - - for ( b = 1; b < numCodingBands; b++ ) - { - - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); - /* transform difference index into positive */ - transform_difference_index( diff_idx, diff_idx, no_ism - 1 ); - /* GR encoding */ - - for ( i = 0; i < no_ism - 1; i++ ) - { - nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); - nbits1 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 1 ); - } - } - - if ( nbits0 < nbits1 ) - { - GR_order_sb = 0; - } - else - { - GR_order_sb = 1; - nbits0 = nbits1; - } - - if ( nbits0 < nbits ) - { - differential_subframe = 0; - nbits = nbits0; - GR_order = GR_order_sb; - } - - nbits++; /* for GR_order */ - nbits++; /* for the prediction type */ - - /* write prediction type */ - push_next_indice( hMetaData, differential_subframe, 1 ); - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - /* write data */ - if ( differential_subframe ) - { - for ( b = 0; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - } - } - else - { - v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - - for ( b = 1; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subband */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx[b - 1], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - } - } - } - else - { - /* only differential wrt previous subframe is possible */ - /* write the differential to subframe case and no bit to signal the difference type */ - - /* write GR order */ - push_next_indice( hMetaData, GR_order, 1 ); - nbits++; /* for GR_order */ - /* write data */ - - for ( b = 0; b < numCodingBands; b++ ) - { - /* take difference with respect to previous subframe */ - v_sub_s( ratio_ism_idx[b], ratio_ism_idx_prev_sf[b], diff_idx, no_ism ); - transform_index_and_GR_encode( diff_idx, no_ism - 1, GR_order, hMetaData ); - } - } - -#ifdef DEBUGGING - assert( nbits == ( hMetaData->nb_bits_tot - bits_pos0 ) ); -#endif - } - - return nbits; -} -#endif static void ivas_encode_masaism_metadata( @@ -3138,12 +2803,9 @@ static void ivas_encode_masaism_metadata( ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ const int16_t omasa_nbands, - const int16_t omasa_nblocks -#ifdef REDUCE_OMASA_META_BITS - , + const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp -#endif ) { int16_t sf, band; @@ -3153,9 +2815,6 @@ static void ivas_encode_masaism_metadata( float eneBand; int16_t bin; int16_t obj; -#ifndef REDUCE_OMASA_META_BITS - float priority[MAX_NUM_OBJECTS]; -#endif int16_t bits_ism[MAX_NUM_OBJECTS]; uint16_t idx_sph; float theta_q, phi_q; @@ -3165,10 +2824,9 @@ static void ivas_encode_masaism_metadata( float step; int16_t inv_step; float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; -#ifdef REDUCE_OMASA_META_BITS int16_t tmp, rotate; int16_t n_ism_tmp, i; -#endif + /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; @@ -3295,10 +2953,10 @@ static void ivas_encode_masaism_metadata( { inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); step = 1.0f / inv_step; -#ifdef REDUCE_OMASA_META_BITS + rotate = 0; n_ism_tmp = 0; -#endif + for ( sf = 0; sf < numSf; sf++ ) { for ( band = 0; band < numCodingBands; band++ ) @@ -3308,8 +2966,7 @@ static void ivas_encode_masaism_metadata( assert( ( hMasa->data.energy_ratio_ism[sf][band][obj] >= 0 ) && ( hMasa->data.energy_ratio_ism[sf][band][obj] <= 1 ) ); ratio_ism[band][obj] = hMasa->data.energy_ratio_ism[sf][band][obj]; } - /* Quantize power ratios */ -#ifdef REDUCE_OMASA_META_BITS + /* Quantize ISM ratios */ quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { @@ -3328,15 +2985,12 @@ static void ivas_encode_masaism_metadata( } } } -#else - quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band] ); -#endif + /* reconstructed values */ reconstruct_ism_ratios( ratio_ism_idx[band], hMasa->data.nchan_ism, step, hMasa->data.q_energy_ratio_ism[sf][band] ); /* encode vector */ } -#ifdef REDUCE_OMASA_META_BITS if ( ( hMasa->data.nchan_ism > 2 ) && ( idx_separated_object == hMasa->data.nchan_ism - 1 ) ) { /* rotate components */ @@ -3376,10 +3030,8 @@ static void ivas_encode_masaism_metadata( } } } -#endif - /* encode data for current subframe */ -#ifdef REDUCE_OMASA_META_BITS + /* encode data for current subframe */ if ( sf > 0 && n_ism_tmp == numCodingBands ) { encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); @@ -3388,9 +3040,7 @@ static void ivas_encode_masaism_metadata( { encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); } -#else - encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf] ); -#endif + /* calculate quantized ISM ratios */ /* save previous subframe indexes */ @@ -3398,7 +3048,7 @@ static void ivas_encode_masaism_metadata( { mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], hMasa->data.nchan_ism ); } -#ifdef REDUCE_OMASA_META_BITS + if ( rotate ) { for ( band = 0; band < numCodingBands; band++ ) @@ -3411,44 +3061,48 @@ static void ivas_encode_masaism_metadata( } } } -#endif - } -#ifndef REDUCE_OMASA_META_BITS - set_f( priority, 0.0f, hMasa->data.nchan_ism ); - for ( sf = 0; sf < numSf; sf++ ) - { - for ( band = 0; band < numCodingBands; band++ ) - { - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) - { - priority[obj] = max( priority[obj], ( hMasa->data.q_energy_ratio_ism[sf][band][obj] * hQMetaData->masa_to_total_energy_ratio[sf][band] ) ); - } - } + } -#endif } -#ifndef REDUCE_OMASA_META_BITS - else - { - priority[0] = 1; - } -#endif -#ifdef REDUCE_OMASA_META_BITS + + calculate_nbits_meta( hMasa->data.nchan_ism, hMasa->data.q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); -#else - /* decide parameters for ISM metadata quantization */ - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) - { - bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - priority[obj] ) * 7 ); - } -#endif + /* quantize directions */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) - { + { +#ifdef OMASA_UPDATES + if ( bits_ism[obj] < 8 ) + { + /* check is same as previous */ + if ( ( fabs( hIsmMeta[obj]->elevation - hIsmMeta[obj]->q_elevation_old ) < 0.01f ) && ( fabs( hIsmMeta[obj]->azimuth - hIsmMeta[obj]->q_azimuth_old ) < 0.01f ) ) + { + push_next_indice( hMetaData, 1, 1 ); + /* the old stays the same */ + } + else + { + push_next_indice( hMetaData, 0, 1 ); + idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; + hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + } + } + else + { + idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); + push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); + hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; + hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; + } + +#else idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); +#endif } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index e9ccefe357..935ea5e342 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -51,11 +51,7 @@ *------------------------------------------------------------------------*/ static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], -#ifdef OMASA_DIFFUSE_ISM_MERGE - float diffuseness_m[MASA_FREQUENCY_BANDS], -#endif - const int16_t input_frame, - const int16_t nchan_inp ); + float diffuseness_m[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); @@ -131,13 +127,8 @@ ivas_error ivas_omasa_enc_open( for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { -#ifdef OMASA_DIFFUSE_ISM_MERGE hOMasa->direction_vector_m[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ); set_zero( hOMasa->direction_vector_m[i][j], MASA_FREQUENCY_BANDS ); -#else - hOMasa->direction_vector_m[i][j] = (float *) malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); - set_zero( hOMasa->direction_vector_m[i][j], MAXIMUM_OMASA_FREQ_BANDS ); -#endif } } @@ -145,13 +136,8 @@ ivas_error ivas_omasa_enc_open( { for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { -#ifdef OMASA_DIFFUSE_ISM_MERGE hOMasa->buffer_intensity_real[i][j] = (float *) malloc( MASA_FREQUENCY_BANDS * sizeof( float ) ); set_zero( hOMasa->buffer_intensity_real[i][j], MASA_FREQUENCY_BANDS ); -#else - hOMasa->buffer_intensity_real[i][j] = (float *) malloc( MAXIMUM_OMASA_FREQ_BANDS * sizeof( float ) ); - set_zero( hOMasa->buffer_intensity_real[i][j], MAXIMUM_OMASA_FREQ_BANDS ); -#endif } } @@ -240,17 +226,18 @@ void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs /* i : Input sample rate */ -#ifdef OMASA_DIFFUSE_ISM_MERGE , ISM_MODE ismMode /* i : ISM mode */ -#endif ) { uint8_t i, maxBin; /* Determine the number of bands */ -#ifdef OMASA_DIFFUSE_ISM_MERGE +#ifdef OMASA_UPDATES + if ( ismMode == ISM_MODE_NONE || ismMode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( ismMode == ISM_MODE_NONE ) +#endif { /* use full resolution for the ISM+MASA merge and reduce later */ hOMasa->nbands = 24; @@ -259,9 +246,7 @@ void ivas_omasa_set_config( { hOMasa->nbands = hMasa->config.numCodingBands; } -#else - hOMasa->nbands = hMasa->config.numCodingBands; -#endif + hOMasa->nCodingBands = hMasa->config.numCodingBands; /* Determine the number of subframes */ @@ -310,9 +295,6 @@ void ivas_omasa_set_config( void ivas_omasa_enc( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ -#ifndef OMASA_DIFFUSE_ISM_MERGE - IVAS_QMETADATA_HANDLE hQMeta, /* i/o: Qmetadata handle */ -#endif MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ float data_in_f[][L_FRAME48k], /* i/o: Input / transport audio signals */ @@ -327,6 +309,11 @@ void ivas_omasa_enc( int16_t i, j; float data_out_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; + +#ifdef OMASA_UPDATES + /* Determine separated object (when applicable) */ + if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else /* Analysis */ if ( ism_mode == ISM_MODE_NONE ) { @@ -455,6 +442,7 @@ void ivas_omasa_enc( ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); } else +#endif { float broadband_energy[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; int16_t loudest_object; @@ -569,11 +557,90 @@ void ivas_omasa_enc( { set_zero( data_in_f[selected_object], input_frame ); } +#ifdef OMASA_UPDATES + } + + /* Analysis */ + if ( ism_mode == ISM_MODE_NONE || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + OMASA_SPATIAL_META OMasaMeta; /* working memory for the ISM-object MASA-parameters */ + OMASA_SPATIAL_META_HANDLE hOMasaMeta; + uint8_t n_bands_orig, n_subframes_orig; + uint8_t numCodingBands_orig, joinedSubframes_orig; + + hOMasaMeta = &OMasaMeta; + hOMasaMeta->num_dirs = 1; /* TODO: hard-coding for now */ + + /* merge MASA directions before adding ISM to the mixture */ + if ( hMasa->config.numberOfDirections == 2 ) + { + n_bands_orig = hMasa->config.numCodingBands; + hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; + + ivas_masa_combine_directions( hMasa ); + + hMasa->config.numCodingBands = (int8_t)n_bands_orig; + } + + /* force computation into high resolution */ + n_bands_orig = hOMasa->nbands; + n_subframes_orig = hOMasa->nSubframes; + + hOMasa->nbands = MASA_FREQUENCY_BANDS; + hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; + + /* Estimate MASA parameters from the objects */ + /* NB: only first direction is populated */ + /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ + ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], + hOMasaMeta->common_meta.diffuse_to_total_ratio[0], input_frame, nchan_ism ); + + /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + mvr2r( hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].energy_ratio[i], MASA_FREQUENCY_BANDS ); + mvr2r( hOMasaMeta->common_meta.surround_coherence[0], hOMasaMeta->common_meta.surround_coherence[i], MASA_FREQUENCY_BANDS ); + mvr2r( hOMasaMeta->common_meta.diffuse_to_total_ratio[0], hOMasaMeta->common_meta.diffuse_to_total_ratio[i], MASA_FREQUENCY_BANDS ); + } + + /* restore resolution parameters */ + hOMasa->nbands = n_bands_orig; + hOMasa->nSubframes = n_subframes_orig; + + /* perform MASA+ISM merge in full resolution */ + numCodingBands_orig = hMasa->config.numCodingBands; + joinedSubframes_orig = hMasa->config.joinedSubframes; + + hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; + hMasa->config.joinedSubframes = 0; + + ivas_merge_masa_metadata( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ + + hMasa->config.numCodingBands = numCodingBands_orig; + hMasa->config.joinedSubframes = joinedSubframes_orig; + + } + else if ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + if ( ism_mode == ISM_MASA_MODE_PARAM ) + { + *idx_separated_object = -1; + } +#endif /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); } +#ifdef OMASA_UPDATES + /* Move the ISM metadata to the first entry for encoding in the MASA_ONE_OBJ mode */ + if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + hIsmMeta[0]->azimuth = hIsmMeta[*idx_separated_object]->azimuth; + hIsmMeta[0]->elevation = hIsmMeta[*idx_separated_object]->elevation; + } +#endif + /* Downmix */ ivas_omasa_dmx( data_in_f, data_out_f, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains, hOMasa->interpolator ); @@ -584,7 +651,6 @@ void ivas_omasa_enc( } -#ifdef OMASA_BRATE /*-------------------------------------------------------------------------* * set_ism_importance_interformat() * @@ -665,6 +731,11 @@ void ivas_set_surplus_brate_enc( #endif ) { +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp @@ -673,9 +744,14 @@ void ivas_set_surplus_brate_enc( 0 #endif ); +#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) +#else else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) +#endif { /* it is already set in ivas_ism_enc() */ } @@ -689,7 +765,12 @@ void ivas_set_surplus_brate_enc( { int16_t input_frame = (int16_t) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); float tmpF = 0; +#ifdef OMAOMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) +#endif { tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); } @@ -711,7 +792,6 @@ void ivas_set_surplus_brate_enc( return; } -#endif /*--------------------------------------------------------------------------* @@ -729,9 +809,7 @@ static void ivas_omasa_param_est_enc( float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], -#ifdef OMASA_DIFFUSE_ISM_MERGE float diffuseness_m[MASA_FREQUENCY_BANDS], -#endif const int16_t input_frame, const int16_t nchan_ism ) { @@ -747,9 +825,6 @@ static void ivas_omasa_param_est_enc( float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float diffuseness_vector[MASA_FREQUENCY_BANDS]; -#ifndef OMASA_DIFFUSE_ISM_MERGE - float diffuseness_m[MASA_FREQUENCY_BANDS]; -#endif int16_t band_m_idx, block_m_idx; float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index b64eb4adbf..b6d2b86382 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -5263,6 +5263,10 @@ void encode_masa_to_total( n_streams = 1; len_stream = nbands; break; + case 12: + matrix_product( dct12, nbands, nbands, 0, data, 1, nbands, 1, dct_data ); + n_streams = 1; + len_stream = nbands; break; case 20: matrix_product( dct5, nbands, nbands, 0, data, nblocks, nbands, 1, dct_data_tmp ); @@ -5277,6 +5281,7 @@ void encode_masa_to_total( len_stream = nbands; break; default: + printf( "Incorrect number of coefficients for OMASA.\n" ); break; } @@ -5352,6 +5357,10 @@ void encode_masa_to_total( matrix_product( dct8, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); mvr2r( dct_data_tmp, q_dct_data, nbands ); break; + case 12: + matrix_product( dct12, nbands, nbands, 1, q_dct_data, nbands, 1, 0, dct_data_tmp ); + mvr2r( dct_data_tmp, q_dct_data, nbands ); + break; case 20: matrix_product( dct5, nbands, nbands, 1, q_dct_data, nbands, nblocks, 0, dct_data_tmp ); matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); /* reuse of variable*/ @@ -5361,6 +5370,7 @@ void encode_masa_to_total( matrix_product( dct_data_tmp, nbands, nblocks, 0, dct4, nblocks, nblocks, 0, q_dct_data ); break; default: + printf( "Incorrect number of coefficients for OMASA.\n" ); break; } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index dde49fb9cd..769e5fe970 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -144,7 +144,11 @@ ivas_error ivas_sce_enc( if ( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL ) { #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( ( ( st_ivas->mc_mode == MC_MODE_MCMASA ) && ( st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) ) || ( st_ivas->ism_mode >= ISM_MASA_MODE_MASA_ONE_OBJ ) ) +#else if ( ( ( st_ivas->mc_mode == MC_MODE_MCMASA ) && ( st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) ) || ( st_ivas->ism_mode >= ISM_MASA_MODE_ONE_OBJ ) ) +#endif #else if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) #endif @@ -220,11 +224,19 @@ ivas_error ivas_sce_enc( reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode ); -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS /*----------------------------------------------------------------* * Combined format coding: get the ISM importance and the bit-rate *----------------------------------------------------------------*/ +#ifdef OMASA_UPDATES + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); + + st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; + } +#else if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) { set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); @@ -237,6 +249,7 @@ ivas_error ivas_sce_enc( ) - nb_bits_metadata * FRAMES_PER_SEC; } +#endif #endif /*----------------------------------------------------------------* @@ -257,8 +270,12 @@ ivas_error ivas_sce_enc( { st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st->low_rate_mode ) +#else else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st->low_rate_mode ) +#endif { st->flag_ACELP16k = 0; } @@ -370,7 +387,11 @@ ivas_error create_sce_enc( copy_encoder_config( st_ivas, st, 1 ); #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { st->element_mode = IVAS_SCE; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index c1df19f243..ad7cee3ce1 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -746,9 +746,7 @@ typedef struct ivas_masa_encoder_data_struct float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t nchan_ism; -#ifdef OMASA_BRATE float lp_noise_CPE; /* LP filterend total noise estimation */ -#endif #endif int16_t num_Cldfb_instances; @@ -948,7 +946,7 @@ typedef struct cpe_enc_data_structure float *input_mem[CPE_CHANNELS]; /* input channels buffers memory; needed to be up-to-date for TD->DFT stereo switching */ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS int32_t brate_surplus; /* bitrate surplus for bitrate adaptation in combined format coding */ #endif #ifdef DEBUGGING diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index d4d0b310b6..b2e3373404 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -118,8 +118,11 @@ int16_t select_stereo_mode( { stereo_switching_flag = 0; } - +#ifdef OMASA_UPDATES + if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO && !( hCPE->element_brate == IVAS_48k && ivas_total_brate == IVAS_32k ) ) /* the second condition for PARAM mode OMASA */ +#else if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO ) +#endif { hStereoClassif->prev_lrtd_mode = 0; hStereoClassif->lrtd_mode = 0; diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 5ccacf4807..e0d5db28a6 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -445,7 +445,7 @@ void stereo_mdct_core_enc( sts[ch]->total_brate = ( sts[ch]->bits_frame_channel + sts[ch]->side_bits_frame_channel ) * FRAMES_PER_SEC; } stereo_bits += SMDCT_NBBITS_SPLIT_RATIO; -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS assert( ( sts[0]->total_brate + sts[1]->total_brate + ( stereo_bits + signal_bits + meta_bits ) * FRAMES_PER_SEC ) == hCPE->element_brate + hCPE->brate_surplus ); #else assert( ( sts[0]->total_brate + sts[1]->total_brate + ( stereo_bits + signal_bits + meta_bits ) * FRAMES_PER_SEC ) == hCPE->element_brate ); diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index c819c887c5..2105b351b3 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -419,7 +419,7 @@ void tdm_configure_enc( sts[1]->coder_type = GENERIC; } -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) { sts[1]->coder_type = INACTIVE; @@ -469,7 +469,7 @@ void tdm_configure_enc( * bitbudget distribution between channels (taking into account also metadata bitbudget) *----------------------------------------------------------------*/ -#ifdef OMASA_BRATE +#ifdef MASA_AND_OBJECTS tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 72ac9311c5..db6bf0293e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -448,6 +448,12 @@ static void ivas_dirac_dec_binaural_internal( /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + { + numInChannels++; + } +#else if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) { if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) @@ -459,6 +465,7 @@ static void ivas_dirac_dec_binaural_internal( numInChannels++; } } +#endif #else if ( st_ivas->hOutSetup.separateChannelEnabled ) { @@ -583,7 +590,11 @@ static void ivas_dirac_dec_binaural_internal( } #ifdef MASA_AND_OBJECTS +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) +#else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) +#endif { preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, @@ -1174,14 +1185,20 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #ifdef MASA_AND_OBJECTS separateCenterChannelRendering = 0; nchanSeparateChannels = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) +#else if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) +#endif { separateCenterChannelRendering = 1; nchanSeparateChannels = 1; +#ifndef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; } +#endif } #else separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; @@ -1325,11 +1342,27 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #ifdef MASA_AND_OBJECTS uint8_t instantChange = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + gainFactor = 0.7943f * sqrtf( h->earlyPartEneCorrection[bin] ); /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ + } + else + { + gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); + } +#else gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); +#endif for ( chB = 0; chB < nchanSeparateChannels; chB++ ) { if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifdef OMASA_UPDATES + aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism; + eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; + instantChange = 1; +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB]; @@ -1341,6 +1374,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; instantChange = 1; } +#endif } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index b60967e7f7..5a2b0e3454 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -182,7 +182,15 @@ ivas_error ivas_td_binaural_open_unwrap( } *hBinRendererTd = pBinRendTd; + +#ifdef OMASA_UPDATES + if ( ivas_format != MASA_ISM_FORMAT ) + { + *binaural_latency_ns = (int32_t) ( ( *hBinRendererTd )->HrFiltSet_p->latency_s * 1000000000.f ); + } +#else *binaural_latency_ns = (int32_t) ( ( *hBinRendererTd )->HrFiltSet_p->latency_s * 1000000000.f ); +#endif return error; } @@ -440,7 +448,11 @@ void TDREND_Update_object_positions( c_indx++; } +#ifdef OMASA_UPDATES + if ( in_format == ISM_FORMAT || in_format == MASA_ISM_FORMAT ) +#else if ( in_format == ISM_FORMAT ) +#endif { /* Update the source positions */ -- GitLab From 69090cd6c7d06e7e6ed200797e1477fb2e653eda Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 28 Mar 2023 16:31:49 +0200 Subject: [PATCH 053/173] - simplifications in ivas_dec() - add error returns --- lib_dec/ivas_dec.c | 91 ++++++++++++++++++++++++++--------------- lib_dec/ivas_init_dec.c | 15 +++++-- lib_enc/ivas_ism_enc.c | 24 ++++++----- 3 files changed, 84 insertions(+), 46 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 871e454605..c53b8b68a9 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -451,7 +451,7 @@ ivas_error ivas_dec( } } - /* MASA decoding */ + /* MASA metadata decoding */ if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; @@ -462,7 +462,25 @@ ivas_error ivas_dec( st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - /* Audio signal decoding */ +#ifdef OMASA_UPDATES + /* set ISM parameters */ + int16_t nchan_ism, nchan_transport_ism; + nchan_ism = st_ivas->nchan_ism; + nchan_transport_ism = st_ivas->nchan_ism; + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + nchan_ism = 1; + nchan_transport_ism = 1; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + nchan_ism = 0; + nchan_transport_ism = 1; + } +#endif + + /* decode ISM metadata */ +#ifndef OMASA_UPDATES #ifdef OMASA_UPDATES if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) #else @@ -471,10 +489,7 @@ ivas_error ivas_dec( { if ( st_ivas->nSCE == 1 ) { - if ( ( error = ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ); } else { @@ -484,24 +499,19 @@ ivas_error ivas_dec( } } else - { -#ifdef OMASA_UPDATES - int16_t nchan_ism = st_ivas->nchan_ism; - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { - nchan_ism = 1; - } +#else + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) #endif - - /* decode ISM format */ + { + /* decode ISM metadata */ #ifdef NCHAN_ISM_PARAMETER if ( ( error = ivas_ism_metadata_dec( ism_total_brate, #ifdef OMASA_UPDATES - nchan_ism, + nchan_ism, &nchan_transport_ism, #else - st_ivas->nchan_ism, + st_ivas->nchan_ism, &( st_ivas->nSCE ), #endif - &( st_ivas->nSCE ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, st_ivas->hISMDTX, NULL ) ) != IVAS_ERR_OK ) + st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, st_ivas->hISMDTX, NULL ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_metadata_dec( ism_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, NULL, NULL ) ) != IVAS_ERR_OK ) #endif @@ -509,19 +519,7 @@ ivas_error ivas_dec( return error; } - for ( n = 0; n < st_ivas->nSCE - 1; n++ ) - { - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) - { - return error; - } - + // VE: move the following updates into ivas_ism_metadata_dec() #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -531,7 +529,7 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); } } - else + else /* ISM_MASA_MODE_MASA_ONE_OBJ */ { st_ivas->hMasaIsmData->azimuth_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); st_ivas->hMasaIsmData->elevation_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); @@ -543,8 +541,35 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); } #endif + +#ifndef OMASA_UPDATES + for ( n = 0; n < st_ivas->nSCE - 1; n++ ) + { + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } +#ifdef OMASA_UPDATES + /* decode ISM channels */ + for ( n = 0; n < nchan_transport_ism; n++ ) + { + if ( ( error = ivas_sce_dec( st_ivas, n, &output[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + + /* decode MASA channels */ if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { return error; @@ -575,7 +600,7 @@ ivas_error ivas_dec( for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + mvr2r( output[2 + n], data_separated_objects[n], output_frame ); v_multc( data_separated_objects[n], gain, data_separated_objects[n], output_frame ); } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 329e62f932..e9300d6cf6 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1132,7 +1132,10 @@ ivas_error ivas_init_decoder( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - ivas_qmetadata_open( &( st_ivas->hQMetaData ) ); + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } k = 0; ism_total_brate = 0; @@ -1150,7 +1153,10 @@ ivas_error ivas_init_decoder( st_ivas->nSCE = 1; ism_total_brate = sep_object_brate[k - 2][0]; - create_sce_dec( st_ivas, 0, ism_total_brate ); + if ( ( error = create_sce_dec( st_ivas, 0, ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; + } reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); @@ -1221,7 +1227,10 @@ ivas_error ivas_init_decoder( if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) { - ivas_dirac_dec_open( st_ivas ); + if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } if ( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 3abaa72637..acdf2b4a5b 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -98,7 +98,7 @@ ivas_error ivas_ism_enc( #endif ivas_error error; #ifdef MASA_AND_OBJECTS - int16_t i, nchan_transport; + int16_t i, nchan_transport_ism; #endif push_wmops( "ivas_ism_enc" ); @@ -132,18 +132,18 @@ ivas_error ivas_ism_enc( set_s( md_diff_flag, 1, nchan_ism ); #ifdef MASA_AND_OBJECTS - nchan_transport = st_ivas->nchan_transport; + nchan_transport_ism = st_ivas->nchan_transport; #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - nchan_transport = 1; + nchan_transport_ism = 1; nchan_ism = 1; } else #endif if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - nchan_transport = st_ivas->hEncoderConfig->nchan_ism; + nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; } #endif @@ -151,10 +151,10 @@ ivas_error ivas_ism_enc( * Preprocesing *-----------------------------------------------------------------*/ - /* in ISM format: st_ivas->nchan_transport = st_ivas->nSCE */ #ifdef MASA_AND_OBJECTS - for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) #else + /* in ISM format: st_ivas->nchan_transport = st_ivas->nSCE */ for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) #endif { @@ -303,7 +303,7 @@ ivas_error ivas_ism_enc( nchan_ism, #endif #ifdef MASA_AND_OBJECTS - nchan_transport, + nchan_transport_ism, #else st_ivas->nchan_transport, #endif @@ -352,7 +352,7 @@ ivas_error ivas_ism_enc( nchan_ism, #endif #ifdef MASA_AND_OBJECTS - nchan_transport, + nchan_transport_ism, #else st_ivas->nchan_transport, #endif @@ -411,7 +411,7 @@ ivas_error ivas_ism_enc( *-----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) #else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) #endif @@ -471,7 +471,7 @@ ivas_error ivas_ism_enc( if ( dtx_flag ) { #ifdef MASA_AND_OBJECTS - for ( sce_id = 0; sce_id < nchan_transport; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) #else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) #endif @@ -493,7 +493,11 @@ ivas_error ivas_ism_enc( int16_t id, n; n = 0; +#ifdef MASA_AND_OBJECTS + for ( sce_id = 0; sce_id < nchan_transport_ism; sce_id++ ) +#else for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) +#endif { if ( sce_id != st_ivas->hISMDTX->sce_id_dtx ) { -- GitLab From 60715ab59244564e9b8dbf28f4feaf645b170c19 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 28 Mar 2023 18:20:08 +0200 Subject: [PATCH 054/173] decoder BR switching updates --- lib_dec/ivas_init_dec.c | 15 +++++----- lib_dec/ivas_ism_dec.c | 14 +++++----- lib_dec/ivas_omasa_dec.c | 60 ++++++++++++++++++++++++++++++++++++++-- lib_enc/ivas_init_enc.c | 5 ++-- lib_enc/ivas_omasa_enc.c | 8 ++++-- 5 files changed, 80 insertions(+), 22 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e9300d6cf6..6b55ee6a0b 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1160,6 +1160,12 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); +#ifdef OMASA_BRATE_SW + if ( ( error = ivas_ism_metadata_dec_create( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) + { + return error; + } +#else #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { @@ -1172,23 +1178,17 @@ ivas_error ivas_init_decoder( } else { -#ifdef OMASA_BRATE_SW - if ( ( error = ivas_ism_metadata_dec_create( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) - { - return error; - } -#else if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); } -#endif } #else if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); } +#endif #endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) @@ -1535,6 +1535,7 @@ ivas_error ivas_init_decoder( } #ifdef OMASA_UPDATES + // VE: introduce a new renderer_type for this case if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) { /* Use td renderer for the objects in DISC mode */ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index b6f33df845..1c908998a4 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -52,7 +52,7 @@ static ivas_error ivas_ism_bitrate_switching( const ISM_MODE last_ism_mode /* i : last ISM mode */ #ifndef NCHAN_ISM_PARAMETER , - const int16_t num_obj /* i : number of objects in the bitstream */ + const int16_t num_obj /* i : number of objects in the bitstream */ #endif ) { @@ -71,14 +71,14 @@ static ivas_error ivas_ism_bitrate_switching( , 0 #endif - ) ) != IVAS_ERR_OK ) + ) ) != IVAS_ERR_OK ) #else - if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL + if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL #ifdef MASA_AND_OBJECTS , 0 #endif -) ) != IVAS_ERR_OK ) + ) ) != IVAS_ERR_OK ) #endif { return error; @@ -209,7 +209,7 @@ static ivas_error ivas_ism_bitrate_switching( ivas_td_binaural_close( &st_ivas->hBinRendererTd ); } - if ( st_ivas->hHrtfTD != NULL ) + if ( st_ivas->hHrtfTD != NULL ) // VE: this looks suspicious { st_ivas->hHrtfTD = NULL; } @@ -261,7 +261,7 @@ ivas_error ivas_ism_dec_config( #endif #ifndef NCHAN_ISM_PARAMETER , - const int16_t num_obj /* i : number of objects in the bitstream */ + const int16_t num_obj /* i : number of objects in the bitstream */ #endif ) { @@ -334,11 +334,11 @@ ivas_error ivas_ism_dec_config( #endif { return error; + } } } } } - } else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) { #ifdef DISCRETE_ISM_DTX_CNG diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index c3f1d35fdc..8ef1dbf26e 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -35,6 +35,9 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" +#ifdef OMASA_UPDATES +#include "ivas_prot_rend.h" +#endif #ifdef OMASA_BRATE_SW #include "ivas_rom_com.h" #endif @@ -147,7 +150,6 @@ ivas_error ivas_omasa_dec_config( ivas_error error; /* initializations */ - error = IVAS_ERR_OK; ism_total_brate = 0; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -229,13 +231,16 @@ ivas_error ivas_omasa_dec_config( } } - if ( ism_mode_old != st_ivas->ism_mode ) { /* ISM MD reconfig. */ n_MD = 0; +#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#endif { n_MD = 1; @@ -270,7 +275,11 @@ ivas_error ivas_omasa_dec_config( st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; /* objects renderer reconfig. */ +#ifdef OMASA_UPDATES + if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#else if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) +#endif { if ( st_ivas->hIsmRendererData == NULL ) { @@ -279,7 +288,11 @@ ivas_error ivas_omasa_dec_config( return error; } } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#else else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) +#endif { for ( n = 1; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) { @@ -313,8 +326,13 @@ ivas_error ivas_omasa_dec_config( mvr2r( tmp, st_ivas->hMasaIsmData->delayBuffer[0], st_ivas->hMasaIsmData->delayBuffer_size ); } } +#ifdef OMASA_UPDATES + else if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) +#else else if ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) +#endif { + // VE: use ivas_masa_ism_data_close() instead? for ( n = 0; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) { free( st_ivas->hMasaIsmData->delayBuffer[n] ); @@ -325,9 +343,45 @@ ivas_error ivas_omasa_dec_config( free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } + +#ifdef OMASA_UPDATES + // VE: introduce a new renderer_type for this case + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + { + /* Use td renderer for the objects in DISC mode */ + error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, + st_ivas->transport_config, +#ifdef TD5 + st_ivas->hRenderConfig->directivity, +#endif + st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); + if ( ( error ) != IVAS_ERR_OK ) + { + return error; + } + + /* Reserve memory for delay buffer */ + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( st_ivas->hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + } + + if ( st_ivas->hHrtfTD != NULL ) // VE: this is copied from ivas_ism_bitrate_switching() but a review is needed + { + st_ivas->hHrtfTD = NULL; + } + } +#endif } - return error; + return IVAS_ERR_OK; } #endif diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 8b8c4bfd4f..1fd102c07c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -633,10 +633,11 @@ ivas_error ivas_init_encoder( return error; } } + #ifdef OMASA_UPDATES - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM) ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) #else - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) #endif { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 4f9148e228..2ec461d5f9 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -232,11 +232,9 @@ ivas_error ivas_omasa_enc_config( ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; - error = IVAS_ERR_OK; hEncoderConfig = st_ivas->hEncoderConfig; ivas_total_brate = hEncoderConfig->ivas_total_brate; - //ivas_masa_enc_reconfigure( st_ivas ); // VE: might not be needed @@ -311,7 +309,11 @@ ivas_error ivas_omasa_enc_config( st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; +#ifdef OMASA_UPDATES + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) +#else if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) +#endif { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } @@ -333,7 +335,7 @@ ivas_error ivas_omasa_enc_config( ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); } - return error; + return IVAS_ERR_OK; } #endif -- GitLab From fd62e881c4956ea826ae27751040ac8e6f6a597d Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 28 Mar 2023 19:55:46 +0200 Subject: [PATCH 055/173] fix decoder BR switching --- lib_dec/ivas_cpe_dec.c | 9 ++++----- lib_dec/ivas_omasa_dec.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 92b0668072..b52c2ea054 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -249,11 +249,9 @@ ivas_error ivas_cpe_dec( nb_bits -= SID_FORMAT_NBITS; sts[1]->bit_stream -= SID_FORMAT_NBITS; } -#ifdef MASA_AND_OBJECTS - if ( ( ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) || - ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) ) ) && - ivas_total_brate > IVAS_SID_5k2 ) +#ifdef MASA_AND_OBJECTS + if ( ( ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) || ( st_ivas->ivas_format == MASA_ISM_FORMAT && cpe_brate < MASA_STEREO_MIN_BITRATE ) ) && ivas_total_brate > IVAS_SID_5k2 ) #else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) #endif @@ -373,6 +371,7 @@ ivas_error ivas_cpe_dec( /*----------------------------------------------------------------* * Core codec configuration *----------------------------------------------------------------*/ + for ( n = 0; n < n_channels; n++ ) { /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ @@ -1116,7 +1115,7 @@ static void read_stereo_mode_and_bwidth( { /* read stereo technology info */ #ifdef OMASA_UPDATES - if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k) ) + if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k ) ) #else if ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 8ef1dbf26e..52812b6fb3 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -187,6 +187,16 @@ ivas_error ivas_omasa_dec_config( return error; } + // VE!!!!!: verification needed, see comment "/* Todo: Nokia make for MASA_ISM*/" in ivas_masa_dec_reconfigure() + if ( cpe_brate < MASA_STEREO_MIN_BITRATE ) + { + st_ivas->hCPE[0]->nchan_out = 1; + } + else + { + st_ivas->hCPE[0]->nchan_out = 2; + } + /* OMASA reconfig. */ if ( st_ivas->hMasaIsmData == NULL && st_ivas->ivas_format == MASA_ISM_FORMAT ) { -- GitLab From ef8970d96e6ef7cc6974b530e37d2811e8e825a5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Apr 2023 09:12:08 +0200 Subject: [PATCH 056/173] white spaces --- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_omasa_enc.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 128c63b114..0b0d03cd09 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -289,7 +289,7 @@ ivas_error ivas_cpe_enc( { #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) - { + { stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } else diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 2ec461d5f9..ef87fd21e4 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -948,7 +948,6 @@ static void ivas_omasa_param_est_enc( float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float diffuseness_vector[MASA_FREQUENCY_BANDS]; - int16_t band_m_idx, block_m_idx; float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; float norm_tmp; @@ -958,7 +957,6 @@ static void ivas_omasa_param_est_enc( num_freq_bands = hOMasa->nbands; l_ts = input_frame / CLDFB_NO_COL_MAX; - /* Need to initialize renormalization_factors, and variables to be normalized */ set_zero( renormalization_factor_diff, hOMasa->nbands ); set_zero( diffuseness_m, hOMasa->nbands ); @@ -1282,7 +1280,6 @@ static void ivas_omasa_dmx( } } - return; } -- GitLab From a6786399666a636b12605fed878db379a9e7ee49 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Apr 2023 10:47:56 +0200 Subject: [PATCH 057/173] fix memory deallocation in bitrate switching --- lib_dec/ivas_omasa_dec.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 6d9e3df5f4..2389512da3 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -158,7 +158,11 @@ ivas_error ivas_omasa_dec_config( st_ivas->ism_mode = ism_mode_old; ivas_format_old = st_ivas->ivas_format; +#ifdef OMASA_UPDATES + if ( ism_mode_old == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_DISC ) +#else if ( ism_mode_old == ISM_MASA_MODE_PARAM || ism_mode_old == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_DISC ) +#endif { st_ivas->ivas_format = MASA_ISM_FORMAT; } @@ -342,16 +346,7 @@ ivas_error ivas_omasa_dec_config( else if ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) #endif { - // VE: use ivas_masa_ism_data_close() instead? - for ( n = 0; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) - { - free( st_ivas->hMasaIsmData->delayBuffer[n] ); - } - free( st_ivas->hMasaIsmData->delayBuffer ); - st_ivas->hMasaIsmData->delayBuffer = NULL; - - free( st_ivas->hIsmRendererData ); - st_ivas->hIsmRendererData = NULL; + ivas_masa_ism_data_close( &( st_ivas->hMasaIsmData ) ); } #ifdef OMASA_UPDATES -- GitLab From e05ea4c7a9380d06ddd3d7dde4476368cb1f37fc Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Apr 2023 11:28:37 +0200 Subject: [PATCH 058/173] remove obsolete callings of ivas_masa_ism_separate_object_renderer_open() --- lib_dec/ivas_init_dec.c | 12 --------- lib_dec/ivas_omasa_dec.c | 57 +++------------------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 035cc5f430..88200f017d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1238,18 +1238,6 @@ ivas_error ivas_init_decoder( { reset_indices_dec( st_ivas->hCPE[0]->hCoreCoder[n] ); } - -#ifdef OMASA_UPDATES - if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif - { - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } } #endif else if ( st_ivas->ivas_format == MC_FORMAT ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 2389512da3..52e1dc0ea1 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -143,7 +143,7 @@ ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t k, n, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; + int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; int32_t ivas_total_brate, ism_total_brate, cpe_brate; IVAS_FORMAT ivas_format_old; ISM_MODE ism_mode_old; @@ -290,60 +290,9 @@ ivas_error ivas_omasa_dec_config( /* objects renderer reconfig. */ #ifdef OMASA_UPDATES - if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) + if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) #else - if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif - { - if ( st_ivas->hIsmRendererData == NULL ) - { - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#ifdef OMASA_UPDATES - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#endif - { - for ( n = 1; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) - { - free( st_ivas->hMasaIsmData->delayBuffer[n] ); - } - - st_ivas->hMasaIsmData->delayBuffer_nchan = 1; - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - float tmp[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - - st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; - - mvr2r( st_ivas->hMasaIsmData->delayBuffer[0], tmp, st_ivas->hMasaIsmData->delayBuffer_size ); - free( st_ivas->hMasaIsmData->delayBuffer[0] ); - free( st_ivas->hMasaIsmData->delayBuffer ); - if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); - } - - for ( n = 0; n < st_ivas->hMasaIsmData->delayBuffer_nchan; n++ ) - { - if ( ( st_ivas->hMasaIsmData->delayBuffer[n] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); - } - set_zero( st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); - } - mvr2r( tmp, st_ivas->hMasaIsmData->delayBuffer[0], st_ivas->hMasaIsmData->delayBuffer_size ); - } - } -#ifdef OMASA_UPDATES - else if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) -#else - else if ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) + if ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) #endif { ivas_masa_ism_data_close( &( st_ivas->hMasaIsmData ) ); -- GitLab From f9afcb5446fdb626ded2b6234aeb73293c0a2110 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Apr 2023 11:48:15 +0200 Subject: [PATCH 059/173] fix memory deallocation in bitrate switching --- lib_dec/ivas_init_dec.c | 4 ++-- lib_dec/ivas_omasa_dec.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 88200f017d..60e024383f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1517,7 +1517,7 @@ ivas_error ivas_init_decoder( // VE: introduce a new renderer_type for this case if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) { - /* Use td renderer for the objects in DISC mode */ + /* Allocate TD renderer for the objects in DISC mode */ error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); if ( ( error ) != IVAS_ERR_OK ) @@ -1525,7 +1525,7 @@ ivas_error ivas_init_decoder( return error; } - /* Reserve memory for delay buffer */ + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 52e1dc0ea1..b32a76b431 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -302,7 +302,7 @@ ivas_error ivas_omasa_dec_config( // VE: introduce a new renderer_type for this case if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { - /* Use td renderer for the objects in DISC mode */ + /* Allocate TD renderer for the objects in DISC mode */ if ( ( error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ) ) != IVAS_ERR_OK ) @@ -310,7 +310,7 @@ ivas_error ivas_omasa_dec_config( return error; } - /* Reserve memory for delay buffer */ + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -318,6 +318,7 @@ ivas_error ivas_omasa_dec_config( } else { + /* TD renderer handle */ if ( st_ivas->hBinRendererTd != NULL ) { ivas_td_binaural_close( &st_ivas->hBinRendererTd ); @@ -327,6 +328,13 @@ ivas_error ivas_omasa_dec_config( { st_ivas->hHrtfTD = NULL; } + + /* ISM renderer handle */ + if ( st_ivas->hIsmRendererData != NULL ) + { + free( st_ivas->hIsmRendererData ); + st_ivas->hIsmRendererData = NULL; + } } #endif } -- GitLab From 26a34518f96c44647368b9abb3e13b050823a6c0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 3 Apr 2023 12:51:11 +0200 Subject: [PATCH 060/173] - use native instead of wrapper functions for TD renderer - re-activate FIX_350_MASA_DELAY_COMP and FIX_382_MASA_META_FRAMING_ASYNC - compilation fixes when MASA_AND_OBJECTS is disabled --- lib_com/options.h | 4 +-- lib_dec/ivas_dec.c | 4 +-- lib_dec/ivas_init_dec.c | 8 +----- lib_dec/ivas_ism_metadata_dec.c | 2 ++ lib_dec/ivas_objectRenderer_internal.c | 37 +++++++++++++++++++++----- lib_dec/ivas_omasa_dec.c | 4 +-- lib_enc/ivas_ism_enc.c | 6 ++++- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 14 +++++----- 9 files changed, 52 insertions(+), 29 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7eb9eb4f35..6d0f913e0e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -144,12 +144,12 @@ #define FIX_103_RA_PARAMS_PARAM_BIN_REND /* Issue 103: Digest room acoustics parameters for Parametric Binaural Renderer*/ /*#define SBA_HPF_TUNING_DEC*/ -//#define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ +#define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ #define FIX_MDCT_BASED_BWD /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */ #define DISCRETE_ISM_DTX_CNG /* FhG/VA: contribution 15 - DTX/CNG for (discrete) ISM */ #define NCHAN_ISM_PARAMETER /* VA: make 'nchan_ism' parameter part of st_ivas/hEncoderConfig */ -//#define FIX_382_MASA_META_FRAMING_ASYNC /* Nokia: Issue 382: detect potential MASA metadata framing offset */ +#define FIX_382_MASA_META_FRAMING_ASYNC /* Nokia: Issue 382: detect potential MASA metadata framing offset */ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 4ceb3d5019..10147488c0 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -607,9 +607,7 @@ ivas_error ivas_dec( ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); - if ( ( error = ivas_td_binaural_renderer_unwrap( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, st_ivas->nchan_ism, LFE_CHANNEL, st_ivas->ivas_format, - st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, - ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Pos : NULL, data_separated_objects, output_frame ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_renderer( st_ivas, data_separated_objects, output_frame ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 60e024383f..e8fccfb9cf 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1518,9 +1518,7 @@ ivas_error ivas_init_decoder( if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) { /* Allocate TD renderer for the objects in DISC mode */ - error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, - st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); - if ( ( error ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1865,11 +1863,7 @@ void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { -#ifdef OMASA_BRATE_SW int16_t i; -#else - int16_t i, n; -#endif /* CLDFB handles */ for ( i = 0; i < MAX_INTERN_CHANNELS; i++ ) diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 4a0c8eb4f7..c28478b0ab 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -180,7 +180,9 @@ ivas_error ivas_ism_metadata_dec( #ifdef DISCRETE_ISM_DTX_CNG int16_t md_diff_flag[MAX_NUM_OBJECTS]; #endif +#ifdef MASA_AND_OBJECTS ivas_error error; +#endif push_wmops( "ism_meta_dec" ); diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index f1c1fc04f2..2b24b08398 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -53,8 +53,22 @@ ivas_error ivas_td_binaural_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef MASA_AND_OBJECTS + int16_t num_src; + + num_src = st_ivas->nchan_transport; + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + num_src = st_ivas->nchan_ism; + } + + return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, num_src, st_ivas->ivas_format, + st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); +#else + return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); +#endif } @@ -71,10 +85,21 @@ ivas_error ivas_td_binaural_renderer( const int16_t output_frame /* i : output frame length */ ) { - return ivas_td_binaural_renderer_unwrap( - st_ivas->hReverb, - st_ivas->transport_config, - st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, - st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, - ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Pos : NULL, output, output_frame ); +#ifdef MASA_AND_OBJECTS + int16_t num_src; + + num_src = st_ivas->nchan_transport; + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + num_src = st_ivas->nchan_ism; + } + + return ivas_td_binaural_renderer_unwrap( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, num_src, LFE_CHANNEL, st_ivas->ivas_format, + st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, + ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Pos : NULL, output, output_frame ); +#else + return ivas_td_binaural_renderer_unwrap( st_ivas->hReverb, st_ivas->transport_config, st_ivas->hBinRendererTd, st_ivas->nchan_transport, LFE_CHANNEL, st_ivas->ivas_format, + st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, + ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Pos : NULL, output, output_frame ); +#endif } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b32a76b431..1afaa4696b 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -303,9 +303,7 @@ ivas_error ivas_omasa_dec_config( if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { /* Allocate TD renderer for the objects in DISC mode */ - if ( ( error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, - st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, - &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 093b653a93..60dfcf7acc 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -355,7 +355,11 @@ ivas_error ivas_ism_enc( } #else - ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, ); + ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, +#ifdef NCHAN_ISM_PARAMETER + nchan_ism, +#endif + st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif } diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 1c84021747..3bf642b85b 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -312,7 +312,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) && nchan_ism == 2 ) #else - if ( ism_mode == ISM_MODE_DISC && num_obj == 2 ) + if ( ism_mode == ISM_MODE_DISC && nchan_ism == 2 ) #endif { float diff_F; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7c85b6188f..28989065a2 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -85,16 +85,16 @@ static void remove_sep_obj( int16_t *diff_idx, const int16_t nchan_ism, const in static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif -#ifdef FIX_382_MASA_META_FRAMING_ASYNC -static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] ); +#ifndef MASA_AND_OBJECTS +static void combine_directions( MASA_ENCODER_HANDLE hMasa ); +#endif -static void copy_masa_metadata_subframe( const MASA_METADATA_HANDLE hMetaFrom, const uint8_t sfFrom, MASA_METADATA_HANDLE hMetaTo, const uint8_t sfTo ); +#ifdef FIX_382_MASA_META_FRAMING_ASYNC +static void detect_framing_async( MASA_ENCODER_HANDLE hMasa ); -static void copy_masa_metadata( const MASA_METADATA_HANDLE hMetaFrom, MASA_METADATA_HANDLE hMetaTo ); +static void average_masa_metadata( MASA_METADATA_FRAME *hMeta, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] ); static uint8_t are_masa_subframes_similar( const MASA_METADATA_HANDLE frame1, const uint8_t sf1_idx, const MASA_METADATA_HANDLE frame2, const uint8_t sf2_idx ); - -static void detect_framing_async( MASA_ENCODER_HANDLE hMasa ); #endif /*-----------------------------------------------------------------------* @@ -1644,10 +1644,12 @@ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format +#ifdef MASA_AND_OBJECTS #ifndef OMASA_UPDATES , const ISM_MODE ism_mode #endif +#endif ) { int16_t sf; -- GitLab From 59cf37d1b8f4c462069bee5e876a48246c552904 Mon Sep 17 00:00:00 2001 From: Auto Commit Date: Tue, 4 Apr 2023 11:17:26 -0400 Subject: [PATCH 061/173] first tuning version, vaclav find it takes off too much ambiance --- Workspace_msvc/decoder.vcxproj | 6 ++--- Workspace_msvc/encoder.vcxproj | 8 +++---- Workspace_msvc/lib_com.vcxproj | 8 +++---- Workspace_msvc/lib_debug.vcxproj | 8 +++---- Workspace_msvc/lib_dec.vcxproj | 8 +++---- Workspace_msvc/lib_enc.vcxproj | 8 +++---- Workspace_msvc/lib_rend.vcxproj | 8 +++---- Workspace_msvc/lib_util.vcxproj | 8 +++---- Workspace_msvc/renderer.vcxproj | 8 +++---- lib_com/ivas_prot.h | 13 +++++++++++ lib_com/ivas_stereo_td_bit_alloc.c | 24 +++++++++++++++----- lib_com/options.h | 7 +++--- lib_dec/ivas_cpe_dec.c | 6 ++++- lib_dec/ivas_stereo_td_dec.c | 10 ++++++++- lib_enc/ivas_cpe_enc.c | 22 ++++++++++++++----- lib_enc/ivas_omasa_enc.c | 2 +- lib_enc/ivas_stereo_classifier.c | 13 +++++++++++ lib_enc/ivas_stereo_td_analysis.c | 12 +++++++++- lib_enc/ivas_stereo_td_enc.c | 35 ++++++++++++++++++++++-------- 19 files changed, 152 insertions(+), 62 deletions(-) diff --git a/Workspace_msvc/decoder.vcxproj b/Workspace_msvc/decoder.vcxproj index e59992847c..f0016965e0 100644 --- a/Workspace_msvc/decoder.vcxproj +++ b/Workspace_msvc/decoder.vcxproj @@ -14,18 +14,18 @@ decoder {E3DCBC31-7FC9-D127-E000-529F8460D5FD} decoder - 10.0.17763.0 + 10.0 Application - v141 + v142 false MultiByte Application - v141 + v142 false MultiByte diff --git a/Workspace_msvc/encoder.vcxproj b/Workspace_msvc/encoder.vcxproj index bcfe92a4db..fc7e189560 100644 --- a/Workspace_msvc/encoder.vcxproj +++ b/Workspace_msvc/encoder.vcxproj @@ -18,24 +18,24 @@ encoder {B3FC9DFC-7268-8660-7C0D-B60BAF02C554} encoder - 10.0.17763.0 + 10.0 Application - v141 + v142 false MultiByte Application - v141 + v142 false MultiByte Application - v141 + v142 false MultiByte diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index 78ed7bb39d..ed8012c4d3 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -17,24 +17,24 @@ {39EC200D-7795-4FF8-B214-B24EDA5526AE} common - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte diff --git a/Workspace_msvc/lib_debug.vcxproj b/Workspace_msvc/lib_debug.vcxproj index 3b648fae04..6a5e102b0c 100644 --- a/Workspace_msvc/lib_debug.vcxproj +++ b/Workspace_msvc/lib_debug.vcxproj @@ -17,22 +17,22 @@ {54509728-928B-44D9-A118-A6F92F08B34F} debug - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 MultiByte StaticLibrary - v141 + v142 MultiByte StaticLibrary - v141 + v142 MultiByte true diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index dd2ed44443..facb2d3bc3 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -18,24 +18,24 @@ lib_dec {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3} evs_dec - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index af7ca35b12..eede51cfde 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -18,24 +18,24 @@ lib_enc {824DA4CF-06F0-45C9-929A-8792F0E19C3E} evs_enc - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index 865652649a..1cb397d10f 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -18,24 +18,24 @@ lib_rend {718DE063-A18B-BB72-9150-62B892E6FFA6} evs_dec - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte StaticLibrary - v141 + v142 false MultiByte diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 5b5e5f30cc..d1a1a8d818 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -17,22 +17,22 @@ {2FA8F384-0775-F3B7-F8C3-85209222FC70} utility - 10.0.17763.0 + 10.0 StaticLibrary - v141 + v142 MultiByte StaticLibrary - v141 + v142 MultiByte StaticLibrary - v141 + v142 MultiByte true diff --git a/Workspace_msvc/renderer.vcxproj b/Workspace_msvc/renderer.vcxproj index 94ad9f774e..d90b4a6251 100644 --- a/Workspace_msvc/renderer.vcxproj +++ b/Workspace_msvc/renderer.vcxproj @@ -18,24 +18,24 @@ renderer {12B4C8A5-1E06-4E30-B443-D1F916F52B47} renderer - 10.0.17763.0 + 10.0 Application - v141 + v142 false MultiByte Application - v141 + v142 false MultiByte Application - v141 + v142 false MultiByte diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bfae9aa4a6..56ec490530 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1766,6 +1766,9 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ +#ifdef OMASA_TUNING + ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#endif ); void stereo_classifier_init( @@ -1851,6 +1854,10 @@ void tdm_configure_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#endif + ); void tdm_upmix_plain( @@ -1904,6 +1911,9 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#endif ); ivas_error signaling_enc_secondary( @@ -1927,6 +1937,9 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : Flag that indicates presence of OMASA */ +#endif ); void td_stereo_param_updt( diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 8b93558b21..b6d3f214b3 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -88,6 +88,9 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : Flag that indicates presence of OMASA */ +#endif ) { int16_t idx, four_subfr_fcb, two_subfr_fcb; @@ -136,7 +139,12 @@ void tdm_bit_alloc( *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /* secondary channel bitrate allocation based on the energy scaling ratio */ +#ifdef OMASA_TUNING + if ( (IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || + ( IsOmasa == 1 && coder_type > UNVOICED ) ) +#else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) +#endif { bit_rate_diff = (float) ( element_brate_wo_meta - 2 * *total_brate_sec ); @@ -404,11 +412,11 @@ void tdm_bit_alloc( } *total_brate_sec += ( fast_FCB_rates_2sfr[idx] - tmp_rate ); } - /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ - if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) - { - *total_brate_sec += 100; - } + ///* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ + //if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) + //{ + // *total_brate_sec += 100; + //} /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ if ( element_brate_wo_meta - *total_brate_sec == ACELP_13k20 ) @@ -416,7 +424,11 @@ void tdm_bit_alloc( *total_brate_sec += 100; } } - + /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ + if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) + { + *total_brate_sec += 100; + } *total_brate_pri = element_brate_wo_meta - *total_brate_sec; return; diff --git a/lib_com/options.h b/lib_com/options.h index d0718997f5..b4d5642711 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,12 +58,12 @@ #ifdef DEBUGGING -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO -/*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ +#define DEBUG_MODE_ACELP /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_DFT */ /* output most important DFT stereo parameters to the subdirectory "res/" */ -/*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ +#define DEBUG_MODE_TD /* output most important TD stereo parameters to the subdirectory "res/ */ /*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_MC */ /* output Parametric MC paramters to the subdirectory "res/" */ @@ -172,6 +172,7 @@ #define OMASA_BRATE_SW /* VA: support of bitrate switching in OMASA format */ #define FIX_TD5_IN_OMASA // do not transmit extended MD in OMASA +#define OMASA_TUNING #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index b52c2ea054..d699511690 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -413,7 +413,11 @@ ivas_error ivas_cpe_dec( { if ( !st_ivas->bfi ) { - tdm_configure_dec( hCPE, &tdm_ratio_idx, nb_bits_metadata ); + tdm_configure_dec( hCPE, &tdm_ratio_idx, nb_bits_metadata +#ifdef OMASA_TUNING + , (st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_24k4)) +#endif + ); sts[1]->bit_stream = sts[0]->bit_stream + ( sts[0]->total_brate / FRAMES_PER_SEC ); } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 31b66044c6..7cfa3d92fd 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -87,6 +87,10 @@ void tdm_configure_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#endif + ) { STEREO_TD_DEC_DATA_HANDLE hStereoTD; @@ -308,7 +312,11 @@ void tdm_configure_dec( tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx +#ifdef OMASA_TUNING + ,IsOmasa +#endif + ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 128c63b114..53a30ce4d5 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -169,12 +169,20 @@ ivas_error ivas_cpe_enc( #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && ivas_total_brate == IVAS_48k ) { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k ); + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k +#ifdef OMASA_TUNING + ,st_ivas->hOMasa!=NULL +#endif + ); } else { #endif - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate +#ifdef OMASA_TUNING + ,st_ivas->hOMasa!=NULL +#endif + ); #ifdef OMASA_UPDATES } #endif @@ -579,7 +587,11 @@ ivas_error ivas_cpe_enc( { tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); - tdm_configure_enc( hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); + tdm_configure_enc( hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata +#ifdef OMASA_TUNING + ,st_ivas->hOMasa != NULL +#endif + ); if ( hEncoderConfig->Opt_DTX_ON ) { @@ -784,7 +796,7 @@ ivas_error ivas_cpe_enc( dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_NCShift" ); dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_ica_gD" ); n = -1; - dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } else if ( hCPE->element_mode == IVAS_CPE_TD ) { @@ -801,7 +813,7 @@ ivas_error ivas_cpe_enc( else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { n = -2; - dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 2ec461d5f9..b853638840 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -892,7 +892,7 @@ void ivas_set_surplus_brate_enc( if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) #else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) + if (1)// st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) #endif { tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index b2e3373404..36f06ccadc 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -90,6 +90,9 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ +#ifdef OMASA_TUNING + ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#endif ) { int16_t element_mode; @@ -209,6 +212,16 @@ int16_t select_stereo_mode( set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); } } +#ifdef OMASA_TUNING + else if ( element_mode == IVAS_CPE_TD && isOmasa ) + { + if ( ( hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) + { + hStereoClassif->lrtd_mode = 0; + hStereoClassif->prev_lrtd_mode = 0; + } + } +#endif #ifdef DEBUG_MODE_TD diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index d2d72c1534..70aaf2ebed 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -229,7 +229,17 @@ int16_t stereo_tdm_ener_analysis( hStereoTD->prev_fr_LRTD_TD_dec = 0; } } - + //if ( hCPE->hStereoTD != NULL ) + //{ + + // if ( /*hStereoClassif->lrtd_mode == 1*/ hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 && hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) + // { + // //hStereoClassif->xtalk_decision = 0; + // //hStereoClassif->lrtd_mode = 0; + // hCPE->hStereoTD->prev_fr_LRTD_TD_dec = 0; + // //hCPE->hStereoClassif->lrtd_mode = 0; + // } + //} side_can_change = 0; /* update LRTD->DFT stereo hangover counters */ diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 2105b351b3..2f34424f70 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -283,8 +283,8 @@ ivas_error stereo_set_tdm( dbgwrite( &tmp, 2, 1, 320, "res/inst_ratio_L" ); dbgwrite( &ftmp, 4, 1, 320, "res/ratio_L" ); dbgwrite( &tmp, 2, 1, 320, "res/tdm_low_rate_mode" ); - dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); - dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); + //dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); + //dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); } #endif hCPE->hCoreCoder[0]->tdm_LRTD_flag = 0; @@ -309,6 +309,9 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_TUNING + ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#endif ) { int16_t tdm_ratio_bit_alloc_idx, mod_ct; @@ -420,11 +423,21 @@ void tdm_configure_enc( } #ifdef MASA_AND_OBJECTS - if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 ) { - sts[1]->coder_type = INACTIVE; - hStereoTD->tdm_Pitch_reuse_flag = 0; + if ( sts[1]->coder_type == UNVOICED) + { + sts[1]->coder_type = GENERIC; + } hStereoTD->tdm_lp_reuse_flag = 1; +#ifdef OMASA_TUNING + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 6000 && hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 ) +#else + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 /*&& hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0*/ ) +#endif + { + sts[1]->coder_type = INACTIVE; + } } if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 14700 ) @@ -473,7 +486,11 @@ void tdm_configure_enc( tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx +#ifdef OMASA_TUNING + ,IsOmasa +#endif + ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #endif @@ -539,9 +556,9 @@ void tdm_configure_enc( } #ifdef DEBUG_MODE_TD - dbgwrite( &hStereoTD->tdm_low_rate_mode, 2, 1, 320, "res/tdm_low_rate_mode" ); - dbgwrite( &hStereoTD->tdm_lp_reuse_flag, 2, 1, 320, "res/tdm_lp_reuse_flag" ); - dbgwrite( &mod_ct, 2, 1, 320, "res/mod_ct.enx" ); + dbgwrite( &hStereoTD->tdm_low_rate_mode, 2, 1, 320, "res/tdm_low_rate_mode_c" ); + dbgwrite( &hStereoTD->tdm_lp_reuse_flag, 2, 1, 320, "res/tdm_lp_reuse_flag_c" ); + dbgwrite( &mod_ct, 2, 1, 320, "res/mod_ct.enc" ); #endif /*----------------------------------------------------------------* * Updates -- GitLab From 7bba4f3ae73dd2f72eaf8f917d7182d4c5bfd6f4 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 5 Apr 2023 08:46:10 +0300 Subject: [PATCH 062/173] Makes ISM rendering to LS in OMASA closer to separate ISM rendering to LS. Also applies clang format. --- lib_com/ivas_ism_config.c | 3 +- lib_com/ivas_omasa_com.c | 14 ++- lib_com/ivas_prot.h | 8 ++ lib_com/ivas_stat_com.h | 2 +- lib_com/options.h | 2 +- lib_dec/ivas_core_dec.c | 2 +- lib_dec/ivas_cpe_dec.c | 3 +- lib_dec/ivas_dec.c | 4 +- lib_dec/ivas_dirac_dec.c | 9 +- lib_dec/ivas_dirac_output_synthesis_dec.c | 17 ++++ lib_dec/ivas_init_dec.c | 6 +- lib_dec/ivas_ism_metadata_dec.c | 4 +- lib_dec/ivas_ism_renderer.c | 28 +++--- lib_dec/ivas_masa_dec.c | 27 +++--- lib_dec/ivas_omasa_dec.c | 6 +- lib_dec/ivas_stat_dec.h | 5 ++ lib_dec/ivas_vbap.c | 92 ++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_decision_matrix_enc.c | 2 +- lib_enc/ivas_enc.c | 2 +- lib_enc/ivas_init_enc.c | 6 +- lib_enc/ivas_ism_metadata_enc.c | 14 +-- lib_enc/ivas_masa_enc.c | 26 ++---- lib_enc/ivas_omasa_enc.c | 8 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 +- 25 files changed, 205 insertions(+), 89 deletions(-) mode change 100755 => 100644 lib_dec/ivas_core_dec.c diff --git a/lib_com/ivas_ism_config.c b/lib_com/ivas_ism_config.c index 8a0621509c..4f2ace5b2a 100644 --- a/lib_com/ivas_ism_config.c +++ b/lib_com/ivas_ism_config.c @@ -386,7 +386,7 @@ ivas_error ivas_ism_config( { int32_t tmpL; tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRMS_PER_SECOND; -#ifdef MASA_AND_OBJECTS +#ifdef MASA_AND_OBJECTS if ( ism_total_brate != tmpL ) #else if ( sum_l( element_brate, n_ISms ) != tmpL ) @@ -394,7 +394,6 @@ ivas_error ivas_ism_config( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISm bit-budget distribution. Exiting!\n" ); } - } #endif diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 175bf22195..101afcbc87 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -69,11 +69,10 @@ #endif - /*--------------------------------------------------------------- * ivas_omasa_ism_mode_select() * - * selects the ISM mode base on IVAS total bit-rate and + * selects the ISM mode base on IVAS total bit-rate and * the number of objects in the combined ISM MASA format mode * ---------------------------------------------------------------*/ @@ -179,7 +178,6 @@ ISM_MODE ivas_omasa_ism_mode_select( } - /*--------------------------------------------------------------- * ivas_interformat_brate() * @@ -209,12 +207,11 @@ int32_t ivas_interformat_brate( } else { - if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) - || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */ + if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */ { #ifdef OMASA_UPDATES - if ( (limit_flag == 1) && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) + if ( ( limit_flag == 1 ) && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) { return element_brate; } @@ -383,7 +380,7 @@ int16_t bits_index_ism_ratio( /*--------------------------------------------------------------- * calculate_nbits_meta() * - * + * * ---------------------------------------------------------------*/ void calculate_nbits_meta( @@ -487,7 +484,7 @@ void ivas_get_stereo_panning_gains( return; } -int16_t calculate_brate_limit_flag(int16_t * ism_imp, int16_t num_obj) +int16_t calculate_brate_limit_flag( int16_t *ism_imp, int16_t num_obj ) { int16_t n; int16_t brate_limit_flag; @@ -517,4 +514,3 @@ int16_t calculate_brate_limit_flag(int16_t * ism_imp, int16_t num_obj) return brate_limit_flag; } #endif - diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 750e5fc85c..7ad36a7cc2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4744,6 +4744,10 @@ ivas_error vbap_init_data( const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ const float *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ +#ifdef OMASA_UPDATES + , + const int16_t support_object_mode /* i : init VBAP also for object panning mode */ +#endif ); void vbap_free_data( @@ -4755,6 +4759,10 @@ void vbap_determine_gains( float *gains, /* o : gain vector for speaker nodes for given direction */ const int16_t azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ const int16_t ele_deg /* i : elevation in degrees for panning direction (positive up) */ +#ifdef OMASA_UPDATES + , + const int16_t use_object_mode /* i : select between object mode panning and spatial mode panning */ +#endif ); void v_sort_ind( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index c7664a9a41..224d26bbea 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -58,7 +58,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 */ -#ifdef MASA_AND_OBJECTS +#ifdef MASA_AND_OBJECTS int16_t ism_imp; /* ISM importance flag */ int16_t ism_vad_flag; #ifdef OMASA_UPDATES diff --git a/lib_com/options.h b/lib_com/options.h index 62011c419e..442a0004d7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -143,7 +143,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define LOW_RATE_TRANS_CORE_CODER /* Eri: Activate low-rate-encoding-of-transients contribution for core coder, affects MC, MASA and SBA */ -#define FIX_197_CREND_INTERFACE +#define FIX_197_CREND_INTERFACE #define FIX_329_ENABLE_TD_RENDERER_REVERB_MC /* Eri: Enable reverb for TD renderer for 5.1 and 7.1 with headtracking enabled for IVAS_dec */ #define FIX_347_DTX_CRASH /* FhG: Fix crash that can happen with DTX */ #define DISABLE_RES_CHANNELS_MCT /* decode only W and residual for Y when outputting to stereo */ diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c old mode 100755 new mode 100644 index 37034da4f8..171ecbfafe --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -269,7 +269,7 @@ ivas_error ivas_core_dec( } } -#ifdef MASA_AND_OBJECTS +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------* * Sanity check in combined format coding *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index b093d58805..1ba5c68f5a 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -176,7 +176,6 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS } #endif - } else { @@ -1116,7 +1115,7 @@ static void read_stereo_mode_and_bwidth( { /* read stereo technology info */ #ifdef OMASA_UPDATES - if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k) ) + if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k ) ) #else if ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 80b5d6edd2..8c5a9b4716 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -529,8 +529,8 @@ ivas_error ivas_dec( } ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); - ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame,st_ivas->hCrendWrapper, - st_ivas->transport_config,st_ivas->hDecoderConfig->output_Fs, st_ivas->hBinRendererTd, + ivas_td_binaural_renderer_unwrap( st_ivas->hRenderConfig, st_ivas->ini_frame, st_ivas->hCrendWrapper, + st_ivas->transport_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hBinRendererTd, st_ivas->nchan_ism, LFE_CHANNEL, st_ivas->ivas_format, st_ivas->hIsmMetaData, st_ivas->hDecoderConfig->Opt_Headrotation, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->Quaternions : NULL, data_separated_objects, output_frame ); diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index f8e0f98d1b..b3c097c3a4 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -579,10 +579,17 @@ ivas_error ivas_dirac_dec_config( { vbap_free_data( &( st_ivas->hVBAPdata ) ); } +#ifdef OMASA_UPDATES + if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format == MASA_ISM_FORMAT ? 1 : 0 ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE ) ) != IVAS_ERR_OK ) { return error; } +#endif } else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) { @@ -2030,7 +2037,7 @@ void ivas_dirac_dec( preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, - (uint8_t)(hDirAC->num_freq_bands), + (uint8_t) ( hDirAC->num_freq_bands ), (uint8_t) subframe_idx, 1 ); } diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 4fcb4c089e..2ef79bfc45 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -1681,11 +1681,19 @@ void ivas_dirac_dec_compute_directional_responses( { if ( hMasaIsm->ism_is_edited[dir] ) { +#ifdef OMASA_UPDATES + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); +#else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir] ); +#endif } else { +#ifdef OMASA_UPDATES + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], 1 ); +#else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir] ); +#endif } for ( l = 0; l < num_channels_dir; l++ ) @@ -2202,12 +2210,21 @@ static void spreadCoherencePanningVbap( return; } +#ifdef OMASA_UPDATES + vbap_determine_gains( hVBAPdata, direct_response, azimuth, elevation, 0 ); +#else vbap_determine_gains( hVBAPdata, direct_response, azimuth, elevation ); +#endif if ( spreadCoh > 0.f ) { +#ifdef OMASA_UPDATES + vbap_determine_gains( hVBAPdata, direct_response_left, azimuth + 30, elevation, 0 ); + vbap_determine_gains( hVBAPdata, direct_response_right, azimuth - 30, elevation, 0 ); +#else vbap_determine_gains( hVBAPdata, direct_response_left, azimuth + 30, elevation ); vbap_determine_gains( hVBAPdata, direct_response_right, azimuth - 30, elevation ); +#endif if ( spreadCoh < 0.5f ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 15519bdee4..16ed84c257 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1250,7 +1250,11 @@ ivas_error ivas_init_decoder( } else { +#ifdef OMASA_UPDATES + vbap_determine_gains( st_ivas->hVBAPdata, st_ivas->hLsSetupCustom->separate_ch_gains, 0, 0, 0 ); +#else vbap_determine_gains( st_ivas->hVBAPdata, st_ivas->hLsSetupCustom->separate_ch_gains, 0, 0 ); +#endif } } @@ -1437,7 +1441,7 @@ ivas_error ivas_init_decoder( { /* Use td renderer for the objects in DISC mode */ error = ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_ism, st_ivas->ivas_format, - st_ivas->transport_config, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); + st_ivas->transport_config, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); if ( ( error ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 4066304dab..4bb56b0b82 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -651,8 +651,8 @@ ivas_error create_ism_metadata_dec( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } - - ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL + + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, n_ISms, n_ISms, NULL, NULL, NULL, element_brate_tmp, NULL, NULL #ifdef MASA_AND_OBJECTS , 0 diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 043b6f8600..feca51b696 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -252,10 +252,10 @@ void ivas_ism_get_stereo_gains( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------------* - * ivas_masa_ism_separate_object_renderer_open() - * - * Open structures, reserve memory, and init values. - *-------------------------------------------------------------------------*/ + * ivas_masa_ism_separate_object_renderer_open() + * + * Open structures, reserve memory, and init values. + *-------------------------------------------------------------------------*/ ivas_error ivas_masa_ism_separate_object_renderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -314,10 +314,10 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( /*-------------------------------------------------------------------------* -* ivas_masa_ism_separate_object_render() -* -* Rendering separated objects and mixing them to the parametrically rendered signals -*-------------------------------------------------------------------------*/ + * ivas_masa_ism_separate_object_render() + * + * Rendering separated objects and mixing them to the parametrically rendered signals + *-------------------------------------------------------------------------*/ void ivas_masa_ism_separate_object_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -327,7 +327,6 @@ void ivas_masa_ism_separate_object_render( ) { VBAP_HANDLE hVBAPdata; - AUDIO_CONFIG output_config; int16_t nchan_out_woLFE; ISM_RENDERER_HANDLE hRendererData; int16_t j, k, j2; @@ -340,13 +339,12 @@ void ivas_masa_ism_separate_object_render( uint8_t single_separated; hVBAPdata = st_ivas->hVBAPdata; - output_config = st_ivas->hDecoderConfig->output_config; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; hRendererData = st_ivas->hIsmRendererData; lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; #ifdef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) #else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) #endif @@ -375,20 +373,26 @@ void ivas_masa_ism_separate_object_render( elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; } - if ( output_config != AUDIO_CONFIG_7_1_4 && output_config != AUDIO_CONFIG_5_1_4 ) + if ( st_ivas->hOutSetup.is_planar_setup ) { /* If no elevation support in output format, then rendering should be done with zero elevation */ elevation = 0; } +#ifndef OMASA_UPDATES else if ( output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_4 ) { /* For no negative elevations, it's better to map them to zero */ elevation = elevation < 0 ? 0 : elevation; } +#endif if ( hVBAPdata != NULL ) { +#ifdef OMASA_UPDATES + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); +#else vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); +#endif } else { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a0fa5cf0b4..e7ae030555 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -74,11 +74,11 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS -static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp); +static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp ); static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); -static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object); +static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, IVAS_QMETADATA_HANDLE hQMetaData, float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object ); static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], uint16_t *bit_stream, int16_t *next_bit_pos, float *masa_to_total_energy_ratio, const int16_t idx_sep_obj, int16_t *num_zeros ); #endif @@ -644,7 +644,7 @@ ivas_error ivas_masa_ism_data_open( hMasaIsmData->q_elevation_old[ch] = 0.0f; hMasaIsmData->q_azimuth_old[ch] = 0.0f; } - #endif +#endif return IVAS_ERR_OK; } @@ -1795,7 +1795,7 @@ static void read_ism_ratio_index( b_signif = 0; no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); - while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) + while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) { /* distribute evenly the objects */ distribute_evenly_ism( ratio_ism_idx[b_signif], no_levels_ratio_ism, nchan_ism ); @@ -2033,9 +2033,6 @@ static void read_ism_ratio_index( } - - - static void decode_ism_ratios( uint16_t *bit_stream, /* i : bitstream */ int16_t *next_bit_pos, /* i/o: position in bitstream */ @@ -2044,7 +2041,7 @@ static void decode_ism_ratios( const int16_t n_ism, /* i : number of objects */ const int16_t nbands, /* i : number of subbands */ const int16_t numSf, /* i : number of subframes */ - const int16_t idx_separated_object /* i: index of separated object */ + const int16_t idx_separated_object /* i: index of separated object */ ) { int16_t sf, band; @@ -2122,8 +2119,7 @@ static int16_t ivas_decode_masaism_metadata( uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, - const int16_t ism_imp -) + const int16_t ism_imp ) { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; @@ -2180,11 +2176,11 @@ static int16_t ivas_decode_masaism_metadata( index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; } deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); - + if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) { delta_phi = 180.0f / (float) ( no_phi_masa[bits_ism[obj] - 1][idx_el] ); /* 360/2*/ - if ( azimuth - hMasaIsmData->q_azimuth_old[obj] > delta_phi ) + if ( azimuth - hMasaIsmData->q_azimuth_old[obj] > delta_phi ) { azimuth -= delta_phi; } @@ -2192,11 +2188,11 @@ static int16_t ivas_decode_masaism_metadata( { if ( hMasaIsmData->q_azimuth_old[obj] - azimuth > delta_phi ) { - azimuth += delta_phi; + azimuth += delta_phi; } } } - + hMasaIsmData->q_azimuth_old[obj] = azimuth; hMasaIsmData->q_elevation_old[obj] = elevation; } @@ -2222,7 +2218,6 @@ static int16_t ivas_decode_masaism_metadata( #endif hMasaIsmData->azimuth_ism[obj] = (int16_t) rint( azimuth ); hMasaIsmData->elevation_ism[obj] = (int16_t) rint( elevation ); - } /* Modify ISM metadata based on the MASA-to-total energy ratios */ @@ -2269,7 +2264,7 @@ static int16_t ivas_decode_masaism_metadata( /*-------------------------------------------------------------------* * ivas_masa_ism_set_edited_objects() * - * + * *-------------------------------------------------------------------*/ void ivas_masa_ism_set_edited_objects( diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 35441360fe..9233e4be99 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -91,14 +91,14 @@ void ivas_set_surplus_brate_dec( { #ifdef OMASA_UPDATES int16_t brate_limit_flag, ism_imp[MAX_NUM_OBJECTS]; - + for ( n = 0; n < st_ivas->nchan_ism; n++ ) { ism_imp[n] = st_ivas->hIsmMetaData[n]->ism_imp; } - + brate_limit_flag = calculate_brate_limit_flag( ism_imp, st_ivas->nchan_ism ); - + #endif ism_total_brate_ref = 0; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4316c90677..ff1f264e46 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1028,6 +1028,11 @@ typedef struct vbap_data_structure float *bottom_virtual_speaker_node_division_gains; float *top_virtual_speaker_node_division_gains; float *back_virtual_speaker_node_division_gains; +#ifdef OMASA_UPDATES + float *object_mode_bottom_virtual_speaker_node_division_gains; + float *object_mode_top_virtual_speaker_node_division_gains; + float *object_mode_back_virtual_speaker_node_division_gains; +#endif } VBAP_DATA, *VBAP_HANDLE; diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index 9c595ea1fe..d3ecedecfd 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -141,7 +141,11 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( VBAP_HAND static int16_t determine_best_triplet_and_gains( VBAP_SEARCH_STRUCT *search_struct, const float panning_unit_vec[3], const int16_t azi_deg, float gains[3] ); +#ifdef OMASA_UPDATES +static void determine_virtual_speaker_node_division_gains( const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes, const int16_t use_object_mode ); +#else static void determine_virtual_speaker_node_division_gains( const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes ); +#endif static void reorder_triplets( VBAP_VS_TRIPLET *triplets, const int16_t *target_order, const int16_t num_triplets ); @@ -157,6 +161,10 @@ ivas_error vbap_init_data( const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ const float *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ +#ifdef OMASA_UPDATES + , + const int16_t support_object_mode /* i : init VBAP also for object panning mode */ +#endif ) { /* Variables */ @@ -203,6 +211,11 @@ ivas_error vbap_init_data( vbap->bottom_virtual_speaker_node_division_gains = NULL; vbap->top_virtual_speaker_node_division_gains = NULL; vbap->back_virtual_speaker_node_division_gains = NULL; +#ifdef OMASA_UPDATES + vbap->object_mode_bottom_virtual_speaker_node_division_gains = NULL; + vbap->object_mode_top_virtual_speaker_node_division_gains = NULL; + vbap->object_mode_back_virtual_speaker_node_division_gains = NULL; +#endif vbap->num_speaker_nodes = num_speaker_nodes; vbap->num_speaker_nodes_internal = num_speaker_nodes; @@ -223,6 +236,14 @@ ivas_error vbap_init_data( vbap->bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->bottom_virtual_speaker_node_division_gains != NULL; +#ifdef OMASA_UPDATES + if ( support_object_mode ) + { + vbap->object_mode_bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + set_zero( vbap->object_mode_bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); + is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains != NULL; + } +#endif speaker_node_azi_deg_internal[vbap->bottom_virtual_speaker_node_index] = 0.0f; speaker_node_ele_deg_internal[vbap->bottom_virtual_speaker_node_index] = -90.0f; } @@ -232,6 +253,14 @@ ivas_error vbap_init_data( vbap->top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->top_virtual_speaker_node_division_gains != NULL; +#ifdef OMASA_UPDATES + if ( support_object_mode ) + { + vbap->object_mode_top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + set_zero( vbap->object_mode_top_virtual_speaker_node_division_gains, num_speaker_nodes ); + is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains != NULL; + } +#endif speaker_node_azi_deg_internal[vbap->top_virtual_speaker_node_index] = 0.0f; speaker_node_ele_deg_internal[vbap->top_virtual_speaker_node_index] = 90.0f; } @@ -241,6 +270,14 @@ ivas_error vbap_init_data( vbap->back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->back_virtual_speaker_node_division_gains != NULL; +#ifdef OMASA_UPDATES + if ( support_object_mode ) + { + vbap->object_mode_back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); + set_zero( vbap->object_mode_back_virtual_speaker_node_division_gains, num_speaker_nodes ); + is_success &= vbap->object_mode_back_virtual_speaker_node_division_gains != NULL; + } +#endif speaker_node_azi_deg_internal[vbap->back_virtual_speaker_node_index] = 180.0f; speaker_node_ele_deg_internal[vbap->back_virtual_speaker_node_index] = 0.0f; } @@ -319,11 +356,23 @@ ivas_error vbap_init_data( /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ if ( is_success ) { +#ifdef OMASA_UPDATES + determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); + determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); + if ( support_object_mode ) + { + determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->object_mode_back_virtual_speaker_node_division_gains, connections, virtual_back_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); + } +#else determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes ); determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes ); determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes ); +#endif } pop_wmops(); @@ -368,6 +417,20 @@ void vbap_free_data( { free( ( *hVBAPdata )->back_virtual_speaker_node_division_gains ); } +#ifdef OMASA_UPDATES + if ( ( *hVBAPdata )->object_mode_bottom_virtual_speaker_node_division_gains != NULL ) + { + free( ( *hVBAPdata )->object_mode_bottom_virtual_speaker_node_division_gains ); + } + if ( ( *hVBAPdata )->object_mode_top_virtual_speaker_node_division_gains != NULL ) + { + free( ( *hVBAPdata )->object_mode_top_virtual_speaker_node_division_gains ); + } + if ( ( *hVBAPdata )->object_mode_back_virtual_speaker_node_division_gains != NULL ) + { + free( ( *hVBAPdata )->object_mode_back_virtual_speaker_node_division_gains ); + } +#endif if ( ( *hVBAPdata )->search_struct[0].triplets != NULL ) { free( ( *hVBAPdata )->search_struct[0].triplets ); @@ -395,6 +458,10 @@ void vbap_determine_gains( float *gains, /* o : gain vector for loudspeakers for given direction */ const int16_t azi_deg, /* i : azimuth in degrees for panning direction (positive left)*/ const int16_t ele_deg /* i : elevation in degrees for panning direction (positive up)*/ +#ifdef OMASA_UPDATES + , + const int16_t use_object_mode /* i : select between object mode panning and spatial mode panning */ +#endif ) { /* This function formulates gains for the given angle. The triplet-selection has been pre-formulated. */ @@ -428,9 +495,24 @@ void vbap_determine_gains( bottom_virtual_speaker_node_index = hVBAPdata->bottom_virtual_speaker_node_index; top_virtual_speaker_node_index = hVBAPdata->top_virtual_speaker_node_index; back_virtual_speaker_node_index = hVBAPdata->back_virtual_speaker_node_index; +#ifdef OMASA_UPDATES + if ( use_object_mode ) + { + bottom_virtual_speaker_node_division_gains = hVBAPdata->object_mode_bottom_virtual_speaker_node_division_gains; + top_virtual_speaker_node_division_gains = hVBAPdata->object_mode_top_virtual_speaker_node_division_gains; + back_virtual_speaker_node_division_gains = hVBAPdata->object_mode_back_virtual_speaker_node_division_gains; + } + else + { + bottom_virtual_speaker_node_division_gains = hVBAPdata->bottom_virtual_speaker_node_division_gains; + top_virtual_speaker_node_division_gains = hVBAPdata->top_virtual_speaker_node_division_gains; + back_virtual_speaker_node_division_gains = hVBAPdata->back_virtual_speaker_node_division_gains; + } +#else bottom_virtual_speaker_node_division_gains = hVBAPdata->bottom_virtual_speaker_node_division_gains; top_virtual_speaker_node_division_gains = hVBAPdata->top_virtual_speaker_node_division_gains; back_virtual_speaker_node_division_gains = hVBAPdata->back_virtual_speaker_node_division_gains; +#endif panning_wrap_angles( (float) azi_deg, (float) ele_deg, &azi_temp, &ele_temp ); azi_rad = azi_temp * PI_OVER_180; @@ -679,6 +761,10 @@ static void determine_virtual_speaker_node_division_gains( const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ const int16_t max_num_connections, /* i : max number of connections */ const int16_t num_speaker_nodes /* i : max number of speaker nodes */ +#ifdef OMASA_UPDATES + , + const int16_t use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ +#endif ) { /* When node type is VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, the gains of the virtual node @@ -721,6 +807,12 @@ static void determine_virtual_speaker_node_division_gains( for ( ch = 0; ch < num_speaker_nodes; ch++ ) { virtual_node_division_gains[ch] /= sum_val; +#ifdef OMASA_UPDATES + if ( use_object_mode ) + { + virtual_node_division_gains[ch] = powf( virtual_node_division_gains[ch], 0.8f ); + } +#endif } } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e3b8342896..861e1015c4 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -285,7 +285,7 @@ ivas_error ivas_cpe_enc( { #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MODE_NONE ) - { + { stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (int32_t) ( 0.70f * st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } else diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index afb4fc8ac7..fcc77edd52 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -405,7 +405,7 @@ void ivas_signaling_enc( * Write element mode info *--------------------------------------------------------------------------*/ #ifdef OMASA_UPDATES - if ( (st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ + if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ #else if ( st->element_mode >= IVAS_CPE_DFT && element_brate < MIN_BRATE_MDCT_STEREO && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ #endif diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index de247c0a56..e4448b0f56 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -320,7 +320,7 @@ ivas_error ivas_enc( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) { /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); + ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); } /* Estimate TF-tile energy for the input MASA stream */ diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1b6e2bd596..ff43a42536 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -481,7 +481,7 @@ ivas_error ivas_init_encoder( if ( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; - } + } } #endif } @@ -631,9 +631,9 @@ ivas_error ivas_init_encoder( } } #ifdef OMASA_UPDATES - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM) ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) #else - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) #endif { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 97b689b5dd..b03b25f6c9 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -257,8 +257,8 @@ ivas_error ivas_ism_metadata_enc( #endif { /*----------------------------------------------------------------* - * Set Metadata presence / importance flag - *----------------------------------------------------------------*/ + * Set Metadata presence / importance flag + *----------------------------------------------------------------*/ for ( ch = 0; ch < num_obj; ch++ ) { @@ -295,8 +295,8 @@ ivas_error ivas_ism_metadata_enc( } /*----------------------------------------------------------------* - * Rate importance of particular ISm streams - *----------------------------------------------------------------*/ + * Rate importance of particular ISm streams + *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS if ( ism_mode == ISM_MASA_MODE_DISC ) { @@ -880,7 +880,7 @@ ivas_error ivas_ism_metadata_enc( int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; #ifdef OMASA_UPDATES int16_t brate_limit_flag; - brate_limit_flag = calculate_brate_limit_flag( ism_imp, num_obj ); + brate_limit_flag = calculate_brate_limit_flag( ism_imp, num_obj ); #endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); @@ -892,7 +892,7 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < num_obj; ch++ ) { #ifdef OMASA_UPDATES - *ism_total_brate += ivas_interformat_brate( ism_mode, num_obj, hSCE[ch]->element_brate, ism_imp[ch],brate_limit_flag + *ism_total_brate += ivas_interformat_brate( ism_mode, num_obj, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag #else *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, num_obj, hSCE[ch]->element_brate, ism_imp[ch] #ifdef FIX_4OBJ_128 @@ -912,7 +912,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS #ifdef OMASA_UPDATES - if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { ivas_ism_config( *ism_total_brate, nchan_transport, num_obj, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ); // VE: this funtion should return an error } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 07c313f002..dec4b97b3c 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -57,8 +57,7 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); #ifdef MASA_AND_OBJECTS -static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, - const int16_t idx_separated_object, const int16_t ism_imp ); +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format, const ISM_MODE ism_mode ); @@ -66,7 +65,7 @@ static void quantize_ratio_ism_vector( float *ratio_ism, int16_t *idx, const int static int16_t index_slice_enum( const int16_t *ratio_ism_idx, int16_t no_ism ); -static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); +static int16_t encode_ratio_ism_subframe( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); static void transform_index_and_GR_encode( int16_t *diff_idx, int16_t len, int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); @@ -2183,8 +2182,7 @@ static void quantize_ratio_ism_vector( int16_t *idx, const int16_t nchan_ism, const float masa_to_total_energy_ratio, - const int16_t idx_sep_object -) + const int16_t idx_sep_object ) { int16_t i, j, best_i, best_i2; float dist, div, tmp, dist2, best_dist; @@ -2407,7 +2405,7 @@ static int16_t try_differential( b_signif = 0; - while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) + while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) { b_signif++; } @@ -2656,7 +2654,7 @@ static int16_t encode_ratio_ism_subframe( nbits0 = 0; nbits1 = 0; b_signif = 0; - while ( (b_signif < numCodingBands) && (masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR) ) + while ( ( b_signif < numCodingBands ) && ( masa_to_total_energy_ratio[b_signif] >= MASA2TOTAL_THR ) ) { b_signif++; } @@ -2793,9 +2791,6 @@ static int16_t encode_ratio_ism_subframe( } - - - static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -2805,8 +2800,7 @@ static void ivas_encode_masaism_metadata( const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, - const int16_t ism_imp -) + const int16_t ism_imp ) { int16_t sf, band; uint8_t numCodingBands; @@ -3061,18 +3055,16 @@ static void ivas_encode_masaism_metadata( } } } - } } - calculate_nbits_meta( hMasa->data.nchan_ism, hMasa->data.q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); /* quantize directions */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) - { + { #ifdef OMASA_UPDATES if ( bits_ism[obj] < 8 ) { @@ -3089,7 +3081,7 @@ static void ivas_encode_masaism_metadata( push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; - } + } } else { @@ -3098,7 +3090,7 @@ static void ivas_encode_masaism_metadata( hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; } - + #else idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 935ea5e342..ee0eadc3e6 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -50,8 +50,7 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], - float diffuseness_m[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); +static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], float diffuseness_m[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); @@ -347,7 +346,7 @@ void ivas_omasa_enc( ivas_masa_combine_directions( hMasa ); - hMasa->config.numCodingBands = (int8_t)n_bands_orig; + hMasa->config.numCodingBands = (int8_t) n_bands_orig; } /* force computation into high resolution */ @@ -579,7 +578,7 @@ void ivas_omasa_enc( ivas_masa_combine_directions( hMasa ); - hMasa->config.numCodingBands = (int8_t)n_bands_orig; + hMasa->config.numCodingBands = (int8_t) n_bands_orig; } /* force computation into high resolution */ @@ -618,7 +617,6 @@ void ivas_omasa_enc( hMasa->config.numCodingBands = numCodingBands_orig; hMasa->config.joinedSubframes = joinedSubframes_orig; - } else if ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index db6bf0293e..6de5688492 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -2074,7 +2074,7 @@ static void hrtfShGetHrtf( /*-------------------------------------------------------------------* * preProcessStereoTransportsForMovedObjects() * - * + * *-------------------------------------------------------------------*/ void preProcessStereoTransportsForMovedObjects( -- GitLab From 902c4f33417abce037f57b9c5c6b791735ee8d8a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 5 Apr 2023 16:56:42 +0200 Subject: [PATCH 063/173] fix crashes in native MASA decoder; changes are within OMASA_BRATE_SW --- lib_dec/ivas_dec.c | 4 ++++ lib_dec/ivas_init_dec.c | 23 ++++++++++++------- lib_dec/ivas_masa_dec.c | 8 +++++++ lib_dec/ivas_omasa_dec.c | 48 +++++++++------------------------------- lib_dec/ivas_stat_dec.h | 3 +++ 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 10147488c0..0b590f3ef9 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -900,6 +900,10 @@ ivas_error ivas_dec( st_ivas->ini_active_frame++; } +#ifdef OMASA_BRATE_SW + st_ivas->last_ivas_format = st_ivas->ivas_format; +#endif + #ifdef DEBUG_MODE_INFO dbgwrite( &st_ivas->bfi, sizeof( int16_t ), 1, output_frame, "res/bfi" ); dbgwrite( &st_ivas->BER_detect, sizeof( int16_t ), 1, output_frame, "res/BER_detect" ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index e8fccfb9cf..a97da59693 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -181,18 +181,25 @@ ivas_error ivas_dec_setup( if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { #ifdef OMASA_BRATE_SW - if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->nCPE == 1 ) + if ( st_ivas->last_ivas_format == MASA_FORMAT ) { - st_ivas->hCPE[0]->nchan_out = 1; +#endif + if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->nCPE == 1 ) + { + st_ivas->hCPE[0]->nchan_out = 1; + } + else + { + if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#ifdef OMASA_BRATE_SW } else { - if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 9d6e1d9612..31acee4924 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1478,6 +1478,14 @@ ivas_error ivas_masa_dec_reconfigure( #endif ); +#ifdef OMASA_BRATE_SW + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + st_ivas->nchan_ism = 0; + st_ivas->ism_mode = ISM_MODE_NONE; + } +#endif + return error; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 1afaa4696b..036b72a939 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -145,7 +145,6 @@ ivas_error ivas_omasa_dec_config( { int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; int32_t ivas_total_brate, ism_total_brate, cpe_brate; - IVAS_FORMAT ivas_format_old; ISM_MODE ism_mode_old; ivas_error error; @@ -157,26 +156,10 @@ ivas_error ivas_omasa_dec_config( ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); st_ivas->ism_mode = ism_mode_old; - ivas_format_old = st_ivas->ivas_format; -#ifdef OMASA_UPDATES - if ( ism_mode_old == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_DISC ) -#else - if ( ism_mode_old == ISM_MASA_MODE_PARAM || ism_mode_old == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode_old == ISM_MASA_MODE_DISC ) -#endif - { - st_ivas->ivas_format = MASA_ISM_FORMAT; - } ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nSCE_old = st_ivas->nSCE; nchan_hp20_old = getNumChanSynthesis( st_ivas ); - /* reconstruct parameters */ - st_ivas->ivas_format = ivas_format_old; - if ( st_ivas->ivas_format == MASA_FORMAT ) - { - st_ivas->nchan_ism = 0; - } - /* set ism_mode of current frame */ st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); @@ -191,7 +174,6 @@ ivas_error ivas_omasa_dec_config( return error; } - // VE!!!!!: verification needed, see comment "/* Todo: Nokia make for MASA_ISM*/" in ivas_masa_dec_reconfigure() if ( cpe_brate < MASA_STEREO_MIN_BITRATE ) { st_ivas->hCPE[0]->nchan_out = 1; @@ -219,30 +201,20 @@ ivas_error ivas_omasa_dec_config( } /* reconfigure core-coders for ISMs */ - if ( st_ivas->ivas_format == MASA_FORMAT ) + k = 0; + while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) { - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, -1, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } + k++; } - else - { - k = 0; - while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) - { - k++; - } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) - { - ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; - } + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; + } - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + { + return error; } if ( ism_mode_old != st_ivas->ism_mode ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index dd9aa2c94f..e1297e9381 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1218,6 +1218,9 @@ typedef struct Decoder_Struct DECODER_CONFIG_HANDLE hDecoderConfig; /* Decoder configuration structure */ IVAS_FORMAT ivas_format; /* IVAS format */ +#ifdef OMASA_BRATE_SW + IVAS_FORMAT last_ivas_format; /* last frame IVAS format */ +#endif int16_t sid_format; /* IVAS format indicator from SID frame */ int16_t nchan_transport; /* number of transport channels */ IVAS_OUTPUT_SETUP hOutSetup; /* output setup structure */ -- GitLab From 02723cade9388c4f42476be12fa63646749095c1 Mon Sep 17 00:00:00 2001 From: Auto Commit Date: Wed, 5 Apr 2023 14:32:35 -0400 Subject: [PATCH 064/173] as tested in the short AB test --- lib_com/ivas_prot.h | 6 +++--- lib_com/ivas_stereo_td_bit_alloc.c | 18 +++++++----------- lib_enc/ivas_cpe_enc.c | 18 +++++++----------- lib_enc/ivas_stereo_classifier.c | 14 -------------- lib_enc/ivas_stereo_td_analysis.c | 24 +++++++++++++----------- lib_enc/ivas_stereo_td_enc.c | 4 ++-- 6 files changed, 32 insertions(+), 52 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 56ec490530..ae82f8b2b6 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1766,9 +1766,6 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ -#ifdef OMASA_TUNING - ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ -#endif ); void stereo_classifier_init( @@ -1833,6 +1830,9 @@ int16_t stereo_tdm_ener_analysis( const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ +#ifdef OMASA_TUNING + ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#endif ); void stereo_tdm_downmix( diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index b6d3f214b3..b0ae12ecd8 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -140,7 +140,8 @@ void tdm_bit_alloc( /* secondary channel bitrate allocation based on the energy scaling ratio */ #ifdef OMASA_TUNING - if ( (IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || + if ( (IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) + || ( IsOmasa == 1 && coder_type > UNVOICED ) ) #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) @@ -412,11 +413,11 @@ void tdm_bit_alloc( } *total_brate_sec += ( fast_FCB_rates_2sfr[idx] - tmp_rate ); } - ///* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ - //if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) - //{ - // *total_brate_sec += 100; - //} + /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ + if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) + { + *total_brate_sec += 100; + } /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ if ( element_brate_wo_meta - *total_brate_sec == ACELP_13k20 ) @@ -424,11 +425,6 @@ void tdm_bit_alloc( *total_brate_sec += 100; } } - /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ - if ( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) - { - *total_brate_sec += 100; - } *total_brate_pri = element_brate_wo_meta - *total_brate_sec; return; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 53a30ce4d5..6800966f99 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -169,20 +169,12 @@ ivas_error ivas_cpe_enc( #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && ivas_total_brate == IVAS_48k ) { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k -#ifdef OMASA_TUNING - ,st_ivas->hOMasa!=NULL -#endif - ); + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k ); } else { #endif - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate -#ifdef OMASA_TUNING - ,st_ivas->hOMasa!=NULL -#endif - ); + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); #ifdef OMASA_UPDATES } #endif @@ -421,7 +413,11 @@ ivas_error ivas_cpe_enc( else if ( hCPE->element_mode == IVAS_CPE_TD ) { /* Determine the energy ratio between the 2 channels */ - tdm_ratio_idx = stereo_tdm_ener_analysis( hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); + tdm_ratio_idx = stereo_tdm_ener_analysis( hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM +#ifdef OMASA_TUNING + , st_ivas->hOMasa != NULL +#endif + ); /* Compute the downmix signal based on the ratio index */ stereo_tdm_downmix( hCPE->hStereoTD, sts[0]->input, sts[1]->input, input_frame, tdm_ratio_idx, ( ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) ? tdm_SM_or_LRTD_Pri : 0 ), tdm_ratio_idx_SM ); diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 36f06ccadc..8e20c13c8a 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -90,9 +90,6 @@ int16_t select_stereo_mode( CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int32_t ivas_total_brate /* i : IVAS total brate */ -#ifdef OMASA_TUNING - ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ -#endif ) { int16_t element_mode; @@ -212,17 +209,6 @@ int16_t select_stereo_mode( set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); } } -#ifdef OMASA_TUNING - else if ( element_mode == IVAS_CPE_TD && isOmasa ) - { - if ( ( hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) - { - hStereoClassif->lrtd_mode = 0; - hStereoClassif->prev_lrtd_mode = 0; - } - } -#endif - #ifdef DEBUG_MODE_TD dbgwrite( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, L_FRAME16k, "res/unclr_decision.enc" ); diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 70aaf2ebed..97522ef861 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -115,6 +115,9 @@ int16_t stereo_tdm_ener_analysis( const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ +#ifdef OMASA_TUNING + ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#endif ) { float rms_R, rms_L; @@ -194,7 +197,16 @@ int16_t stereo_tdm_ener_analysis( * When the energies of channels are low enough, compute the ratio * of L and R needed to create new mono/side signals *----------------------------------------------------------------*/ +#ifdef OMASA_TUNING + if ( isOmasa ) + { + if ( ( hCPE->hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) + { + hStereoTD->prev_fr_LRTD_TD_dec = 0; + } + } +#endif rms_thd = RMS_MIN; if ( hCPE->hStereoClassif->lrtd_mode == 1 ) { @@ -229,17 +241,7 @@ int16_t stereo_tdm_ener_analysis( hStereoTD->prev_fr_LRTD_TD_dec = 0; } } - //if ( hCPE->hStereoTD != NULL ) - //{ - - // if ( /*hStereoClassif->lrtd_mode == 1*/ hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 && hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus < 12600 ) - // { - // //hStereoClassif->xtalk_decision = 0; - // //hStereoClassif->lrtd_mode = 0; - // hCPE->hStereoTD->prev_fr_LRTD_TD_dec = 0; - // //hCPE->hStereoClassif->lrtd_mode = 0; - // } - //} + side_can_change = 0; /* update LRTD->DFT stereo hangover counters */ diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 2f34424f70..6e13ec2075 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -431,9 +431,9 @@ void tdm_configure_enc( } hStereoTD->tdm_lp_reuse_flag = 1; #ifdef OMASA_TUNING - if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 6000 && hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0 ) + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 11000 ) #else - if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 /*&& hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 0*/ ) + if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 ) #endif { sts[1]->coder_type = INACTIVE; -- GitLab From ff5314ab3351a768ecb5d1ebfa5b4535e6542b0b Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 6 Apr 2023 08:49:50 +0200 Subject: [PATCH 065/173] fixes for bitrate switching and MC output config. --- lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_init_dec.c | 23 +++++++++----- lib_dec/ivas_omasa_dec.c | 68 ++++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index ecfa303713..c0deb07a1a 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -603,7 +603,7 @@ ivas_error ivas_dec( ivas_masa_ism_set_edited_objects( st_ivas ); /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 792521c573..c26a94f2dc 100755 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1541,19 +1541,26 @@ ivas_error ivas_init_decoder( } #ifdef OMASA_UPDATES - // VE: introduce a new renderer_type for this case - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - /* Allocate TD renderer for the objects in DISC mode */ - if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + // VE: introduce a new renderer_type for this case + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL ) { - return error; + /* Allocate TD renderer for the objects in DISC mode */ + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + // VE: introduce a new renderer_type for this case + if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { - return error; + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 036b72a939..a688e0062f 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -271,39 +271,67 @@ ivas_error ivas_omasa_dec_config( } #ifdef OMASA_UPDATES - // VE: introduce a new renderer_type for this case - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { - /* Allocate TD renderer for the objects in DISC mode */ - if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - return error; - } + /* Allocate TD renderer for the objects in DISC mode */ + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } - /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else { - return error; + /* TD renderer handle */ + if ( st_ivas->hBinRendererTd != NULL ) + { + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + } + + if ( st_ivas->hHrtfTD != NULL ) // VE: this is copied from ivas_ism_bitrate_switching() but a review is needed + { + st_ivas->hHrtfTD = NULL; + } + + /* ISM renderer handle */ + if ( st_ivas->hIsmRendererData != NULL ) + { + free( st_ivas->hIsmRendererData ); + st_ivas->hIsmRendererData = NULL; + } } } - else + + if ( st_ivas->renderer_type == RENDERER_DIRAC ) { - /* TD renderer handle */ - if ( st_ivas->hBinRendererTd != NULL ) + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { - ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + return error; } - if ( st_ivas->hHrtfTD != NULL ) // VE: this is copied from ivas_ism_bitrate_switching() but a review is needed + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - st_ivas->hHrtfTD = NULL; + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ + if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } } - - /* ISM renderer handle */ - if ( st_ivas->hIsmRendererData != NULL ) + else { - free( st_ivas->hIsmRendererData ); - st_ivas->hIsmRendererData = NULL; + /* ISM renderer handle */ + if ( st_ivas->hIsmRendererData != NULL ) + { + free( st_ivas->hIsmRendererData ); + st_ivas->hIsmRendererData = NULL; + } } } #endif -- GitLab From 1b9e750b9f24208e15e8d8cd64547d222226a14c Mon Sep 17 00:00:00 2001 From: Auto Commit Date: Tue, 11 Apr 2023 06:49:44 -0400 Subject: [PATCH 066/173] just remove option2 as it didn't show significative improvement --- lib_com/ivas_stereo_td_bit_alloc.c | 2 +- lib_enc/ivas_stereo_classifier.c | 1 - lib_enc/ivas_stereo_td_enc.c | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index b0ae12ecd8..5daaf61e12 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -139,7 +139,7 @@ void tdm_bit_alloc( *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /* secondary channel bitrate allocation based on the energy scaling ratio */ -#ifdef OMASA_TUNING +#if defined OMASA_TUNING if ( (IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( IsOmasa == 1 && coder_type > UNVOICED ) ) diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 8e20c13c8a..534dc2189c 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -209,7 +209,6 @@ int16_t select_stereo_mode( set_f( hStereoClassif->xtalk_fv, -1.0f, SSC_MAX_NFEA ); } } - #ifdef DEBUG_MODE_TD dbgwrite( &hStereoClassif->unclr_decision, sizeof( int16_t ), 1, L_FRAME16k, "res/unclr_decision.enc" ); dbgwrite( &hStereoClassif->xtalk_decision, sizeof( int16_t ), 1, L_FRAME16k, "res/xtalk_decision.enc" ); diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 6e13ec2075..11da8f6404 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -430,6 +430,7 @@ void tdm_configure_enc( sts[1]->coder_type = GENERIC; } hStereoTD->tdm_lp_reuse_flag = 1; + #ifdef OMASA_TUNING if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 11000 ) #else -- GitLab From 4f30e166afc2d359b756ece40a960aa29014dae2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 11 Apr 2023 16:19:47 +0200 Subject: [PATCH 067/173] - rename compilation switch OMASA_TUNING to OMASA_TUNING_TD_STEREO - revert changes in MSVC project files --- Workspace_msvc/decoder.vcxproj | 6 +++--- Workspace_msvc/encoder.vcxproj | 8 ++++---- Workspace_msvc/lib_com.vcxproj | 8 ++++---- Workspace_msvc/lib_debug.vcxproj | 8 ++++---- Workspace_msvc/lib_dec.vcxproj | 8 ++++---- Workspace_msvc/lib_enc.vcxproj | 8 ++++---- Workspace_msvc/lib_rend.vcxproj | 8 ++++---- Workspace_msvc/lib_util.vcxproj | 8 ++++---- Workspace_msvc/renderer.vcxproj | 8 ++++---- lib_com/ivas_prot.h | 16 ++++++++-------- lib_com/ivas_stereo_td_bit_alloc.c | 11 +++++------ lib_com/options.h | 2 +- lib_dec/ivas_cpe_dec.c | 9 +++++---- lib_dec/ivas_stereo_td_dec.c | 12 +++++++----- lib_enc/ivas_cpe_enc.c | 10 ++++++---- lib_enc/ivas_stereo_td_analysis.c | 10 ++++++---- lib_enc/ivas_stereo_td_enc.c | 16 +++++++++------- 17 files changed, 82 insertions(+), 74 deletions(-) diff --git a/Workspace_msvc/decoder.vcxproj b/Workspace_msvc/decoder.vcxproj index f0016965e0..e59992847c 100644 --- a/Workspace_msvc/decoder.vcxproj +++ b/Workspace_msvc/decoder.vcxproj @@ -14,18 +14,18 @@ decoder {E3DCBC31-7FC9-D127-E000-529F8460D5FD} decoder - 10.0 + 10.0.17763.0 Application - v142 + v141 false MultiByte Application - v142 + v141 false MultiByte diff --git a/Workspace_msvc/encoder.vcxproj b/Workspace_msvc/encoder.vcxproj index fc7e189560..bcfe92a4db 100644 --- a/Workspace_msvc/encoder.vcxproj +++ b/Workspace_msvc/encoder.vcxproj @@ -18,24 +18,24 @@ encoder {B3FC9DFC-7268-8660-7C0D-B60BAF02C554} encoder - 10.0 + 10.0.17763.0 Application - v142 + v141 false MultiByte Application - v142 + v141 false MultiByte Application - v142 + v141 false MultiByte diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index ed8012c4d3..78ed7bb39d 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -17,24 +17,24 @@ {39EC200D-7795-4FF8-B214-B24EDA5526AE} common - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte diff --git a/Workspace_msvc/lib_debug.vcxproj b/Workspace_msvc/lib_debug.vcxproj index 6a5e102b0c..3b648fae04 100644 --- a/Workspace_msvc/lib_debug.vcxproj +++ b/Workspace_msvc/lib_debug.vcxproj @@ -17,22 +17,22 @@ {54509728-928B-44D9-A118-A6F92F08B34F} debug - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 MultiByte StaticLibrary - v142 + v141 MultiByte StaticLibrary - v142 + v141 MultiByte true diff --git a/Workspace_msvc/lib_dec.vcxproj b/Workspace_msvc/lib_dec.vcxproj index facb2d3bc3..dd2ed44443 100644 --- a/Workspace_msvc/lib_dec.vcxproj +++ b/Workspace_msvc/lib_dec.vcxproj @@ -18,24 +18,24 @@ lib_dec {E822DDAF-0F5F-4CD0-A694-38AE69DE74D3} evs_dec - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte diff --git a/Workspace_msvc/lib_enc.vcxproj b/Workspace_msvc/lib_enc.vcxproj index eede51cfde..af7ca35b12 100644 --- a/Workspace_msvc/lib_enc.vcxproj +++ b/Workspace_msvc/lib_enc.vcxproj @@ -18,24 +18,24 @@ lib_enc {824DA4CF-06F0-45C9-929A-8792F0E19C3E} evs_enc - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte diff --git a/Workspace_msvc/lib_rend.vcxproj b/Workspace_msvc/lib_rend.vcxproj index 1cb397d10f..865652649a 100644 --- a/Workspace_msvc/lib_rend.vcxproj +++ b/Workspace_msvc/lib_rend.vcxproj @@ -18,24 +18,24 @@ lib_rend {718DE063-A18B-BB72-9150-62B892E6FFA6} evs_dec - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte StaticLibrary - v142 + v141 false MultiByte diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index d1a1a8d818..5b5e5f30cc 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -17,22 +17,22 @@ {2FA8F384-0775-F3B7-F8C3-85209222FC70} utility - 10.0 + 10.0.17763.0 StaticLibrary - v142 + v141 MultiByte StaticLibrary - v142 + v141 MultiByte StaticLibrary - v142 + v141 MultiByte true diff --git a/Workspace_msvc/renderer.vcxproj b/Workspace_msvc/renderer.vcxproj index d90b4a6251..94ad9f774e 100644 --- a/Workspace_msvc/renderer.vcxproj +++ b/Workspace_msvc/renderer.vcxproj @@ -18,24 +18,24 @@ renderer {12B4C8A5-1E06-4E30-B443-D1F916F52B47} renderer - 10.0 + 10.0.17763.0 Application - v142 + v141 false MultiByte Application - v142 + v141 false MultiByte Application - v142 + v141 false MultiByte diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 61a40222ed..0964ffe870 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1825,8 +1825,8 @@ int16_t stereo_tdm_ener_analysis( const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ -#ifdef OMASA_TUNING - ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#ifdef OMASA_TUNING_TD_STEREO + ,const int16_t isOmasa /* i : flag that indicates OMASA format */ #endif ); @@ -1849,8 +1849,8 @@ void tdm_configure_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#ifdef OMASA_TUNING_TD_STEREO + ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ #endif ); @@ -1906,8 +1906,8 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#ifdef OMASA_TUNING_TD_STEREO + ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ #endif ); @@ -1932,8 +1932,8 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : Flag that indicates presence of OMASA */ +#ifdef OMASA_TUNING_TD_STEREO + ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ #endif ); diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 5daaf61e12..ac56cd6537 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -88,8 +88,9 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : Flag that indicates presence of OMASA */ +#ifdef OMASA_TUNING_TD_STEREO + , + const int16_t IsOmasa /* i : flag that indicates OMASA format */ #endif ) { @@ -139,10 +140,8 @@ void tdm_bit_alloc( *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /* secondary channel bitrate allocation based on the energy scaling ratio */ -#if defined OMASA_TUNING - if ( (IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) - || - ( IsOmasa == 1 && coder_type > UNVOICED ) ) +#ifdef OMASA_TUNING_TD_STEREO + if ( ( IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( IsOmasa == 1 && coder_type > UNVOICED ) ) #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) #endif diff --git a/lib_com/options.h b/lib_com/options.h index ce6430957f..024ea86156 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,7 +159,7 @@ #define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ #define OMASA_BRATE_SW /* VA: support of bitrate switching in OMASA format */ #define FIX_TD5_IN_OMASA // do not transmit extended MD in OMASA -#define OMASA_TUNING +#define OMASA_TUNING_TD_STEREO /* VA: tuning of TD stereo in OMASA format */ #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index f42dfe42e7..d1495e7f91 100755 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -413,11 +413,12 @@ ivas_error ivas_cpe_dec( { if ( !st_ivas->bfi ) { - tdm_configure_dec( hCPE, &tdm_ratio_idx, nb_bits_metadata -#ifdef OMASA_TUNING - , (st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_24k4)) + tdm_configure_dec( hCPE, &tdm_ratio_idx, nb_bits_metadata +#ifdef OMASA_TUNING_TD_STEREO + , + ( st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_24k4 ) ) #endif - ); + ); sts[1]->bit_stream = sts[0]->bit_stream + ( sts[0]->total_brate / FRAMES_PER_SEC ); } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 7cfa3d92fd..e613e8ea2e 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -87,8 +87,9 @@ void tdm_configure_dec( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#ifdef OMASA_TUNING_TD_STEREO + , + const int16_t IsOmasa /* i : flag that indicates OMASA format*/ #endif ) @@ -313,10 +314,11 @@ void tdm_configure_dec( hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx -#ifdef OMASA_TUNING - ,IsOmasa +#ifdef OMASA_TUNING_TD_STEREO + , + IsOmasa #endif - ); + ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 0865e2b281..422d7f9156 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -414,8 +414,9 @@ ivas_error ivas_cpe_enc( { /* Determine the energy ratio between the 2 channels */ tdm_ratio_idx = stereo_tdm_ener_analysis( hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM -#ifdef OMASA_TUNING - , st_ivas->hOMasa != NULL +#ifdef OMASA_TUNING_TD_STEREO + , + st_ivas->hOMasa != NULL #endif ); @@ -584,8 +585,9 @@ ivas_error ivas_cpe_enc( tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); tdm_configure_enc( hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata -#ifdef OMASA_TUNING - ,st_ivas->hOMasa != NULL +#ifdef OMASA_TUNING_TD_STEREO + , + st_ivas->hOMasa != NULL #endif ); diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 97522ef861..5ef8001b7a 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -115,8 +115,9 @@ int16_t stereo_tdm_ener_analysis( const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ -#ifdef OMASA_TUNING - ,const int16_t isOmasa /* i : Flag to indicate that Omasa is present */ +#ifdef OMASA_TUNING_TD_STEREO + , + const int16_t isOmasa /* i : flag that indicates OMASA format */ #endif ) { @@ -197,8 +198,9 @@ int16_t stereo_tdm_ener_analysis( * When the energies of channels are low enough, compute the ratio * of L and R needed to create new mono/side signals *----------------------------------------------------------------*/ -#ifdef OMASA_TUNING - if ( isOmasa ) + +#ifdef OMASA_TUNING_TD_STEREO + if ( isOmasa ) { if ( ( hCPE->hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 11da8f6404..82e3f4bdfd 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -309,8 +309,9 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING - ,const int16_t IsOmasa /* i : flag that indicate the presence of Omasa*/ +#ifdef OMASA_TUNING_TD_STEREO + , + const int16_t IsOmasa /* i : flag that indicates OMASA format */ #endif ) { @@ -425,13 +426,13 @@ void tdm_configure_enc( #ifdef MASA_AND_OBJECTS if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 ) { - if ( sts[1]->coder_type == UNVOICED) + if ( sts[1]->coder_type == UNVOICED ) { sts[1]->coder_type = GENERIC; } hStereoTD->tdm_lp_reuse_flag = 1; -#ifdef OMASA_TUNING +#ifdef OMASA_TUNING_TD_STEREO if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 11000 ) #else if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 ) @@ -488,10 +489,11 @@ void tdm_configure_enc( hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx -#ifdef OMASA_TUNING - ,IsOmasa +#ifdef OMASA_TUNING_TD_STEREO + , + IsOmasa #endif - ); + ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #endif -- GitLab From 6e84dd1c22ac89b7b8adbcb4504a8a1e46b1a199 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 18 Apr 2023 15:49:04 +0200 Subject: [PATCH 068/173] comment --- lib_enc/ivas_masa_enc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index dd025797d2..5e81132ced 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2315,11 +2315,12 @@ static void copy_masa_metadata( * Compare the similarity of MASA metadata in two sub-frames *-------------------------------------------------------------------*/ +/* r: similarity decision */ static uint8_t are_masa_subframes_similar( const MASA_METADATA_HANDLE frame1, /* i : MASA metadata frame 1 */ const uint8_t sf1_idx, /* i : index of the subframe of frame1 to inspect */ const MASA_METADATA_HANDLE frame2, /* i : MASA metadata frame 2 */ - const uint8_t sf2_idx /* o : index of the subframe of frame2 to inspect */ + const uint8_t sf2_idx /* i : index of the subframe of frame2 to inspect */ ) { uint8_t num_dir; -- GitLab From e71215d99e750557a18aa57573de637d6f19ec6c Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 19 Apr 2023 15:27:03 +0300 Subject: [PATCH 069/173] Disable switch for issue 350 to restore BE within OMASA until branch is fully adapted to it. --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 29d3c3340e..8bd854e1b4 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -144,7 +144,7 @@ #define FIX_103_RA_PARAMS_PARAM_BIN_REND /* Issue 103: Digest room acoustics parameters for Parametric Binaural Renderer*/ /*#define SBA_HPF_TUNING_DEC*/ -#define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ +/*#define FIX_350_MASA_DELAY_COMP*/ /* Nokia: Issue 350: MASA audio/meta delay compensation */ #define FIX_MDCT_BASED_BWD /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */ #define DISCRETE_ISM_DTX_CNG /* FhG/VA: contribution 15 - DTX/CNG for (discrete) ISM */ #define NCHAN_ISM_PARAMETER /* VA: make 'nchan_ism' parameter part of st_ivas/hEncoderConfig */ -- GitLab From d34332b6fe1b4b0fff45c990d7f76f2e32e53352 Mon Sep 17 00:00:00 2001 From: Lauros Pajunen Date: Thu, 20 Apr 2023 10:13:54 +0300 Subject: [PATCH 070/173] Fixes to stereo, binaural_room, and edited rendering, and fixes to msan errors. --- lib_com/bitstream.c | 14 ++++++++++---- lib_dec/ivas_masa_dec.c | 4 ++++ lib_dec/lib_dec.c | 4 ++++ lib_rend/ivas_dirac_dec_binaural_functions.c | 17 +++++++++++------ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 3b11ab8c3d..ac201dffbc 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1979,17 +1979,22 @@ ivas_error preview_indices( else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { /* read number of objects from the bitstream */ +#ifdef OMASA_UPDATES + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ + st_ivas->nchan_ism = 0; +#else st_ivas->nchan_transport = 0; +#endif if ( total_brate != SID_2k40 && total_brate != FRAME_NO_DATA ) { +#ifdef OMASA_UPDATES + st_ivas->nchan_ism = 2 * bit_stream[total_brate / FRAMES_PER_SEC - 1] + bit_stream[total_brate / FRAMES_PER_SEC - 2] + 1; +#endif st_ivas->ism_mode = ivas_omasa_ism_mode_select( total_brate, st_ivas->nchan_ism ); -#ifdef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else +#ifndef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { st_ivas->nchan_transport = 0; } @@ -2004,6 +2009,7 @@ ivas_error preview_indices( st_ivas->nchan_transport++; k--; } +#endif } } #endif diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 38ef2a4c06..959300ca74 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -2462,6 +2462,10 @@ void ivas_masa_ism_set_edited_objects( { hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism] = st_ivas->azimuth_edited; hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism] = st_ivas->elevation_edited; +#ifdef OMASA_UPDATES + st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->azimuth = st_ivas->azimuth_edited; + st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->elevation = st_ivas->elevation_edited; +#endif } } #ifdef OMASA_UPDATES diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index bcd93ece03..1826052808 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2026,7 +2026,11 @@ static ivas_error printConfigInfo_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifdef OMASA_UPDATES + fprintf( stdout, "Input configuration: combined ISM and MASA (%i ISM stream(s)) \n", st_ivas->nchan_ism ); +#else fprintf( stdout, "Input configuration: combined ISM and MASA (%i separated ISM stream(s)) \n", st_ivas->nchan_transport ); +#endif } #endif } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index e219e5bd54..1e1e591508 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -467,6 +467,10 @@ static void ivas_dirac_dec_binaural_internal( { numInChannels++; } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + numInChannels += (uint8_t) st_ivas->nchan_ism; + } #else if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) { @@ -1220,6 +1224,13 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( } #endif } +#ifdef OMASA_UPDATES + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + separateCenterChannelRendering = 1; + nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; + } +#endif #else separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; #endif @@ -1386,11 +1397,6 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES - aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism; - eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; - instantChange = 1; -#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB]; @@ -1402,7 +1408,6 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; instantChange = 1; } -#endif } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) -- GitLab From 9649dad5232f5eabca597721934243e9890435ca Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 12:29:34 +0200 Subject: [PATCH 071/173] fix build when MASA_AND_OBJECTS is disabled --- lib_com/options.h | 10 +++++----- lib_dec/ivas_cpe_dec.c | 2 ++ lib_dec/ivas_sce_dec.c | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8bd854e1b4..f5f9f9d214 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,13 +58,13 @@ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO -#define DEBUG_MODE_ACELP /* output most important ACELP core parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ -/*#define DEBUG_MODE_DFT */ /* output most important DFT stereo parameters to the subdirectory "res/" */ -#define DEBUG_MODE_TD /* output most important TD stereo parameters to the subdirectory "res/ */ -//#define DEBUG_MODE_DIRAC /* output most important DIRAC parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_DFT */ /* output most important DFT stereo parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_TD*/ /* output most important TD stereo parameters to the subdirectory "res/ */ +/*#define DEBUG_MODE_DIRAC*/ /* output most important DIRAC parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_MDCT*/ /* output most important MDCT parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_MC */ /* output Parametric MC paramters to the subdirectory "res/" */ /*#define DEBUG_MODE_PARAM_ISM*/ /* output Parametric ISM paramters to the subdirectory "res/" */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index f78f5f08c8..12bcab4584 100755 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -597,12 +597,14 @@ ivas_error ivas_cpe_dec( dbgwrite( output[j], sizeof( float ), output_frame, 1, fname( debug_dir, "output.cpe", j, cpe_id, DEC ) ); } +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) { tmpF = 0; dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.sce", 0, cpe_id, DEC ) ); dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, cpe_id, DEC ) ); } +#endif } } #endif diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index ccb5fcca89..dc44097d9d 100755 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -326,12 +326,14 @@ ivas_error ivas_sce_dec( dbgwrite( output, sizeof( float ), output_frame, 1, fname( debug_dir, "output.sce", 0, sce_id, DEC ) ); +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) { tmpF = 0; dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.cpe", 0, sce_id, DEC ) ); dbgwrite( &tmpF, sizeof( float ), 1, output_frame, fname( debug_dir, "output.mct", 0, sce_id, DEC ) ); } +#endif } } #endif -- GitLab From 8d38e91d2277806687070c44d9c38cfbdb70307e Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 12:32:04 +0200 Subject: [PATCH 072/173] fix in tdm_configure_dec() within MASA_AND_OBJECTS --- lib_dec/ivas_stereo_td_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index e613e8ea2e..fbfa270727 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -291,7 +291,7 @@ void tdm_configure_dec( /* set the BW of the secondary channel */ #ifdef MASA_AND_OBJECTS - if ( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel > IVAS_16k4 / FRAMES_PER_SEC ) + if ( hStereoTD->tdm_LRTD_flag && sts[1]->bits_frame_channel >= IVAS_16k4 / FRAMES_PER_SEC ) #else if ( hStereoTD->tdm_LRTD_flag && hCPE->element_brate > IVAS_13k2 ) #endif -- GitLab From d5025ce2109d4e1934b148b311443a2b3690c4e2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 12:34:40 +0200 Subject: [PATCH 073/173] clang-format --- lib_dec/ivas_dirac_dec.c | 82 ++++++++++++++++----------------- lib_dec/ivas_ism_metadata_dec.c | 12 ++--- lib_dec/ivas_ism_renderer.c | 6 +-- lib_enc/ivas_cpe_enc.c | 4 +- lib_enc/ivas_enc.c | 4 +- lib_enc/ivas_stereo_td_enc.c | 4 +- 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index e471738ca3..e2bf03e4fb 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -321,7 +321,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } ivas_masa_init_stereotype_detection( hDirAC->masa_stereo_type_detect ); } @@ -401,7 +401,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } if ( hDirAC->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) @@ -410,7 +410,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_s( hDirAC->proto_index_dir, 0, hDirAC->num_outputs_dir ); @@ -420,7 +420,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff ); @@ -543,7 +543,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } /* reallocate static memory */ else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->num_outputs_dir != num_outputs_dir_old ) @@ -553,7 +553,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } if ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) @@ -574,7 +574,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder && ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) { @@ -583,7 +583,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_f( hDirAC->hoa_encoder, 0.0f, nchan_out_woLFE * hDirAC->num_outputs_diff ); compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirAC->hoa_encoder, hDirAC->num_outputs_diff, hDirAC->hOutSetup.ambisonics_order ); @@ -673,17 +673,17 @@ ivas_error ivas_dirac_dec_config( if ( ( flag_config == DIRAC_OPEN && hDirAC->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; - } + } } else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { @@ -697,19 +697,19 @@ ivas_error ivas_dirac_dec_config( ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; + } } } - } /* output synthesis */ if ( flag_config == DIRAC_OPEN ) @@ -755,7 +755,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } else if ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->num_protos_diff != num_protos_diff_old ) ) { @@ -764,9 +764,9 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } } - } if ( flag_config == DIRAC_OPEN ) @@ -793,7 +793,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } @@ -1329,9 +1329,9 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } - } hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; hDirAC->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; @@ -1388,17 +1388,17 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } } else { if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } - } hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; @@ -1410,7 +1410,7 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) { @@ -1435,10 +1435,10 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } - } else { if ( num_protos_dir > 2 ) @@ -1446,7 +1446,7 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } } if ( hDirAC->proto_signal_decorr_on ) @@ -1454,9 +1454,9 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } - } return IVAS_ERR_OK; } @@ -1755,10 +1755,10 @@ void ivas_qmetadata_to_dirac( { meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { hDirAC->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; hDirAC->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hDirAC->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; @@ -1827,10 +1827,10 @@ void ivas_qmetadata_to_dirac( { meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { hDirAC->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; hDirAC->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hDirAC->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; @@ -1883,7 +1883,7 @@ void ivas_qmetadata_to_dirac( set_s( hDirAC->elevation2[meta_write_index], 0, hDirAC->num_freq_bands ); set_zero( hDirAC->energy_ratio2[meta_write_index], hDirAC->num_freq_bands ); set_zero( hDirAC->spreadCoherence2[meta_write_index], hDirAC->num_freq_bands ); - } + } } #endif } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 1cc7028c55..0565447847 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -396,8 +396,8 @@ ivas_error ivas_ism_metadata_dec( if ( ism_metadata_flag_global ) { /*----------------------------------------------------------------* - * Metadata decoding and dequantization, loop over all objects - *----------------------------------------------------------------*/ + * Metadata decoding and dequantization, loop over all objects + *----------------------------------------------------------------*/ int16_t total_bits_metadata = 0, bits_metadata_ism = 0; int16_t nb_bits_objcod_read; @@ -732,8 +732,8 @@ ivas_error ivas_ism_metadata_dec( } /*----------------------------------------------------------------* - * Set bitsream pointers - *----------------------------------------------------------------*/ + * Set bitsream pointers + *----------------------------------------------------------------*/ /* set the bitstream pointer to its original position */ st0->bit_stream = bstr_orig; @@ -747,8 +747,8 @@ ivas_error ivas_ism_metadata_dec( #ifdef DISCRETE_ISM_DTX_CNG /*----------------------------------------------------------------* - * Updates - *----------------------------------------------------------------*/ + * Updates + *----------------------------------------------------------------*/ set_s( md_diff_flag, 1, nchan_ism ); diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 00d93d15b6..119845d462 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -256,8 +256,8 @@ void ivas_ism_get_stereo_gains( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------------* -* ivas_masa_ism_separate_object_renderer_open() -* + * ivas_masa_ism_separate_object_renderer_open() + * * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ @@ -348,7 +348,7 @@ void ivas_masa_ism_separate_object_render( lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; #ifdef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) #else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 490cd41d1e..bfa7d86756 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -820,7 +820,7 @@ ivas_error ivas_cpe_enc( dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_NCShift" ); dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_ica_gD" ); n = -1; - //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + // dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } else if ( hCPE->element_mode == IVAS_CPE_TD ) { @@ -837,7 +837,7 @@ ivas_error ivas_cpe_enc( else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { n = -2; - //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + // dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5d329701cb..920193c999 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -249,7 +249,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ) ) != IVAS_ERR_OK ) { @@ -459,7 +459,7 @@ ivas_error ivas_enc( if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 82e3f4bdfd..7c0649c5ab 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -283,8 +283,8 @@ ivas_error stereo_set_tdm( dbgwrite( &tmp, 2, 1, 320, "res/inst_ratio_L" ); dbgwrite( &ftmp, 4, 1, 320, "res/ratio_L" ); dbgwrite( &tmp, 2, 1, 320, "res/tdm_low_rate_mode" ); - //dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); - //dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); + // dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); + // dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); } #endif hCPE->hCoreCoder[0]->tdm_LRTD_flag = 0; -- GitLab From b12b6b9a5cd566d1778323c0c7f1d148f8f2f4cc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 12:37:50 +0200 Subject: [PATCH 074/173] build warnings --- lib_enc/ivas_masa_enc.c | 4 ++-- lib_enc/ivas_omasa_enc.c | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 5e81132ced..c62fc4b3bf 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -71,7 +71,7 @@ static void quantize_ratio_ism_vector( const float *ratio_ism, int16_t *idx, con static int16_t index_slice_enum( const int16_t *ratio_ism_idx, const int16_t nchan_ism ); -static int16_t encode_ratio_ism_subframe( const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, const int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); +static int16_t encode_ratio_ism_subframe( const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const uint8_t numCodingBands, const int16_t sf, const int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); static void transform_index_and_GR_encode( int16_t *diff_idx, const int16_t len, const int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); @@ -3064,7 +3064,7 @@ static void estimate_bits_subband_ism_ratio( static int16_t encode_ratio_ism_subframe( const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, - const int16_t numCodingBands, + const uint8_t numCodingBands, const int16_t sf, const int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 86b5cbe90f..ac89c528a6 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -228,13 +228,11 @@ ivas_error ivas_omasa_enc_config( { int16_t k, sce_id, nSCE_old; int32_t ivas_total_brate, ism_total_brate; - ISM_MODE ism_mode_old; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; hEncoderConfig = st_ivas->hEncoderConfig; ivas_total_brate = hEncoderConfig->ivas_total_brate; - ism_mode_old = st_ivas->ism_mode; nSCE_old = st_ivas->nSCE; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); -- GitLab From a0fdc85f356f42c6c7383d8cdddc33912839b683 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 13:12:25 +0200 Subject: [PATCH 075/173] build warnings --- lib_enc/ivas_masa_enc.c | 45 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c62fc4b3bf..67c935d187 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -67,20 +67,6 @@ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_H #endif ); -static void quantize_ratio_ism_vector( const float *ratio_ism, int16_t *idx, const int16_t nchan_ism, const float masa_to_total_energy_ratio, const int16_t idx_sep_object ); - -static int16_t index_slice_enum( const int16_t *ratio_ism_idx, const int16_t nchan_ism ); - -static int16_t encode_ratio_ism_subframe( const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const uint8_t numCodingBands, const int16_t sf, const int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, const int16_t idx_sep_obj ); - -static void transform_index_and_GR_encode( int16_t *diff_idx, const int16_t len, const int16_t GR_order, BSTR_ENC_HANDLE hMetaData ); - -static void transform_difference_index( const int16_t *diff_idx, int16_t *idx, const int16_t len ); - -static void independent_coding_ratio_ism_idx( const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const float *masa_to_total_energy_ratio, const int16_t nchan_ism, const int16_t numCodingBands, const int16_t bits_index, BSTR_ENC_HANDLE hMetaData ); - -static void remove_sep_obj( int16_t *diff_idx, const int16_t nchan_ism, const int16_t idx_sep_obj ); - #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif @@ -764,6 +750,7 @@ ivas_error ivas_masa_enc_config( { #ifdef FIX_382_MASA_META_FRAMING_ASYNC detect_framing_async( hMasa ); /* detect the offset, set 1sf/4sf mode based on this. potentially also shift the metadata using a history buffer */ + if ( hMasa->data.sync_state.frame_mode == MASA_FRAME_1SF && hMasa->data.sync_state.prev_offset != 0 ) { /* average over sub-frames */ @@ -2871,7 +2858,7 @@ static void transform_index_and_GR_encode( int16_t *diff_idx, /* i : differenc eindex to encode */ const int16_t len, /* i : input length */ const int16_t GR_order, /* i : GR order */ - BSTR_ENC_HANDLE hMetaData /* i/o: bitstream */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ ) { int16_t i; @@ -2893,7 +2880,7 @@ static void transform_index_and_GR_encode( static int16_t try_differential( const int16_t numCodingBands, const float *masa_to_total_energy_ratio, - const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t bits_index, int16_t *p_b_signif ) @@ -2945,7 +2932,7 @@ static void differential_coding_first_subframe( BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t b_signif, - const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t bits_index ) @@ -2982,12 +2969,12 @@ static void differential_coding_first_subframe( static void independent_coding_ratio_ism_idx( - const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ - const float *masa_to_total_energy_ratio, /* i : MASA to total ratios */ - const int16_t nchan_ism, /* i : number of objects */ - const int16_t numCodingBands, /* i : number of subbands */ - const int16_t bits_index, /* i : number of bits per index */ - BSTR_ENC_HANDLE hMetaData /* i/o: bitstream */ + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ + const float *masa_to_total_energy_ratio, /* i : MASA to total ratios */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t numCodingBands, /* i : number of subbands */ + const int16_t bits_index, /* i : number of bits per index */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ ) { int16_t b, index; @@ -3040,14 +3027,16 @@ static void estimate_bits_subband_ism_ratio( /* take difference with respect to previous subframe */ v_sub_s( ratio_ism_idx, ratio_ism_idx_ref, diff_idx, nchan_ism ); + if ( shift_one ) { remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj ); } + /* transform difference index into positive */ transform_difference_index( diff_idx, diff_idx, nchan_ism - 1 - shift_one ); - /* GR encoding */ + /* GR encoding */ for ( i = 0; i < nchan_ism - 1 - shift_one; i++ ) { nbits0 += ivas_qmetadata_encode_extended_gr_length( diff_idx[i], 100, 0 ); @@ -3062,11 +3051,11 @@ static void estimate_bits_subband_ism_ratio( static int16_t encode_ratio_ism_subframe( - const int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const uint8_t numCodingBands, const int16_t sf, - const int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], + int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], BSTR_ENC_HANDLE hMetaData, const float *masa_to_total_energy_ratio, const int16_t shift_one, @@ -3289,6 +3278,7 @@ static int16_t encode_ratio_ism_subframe( { /* take difference with respect to previous subframe */ v_sub_s( ratio_ism_idx[0], ratio_ism_idx_prev_sf[0], diff_idx, nchan_ism ); + if ( shift_one ) { remove_sep_obj( diff_idx, nchan_ism, idx_sep_obj_local ); @@ -3478,8 +3468,10 @@ static void ivas_encode_masaism_metadata( assert( ( hMasa->data.energy_ratio_ism[sf][band][obj] >= 0 ) && ( hMasa->data.energy_ratio_ism[sf][band][obj] <= 1 ) ); ratio_ism[band][obj] = hMasa->data.energy_ratio_ism[sf][band][obj]; } + /* Quantize ISM ratios */ quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); + if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { i = 0; @@ -3553,7 +3545,6 @@ static void ivas_encode_masaism_metadata( encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); } - /* calculate quantized ISM ratios */ /* save previous subframe indexes */ for ( band = 0; band < numCodingBands; band++ ) -- GitLab From ea30c7e221bfe2cbb1395943c3730e0aa591e7c4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 13:21:46 +0200 Subject: [PATCH 076/173] attempt to fix error: "MemorySanitizer: use-of-uninitialized-value" --- lib_dec/ivas_dirac_output_synthesis_dec.c | 1 + lib_dec/ivas_masa_dec.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 40883784bd..461ce67274 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -1526,6 +1526,7 @@ void ivas_dirac_dec_compute_directional_responses( num_channels_dir = hDirAC->num_outputs_dir; azimuth = hDirAC->azimuth[hDirAC->dirac_read_idx]; elevation = hDirAC->elevation[hDirAC->dirac_read_idx]; + #ifdef MASA_AND_OBJECTS if ( hDirAC->numParametricDirections == 2 ) #else diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 959300ca74..99c9cdaf60 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1523,6 +1523,9 @@ void ivas_spar_param_to_masa_param_mapping( /* Set values */ hDirAC = st_ivas->hDirAC; +#ifdef MASA_AND_OBJECTS + hDirAC->numParametricDirections = 1; +#endif hDirAC->numSimultaneousDirections = 1; hDiffuseDist = st_ivas->hDirAC->hDiffuseDist; nchan_transport = st_ivas->nchan_transport; -- GitLab From fce075b35370a055aba597f2f02241c34672b1e9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 13:38:19 +0200 Subject: [PATCH 077/173] attempt to fix error: "MemorySanitizer: use-of-uninitialized-value" --- lib_rend/lib_rend.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3d2420632d..4249b4790e 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5312,6 +5312,9 @@ static void copyMasaMetadataToDiracRenderer( int16_t meta_write_index; #endif +#ifdef MASA_AND_OBJECTS + hDirAC->numParametricDirections = meta->descriptive_meta.numberOfDirections; +#endif hDirAC->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1; for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) -- GitLab From d9037ac9e13d6d893f7afbbe1bd00859bb6aaa98 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 25 Apr 2023 14:21:34 +0200 Subject: [PATCH 078/173] updates within OMASA_TUNING_TD_STEREO --- lib_com/ivas_prot.h | 26 +++++++++++++------------- lib_com/ivas_stereo_td_bit_alloc.c | 9 ++++----- lib_dec/ivas_cpe_dec.c | 7 +++---- lib_dec/ivas_stereo_td_dec.c | 22 ++++++++++------------ lib_enc/ivas_cpe_enc.c | 14 ++++++-------- lib_enc/ivas_stereo_td_analysis.c | 10 +++++----- lib_enc/ivas_stereo_td_enc.c | 20 +++++++++----------- 7 files changed, 50 insertions(+), 58 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 1bc5b19ea4..3ca21a13d1 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1826,14 +1826,15 @@ void stereo_tdm_prep_dwnmx ( const float *input1, /* i : right channel input */ const int16_t input_frame /* i : frame lenght */ ); + int16_t stereo_tdm_ener_analysis( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_ENC_HANDLE hCPE, /* i : CPE structure */ const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ -#ifdef OMASA_TUNING_TD_STEREO - ,const int16_t isOmasa /* i : flag that indicates OMASA format */ -#endif ); void stereo_tdm_downmix( @@ -1852,13 +1853,12 @@ void stereo_td_init_dec( ); void tdm_configure_dec( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING_TD_STEREO - ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ -#endif - ); void tdm_upmix_plain( @@ -1905,6 +1905,9 @@ void tdm_ol_pitch_comparison( ); void tdm_configure_enc( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ @@ -1912,9 +1915,6 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING_TD_STEREO - ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ -#endif ); ivas_error signaling_enc_secondary( @@ -1924,6 +1924,9 @@ ivas_error signaling_enc_secondary( ); void tdm_bit_alloc( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ int32_t *total_brate_pri, /* o : Allocated primary channel bitrate */ @@ -1938,9 +1941,6 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx /* i : instantaneous correlation ratio index */ -#ifdef OMASA_TUNING_TD_STEREO - ,const int16_t IsOmasa /* i : flag that indicates OMASA format */ -#endif ); void td_stereo_param_updt( diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index ac56cd6537..48c5eaf8ae 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -74,6 +74,9 @@ *-------------------------------------------------------------------*/ void tdm_bit_alloc( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ int32_t *total_brate_pri, /* o : Allocated primary channel bitrate */ @@ -88,10 +91,6 @@ void tdm_bit_alloc( const int16_t tdm_LRTD_flag, /* i : LRTD stereo mode flag */ const int16_t coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ const int16_t tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ -#ifdef OMASA_TUNING_TD_STEREO - , - const int16_t IsOmasa /* i : flag that indicates OMASA format */ -#endif ) { int16_t idx, four_subfr_fcb, two_subfr_fcb; @@ -141,7 +140,7 @@ void tdm_bit_alloc( /* secondary channel bitrate allocation based on the energy scaling ratio */ #ifdef OMASA_TUNING_TD_STEREO - if ( ( IsOmasa == 0 && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( IsOmasa == 1 && coder_type > UNVOICED ) ) + if ( ( ivas_format != MASA_ISM_FORMAT && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && coder_type > UNVOICED ) ) #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 12bcab4584..74f22590ad 100755 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -413,12 +413,11 @@ ivas_error ivas_cpe_dec( { if ( !st_ivas->bfi ) { - tdm_configure_dec( hCPE, &tdm_ratio_idx, nb_bits_metadata + tdm_configure_dec( #ifdef OMASA_TUNING_TD_STEREO - , - ( st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_24k4 ) ) + st_ivas->ivas_format, #endif - ); + hCPE, &tdm_ratio_idx, nb_bits_metadata ); sts[1]->bit_stream = sts[0]->bit_stream + ( sts[0]->total_brate / FRAMES_PER_SEC ); } diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index fbfa270727..d8e817638a 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -84,14 +84,12 @@ void stereo_td_init_dec( *-------------------------------------------------------------------*/ void tdm_configure_dec( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING_TD_STEREO - , - const int16_t IsOmasa /* i : flag that indicates OMASA format*/ -#endif - ) { STEREO_TD_DEC_DATA_HANDLE hStereoTD; @@ -310,15 +308,15 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, - hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), - &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx + tdm_bit_alloc( #ifdef OMASA_TUNING_TD_STEREO - , - IsOmasa + ivas_format, #endif - ); + + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index bfa7d86756..48a343bec1 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -435,12 +435,11 @@ ivas_error ivas_cpe_enc( else if ( hCPE->element_mode == IVAS_CPE_TD ) { /* Determine the energy ratio between the 2 channels */ - tdm_ratio_idx = stereo_tdm_ener_analysis( hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM + tdm_ratio_idx = stereo_tdm_ener_analysis( #ifdef OMASA_TUNING_TD_STEREO - , - st_ivas->hOMasa != NULL + ivas_format, #endif - ); + hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); /* Compute the downmix signal based on the ratio index */ stereo_tdm_downmix( hCPE->hStereoTD, sts[0]->input, sts[1]->input, input_frame, tdm_ratio_idx, ( ( hCPE->hStereoTD->tdm_LRTD_flag == 0 ) ? tdm_SM_or_LRTD_Pri : 0 ), tdm_ratio_idx_SM ); @@ -606,12 +605,11 @@ ivas_error ivas_cpe_enc( { tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); - tdm_configure_enc( hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata + tdm_configure_enc( #ifdef OMASA_TUNING_TD_STEREO - , - st_ivas->hOMasa != NULL + ivas_format, #endif - ); + hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); if ( hEncoderConfig->Opt_DTX_ON ) { diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 5ef8001b7a..ee07ae2f52 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -111,14 +111,13 @@ static float Comp_diff_lt_corr( CPE_ENC_HANDLE hCPE, const int16_t IsSideMono, c *-------------------------------------------------------------------*/ int16_t stereo_tdm_ener_analysis( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_ENC_HANDLE hCPE, /* i : CPE structure */ const int16_t input_frame, /* i : Number of samples */ int16_t *tdm_SM_or_LRTD_Pri, /* o : channel combination scheme flag in TD stereo OR LRTD primary channel */ int16_t *tdm_ratio_idx_SM /* o : TDM ratio index for SM mode */ -#ifdef OMASA_TUNING_TD_STEREO - , - const int16_t isOmasa /* i : flag that indicates OMASA format */ -#endif ) { float rms_R, rms_L; @@ -200,7 +199,7 @@ int16_t stereo_tdm_ener_analysis( *----------------------------------------------------------------*/ #ifdef OMASA_TUNING_TD_STEREO - if ( isOmasa ) + if ( ivas_format == MASA_ISM_FORMAT ) { if ( ( hCPE->hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) @@ -209,6 +208,7 @@ int16_t stereo_tdm_ener_analysis( } } #endif + rms_thd = RMS_MIN; if ( hCPE->hStereoClassif->lrtd_mode == 1 ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 7c0649c5ab..d8c8086562 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -302,6 +302,9 @@ ivas_error stereo_set_tdm( *-------------------------------------------------------------------*/ void tdm_configure_enc( +#ifdef OMASA_TUNING_TD_STEREO + const int16_t ivas_format, /* i : IVAS format */ +#endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ @@ -309,10 +312,6 @@ void tdm_configure_enc( const int16_t tdm_ratio_idx_SM, /* i : ratio index in SM mode */ const int16_t attack_flag, /* i : Primary channel attack flag */ const int16_t nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_TUNING_TD_STEREO - , - const int16_t IsOmasa /* i : flag that indicates OMASA format */ -#endif ) { int16_t tdm_ratio_bit_alloc_idx, mod_ct; @@ -485,15 +484,14 @@ void tdm_configure_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, - hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), - &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx + tdm_bit_alloc( #ifdef OMASA_TUNING_TD_STEREO - , - IsOmasa + ivas_format, #endif - ); + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #endif -- GitLab From b852f843b388327e38f5f06a06618fe8f29adc35 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 25 Apr 2023 21:07:31 +0300 Subject: [PATCH 079/173] Changes sync between audio and metadata in OMASA to follow the paradigm in MASA. --- lib_com/delay_comp.c | 8 ++ lib_com/ivas_prot.h | 4 + lib_com/options.h | 3 +- lib_dec/ivas_dec.c | 49 +++++++ lib_dec/ivas_dirac_dec.c | 4 + lib_dec/ivas_dirac_output_synthesis_dec.c | 32 +++++ lib_dec/ivas_ism_renderer.c | 127 +++++++++++++------ lib_dec/ivas_masa_dec.c | 86 +++++++++++++ lib_dec/ivas_stat_dec.h | 11 ++ lib_enc/ivas_init_enc.c | 4 + lib_enc/ivas_omasa_enc.c | 28 ++++ lib_enc/ivas_stat_enc.h | 2 + lib_rend/ivas_dirac_dec_binaural_functions.c | 46 +++++++ 13 files changed, 362 insertions(+), 42 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index b96798815e..909a335516 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -70,7 +70,11 @@ int32_t get_delay( delay = IVAS_ENC_DELAY_NS; #ifdef FIX_350_MASA_DELAY_COMP +#ifdef FIX_OMASA_DELAY_COMP + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { delay = 0; /* All delay is compensated in the decoder with MASA */ } @@ -108,7 +112,11 @@ int32_t get_delay( #ifdef FIX_350_MASA_DELAY_COMP +#ifdef FIX_OMASA_DELAY_COMP + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else if ( ivas_format == MASA_FORMAT ) +#endif { delay += IVAS_ENC_DELAY_NS; /* Compensate also the encoder delay in the decoder with MASA */ } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 1bc5b19ea4..f20fd0ab88 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5191,8 +5191,12 @@ ivas_error ivas_omasa_enc_open( ); void ivas_omasa_enc_close( +#ifdef FIX_OMASA_DELAY_COMP + OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ +#else OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ const int16_t nchan_ism /* i : number of objects */ +#endif ); #ifdef OMASA_BRATE_SW diff --git a/lib_com/options.h b/lib_com/options.h index 8bd854e1b4..de3c8de9a7 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -144,7 +144,7 @@ #define FIX_103_RA_PARAMS_PARAM_BIN_REND /* Issue 103: Digest room acoustics parameters for Parametric Binaural Renderer*/ /*#define SBA_HPF_TUNING_DEC*/ -/*#define FIX_350_MASA_DELAY_COMP*/ /* Nokia: Issue 350: MASA audio/meta delay compensation */ +#define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ #define FIX_MDCT_BASED_BWD /* FhG: fixes for BWD for issues with reaction to transients for MDCT-stereo and MCT */ #define DISCRETE_ISM_DTX_CNG /* FhG/VA: contribution 15 - DTX/CNG for (discrete) ISM */ #define NCHAN_ISM_PARAMETER /* VA: make 'nchan_ism' parameter part of st_ivas/hEncoderConfig */ @@ -177,6 +177,7 @@ #define OMASA_BRATE_SW /* VA: support of bitrate switching in OMASA format */ #define FIX_TD5_IN_OMASA // do not transmit extended MD in OMASA #define OMASA_TUNING_TD_STEREO /* VA: tuning of TD stereo in OMASA format */ +#define FIX_OMASA_DELAY_COMP /* Nokia: OMASA audio/meta delay compensation */ #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 4b885ea217..c069a5847e 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -479,6 +479,10 @@ ivas_error ivas_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifdef FIX_OMASA_DELAY_COMP + int16_t dirac_bs_md_write_idx = 0; +#endif + st = st_ivas->hCPE[0]->hCoreCoder[0]; nb_bits_metadata[0] = 0; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -498,6 +502,10 @@ ivas_error ivas_dec( { st_ivas->hDirAC->numIsmDirections = 0; } + +#ifdef FIX_OMASA_DELAY_COMP + dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ +#endif } /* MASA metadata decoding */ @@ -548,6 +556,13 @@ ivas_error ivas_dec( if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) #endif { +#ifdef FIX_OMASA_DELAY_COMP + int16_t azimuth_ism; + int16_t elevation_ism; + int16_t block; + int16_t meta_write_index; +#endif + /* decode ISM metadata */ #ifdef NCHAN_ISM_PARAMETER if ( ( error = ivas_ism_metadata_dec( ism_total_brate, @@ -570,14 +585,38 @@ ivas_error ivas_dec( { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { +#ifdef FIX_OMASA_DELAY_COMP + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; + } +#else st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); +#endif } } else /* ISM_MASA_MODE_MASA_ONE_OBJ */ { +#ifdef FIX_OMASA_DELAY_COMP + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; + } +#else st_ivas->hMasaIsmData->azimuth_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); st_ivas->hMasaIsmData->elevation_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); +#endif } #else for ( n = 0; n < st_ivas->nchan_ism; n++ ) @@ -687,6 +726,10 @@ ivas_error ivas_dec( #endif { float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; +#ifdef FIX_OMASA_DELAY_COMP + int16_t dirac_read_idx; +#endif + #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) #else @@ -703,8 +746,14 @@ ivas_error ivas_dec( } } +#ifdef FIX_OMASA_DELAY_COMP + dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; +#endif ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hDirAC->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ +#endif ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); } else diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index e471738ca3..4f19654485 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -845,7 +845,11 @@ ivas_error ivas_dirac_dec_config( { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; } +#ifdef FIX_OMASA_DELAY_COMP + else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) +#else else if ( st_ivas->ivas_format == MASA_FORMAT ) +#endif { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; hDirAC->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 40883784bd..e137962811 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -1626,12 +1626,20 @@ void ivas_dirac_dec_compute_directional_responses( } else { +#ifdef FIX_OMASA_DELAY_COMP + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); +#else ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); +#endif } for ( l = 0; l < num_channels_dir; l++ ) { +#ifdef FIX_OMASA_DELAY_COMP + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; +#else direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; +#endif } } @@ -1640,10 +1648,18 @@ void ivas_dirac_dec_compute_directional_responses( { masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; } +#ifdef FIX_OMASA_DELAY_COMP + ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; +#else ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; +#endif for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) { +#ifdef FIX_OMASA_DELAY_COMP + ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; +#else ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; +#endif } totalDirect = masaDirect + ismDirect; @@ -1747,7 +1763,11 @@ void ivas_dirac_dec_compute_directional_responses( else { #ifdef OMASA_UPDATES +#ifdef FIX_OMASA_DELAY_COMP + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], 1 ); +#else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], 1 ); +#endif #else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir] ); #endif @@ -1755,7 +1775,11 @@ void ivas_dirac_dec_compute_directional_responses( for ( l = 0; l < num_channels_dir; l++ ) { +#ifdef FIX_OMASA_DELAY_COMP + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; +#else direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; +#endif } } normalizePanningGains( direct_response_ism, num_channels_dir ); @@ -1765,10 +1789,18 @@ void ivas_dirac_dec_compute_directional_responses( { masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; } +#ifdef FIX_OMASA_DELAY_COMP + ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; +#else ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; +#endif for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) { +#ifdef FIX_OMASA_DELAY_COMP + ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; +#else ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; +#endif } totalDirect = masaDirect + ismDirect; diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 00d93d15b6..54856c700d 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -278,7 +278,11 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); } +#ifdef FIX_OMASA_DELAY_COMP + interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); +#else interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / 50 ); +#endif for ( i = 0; i < interpolator_length; i++ ) { st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length ); @@ -341,11 +345,20 @@ void ivas_masa_ism_separate_object_render( int16_t azimuth, elevation; int16_t num_objects; uint8_t single_separated; +#ifdef FIX_OMASA_DELAY_COMP + int16_t block; + int16_t subframe_len; + int16_t idx_offset; + int16_t dirac_read_idx; +#endif hVBAPdata = st_ivas->hVBAPdata; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; hRendererData = st_ivas->hIsmRendererData; lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; +#ifdef FIX_OMASA_DELAY_COMP + subframe_len = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; +#endif #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) @@ -366,67 +379,99 @@ void ivas_masa_ism_separate_object_render( { delay_signal( input_f[obj], output_frame, st_ivas->hMasaIsmData->delayBuffer[obj], st_ivas->hMasaIsmData->delayBuffer_size ); /* Delay the signal to match CLDFB delay */ - if ( single_separated ) - { - azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; - elevation = st_ivas->hMasaIsmData->elevation_separated_ism; - } - else +#ifdef FIX_OMASA_DELAY_COMP + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; - elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; - } + idx_offset = block * subframe_len; + dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; +#endif - if ( st_ivas->hOutSetup.is_planar_setup ) - { - /* If no elevation support in output format, then rendering should be done with zero elevation */ - elevation = 0; - } + if ( single_separated ) + { +#ifdef FIX_OMASA_DELAY_COMP + azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; + elevation = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; +#else + azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; + elevation = st_ivas->hMasaIsmData->elevation_separated_ism; +#endif + } + else + { +#ifdef FIX_OMASA_DELAY_COMP + azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj][dirac_read_idx]; + elevation = st_ivas->hMasaIsmData->elevation_ism[obj][dirac_read_idx]; +#else + azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; + elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; +#endif + } + + if ( st_ivas->hOutSetup.is_planar_setup ) + { + /* If no elevation support in output format, then rendering should be done with zero elevation */ + elevation = 0; + } #ifndef OMASA_UPDATES - else if ( output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_4 ) - { - /* For no negative elevations, it's better to map them to zero */ - elevation = elevation < 0 ? 0 : elevation; - } + else if ( output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_4 ) + { + /* For no negative elevations, it's better to map them to zero */ + elevation = elevation < 0 ? 0 : elevation; + } #endif - if ( hVBAPdata != NULL ) - { + if ( hVBAPdata != NULL ) + { #ifdef OMASA_UPDATES - vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); #else - vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); #endif - } - else - { - ivas_dirac_dec_get_response( azimuth, elevation, gains, st_ivas->hDirAC->hOutSetup.ambisonics_order ); - } - - for ( j = 0; j < nchan_out_woLFE; j++ ) - { - if ( st_ivas->hDirAC->hOutSetup.num_lfe > 0 ) - { - j2 = j + ( j >= lfe_index ); } else { - j2 = j; + ivas_dirac_dec_get_response( azimuth, elevation, gains, st_ivas->hDirAC->hOutSetup.ambisonics_order ); } - if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) + for ( j = 0; j < nchan_out_woLFE; j++ ) { - for ( k = 0; k < output_frame; k++ ) + if ( st_ivas->hDirAC->hOutSetup.num_lfe > 0 ) { - g1 = hRendererData->interpolator[k]; - g2 = 1.0f - g1; - output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; + j2 = j + ( j >= lfe_index ); } + else + { + j2 = j; + } + + if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) + { +#ifdef FIX_OMASA_DELAY_COMP + for ( k = 0; k < subframe_len; k++ ) +#else + for ( k = 0; k < output_frame; k++ ) +#endif + { + g1 = hRendererData->interpolator[k]; + g2 = 1.0f - g1; +#ifdef FIX_OMASA_DELAY_COMP + output_f[j2][k + idx_offset] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k + idx_offset]; +#else + output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; +#endif + } + } + hRendererData->prev_gains[obj][j] = gains[j]; } - hRendererData->prev_gains[obj][j] = gains[j]; +#ifdef FIX_OMASA_DELAY_COMP } +#endif } +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % st_ivas->hDirAC->dirac_md_buffer_length; +#endif + return; } #endif diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 959300ca74..c91b31b288 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -80,7 +80,11 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS +#ifdef FIX_OMASA_DELAY_COMP +static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp, const int16_t dirac_bs_md_write_idx, const int16_t dirac_md_buffer_length ); +#else static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp ); +#endif static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); @@ -113,6 +117,9 @@ ivas_error ivas_masa_decode( #ifdef MASA_AND_OBJECTS int16_t obj; int16_t i, ch, ism_imp; +#ifdef FIX_OMASA_DELAY_COMP + int16_t dirac_bs_md_write_idx; +#endif ism_imp = 0; #endif @@ -329,7 +336,11 @@ ivas_error ivas_masa_decode( #endif { *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); +#else st_ivas->hMasaIsmData->idx_separated_ism, ism_imp ); +#endif } #ifdef OMASA_UPDATES @@ -342,8 +353,20 @@ ivas_error ivas_masa_decode( { if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) { +#ifdef FIX_OMASA_DELAY_COMP + int16_t sf; + int16_t meta_write_index; + + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + meta_write_index = ( st_ivas->hDirAC->dirac_bs_md_write_idx + sf ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; + st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; + } +#else st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->hMasaIsmData->azimuth_ism[obj]; st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->hMasaIsmData->elevation_ism[obj]; +#endif } } } @@ -450,6 +473,9 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { +#ifdef FIX_OMASA_DELAY_COMP + dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ +#endif ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, SBA_MODE_NONE, 0 ); } @@ -468,22 +494,39 @@ ivas_error ivas_masa_decode( { int16_t b; int16_t block; +#ifdef FIX_OMASA_DELAY_COMP + int16_t meta_write_index; +#endif for ( i = 0; i < st_ivas->hDirAC->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { +#ifdef FIX_OMASA_DELAY_COMP + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; +#endif for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][meta_write_index][b]; +#else st_ivas->hDirAC->diffuseness_vector[block][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b]; +#endif } } } for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { +#ifdef FIX_OMASA_DELAY_COMP + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; +#endif for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] ); +#else st_ivas->hDirAC->diffuseness_vector[block][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[block][b] ); +#endif } } } @@ -2298,7 +2341,13 @@ static int16_t ivas_decode_masaism_metadata( uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, +#ifdef FIX_OMASA_DELAY_COMP + const int16_t ism_imp, + const int16_t dirac_bs_md_write_idx, + const int16_t dirac_md_buffer_length ) +#else const int16_t ism_imp ) +#endif { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; @@ -2310,6 +2359,9 @@ static int16_t ivas_decode_masaism_metadata( int16_t nb_bits_read; #ifdef OMASA_UPDATES float delta_phi; +#ifdef FIX_OMASA_DELAY_COMP + int16_t meta_write_index; +#endif #endif nb_bits_read = *next_bit_pos; nbands = hQMetaData->q_direction->cfg.nbands; @@ -2395,8 +2447,17 @@ static int16_t ivas_decode_masaism_metadata( #endif +#ifdef FIX_OMASA_DELAY_COMP + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + sf ) % dirac_md_buffer_length; + hMasaIsmData->azimuth_ism[obj][meta_write_index] = (int16_t) rint( azimuth ); + hMasaIsmData->elevation_ism[obj][meta_write_index] = (int16_t) rint( elevation ); + } +#else hMasaIsmData->azimuth_ism[obj] = (int16_t) rint( azimuth ); hMasaIsmData->elevation_ism[obj] = (int16_t) rint( elevation ); +#endif } /* Modify ISM metadata based on the MASA-to-total energy ratios */ @@ -2427,10 +2488,17 @@ static int16_t ivas_decode_masaism_metadata( { i = sf; } +#ifdef FIX_OMASA_DELAY_COMP + meta_write_index = ( dirac_bs_md_write_idx + sf ) % dirac_md_buffer_length; +#endif for ( dir = 0; dir < nchan_ism; dir++ ) { +#ifdef FIX_OMASA_DELAY_COMP + hMasaIsmData->energy_ratio_ism[dir][meta_write_index][b] = energy_ratio_ism[i][band][dir]; +#else hMasaIsmData->energy_ratio_ism[dir][sf][b] = energy_ratio_ism[i][band][dir]; +#endif } } } @@ -2460,8 +2528,17 @@ void ivas_masa_ism_set_edited_objects( { if ( st_ivas->editing_ism_enabled ) { +#ifdef FIX_OMASA_DELAY_COMP + int16_t sf; + for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) + { + hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->azimuth_edited; + hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->elevation_edited; + } +#else hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism] = st_ivas->azimuth_edited; hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism] = st_ivas->elevation_edited; +#endif #ifdef OMASA_UPDATES st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->azimuth = st_ivas->azimuth_edited; st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->elevation = st_ivas->elevation_edited; @@ -2498,8 +2575,17 @@ void ivas_masa_ism_set_edited_objects( { if ( st_ivas->hMasaIsmData->idx_separated_ism == st_ivas->index_of_edited_ism ) { +#ifdef FIX_OMASA_DELAY_COMP + int16_t sf; + for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) + { + st_ivas->hMasaIsmData->azimuth_separated_ism[sf] = st_ivas->azimuth_edited; + st_ivas->hMasaIsmData->elevation_separated_ism[sf] = st_ivas->elevation_edited; + } +#else st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->azimuth_edited; st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->elevation_edited; +#endif } } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index ccaed09898..a412616749 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1162,17 +1162,28 @@ typedef struct ivas_masa_decoder_struct /* Data structure for MASA_ISM rendering */ typedef struct ivas_masa_ism_data_structure { +#ifdef FIX_OMASA_DELAY_COMP + int16_t azimuth_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; + int16_t elevation_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; + float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; +#else int16_t azimuth_ism[MAX_NUM_OBJECTS]; int16_t elevation_ism[MAX_NUM_OBJECTS]; float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +#endif int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; uint8_t ism_is_edited[MAX_NUM_OBJECTS]; int16_t idx_separated_ism; +#ifdef FIX_OMASA_DELAY_COMP + int16_t azimuth_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; + int16_t elevation_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; +#else int16_t azimuth_separated_ism; int16_t elevation_separated_ism; +#endif #ifdef OMASA_UPDATES float q_azimuth_old[MAX_NUM_OBJECTS]; float q_elevation_old[MAX_NUM_OBJECTS]; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 1fd102c07c..c6d1066e66 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1101,7 +1101,11 @@ void ivas_destroy_enc( #ifdef MASA_AND_OBJECTS if ( st_ivas->hOMasa != NULL ) { +#ifdef FIX_OMASA_DELAY_COMP + ivas_omasa_enc_close( st_ivas->hOMasa ); +#else ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); +#endif st_ivas->hOMasa = NULL; } #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 86b5cbe90f..002a4d52c7 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -89,6 +89,7 @@ ivas_error ivas_omasa_enc_open( numAnalysisChannels = st_ivas->hEncoderConfig->nchan_ism; +#ifndef FIX_OMASA_DELAY_COMP /* initialize delay compensation */ hOMasa->num_samples_delay_comp = NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS ); tmp_f = ( (float) hOMasa->num_samples_delay_comp ) / (float) ( NS2SA( st_ivas->hEncoderConfig->input_Fs, DIRAC_SLOT_NS ) ); @@ -111,6 +112,7 @@ ivas_error ivas_omasa_enc_open( hOMasa->delay_buffer[i] = (float *) malloc( NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) * sizeof( float ) ); /* Todo Nokia: Return errors if alloc fails */ set_zero( hOMasa->delay_buffer[i], NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) ); } +#endif /* open/initialize CLDFB */ hOMasa->num_Cldfb_instances = numAnalysisChannels; @@ -174,17 +176,23 @@ ivas_error ivas_omasa_enc_open( *--------------------------------------------------------------------------*/ void ivas_omasa_enc_close( +#ifdef FIX_OMASA_DELAY_COMP + OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ +#else OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ const int16_t nchan_ism /* i : number of objects */ +#endif ) { int16_t i, j; +#ifndef FIX_OMASA_DELAY_COMP for ( i = 0; i < nchan_ism; i++ ) { free( hOMasa->delay_buffer[i] ); hOMasa->delay_buffer[i] = NULL; } +#endif for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { @@ -299,7 +307,11 @@ ivas_error ivas_omasa_enc_config( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hOMasa != NULL ) { +#ifdef FIX_OMASA_DELAY_COMP + ivas_omasa_enc_close( st_ivas->hOMasa ); +#else ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); +#endif st_ivas->hOMasa = NULL; } @@ -957,11 +969,13 @@ static void ivas_omasa_param_est_enc( set_zero( renormalization_factor_diff, hOMasa->nbands ); set_zero( diffuseness_m, hOMasa->nbands ); +#ifndef FIX_OMASA_DELAY_COMP /* Copy current frame to memory for delay compensation */ for ( i = 0; i < nchan_ism; i++ ) { mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); } +#endif /* Compute ISM to FOA matrices */ for ( i = 0; i < nchan_ism; i++ ) @@ -991,6 +1005,9 @@ static void ivas_omasa_param_est_enc( { for ( i = 0; i < nchan_ism; i++ ) { +#ifdef FIX_OMASA_DELAY_COMP + cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); +#else if ( ts < hOMasa->num_slots_delay_comp ) { cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); @@ -999,6 +1016,7 @@ static void ivas_omasa_param_est_enc( { cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); } +#endif } /* Compute energy */ @@ -1116,11 +1134,13 @@ static void ivas_omasa_param_est_enc( energyRatio[band_m_idx] = 1.0f - diffuseness_m[band_m_idx]; } +#ifndef FIX_OMASA_DELAY_COMP /* Update memory */ for ( i = 0; i < nchan_ism; i++ ) { mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); } +#endif return; } @@ -1148,11 +1168,13 @@ static void ivas_omasa_energy_and_ratio_est( l_ts = input_frame / CLDFB_NO_COL_MAX; +#ifndef FIX_OMASA_DELAY_COMP /* Copy current frame to memory for delay compensation */ for ( i = 0; i < nchan_inp; i++ ) { mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); } +#endif /* do processing over all CLDFB time slots */ for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) @@ -1172,6 +1194,9 @@ static void ivas_omasa_energy_and_ratio_est( { for ( i = 0; i < nchan_inp; i++ ) { +#ifdef FIX_OMASA_DELAY_COMP + cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); +#else if ( ts < hOMasa->num_slots_delay_comp ) { cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); @@ -1180,6 +1205,7 @@ static void ivas_omasa_energy_and_ratio_est( { cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); } +#endif } /* Compute energy */ @@ -1221,11 +1247,13 @@ static void ivas_omasa_energy_and_ratio_est( hMasa->data.nchan_ism = nchan_inp; } +#ifndef FIX_OMASA_DELAY_COMP /* Update memory */ for ( i = 0; i < nchan_inp; i++ ) { mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); } +#endif return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 643bd32164..e5ccdc7b19 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -861,11 +861,13 @@ typedef struct ivas_omasa_enc_data_structure uint8_t nCodingBands; uint8_t nSubframes; +#ifndef FIX_OMASA_DELAY_COMP /* delay compensation */ float *delay_buffer[MAX_NUM_OBJECTS]; /* Delay buffer for parameter estimation */ int16_t num_samples_delay_comp; int16_t num_slots_delay_comp; int16_t offset_comp; +#endif /* CLDFB analysis */ int16_t num_Cldfb_instances; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 1e1e591508..38f2d8eed5 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -657,6 +657,9 @@ static void ivas_dirac_dec_binaural_internal( ivas_dirac_dec_binaural_process_output( st_ivas, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, firstSlot, slotEnd ); st_ivas->hDirAC->hDiffuseDist = NULL; +#ifdef FIX_OMASA_DELAY_COMP + st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + nSubframes ) % st_ivas->hDirAC->dirac_md_buffer_length; +#endif return; } @@ -898,10 +901,19 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } else { +#ifdef FIX_OMASA_DELAY_COMP + aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx]; +#else aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex]; eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex]; +#endif } +#ifdef FIX_OMASA_DELAY_COMP + ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; +#else ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; +#endif spreadCoh = 0.0f; } #endif @@ -1118,7 +1130,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric frameMeanDiffusenessEneWeight[bin] += meanEnePerCh; } +#ifndef FIX_OMASA_DELAY_COMP hDirAC->dirac_read_idx = ( hDirAC->dirac_read_idx + 1 ) % hDirAC->dirac_md_buffer_length; +#endif } /* Formulate average diffuseness over frame */ @@ -1204,6 +1218,9 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( uint8_t nchanSeparateChannels; #endif int16_t nBins; +#ifdef FIX_OMASA_DELAY_COMP + int16_t dirac_read_idx; +#endif DIRAC_DEC_BIN_HANDLE h; h = st_ivas->hDiracDecBin; #ifdef MASA_AND_OBJECTS @@ -1235,6 +1252,9 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; #endif nBins = st_ivas->hDirAC->num_freq_bands; /* Actually bins */ +#ifdef FIX_OMASA_DELAY_COMP + dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; +#endif for ( bin = 0; bin < nBins; bin++ ) { @@ -1399,13 +1419,23 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { +#ifdef FIX_OMASA_DELAY_COMP + aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB][dirac_read_idx]; +#else aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB]; eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB]; +#endif } else { +#ifdef FIX_OMASA_DELAY_COMP + aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; + eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; +#else aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism; eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; +#endif instantChange = 1; } } @@ -2393,6 +2423,9 @@ void preProcessStereoTransportsForMovedObjects( DIRAC_DEC_HANDLE hDirAC; MASA_ISM_DATA_HANDLE hMasaIsmData; uint8_t enableCentering; +#ifdef FIX_OMASA_DELAY_COMP + int16_t dirac_read_idx; +#endif hDirAC = st_ivas->hDirAC; hMasaIsmData = st_ivas->hMasaIsmData; @@ -2426,6 +2459,10 @@ void preProcessStereoTransportsForMovedObjects( /* Perform object-movement based processing */ for ( subframe = firstSubframe; subframe < ( firstSubframe + nSubframes ); subframe++ ) { +#ifdef FIX_OMASA_DELAY_COMP + dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; +#endif + for ( bin = 0; bin < nBins; bin++ ) { float ismPreprocMtxNew[2][2]; @@ -2471,12 +2508,21 @@ void preProcessStereoTransportsForMovedObjects( float panEnesIn[2]; float centeringFactor; +#ifdef FIX_OMASA_DELAY_COMP + ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; +#else ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; +#endif ismRatioAcc += ratio; /* Get input and output panning gains */ +#ifdef FIX_OMASA_DELAY_COMP + ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], + hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], +#else ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex], hMasaIsmData->elevation_ism[ismDirIndex], +#endif panGainsIn ); if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) -- GitLab From b9622617087d96e8f23cee040cb03889979e1db7 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 25 Apr 2023 21:09:01 +0300 Subject: [PATCH 080/173] Apply clang format --- lib_dec/ivas_dirac_dec.c | 82 ++++++++++++++++----------------- lib_dec/ivas_ism_metadata_dec.c | 12 ++--- lib_dec/ivas_ism_renderer.c | 20 ++++---- lib_enc/ivas_cpe_enc.c | 4 +- lib_enc/ivas_enc.c | 4 +- lib_enc/ivas_stereo_td_enc.c | 4 +- 6 files changed, 63 insertions(+), 63 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 4f19654485..878657ec8a 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -321,7 +321,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } ivas_masa_init_stereotype_detection( hDirAC->masa_stereo_type_detect ); } @@ -401,7 +401,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } if ( hDirAC->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) @@ -410,7 +410,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_s( hDirAC->proto_index_dir, 0, hDirAC->num_outputs_dir ); @@ -420,7 +420,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff ); @@ -543,7 +543,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } /* reallocate static memory */ else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->num_outputs_dir != num_outputs_dir_old ) @@ -553,7 +553,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } if ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) @@ -574,7 +574,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder && ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) { @@ -583,7 +583,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_f( hDirAC->hoa_encoder, 0.0f, nchan_out_woLFE * hDirAC->num_outputs_diff ); compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirAC->hoa_encoder, hDirAC->num_outputs_diff, hDirAC->hOutSetup.ambisonics_order ); @@ -673,17 +673,17 @@ ivas_error ivas_dirac_dec_config( if ( ( flag_config == DIRAC_OPEN && hDirAC->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; - } + } } else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { @@ -697,19 +697,19 @@ ivas_error ivas_dirac_dec_config( ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, - nchan_transport > 2 ? 4 : nchan_transport, + &( hDirAC->h_freq_domain_decorr_ap_state ), + hDirAC->num_freq_bands, + hDirAC->num_outputs_diff, + hDirAC->num_protos_diff, + hDirAC->synthesisConf, + hDirAC->frequency_axis, + nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; + } } } - } /* output synthesis */ if ( flag_config == DIRAC_OPEN ) @@ -755,7 +755,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } else if ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->num_protos_diff != num_protos_diff_old ) ) { @@ -764,9 +764,9 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } } - } if ( flag_config == DIRAC_OPEN ) @@ -793,7 +793,7 @@ ivas_error ivas_dirac_dec_config( if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + } } set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } @@ -1333,9 +1333,9 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } - } hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; hDirAC->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; @@ -1392,17 +1392,17 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } } else { if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } - } hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; @@ -1414,7 +1414,7 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * num_freq_bands ) ) == NULL ) { @@ -1439,10 +1439,10 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } } - } else { if ( num_protos_dir > 2 ) @@ -1450,7 +1450,7 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + } } if ( hDirAC->proto_signal_decorr_on ) @@ -1458,9 +1458,9 @@ static ivas_error ivas_dirac_alloc_mem( if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } } } - } return IVAS_ERR_OK; } @@ -1759,10 +1759,10 @@ void ivas_qmetadata_to_dirac( { meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { hDirAC->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; hDirAC->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hDirAC->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; @@ -1831,10 +1831,10 @@ void ivas_qmetadata_to_dirac( { meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { hDirAC->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; hDirAC->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; hDirAC->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; @@ -1887,7 +1887,7 @@ void ivas_qmetadata_to_dirac( set_s( hDirAC->elevation2[meta_write_index], 0, hDirAC->num_freq_bands ); set_zero( hDirAC->energy_ratio2[meta_write_index], hDirAC->num_freq_bands ); set_zero( hDirAC->spreadCoherence2[meta_write_index], hDirAC->num_freq_bands ); - } + } } #endif } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 1cc7028c55..0565447847 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -396,8 +396,8 @@ ivas_error ivas_ism_metadata_dec( if ( ism_metadata_flag_global ) { /*----------------------------------------------------------------* - * Metadata decoding and dequantization, loop over all objects - *----------------------------------------------------------------*/ + * Metadata decoding and dequantization, loop over all objects + *----------------------------------------------------------------*/ int16_t total_bits_metadata = 0, bits_metadata_ism = 0; int16_t nb_bits_objcod_read; @@ -732,8 +732,8 @@ ivas_error ivas_ism_metadata_dec( } /*----------------------------------------------------------------* - * Set bitsream pointers - *----------------------------------------------------------------*/ + * Set bitsream pointers + *----------------------------------------------------------------*/ /* set the bitstream pointer to its original position */ st0->bit_stream = bstr_orig; @@ -747,8 +747,8 @@ ivas_error ivas_ism_metadata_dec( #ifdef DISCRETE_ISM_DTX_CNG /*----------------------------------------------------------------* - * Updates - *----------------------------------------------------------------*/ + * Updates + *----------------------------------------------------------------*/ set_s( md_diff_flag, 1, nchan_ism ); diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 54856c700d..0b99968a5a 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -256,8 +256,8 @@ void ivas_ism_get_stereo_gains( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------------* -* ivas_masa_ism_separate_object_renderer_open() -* + * ivas_masa_ism_separate_object_renderer_open() + * * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ @@ -361,7 +361,7 @@ void ivas_masa_ism_separate_object_render( #endif #ifdef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) #else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) #endif @@ -392,8 +392,8 @@ void ivas_masa_ism_separate_object_render( azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; elevation = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; #else - azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; - elevation = st_ivas->hMasaIsmData->elevation_separated_ism; + azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; + elevation = st_ivas->hMasaIsmData->elevation_separated_ism; #endif } else @@ -402,8 +402,8 @@ void ivas_masa_ism_separate_object_render( azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj][dirac_read_idx]; elevation = st_ivas->hMasaIsmData->elevation_ism[obj][dirac_read_idx]; #else - azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; - elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; + azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; + elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; #endif } @@ -425,7 +425,7 @@ void ivas_masa_ism_separate_object_render( #ifdef OMASA_UPDATES vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); #else - vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); #endif } else @@ -449,7 +449,7 @@ void ivas_masa_ism_separate_object_render( #ifdef FIX_OMASA_DELAY_COMP for ( k = 0; k < subframe_len; k++ ) #else - for ( k = 0; k < output_frame; k++ ) + for ( k = 0; k < output_frame; k++ ) #endif { g1 = hRendererData->interpolator[k]; @@ -457,7 +457,7 @@ void ivas_masa_ism_separate_object_render( #ifdef FIX_OMASA_DELAY_COMP output_f[j2][k + idx_offset] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k + idx_offset]; #else - output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; + output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; #endif } } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 490cd41d1e..bfa7d86756 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -820,7 +820,7 @@ ivas_error ivas_cpe_enc( dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_NCShift" ); dbgwrite( &n, 2, 1, input_frame, "res/TCA_idx_ica_gD" ); n = -1; - //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + // dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } else if ( hCPE->element_mode == IVAS_CPE_TD ) { @@ -837,7 +837,7 @@ ivas_error ivas_cpe_enc( else if ( hCPE->element_mode == IVAS_CPE_MDCT ) { n = -2; - //dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); + // dbgwrite( &n, 2, 1, input_frame, "res/tdm_ratio_idx.enc" ); } { diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 5d329701cb..920193c999 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -249,7 +249,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ) ) != IVAS_ERR_OK ) { @@ -459,7 +459,7 @@ ivas_error ivas_enc( if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 82e3f4bdfd..7c0649c5ab 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -283,8 +283,8 @@ ivas_error stereo_set_tdm( dbgwrite( &tmp, 2, 1, 320, "res/inst_ratio_L" ); dbgwrite( &ftmp, 4, 1, 320, "res/ratio_L" ); dbgwrite( &tmp, 2, 1, 320, "res/tdm_low_rate_mode" ); - //dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); - //dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); + // dbgwrite( &tmp, 2, 1, 320, "res/tdm_lp_reuse_flag" ); + // dbgwrite( &tmp, 2, 1, 320, "res/mod_ct.enx" ); } #endif hCPE->hCoreCoder[0]->tdm_LRTD_flag = 0; -- GitLab From f15d1763c619cf1d4cb875708d581749564477c1 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 25 Apr 2023 21:12:13 +0300 Subject: [PATCH 081/173] Disable DEBUG_MODE_INFO --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index de3c8de9a7..8d94dd3c1e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO #define DEBUG_MODE_ACELP /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ -- GitLab From b2357112fb13c7c59f7068381e480a47529a5cd3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 08:50:46 +0200 Subject: [PATCH 082/173] MSVC compilation warnings --- lib_dec/ivas_masa_dec.c | 2 ++ lib_enc/ivas_omasa_enc.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 75dfcbe9b0..20bd5c18f9 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -119,6 +119,8 @@ ivas_error ivas_masa_decode( int16_t i, ch, ism_imp; #ifdef FIX_OMASA_DELAY_COMP int16_t dirac_bs_md_write_idx; + + dirac_bs_md_write_idx = 0; #endif ism_imp = 0; #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index bcd73cc42a..677558db09 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -72,7 +72,9 @@ ivas_error ivas_omasa_enc_open( ) { int16_t i, j; +#ifndef FIX_OMASA_DELAY_COMP float tmp_f; +#endif OMASA_ENC_HANDLE hOMasa; int16_t numAnalysisChannels; int16_t input_frame; -- GitLab From a3e043792609f56b22d94f91d82a388113dac41d Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 16:24:27 +0200 Subject: [PATCH 083/173] merge OMASA_BRATE_SW into MASA_AND_OBJECTS --- lib_com/ivas_ism_com.c | 4 +- lib_com/ivas_omasa_com.c | 2 - lib_com/ivas_prot.h | 10 +-- lib_com/options.h | 1 - lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_init_dec.c | 67 ++------------------ lib_dec/ivas_ism_metadata_dec.c | 6 +- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 8 +-- lib_dec/ivas_stat_dec.h | 2 +- lib_dec/ivas_stereo_switching_dec.c | 2 +- lib_enc/ivas_corecoder_enc_reconfig.c | 6 +- lib_enc/ivas_cpe_enc.c | 2 +- lib_enc/ivas_enc.c | 21 ------ lib_enc/ivas_init_enc.c | 8 +-- lib_enc/ivas_ism_metadata_enc.c | 30 --------- lib_enc/ivas_omasa_enc.c | 11 ++-- lib_rend/ivas_dirac_dec_binaural_functions.c | 7 +- 18 files changed, 32 insertions(+), 159 deletions(-) diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index adde308208..3db790e924 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -606,7 +606,7 @@ ISM_MODE ivas_ism_mode_select( void ivas_ism_metadata_close( ISM_METADATA_HANDLE hIsmMetaData[] /* i/o : object metadata handles */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS , const int16_t first_idx /* i : index of first handle to deallocate */ #endif @@ -619,7 +619,7 @@ void ivas_ism_metadata_close( return; } -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS for ( n = first_idx; n < MAX_NUM_OBJECTS; n++ ) #else for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 57618c9540..4bf5c3ed83 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -178,7 +178,6 @@ ISM_MODE ivas_omasa_ism_mode_select( } -#ifdef OMASA_BRATE_SW /*--------------------------------------------------------------- * ivas_set_omasa_TC() * @@ -221,7 +220,6 @@ void ivas_set_omasa_TC( return; } -#endif /*--------------------------------------------------------------- diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5a5d7023d8..bcf208f550 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -883,7 +883,7 @@ void ivas_param_ism_enc_close( void ivas_ism_metadata_close( ISM_METADATA_HANDLE hIsmMetaData[] /* i/o : object metadata handles */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS , const int16_t first_idx /* i : index of first handle to deallocate */ #endif @@ -5135,7 +5135,7 @@ void ivas_omasa_enc_close( #endif ); -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -5149,7 +5149,7 @@ void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs, /* i : Input sample rate */ - const ISM_MODE ismMode /* i : ISM mode */ + const ISM_MODE ism_mode /* i : ISM mode */ ); void ivas_omasa_enc( @@ -5211,7 +5211,7 @@ ISM_MODE ivas_omasa_ism_mode_select( const int16_t nchan_ism /* i : number of input ISM's */ ); -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS void ivas_set_omasa_TC( const ISM_MODE ism_mode, /* i : ISM mode */ const int16_t nchan_ism, /* i : number of input ISMs */ @@ -5232,7 +5232,7 @@ ivas_error ivas_masa_ism_data_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS void ivas_masa_ism_data_close( MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 32b61cf5ba..f0218d53e0 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,7 +169,6 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ -#define OMASA_BRATE_SW /* VA: support of bitrate switching in OMASA format */ #define FIX_TD5_IN_OMASA // do not transmit extended MD in OMASA #define OMASA_TUNING_TD_STEREO /* VA: tuning of TD stereo in OMASA format */ #define FIX_OMASA_DELAY_COMP /* Nokia: OMASA audio/meta delay compensation */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 6a6b190dfc..6b368ab391 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -915,7 +915,7 @@ ivas_error ivas_dec( st_ivas->ini_active_frame++; } -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS st_ivas->last_ivas_format = st_ivas->ivas_format; #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 3170f3629f..99e2fb0a15 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -70,11 +70,7 @@ ivas_error ivas_dec_setup( Decoder_State *st; int32_t ivas_total_brate; ivas_error error; -#ifdef MASA_AND_OBJECTS -#ifndef OMASA_BRATE_SW - int32_t cpe_brate; -#endif -#endif + error = IVAS_ERR_OK; num_bits_read = 0; @@ -166,7 +162,7 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( st_ivas->last_ivas_format == MASA_FORMAT ) { #endif @@ -181,7 +177,7 @@ ivas_error ivas_dec_setup( return error; } } -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS } else { @@ -208,22 +204,10 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { -#ifdef OMASA_BRATE_SW if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); - if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 ) - { - st_ivas->hCPE[0]->nchan_out = 1; - } - else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } } } @@ -1095,36 +1079,10 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[0]->hCoreCoder[0] ); -#ifdef OMASA_BRATE_SW if ( ( error = ivas_ism_metadata_dec_create( st_ivas, 1, NULL ) ) != IVAS_ERR_OK ) { return error; } -#else -#ifdef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { - int32_t temp_brate[MAX_SCE]; - - if ( ( error = ivas_ism_metadata_dec_create( st_ivas, 1, temp_brate ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else - { - if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); - } - } -#else - if ( ( st_ivas->hIsmMetaData[0] = (ISM_METADATA_HANDLE) malloc( sizeof( ISM_METADATA_FRAME ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISm MetaData\n" ) ); - } -#endif -#endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -1870,7 +1828,7 @@ void ivas_destroy_dec( } /* ISM metadata handles */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); #else ivas_ism_metadata_close( st_ivas->hIsmMetaData ); @@ -1955,24 +1913,7 @@ void ivas_destroy_dec( #ifdef MASA_AND_OBJECTS /* MASA ISM structure */ -#ifdef OMASA_BRATE_SW ivas_masa_ism_data_close( &st_ivas->hMasaIsmData ); -#else - if ( st_ivas->hMasaIsmData != NULL ) - { - if ( st_ivas->hMasaIsmData->delayBuffer != NULL ) - { - for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) - { - free( st_ivas->hMasaIsmData->delayBuffer[i] ); - } - free( st_ivas->hMasaIsmData->delayBuffer ); - st_ivas->hMasaIsmData->delayBuffer = NULL; - } - free( st_ivas->hMasaIsmData ); - st_ivas->hMasaIsmData = NULL; - } -#endif #endif /* Head track data handle */ diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 0f14195073..610ed868e5 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -669,7 +669,7 @@ ivas_error ivas_ism_metadata_dec_create( ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); } -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( element_brate_tmp != NULL ) { #endif @@ -682,7 +682,7 @@ ivas_error ivas_ism_metadata_dec_create( { return error; } -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS } #endif @@ -701,7 +701,7 @@ ivas_error ivas_ism_metadata_dec_create( 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_angle1 /* o : Azimuth/yaw encoding mode */ + int16_t *flag_abs_angle1 /* o : Azimuth/yaw encoding mode */ ) { int16_t idx_angle1, nbits_diff_angle1, diff, sgn; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 325f02ad3b..4ad5e8f437 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1507,7 +1507,7 @@ ivas_error ivas_masa_dec_reconfigure( #endif ); -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_FORMAT ) { st_ivas->nchan_ism = 0; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index a688e0062f..a02a2bf051 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -38,7 +38,7 @@ #ifdef OMASA_UPDATES #include "ivas_prot_rend.h" #endif -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS #include "ivas_rom_com.h" #endif #ifdef DEBUGGING @@ -95,7 +95,6 @@ ivas_error ivas_masa_ism_data_open( } -#ifdef OMASA_BRATE_SW /*-------------------------------------------------------------------* * ivas_masa_ism_data_close() * @@ -128,11 +127,8 @@ void ivas_masa_ism_data_close( return; } -#endif -#endif -#ifdef OMASA_BRATE_SW /*--------------------------------------------------------------------------* * ivas_omasa_dec_config() * @@ -339,10 +335,8 @@ ivas_error ivas_omasa_dec_config( return IVAS_ERR_OK; } -#endif -#ifdef MASA_AND_OBJECTS /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_dec() * diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index cd14053522..793b438aaf 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1225,7 +1225,7 @@ typedef struct Decoder_Struct DECODER_CONFIG_HANDLE hDecoderConfig; /* Decoder configuration structure */ IVAS_FORMAT ivas_format; /* IVAS format */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS IVAS_FORMAT last_ivas_format; /* last frame IVAS format */ #endif int16_t sid_format; /* IVAS format indicator from SID frame */ diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index ff37582cc4..584b48f906 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -880,7 +880,7 @@ ivas_error stereo_memory_dec( * Bitrate switching in MASA format *---------------------------------------------------------------*/ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && nchan_transport == 2 ) #else if ( ivas_format == MASA_FORMAT && nchan_transport == 2 ) diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index a7cd931a1a..31dce8ad0a 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -251,7 +251,7 @@ ivas_error ivas_corecoder_enc_reconfig( } /* propagate input audio buffers */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) #else if ( n_CoreCoder_existing > sce_id ) @@ -264,7 +264,7 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list + sce_id * MAX_NUM_INDICES; /* only reset indices if it is not the first index list, this already contains the IVAS format bits */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) #else if ( sce_id > 0 ) @@ -299,7 +299,7 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->ind_list = ind_list + ( cpe_id * CPE_CHANNELS + n + st_ivas->nSCE ) * MAX_NUM_INDICES; -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS if ( ( cpe_id * CPE_CHANNELS + n > 0 ) || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) || ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) ) diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 3042bab0c4..c34216b079 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -283,7 +283,7 @@ ivas_error ivas_cpe_enc( if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || #endif sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 514e90fb51..1708e4d701 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -294,14 +294,10 @@ ivas_error ivas_enc( float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; -#ifdef OMASA_BRATE_SW if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -#else - ivas_masa_enc_reconfigure( st_ivas ); -#endif hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; @@ -312,25 +308,8 @@ ivas_error ivas_enc( mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); } - /* nb_bits_metadata[0] = 0; */ set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); - -#ifdef OMASA_BRATE_SW idx_separated_object = 0; -#else - /* Configure MASA encoder based on frame parameters */ - if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } - idx_separated_object = 0; - - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - /* Configure oMASA analysis based on MASA config */ - ivas_omasa_set_config( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hEncoderConfig->input_Fs, st_ivas->ism_mode ); - } -#endif /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 404a0d577c..7e9bdcd0e0 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -610,12 +610,10 @@ ivas_error ivas_init_encoder( return error; } -#ifdef OMASA_BRATE_SW for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_f( st_ivas->hQMetaData->masa_to_total_energy_ratio[i], 0, MASA_FREQUENCY_BANDS ); } -#endif if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { @@ -630,11 +628,7 @@ ivas_error ivas_init_encoder( } } -#ifdef OMASA_UPDATES if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) -#else - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) -#endif { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } @@ -1046,7 +1040,7 @@ void ivas_destroy_enc( } /* ISM metadata handles */ -#ifdef OMASA_BRATE_SW +#ifdef MASA_AND_OBJECTS ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); #else ivas_ism_metadata_close( st_ivas->hIsmMetaData ); diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 5bac1b332e..13d7d64e4f 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -730,37 +730,7 @@ ivas_error ivas_ism_metadata_enc_create( if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { nchan_transport = MAX_PARAM_ISM_WAVE; -#ifdef OMASA_BRATE_SW ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); -#else - switch ( st_ivas->ism_mode ) - { - case ISM_MASA_MODE_PARAM: - st_ivas->nCPE = 1; - st_ivas->nSCE = 0; - break; -#ifdef OMASA_UPDATES - case ISM_MASA_MODE_MASA_ONE_OBJ: - case ISM_MASA_MODE_PARAM_ONE_OBJ: -#else - case ISM_MASA_MODE_ONE_OBJ: -#endif - st_ivas->nCPE = 1; - st_ivas->nSCE = 1; - break; - case ISM_MASA_MODE_DISC: - st_ivas->nCPE = 1; - st_ivas->nSCE = n_ISms; - break; - case ISM_MODE_NONE: - st_ivas->nSCE = 0; - st_ivas->nCPE = 1; - - break; - default: - break; - } -#endif } else { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 677558db09..fdbe8d063d 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -225,7 +225,6 @@ void ivas_omasa_enc_close( } -#ifdef OMASA_BRATE_SW /*--------------------------------------------------------------------------* * ivas_omasa_enc_config() * @@ -345,7 +344,6 @@ ivas_error ivas_omasa_enc_config( return IVAS_ERR_OK; } -#endif /*--------------------------------------------------------------------------* @@ -357,18 +355,17 @@ ivas_error ivas_omasa_enc_config( void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ - const int32_t input_Fs /* i : Input sample rate */ - , - const ISM_MODE ismMode /* i : ISM mode */ + const int32_t input_Fs, /* i : Input sample rate */ + const ISM_MODE ism_mode /* i : ISM mode */ ) { uint8_t i, maxBin; /* Determine the number of bands */ #ifdef OMASA_UPDATES - if ( ismMode == ISM_MODE_NONE || ismMode == ISM_MASA_MODE_MASA_ONE_OBJ ) + if ( ism_mode == ISM_MODE_NONE || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) #else - if ( ismMode == ISM_MODE_NONE ) + if ( ism_mode == ISM_MODE_NONE ) #endif { /* use full resolution for the ISM+MASA merge and reduce later */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 1525c4a508..7ee3add834 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -2246,10 +2246,11 @@ static void hrtfShGetHrtf( /*! r: Configured reqularization factor value to be set. */ static float configure_reqularization_factor( - const IVAS_FORMAT ivas_format, /* i: IVAS codec format in use */ - const int32_t ivas_brate ) /* i: Current IVAS bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS codec format in use */ + const int32_t ivas_brate ) /* i : Current IVAS bitrate */ { float reqularizationFactor; + reqularizationFactor = 1.0f; /* Default value */ if ( ivas_format == MASA_FORMAT ) @@ -2308,7 +2309,7 @@ static float configure_reqularization_factor( } } - /* For SBA and parametric ISM, currently in default value of 1.0f. */ + /* For SBA and parametric ISM, default value of 1.0f. */ return reqularizationFactor; } -- GitLab From f69a7dcb58cdb54876e468de9e16d202563714e7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 16:28:39 +0200 Subject: [PATCH 084/173] merge OMASA_TUNING_TD_STEREO and FIX_TD5_IN_OMASA into MASA_AND_OBJECTS --- lib_com/ivas_prot.h | 8 ++++---- lib_com/ivas_stereo_td_bit_alloc.c | 4 ++-- lib_com/options.h | 2 -- lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_ism_metadata_dec.c | 2 +- lib_dec/ivas_stereo_td_dec.c | 15 +++++---------- lib_enc/ivas_cpe_enc.c | 4 ++-- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_stereo_td_analysis.c | 4 ++-- lib_enc/ivas_stereo_td_enc.c | 18 +++++------------- 10 files changed, 23 insertions(+), 38 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bcf208f550..79a8a6db6d 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1778,7 +1778,7 @@ void stereo_tdm_prep_dwnmx ( ); int16_t stereo_tdm_ener_analysis( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE structure */ @@ -1803,7 +1803,7 @@ void stereo_td_init_dec( ); void tdm_configure_dec( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -1855,7 +1855,7 @@ void tdm_ol_pitch_comparison( ); void tdm_configure_enc( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ @@ -1874,7 +1874,7 @@ ivas_error signaling_enc_secondary( ); void tdm_bit_alloc( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index f593d41a18..97ddb731fe 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -74,7 +74,7 @@ *-------------------------------------------------------------------*/ void tdm_bit_alloc( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ @@ -139,7 +139,7 @@ void tdm_bit_alloc( *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; /* secondary channel bitrate allocation based on the energy scaling ratio */ -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS if ( ( ivas_format != MASA_ISM_FORMAT && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && coder_type > UNVOICED ) ) #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) diff --git a/lib_com/options.h b/lib_com/options.h index f0218d53e0..d251f3b838 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,8 +169,6 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ -#define FIX_TD5_IN_OMASA // do not transmit extended MD in OMASA -#define OMASA_TUNING_TD_STEREO /* VA: tuning of TD stereo in OMASA format */ #define FIX_OMASA_DELAY_COMP /* Nokia: OMASA audio/meta delay compensation */ #endif /* MASA_AND_OBJECTS */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 43b02b0120..e6cbf2bc74 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -414,7 +414,7 @@ ivas_error ivas_cpe_dec( if ( !st_ivas->bfi ) { tdm_configure_dec( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS st_ivas->ivas_format, #endif hCPE, &tdm_ratio_idx, nb_bits_metadata ); diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 610ed868e5..9b12be21ed 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -233,7 +233,7 @@ ivas_error ivas_ism_metadata_dec( } /* read extended metadata presence flag */ -#ifdef FIX_TD5_IN_OMASA +#ifdef MASA_AND_OBJECTS if ( ism_mode == ISM_MODE_DISC && ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) #else if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index d8e817638a..1b90885b0f 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -84,7 +84,7 @@ void stereo_td_init_dec( *-------------------------------------------------------------------*/ void tdm_configure_dec( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -308,15 +308,10 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( -#ifdef OMASA_TUNING_TD_STEREO - ivas_format, -#endif - - hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, - hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), - &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); + tdm_bit_alloc( ivas_format, hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c34216b079..bce8d37984 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -419,7 +419,7 @@ ivas_error ivas_cpe_enc( { /* Determine the energy ratio between the 2 channels */ tdm_ratio_idx = stereo_tdm_ener_analysis( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS ivas_format, #endif hCPE, input_frame, &tdm_SM_or_LRTD_Pri, &tdm_ratio_idx_SM ); @@ -589,7 +589,7 @@ ivas_error ivas_cpe_enc( tdm_ol_pitch_comparison( hCPE, pitch_fr, voicing_fr ); tdm_configure_enc( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS ivas_format, #endif hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 13d7d64e4f..e0451811ac 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -279,7 +279,7 @@ ivas_error ivas_ism_metadata_enc( #endif /* write extended metadata presence flag */ -#ifdef FIX_TD5_IN_OMASA +#ifdef MASA_AND_OBJECTS if ( ism_mode == ISM_MODE_DISC && *ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) #else if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index ee07ae2f52..8f86f25986 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -111,7 +111,7 @@ static float Comp_diff_lt_corr( CPE_ENC_HANDLE hCPE, const int16_t IsSideMono, c *-------------------------------------------------------------------*/ int16_t stereo_tdm_ener_analysis( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE structure */ @@ -198,7 +198,7 @@ int16_t stereo_tdm_ener_analysis( * of L and R needed to create new mono/side signals *----------------------------------------------------------------*/ -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index d8c8086562..0626f3d859 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -302,7 +302,7 @@ ivas_error stereo_set_tdm( *-------------------------------------------------------------------*/ void tdm_configure_enc( -#ifdef OMASA_TUNING_TD_STEREO +#ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ @@ -431,11 +431,7 @@ void tdm_configure_enc( } hStereoTD->tdm_lp_reuse_flag = 1; -#ifdef OMASA_TUNING_TD_STEREO if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 11000 ) -#else - if ( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus < 12000 ) -#endif { sts[1]->coder_type = INACTIVE; } @@ -484,14 +480,10 @@ void tdm_configure_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( -#ifdef OMASA_TUNING_TD_STEREO - ivas_format, -#endif - hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, - hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), - &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, - sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); + tdm_bit_alloc( ivas_format, hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), + &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, + sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #else tdm_bit_alloc( hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); #endif -- GitLab From 3b9c6d094869565165ea61841cae3b5a0967f07a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 16:38:44 +0200 Subject: [PATCH 085/173] merge FIX_OMASA_DELAY_COMP into MASA_AND_OBJECTS --- lib_com/delay_comp.c | 4 +- lib_com/ivas_prot.h | 7 -- lib_com/options.h | 4 +- lib_dec/ivas_dec.c | 24 +---- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_dirac_output_synthesis_dec.c | 50 +--------- lib_dec/ivas_ism_renderer.c | 48 +-------- lib_dec/ivas_masa_dec.c | 63 +----------- lib_dec/ivas_stat_dec.h | 12 +-- lib_enc/ivas_init_enc.c | 6 +- lib_enc/ivas_omasa_enc.c | 100 ------------------- lib_enc/ivas_stat_enc.h | 8 -- lib_rend/ivas_dirac_dec_binaural_functions.c | 46 ++------- 13 files changed, 23 insertions(+), 351 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 8e811e6938..2566ad5fad 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -69,7 +69,7 @@ int32_t get_delay( { delay = IVAS_ENC_DELAY_NS; -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else if ( ivas_format == MASA_FORMAT ) @@ -109,7 +109,7 @@ int32_t get_delay( } -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else if ( ivas_format == MASA_FORMAT ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 79a8a6db6d..338e1b4d24 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5127,15 +5127,9 @@ ivas_error ivas_omasa_enc_open( ); void ivas_omasa_enc_close( -#ifdef FIX_OMASA_DELAY_COMP OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ -#else - OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ - const int16_t nchan_ism /* i : number of objects */ -#endif ); -#ifdef MASA_AND_OBJECTS ivas_error ivas_omasa_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -5143,7 +5137,6 @@ ivas_error ivas_omasa_enc_config( ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#endif void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ diff --git a/lib_com/options.h b/lib_com/options.h index d251f3b838..d86a5355fa 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -169,9 +169,7 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ -#define FIX_OMASA_DELAY_COMP /* Nokia: OMASA audio/meta delay compensation */ - -#endif /* MASA_AND_OBJECTS */ +#endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 6b368ab391..8e5ab73f21 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -404,9 +404,7 @@ ivas_error ivas_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifdef FIX_OMASA_DELAY_COMP int16_t dirac_bs_md_write_idx = 0; -#endif st = st_ivas->hCPE[0]->hCoreCoder[0]; nb_bits_metadata[0] = 0; @@ -428,9 +426,7 @@ ivas_error ivas_dec( st_ivas->hDirAC->numIsmDirections = 0; } -#ifdef FIX_OMASA_DELAY_COMP dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ -#endif } /* MASA metadata decoding */ @@ -481,12 +477,10 @@ ivas_error ivas_dec( if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) #endif { -#ifdef FIX_OMASA_DELAY_COMP int16_t azimuth_ism; int16_t elevation_ism; int16_t block; int16_t meta_write_index; -#endif /* decode ISM metadata */ if ( ( error = ivas_ism_metadata_dec( ism_total_brate, @@ -506,7 +500,6 @@ ivas_error ivas_dec( { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { -#ifdef FIX_OMASA_DELAY_COMP azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); @@ -516,15 +509,10 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; } -#else - st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); -#endif } } else /* ISM_MASA_MODE_MASA_ONE_OBJ */ { -#ifdef FIX_OMASA_DELAY_COMP azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); @@ -534,10 +522,6 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; } -#else - st_ivas->hMasaIsmData->azimuth_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); - st_ivas->hMasaIsmData->elevation_separated_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); -#endif } #else for ( n = 0; n < st_ivas->nchan_ism; n++ ) @@ -647,9 +631,7 @@ ivas_error ivas_dec( #endif { float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; -#ifdef FIX_OMASA_DELAY_COMP int16_t dirac_read_idx; -#endif #ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) @@ -667,14 +649,12 @@ ivas_error ivas_dec( } } -#ifdef FIX_OMASA_DELAY_COMP dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; -#endif + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); -#ifdef FIX_OMASA_DELAY_COMP st_ivas->hDirAC->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ -#endif + ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); } else diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index db8caed4bb..7fb40f6a4f 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -843,7 +843,7 @@ ivas_error ivas_dirac_dec_config( { hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; } -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) #else else if ( st_ivas->ivas_format == MASA_FORMAT ) diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index a7fd962ff9..d5e5710fa2 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -1625,48 +1625,25 @@ void ivas_dirac_dec_compute_directional_responses( } else { -#ifdef FIX_OMASA_DELAY_COMP ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); -#else - ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); -#endif } for ( l = 0; l < num_channels_dir; l++ ) { -#ifdef FIX_OMASA_DELAY_COMP direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; -#else - direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; -#endif } } -#ifdef FIX_OMASA_DELAY_COMP masaDirect = hDirAC->energy_ratio1[hDirAC->dirac_read_idx][k] + EPSILON; -#else - masaDirect = hDirAC->energy_ratio1[subframe_idx][k] + EPSILON; -#endif if ( hDirAC->numParametricDirections == 2 ) { -#ifdef FIX_OMASA_DELAY_COMP masaDirect += hDirAC->energy_ratio2[hDirAC->dirac_read_idx][k]; -#else - masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; -#endif } -#ifdef FIX_OMASA_DELAY_COMP + ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; -#else - ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; -#endif for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) { -#ifdef FIX_OMASA_DELAY_COMP ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; -#else - ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; -#endif } totalDirect = masaDirect + ismDirect; @@ -1770,11 +1747,7 @@ void ivas_dirac_dec_compute_directional_responses( else { #ifdef OMASA_UPDATES -#ifdef FIX_OMASA_DELAY_COMP vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], 1 ); -#else - vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir], 1 ); -#endif #else vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir] ); #endif @@ -1782,40 +1755,21 @@ void ivas_dirac_dec_compute_directional_responses( for ( l = 0; l < num_channels_dir; l++ ) { -#ifdef FIX_OMASA_DELAY_COMP direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; -#else - direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; -#endif } } normalizePanningGains( direct_response_ism, num_channels_dir ); -#ifdef FIX_OMASA_DELAY_COMP masaDirect = hDirAC->energy_ratio1[hDirAC->dirac_read_idx][k] + EPSILON; -#else - masaDirect = hDirAC->energy_ratio1[subframe_idx][k] + EPSILON; -#endif if ( hDirAC->numParametricDirections == 2 ) { -#ifdef FIX_OMASA_DELAY_COMP masaDirect += hDirAC->energy_ratio2[hDirAC->dirac_read_idx][k]; -#else - masaDirect += hDirAC->energy_ratio2[subframe_idx][k]; -#endif } -#ifdef FIX_OMASA_DELAY_COMP + ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; -#else - ismDirect = hMasaIsm->energy_ratio_ism[0][subframe_idx][k]; -#endif for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) { -#ifdef FIX_OMASA_DELAY_COMP ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; -#else - ismDirect += hMasaIsm->energy_ratio_ism[dir][subframe_idx][k]; -#endif } totalDirect = masaDirect + ismDirect; diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 9ffc1b479c..a44a8c4588 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -274,11 +274,8 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); } -#ifdef FIX_OMASA_DELAY_COMP interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); -#else - interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / 50 ); -#endif + for ( i = 0; i < interpolator_length; i++ ) { st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length ); @@ -341,26 +338,18 @@ void ivas_masa_ism_separate_object_render( int16_t azimuth, elevation; int16_t num_objects; uint8_t single_separated; -#ifdef FIX_OMASA_DELAY_COMP int16_t block; int16_t subframe_len; int16_t idx_offset; int16_t dirac_read_idx; -#endif hVBAPdata = st_ivas->hVBAPdata; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; hRendererData = st_ivas->hIsmRendererData; lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; -#ifdef FIX_OMASA_DELAY_COMP subframe_len = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; -#endif -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { single_separated = 1; num_objects = 1; @@ -375,32 +364,20 @@ void ivas_masa_ism_separate_object_render( { delay_signal( input_f[obj], output_frame, st_ivas->hMasaIsmData->delayBuffer[obj], st_ivas->hMasaIsmData->delayBuffer_size ); /* Delay the signal to match CLDFB delay */ -#ifdef FIX_OMASA_DELAY_COMP for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { idx_offset = block * subframe_len; dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; -#endif if ( single_separated ) { -#ifdef FIX_OMASA_DELAY_COMP azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; elevation = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; -#else - azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism; - elevation = st_ivas->hMasaIsmData->elevation_separated_ism; -#endif } else { -#ifdef FIX_OMASA_DELAY_COMP azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj][dirac_read_idx]; elevation = st_ivas->hMasaIsmData->elevation_ism[obj][dirac_read_idx]; -#else - azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj]; - elevation = st_ivas->hMasaIsmData->elevation_ism[obj]; -#endif } if ( st_ivas->hOutSetup.is_planar_setup ) @@ -408,21 +385,10 @@ void ivas_masa_ism_separate_object_render( /* If no elevation support in output format, then rendering should be done with zero elevation */ elevation = 0; } -#ifndef OMASA_UPDATES - else if ( output_config == AUDIO_CONFIG_7_1_4 || output_config == AUDIO_CONFIG_5_1_4 ) - { - /* For no negative elevations, it's better to map them to zero */ - elevation = elevation < 0 ? 0 : elevation; - } -#endif if ( hVBAPdata != NULL ) { -#ifdef OMASA_UPDATES vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); -#else - vbap_determine_gains( hVBAPdata, gains, azimuth, elevation ); -#endif } else { @@ -442,31 +408,19 @@ void ivas_masa_ism_separate_object_render( if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) { -#ifdef FIX_OMASA_DELAY_COMP for ( k = 0; k < subframe_len; k++ ) -#else - for ( k = 0; k < output_frame; k++ ) -#endif { g1 = hRendererData->interpolator[k]; g2 = 1.0f - g1; -#ifdef FIX_OMASA_DELAY_COMP output_f[j2][k + idx_offset] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k + idx_offset]; -#else - output_f[j2][k] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k]; -#endif } } hRendererData->prev_gains[obj][j] = gains[j]; } -#ifdef FIX_OMASA_DELAY_COMP } -#endif } -#ifdef FIX_OMASA_DELAY_COMP st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % st_ivas->hDirAC->dirac_md_buffer_length; -#endif return; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 4ad5e8f437..37941c7328 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -76,11 +76,7 @@ static int16_t decode_lfe_to_total_energy_ratio( MCMASA_LFE_SYNTH_DATA_HANDLE hM static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas ); #ifdef MASA_AND_OBJECTS -#ifdef FIX_OMASA_DELAY_COMP static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp, const int16_t dirac_bs_md_write_idx, const int16_t dirac_md_buffer_length ); -#else -static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp ); -#endif static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); @@ -113,11 +109,9 @@ ivas_error ivas_masa_decode( #ifdef MASA_AND_OBJECTS int16_t obj; int16_t i, ch, ism_imp; -#ifdef FIX_OMASA_DELAY_COMP int16_t dirac_bs_md_write_idx; dirac_bs_md_write_idx = 0; -#endif ism_imp = 0; #endif @@ -334,11 +328,7 @@ ivas_error ivas_masa_decode( #endif { *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, -#ifdef FIX_OMASA_DELAY_COMP st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); -#else - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp ); -#endif } #ifdef OMASA_UPDATES @@ -351,7 +341,6 @@ ivas_error ivas_masa_decode( { if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) { -#ifdef FIX_OMASA_DELAY_COMP int16_t sf; int16_t meta_write_index; @@ -361,10 +350,6 @@ ivas_error ivas_masa_decode( st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; } -#else - st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->hMasaIsmData->azimuth_ism[obj]; - st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->hMasaIsmData->elevation_ism[obj]; -#endif } } } @@ -471,9 +456,8 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { -#ifdef FIX_OMASA_DELAY_COMP dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ -#endif + ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, SBA_MODE_NONE, 0 ); } @@ -492,39 +476,27 @@ ivas_error ivas_masa_decode( { int16_t b; int16_t block; -#ifdef FIX_OMASA_DELAY_COMP int16_t meta_write_index; -#endif for ( i = 0; i < st_ivas->hDirAC->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { -#ifdef FIX_OMASA_DELAY_COMP meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; -#endif + for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { -#ifdef FIX_OMASA_DELAY_COMP st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][meta_write_index][b]; -#else - st_ivas->hDirAC->diffuseness_vector[block][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][block][b]; -#endif } } } for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { -#ifdef FIX_OMASA_DELAY_COMP meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; -#endif + for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { -#ifdef FIX_OMASA_DELAY_COMP st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] ); -#else - st_ivas->hDirAC->diffuseness_vector[block][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[block][b] ); -#endif } } } @@ -2328,13 +2300,9 @@ static int16_t ivas_decode_masaism_metadata( uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, -#ifdef FIX_OMASA_DELAY_COMP const int16_t ism_imp, const int16_t dirac_bs_md_write_idx, const int16_t dirac_md_buffer_length ) -#else - const int16_t ism_imp ) -#endif { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; @@ -2346,10 +2314,9 @@ static int16_t ivas_decode_masaism_metadata( int16_t nb_bits_read; #ifdef OMASA_UPDATES float delta_phi; -#ifdef FIX_OMASA_DELAY_COMP int16_t meta_write_index; #endif -#endif + nb_bits_read = *next_bit_pos; nbands = hQMetaData->q_direction->cfg.nbands; nblocks = hQMetaData->q_direction->cfg.nblocks; /* To do: what if other value than 4? */ @@ -2434,17 +2401,12 @@ static int16_t ivas_decode_masaism_metadata( #endif -#ifdef FIX_OMASA_DELAY_COMP for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { meta_write_index = ( dirac_bs_md_write_idx + sf ) % dirac_md_buffer_length; hMasaIsmData->azimuth_ism[obj][meta_write_index] = (int16_t) rint( azimuth ); hMasaIsmData->elevation_ism[obj][meta_write_index] = (int16_t) rint( elevation ); } -#else - hMasaIsmData->azimuth_ism[obj] = (int16_t) rint( azimuth ); - hMasaIsmData->elevation_ism[obj] = (int16_t) rint( elevation ); -#endif } /* Modify ISM metadata based on the MASA-to-total energy ratios */ @@ -2475,17 +2437,12 @@ static int16_t ivas_decode_masaism_metadata( { i = sf; } -#ifdef FIX_OMASA_DELAY_COMP + meta_write_index = ( dirac_bs_md_write_idx + sf ) % dirac_md_buffer_length; -#endif for ( dir = 0; dir < nchan_ism; dir++ ) { -#ifdef FIX_OMASA_DELAY_COMP hMasaIsmData->energy_ratio_ism[dir][meta_write_index][b] = energy_ratio_ism[i][band][dir]; -#else - hMasaIsmData->energy_ratio_ism[dir][sf][b] = energy_ratio_ism[i][band][dir]; -#endif } } } @@ -2515,17 +2472,12 @@ void ivas_masa_ism_set_edited_objects( { if ( st_ivas->editing_ism_enabled ) { -#ifdef FIX_OMASA_DELAY_COMP int16_t sf; for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) { hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->azimuth_edited; hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->elevation_edited; } -#else - hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism] = st_ivas->azimuth_edited; - hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism] = st_ivas->elevation_edited; -#endif #ifdef OMASA_UPDATES st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->azimuth = st_ivas->azimuth_edited; st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->elevation = st_ivas->elevation_edited; @@ -2562,17 +2514,12 @@ void ivas_masa_ism_set_edited_objects( { if ( st_ivas->hMasaIsmData->idx_separated_ism == st_ivas->index_of_edited_ism ) { -#ifdef FIX_OMASA_DELAY_COMP int16_t sf; for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) { st_ivas->hMasaIsmData->azimuth_separated_ism[sf] = st_ivas->azimuth_edited; st_ivas->hMasaIsmData->elevation_separated_ism[sf] = st_ivas->elevation_edited; } -#else - st_ivas->hMasaIsmData->azimuth_separated_ism = st_ivas->azimuth_edited; - st_ivas->hMasaIsmData->elevation_separated_ism = st_ivas->elevation_edited; -#endif } } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 793b438aaf..a643fe15a0 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1144,28 +1144,18 @@ typedef struct ivas_masa_decoder_struct /* Data structure for MASA_ISM rendering */ typedef struct ivas_masa_ism_data_structure { -#ifdef FIX_OMASA_DELAY_COMP int16_t azimuth_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; -#else - int16_t azimuth_ism[MAX_NUM_OBJECTS]; - int16_t elevation_ism[MAX_NUM_OBJECTS]; - float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; -#endif int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; uint8_t ism_is_edited[MAX_NUM_OBJECTS]; int16_t idx_separated_ism; -#ifdef FIX_OMASA_DELAY_COMP int16_t azimuth_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; -#else - int16_t azimuth_separated_ism; - int16_t elevation_separated_ism; -#endif + #ifdef OMASA_UPDATES float q_azimuth_old[MAX_NUM_OBJECTS]; float q_elevation_old[MAX_NUM_OBJECTS]; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 7e9bdcd0e0..6c8c10226f 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1087,11 +1087,7 @@ void ivas_destroy_enc( #ifdef MASA_AND_OBJECTS if ( st_ivas->hOMasa != NULL ) { -#ifdef FIX_OMASA_DELAY_COMP - ivas_omasa_enc_close( st_ivas->hOMasa ); -#else - ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); -#endif + ivas_omasa_enc_close( st_ivas->hOMasa ); // VE!!!!! st_ivas->hOMasa = NULL; } #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index fdbe8d063d..bd38a64945 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -72,9 +72,6 @@ ivas_error ivas_omasa_enc_open( ) { int16_t i, j; -#ifndef FIX_OMASA_DELAY_COMP - float tmp_f; -#endif OMASA_ENC_HANDLE hOMasa; int16_t numAnalysisChannels; int16_t input_frame; @@ -91,31 +88,6 @@ ivas_error ivas_omasa_enc_open( numAnalysisChannels = st_ivas->hEncoderConfig->nchan_ism; -#ifndef FIX_OMASA_DELAY_COMP - /* initialize delay compensation */ - hOMasa->num_samples_delay_comp = NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS ); - tmp_f = ( (float) hOMasa->num_samples_delay_comp ) / (float) ( NS2SA( st_ivas->hEncoderConfig->input_Fs, DIRAC_SLOT_NS ) ); - hOMasa->num_slots_delay_comp = (int16_t) ( tmp_f ); - - if ( tmp_f > hOMasa->num_slots_delay_comp ) - { - hOMasa->num_slots_delay_comp++; - hOMasa->offset_comp = -hOMasa->num_samples_delay_comp; - hOMasa->num_samples_delay_comp = hOMasa->num_slots_delay_comp * NS2SA( st_ivas->hEncoderConfig->input_Fs, DIRAC_SLOT_NS ); - hOMasa->offset_comp += hOMasa->num_samples_delay_comp; - } - else - { - hOMasa->offset_comp = 0; - } - - for ( i = 0; i < numAnalysisChannels; i++ ) - { - hOMasa->delay_buffer[i] = (float *) malloc( NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) * sizeof( float ) ); /* Todo Nokia: Return errors if alloc fails */ - set_zero( hOMasa->delay_buffer[i], NS2SA( st_ivas->hEncoderConfig->input_Fs, DELAY_DIRAC_ENC_CMP_NS + DIRAC_SLOT_NS ) ); - } -#endif - /* open/initialize CLDFB */ hOMasa->num_Cldfb_instances = numAnalysisChannels; for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) @@ -178,24 +150,11 @@ ivas_error ivas_omasa_enc_open( *--------------------------------------------------------------------------*/ void ivas_omasa_enc_close( -#ifdef FIX_OMASA_DELAY_COMP OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ -#else - OMASA_ENC_HANDLE hOMasa, /* i/o: encoder OMASA handle */ - const int16_t nchan_ism /* i : number of objects */ -#endif ) { int16_t i, j; -#ifndef FIX_OMASA_DELAY_COMP - for ( i = 0; i < nchan_ism; i++ ) - { - free( hOMasa->delay_buffer[i] ); - hOMasa->delay_buffer[i] = NULL; - } -#endif - for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) { deleteCldfb( &( hOMasa->cldfbAnaEnc[i] ) ); @@ -306,11 +265,7 @@ ivas_error ivas_omasa_enc_config( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hOMasa != NULL ) { -#ifdef FIX_OMASA_DELAY_COMP ivas_omasa_enc_close( st_ivas->hOMasa ); -#else - ivas_omasa_enc_close( st_ivas->hOMasa, st_ivas->hEncoderConfig->nchan_ism ); -#endif st_ivas->hOMasa = NULL; } @@ -966,14 +921,6 @@ static void ivas_omasa_param_est_enc( set_zero( renormalization_factor_diff, hOMasa->nbands ); set_zero( diffuseness_m, hOMasa->nbands ); -#ifndef FIX_OMASA_DELAY_COMP - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_ism; i++ ) - { - mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); - } -#endif - /* Compute ISM to FOA matrices */ for ( i = 0; i < nchan_ism; i++ ) { @@ -1002,18 +949,7 @@ static void ivas_omasa_param_est_enc( { for ( i = 0; i < nchan_ism; i++ ) { -#ifdef FIX_OMASA_DELAY_COMP cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); -#else - if ( ts < hOMasa->num_slots_delay_comp ) - { - cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); - } - else - { - cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); - } -#endif } /* Compute energy */ @@ -1131,14 +1067,6 @@ static void ivas_omasa_param_est_enc( energyRatio[band_m_idx] = 1.0f - diffuseness_m[band_m_idx]; } -#ifndef FIX_OMASA_DELAY_COMP - /* Update memory */ - for ( i = 0; i < nchan_ism; i++ ) - { - mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); - } -#endif - return; } @@ -1164,15 +1092,6 @@ static void ivas_omasa_energy_and_ratio_est( num_freq_bands = hOMasa->nbands; l_ts = input_frame / CLDFB_NO_COL_MAX; - -#ifndef FIX_OMASA_DELAY_COMP - /* Copy current frame to memory for delay compensation */ - for ( i = 0; i < nchan_inp; i++ ) - { - mvr2r( &data_f[i][0], &( hOMasa->delay_buffer[i][hOMasa->num_samples_delay_comp - hOMasa->offset_comp] ), hOMasa->offset_comp ); - } -#endif - /* do processing over all CLDFB time slots */ for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) { @@ -1191,18 +1110,7 @@ static void ivas_omasa_energy_and_ratio_est( { for ( i = 0; i < nchan_inp; i++ ) { -#ifdef FIX_OMASA_DELAY_COMP cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); -#else - if ( ts < hOMasa->num_slots_delay_comp ) - { - cldfbAnalysis_ts( &( hOMasa->delay_buffer[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); - } - else - { - cldfbAnalysis_ts( &( data_f[i][hOMasa->offset_comp + l_ts * ( ts - hOMasa->num_slots_delay_comp )] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); - } -#endif } /* Compute energy */ @@ -1244,14 +1152,6 @@ static void ivas_omasa_energy_and_ratio_est( hMasa->data.nchan_ism = nchan_inp; } -#ifndef FIX_OMASA_DELAY_COMP - /* Update memory */ - for ( i = 0; i < nchan_inp; i++ ) - { - mvr2r( &data_f[i][input_frame - hOMasa->num_samples_delay_comp + hOMasa->offset_comp], &( hOMasa->delay_buffer[i][0] ), ( hOMasa->num_samples_delay_comp - hOMasa->offset_comp ) ); - } -#endif - return; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 0c7a3bc375..80dddaf9dd 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -852,14 +852,6 @@ typedef struct ivas_omasa_enc_data_structure uint8_t nCodingBands; uint8_t nSubframes; -#ifndef FIX_OMASA_DELAY_COMP - /* delay compensation */ - float *delay_buffer[MAX_NUM_OBJECTS]; /* Delay buffer for parameter estimation */ - int16_t num_samples_delay_comp; - int16_t num_slots_delay_comp; - int16_t offset_comp; -#endif - /* CLDFB analysis */ int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 7ee3add834..0135239e2e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -641,7 +641,7 @@ static void ivas_dirac_dec_binaural_internal( ivas_dirac_dec_binaural_process_output( st_ivas, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, firstSlot, slotEnd ); st_ivas->hDirAC->hDiffuseDist = NULL; -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + nSubframes ) % st_ivas->hDirAC->dirac_md_buffer_length; #endif @@ -885,19 +885,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } else { -#ifdef FIX_OMASA_DELAY_COMP aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx]; eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx]; -#else - aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex]; - eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex]; -#endif } -#ifdef FIX_OMASA_DELAY_COMP ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; -#else - ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; -#endif spreadCoh = 0.0f; } #endif @@ -1113,10 +1104,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric #endif frameMeanDiffusenessEneWeight[bin] += meanEnePerCh; } - -#ifndef FIX_OMASA_DELAY_COMP - hDirAC->dirac_read_idx = ( hDirAC->dirac_read_idx + 1 ) % hDirAC->dirac_md_buffer_length; -#endif } /* Formulate average diffuseness over frame */ @@ -1202,14 +1189,16 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( uint8_t nchanSeparateChannels; #endif int16_t nBins; -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS int16_t dirac_read_idx; #endif DIRAC_DEC_BIN_HANDLE h; + h = st_ivas->hDiracDecBin; #ifdef MASA_AND_OBJECTS separateCenterChannelRendering = 0; nchanSeparateChannels = 0; + #ifdef OMASA_UPDATES if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) #else @@ -1235,8 +1224,9 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #else separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; #endif + nBins = st_ivas->hDirAC->num_freq_bands; /* Actually bins */ -#ifdef FIX_OMASA_DELAY_COMP +#ifdef MASA_AND_OBJECTS dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; #endif @@ -1395,23 +1385,13 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { -#ifdef FIX_OMASA_DELAY_COMP aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB][dirac_read_idx]; -#else - aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB]; - eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB]; -#endif } else { -#ifdef FIX_OMASA_DELAY_COMP aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; -#else - aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism; - eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism; -#endif instantChange = 1; } } @@ -2334,9 +2314,7 @@ void preProcessStereoTransportsForMovedObjects( DIRAC_DEC_HANDLE hDirAC; MASA_ISM_DATA_HANDLE hMasaIsmData; uint8_t enableCentering; -#ifdef FIX_OMASA_DELAY_COMP int16_t dirac_read_idx; -#endif hDirAC = st_ivas->hDirAC; hMasaIsmData = st_ivas->hMasaIsmData; @@ -2370,9 +2348,7 @@ void preProcessStereoTransportsForMovedObjects( /* Perform object-movement based processing */ for ( subframe = firstSubframe; subframe < ( firstSubframe + nSubframes ); subframe++ ) { -#ifdef FIX_OMASA_DELAY_COMP dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; -#endif for ( bin = 0; bin < nBins; bin++ ) { @@ -2419,21 +2395,13 @@ void preProcessStereoTransportsForMovedObjects( float panEnesIn[2]; float centeringFactor; -#ifdef FIX_OMASA_DELAY_COMP ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; -#else - ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][subframe][bin]; -#endif + ismRatioAcc += ratio; /* Get input and output panning gains */ -#ifdef FIX_OMASA_DELAY_COMP ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], -#else - ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex], - hMasaIsmData->elevation_ism[ismDirIndex], -#endif panGainsIn ); if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) -- GitLab From 81ef67c806106225a5c531fa9b3b647dfd0e7d8f Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 16:47:38 +0200 Subject: [PATCH 086/173] formal improvement --- lib_com/ivas_prot.h | 2 +- lib_dec/ivas_masa_dec.c | 2 ++ lib_enc/ivas_init_enc.c | 7 ++----- lib_enc/ivas_omasa_enc.c | 28 +++++++++++++++++----------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 338e1b4d24..21488cafbf 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5127,7 +5127,7 @@ ivas_error ivas_omasa_enc_open( ); void ivas_omasa_enc_close( - OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ); ivas_error ivas_omasa_enc_config( diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 37941c7328..23865f11ec 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -456,7 +456,9 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { +#ifdef MASA_AND_OBJECTS dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ +#endif ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, SBA_MODE_NONE, 0 ); } diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 6c8c10226f..a9d1c83c43 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -1085,11 +1085,8 @@ void ivas_destroy_enc( ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); #ifdef MASA_AND_OBJECTS - if ( st_ivas->hOMasa != NULL ) - { - ivas_omasa_enc_close( st_ivas->hOMasa ); // VE!!!!! - st_ivas->hOMasa = NULL; - } + /* OMASA handle */ + ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); #endif /* Stereo downmix for EVS encoder handle */ diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index bd38a64945..a9f182705a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -150,35 +150,41 @@ ivas_error ivas_omasa_enc_open( *--------------------------------------------------------------------------*/ void ivas_omasa_enc_close( - OMASA_ENC_HANDLE hOMasa /* i/o: encoder OMASA handle */ + OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ) { int16_t i, j; - for ( i = 0; i < hOMasa->num_Cldfb_instances; i++ ) + if ( hOMasa == NULL || *hOMasa == NULL ) + { + return; + } + + for ( i = 0; i < ( *hOMasa )->num_Cldfb_instances; i++ ) { - deleteCldfb( &( hOMasa->cldfbAnaEnc[i] ) ); + deleteCldfb( &( ( *hOMasa )->cldfbAnaEnc[i] ) ); } for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) { - free( hOMasa->direction_vector_m[i][j] ); - hOMasa->direction_vector_m[i][j] = NULL; + free( ( *hOMasa )->direction_vector_m[i][j] ); + ( *hOMasa )->direction_vector_m[i][j] = NULL; } for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - free( hOMasa->buffer_intensity_real[i][j] ); - hOMasa->buffer_intensity_real[i][j] = NULL; + free( ( *hOMasa )->buffer_intensity_real[i][j] ); + ( *hOMasa )->buffer_intensity_real[i][j] = NULL; } - free( hOMasa->direction_vector_m[i] ); - hOMasa->direction_vector_m[i] = NULL; + free( ( *hOMasa )->direction_vector_m[i] ); + ( *hOMasa )->direction_vector_m[i] = NULL; } - free( hOMasa ); + free( *hOMasa ); + ( *hOMasa ) = NULL; return; } @@ -265,7 +271,7 @@ ivas_error ivas_omasa_enc_config( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hOMasa != NULL ) { - ivas_omasa_enc_close( st_ivas->hOMasa ); + ivas_omasa_enc_close( &( st_ivas->hOMasa ) ); st_ivas->hOMasa = NULL; } -- GitLab From b4e8c3286fcdc50e5bfd232d7de1e4cfe42c92f8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 16:58:02 +0200 Subject: [PATCH 087/173] merge OMASA_UPDATES into MASA_AND_OBJECTS; decoder side --- lib_dec/ivas_cpe_dec.c | 18 +----- lib_dec/ivas_dec.c | 69 +---------------------- lib_dec/ivas_dirac_dec.c | 11 +--- lib_dec/ivas_dirac_output_synthesis_dec.c | 12 +--- lib_dec/ivas_init_dec.c | 15 +---- lib_dec/ivas_ism_metadata_dec.c | 36 ------------ lib_dec/ivas_ism_renderer.c | 4 -- lib_dec/ivas_masa_dec.c | 69 +---------------------- lib_dec/ivas_mono_dmx_renderer.c | 5 +- lib_dec/ivas_omasa_dec.c | 41 +------------- lib_dec/ivas_sce_dec.c | 12 ---- lib_dec/ivas_stat_dec.h | 4 +- lib_dec/ivas_vbap.c | 24 ++++---- 13 files changed, 27 insertions(+), 293 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index e6cbf2bc74..97a046fe9d 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -268,11 +268,7 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif { sts[0]->total_brate += hCPE->brate_surplus; } @@ -301,11 +297,7 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS /* compute bit-rate surplus per channel in combined format coding */ int32_t brate_surplus[CPE_CHANNELS]; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; @@ -339,11 +331,7 @@ ivas_error ivas_cpe_dec( #ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); sts[n]->total_brate += brate_surplus[n]; @@ -681,11 +669,7 @@ ivas_error create_cpe_dec( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { cpe_brate = element_brate; } @@ -1116,7 +1100,7 @@ static void read_stereo_mode_and_bwidth( else { /* read stereo technology info */ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k ) ) #else if ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 8e5ab73f21..199af09c8d 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -413,11 +413,7 @@ ivas_error ivas_dec( /* Set the number of objects for the parametric rendering */ if ( st_ivas->hDirAC != NULL ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) -#endif { st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; } @@ -440,7 +436,7 @@ ivas_error ivas_dec( st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); -#ifdef OMASA_UPDATES + //VE: !!!!! /* set ISM parameters */ int16_t nchan_ism, nchan_transport_ism; nchan_ism = st_ivas->nchan_ism; @@ -455,27 +451,9 @@ ivas_error ivas_dec( nchan_ism = 0; nchan_transport_ism = 1; } -#endif /* decode ISM metadata */ -#ifndef OMASA_UPDATES - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) - { - if ( st_ivas->nSCE == 1 ) - { - ivas_sce_dec( st_ivas, 0, &output[2], output_frame, nb_bits_metadata[1] ); - } - else - { -#ifdef DEBUGGING - assert( ( st_ivas->nSCE <= 1 ) && "nSCE should be 1 if not in ISM_MASA_MODE_DISC." ); -#endif - } - } - else -#else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#endif { int16_t azimuth_ism; int16_t elevation_ism; @@ -483,19 +461,12 @@ ivas_error ivas_dec( int16_t meta_write_index; /* decode ISM metadata */ - if ( ( error = ivas_ism_metadata_dec( ism_total_brate, -#ifdef OMASA_UPDATES - nchan_ism, &nchan_transport_ism, -#else - st_ivas->nchan_ism, &( st_ivas->nSCE ), -#endif - st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_metadata_dec( ism_total_brate, nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK ) { return error; } // VE: move the following updates into ivas_ism_metadata_dec() -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { for ( n = 0; n < st_ivas->nchan_ism; n++ ) @@ -523,31 +494,8 @@ ivas_error ivas_dec( st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; } } -#else - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - st_ivas->hMasaIsmData->azimuth_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - st_ivas->hMasaIsmData->elevation_ism[n] = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - } -#endif - -#ifndef OMASA_UPDATES - for ( n = 0; n < st_ivas->nSCE - 1; n++ ) - { - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = ivas_sce_dec( st_ivas, n, &output[2 * st_ivas->nCPE + n], output_frame, sum_s( &nb_bits_metadata[1], st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } -#ifdef OMASA_UPDATES /* decode ISM channels */ for ( n = 0; n < nchan_transport_ism; n++ ) { @@ -556,7 +504,6 @@ ivas_error ivas_dec( return error; } } -#endif /* decode MASA channels */ if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) @@ -581,7 +528,6 @@ ivas_error ivas_dec( /* Rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; @@ -614,9 +560,6 @@ ivas_error ivas_dec( { ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); } -#else - ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); -#endif } else if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) { @@ -624,20 +567,12 @@ ivas_error ivas_dec( } else if ( st_ivas->hDirAC ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; int16_t dirac_read_idx; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { mvr2r( output[2], data_separated_objects[0], output_frame ); } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 7fb40f6a4f..69e9dcfef4 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2250,18 +2250,9 @@ void ivas_dirac_dec( } } -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) -#endif { - preProcessStereoTransportsForMovedObjects( st_ivas, - Cldfb_RealBuffer_Temp, - Cldfb_ImagBuffer_Temp, - (uint8_t) ( hDirAC->num_freq_bands ), - (uint8_t) subframe_idx, - 1 ); + preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, (uint8_t) ( hDirAC->num_freq_bands ), (uint8_t) subframe_idx, 1 ); } } #endif diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index d5e5710fa2..d245849376 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -1738,19 +1738,11 @@ void ivas_dirac_dec_compute_directional_responses( { if ( hMasaIsm->ism_is_edited[dir] ) { -#ifdef OMASA_UPDATES vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], 1 ); -#else - vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir] ); -#endif } else { -#ifdef OMASA_UPDATES vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], 1 ); -#else - vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir], hMasaIsm->elevation_ism[dir] ); -#endif } for ( l = 0; l < num_channels_dir; l++ ) @@ -2268,7 +2260,7 @@ static void spreadCoherencePanningVbap( return; } -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS vbap_determine_gains( hVBAPdata, direct_response, azimuth, elevation, 0 ); #else vbap_determine_gains( hVBAPdata, direct_response, azimuth, elevation ); @@ -2276,7 +2268,7 @@ static void spreadCoherencePanningVbap( if ( spreadCoh > 0.f ) { -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS vbap_determine_gains( hVBAPdata, direct_response_left, azimuth + 30, elevation, 0 ); vbap_determine_gains( hVBAPdata, direct_response_right, azimuth - 30, elevation, 0 ); #else diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 99e2fb0a15..560618b552 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1062,11 +1062,8 @@ ivas_error ivas_init_decoder( { k++; } -#ifdef OMASA_UPDATES + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { /* one separated object */ st_ivas->nSCE = 1; @@ -1247,7 +1244,7 @@ ivas_error ivas_init_decoder( } else { -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS vbap_determine_gains( st_ivas->hVBAPdata, st_ivas->hLsSetupCustom->separate_ch_gains, 0, 0, 0 ); #else vbap_determine_gains( st_ivas->hVBAPdata, st_ivas->hLsSetupCustom->separate_ch_gains, 0, 0 ); @@ -1414,10 +1411,9 @@ ivas_error ivas_init_decoder( st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; } -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - // VE: introduce a new renderer_type for this case if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { /* Allocate TD renderer for the objects in DISC mode */ @@ -1433,7 +1429,6 @@ ivas_error ivas_init_decoder( } } - // VE: introduce a new renderer_type for this case if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ @@ -1997,11 +1992,7 @@ void ivas_init_dec_get_num_cldfb_instances( { *numCldfbAnalyses += st_ivas->nchan_ism; } -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 9b12be21ed..e512061cfb 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -204,11 +204,7 @@ ivas_error ivas_ism_metadata_dec( /* number of objects was read in ivas_dec_setup() */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode != ISM_MASA_MODE_DISC ) -#endif #endif { /* number of objects was read in ivas_dec_setup() */ @@ -261,11 +257,7 @@ ivas_error ivas_ism_metadata_dec( for ( ch = 0; ch < *nchan_transport; ch++ ) { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* ISM importance flag is already read in ivas_masa_decode() */ ism_imp[ch] = hIsmMeta[ch]->ism_imp; @@ -300,11 +292,7 @@ ivas_error ivas_ism_metadata_dec( if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* VAD flag is already read in ivas_masa_decode() */ localVAD[ch] = hIsmMeta[ch]->ism_vad_flag; @@ -339,11 +327,7 @@ ivas_error ivas_ism_metadata_dec( { hIsmMetaData = hIsmMeta[ch]; #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -405,11 +389,7 @@ ivas_error ivas_ism_metadata_dec( /* save number of metadata bits read */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -497,11 +477,7 @@ ivas_error ivas_ism_metadata_dec( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { ism_metadata_flag_global = 1; } @@ -515,11 +491,7 @@ ivas_error ivas_ism_metadata_dec( { #ifdef MASA_AND_OBJECTS int16_t masa_ism_flag = 0; -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { masa_ism_flag = 1; @@ -550,11 +522,7 @@ ivas_error ivas_ism_metadata_dec( hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; #endif #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -569,11 +537,7 @@ ivas_error ivas_ism_metadata_dec( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode != ISM_MASA_MODE_DISC ) -#endif #endif { hSCE[ch]->element_brate = element_brate[ch]; diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index a44a8c4588..9957522feb 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -283,11 +283,7 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( st_ivas->hMasaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { st_ivas->hMasaIsmData->delayBuffer_nchan = 1; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 23865f11ec..b84d8d1cca 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -121,11 +121,7 @@ ivas_error ivas_masa_decode( low_bitrate_mode = -1; /* This means that LBR mode is not used. */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->hOutSetup.separateChannelEnabled || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->hOutSetup.separateChannelEnabled || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( st_ivas->hOutSetup.separateChannelEnabled ) #endif @@ -177,11 +173,7 @@ ivas_error ivas_masa_decode( st->next_bit_pos -= NO_BITS_MASA_ISM_NO_OBJ; *nb_bits_read += NO_BITS_MASA_ISM_NO_OBJ; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { /* read index of separated object */ /* nchan_ism should be > 1*/ @@ -196,7 +188,6 @@ ivas_error ivas_masa_decode( } /* read ISM importance flag (one per object) */ -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { ism_imp = 0; @@ -208,10 +199,8 @@ ivas_error ivas_masa_decode( } st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; } + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { ism_imp = 0; for ( i = 0; i < ISM_METADATA_FLAG_BITS; i++ ) @@ -222,7 +211,6 @@ ivas_error ivas_masa_decode( } st_ivas->hIsmMetaData[0]->ism_imp = ism_imp; -#ifdef OMASA_UPDATES /* reset */ st_ivas->hIsmMetaData[0]->ism_vad_flag = 1; if ( st_ivas->hIsmMetaData[0]->ism_imp == ISM_NO_META ) @@ -231,7 +219,6 @@ ivas_error ivas_masa_decode( st_ivas->hIsmMetaData[0]->ism_vad_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read ) += ISM_METADATA_VAD_FLAG_BITS; } -#endif } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { @@ -321,21 +308,13 @@ ivas_error ivas_masa_decode( #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) -#endif { *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); } -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { @@ -358,11 +337,7 @@ ivas_error ivas_masa_decode( *nb_bits_read += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &st->next_bit_pos ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) -#endif { /* Modify spatial metadata based on the MASA-to-total energy ratios */ modify_masa_energy_ratios( hQMetaData ); @@ -589,11 +564,7 @@ ivas_error ivas_masa_dec_open( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -738,11 +709,7 @@ static ivas_error ivas_masa_dec_config( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -754,18 +721,14 @@ static ivas_error ivas_masa_dec_config( if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) { ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); } else { -#endif ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); -#ifdef OMASA_UPDATES } -#endif } else { @@ -1461,11 +1424,7 @@ ivas_error ivas_masa_dec_reconfigure( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( n = 0; n < st_ivas->nSCE; n++ ) { @@ -2314,10 +2273,8 @@ static int16_t ivas_decode_masaism_metadata( uint16_t idx_el, idx_az; float azimuth, elevation; int16_t nb_bits_read; -#ifdef OMASA_UPDATES float delta_phi; int16_t meta_write_index; -#endif nb_bits_read = *next_bit_pos; nbands = hQMetaData->q_direction->cfg.nbands; @@ -2347,7 +2304,6 @@ static int16_t ivas_decode_masaism_metadata( for ( obj = 0; obj < nchan_ism; obj++ ) { index = 0; -#ifdef OMASA_UPDATES if ( bits_ism[obj] < 8 ) /* if low resolution, can look to the past */ { /* read if same as previous */ @@ -2394,15 +2350,7 @@ static int16_t ivas_decode_masaism_metadata( hMasaIsmData->q_azimuth_old[obj] = azimuth; hMasaIsmData->q_elevation_old[obj] = elevation; } -#else - for ( i = 0; i < bits_ism[obj]; i++ ) - { - index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; - } - deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); - -#endif for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { meta_write_index = ( dirac_bs_md_write_idx + sf ) % dirac_md_buffer_length; @@ -2464,7 +2412,7 @@ void ivas_masa_ism_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - int16_t dir; + int16_t dir, sf; MASA_ISM_DATA_HANDLE hMasaIsmData; hMasaIsmData = st_ivas->hMasaIsmData; @@ -2474,24 +2422,20 @@ void ivas_masa_ism_set_edited_objects( { if ( st_ivas->editing_ism_enabled ) { - int16_t sf; for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) { hMasaIsmData->azimuth_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->azimuth_edited; hMasaIsmData->elevation_ism[st_ivas->index_of_edited_ism][sf] = st_ivas->elevation_edited; } -#ifdef OMASA_UPDATES + st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->azimuth = st_ivas->azimuth_edited; st_ivas->hIsmMetaData[st_ivas->index_of_edited_ism]->elevation = st_ivas->elevation_edited; -#endif } } -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { /* Directions cannot be edited in this mode */ } -#endif else { for ( dir = 0; dir < MAX_NUM_OBJECTS; dir++ ) @@ -2508,15 +2452,10 @@ void ivas_masa_ism_set_edited_objects( } } -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->editing_ism_enabled ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st_ivas->editing_ism_enabled ) -#endif { if ( st_ivas->hMasaIsmData->idx_separated_ism == st_ivas->index_of_edited_ism ) { - int16_t sf; for ( sf = 0; sf < ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); sf++ ) { st_ivas->hMasaIsmData->azimuth_separated_ism[sf] = st_ivas->azimuth_edited; @@ -2528,6 +2467,4 @@ void ivas_masa_ism_set_edited_objects( return; } - - #endif diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index a0ba899f0d..a6f0abfddb 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -101,11 +101,7 @@ void ivas_mono_downmix_render_passive( { numInputChannels = st_ivas->nchan_transport; } -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { numInputChannels = st_ivas->nchan_transport + 1; } @@ -115,6 +111,7 @@ void ivas_mono_downmix_render_passive( } } #endif + hDownmix = st_ivas->hMonoDmxRenderer; set_zero( proto_signal, output_frame ); diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index a02a2bf051..777d6bfbe5 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -35,12 +35,8 @@ #include "ivas_cnst.h" #include "ivas_prot.h" #include "prot.h" -#ifdef OMASA_UPDATES #include "ivas_prot_rend.h" -#endif -#ifdef MASA_AND_OBJECTS #include "ivas_rom_com.h" -#endif #ifdef DEBUGGING #include "debug.h" #endif @@ -81,13 +77,11 @@ ivas_error ivas_masa_ism_data_open( hMasaIsmData->objectsMoved = 0; hMasaIsmData->delayBuffer = NULL; -#ifdef OMASA_UPDATES for ( ch = 0; ch < st_ivas->nchan_ism; ch++ ) { hMasaIsmData->q_elevation_old[ch] = 0.0f; hMasaIsmData->q_azimuth_old[ch] = 0.0f; } -#endif st_ivas->hMasaIsmData = hMasaIsmData; @@ -218,11 +212,7 @@ ivas_error ivas_omasa_dec_config( /* ISM MD reconfig. */ n_MD = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#endif { n_MD = 1; @@ -257,16 +247,11 @@ ivas_error ivas_omasa_dec_config( st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; /* objects renderer reconfig. */ -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) -#else - if ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) -#endif { ivas_masa_ism_data_close( &( st_ivas->hMasaIsmData ) ); } -#ifdef OMASA_UPDATES if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) @@ -330,7 +315,6 @@ ivas_error ivas_omasa_dec_config( } } } -#endif } return IVAS_ERR_OK; @@ -353,28 +337,13 @@ void ivas_set_surplus_brate_dec( *ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - *ism_total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp -#ifdef FIX_4OBJ_128 - , - 0 -#endif - ); -#endif st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - *ism_total_brate; -#ifdef OMASA_UPDATES /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_PARAM_ONE_OBJ mode */ -#else - /* set 'st->total_brate'; there are no meta-data in ISM_MASA_MODE_ONE_OBJ mode */ -#endif st_ivas->hSCE[0]->hCoreCoder[0]->total_brate = *ism_total_brate; st_ivas->hSCE[0]->hCoreCoder[0]->low_rate_mode = 0; @@ -385,7 +354,6 @@ void ivas_set_surplus_brate_dec( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { -#ifdef OMASA_UPDATES int16_t brate_limit_flag, ism_imp[MAX_NUM_OBJECTS]; for ( n = 0; n < st_ivas->nchan_ism; n++ ) @@ -395,8 +363,6 @@ void ivas_set_surplus_brate_dec( brate_limit_flag = calculate_brate_limit_flag( ism_imp, st_ivas->nchan_ism ); -#endif - ism_total_brate_ref = 0; for ( n = 0; n < st_ivas->nchan_ism; n++ ) { @@ -413,12 +379,7 @@ void ivas_set_surplus_brate_dec( { st_ivas->hSCE[n]->element_brate = element_brate[n]; - *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp -#ifdef OMASA_UPDATES - , - brate_limit_flag -#endif - ); + *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ); } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 9b6ea5ec29..201355fc5b 100755 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -159,19 +159,11 @@ ivas_error ivas_sce_dec( ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { st->bits_frame_nominal = (int16_t) ( ( hSCE->element_brate / FRAMES_PER_SEC ) - ISM_NB_BITS_METADATA_NOMINAL ); } -#ifdef OMASA_UPDATES else if ( ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#else - else if ( ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) || ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif #else if ( st_ivas->mc_mode == MC_MODE_MCMASA && ivas_total_brate >= MCMASA_SEPARATE_BRATE ) #endif @@ -228,11 +220,7 @@ ivas_error ivas_sce_dec( /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) && -#else - if ( ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) && -#endif st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) #else if ( st_ivas->ivas_format == ISM_FORMAT && st->low_rate_mode && !( st->total_brate == SID_2k40 || st->total_brate == FRAME_NO_DATA ) ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a643fe15a0..e474e0fd1f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1026,7 +1026,7 @@ typedef struct vbap_data_structure float *bottom_virtual_speaker_node_division_gains; float *top_virtual_speaker_node_division_gains; float *back_virtual_speaker_node_division_gains; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS float *object_mode_bottom_virtual_speaker_node_division_gains; float *object_mode_top_virtual_speaker_node_division_gains; float *object_mode_back_virtual_speaker_node_division_gains; @@ -1156,10 +1156,8 @@ typedef struct ivas_masa_ism_data_structure int16_t azimuth_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_separated_ism[MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; -#ifdef OMASA_UPDATES float q_azimuth_old[MAX_NUM_OBJECTS]; float q_elevation_old[MAX_NUM_OBJECTS]; -#endif float ismPreprocMatrix[2][2][CLDFB_NO_CHANNELS_MAX]; uint8_t objectsMoved; diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index 37547deaad..ed2ce47942 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -141,7 +141,7 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node( VBAP_HAND static int16_t determine_best_triplet_and_gains( VBAP_SEARCH_STRUCT *search_struct, const float panning_unit_vec[3], const int16_t azi_deg, float gains[3] ); -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS static void determine_virtual_speaker_node_division_gains( const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes, const int16_t use_object_mode ); #else static void determine_virtual_speaker_node_division_gains( const int16_t virtual_speaker_node_index, float *virtual_node_division_gains, int16_t connections[][2], const enum VirtualSpeakerNodeType type, const int16_t max_num_connections, const int16_t num_speaker_nodes ); @@ -161,7 +161,7 @@ ivas_error vbap_init_data( const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ const float *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS , const int16_t support_object_mode /* i : init VBAP also for object panning mode */ #endif @@ -213,7 +213,7 @@ ivas_error vbap_init_data( vbap->bottom_virtual_speaker_node_division_gains = NULL; vbap->top_virtual_speaker_node_division_gains = NULL; vbap->back_virtual_speaker_node_division_gains = NULL; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS vbap->object_mode_bottom_virtual_speaker_node_division_gains = NULL; vbap->object_mode_top_virtual_speaker_node_division_gains = NULL; vbap->object_mode_back_virtual_speaker_node_division_gains = NULL; @@ -240,7 +240,7 @@ ivas_error vbap_init_data( } set_zero( vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->bottom_virtual_speaker_node_division_gains != NULL; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( support_object_mode ) { vbap->object_mode_bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); @@ -260,7 +260,7 @@ ivas_error vbap_init_data( } set_zero( vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->top_virtual_speaker_node_division_gains != NULL; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( support_object_mode ) { vbap->object_mode_top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); @@ -280,7 +280,7 @@ ivas_error vbap_init_data( } set_zero( vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->back_virtual_speaker_node_division_gains != NULL; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( support_object_mode ) { vbap->object_mode_back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); @@ -377,7 +377,7 @@ ivas_error vbap_init_data( /* Determine how the virtual node gains should be distributed to real nodes, if necessary (checked within function). */ if ( is_success ) { -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); @@ -438,7 +438,7 @@ void vbap_free_data( { free( ( *hVBAPdata )->back_virtual_speaker_node_division_gains ); } -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( ( *hVBAPdata )->object_mode_bottom_virtual_speaker_node_division_gains != NULL ) { free( ( *hVBAPdata )->object_mode_bottom_virtual_speaker_node_division_gains ); @@ -479,7 +479,7 @@ void vbap_determine_gains( float *gains, /* o : gain vector for loudspeakers for given direction */ const int16_t azi_deg, /* i : azimuth in degrees for panning direction (positive left)*/ const int16_t ele_deg /* i : elevation in degrees for panning direction (positive up)*/ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS , const int16_t use_object_mode /* i : select between object mode panning and spatial mode panning */ #endif @@ -516,7 +516,7 @@ void vbap_determine_gains( bottom_virtual_speaker_node_index = hVBAPdata->bottom_virtual_speaker_node_index; top_virtual_speaker_node_index = hVBAPdata->top_virtual_speaker_node_index; back_virtual_speaker_node_index = hVBAPdata->back_virtual_speaker_node_index; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( use_object_mode ) { bottom_virtual_speaker_node_division_gains = hVBAPdata->object_mode_bottom_virtual_speaker_node_division_gains; @@ -782,7 +782,7 @@ static void determine_virtual_speaker_node_division_gains( const enum VirtualSpeakerNodeType type, /* i : virtual speaker node typel */ const int16_t max_num_connections, /* i : max number of connections */ const int16_t num_speaker_nodes /* i : max number of speaker nodes */ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS , const int16_t use_object_mode /* i : use VBAP in object panning mode vs. spatial panning mode */ #endif @@ -828,7 +828,7 @@ static void determine_virtual_speaker_node_division_gains( for ( ch = 0; ch < num_speaker_nodes; ch++ ) { virtual_node_division_gains[ch] /= sum_val; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( use_object_mode ) { virtual_node_division_gains[ch] = powf( virtual_node_division_gains[ch], 0.8f ); -- GitLab From 687ce1a008e155efd5e6bee33736b10b603c79f1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 18:46:03 +0200 Subject: [PATCH 088/173] merge OMASA_UPDATES into MASA_AND_OBJECTS; encoder side --- lib_com/bitstream.c | 24 --- lib_com/ivas_cnst.h | 10 +- lib_com/ivas_masa_com.c | 12 -- lib_com/ivas_omasa_com.c | 65 ++------ lib_com/ivas_prot.h | 10 +- lib_com/ivas_stat_com.h | 2 - lib_com/options.h | 1 - lib_dec/ivas_dirac_dec.c | 3 +- lib_dec/lib_dec.c | 4 - lib_enc/ivas_cpe_enc.c | 16 +- lib_enc/ivas_decision_matrix_enc.c | 2 +- lib_enc/ivas_enc.c | 14 +- lib_enc/ivas_ism_enc.c | 44 +---- lib_enc/ivas_ism_metadata_enc.c | 64 +------ lib_enc/ivas_masa_enc.c | 76 +-------- lib_enc/ivas_omasa_enc.c | 165 +------------------ lib_enc/ivas_sce_enc.c | 27 --- lib_enc/ivas_stereo_classifier.c | 3 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 42 +---- lib_rend/ivas_objectRenderer.c | 4 +- 20 files changed, 42 insertions(+), 546 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 9b54224860..d7c063bf1a 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1972,37 +1972,13 @@ ivas_error preview_indices( else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { /* read number of objects from the bitstream */ -#ifdef OMASA_UPDATES st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ st_ivas->nchan_ism = 0; -#else - st_ivas->nchan_transport = 0; -#endif if ( total_brate != SID_2k40 && total_brate != FRAME_NO_DATA ) { -#ifdef OMASA_UPDATES st_ivas->nchan_ism = 2 * bit_stream[total_brate / FRAMES_PER_SEC - 1] + bit_stream[total_brate / FRAMES_PER_SEC - 2] + 1; -#endif st_ivas->ism_mode = ivas_omasa_ism_mode_select( total_brate, st_ivas->nchan_ism ); - -#ifndef OMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - st_ivas->nchan_transport = 0; - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - st_ivas->nchan_transport = 2 * st_ivas->bit_stream[total_brate / FRAMES_PER_SEC - 2] + st_ivas->bit_stream[total_brate / FRAMES_PER_SEC - 3] + 1; - } - - k = (int16_t) ( ( total_brate / FRAMES_PER_SEC ) - 1 ); - - { - st_ivas->nchan_transport++; - k--; - } -#endif } } #endif diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 07d6c66f75..2ebd9e359e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -374,12 +374,8 @@ typedef enum #ifdef MASA_AND_OBJECTS , ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ -#ifdef OMASA_UPDATES ISM_MASA_MODE_MASA_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using MASA parameters */ ISM_MASA_MODE_PARAM_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using parametric object model */ -#else - ISM_MASA_MODE_ONE_OBJ, /* MASA ISM mode when one object is encoded separarately */ -#endif ISM_MASA_MODE_DISC /* MASA ISM mode when all objects are encoded separarately */ #endif } ISM_MODE; @@ -639,11 +635,7 @@ enum IND_STEREO_DFT_SIDEGAIN_FLAG, IND_STEREO_DFT_SIDEGAINS, - #ifdef OMASA_UPDATES - IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 120, - #else - IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 72, - #endif + IND_STEREO_DFT_ITD_MODE = IND_STEREO_DFT_SIDEGAINS + 4 * STEREO_DFT_BAND_MAX + 120, IND_STEREO_DFT_ITD_HUFF, IND_STEREO_DFT_ITD_NEG, diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index c4ab8be9af..dd088fca52 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -96,11 +96,7 @@ void ivas_masa_set_elements( if ( ivas_total_brate > MIN_BRATE_MDCT_STEREO ) { *element_mode = IVAS_CPE_MDCT; -#ifdef OMASA_UPDATES if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) ) -#else - if ( ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_ONE_OBJ ) && ( ivas_total_brate - ism_total_brate < MIN_BRATE_MDCT_STEREO ) ) -#endif { *element_mode = IVAS_CPE_DFT; } @@ -119,11 +115,7 @@ void ivas_masa_set_elements( } hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_ONE_OBJ || ism_mode == ISM_MASA_MODE_DISC ) ) -#endif { hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); } @@ -634,11 +626,7 @@ int32_t calculate_cpe_brate_MASA_ISM( k++; } -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { cpe_brate = ivas_total_brate - sep_object_brate[k - 2][0]; /* take data from the first column */ } diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 4bf5c3ed83..5501fa79aa 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -58,15 +58,9 @@ #define GAMMA_ISM_MEDIUM_IMP3 1.15f #define GAMMA_ISM_HIGH_IMP3 1.3f -#ifdef OMASA_UPDATES #define GAMMA_ISM_LOW_IMP4 0.8f #define GAMMA_ISM_MEDIUM_IMP4 1.0f #define GAMMA_ISM_HIGH_IMP4 1.2f -#else -#define GAMMA_ISM_LOW_IMP4 0.6f -#define GAMMA_ISM_MEDIUM_IMP4 0.8f -#define GAMMA_ISM_HIGH_IMP4 1.0f -#endif /*--------------------------------------------------------------- @@ -103,11 +97,7 @@ ISM_MODE ivas_omasa_ism_mode_select( } else if ( ivas_total_brate >= IVAS_32k ) { -#ifdef OMASA_UPDATES ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; -#else - ism_mode = ISM_MASA_MODE_ONE_OBJ; -#endif } else { @@ -121,23 +111,12 @@ ISM_MODE ivas_omasa_ism_mode_select( } else if ( ivas_total_brate >= IVAS_64k ) { -#ifdef OMASA_UPDATES ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; -#else - ism_mode = ISM_MASA_MODE_ONE_OBJ; -#endif } -#ifdef OMASA_UPDATES else if ( ivas_total_brate >= IVAS_32k ) { ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; } -#else - else if ( ivas_total_brate >= IVAS_48k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } -#endif else { ism_mode = ISM_MODE_NONE; @@ -148,7 +127,6 @@ ISM_MODE ivas_omasa_ism_mode_select( { ism_mode = ISM_MASA_MODE_DISC; } -#ifdef OMASA_UPDATES else if ( ivas_total_brate >= IVAS_64k ) { ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ; @@ -157,16 +135,6 @@ ISM_MODE ivas_omasa_ism_mode_select( { ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ; } -#else - else if ( ivas_total_brate >= IVAS_64k ) - { - ism_mode = ISM_MASA_MODE_ONE_OBJ; - } - else if ( ivas_total_brate >= IVAS_48k ) - { - ism_mode = ISM_MASA_MODE_PARAM; - } -#endif else { ism_mode = ISM_MODE_NONE; @@ -197,12 +165,8 @@ void ivas_set_omasa_TC( *nCPE = 1; *nSCE = 0; break; -#ifdef OMASA_UPDATES case ISM_MASA_MODE_MASA_ONE_OBJ: case ISM_MASA_MODE_PARAM_ONE_OBJ: -#else - case ISM_MASA_MODE_ONE_OBJ: -#endif *nCPE = 1; *nSCE = 1; break; @@ -230,14 +194,11 @@ void ivas_set_omasa_TC( /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( - const ISM_MODE ism_mode, /* i : ISM mode */ - const int16_t nchan_ism, /* i : number of ISM channels */ - const int32_t element_brate, /* i : element bitrate */ - const int16_t ism_imp /* i : ISM importance flag */ -#ifdef OMASA_UPDATES - , - const int16_t limit_flag /* i : flag to limit the bitrate increase */ -#endif + const ISM_MODE ism_mode, /* i : ISM mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ + const int32_t element_brate, /* i : element bitrate */ + const int16_t ism_imp, /* i : ISM importance flag */ + const int16_t limit_flag /* i : flag to limit the bitrate increase */ ) { int32_t element_brate_out; @@ -254,12 +215,11 @@ int32_t ivas_interformat_brate( if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */ { -#ifdef OMASA_UPDATES - if ( ( limit_flag == 1 ) && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) + if ( limit_flag == 1 && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) { return element_brate; } -#endif + if ( ism_imp == ISM_LOW_IMP ) { nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 ); @@ -281,14 +241,9 @@ int32_t ivas_interformat_brate( } } } - else -#ifdef OMASA_UPDATES - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || -#else - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ || -#endif - ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ - ) + else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || + ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ + ) { if ( ism_imp == ISM_LOW_IMP ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 21488cafbf..a6392e2a09 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4844,7 +4844,7 @@ ivas_error vbap_init_data( const float *speaker_node_azi_deg, /* i : vector of speaker node azimuths (positive left) */ const float *speaker_node_ele_deg, /* i : vector of speaker node elevations (positive up) */ const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS , const int16_t support_object_mode /* i : init VBAP also for object panning mode */ #endif @@ -4859,7 +4859,7 @@ void vbap_determine_gains( float *gains, /* o : gain vector for speaker nodes for given direction */ const int16_t azi_deg, /* i : azimuth in degrees for panning direction (positive left) */ const int16_t ele_deg /* i : elevation in degrees for panning direction (positive up) */ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS , const int16_t use_object_mode /* i : select between object mode panning and spatial mode panning */ #endif @@ -5185,10 +5185,8 @@ int32_t ivas_interformat_brate( const ISM_MODE ism_mode, /* i : ISM mode */ const int16_t nchan_ism, /* i : number of ISM channels */ const int32_t element_brate, /* i : element bitrate */ - const int16_t ism_imp /* i : ISM importance flag */ -#ifdef OMASA_UPDATES - , const int16_t limit_flag /* i : flag to limit the bitrate increase */ -#endif + const int16_t ism_imp, /* i : ISM importance flag */ + const int16_t limit_flag /* i : flag to limit the bitrate increase */ ); void ivas_combined_format_brate_sanity( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 80e3712dad..5f09e0d45a 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -74,11 +74,9 @@ typedef struct #ifdef MASA_AND_OBJECTS int16_t ism_imp; /* ISM importance flag */ int16_t ism_vad_flag; -#ifdef OMASA_UPDATES float q_azimuth_old; float q_elevation_old; #endif -#endif } ISM_METADATA_FRAME, *ISM_METADATA_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index d86a5355fa..64aab79878 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -168,7 +168,6 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define OMASA_UPDATES /* Nokia: Updates to the OMASA processing */ #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 69e9dcfef4..2fb2af0de4 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -609,7 +609,8 @@ ivas_error ivas_dirac_dec_config( { vbap_free_data( &( st_ivas->hVBAPdata ) ); } -#ifdef OMASA_UPDATES + +#ifdef MASA_AND_OBJECTS if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format == MASA_ISM_FORMAT ? 1 : 0 ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 4371a8dc20..8c90a3a82d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2012,11 +2012,7 @@ static ivas_error printConfigInfo_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES fprintf( stdout, "Input configuration: combined ISM and MASA (%i ISM stream(s)) \n", st_ivas->nchan_ism ); -#else - fprintf( stdout, "Input configuration: combined ISM and MASA (%i separated ISM stream(s)) \n", st_ivas->nchan_transport ); -#endif } #endif } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index bce8d37984..db0da4666d 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -169,7 +169,7 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && ivas_total_brate == IVAS_48k ) { hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k ); @@ -178,7 +178,7 @@ ivas_error ivas_cpe_enc( { #endif hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS } #endif } @@ -329,11 +329,7 @@ ivas_error ivas_cpe_enc( #ifdef MASA_AND_OBJECTS /* compute bit-rate surplus per channel in combined format coding */ int32_t brate_surplus[CPE_CHANNELS]; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { brate_surplus[0] = ( ( hCPE->brate_surplus / FRAMES_PER_SEC ) >> 1 ) * FRAMES_PER_SEC; brate_surplus[1] = hCPE->brate_surplus - brate_surplus[0]; @@ -362,11 +358,7 @@ ivas_error ivas_cpe_enc( #ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { sts[n]->bits_frame_channel += (int16_t) ( brate_surplus[n] / FRAMES_PER_SEC ); sts[n]->total_brate += brate_surplus[n]; @@ -723,11 +715,7 @@ ivas_error ivas_cpe_enc( #ifdef MASA_AND_OBJECTS /* subtract bit-rate for combined format coding */ -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif { sts[0]->total_brate += hCPE->brate_surplus; } diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index e26d1e7a72..1ef2fc00b0 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -404,7 +404,7 @@ void ivas_signaling_enc( /*-------------------------------------------------------------------------- * Write element mode info *--------------------------------------------------------------------------*/ -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ #else if ( st->element_mode >= IVAS_CPE_DFT && element_brate < MIN_BRATE_MDCT_STEREO && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 1708e4d701..87b6505716 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -323,18 +323,13 @@ ivas_error ivas_enc( /* Encode ISMs transport channels */ n = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */ { return error; } } -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) @@ -342,7 +337,6 @@ ivas_error ivas_enc( return error; } } -#endif else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { /* Analysis, decision about bitrates per channel & core coding */ @@ -355,12 +349,7 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa -#ifdef MASA_AND_OBJECTS - , - st_ivas->hIsmMetaData[0]->ism_imp -#endif - ); + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp ); /* Configuration of combined-format bit-budget distribution */ #ifdef DEBUG_MODE_INFO @@ -369,7 +358,6 @@ ivas_error ivas_enc( ivas_set_surplus_brate_enc( st_ivas ); #endif - /* Encode MASA transport channels */ if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 8cf039868c..b560d04f4d 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -87,10 +87,11 @@ ivas_error ivas_ism_enc( int16_t localVAD_HE_SAD[1]; /* local HE VAD */ int16_t nchan_ism, dtx_flag, sid_flag, flag_noisy_speech; int16_t md_diff_flag[MAX_NUM_OBJECTS]; - ivas_error error; #ifdef MASA_AND_OBJECTS + int32_t ism_total_brate_ref, ism_total_brate; int16_t i, nchan_transport_ism; #endif + ivas_error error; push_wmops( "ivas_ism_enc" ); @@ -109,15 +110,12 @@ ivas_error ivas_ism_enc( #ifdef MASA_AND_OBJECTS nchan_transport_ism = st_ivas->nchan_transport; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { nchan_transport_ism = 1; nchan_ism = 1; } - else -#endif - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { nchan_transport_ism = st_ivas->hEncoderConfig->nchan_ism; } @@ -245,36 +243,17 @@ ivas_error ivas_ism_enc( } else if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { - // VE: call ivas_ism_metadata_enc() with 'st_ivas' - TBD - ivas_ism_metadata_enc( -#ifdef MASA_AND_OBJECTS - &st_ivas->hEncoderConfig->ivas_total_brate, -#else - st_ivas->hEncoderConfig->ivas_total_brate, -#endif - nchan_ism, #ifdef MASA_AND_OBJECTS - nchan_transport_ism, + ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1 ); #else - st_ivas->nchan_transport, + ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif - st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag -#ifdef MASA_AND_OBJECTS - , - -1 -#endif - ); } else /* ISM_MODE_DISC */ { #ifdef MASA_AND_OBJECTS - int32_t ism_total_brate_ref; - int32_t ism_total_brate; -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { ism_total_brate = 0; for ( i = 0; i < st_ivas->nSCE; i++ ) @@ -289,20 +268,15 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; - // VE: change the interface of the following function and call it with 'st_ivas' only - ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, - nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, - st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ); + ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - ism_total_brate; } - #else - ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, - nchan_ism, - st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); + ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif } diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index e0451811ac..24924a25bb 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -214,11 +214,7 @@ ivas_error ivas_ism_metadata_enc( set_s( flag_abs_radius, 0, nchan_ism ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /*----------------------------------------------------------------* * Rate importance of particular ISM streams in combined format coding @@ -261,11 +257,7 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode != ISM_MASA_MODE_DISC ) -#endif { #endif /* write number of objects - unary coding */ @@ -296,11 +288,7 @@ ivas_error ivas_ism_metadata_enc( #endif { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* ISM importance flag will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_imp = ism_imp[ch]; @@ -318,11 +306,7 @@ ivas_error ivas_ism_metadata_enc( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -331,11 +315,7 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_transport; ch++ ) { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* reset */ hIsmMeta[ch]->ism_vad_flag = 1; @@ -346,11 +326,7 @@ ivas_error ivas_ism_metadata_enc( { /* this flag distinguishes between coding of inactive frame and active frame w/o. metadata */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* VAD flag will be written in ivas_masa_encode() */ hIsmMeta[ch]->ism_vad_flag = localVAD[ch]; @@ -382,11 +358,7 @@ ivas_error ivas_ism_metadata_enc( { hIsmMetaData = hIsmMeta[ch]; #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -401,11 +373,7 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -434,11 +402,7 @@ ivas_error ivas_ism_metadata_enc( /* save number of metadata bits written */ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) -#endif #else if ( ism_mode == ISM_MODE_DISC ) #endif @@ -574,18 +538,13 @@ ivas_error ivas_ism_metadata_enc( * Take into account the combined format bit-budget distribution *----------------------------------------------------------------*/ -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; -#ifdef OMASA_UPDATES int16_t brate_limit_flag; + brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); -#endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); @@ -595,11 +554,7 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < nchan_ism; ch++ ) { -#ifdef OMASA_UPDATES *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); -#else - *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch] ); -#endif } ism_metadata_flag_global = 1; } @@ -610,7 +565,6 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) @@ -625,12 +579,6 @@ ivas_error ivas_ism_metadata_enc( return error; } } -#else - if ( ( error = ivas_ism_config( ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata, ism_mode == ISM_MASA_MODE_DISC ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif #else if ( ( error = ivas_ism_config( ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, localVAD, ism_imp, element_brate, total_brate, nb_bits_metadata ) ) != IVAS_ERR_OK ) { @@ -656,11 +604,7 @@ ivas_error ivas_ism_metadata_enc( hSCE[ch]->element_brate = element_brate[ch]; } -#ifdef OMASA_UPDATES else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - else if ( ism_mode == ISM_MASA_MODE_DISC ) -#endif { if ( ism_imp[ch] == ISM_INACTIVE_IMP ) { @@ -788,10 +732,8 @@ ivas_error ivas_ism_metadata_enc_create( #ifdef MASA_AND_OBJECTS st_ivas->hIsmMetaData[ch]->ism_imp = -1; st_ivas->hIsmMetaData[ch]->ism_vad_flag = 1; -#ifdef OMASA_UPDATES st_ivas->hIsmMetaData[ch]->q_azimuth_old = 0.0f; st_ivas->hIsmMetaData[ch]->q_elevation_old = 0.0f; -#endif #endif ivas_ism_reset_metadata( st_ivas->hIsmMetaData[ch] ); @@ -803,11 +745,7 @@ ivas_error ivas_ism_metadata_enc_create( #ifdef MASA_AND_OBJECTS if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, 1, NULL, NULL, NULL, element_brate_tmp, NULL, NULL, 1 ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index b588302bf9..c1f509d9bb 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -64,12 +64,7 @@ static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR #ifdef MASA_AND_OBJECTS static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); -static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format -#ifndef OMASA_UPDATES - , - const ISM_MODE ism_mode -#endif -); +static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #else static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); @@ -150,11 +145,7 @@ ivas_error ivas_masa_enc_open( } #ifdef MASA_AND_OBJECTS ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -320,11 +311,7 @@ ivas_error ivas_masa_encode( #endif { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) -#else - if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) || ( ivas_format != MASA_ISM_FORMAT ) ) -#endif { /* Combine directions */ ivas_masa_combine_directions( hMasa ); @@ -364,27 +351,18 @@ ivas_error ivas_masa_encode( hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; /* write index of separated object if needed */ -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && hMasa->data.nchan_ism > 1 ) -#else - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ && hMasa->data.nchan_ism > 1 ) -#endif { push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; } /* write ISM importance flag (one per object) */ -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; } -#ifdef OMASA_UPDATES else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); @@ -397,7 +375,6 @@ ivas_error ivas_masa_encode( hQMetaData->metadata_max_bits -= ISM_METADATA_VAD_FLAG_BITS; } } -#endif else if ( ism_mode == ISM_MASA_MODE_DISC ) { for ( i = 0; i < nchan_ism; i++ ) @@ -455,12 +432,8 @@ ivas_error ivas_masa_encode( if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) { #ifdef MASA_AND_OBJECTS - reduce_metadata_further( hMasa, hQMetaData, ivas_format -#ifndef OMASA_UPDATES - , - ism_mode -#endif - ); + reduce_metadata_further( hMasa, hQMetaData, ivas_format ); + low_bitrate_mode = ( ivas_total_brate <= 32000 ); #else reduce_metadata_further( hMasa, hQMetaData, ivas_format ); @@ -472,11 +445,7 @@ ivas_error ivas_masa_encode( #ifdef MASA_AND_OBJECTS /* Encode MASA+ISM metadata */ -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { /* encode MASA/ISM energy ratios */ ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, @@ -491,11 +460,7 @@ ivas_error ivas_masa_encode( ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { /* Modify spatial metadata based on the MASA-to-total energy ratios */ modify_masa_energy_ratios( hQMetaData ); @@ -674,11 +639,7 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( i = 0; i < st_ivas->nSCE; i++ ) { @@ -731,18 +692,14 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { -#ifdef OMASA_UPDATES if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) { ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); } else { -#endif ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); -#ifdef OMASA_UPDATES } -#endif } else { @@ -843,11 +800,7 @@ ivas_error ivas_masa_enc_config( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif { if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) { @@ -1528,14 +1481,7 @@ static void compensate_energy_ratios( static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, - const IVAS_FORMAT ivas_format -#ifdef MASA_AND_OBJECTS -#ifndef OMASA_UPDATES - , - const ISM_MODE ism_mode -#endif -#endif -) + const IVAS_FORMAT ivas_format ) { int16_t sf; int16_t band; @@ -1559,11 +1505,7 @@ static void reduce_metadata_further( /* Get energy for the input data in 4-subframe, 5-band format */ totalEnergySum = 0.0f; #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ -#else - if ( ivas_format == MASA_FORMAT || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) ) /* Energy data is in 4-subframe, 24-band format */ -#endif #else if ( ivas_format == MASA_FORMAT ) /* Energy data is in 4-subframe, 24-band format */ #endif @@ -1953,11 +1895,7 @@ void ivas_masa_enc_reconfigure( #ifdef MASA_AND_OBJECTS ism_total_brate = 0; -#ifdef OMASA_UPDATES if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) ) -#endif { for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -3633,7 +3571,6 @@ static void ivas_encode_masaism_metadata( /* quantize directions */ for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) { -#ifdef OMASA_UPDATES if ( bits_ism[obj] < 8 ) { /* check is same as previous */ @@ -3658,11 +3595,6 @@ static void ivas_encode_masaism_metadata( hIsmMeta[obj]->q_elevation_old = hIsmMeta[obj]->elevation; hIsmMeta[obj]->q_azimuth_old = hIsmMeta[obj]->azimuth; } - -#else - idx_sph = quantize_direction( hIsmMeta[obj]->elevation, hIsmMeta[obj]->azimuth, bits_ism[obj], &theta_q, &phi_q, &index_theta, &index_phi, MC_LS_SETUP_INVALID ); - push_next_indice( hMetaData, idx_sph, bits_ism[obj] ); -#endif } return; diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index a9f182705a..d9acdc7d2f 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -277,11 +277,7 @@ ivas_error ivas_omasa_enc_config( st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; -#ifdef OMASA_UPDATES if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) -#else - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) -#endif { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } @@ -323,11 +319,7 @@ void ivas_omasa_set_config( uint8_t i, maxBin; /* Determine the number of bands */ -#ifdef OMASA_UPDATES if ( ism_mode == ISM_MODE_NONE || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( ism_mode == ISM_MODE_NONE ) -#endif { /* use full resolution for the ISM+MASA merge and reduce later */ hOMasa->nbands = 24; @@ -399,140 +391,8 @@ void ivas_omasa_enc( int16_t i, j; float data_out_f[MASA_MAX_TRANSPORT_CHANNELS][L_FRAME48k]; - -#ifdef OMASA_UPDATES /* Determine separated object (when applicable) */ if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - /* Analysis */ - if ( ism_mode == ISM_MODE_NONE ) - { -#ifdef OMASA_DIFFUSE_ISM_MERGE - OMASA_SPATIAL_META OMasaMeta; /* working memory for the ISM-object MASA-parameters */ - OMASA_SPATIAL_META_HANDLE hOMasaMeta; - uint8_t n_bands_orig, n_subframes_orig; - uint8_t numCodingBands_orig, joinedSubframes_orig; -#else - float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float energyRatio[MASA_FREQUENCY_BANDS]; - float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - float surroundingCoherence[MASA_FREQUENCY_BANDS]; - int16_t nBands, nBlocks; - uint8_t fixedDistance = 0; - - nBands = hOMasa->nbands; - nBlocks = hOMasa->nSubframes; -#endif - -#ifdef OMASA_DIFFUSE_ISM_MERGE - hOMasaMeta = &OMasaMeta; - hOMasaMeta->num_dirs = 1; /* TODO: hard-coding for now */ - - /* merge MASA directions before adding ISM to the mixture */ - if ( hMasa->config.numberOfDirections == 2 ) - { - n_bands_orig = hMasa->config.numCodingBands; - hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; - - ivas_masa_combine_directions( hMasa ); - - hMasa->config.numCodingBands = (int8_t) n_bands_orig; - } - - /* force computation into high resolution */ - n_bands_orig = hOMasa->nbands; - n_subframes_orig = hOMasa->nSubframes; - - hOMasa->nbands = MASA_FREQUENCY_BANDS; - hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; - - /* Estimate MASA parameters from the objects */ - /* NB: only first direction is populated */ - /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ - ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], - hOMasaMeta->common_meta.diffuse_to_total_ratio[0], input_frame, nchan_ism ); - - /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ - for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - mvr2r( hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].energy_ratio[i], MASA_FREQUENCY_BANDS ); - mvr2r( hOMasaMeta->common_meta.surround_coherence[0], hOMasaMeta->common_meta.surround_coherence[i], MASA_FREQUENCY_BANDS ); - mvr2r( hOMasaMeta->common_meta.diffuse_to_total_ratio[0], hOMasaMeta->common_meta.diffuse_to_total_ratio[i], MASA_FREQUENCY_BANDS ); - } -#else - /* Estimate MASA parameters from the objects */ - ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, nchan_ism ); -#endif - -#ifdef OMASA_DIFFUSE_ISM_MERGE - /* restore resolution parameters */ - hOMasa->nbands = n_bands_orig; - hOMasa->nSubframes = n_subframes_orig; - - /* perform MASA+ISM merge in full resolution */ - numCodingBands_orig = hMasa->config.numCodingBands; - joinedSubframes_orig = hMasa->config.joinedSubframes; - - hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; - hMasa->config.joinedSubframes = 0; - - ivas_merge_masa_metadata( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ - - hMasa->config.numCodingBands = numCodingBands_orig; - hMasa->config.joinedSubframes = joinedSubframes_orig; -#else - - /* Set analyzed values to the QMeta struct */ - for ( i = 0; i < nBands; i++ ) - { - for ( j = 0; j < nBlocks; j++ ) - { - hQMeta->q_direction[0].band_data[i].azimuth[j] = azimuth_m_values[j][i]; - hQMeta->q_direction[0].band_data[i].elevation[j] = elevation_m_values[j][i]; - hQMeta->q_direction[0].band_data[i].energy_ratio[j] = energyRatio[i]; /* Only one value is transmitted for all subframes */ - hQMeta->q_direction[0].band_data[i].distance[j] = fixedDistance; - - if ( hQMeta->surcoh_band_data != NULL ) - { - hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = (uint8_t) roundf( spreadCoherence[j][i] * UINT8_MAX ); - hQMeta->surcoh_band_data[i].surround_coherence[j] = (uint8_t) roundf( surroundingCoherence[i] * UINT8_MAX ); - } - } - } - - /* At lower sampling rates, set zeros for higher bands that were not analyzed */ - if ( nBands < hOMasa->nCodingBands ) - { - for ( i = nBands; i < hOMasa->nCodingBands; i++ ) - { - for ( j = 0; j < nBlocks; j++ ) - { - hQMeta->q_direction[0].band_data[i].azimuth[j] = 0.0f; - hQMeta->q_direction[0].band_data[i].elevation[j] = 0.0f; - hQMeta->q_direction[0].band_data[i].energy_ratio[j] = 0.0f; - hQMeta->q_direction[0].band_data[i].distance[j] = 0; - - if ( hQMeta->surcoh_band_data != NULL ) - { - hQMeta->q_direction[0].coherence_band_data[i].spread_coherence[j] = 0; - hQMeta->surcoh_band_data[i].surround_coherence[j] = 0; - } - } - } - } -#endif - } - else if ( ism_mode == ISM_MASA_MODE_PARAM ) - { -#ifdef REDUCE_OMASA_META_BITS - *idx_separated_object = -1; -#endif - /* Estimate energies and ratios */ - ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); - } - else -#endif { float broadband_energy[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; int16_t loudest_object; @@ -647,7 +507,6 @@ void ivas_omasa_enc( { set_zero( data_in_f[selected_object], input_frame ); } -#ifdef OMASA_UPDATES } /* Analysis */ @@ -715,20 +574,17 @@ void ivas_omasa_enc( { *idx_separated_object = -1; } -#endif /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); } -#ifdef OMASA_UPDATES /* Move the ISM metadata to the first entry for encoding in the MASA_ONE_OBJ mode */ if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { hIsmMeta[0]->azimuth = hIsmMeta[*idx_separated_object]->azimuth; hIsmMeta[0]->elevation = hIsmMeta[*idx_separated_object]->elevation; } -#endif /* Downmix */ ivas_omasa_dmx( data_in_f, data_out_f, input_frame, nchan_transport, nchan_ism, hIsmMeta, hOMasa->prev_object_dm_gains, hOMasa->interpolator ); @@ -820,27 +676,12 @@ void ivas_set_surplus_brate_enc( #endif ) { -#ifdef OMASA_UPDATES if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); -#else - if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp -#ifdef FIX_4OBJ_128 - , - 0 -#endif - ); -#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) -#endif { /* it is already set in ivas_ism_enc() */ } @@ -854,12 +695,8 @@ void ivas_set_surplus_brate_enc( { int16_t input_frame = (int16_t) ( st_ivas->hEncoderConfig->input_Fs / FRAMES_PER_SEC ); float tmpF = 0; -#ifdef OMAOMASA_UPDATES - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) -#else - if ( 1 ) // st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) -#endif + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { tmpF += st_ivas->hSCE[0]->hCoreCoder[0]->total_brate + (float) ( nb_bits_metadata[1] * 50 ); } diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 1a42cf635f..e236ecf5ba 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -144,11 +144,7 @@ ivas_error ivas_sce_enc( if ( st_ivas->hQMetaData != NULL && st_ivas->hSpar == NULL ) { #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( ( ( st_ivas->mc_mode == MC_MODE_MCMASA ) && ( st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) ) || ( st_ivas->ism_mode >= ISM_MASA_MODE_MASA_ONE_OBJ ) ) -#else - if ( ( ( st_ivas->mc_mode == MC_MODE_MCMASA ) && ( st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) ) || ( st_ivas->ism_mode >= ISM_MASA_MODE_ONE_OBJ ) ) -#endif #else if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hEncoderConfig->ivas_total_brate >= MCMASA_SEPARATE_BRATE ) #endif @@ -220,27 +216,12 @@ ivas_error ivas_sce_enc( * Combined format coding: get the ISM importance and the bit-rate *----------------------------------------------------------------*/ -#ifdef OMASA_UPDATES if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; } -#else - if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ ) - { - set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); - - st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp -#ifdef FIX_4OBJ_128 - , - 0 -#endif - ) - - nb_bits_metadata * FRAMES_PER_SEC; - } -#endif #endif /*----------------------------------------------------------------* @@ -262,11 +243,7 @@ ivas_error ivas_sce_enc( st->flag_ACELP16k = set_ACELP_flag( IVAS_SCE, hSCE->element_brate, st->core_brate, 0, 0, -1, -1 ); } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && st->low_rate_mode ) -#else - else if ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ && st->low_rate_mode ) -#endif { st->flag_ACELP16k = 0; } @@ -376,11 +353,7 @@ ivas_error create_sce_enc( copy_encoder_config( st_ivas, st, 1 ); #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#else - if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) -#endif { st->element_mode = IVAS_SCE; } diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 534dc2189c..59b7c0a399 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -118,7 +118,8 @@ int16_t select_stereo_mode( { stereo_switching_flag = 0; } -#ifdef OMASA_UPDATES + +#ifdef MASA_AND_OBJECTS if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO && !( hCPE->element_brate == IVAS_48k && ivas_total_brate == IVAS_32k ) ) /* the second condition for PARAM mode OMASA */ #else if ( hCPE->element_brate >= MIN_BRATE_MDCT_STEREO ) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 0135239e2e..e6f645197a 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -448,7 +448,6 @@ static void ivas_dirac_dec_binaural_internal( /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { numInChannels++; @@ -457,19 +456,6 @@ static void ivas_dirac_dec_binaural_internal( { numInChannels += (uint8_t) st_ivas->nchan_ism; } -#else - if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) - { - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - numInChannels += (uint8_t) st_ivas->nchan_ism; - } - else - { - numInChannels++; - } - } -#endif #else if ( st_ivas->hOutSetup.separateChannelEnabled ) { @@ -594,18 +580,9 @@ static void ivas_dirac_dec_binaural_internal( } #ifdef MASA_AND_OBJECTS -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) -#else - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) -#endif { - preProcessStereoTransportsForMovedObjects( st_ivas, - Cldfb_RealBuffer_in, - Cldfb_ImagBuffer_in, - nBins, - firstSubframe, - nSubframes ); + preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, firstSubframe, nSubframes ); } #endif @@ -1199,28 +1176,16 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( separateCenterChannelRendering = 0; nchanSeparateChannels = 0; -#ifdef OMASA_UPDATES if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) -#else - if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) ) -#endif { separateCenterChannelRendering = 1; nchanSeparateChannels = 1; -#ifndef OMASA_UPDATES - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; - } -#endif } -#ifdef OMASA_UPDATES else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { separateCenterChannelRendering = 1; nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; } -#endif #else separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; #endif @@ -1367,7 +1332,6 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #ifdef MASA_AND_OBJECTS uint8_t instantChange = 0; -#ifdef OMASA_UPDATES if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { gainFactor = 0.7943f * sqrtf( h->earlyPartEneCorrection[bin] ); /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ @@ -1376,9 +1340,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); } -#else - gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); -#endif + for ( chB = 0; chB < nchanSeparateChannels; chB++ ) { if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 732b7f84da..ce68f4f313 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -211,7 +211,7 @@ ivas_error ivas_td_binaural_open_unwrap( *hBinRendererTd = pBinRendTd; -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( ivas_format != MASA_ISM_FORMAT ) { *binaural_latency_ns = (int32_t) ( ( *hBinRendererTd )->HrFiltSet_p->latency_s * 1000000000.f ); @@ -436,7 +436,7 @@ void TDREND_Update_object_positions( c_indx++; } -#ifdef OMASA_UPDATES +#ifdef MASA_AND_OBJECTS if ( in_format == ISM_FORMAT || in_format == MASA_ISM_FORMAT ) #else if ( in_format == ISM_FORMAT ) -- GitLab From 1d5d629e4473b1e03b82c1e358ffe59c3877a07a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 20:02:33 +0200 Subject: [PATCH 089/173] introduce function ivas_omasa_ism_metadata_dec(0 in order to simplify ivas_dec.c() --- lib_com/ivas_prot.h | 14 +++++--- lib_dec/ivas_dec.c | 78 +++++++--------------------------------- lib_dec/ivas_omasa_dec.c | 76 +++++++++++++++++++++++++++++++++++++++ lib_enc/ivas_enc.c | 9 +++-- 4 files changed, 103 insertions(+), 74 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a6392e2a09..eeb267aec7 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5196,20 +5196,17 @@ void ivas_combined_format_brate_sanity( int16_t *diff_nBits /* o : number of differential bits */ ); - ISM_MODE ivas_omasa_ism_mode_select( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t nchan_ism /* i : number of input ISM's */ ); -#ifdef MASA_AND_OBJECTS void ivas_set_omasa_TC( const ISM_MODE ism_mode, /* i : ISM mode */ const int16_t nchan_ism, /* i : number of input ISMs */ int16_t *nSCE, /* o : number of SCEs */ int16_t *nCPE /* o : number of CPEs */ ); -#endif void ivas_merge_masa_transports( float data_in_f1[][L_FRAME48k], /* i : Transport audio signals 1 */ @@ -5219,15 +5216,22 @@ void ivas_merge_masa_transports( const int16_t num_transport_channels /* i : Number of transport audio signals */ ); +ivas_error ivas_omasa_ism_metadata_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + int16_t *nchan_ism, /* o : number of ISM separated channels */ + int16_t *nchan_transport_ism, /* o : number of ISM TCs */ + const int16_t dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ + int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ +); + ivas_error ivas_masa_ism_data_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ ); -#ifdef MASA_AND_OBJECTS void ivas_masa_ism_data_close( MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ); -#endif void preProcessStereoTransportsForMovedObjects( Decoder_Struct* st_ivas, diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 199af09c8d..a01cee2056 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -404,23 +404,21 @@ ivas_error ivas_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - int16_t dirac_bs_md_write_idx = 0; + int16_t nchan_ism, nchan_transport_ism; + int16_t dirac_bs_md_write_idx, dirac_read_idx; st = st_ivas->hCPE[0]->hCoreCoder[0]; - nb_bits_metadata[0] = 0; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); /* Set the number of objects for the parametric rendering */ + dirac_bs_md_write_idx = 0; if ( st_ivas->hDirAC != NULL ) { + st_ivas->hDirAC->numIsmDirections = 0; if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; } - else - { - st_ivas->hDirAC->numIsmDirections = 0; - } dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ } @@ -436,64 +434,10 @@ ivas_error ivas_dec( st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); - //VE: !!!!! - /* set ISM parameters */ - int16_t nchan_ism, nchan_transport_ism; - nchan_ism = st_ivas->nchan_ism; - nchan_transport_ism = st_ivas->nchan_ism; - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { - nchan_ism = 1; - nchan_transport_ism = 1; - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - nchan_ism = 0; - nchan_transport_ism = 1; - } - - /* decode ISM metadata */ - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + /* set ISM parameters and decode ISM metadata in OMASA format */ + if ( ( error = ivas_omasa_ism_metadata_dec( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) { - int16_t azimuth_ism; - int16_t elevation_ism; - int16_t block; - int16_t meta_write_index; - - /* decode ISM metadata */ - if ( ( error = ivas_ism_metadata_dec( ism_total_brate, nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, &nb_bits_metadata[1], st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK ) - { - return error; - } - - // VE: move the following updates into ivas_ism_metadata_dec() - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; - st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; - st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; - } - } - } - else /* ISM_MASA_MODE_MASA_ONE_OBJ */ - { - azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); - elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; - st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; - st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; - } - } + return error; } /* decode ISM channels */ @@ -569,18 +513,20 @@ ivas_error ivas_dec( { if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { + //ivas_omasa_rend( st_ivas, output ); + + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; - int16_t dirac_read_idx; if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - mvr2r( output[2], data_separated_objects[0], output_frame ); + // mvr2r( output[2], data_separated_objects[0], output_frame ); } else { for ( n = 0; n < st_ivas->nchan_ism; n++ ) { - mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + // mvr2r( output[n + 2], data_separated_objects[n], output_frame ); } } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 777d6bfbe5..d538462db6 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -392,4 +392,80 @@ void ivas_set_surplus_brate_dec( return; } + + +/*--------------------------------------------------------------------------* + * ivas_omasa_ism_metadata_dec() + * + * decode ISM metadata in OMASA format + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_ism_metadata_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int32_t ism_total_brate, /* i : ISM total bitrate */ + int16_t *nchan_ism, /* o : number of ISM separated channels */ + int16_t *nchan_transport_ism, /* o : number of ISM TCs */ + const int16_t dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ + int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ +) +{ + int16_t n, block; + int16_t azimuth_ism, elevation_ism, meta_write_index; + ivas_error error; + + /* set ISM parameters */ + *nchan_ism = st_ivas->nchan_ism; + *nchan_transport_ism = st_ivas->nchan_ism; + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + *nchan_ism = 1; + *nchan_transport_ism = 1; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + *nchan_ism = 0; + *nchan_transport_ism = 1; + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + /* decode ISM metadata */ + if ( ( error = ivas_ism_metadata_dec( ism_total_brate, *nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, + nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; + } + } + } + else /* ISM_MASA_MODE_MASA_ONE_OBJ */ + { + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; + } + } + } + + return IVAS_ERR_OK; +} + #endif diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 87b6505716..457d56a5e9 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -348,8 +348,11 @@ ivas_error ivas_enc( } /* Encode MASA parameters and write MASA metadata bitstream */ - ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp ); + if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp ) ) != IVAS_ERR_OK ) + { + return error; + } /* Configuration of combined-format bit-budget distribution */ #ifdef DEBUG_MODE_INFO @@ -368,7 +371,7 @@ ivas_error ivas_enc( else if ( ivas_format == MC_FORMAT ) { /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */ - if ( ( ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 214ddc703fc11dd81d2ff34999b267fc1ad86c62 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 20:19:17 +0200 Subject: [PATCH 090/173] introduce function ivas_omasa_rend() in order to safe stack memory --- lib_com/ivas_prot.h | 18 ++++++++++++------ lib_dec/ivas_dec.c | 28 +++------------------------- lib_dec/ivas_omasa_dec.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 31 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index eeb267aec7..238492a510 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5216,6 +5216,14 @@ void ivas_merge_masa_transports( const int16_t num_transport_channels /* i : Number of transport audio signals */ ); +ivas_error ivas_masa_ism_data_open( + Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ +); + +void ivas_masa_ism_data_close( + MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ +); + ivas_error ivas_omasa_ism_metadata_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int32_t ism_total_brate, /* i : ISM total bitrate */ @@ -5225,12 +5233,10 @@ ivas_error ivas_omasa_ism_metadata_dec( int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); -ivas_error ivas_masa_ism_data_open( - Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ -); - -void ivas_masa_ism_data_close( - MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ +void ivas_omasa_rend( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float output[][L_FRAME48k], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length per channel */ ); void preProcessStereoTransportsForMovedObjects( diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index a01cee2056..3e43b6aec5 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -509,37 +509,15 @@ ivas_error ivas_dec( { ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); } - else if ( st_ivas->hDirAC ) + else if ( st_ivas->renderer_type == RENDERER_DIRAC ) // VE2TP: please verify, it was "else if (st_ivas->hDirAC)" { if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - //ivas_omasa_rend( st_ivas, output ); - - - float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; - - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - // mvr2r( output[2], data_separated_objects[0], output_frame ); - } - else - { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - // mvr2r( output[n + 2], data_separated_objects[n], output_frame ); - } - } - - dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; - - ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); - - st_ivas->hDirAC->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ - - ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); + ivas_omasa_rend( st_ivas, output, output_frame ); } else { + // VE2TP: this should never happen (ISM_MODE_NONE is renderered via ivas_format==MASA_FORMAT if branch) ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); } } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index d538462db6..bd4af659d0 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -468,4 +468,42 @@ ivas_error ivas_omasa_ism_metadata_dec( return IVAS_ERR_OK; } + +/*--------------------------------------------------------------------------* + * ivas_omasa_rend() + * + * Rendering in OMASA format + *--------------------------------------------------------------------------*/ + +void ivas_omasa_rend( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float output[][L_FRAME48k], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length per channel */ +) +{ + int16_t n, dirac_read_idx; + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + mvr2r( output[2], data_separated_objects[0], output_frame ); + } + else + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( output[n + 2], data_separated_objects[n], output_frame ); + } + } + + dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; + + ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); + + st_ivas->hDirAC->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ + + ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); + + return; +} #endif -- GitLab From b029297cfedf12982fc5aaf44cc5de8be6bfd677 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 20:29:10 +0200 Subject: [PATCH 091/173] introduce function ivas_omasa_dirac_td_binaural() in order to safe stack memory --- lib_com/ivas_prot.h | 8 ++++++- lib_dec/ivas_dec.c | 29 ++++-------------------- lib_dec/ivas_omasa_dec.c | 48 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 238492a510..dd3c658455 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5233,7 +5233,13 @@ ivas_error ivas_omasa_ism_metadata_dec( int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); -void ivas_omasa_rend( +ivas_error ivas_omasa_dirac_td_binaural( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float output[][L_FRAME48k], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length per channel */ +); + +void ivas_omasa_dirac_rend( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* o : output synthesis signal */ const int16_t output_frame /* i : output frame length per channel */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 3e43b6aec5..6d8ab4db78 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -405,7 +405,7 @@ ivas_error ivas_dec( else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { int16_t nchan_ism, nchan_transport_ism; - int16_t dirac_bs_md_write_idx, dirac_read_idx; + int16_t dirac_bs_md_write_idx; st = st_ivas->hCPE[0]->hCoreCoder[0]; set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); @@ -474,31 +474,10 @@ ivas_error ivas_dec( { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { - float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; - float gain = 0.7943f; /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ - - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - mvr2r( output[2 + n], data_separated_objects[n], output_frame ); - v_multc( data_separated_objects[n], gain, data_separated_objects[n], output_frame ); - } - - for ( n = 0; n < st_ivas->nchan_ism; n++ ) - { - delay_signal( data_separated_objects[n], output_frame, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); - } - - ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); - - if ( ( error = ivas_td_binaural_renderer( st_ivas, data_separated_objects, output_frame ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_dirac_td_binaural( st_ivas, output, output_frame ) ) != IVAS_ERR_OK ) { return error; } - - for ( n = 0; n < BINAURAL_CHANNELS; n++ ) - { - v_add( output[n], data_separated_objects[n], output[n], output_frame ); - } } else { @@ -513,11 +492,11 @@ ivas_error ivas_dec( { if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - ivas_omasa_rend( st_ivas, output, output_frame ); + ivas_omasa_dirac_rend( st_ivas, output, output_frame ); } else { - // VE2TP: this should never happen (ISM_MODE_NONE is renderered via ivas_format==MASA_FORMAT if branch) + // VE2TP: please verify - this should probably never happen (ISM_MODE_NONE is renderered via "ivas_format == MASA_FORMAT" if branch) ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); } } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index bd4af659d0..870ba29169 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -470,12 +470,12 @@ ivas_error ivas_omasa_ism_metadata_dec( /*--------------------------------------------------------------------------* - * ivas_omasa_rend() + * ivas_omasa_dirac_rend() * * Rendering in OMASA format *--------------------------------------------------------------------------*/ -void ivas_omasa_rend( +void ivas_omasa_dirac_rend( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* o : output synthesis signal */ const int16_t output_frame /* i : output frame length per channel */ @@ -506,4 +506,48 @@ void ivas_omasa_rend( return; } + + +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_td_binaural() + * + * Binaural rendering in OMASA format + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_dirac_td_binaural( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float output[][L_FRAME48k], /* o : output synthesis signal */ + const int16_t output_frame /* i : output frame length per channel */ +) +{ + int16_t n; + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + float gain = 0.7943f; /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ + ivas_error error; + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + mvr2r( output[2 + n], data_separated_objects[n], output_frame ); + v_multc( data_separated_objects[n], gain, data_separated_objects[n], output_frame ); + } + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + delay_signal( data_separated_objects[n], output_frame, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); + } + + ivas_dirac_dec_binaural( st_ivas, output, st_ivas->nchan_transport ); + + if ( ( error = ivas_td_binaural_renderer( st_ivas, data_separated_objects, output_frame ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < BINAURAL_CHANNELS; n++ ) + { + v_add( output[n], data_separated_objects[n], output[n], output_frame ); + } + + return IVAS_ERR_OK; +} #endif -- GitLab From 5aadd51042e74d56f6e83a39d1fe4937f0b144de Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Apr 2023 20:37:10 +0200 Subject: [PATCH 092/173] remove obsolete ISM_MASA_MODE_PARAM mode --- lib_com/ivas_cnst.h | 2 +- lib_com/ivas_omasa_com.c | 5 ----- lib_dec/ivas_cpe_dec.c | 4 ---- lib_dec/ivas_masa_dec.c | 9 +-------- lib_dec/ivas_mono_dmx_renderer.c | 6 +----- lib_enc/ivas_cpe_enc.c | 13 +------------ lib_enc/ivas_init_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 13 +++---------- lib_enc/ivas_omasa_enc.c | 9 ++------- 9 files changed, 10 insertions(+), 53 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 2ebd9e359e..2f8d004a9e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -373,11 +373,11 @@ typedef enum ISM_MODE_PARAM /* parametric ISM */ #ifdef MASA_AND_OBJECTS , - ISM_MASA_MODE_PARAM, /* parametric ISM mode for combined MASA ISM format */ ISM_MASA_MODE_MASA_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using MASA parameters */ ISM_MASA_MODE_PARAM_ONE_OBJ, /* MASA ISM mode when one object is encoded separately and remainder using parametric object model */ ISM_MASA_MODE_DISC /* MASA ISM mode when all objects are encoded separarately */ #endif + } ISM_MODE; diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index 5501fa79aa..8e385537c3 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -161,10 +161,6 @@ void ivas_set_omasa_TC( { switch ( ism_mode ) { - case ISM_MASA_MODE_PARAM: - *nCPE = 1; - *nSCE = 0; - break; case ISM_MASA_MODE_MASA_ONE_OBJ: case ISM_MASA_MODE_PARAM_ONE_OBJ: *nCPE = 1; @@ -214,7 +210,6 @@ int32_t ivas_interformat_brate( { if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */ { - if ( limit_flag == 1 && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) { return element_brate; diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 97a046fe9d..9667995683 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -1100,11 +1100,7 @@ static void read_stereo_mode_and_bwidth( else { /* read stereo technology info */ -#ifdef MASA_AND_OBJECTS - if ( ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) || ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && hCPE->element_brate == IVAS_48k ) ) -#else if ( hCPE->element_brate < MIN_BRATE_MDCT_STEREO && st_ivas->hMCT == NULL ) -#endif { hCPE->element_mode = get_next_indice( sts[0], NBITS_ELEMENT_MODE ) + IVAS_CPE_DFT; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b84d8d1cca..d559c05261 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -721,14 +721,7 @@ static ivas_error ivas_masa_dec_config( if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); - } - else - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); - } + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } else { diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index a6f0abfddb..4e16edca30 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -97,11 +97,7 @@ void ivas_mono_downmix_render_passive( #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) - { - numInputChannels = st_ivas->nchan_transport; - } - else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { numInputChannels = st_ivas->nchan_transport + 1; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index db0da4666d..5c13e032e8 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -169,18 +169,7 @@ ivas_error ivas_cpe_enc( if ( sts[0]->ini_frame > 0 && st_ivas->hMCT == NULL ) { -#ifdef MASA_AND_OBJECTS - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM && ivas_total_brate == IVAS_48k ) - { - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, IVAS_32k ); - } - else - { -#endif - hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); -#ifdef MASA_AND_OBJECTS - } -#endif + hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index a9d1c83c43..f2b30df804 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -628,7 +628,7 @@ ivas_error ivas_init_encoder( } } - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) { st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c1f509d9bb..e12251abf7 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -445,7 +445,7 @@ ivas_error ivas_masa_encode( #ifdef MASA_AND_OBJECTS /* Encode MASA+ISM metadata */ - if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* encode MASA/ISM energy ratios */ ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, @@ -460,7 +460,7 @@ ivas_error ivas_masa_encode( ivas_qmetadata_enc_encode( hMetaData, hQMetaData ); #ifdef MASA_AND_OBJECTS - if ( ivas_format == MASA_ISM_FORMAT && ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ modify_masa_energy_ratios( hQMetaData ); @@ -692,14 +692,7 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { - if ( st_ivas->hCPE[0]->element_brate == IVAS_48k && st_ivas->ism_mode == ISM_MASA_MODE_PARAM ) - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, IVAS_32k, st_ivas->nchan_transport, MC_MODE_NONE ); - } - else - { - ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); - } + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } else { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index d9acdc7d2f..8c6cd7038c 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -277,7 +277,7 @@ ivas_error ivas_omasa_enc_config( st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; - if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO && ( st_ivas->ism_mode != ISM_MASA_MODE_PARAM ) ) + if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; } @@ -568,13 +568,8 @@ void ivas_omasa_enc( hMasa->config.numCodingBands = numCodingBands_orig; hMasa->config.joinedSubframes = joinedSubframes_orig; } - else if ( ism_mode == ISM_MASA_MODE_PARAM || ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - if ( ism_mode == ISM_MASA_MODE_PARAM ) - { - *idx_separated_object = -1; - } - /* Estimate energies and ratios */ ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); } -- GitLab From 3e53ed8d1b53f3170b2487fcf9eeea63c87d824b Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 27 Apr 2023 11:03:19 +0300 Subject: [PATCH 093/173] Fixes to OMASA mono output path and addressing VE2TP comments. --- lib_dec/ivas_dec.c | 12 ++---------- lib_dec/ivas_masa_dec.c | 35 ++++++++++++++++++++--------------- lib_dec/ivas_omasa_dec.c | 39 +++++++++++++++++++++------------------ 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 6d8ab4db78..a45fe2bb7d 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -488,17 +488,9 @@ ivas_error ivas_dec( { ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); } - else if ( st_ivas->renderer_type == RENDERER_DIRAC ) // VE2TP: please verify, it was "else if (st_ivas->hDirAC)" + else if ( st_ivas->renderer_type == RENDERER_DIRAC ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) - { - ivas_omasa_dirac_rend( st_ivas, output, output_frame ); - } - else - { - // VE2TP: please verify - this should probably never happen (ISM_MODE_NONE is renderered via "ivas_format == MASA_FORMAT" if branch) - ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport, NULL, NULL, -1 ); - } + ivas_omasa_dirac_rend( st_ivas, output, output_frame ); } } #endif diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index d559c05261..9f1c5750c3 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -308,29 +308,34 @@ ivas_error ivas_masa_decode( #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) - { - *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); - } - if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) + if ( st_ivas->hDirAC != NULL ) { - if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) - { - int16_t sf; - int16_t meta_write_index; + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); - for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) + { + if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) { - meta_write_index = ( st_ivas->hDirAC->dirac_bs_md_write_idx + sf ) % st_ivas->hDirAC->dirac_md_buffer_length; - st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; - st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; + int16_t sf; + int16_t meta_write_index; + + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + meta_write_index = ( st_ivas->hDirAC->dirac_bs_md_write_idx + sf ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; + st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; + } } } } + else + { + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + } } } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 870ba29169..c568f646c5 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -436,33 +436,36 @@ ivas_error ivas_omasa_ism_metadata_dec( return error; } - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + if (st_ivas->hDirAC != NULL ) { - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; + } + } + } + else /* ISM_MASA_MODE_MASA_ONE_OBJ */ { - azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); - elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); + azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); + elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; - st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; - st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; + st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; + st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; } } } - else /* ISM_MASA_MODE_MASA_ONE_OBJ */ - { - azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->azimuth + 0.5f ); - elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[0]->elevation + 0.5f ); - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; - st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; - st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; - } - } } return IVAS_ERR_OK; -- GitLab From bd4d275e8facc9c2e98c2d0436160a1207913276 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 27 Apr 2023 11:10:01 +0300 Subject: [PATCH 094/173] Apply clang format --- lib_dec/ivas_omasa_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index c568f646c5..4fe74fd841 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -436,7 +436,7 @@ ivas_error ivas_omasa_ism_metadata_dec( return error; } - if (st_ivas->hDirAC != NULL ) + if ( st_ivas->hDirAC != NULL ) { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { -- GitLab From 9aa8bea31b0fd3fcbcb4dc18e51e35945921ee04 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 28 Apr 2023 14:54:12 +0200 Subject: [PATCH 095/173] introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps; under FIX_OMASA_STEREO_SWITCHING --- lib_com/cnst.h | 3 ++ lib_com/ivas_cnst.h | 9 +++++- lib_com/ivas_prot.h | 3 ++ lib_com/options.h | 3 +- lib_dec/ivas_cpe_dec.c | 40 ++++++++++++++++++++++++ lib_enc/ivas_cpe_enc.c | 54 +++++++++++++++++++++++++++++++++ lib_enc/ivas_ism_enc.c | 14 +++++++-- lib_enc/ivas_ism_metadata_enc.c | 21 ++++++++++++- lib_enc/ivas_masa_enc.c | 9 ++++++ lib_enc/ivas_stat_enc.h | 6 +++- 10 files changed, 156 insertions(+), 6 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7b359e2f40..fd241c8acd 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -263,6 +263,9 @@ enum{ enum { IND_IVAS_FORMAT, +#ifdef FIX_OMASA_STEREO_SWITCHING + IND_SMODE_OMASA, +#endif IND_SMODE, IND_SID_TYPE, IND_BWIDTH, diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 2f8d004a9e..fe849fca55 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1214,10 +1214,17 @@ enum #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #ifdef MASA_AND_OBJECTS #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ + +#ifdef FIX_OMASA_STEREO_SWITCHING +#define OMASA_STEREO_SW_CNT_MAX 100 +#define OMASA_STEREO_SW_CNT_MAX2 5 +#endif + #endif #define MASA_BIT_REDUCT_PARAM 10 -#define MASA_MAXIMUM_TWO_DIR_BANDS 18 +#define MASA_MAXIMUM_TWO_DIR_BANDS 18 + typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index dd3c658455..6ca23dd915 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -837,6 +837,9 @@ ivas_error ivas_ism_metadata_enc( const int16_t ism_extended_metadata_flag /* i : Extended metadata flag */ #ifdef MASA_AND_OBJECTS ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ +#ifdef FIX_OMASA_STEREO_SWITCHING + ,int16_t *omasa_stereo_sw_cnt +#endif #endif ); diff --git a/lib_com/options.h b/lib_com/options.h index 64aab79878..1f33b8c36f 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ +#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ @@ -168,6 +168,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ +#define FIX_OMASA_STEREO_SWITCHING // VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 9667995683..714149b9aa 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -79,6 +79,9 @@ ivas_error ivas_cpe_dec( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t cpe_brate; +#ifdef FIX_OMASA_STEREO_SWITCHING + int32_t element_brate_ref; +#endif #endif error = IVAS_ERR_OK; @@ -95,10 +98,40 @@ ivas_error ivas_cpe_dec( sts[0]->BER_detect |= st_ivas->BER_detect; sts[1]->BER_detect |= st_ivas->BER_detect; +#ifdef FIX_OMASA_STEREO_SWITCHING + element_brate_ref = hCPE->element_brate; +#endif + /*------------------------------------------------------------------* * Read stereo technology info & audio bandwidth *-----------------------------------------------------------------*/ +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && + ( ( st_ivas->nchan_ism == 3 && ivas_total_brate == IVAS_96k ) || + ( st_ivas->nchan_ism == 4 && ivas_total_brate == IVAS_128k ) ) ) + { + /* read OMASA stereo mode signalling */ + if ( get_next_indice( sts[0], NBITS_ELEMENT_MODE ) ) + { + hCPE->element_mode = IVAS_CPE_MDCT; + } + else + { + hCPE->element_mode = IVAS_CPE_DFT; + } + + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + hCPE->element_brate = IVAS_64k; + hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); + } + } + } +#endif + read_stereo_mode_and_bwidth( hCPE, st_ivas ); /*----------------------------------------------------------------* @@ -551,6 +584,13 @@ ivas_error ivas_cpe_dec( hCPE->last_element_brate = hCPE->element_brate; hCPE->last_element_mode = hCPE->element_mode; +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + hCPE->element_brate = element_brate_ref; + } +#endif + if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) { stereo_cng_dec_update( hCPE, ivas_total_brate ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 5c13e032e8..c6b33d7539 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -103,6 +103,10 @@ ivas_error ivas_cpe_enc( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t cpe_brate; +#ifdef FIX_OMASA_STEREO_SWITCHING + int32_t element_brate_ref; + int16_t element_mode_ref; +#endif #endif error = IVAS_ERR_OK; @@ -117,6 +121,10 @@ ivas_error ivas_cpe_enc( ivas_format = hEncoderConfig->ivas_format; input_Fs = hEncoderConfig->input_Fs; ivas_total_brate = hEncoderConfig->ivas_total_brate; +#ifdef FIX_OMASA_STEREO_SWITCHING + element_brate_ref = hCPE->element_brate; + element_mode_ref = hCPE->element_mode; +#endif /*------------------------------------------------------------------* * Initialization - general @@ -172,6 +180,43 @@ ivas_error ivas_cpe_enc( hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && + ( ( hEncoderConfig->nchan_ism == 3 && ivas_total_brate == IVAS_96k ) || + ( hEncoderConfig->nchan_ism == 4 && ivas_total_brate == IVAS_128k ) ) ) + { + if ( hCPE->element_brate + hCPE->brate_surplus > IVAS_64k ) + { + st_ivas->hMasa->data.omasa_stereo_sw_cnt = 0; + } + else + { + st_ivas->hMasa->data.omasa_stereo_sw_cnt++; + st_ivas->hMasa->data.omasa_stereo_sw_cnt = min( st_ivas->hMasa->data.omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); + } + + if ( st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + { + hCPE->element_mode = IVAS_CPE_MDCT; + hCPE->element_brate = IVAS_64k; + hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); + } + + /* write OMASA stereo mode signalling */ + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 1, NBITS_ELEMENT_MODE ); + } + else + { + push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 0, NBITS_ELEMENT_MODE ); + } + } + } +#endif + if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; @@ -197,6 +242,7 @@ ivas_error ivas_cpe_enc( return error; } + /*----------------------------------------------------------------* * Set TD stereo parameters *----------------------------------------------------------------*/ @@ -728,6 +774,14 @@ ivas_error ivas_cpe_enc( hCPE->last_element_brate = hCPE->element_brate; hCPE->last_element_mode = hCPE->element_mode; +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( ivas_format == MASA_ISM_FORMAT ) + { + hCPE->element_brate = element_brate_ref; + } +#endif + + if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { /* update input samples buffer */ diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index b560d04f4d..35de64ab26 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -245,7 +245,12 @@ ivas_error ivas_ism_enc( { #ifdef MASA_AND_OBJECTS ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1 ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1 +#ifdef FIX_OMASA_STEREO_SWITCHING + , + NULL +#endif + ); #else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif @@ -269,7 +274,12 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 +#ifdef FIX_OMASA_STEREO_SWITCHING + , + st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL +#endif + ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 24924a25bb..922bfa5123 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -180,6 +180,10 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS , const float lp_noise_CPE +#ifdef FIX_OMASA_STEREO_SWITCHING + , + int16_t *omasa_stereo_sw_cnt +#endif #endif ) { @@ -539,7 +543,6 @@ ivas_error ivas_ism_metadata_enc( *----------------------------------------------------------------*/ if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) - { int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; int16_t brate_limit_flag; @@ -557,6 +560,22 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); } ism_metadata_flag_global = 1; + +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + brate_limit_flag = 0; + for ( int16_t n = 0; n < nchan_ism; n++ ) + { + brate_limit_flag += ism_imp[n]; + } + + if ( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) + { + *omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + } + } +#endif } #endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e12251abf7..048adbe2dc 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -185,6 +185,10 @@ ivas_error ivas_masa_enc_open( #ifdef MASA_AND_OBJECTS hMasa->data.lp_noise_CPE = -1; +#ifdef FIX_OMASA_STEREO_SWITCHING + hMasa->data.omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + hMasa->data.omasa_stereo_sw_cnt2 = OMASA_STEREO_SW_CNT_MAX2; +#endif #endif st_ivas->hMasa = hMasa; @@ -795,7 +799,12 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { +#ifdef FIX_OMASA_STEREO_SWITCHING + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) +#else + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) +#endif { st_ivas->hMasa->data.lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 80dddaf9dd..45c95b38fa 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -750,7 +750,11 @@ typedef struct ivas_masa_encoder_data_struct float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t nchan_ism; - float lp_noise_CPE; /* LP filterend total noise estimation */ + float lp_noise_CPE; /* LP filtered total noise estimation */ +#ifdef FIX_OMASA_STEREO_SWITCHING + int16_t omasa_stereo_sw_cnt; + int16_t omasa_stereo_sw_cnt2; +#endif #endif int16_t num_Cldfb_instances; -- GitLab From 437a016d83351f4fce6d037ad8e7deef00e648bf Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 2 May 2023 08:37:32 +0200 Subject: [PATCH 096/173] bugfix: ISM extended metadata -related variables need to be initialized also in OMASA --- lib_dec/ivas_init_dec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 560618b552..a1360fc985 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1051,6 +1051,9 @@ ivas_error ivas_init_decoder( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { + st_ivas->ism_extmeta_active = -1; + st_ivas->ism_extmeta_cnt = 0; + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; -- GitLab From 0badcc3496b8ab6e949efd09885ed69fcba25026 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 2 May 2023 10:23:18 +0200 Subject: [PATCH 097/173] fix global-buffer-overflow --- lib_dec/ivas_omasa_dec.c | 2 +- lib_enc/ivas_omasa_enc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 4fe74fd841..a5ba2d6ddf 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -202,7 +202,7 @@ ivas_error ivas_omasa_dec_config( ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1]; } - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, 1, 2, 0, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 8c6cd7038c..fc479d3f0b 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -245,7 +245,7 @@ ivas_error ivas_omasa_enc_config( } /* reconfigure core-coders for ISMs */ - if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, 1, 2, sep_object_brate[k - 2][st_ivas->nSCE - 1], ivas_total_brate - ism_total_brate, MC_MODE_NONE ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_corecoder_enc_reconfig( st_ivas, nSCE_old, 1, 2, st_ivas->nSCE > 0 ? sep_object_brate[k - 2][st_ivas->nSCE - 1] : 0, ivas_total_brate - ism_total_brate, MC_MODE_NONE ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 2f12af7b0113d53e2116a0f5201372f556db34c3 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 2 May 2023 10:56:35 +0200 Subject: [PATCH 098/173] update OMASA for FIX_417_TD_DECORR_BRATE_SW (fixes crash for BR switching) --- lib_dec/ivas_masa_dec.c | 43 ++++++++++++++++++++++++---------------- lib_dec/ivas_omasa_dec.c | 11 ++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a8fa913024..57dfa13fd5 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1427,31 +1427,40 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) + { +#endif + #ifdef FIX_417_TD_DECORR_BRATE_SW - /*-----------------------------------------------------------------* - * TD Decorrelator - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ - if ( st_ivas->hDiracDecBin != NULL ) - { - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { return error; } - } - /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Set-up MASA coding elements and bitrates + *-----------------------------------------------------------------*/ +#endif - if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) - { - return error; +#ifdef MASA_AND_OBJECTS } - - /*-----------------------------------------------------------------* - * Set-up MASA coding elements and bitrates - *-----------------------------------------------------------------*/ #endif #ifdef MASA_AND_OBJECTS diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index a5ba2d6ddf..a6bd23db3f 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -238,6 +238,17 @@ ivas_error ivas_omasa_dec_config( ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); +#ifdef FIX_417_TD_DECORR_BRATE_SW + /* TD Decorrelator */ + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + /* CLDFB instances */ if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { -- GitLab From e032fd5c6424b01d67dd4ecbfcb4c20f43b17210 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 2 May 2023 11:41:11 +0200 Subject: [PATCH 099/173] fix memory leaks in bitrate switching --- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 57dfa13fd5..810bd7bc09 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1428,7 +1428,7 @@ ivas_error ivas_masa_dec_reconfigure( } #ifdef MASA_AND_OBJECTS - if ( st_ivas->ivas_format != MASA_ISM_FORMAT ) + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ { #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index a6bd23db3f..b89ce05019 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -136,6 +136,7 @@ ivas_error ivas_omasa_dec_config( int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; int32_t ivas_total_brate, ism_total_brate, cpe_brate; ISM_MODE ism_mode_old; + IVAS_FORMAT ivas_format_orig; ivas_error error; /* initializations */ @@ -146,7 +147,11 @@ ivas_error ivas_omasa_dec_config( ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); st_ivas->ism_mode = ism_mode_old; + ivas_format_orig = st_ivas->ivas_format; + st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); + st_ivas->ivas_format = ivas_format_orig; + nSCE_old = st_ivas->nSCE; nchan_hp20_old = getNumChanSynthesis( st_ivas ); -- GitLab From a444b46f2e83dda49997c405f603904d126aac6f Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 3 May 2023 13:53:27 +0300 Subject: [PATCH 100/173] Fix addressing 128k quality --- lib_com/ivas_cnst.h | 6 +- lib_com/ivas_prot.h | 12 +++ lib_com/options.h | 1 + lib_dec/ivas_cpe_dec.c | 5 +- lib_dec/ivas_masa_dec.c | 8 ++ lib_dec/ivas_omasa_dec.c | 12 +++ lib_dec/ivas_stat_dec.h | 3 + lib_enc/ivas_cpe_enc.c | 5 -- lib_enc/ivas_enc.c | 78 ++++++++++++++++++-- lib_enc/ivas_init_enc.c | 1 + lib_enc/ivas_ism_enc.c | 12 +++ lib_enc/ivas_ism_metadata_enc.c | 68 ++++++++++------- lib_enc/ivas_masa_enc.c | 12 ++- lib_enc/ivas_stat_enc.h | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 +- 15 files changed, 184 insertions(+), 43 deletions(-) mode change 100755 => 100644 lib_com/ivas_prot.h mode change 100755 => 100644 lib_com/options.h diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index be34fdb477..113d7a67bd 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -318,6 +318,10 @@ typedef enum #ifdef MASA_AND_OBJECTS #define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM no meta / inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) +#ifdef OMASA_ENERGIES +#define ADJUST_ISM_BRATE_NEG 6000 +#define ADJUST_ISM_BRATE_POS 8000 +#endif #endif #define ISM_AZIMUTH_NBITS 7 @@ -1221,12 +1225,10 @@ enum #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #ifdef MASA_AND_OBJECTS #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ - #ifdef FIX_OMASA_STEREO_SWITCHING #define OMASA_STEREO_SW_CNT_MAX 100 #define OMASA_STEREO_SW_CNT_MAX2 5 #endif - #endif #define MASA_BIT_REDUCT_PARAM 10 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h old mode 100755 new mode 100644 index 21439160e0..5625fc2fb7 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -817,6 +817,10 @@ ivas_error ivas_ism_enc( float data[MAX_NUM_OBJECTS][L_FRAME48k], /* i : input signal */ const int16_t input_frame, /* i : input frame length per channel */ int16_t *nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate +#endif ); ivas_error ivas_ism_metadata_enc( @@ -837,6 +841,10 @@ ivas_error ivas_ism_metadata_enc( const int16_t ism_extended_metadata_flag /* i : Extended metadata flag */ #ifdef MASA_AND_OBJECTS ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate +#endif #ifdef FIX_OMASA_STEREO_SWITCHING ,int16_t *omasa_stereo_sw_cnt #endif @@ -4625,6 +4633,10 @@ ivas_error ivas_masa_encode( const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ const int16_t ism_imp /* i : importance of separated object */ +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate /* i: flag for using less bitrate for objects in OMASA */ +#endif #endif ); diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index c23efa7568..99627150c5 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -179,6 +179,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ +#define OMASA_ENERGIES #define FIX_OMASA_STEREO_SWITCHING // VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps #endif diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 714149b9aa..c4440417c9 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -97,6 +97,9 @@ ivas_error ivas_cpe_dec( sts[0]->BER_detect |= st_ivas->BER_detect; sts[1]->BER_detect |= st_ivas->BER_detect; +#ifdef FIX_OMASA_STEREO_SWITCHING + element_brate_ref = hCPE->element_brate; +#endif #ifdef FIX_OMASA_STEREO_SWITCHING element_brate_ref = hCPE->element_brate; @@ -105,7 +108,6 @@ ivas_error ivas_cpe_dec( /*------------------------------------------------------------------* * Read stereo technology info & audio bandwidth *-----------------------------------------------------------------*/ - #ifdef FIX_OMASA_STEREO_SWITCHING if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { @@ -131,7 +133,6 @@ ivas_error ivas_cpe_dec( } } #endif - read_stereo_mode_and_bwidth( hCPE, st_ivas ); /*----------------------------------------------------------------* diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 810bd7bc09..866a20103c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -242,6 +242,14 @@ ivas_error ivas_masa_decode( ( *nb_bits_read ) += ISM_METADATA_VAD_FLAG_BITS; } } +#ifdef OMASA_ENERGIES + st_ivas->flag_omasa_brate = 0; + if ( st_ivas->nchan_ism >= 3 && ivas_total_brate == IVAS_128k ) + { + st_ivas->flag_omasa_brate = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits_read ) += 1; + } +#endif } } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b89ce05019..92cb4336ec 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -396,6 +396,18 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[n]->element_brate = element_brate[n]; *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ); +#ifdef OMASA_ENERGIES + if ( ism_imp[n] > 1 && st_ivas->flag_omasa_brate == 1 && brate_limit_flag >= 0 ) + { + *ism_total_brate -= ADJUST_ISM_BRATE_NEG; + } + + if ( brate_limit_flag == -1 && ism_imp[n] >= 1 && st_ivas->nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) + { + *ism_total_brate += ADJUST_ISM_BRATE_POS; + } + +#endif } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index fbaedb0453..10319e4f68 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1299,6 +1299,9 @@ typedef struct Decoder_Struct int16_t index_of_edited_ism; /* Todo Nokia: Temporary, used until proper ISM control available */ int16_t azimuth_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ int16_t elevation_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ + #ifdef OMASA_ENERGIES + int16_t flag_omasa_brate; + #endif #endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index c6b33d7539..9a54cdaf5a 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -105,7 +105,6 @@ ivas_error ivas_cpe_enc( int32_t cpe_brate; #ifdef FIX_OMASA_STEREO_SWITCHING int32_t element_brate_ref; - int16_t element_mode_ref; #endif #endif @@ -123,7 +122,6 @@ ivas_error ivas_cpe_enc( ivas_total_brate = hEncoderConfig->ivas_total_brate; #ifdef FIX_OMASA_STEREO_SWITCHING element_brate_ref = hCPE->element_brate; - element_mode_ref = hCPE->element_mode; #endif /*------------------------------------------------------------------* @@ -179,7 +177,6 @@ ivas_error ivas_cpe_enc( { hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } - #ifdef FIX_OMASA_STEREO_SWITCHING if ( ivas_format == MASA_ISM_FORMAT ) { @@ -216,7 +213,6 @@ ivas_error ivas_cpe_enc( } } #endif - if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; @@ -781,7 +777,6 @@ ivas_error ivas_cpe_enc( } #endif - if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->hStereoMdct != NULL && hCPE->hStereoMdct->hItd != NULL ) { /* update input samples buffer */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 457d56a5e9..b945ac48c6 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -63,6 +63,9 @@ ivas_error ivas_enc( Encoder_State *st; /* used for bitstream handling */ #ifdef MASA_AND_OBJECTS int16_t nb_bits_metadata[MAX_SCE + 1]; +#ifdef OMASA_ENERGIES + int16_t flag_omasa_brate; +#endif #else int16_t nb_bits_metadata[MAX_SCE]; #endif @@ -89,6 +92,9 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); +#ifdef OMASA_ENERGIES + flag_omasa_brate = 0; +#endif #else set_s( nb_bits_metadata, 0, MAX_SCE ); #endif @@ -185,7 +191,12 @@ ivas_error ivas_enc( ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame ); /* Core coding of Stereo DMX */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata +#ifdef OMASA_ENERGIES + , + 0 +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -193,7 +204,12 @@ ivas_error ivas_enc( else if ( st_ivas->ism_mode == ISM_MODE_DISC ) { /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata +#ifdef OMASA_ENERGIES + , + 0 +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -245,6 +261,10 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS , ISM_MODE_NONE, -1, NULL, -1, NULL, 0 +#endif +#ifdef OMASA_ENERGIES + , + 0 #endif ) ) != IVAS_ERR_OK ) { @@ -332,15 +352,53 @@ ivas_error ivas_enc( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1] +#ifdef OMASA_ENERGIES + , + 0 +#endif + ) ) != IVAS_ERR_OK ) { return error; } } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { +#ifdef OMASA_ENERGIES + float energy_ism, energy_masa; + + energy_ism = 0.0f; + + if ( st_ivas->nSCE >= 3 && st_ivas->hEncoderConfig->ivas_total_brate == IVAS_128k ) + { + for ( i = 0; i < st_ivas->nSCE; i++ ) + { + energy_ism += sum2_f( data_f[i], input_frame ); + } + + energy_masa = 0.0f; + + for ( i = st_ivas->nSCE; i < st_ivas->nSCE + 2; i++ ) + { + energy_masa += sum2_f( data_f[i], input_frame ); + } + + energy_ism = energy_ism / ( energy_masa + 1.0f ) * 2.0f / (float) ( st_ivas->nSCE ); + flag_omasa_brate = 0; + if ( energy_ism < 1.0f ) + { + flag_omasa_brate = 1; + } + dbgwrite( &energy_ism, sizeof( float ), 1, 1, "en_ratio.bin" ); + } +#endif /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] +#ifdef OMASA_ENERGIES + , + flag_omasa_brate +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -349,7 +407,12 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp ) ) != IVAS_ERR_OK ) + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp +#ifdef OMASA_ENERGIES + , + flag_omasa_brate +#endif + ) ) != IVAS_ERR_OK ) { return error; } @@ -426,6 +489,11 @@ ivas_error ivas_enc( , ISM_MODE_NONE, -1, NULL, -1, NULL, 0 #endif +#ifdef OMASA_ENERGIES + , + 0 +#endif + ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index c2c348f19c..d17a70ea44 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -647,6 +647,7 @@ ivas_error ivas_init_encoder( return error; } + /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 35de64ab26..a8ca36ccfb 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -53,6 +53,10 @@ ivas_error ivas_ism_enc( float data[MAX_NUM_OBJECTS][L_FRAME48k], /* i : input signal */ const int16_t input_frame, /* i : input frame length per channel */ int16_t *nb_bits_metadata /* i : number of metadata bits */ +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate +#endif ) { SCE_ENC_HANDLE hSCE; @@ -246,6 +250,10 @@ ivas_error ivas_ism_enc( #ifdef MASA_AND_OBJECTS ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1 +#ifdef OMASA_ENERGIES + , + 0 +#endif #ifdef FIX_OMASA_STEREO_SWITCHING , NULL @@ -275,6 +283,10 @@ ivas_error ivas_ism_enc( ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 +#ifdef OMASA_ENERGIES + , + flag_omasa_brate +#endif #ifdef FIX_OMASA_STEREO_SWITCHING , st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 2fcffbb358..a28cc7c79b 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -185,6 +185,10 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS , const float lp_noise_CPE +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate +#endif #ifdef FIX_OMASA_STEREO_SWITCHING , int16_t *omasa_stereo_sw_cnt @@ -252,37 +256,37 @@ ivas_error ivas_ism_metadata_enc( hIsmMeta[ch]->ism_metadata_flag = localVAD[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10; #ifdef FIX_387_ISM_MD_FEC - /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ - if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) - { - if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || - ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) ) + /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - hIsmMeta[ch]->ism_metadata_flag = 1; - hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; - } - else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) - { - hIsmMeta[ch]->ism_metadata_flag = 1; - - if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || + ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) ) { - hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; } - else + else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) { - hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + hIsmMeta[ch]->ism_metadata_flag = 1; + + if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + { + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + else + { + hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + } + } + else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; } } - else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) - { - hIsmMeta[ch]->ism_metadata_flag = 1; - hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; - } - } #endif + } } - } /*----------------------------------------------------------------* * Rate importance of particular ISM streams @@ -590,7 +594,8 @@ ivas_error ivas_ism_metadata_enc( { int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; int16_t brate_limit_flag; - + int32_t ism_total_brate_ref; + ism_total_brate_ref = *ism_total_brate; brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SECOND ); @@ -602,9 +607,20 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_ism; ch++ ) { *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); +#ifdef OMASA_ENERGIES + if ( ism_imp[ch] > 1 && flag_omasa_brate == 1 && brate_limit_flag >= 0 ) + { + *ism_total_brate -= flag_omasa_brate * ADJUST_ISM_BRATE_NEG; + } + + if ( brate_limit_flag == -1 && ism_imp[ch] >= 1 && nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) + { + *ism_total_brate += ADJUST_ISM_BRATE_POS; + } + +#endif } ism_metadata_flag_global = 1; - #ifdef FIX_OMASA_STEREO_SWITCHING if ( ism_mode == ISM_MASA_MODE_DISC ) { @@ -657,7 +673,7 @@ ivas_error ivas_ism_metadata_enc( if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; - } + } else { hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 048adbe2dc..bfa5e60735 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -251,6 +251,10 @@ ivas_error ivas_masa_encode( const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ const int16_t ism_imp /* i : importance of separated object */ +#ifdef OMASA_ENERGIES + , + int16_t flag_omasa_brate /* i: flag for using less bitrate for objects in OMASA */ +#endif #endif ) { @@ -393,6 +397,13 @@ ivas_error ivas_masa_encode( hQMetaData->metadata_max_bits -= ISM_METADATA_VAD_FLAG_BITS; } } +#ifdef OMASA_ENERGIES + if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) + { + push_next_indice( hMetaData, flag_omasa_brate, 1 ); + hQMetaData->metadata_max_bits -= 1; + } +#endif } } else @@ -802,7 +813,6 @@ ivas_error ivas_masa_enc_config( #ifdef FIX_OMASA_STEREO_SWITCHING if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) #else - if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) #endif { diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 67345ab8c9..cf470e9248 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -750,7 +750,7 @@ typedef struct ivas_masa_encoder_data_struct float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t nchan_ism; - float lp_noise_CPE; /* LP filtered total noise estimation */ + float lp_noise_CPE; /* LP filterend total noise estimation */ #ifdef FIX_OMASA_STEREO_SWITCHING int16_t omasa_stereo_sw_cnt; int16_t omasa_stereo_sw_cnt2; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index a2c7b242e1..23b8f36e6b 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -52,7 +52,7 @@ * Local constants *------------------------------------------------------------------------*/ -#define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f +#define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f #ifdef FIX_417_TD_DECORR_BRATE_SW #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) #define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) -- GitLab From 73f4d59582b584ded0089fd3f21fcf6494d2254e Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 10 May 2023 10:39:53 +0200 Subject: [PATCH 101/173] bugfixes for OMASA: missing inits of ISM extended meta flags and ISM/MASA delay buffers. missing renderer reconfig in brsw. --- lib_com/options.h | 3 +- lib_dec/ivas_init_dec.c | 5 +++ lib_dec/ivas_omasa_dec.c | 85 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 99627150c5..9a1d0ae929 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -180,7 +180,8 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define OMASA_ENERGIES -#define FIX_OMASA_STEREO_SWITCHING // VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps +#define FIX_OMASA_STEREO_SWITCHING // VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps +#define FIX_OMASA_BRSW /* Nokia + VA: Fix missing init of OMASA metadata delay buffers, brsw-related init fixes */ #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9469278bb8..70d4b7a1c2 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -938,6 +938,11 @@ ivas_error ivas_init_decoder( if ( st_ivas->ivas_format == MASA_FORMAT ) { +#ifdef FIX_OMASA_BRSW + /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ + st_ivas->ism_extmeta_active = -1; + st_ivas->ism_extmeta_cnt = 0; +#endif if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 92cb4336ec..bc8bd03c5b 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -55,6 +55,9 @@ ivas_error ivas_masa_ism_data_open( { MASA_ISM_DATA_HANDLE hMasaIsmData; int16_t ch, bin; +#ifdef FIX_OMASA_BRSW + int16_t sf, obj_idx; +#endif if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) { @@ -83,6 +86,20 @@ ivas_error ivas_masa_ism_data_open( hMasaIsmData->q_azimuth_old[ch] = 0.0f; } +#ifdef FIX_OMASA_BRSW + for ( obj_idx = 0; obj_idx < MAX_NUM_OBJECTS; obj_idx++ ) + { + set_s( hMasaIsmData->azimuth_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + set_s( hMasaIsmData->elevation_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) + { + set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX ); + } + } + set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); + set_s( hMasaIsmData->elevation_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); +#endif + st_ivas->hMasaIsmData = hMasaIsmData; return IVAS_ERR_OK; @@ -139,6 +156,10 @@ ivas_error ivas_omasa_dec_config( IVAS_FORMAT ivas_format_orig; ivas_error error; +#ifdef FIX_OMASA_BRSW + RENDERER_TYPE old_renderer_type; +#endif + /* initializations */ ism_total_brate = 0; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -158,6 +179,13 @@ ivas_error ivas_omasa_dec_config( /* set ism_mode of current frame */ st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); +#ifdef FIX_OMASA_BRSW + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ + old_renderer_type = st_ivas->renderer_type; +#endif + /* MASA reconfig. */ cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ( cpe_brate < MASA_STEREO_MIN_BITRATE ) && st_ivas->nCPE == 1 ) @@ -243,6 +271,7 @@ ivas_error ivas_omasa_dec_config( ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); +#ifndef FIX_OMASA_BRSW #ifdef FIX_417_TD_DECORR_BRATE_SW /* TD Decorrelator */ if ( st_ivas->hDiracDecBin != NULL ) @@ -259,9 +288,40 @@ ivas_error ivas_omasa_dec_config( { return error; } +#endif st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; +#ifdef FIX_OMASA_BRSW + /*-----------------------------------------------------------------* + * Renderer selection + *-----------------------------------------------------------------*/ + ivas_renderer_select( st_ivas ); + + /*-------------------------------------------------------------------* + * Reallocate rendering handles + *--------------------------------------------------------------------*/ + + if ( old_renderer_type != st_ivas->renderer_type ) + { + if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( st_ivas->hMonoDmxRenderer != NULL ) + { + free( st_ivas->hMonoDmxRenderer ); + st_ivas->hMonoDmxRenderer = NULL; + } + } + } +#endif + /* objects renderer reconfig. */ if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) { @@ -331,6 +391,31 @@ ivas_error ivas_omasa_dec_config( } } } + +#ifdef FIX_OMASA_BRSW +#ifdef FIX_417_TD_DECORR_BRATE_SW + /*-----------------------------------------------------------------* + * TD Decorrelator + *-----------------------------------------------------------------*/ + + if ( st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + + /*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ + + if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } return IVAS_ERR_OK; -- GitLab From 25a7e706e98cf94ad1aa81dc7a0fa8a64c82d31d Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 10 May 2023 15:13:56 +0200 Subject: [PATCH 102/173] disable flag DEBUG_MODE_INFO --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7cc706472c..4041f922c2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -58,7 +58,7 @@ #ifdef DEBUGGING -#define DEBUG_MODE_INFO /* output most important parameters to the subdirectory "res/" */ +/*#define DEBUG_MODE_INFO*/ /* output most important parameters to the subdirectory "res/" */ #ifdef DEBUG_MODE_INFO /*#define DEBUG_MODE_ACELP*/ /* output most important ACELP core parameters to the subdirectory "res/" */ /*#define DEBUG_MODE_TCX*/ /* output most important TCX core parameters to the subdirectory "res/" */ -- GitLab From 42de1177a593842e889c6c0f27f361b1bd4d23a2 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 10 May 2023 15:24:24 +0200 Subject: [PATCH 103/173] wrap dbgwrite() within OMASA_ENERGIES under DEBUGGING flag --- lib_enc/ivas_enc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index b945ac48c6..c15e4f0bf0 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -389,7 +389,9 @@ ivas_error ivas_enc( { flag_omasa_brate = 1; } +#ifdef DEBUGGING dbgwrite( &energy_ism, sizeof( float ), 1, 1, "en_ratio.bin" ); +#endif } #endif /* Analysis, decision about bitrates per channel & core coding */ -- GitLab From 7ad5cdbf88131ca9ac70ea4e719b4193cee9e5d5 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 24 May 2023 11:14:03 +0300 Subject: [PATCH 104/173] Add back support for 1TC MASA + objects. --- lib_enc/lib_enc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 1420d8cef3..631b488626 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -389,6 +389,10 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( st_ivas->hEncoderConfig->nchan_inp = CPE_CHANNELS + numObjects; st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ break; + case IVAS_ENC_MASA_1CH: + st_ivas->hEncoderConfig->nchan_inp = 1 + numObjects; + st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */ + break; default: return IVAS_ERR_INVALID_MASA_CONFIG; break; -- GitLab From 2047a0a4d7902e1b2f9649e995191f06c46c6baf Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 24 May 2023 12:05:06 +0300 Subject: [PATCH 105/173] Wrap debug output into DEBUG_MODE_INFO switch. --- lib_enc/ivas_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index c15e4f0bf0..cd97060613 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -389,7 +389,7 @@ ivas_error ivas_enc( { flag_omasa_brate = 1; } -#ifdef DEBUGGING +#ifdef DEBUG_MODE_INFO dbgwrite( &energy_ism, sizeof( float ), 1, 1, "en_ratio.bin" ); #endif } -- GitLab From 6d61e9152a10d6b3d50df030f9b18c6aec975143 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 26 May 2023 17:49:47 +0300 Subject: [PATCH 106/173] Fixes to merge of main up to 1bfc64ea --- lib_com/ivas_prot.h | 8 +- lib_dec/ivas_dirac_dec.c | 14 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 378 ++++++++++++------- 3 files changed, 243 insertions(+), 157 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 492ebd84ae..e609305047 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5537,11 +5537,9 @@ void ivas_omasa_dirac_rend( void preProcessStereoTransportsForMovedObjects( Decoder_Struct* st_ivas, - float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - const uint8_t nBins, - const uint8_t firstSubframe, - const uint8_t nSubframes + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + const int16_t nBins ); ivas_error ivas_masa_ism_separate_object_renderer_open( diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index bcf788f3d2..c407a2b058 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2527,8 +2527,8 @@ void ivas_dirac_dec( float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; #ifdef MASA_AND_OBJECTS - float Cldfb_RealBuffer_Temp[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ - float Cldfb_ImagBuffer_Temp[2][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ + float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ + float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ #endif int16_t index, num_freq_bands; @@ -2718,8 +2718,8 @@ void ivas_dirac_dec( for ( ch = 0; ch < nchan_transport; ch++ ) { cldfbAnalysis_ts( &( output_f[sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), - Cldfb_RealBuffer_Temp[ch][index_slot], - Cldfb_ImagBuffer_Temp[ch][index_slot], + Cldfb_RealBuffer_Temp[ch][slot_idx], + Cldfb_ImagBuffer_Temp[ch][slot_idx], hDirAC->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); } @@ -2727,7 +2727,7 @@ void ivas_dirac_dec( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { - preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, (uint8_t) ( hDirAC->num_freq_bands ), (uint8_t) subframe_idx, 1 ); + preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, (uint8_t) ( hDirAC->num_freq_bands ) ); } } #endif @@ -2749,8 +2749,8 @@ void ivas_dirac_dec( { for ( ch = 0; ch < nchan_transport; ch++ ) { - mvr2r( Cldfb_RealBuffer_Temp[ch][index_slot], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands ); - mvr2r( Cldfb_ImagBuffer_Temp[ch][index_slot], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); + mvr2r( Cldfb_RealBuffer_Temp[ch][slot_idx], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands ); + mvr2r( Cldfb_ImagBuffer_Temp[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); } } #endif diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c58326d884..38a9374f10 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -498,8 +498,13 @@ static void ivas_dirac_dec_binaural_internal( { DIRAC_DEC_HANDLE hDirAC; int16_t slot, ch, numInChannels; +#ifdef MASA_AND_OBJECTS + float Cldfb_RealBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#else float Cldfb_RealBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#endif float Rmat[3][3]; int16_t max_band_decorr; DIFFUSE_DISTRIBUTION_DATA diffuseDistData; @@ -511,10 +516,21 @@ static void ivas_dirac_dec_binaural_internal( /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + { + numInChannels++; + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + numInChannels += (uint8_t) st_ivas->nchan_ism; + } +#else if ( st_ivas->hOutSetup.separateChannelEnabled ) { numInChannels++; } +#endif Rmat[0][0] = 1.0f; Rmat[0][1] = 0.0f; @@ -634,6 +650,13 @@ static void ivas_dirac_dec_binaural_internal( ivas_sba_prototype_renderer( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) + { + preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins ); + } +#endif + if ( st_ivas->hHeadTrackData && st_ivas->hHeadTrackData->num_quaternions >= 0 ) { QuatToRotMat( st_ivas->hHeadTrackData->Quaternions[subframe], Rmat ); @@ -1063,6 +1086,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric for ( bin = 0; bin < nBins; bin++ ) { float diffuseness = 1.0f; /* ratio1 and ratio2 are subtracted from diffuseness further below */ +#ifdef MASA_AND_OBJECTS + float diffusenessValForDecorrelationReduction = 1.0f; + float diffEneValForDecorrelationReduction; +#endif float surCoh = 0.0f, spreadCoh = 0.0f; /* Default values if spreadSurroundCoherenceApplied == false */ float diffEne, dirEne, meanEnePerCh; int16_t dirIndex; @@ -1081,6 +1108,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric float lRealp, lImagp, rRealp, rImagp; float lRealpTmp, lImagpTmp, rRealpTmp, rImagpTmp; float hrtfEne[BINAURAL_CHANNELS], hrtfCrossRe, hrtfCrossIm, ratio; +#ifdef MASA_AND_OBJECTS + uint8_t isIsmDirection = 0; +#endif if ( dirIndex == 0 ) /* For first of the two simultaneous directions */ { @@ -1089,15 +1119,55 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric ratio = hDirAC->energy_ratio1[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence[dirac_read_idx][bin]; } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format != MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_ISM_FORMAT && dirIndex < hDirAC->numParametricDirections ) ) /* For second of the two simultaneous directions */ +#else else /* For second of the two simultaneous directions */ +#endif { aziDeg = hDirAC->azimuth2[dirac_read_idx][bin]; eleDeg = hDirAC->elevation2[dirac_read_idx][bin]; ratio = hDirAC->energy_ratio2[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence2[dirac_read_idx][bin]; } +#ifdef MASA_AND_OBJECTS + else /* For object directions of MASA_ISM_FORMAT */ + { + isIsmDirection = 1; + uint16_t ismDirIndex; + ismDirIndex = dirIndex - hDirAC->numParametricDirections; + if ( st_ivas->hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + aziDeg = st_ivas->hMasaIsmData->azimuth_ism_edited[ismDirIndex]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism_edited[ismDirIndex]; + } + else + { + aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx]; + eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx]; + } + ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; + spreadCoh = 0.0f; + } +#endif diffuseness -= ratio; /* diffuseness = 1 - ratio1 - ratio2 */ +#ifdef MASA_AND_OBJECTS + if ( diffuseness < 0.0f ) + { + diffuseness = 0.0f; + } + if ( isIsmDirection ) + { + /* Objects cause lesser decorrelation reduction, to avoid removing all decorrelation when only objects are present */ + diffusenessValForDecorrelationReduction -= ratio * 0.5f; + } + else + { + diffusenessValForDecorrelationReduction -= ratio; + } +#endif + if ( separateCenterChannelRendering ) { /* In masa + mono rendering mode, the center directions originate from phantom sources, so the @@ -1233,13 +1303,32 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric diffuseness = max( 0.0f, diffuseness ); diffEne = diffuseness * meanEnePerCh; surCoh = hDirAC->surroundingCoherence[dirac_read_idx][bin]; + +#ifdef MASA_AND_OBJECTS + diffusenessValForDecorrelationReduction = max( 0.0f, diffusenessValForDecorrelationReduction ); + diffEneValForDecorrelationReduction = diffusenessValForDecorrelationReduction * meanEnePerCh; +#endif + if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { if ( !h->renderStereoOutputInsteadOfBinaural ) { +#ifdef MASA_AND_OBJECTS + float spectrumModVal; + + idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); + /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ + spectrumModVal = ( 1.0f - surCoh ) + surCoh * surCohEne[idx]; + diffEne *= spectrumModVal; +#else idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ diffEne *= ( 1.0f - surCoh ) + surCoh * surCohEne[idx]; +#endif +#ifdef MASA_AND_OBJECTS + /* Modify also the value for decorrelation reduction */ + diffEneValForDecorrelationReduction *= spectrumModVal; +#endif } } h->ChEneOut[0][bin] += diffEne; /* Diff ene part*/ @@ -1265,7 +1354,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } /* Store parameters for formulating average diffuseness over frame */ +#ifdef MASA_AND_OBJECTS + h->frameMeanDiffuseness[bin] += diffEneValForDecorrelationReduction; +#else h->frameMeanDiffuseness[bin] += diffEne; +#endif frameMeanDiffusenessEneWeight[bin] += meanEnePerCh; } @@ -2048,7 +2141,6 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( } } #else - gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { @@ -3194,13 +3286,12 @@ static void preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, - float inRe[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - float inIm[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], - const uint8_t nBins, - const uint8_t firstSubframe, - const uint8_t nSubframes ) + float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + const int16_t nBins +) { - int16_t subframe, bin, ch, inCh, outCh, ismDirIndex, slot; + int16_t bin, ch, inCh, outCh, ismDirIndex, slot; DIRAC_DEC_HANDLE hDirAC; MASA_ISM_DATA_HANDLE hMasaIsmData; uint8_t enableCentering; @@ -3236,176 +3327,173 @@ void preProcessStereoTransportsForMovedObjects( } /* Perform object-movement based processing */ - for ( subframe = firstSubframe; subframe < ( firstSubframe + nSubframes ); subframe++ ) - { - dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; + dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; - for ( bin = 0; bin < nBins; bin++ ) + for ( bin = 0; bin < nBins; bin++ ) + { + float ismPreprocMtxNew[2][2]; + float ismPreprocMtxIncrement[2][2]; + float eneMove[2]; + float enePreserve[2]; + float ismRatioAcc; + float subframeEne; + float normEnes[2]; + float remainderNormEne; + + set_zero( ismPreprocMtxNew[0], 2 ); + set_zero( ismPreprocMtxNew[1], 2 ); + set_zero( ismPreprocMtxIncrement[0], 2 ); + set_zero( ismPreprocMtxIncrement[1], 2 ); + set_zero( eneMove, 2 ); + set_zero( enePreserve, 2 ); + ismRatioAcc = 0.0f; + subframeEne = 0.0f; + set_zero( normEnes, 2 ); + + /* Determine transport normalized energies and subframe energy */ + for ( slot = 0; slot < hDirAC->subframe_nbslots; slot++ ) { - float ismPreprocMtxNew[2][2]; - float ismPreprocMtxIncrement[2][2]; - float eneMove[2]; - float enePreserve[2]; - float ismRatioAcc; - float subframeEne; - float normEnes[2]; - float remainderNormEne; - - set_zero( ismPreprocMtxNew[0], 2 ); - set_zero( ismPreprocMtxNew[1], 2 ); - set_zero( ismPreprocMtxIncrement[0], 2 ); - set_zero( ismPreprocMtxIncrement[1], 2 ); - set_zero( eneMove, 2 ); - set_zero( enePreserve, 2 ); - ismRatioAcc = 0.0f; - subframeEne = 0.0f; - set_zero( normEnes, 2 ); - - /* Determine transport normalized energies and subframe energy */ - for ( slot = subframe * hDirAC->subframe_nbslots; slot < (int16_t) ( ( subframe + 1 ) * hDirAC->subframe_nbslots ); slot++ ) + for ( ch = 0; ch < 2; ch++ ) { - for ( ch = 0; ch < 2; ch++ ) - { - normEnes[ch] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; - normEnes[ch] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; - } + normEnes[ch] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; + normEnes[ch] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; } - subframeEne = normEnes[0] + normEnes[1]; - normEnes[0] /= fmaxf( 1e-12f, subframeEne ); - normEnes[1] /= fmaxf( 1e-12f, subframeEne ); - - /* For each ismDir, formulate a mix-matrix that moves object audio signals between - * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ - for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) - { - float panGainsOut[2]; - float panGainsIn[2]; - float ratio; - float panEnesOut[2]; - float panEnesIn[2]; - float centeringFactor; + } + subframeEne = normEnes[0] + normEnes[1]; + normEnes[0] /= fmaxf( 1e-12f, subframeEne ); + normEnes[1] /= fmaxf( 1e-12f, subframeEne ); - ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; + /* For each ismDir, formulate a mix-matrix that moves object audio signals between + * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ + for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) + { + float panGainsOut[2]; + float panGainsIn[2]; + float ratio; + float panEnesOut[2]; + float panEnesIn[2]; + float centeringFactor; - ismRatioAcc += ratio; + ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; - /* Get input and output panning gains */ - ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], - hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], - panGainsIn ); + ismRatioAcc += ratio; - if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) - { - ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism_edited[ismDirIndex], - hMasaIsmData->elevation_ism_edited[ismDirIndex], - panGainsOut ); - } - else - { - /* When not edited, input and output pan gains are the same */ - for ( ch = 0; ch < 2; ch++ ) - { - panGainsOut[ch] = panGainsIn[ch]; - } - } + /* Get input and output panning gains */ + ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], + hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], + panGainsIn ); - /* Determine pan enes */ + if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + ivas_get_stereo_panning_gains( hMasaIsmData->azimuth_ism_edited[ismDirIndex], + hMasaIsmData->elevation_ism_edited[ismDirIndex], + panGainsOut ); + } + else + { + /* When not edited, input and output pan gains are the same */ for ( ch = 0; ch < 2; ch++ ) { - panEnesOut[ch] = panGainsOut[ch] * panGainsOut[ch]; - panEnesIn[ch] = panGainsIn[ch] * panGainsIn[ch]; + panGainsOut[ch] = panGainsIn[ch]; } + } - if ( enableCentering ) - { - centeringFactor = fmaxf( 0.0f, 2.0f * fabsf( panEnesIn[0] - panEnesOut[0] ) - 1.0f ); - for ( ch = 0; ch < 2; ch++ ) - { - panEnesOut[ch] *= ( 1.0f - centeringFactor ); - panEnesOut[ch] += 0.5f * centeringFactor; - } - } + /* Determine pan enes */ + for ( ch = 0; ch < 2; ch++ ) + { + panEnesOut[ch] = panGainsOut[ch] * panGainsOut[ch]; + panEnesIn[ch] = panGainsIn[ch] * panGainsIn[ch]; + } + if ( enableCentering ) + { + centeringFactor = fmaxf( 0.0f, 2.0f * fabsf( panEnesIn[0] - panEnesOut[0] ) - 1.0f ); for ( ch = 0; ch < 2; ch++ ) { - float eneMoveThis; - float enePreserveThis; - eneMoveThis = fmaxf( 0.0f, panEnesIn[ch] - panEnesOut[ch] ); - enePreserveThis = panEnesIn[ch] - eneMoveThis; - - eneMove[ch] += ratio * eneMoveThis; - enePreserve[ch] += ratio * enePreserveThis; - - /* Subtract object parts from normEnes */ - normEnes[ch] -= panEnesIn[ch] * ratio; + panEnesOut[ch] *= ( 1.0f - centeringFactor ); + panEnesOut[ch] += 0.5f * centeringFactor; } } - /* Any remaining (non-object) energy is set to be preserved at both channels */ - remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); for ( ch = 0; ch < 2; ch++ ) { - enePreserve[ch] += fmaxf( 0.0f, normEnes[ch] + remainderNormEne / 2.0f ); - } + float eneMoveThis; + float enePreserveThis; + eneMoveThis = fmaxf( 0.0f, panEnesIn[ch] - panEnesOut[ch] ); + enePreserveThis = panEnesIn[ch] - eneMoveThis; - /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix */ - for ( ch = 0; ch < 2; ch++ ) - { - float normVal; - hMasaIsmData->eneMoveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; - hMasaIsmData->eneMoveIIR[ch][bin] += eneMove[ch] * subframeEne; - hMasaIsmData->enePreserveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; - hMasaIsmData->enePreserveIIR[ch][bin] += enePreserve[ch] * subframeEne; - normVal = fmaxf( EPSILON, hMasaIsmData->eneMoveIIR[ch][bin] + hMasaIsmData->enePreserveIIR[ch][bin] ); - ismPreprocMtxNew[ch][ch] = sqrtf( hMasaIsmData->enePreserveIIR[ch][bin] / normVal ); - ismPreprocMtxNew[1 - ch][ch] = sqrtf( hMasaIsmData->eneMoveIIR[ch][bin] / normVal ); + eneMove[ch] += ratio * eneMoveThis; + enePreserve[ch] += ratio * enePreserveThis; + + /* Subtract object parts from normEnes */ + normEnes[ch] -= panEnesIn[ch] * ratio; } + } + + /* Any remaining (non-object) energy is set to be preserved at both channels */ + remainderNormEne = fmaxf( 0.0f, ( 1.0f - ismRatioAcc ) - normEnes[0] - normEnes[1] ); + for ( ch = 0; ch < 2; ch++ ) + { + enePreserve[ch] += fmaxf( 0.0f, normEnes[ch] + remainderNormEne / 2.0f ); + } + + /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix */ + for ( ch = 0; ch < 2; ch++ ) + { + float normVal; + hMasaIsmData->eneMoveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->eneMoveIIR[ch][bin] += eneMove[ch] * subframeEne; + hMasaIsmData->enePreserveIIR[ch][bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->enePreserveIIR[ch][bin] += enePreserve[ch] * subframeEne; + normVal = fmaxf( EPSILON, hMasaIsmData->eneMoveIIR[ch][bin] + hMasaIsmData->enePreserveIIR[ch][bin] ); + ismPreprocMtxNew[ch][ch] = sqrtf( hMasaIsmData->enePreserveIIR[ch][bin] / normVal ); + ismPreprocMtxNew[1 - ch][ch] = sqrtf( hMasaIsmData->eneMoveIIR[ch][bin] / normVal ); + } - /* Get increment value for temporal interpolation */ - for ( inCh = 0; inCh < 2; inCh++ ) + /* Get increment value for temporal interpolation */ + for ( inCh = 0; inCh < 2; inCh++ ) + { + for ( outCh = 0; outCh < 2; outCh++ ) { - for ( outCh = 0; outCh < 2; outCh++ ) - { - ismPreprocMtxIncrement[outCh][inCh] = ( ismPreprocMtxNew[outCh][inCh] - hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] ) / (float) hDirAC->subframe_nbslots; - } + ismPreprocMtxIncrement[outCh][inCh] = ( ismPreprocMtxNew[outCh][inCh] - hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] ) / (float) hDirAC->subframe_nbslots; } + } - /* Mix signals */ - for ( slot = subframe * hDirAC->subframe_nbslots; slot < (int16_t) ( ( subframe + 1 ) * hDirAC->subframe_nbslots ); slot++ ) - { - float eqVal; - float outSlotRe[2]; - float outSlotIm[2]; + /* Mix signals */ + for ( slot = 0; slot < hDirAC->subframe_nbslots; slot++ ) + { + float eqVal; + float outSlotRe[2]; + float outSlotIm[2]; - set_zero( outSlotRe, 2 ); - set_zero( outSlotIm, 2 ); + set_zero( outSlotRe, 2 ); + set_zero( outSlotIm, 2 ); - for ( outCh = 0; outCh < 2; outCh++ ) + for ( outCh = 0; outCh < 2; outCh++ ) + { + for ( inCh = 0; inCh < 2; inCh++ ) { - for ( inCh = 0; inCh < 2; inCh++ ) - { - hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] += ismPreprocMtxIncrement[outCh][inCh]; - outSlotRe[outCh] += inRe[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; - outSlotIm[outCh] += inIm[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; - } + hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin] += ismPreprocMtxIncrement[outCh][inCh]; + outSlotRe[outCh] += inRe[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; + outSlotIm[outCh] += inIm[inCh][slot][bin] * hMasaIsmData->ismPreprocMatrix[outCh][inCh][bin]; } + } - /* IIR average the energy measures and determine and apply energy-preserving equalizer */ - hMasaIsmData->preprocEneTarget[bin] *= STEREO_PREPROCESS_IIR_FACTOR; - hMasaIsmData->preprocEneRealized[bin] *= STEREO_PREPROCESS_IIR_FACTOR; - for ( ch = 0; ch < 2; ch++ ) - { - hMasaIsmData->preprocEneTarget[bin] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; - hMasaIsmData->preprocEneTarget[bin] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; - hMasaIsmData->preprocEneRealized[bin] += outSlotRe[ch] * outSlotRe[ch]; - hMasaIsmData->preprocEneRealized[bin] += outSlotIm[ch] * outSlotIm[ch]; - } - eqVal = fminf( 4.0f, sqrtf( hMasaIsmData->preprocEneTarget[bin] / fmaxf( 1e-12f, hMasaIsmData->preprocEneRealized[bin] ) ) ); - for ( ch = 0; ch < 2; ch++ ) - { - inRe[ch][slot][bin] = outSlotRe[ch] * eqVal; - inIm[ch][slot][bin] = outSlotIm[ch] * eqVal; - } + /* IIR average the energy measures and determine and apply energy-preserving equalizer */ + hMasaIsmData->preprocEneTarget[bin] *= STEREO_PREPROCESS_IIR_FACTOR; + hMasaIsmData->preprocEneRealized[bin] *= STEREO_PREPROCESS_IIR_FACTOR; + for ( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->preprocEneTarget[bin] += inRe[ch][slot][bin] * inRe[ch][slot][bin]; + hMasaIsmData->preprocEneTarget[bin] += inIm[ch][slot][bin] * inIm[ch][slot][bin]; + hMasaIsmData->preprocEneRealized[bin] += outSlotRe[ch] * outSlotRe[ch]; + hMasaIsmData->preprocEneRealized[bin] += outSlotIm[ch] * outSlotIm[ch]; + } + eqVal = fminf( 4.0f, sqrtf( hMasaIsmData->preprocEneTarget[bin] / fmaxf( 1e-12f, hMasaIsmData->preprocEneRealized[bin] ) ) ); + for ( ch = 0; ch < 2; ch++ ) + { + inRe[ch][slot][bin] = outSlotRe[ch] * eqVal; + inIm[ch][slot][bin] = outSlotIm[ch] * eqVal; } } } -- GitLab From 5afac642d22859ed963afad1a48ec93d10b38add Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 12 Jun 2023 11:05:49 +0200 Subject: [PATCH 107/173] fixes for support of IND_LIST_DYN + activate IND_LIST_DYN --- lib_com/bitstream.c | 86 ++++++++++++++++++++++++++++++++++++++++ lib_com/options.h | 4 +- lib_enc/ivas_enc.c | 13 ++++++ lib_enc/ivas_init_enc.c | 5 ++- lib_enc/ivas_omasa_enc.c | 16 +++++++- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index aa46c531d1..5ac1b602ba 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -462,6 +462,47 @@ int16_t get_ivas_max_num_indices( /* o : maximum return 1650; } } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_ISM_FORMAT ) + { + if ( ivas_total_brate <= IVAS_16k4 ) + { + return 300; + } + else if ( ivas_total_brate <= IVAS_32k ) + { + return 400; + } + else if ( ivas_total_brate <= IVAS_48k ) + { + return 650; + } + else if ( ivas_total_brate <= IVAS_80k ) + { + return 750; + } + else if ( ivas_total_brate <= IVAS_160k ) + { + return 850; + } + else if ( ivas_total_brate <= IVAS_192k ) + { + return 950; + } + else if ( ivas_total_brate <= IVAS_256k ) + { + return 1150; + } + else if ( ivas_total_brate <= IVAS_384k ) + { + return 1450; + } + else + { + return 1650; + } + } +#endif else if ( ivas_format == MC_FORMAT ) { if ( ivas_total_brate <= IVAS_16k4 ) @@ -862,6 +903,51 @@ int16_t get_ivas_max_num_indices_metadata( /* o #endif } } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_ISM_FORMAT ) + { + if ( ivas_total_brate <= IVAS_16k4 ) + { + return 80; + } + else if ( ivas_total_brate <= IVAS_32k ) + { + return 125 + 100; + } + else if ( ivas_total_brate <= IVAS_48k ) + { + return 205 + 100; + } + else if ( ivas_total_brate <= IVAS_96k ) + { + return 240 + 100; + } + else if ( ivas_total_brate <= IVAS_128k ) + { + return 305 + 30; + } + else if ( ivas_total_brate <= IVAS_160k ) + { + return 425 + 30; + } + else if ( ivas_total_brate <= IVAS_192k ) + { + return 630 + 30; + } + else if ( ivas_total_brate <= IVAS_256k ) + { + return 850 + 30; + } + else if ( ivas_total_brate <= IVAS_384k ) + { + return 1000 + 30; + } + else + { + return 1750 + 30; + } + } +#endif else if ( ivas_format == MC_FORMAT ) { if ( ivas_total_brate <= IVAS_13k2 ) diff --git a/lib_com/options.h b/lib_com/options.h index ab71c50837..7fa5e09a70 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -134,8 +134,8 @@ /* ################# Start DEVELOPMENT switches ######################## */ #define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ -/* Todo OMASA: This needs to be implemented for OMASA */ -/*#define IND_LIST_DYN */ /* VA: Issue 18: Dynamic allocation of ind_list[] and ind_list_metadata[] based on # of transport channels */ + +#define IND_LIST_DYN /* VA: Issue 18: Dynamic allocation of ind_list[] and ind_list_metadata[] based on # of transport channels */ #ifndef IND_LIST_DYN #define BITSTREAM_INDICES_MEMORY /* Don't count memory for bitstream Indice at the encoder - it is a temporary solution for development only */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index ce7d6d764a..4cf4018cb6 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -319,7 +319,9 @@ ivas_error ivas_enc( return error; } +#ifndef IND_LIST_DYN hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; +#endif /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) @@ -407,6 +409,17 @@ ivas_error ivas_enc( n = st_ivas->hEncoderConfig->nchan_ism; } +#ifdef IND_LIST_DYN + hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData; + + if ( st_ivas->nSCE > 0 ) + { + /* update pointer to the buffer of indices (ISM indices were alredy written) */ + hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot; + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot; + } +#endif + /* Encode MASA parameters and write MASA metadata bitstream */ if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2900d3e143..7e9f349e1d 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -661,12 +661,14 @@ ivas_error ivas_init_encoder( return error; } +#ifndef IND_LIST_DYN /* prepare bitstream buffers */ st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list[sce_id]; reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata[sce_id]; reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); +#endif } if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) @@ -706,7 +708,7 @@ ivas_error ivas_init_encoder( return error; } - +#ifndef IND_LIST_DYN /* prepare bitstream buffers */ for ( n = 0; n < CPE_CHANNELS; n++ ) { @@ -716,6 +718,7 @@ ivas_error ivas_init_encoder( st_ivas->hCPE[0]->hMetaData->ind_list = ind_list_metadata[st_ivas->nSCE]; reset_indices_enc( st_ivas->hCPE[0]->hMetaData, MAX_BITS_METADATA ); +#endif } #endif else if ( ivas_format == MC_FORMAT ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 03055d56cb..46b7c0418b 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -253,11 +253,23 @@ ivas_error ivas_omasa_enc_config( /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ if ( st_ivas->nSCE > 0 ) { - reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->next_ind ); + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, +#ifdef IND_LIST_DYN + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot +#else + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->next_ind +#endif + ); } else { - reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->next_ind ); + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, +#ifdef IND_LIST_DYN + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot +#else + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->next_ind +#endif + ); } ivas_write_format( st_ivas ); -- GitLab From 3b64b06c035bc2a0607456ced088a7b5b62e1fee Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 13 Jun 2023 11:23:59 +0300 Subject: [PATCH 108/173] Fix build with switch MASA_AND_OBJECTS inactive --- lib_dec/ivas_ism_metadata_dec.c | 1 + lib_dec/ivas_masa_dec.c | 6 +++++- lib_enc/ivas_masa_enc.c | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 4b154a22cd..8be626576b 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -174,6 +174,7 @@ ivas_error ivas_ism_metadata_dec( int16_t md_diff_flag[MAX_NUM_OBJECTS]; ivas_error error; + push_wmops( "ism_meta_dec" ); diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6c0606de0f..310781c0c7 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -814,7 +814,11 @@ static ivas_error ivas_masa_dec_config( ivas_masa_set_coding_config(&(hMasa->config), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA)); #endif #ifdef HR_METADATA - if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k ) +#ifdef MASA_AND_OBJECTS + if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k ) +#else + if ((st_ivas->ivas_format == MASA_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k) +#endif { hMasa->config.mergeRatiosOverSubframes = 0; /* initialize spherical grid */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 4e2670ff9f..6db0dd1a0c 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -317,7 +317,11 @@ ivas_error ivas_masa_encode( } #ifdef HR_METADATA +#ifdef MASA_AND_OBJECTS if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ivas_total_brate >= IVAS_384k ) +#else + if ( (ivas_format == MASA_FORMAT) && ivas_total_brate >= IVAS_384k ) +#endif { hMasa->config.mergeRatiosOverSubframes = 0; } -- GitLab From 7f6cdce89e8c43b9927cb3279553c5d726b3c94f Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 13 Jun 2023 11:58:41 +0300 Subject: [PATCH 109/173] Fix DIRAC_MAX_ANA_CHANS to FOA_CHANNELS within OMASA. --- lib_enc/ivas_omasa_enc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 46b7c0418b..00f61fca4a 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -56,9 +56,9 @@ static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCOD static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_transport, const int16_t nchan_ism, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ); -static void computeIntensityVector_enc( const int16_t *band_grouping, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ); +static void computeIntensityVector_enc( const int16_t *band_grouping, float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ); -static void computeReferencePower_omasa( const int16_t *band_grouping, float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], float *reference_power, const int16_t enc_param_start_band, const int16_t num_freq_bands ); +static void computeReferencePower_omasa( const int16_t *band_grouping, float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], float *reference_power, const int16_t enc_param_start_band, const int16_t num_freq_bands ); /*--------------------------------------------------------------------------* @@ -753,8 +753,8 @@ static void ivas_omasa_param_est_enc( int16_t l_ts; float Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; float Chnl_ImagBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; - float Foa_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; - float Foa_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Foa_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float Foa_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; float diffuseness_vector[MASA_FREQUENCY_BANDS]; @@ -1057,8 +1057,8 @@ static void ivas_omasa_dmx( static void computeIntensityVector_enc( const int16_t *band_grouping, - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], + float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] ) { @@ -1095,8 +1095,8 @@ static void computeIntensityVector_enc( static void computeReferencePower_omasa( const int16_t *band_grouping, /* i : Band grouping for estimation */ - float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ + float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ + float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ float *reference_power, /* o : Estimated power */ const int16_t enc_param_start_band, /* i : first band to process */ const int16_t num_freq_bands /* i : Number of frequency bands */ @@ -1111,7 +1111,7 @@ static void computeReferencePower_omasa( brange[1] = band_grouping[i + enc_param_start_band + 1]; reference_power[i] = 0; - for ( ch_idx = 0; ch_idx < DIRAC_MAX_ANA_CHANS; ch_idx++ ) + for ( ch_idx = 0; ch_idx < FOA_CHANNELS; ch_idx++ ) { /* abs()^2 */ for ( j = brange[0]; j < brange[1]; j++ ) -- GitLab From 39836d9722636edf23dbb48647054b5e4ffe6044 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 11:18:52 +0200 Subject: [PATCH 110/173] fix crash in bitrate switching --- lib_enc/ivas_omasa_enc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 00f61fca4a..24d1cfe140 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -265,7 +265,7 @@ ivas_error ivas_omasa_enc_config( { reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, #ifdef IND_LIST_DYN - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot + st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot #else st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->next_ind #endif @@ -1094,12 +1094,12 @@ static void computeIntensityVector_enc( static void computeReferencePower_omasa( - const int16_t *band_grouping, /* i : Band grouping for estimation */ + const int16_t *band_grouping, /* i : Band grouping for estimation */ float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - float *reference_power, /* o : Estimated power */ - const int16_t enc_param_start_band, /* i : first band to process */ - const int16_t num_freq_bands /* i : Number of frequency bands */ + float *reference_power, /* o : Estimated power */ + const int16_t enc_param_start_band, /* i : first band to process */ + const int16_t num_freq_bands /* i : Number of frequency bands */ ) { int16_t brange[2]; -- GitLab From e380832aff0c2fda4b0341138715018a6bfc5baa Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 11:23:26 +0200 Subject: [PATCH 111/173] clang-format --- lib_dec/ivas_dirac_dec.c | 8 ++-- lib_dec/ivas_masa_dec.c | 44 ++++++++++---------- lib_enc/ivas_ism_metadata_enc.c | 4 +- lib_enc/ivas_masa_enc.c | 4 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 3 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index fbdd9f76f5..4796b15788 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3784,7 +3784,7 @@ static void initDiffuseResponses( #ifdef MASA_AND_OBJECTS else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) #else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) #endif { mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); @@ -3792,7 +3792,7 @@ static void initDiffuseResponses( #ifdef MASA_AND_OBJECTS else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_2 ) && ( num_channels == 7 ) ) #else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) #endif { mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); @@ -3800,7 +3800,7 @@ static void initDiffuseResponses( #ifdef MASA_AND_OBJECTS else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) #else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) #endif { mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); @@ -3808,7 +3808,7 @@ static void initDiffuseResponses( #ifdef MASA_AND_OBJECTS else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) #else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) #endif { if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 310781c0c7..633e4edfb2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -314,25 +314,25 @@ ivas_error ivas_masa_decode( /* Remove already read bits from the bit budget */ hQMetaData->metadata_max_bits -= *nb_bits_read; #ifdef MASA_AND_OBJECTS - if (st_ivas->ivas_format == MASA_ISM_FORMAT) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - if (st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ) + if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - if (st_ivas->hDirAC != NULL) + if ( st_ivas->hDirAC != NULL ) { - *nb_bits_read += ivas_decode_masaism_metadata(hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length); + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); - for (obj = 0; obj <= st_ivas->nchan_ism; obj++) + for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { - if (st_ivas->hMasaIsmData->idx_separated_ism == obj) + if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) { int16_t sf; int16_t meta_write_index; - for (sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - meta_write_index = (st_ivas->hDirAC->dirac_bs_md_write_idx + sf) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( st_ivas->hDirAC->dirac_bs_md_write_idx + sf ) % st_ivas->hDirAC->dirac_md_buffer_length; st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; } @@ -341,8 +341,8 @@ ivas_error ivas_masa_decode( } else { - *nb_bits_read += ivas_decode_masaism_metadata(hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES); + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); } } } @@ -392,10 +392,10 @@ ivas_error ivas_masa_decode( #endif #ifdef MASA_AND_OBJECTS - if (st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ - modify_masa_energy_ratios(hQMetaData); + modify_masa_energy_ratios( hQMetaData ); } #endif @@ -791,33 +791,33 @@ static ivas_error ivas_masa_dec_config( #ifdef MASA_AND_OBJECTS ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; ism_total_brate = 0; - if (st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && (st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ)) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) { - for (i = 0; i < st_ivas->nSCE; i++) + for ( i = 0; i < st_ivas->nSCE; i++ ) { ism_total_brate += st_ivas->hSCE[i]->element_brate; } } - ivas_masa_set_elements(ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate); + ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); - if (st_ivas->ivas_format == MASA_ISM_FORMAT) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - ivas_masa_set_coding_config(&(hMasa->config), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } else { - ivas_masa_set_coding_config(&(hMasa->config), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA)); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } #else - ivas_masa_set_elements(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE); - ivas_masa_set_coding_config(&(hMasa->config), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, (st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA)); + ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); #endif #ifdef HR_METADATA #ifdef MASA_AND_OBJECTS if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k ) #else - if ((st_ivas->ivas_format == MASA_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k) + if ( ( st_ivas->ivas_format == MASA_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_512k ) #endif { hMasa->config.mergeRatiosOverSubframes = 0; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 457ba7bbd4..734a0cbd14 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -252,7 +252,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC ) #else - else if ( ism_mode == ISM_MODE_DISC ) + else if ( ism_mode == ISM_MODE_DISC ) #endif { if ( hIsmMeta[ch]->ism_metadata_flag == 1 ) @@ -897,7 +897,7 @@ ivas_error ivas_ism_metadata_enc_create( } else { - if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, nchan_transport, n_ISms, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6db0dd1a0c..5260e097dc 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -69,7 +69,7 @@ static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_H static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #endif -static void average_masa_metadata(MASA_METADATA_FRAME* masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] +static void average_masa_metadata( MASA_METADATA_FRAME *masaMetadata, float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] #ifdef HR_METADATA , const SPHERICAL_GRID_DATA *sphGrid @@ -320,7 +320,7 @@ ivas_error ivas_masa_encode( #ifdef MASA_AND_OBJECTS if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ivas_total_brate >= IVAS_384k ) #else - if ( (ivas_format == MASA_FORMAT) && ivas_total_brate >= IVAS_384k ) + if ( ( ivas_format == MASA_FORMAT ) && ivas_total_brate >= IVAS_384k ) #endif { hMasa->config.mergeRatiosOverSubframes = 0; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 6401243fb4..00f86731e5 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -826,7 +826,6 @@ static void ivas_dirac_dec_decorrelate_slot( } - static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -958,7 +957,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Determine target covariance matrix containing target binaural properties */ for ( bin = 0; bin < nBins; bin++ ) { - float diffuseness = 1.0f; /* ratio1 and ratio2 are subtracted from diffuseness further below */ + float diffuseness = 1.0f; /* ratio1 and ratio2 are subtracted from diffuseness further below */ #ifdef MASA_AND_OBJECTS float diffusenessValForDecorrelationReduction = 1.0f; float diffEneValForDecorrelationReduction; -- GitLab From 7b4ed8589c95fe2778ddd5234fea5ac79b7818ac Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 12:09:18 +0200 Subject: [PATCH 112/173] activate FIX_356_ISM_METADATA_SYNC; intorduce FIX_356_ISM_METADATA_SYNC_OMASA to temporarily keep BE in OMASA --- lib_com/options.h | 4 ++-- lib_dec/ivas_objectRenderer_internal.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7fa5e09a70..1fd31be0c5 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -158,8 +158,7 @@ #define FIX_411_EVS_BE_TESTS_ON_WINDOWS_FAILING /* Eri: Fix incorrect use of stack variable used for channel aware config file */ #define COMBINED_FORMAT_SIGNALING /* VA: Introduce a signaling bit for combined format coding */ -/* Todo OMASA: This switch causes more difference for OMASA path. Thus, disabled for OMASA currently. Enable to get BE to main. */ -/*#define FIX_356_ISM_METADATA_SYNC*/ /* Eri: issue 356: Metadata out-of-synch for -no_delay_comp */ +#define FIX_356_ISM_METADATA_SYNC /* Eri: issue 356: Metadata out-of-synch for -no_delay_comp */ #define FIX_446_STEREO_DMX_CRASH /* FhG: fix discrepancy with EVS code that could cause crashes in rare cases */ @@ -230,6 +229,7 @@ #define OMASA_ENERGIES #define FIX_OMASA_STEREO_SWITCHING /* VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps */ #define FIX_OMASA_BRSW /* Nokia + VA: Fix missing init of OMASA metadata delay buffers, brsw-related init fixes */ +#define FIX_356_ISM_METADATA_SYNC_OMASA #endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 8d5f8e8772..21093ff266 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -114,6 +114,13 @@ ivas_error ivas_td_binaural_renderer( ism_md_subframe_update = 2; } +#ifdef FIX_356_ISM_METADATA_SYNC_OMASA + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + ism_md_subframe_update = 0; + } +#endif + return ivas_td_binaural_renderer_unwrap( st_ivas->hReverb, st_ivas->transport_config, -- GitLab From 1d6ebb472f56cefd6eb65c789a4978c6a29adc0a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 15:21:09 +0200 Subject: [PATCH 113/173] fix warnings --- lib_dec/ivas_dirac_output_synthesis_dec.c | 188 +++++++++++----------- lib_dec/ivas_init_dec.c | 7 +- lib_rend/ivas_objectRenderer.c | 44 ++--- lib_rend/lib_rend.c | 10 +- 4 files changed, 123 insertions(+), 126 deletions(-) diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 8de9c8539e..1c74fec901 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -625,119 +625,119 @@ void ivas_dirac_dec_output_synthesis_process_slot( } else // ( hDirAC->hConfig->dec_param_estim == TRUE ) if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { + { - /* compute direct responses */ - ivas_dirac_dec_compute_directional_responses( hDirAC, - hVBAPdata, - NULL, + /* compute direct responses */ + ivas_dirac_dec_compute_directional_responses( hDirAC, + hVBAPdata, + NULL, #ifdef MASA_AND_OBJECTS - NULL, + NULL, #endif - azimuth, - elevation, - md_idx, - NULL, - sh_rot_max_order, - p_Rmat, - hodirac_flag ); - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_compute_gain_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); + azimuth, + elevation, + md_idx, + NULL, + sh_rot_max_order, + p_Rmat, + hodirac_flag ); + + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_gain_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); - v_multc( h_dirac_output_synthesis_state->direct_power_factor, - 0.25f, - h_dirac_output_synthesis_state->direct_power_factor, - num_freq_bands ); - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - 0.25f, - h_dirac_output_synthesis_state->diffuse_power_factor, - num_freq_bands ); + v_multc( h_dirac_output_synthesis_state->direct_power_factor, + 0.25f, + h_dirac_output_synthesis_state->direct_power_factor, + num_freq_bands ); + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + 0.25f, + h_dirac_output_synthesis_state->diffuse_power_factor, + num_freq_bands ); - /*Direct gain*/ - for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) - { - int16_t k; - if ( ch_idx != 0 ) + /*Direct gain*/ + for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) { - float a, b, c; - - /*Directonal sound gain nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) + int16_t k; + if ( ch_idx != 0 ) { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + float a, b, c; + + /*Directonal sound gain nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + } + for ( ; k < num_freq_bands; k++ ) + { + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + } } - for ( ; k < num_freq_bands; k++ ) + else { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + /*Diffuseness modellling nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); + } + for ( ; k < num_freq_bands; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); + } } } - else + + /*Directional gain (panning)*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { - /*Diffuseness modellling nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); - } - for ( ; k < num_freq_bands; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); - } + v_mult( h_dirac_output_synthesis_state->direct_power_factor, + &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], + aux_buf, + num_freq_bands ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + num_freq_bands ); } - } - /*Directional gain (panning)*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) - { - v_mult( h_dirac_output_synthesis_state->direct_power_factor, - &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], - aux_buf, - num_freq_bands ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - num_freq_bands ); - } + /*Diffuse gain*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + { + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + hDirAC->diffuse_response_function[ch_idx], + aux_buf, + num_freq_bands_diff ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + num_freq_bands_diff ); + } - /*Diffuse gain*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + return; + } + else { - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - hDirAC->diffuse_response_function[ch_idx], - aux_buf, - num_freq_bands_diff ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - num_freq_bands_diff ); + /* compute reference and diffuse power factor for this frame */ + ivas_dirac_dec_compute_power_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); } - - return; - } - else - { - /* compute reference and diffuse power factor for this frame */ - ivas_dirac_dec_compute_power_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); } - } diff_start_band = 0; if ( h_dirac_output_synthesis_params->use_onset_filters ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6e730727cf..5d4b7812c0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -731,7 +731,11 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef MASA_AND_OBJECTS + int16_t i, n, k; +#else int16_t i, n; +#endif int16_t sce_id, cpe_id; int16_t numCldfbAnalyses, numCldfbSyntheses; int16_t granularity, n_channels_transport_jbm; @@ -743,6 +747,7 @@ ivas_error ivas_init_decoder( #ifdef MASA_AND_OBJECTS int32_t ism_total_brate; #endif + error = IVAS_ERR_OK; output_Fs = st_ivas->hDecoderConfig->output_Fs; @@ -1061,7 +1066,7 @@ ivas_error ivas_init_decoder( return error; } - int16_t k = 0; + k = 0; ism_total_brate = 0; while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) { diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 1ffbeecec9..f9831d4ce5 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -275,13 +275,13 @@ ivas_error ivas_td_binaural_renderer_unwrap( #ifdef EXTERNAL_ORIENTATIONS const int16_t *enableCombinedOrientation, /* i : Combined orientation flag */ #else - const int16_t Opt_Headrotation, /* i : Head rotation flag */ + const int16_t Opt_Headrotation, /* i : Head rotation flag */ #endif - const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ - const IVAS_VECTOR3 *Pos, /* i : Listener position data per subframe */ + const IVAS_QUATERNION *Quaternions, /* i : Head tracking data per subframe */ + const IVAS_VECTOR3 *Pos, /* i : Listener position data per subframe */ const int16_t ism_md_subframe_update, /* i: Number of subframes to delay ism metadata to sync with audio */ - float *output[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t output_frame /* i : output frame length */ + float *output[], /* i/o: SCE channels / Binaural synthesis */ + const int16_t output_frame /* i : output frame length */ ) { int16_t subframe_length; @@ -366,10 +366,10 @@ ivas_error ivas_td_binaural_renderer_unwrap( ivas_error TDREND_GetMix( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ - float *output[], /* 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 */ - const int16_t ism_md_subframe_update /* Number of subframes to delay ism metadata to sync with audio */ + float *output[], /* 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 */ + const int16_t ism_md_subframe_update /* Number of subframes to delay ism metadata to sync with audio */ ) { int16_t i; @@ -470,8 +470,8 @@ 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 num_src, /* i : number of sources to render */ - const IVAS_FORMAT in_format, /* i : Format of input sources */ - const ISM_METADATA_HANDLE *hIsmMetaData /* i : Input metadata for ISM objects */ + const IVAS_FORMAT in_format, /* i : Format of input sources */ + const ISM_METADATA_HANDLE *hIsmMetaData /* i : Input metadata for ISM objects */ ) { TDREND_DirAtten_t *DirAtten_p; @@ -552,13 +552,13 @@ void TDREND_Update_listener_orientation( #ifdef EXTERNAL_ORIENTATIONS if ( Pos != NULL ) { - /* Input position */ - Pos_p[0] = ( *Pos ).x; - Pos_p[1] = ( *Pos ).y; - Pos_p[2] = ( *Pos ).z; - } - else - { + /* Input position */ + Pos_p[0] = ( *Pos ).x; + Pos_p[1] = ( *Pos ).y; + Pos_p[2] = ( *Pos ).z; + } + else + { /* Listener at the origin */ Pos_p[0] = 0.0f; Pos_p[1] = 0.0f; @@ -649,13 +649,13 @@ ivas_error ivas_td_binaural_open_ext( *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_renderer_ext( - const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ - const IVAS_REND_AudioConfig inConfig, /* i : Input audio configuration */ - const LSSETUP_CUSTOM_STRUCT *customLsInput, /* i : Input custom loudspeaker layout */ + const TDREND_WRAPPER *pTDRend, /* i : TD Renderer wrapper structure */ + const IVAS_REND_AudioConfig inConfig, /* i : Input audio configuration */ + const LSSETUP_CUSTOM_STRUCT *customLsInput, /* i : Input custom loudspeaker layout */ #ifdef EXTERNAL_ORIENTATIONS const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ #else - const IVAS_REND_HeadRotData *headRotData, /* i : Input head positions */ + const IVAS_REND_HeadRotData *headRotData, /* i : Input head positions */ #endif const IVAS_REND_AudioObjectPosition *currentPos, /* i : Object position */ const REVERB_HANDLE hReverb, /* i : Reverberator handle */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 6b637b7767..3ceb66f2c5 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5117,7 +5117,6 @@ static ivas_error renderIsmToBinauralRoom( } #ifdef FIX_196_REFACTOR_RENDERER_OUTPUT_CONFIG - static ivas_error renderIsmToBinauralReverb( input_ism *ismInput, IVAS_REND_AudioBuffer outAudio ) @@ -5452,13 +5451,6 @@ static ivas_error renderMcToBinaural( #else int8_t headRotEnabled; #endif - float *p_tmpRendBuffer[MAX_OUTPUT_CHANNELS]; - int16_t i; - - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - p_tmpRendBuffer[i] = tmpRendBuffer[i]; - } push_wmops( "renderMcToBinaural" ); @@ -5537,7 +5529,7 @@ static ivas_error renderMcToBinaural( /* call CREND */ if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, NULL, NULL, NULL, p_tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + NULL, NULL, NULL, NULL, NULL /* ToDo: TBV */, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From f31a511372ff196a26bfd8ab50a3a1012c1e18dc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 16:01:40 +0200 Subject: [PATCH 114/173] formatting --- apps/encoder.c | 6 +- lib_com/ivas_prot.h | 8 +- lib_com/ivas_stat_com.h | 2 + lib_dec/ivas_cpe_dec.c | 1 + lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_dirac_output_synthesis_dec.c | 194 +++++++++---------- lib_dec/ivas_init_dec.c | 11 +- lib_dec/ivas_masa_dec.c | 2 + lib_dec/ivas_mono_dmx_renderer.c | 1 + lib_dec/ivas_omasa_dec.c | 2 + lib_dec/ivas_vbap.c | 14 +- lib_enc/ivas_cpe_enc.c | 1 - lib_enc/ivas_decision_matrix_enc.c | 1 + lib_enc/ivas_ism_metadata_enc.c | 4 - lib_enc/ivas_masa_enc.c | 14 +- lib_enc/ivas_qmetadata_enc.c | 3 + lib_enc/ivas_stat_enc.h | 2 +- lib_enc/lib_enc.c | 6 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 + lib_rend/ivas_objectRenderer.c | 1 + 21 files changed, 151 insertions(+), 128 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 567e32d431..66c64f39f3 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -97,6 +97,7 @@ typedef union _EncInputFormatConfig IVAS_ENC_MASA_VARIANT masaVariant; } masa_ism; #endif + } EncInputFormatConfig; /* Struct for storing cmdln arguments */ @@ -542,7 +543,6 @@ int main( } } - #ifdef MASA_AND_OBJECTS const int16_t numIsmInputs = ( arg.inputFormat == IVAS_ENC_INPUT_ISM || arg.inputFormat == IVAS_ENC_INPUT_MASA_ISM ) ? arg.inputFormatConfig.ism.numObjects : 0; #else @@ -1809,8 +1809,8 @@ static void usage_enc( void ) fprintf( stdout, " for IVAS SBA, MASA, MC R=(13200, 16400, 24400, 32000, 48000, 64000, 80000, \n" ); fprintf( stdout, " 96000, 128000, 160000, 192000, 256000, 384000, 512000) \n" ); #ifdef MASA_AND_OBJECTS - fprintf( stdout, " for IVAS MASA and objects R = (13200, 16400, 24400, 32000, 48000, 64000, 96000, 128000, \n" ); - fprintf( stdout, " 160000, 192000, 256000, 384000, 512000)\n" ); + fprintf( stdout, " for IVAS objects-MASA R =(13200, 16400, 24400, 32000, 48000, 64000, 96000, 128000, \n" ); + fprintf( stdout, " 160000, 192000, 256000, 384000, 512000)\n" ); #endif fprintf( stdout, " Alternatively, R can be a bitrate switching file which consists of R values\n" ); fprintf( stdout, " indicating the bitrate for each frame in bps. These values are stored in\n" ); diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 0d4c8dc241..09c08ccb29 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1024,7 +1024,7 @@ void ivas_ism_metadata_close( ISM_METADATA_HANDLE hIsmMetaData[] /* i/o : object metadata handles */ #ifdef MASA_AND_OBJECTS , - const int16_t first_idx /* i : index of first handle to deallocate */ + const int16_t first_idx /* i : index of first handle to deallocate */ #endif ); @@ -5090,7 +5090,7 @@ ivas_error ivas_masa_encode( const int16_t ism_imp /* i : importance of separated object */ #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate /* i: flag for using less bitrate for objects in OMASA */ + const int16_t flag_omasa_brate /* i : flag for using less bitrate for objects in OMASA*/ #endif #endif ); @@ -5404,7 +5404,7 @@ ivas_error vbap_init_data( const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ #ifdef MASA_AND_OBJECTS , - const int16_t support_object_mode /* i : init VBAP also for object panning mode */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ #endif ); @@ -5706,7 +5706,7 @@ void ivas_omasa_set_config( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const int32_t input_Fs, /* i : Input sample rate */ - const ISM_MODE ism_mode /* i : ISM mode */ + const ISM_MODE ism_mode /* i : ISM mode */ ); void ivas_omasa_enc( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index f0e5a05a97..9b8cee1df5 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -455,6 +455,7 @@ typedef struct ivas_omasa_meta_struct uint8_t num_dirs; MASA_DIRECTIONAL_SPATIAL_META directional_meta[MASA_MAXIMUM_DIRECTIONS]; MASA_COMMON_SPATIAL_META common_meta; + } OMASA_SPATIAL_META, *OMASA_SPATIAL_META_HANDLE; #endif @@ -570,6 +571,7 @@ typedef struct ivas_masa_qmetadata_frame_struct #ifdef MASA_AND_OBJECTS float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: This should be moved to some other place and reserved only when needed. */ #endif + } IVAS_QMETADATA, *IVAS_QMETADATA_HANDLE; diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 8a1d2e93e1..daf7056f7b 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -83,6 +83,7 @@ ivas_error ivas_cpe_dec( int32_t element_brate_ref; #endif #endif + error = IVAS_ERR_OK; push_wmops( "ivas_cpe_dec" ); diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 4cb89aec42..6fb6cbc2cd 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -71,10 +71,10 @@ ivas_error ivas_dec( float pan_left, pan_right; ivas_error error; float *p_output[MAX_OUTPUT_CHANNELS]; - #ifdef MASA_AND_OBJECTS int32_t ism_total_brate; #endif + error = IVAS_ERR_OK; push_wmops( "ivas_dec" ); diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1b76add66a..7197186a0b 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -784,7 +784,7 @@ ivas_error ivas_dirac_dec_config( } #ifdef MASA_AND_OBJECTS - if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format == MASA_ISM_FORMAT ? 1 : 0 ) ) != IVAS_ERR_OK ) + if ( ( error = vbap_init_data( &( st_ivas->hVBAPdata ), ls_azimuth, ls_elevation, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_dec/ivas_dirac_output_synthesis_dec.c index 1c74fec901..97bbbab852 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_dec/ivas_dirac_output_synthesis_dec.c @@ -623,121 +623,119 @@ void ivas_dirac_dec_output_synthesis_process_slot( h_dirac_output_synthesis_state->diffuse_power_factor ); } } - else // ( hDirAC->hConfig->dec_param_estim == TRUE ) - if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { - - /* compute direct responses */ - ivas_dirac_dec_compute_directional_responses( hDirAC, - hVBAPdata, - NULL, + else if ( hDirAC->hConfig->dec_param_estim == TRUE ) + { + /* compute direct responses */ + ivas_dirac_dec_compute_directional_responses( hDirAC, + hVBAPdata, + NULL, #ifdef MASA_AND_OBJECTS - NULL, + NULL, #endif - azimuth, - elevation, - md_idx, - NULL, - sh_rot_max_order, - p_Rmat, - hodirac_flag ); - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_compute_gain_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); + azimuth, + elevation, + md_idx, + NULL, + sh_rot_max_order, + p_Rmat, + hodirac_flag ); + if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_gain_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); - v_multc( h_dirac_output_synthesis_state->direct_power_factor, - 0.25f, - h_dirac_output_synthesis_state->direct_power_factor, - num_freq_bands ); - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - 0.25f, - h_dirac_output_synthesis_state->diffuse_power_factor, - num_freq_bands ); - /*Direct gain*/ - for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) + v_multc( h_dirac_output_synthesis_state->direct_power_factor, + 0.25f, + h_dirac_output_synthesis_state->direct_power_factor, + num_freq_bands ); + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + 0.25f, + h_dirac_output_synthesis_state->diffuse_power_factor, + num_freq_bands ); + + /*Direct gain*/ + for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) + { + int16_t k; + if ( ch_idx != 0 ) { - int16_t k; - if ( ch_idx != 0 ) - { - float a, b, c; + float a, b, c; - /*Directonal sound gain nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) - { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); - } - for ( ; k < num_freq_bands; k++ ) - { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); - } + /*Directonal sound gain nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); } - else + for ( ; k < num_freq_bands; k++ ) { - /*Diffuseness modellling nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); - } - for ( ; k < num_freq_bands; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); - } + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); } } - - /*Directional gain (panning)*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) - { - v_mult( h_dirac_output_synthesis_state->direct_power_factor, - &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], - aux_buf, - num_freq_bands ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - num_freq_bands ); - } - - /*Diffuse gain*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + else { - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - hDirAC->diffuse_response_function[ch_idx], - aux_buf, - num_freq_bands_diff ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - num_freq_bands_diff ); + /*Diffuseness modellling nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); + } + for ( ; k < num_freq_bands; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); + } } + } - return; + /*Directional gain (panning)*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) + { + v_mult( h_dirac_output_synthesis_state->direct_power_factor, + &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], + aux_buf, + num_freq_bands ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + num_freq_bands ); } - else + + /*Diffuse gain*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) { - /* compute reference and diffuse power factor for this frame */ - ivas_dirac_dec_compute_power_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + hDirAC->diffuse_response_function[ch_idx], + aux_buf, + num_freq_bands_diff ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + num_freq_bands_diff ); } + + return; + } + else + { + /* compute reference and diffuse power factor for this frame */ + ivas_dirac_dec_compute_power_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); } + } diff_start_band = 0; if ( h_dirac_output_synthesis_params->use_onset_filters ) @@ -1874,6 +1872,7 @@ void ivas_dirac_dec_compute_directional_responses( { /* Synthesize the first direction */ spreadCoherencePanningHoa( azimuth[k], elevation[k], hDirAC->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirAC->hOutSetup.ambisonics_order ); + /* Synthesize the second direction and combine the gains */ #ifdef MASA_AND_OBJECTS if ( hDirAC->numParametricDirections == 2 ) @@ -2010,6 +2009,7 @@ void ivas_dirac_dec_compute_directional_responses( } normalizePanningGains( direct_response_ls, num_channels_dir ); } + #ifdef MASA_AND_OBJECTS // Todo OMASA JBM: Here we also probably need md_idx if ( hDirAC->numIsmDirections > 0 ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5d4b7812c0..f4f741bb8c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -436,14 +436,13 @@ static ivas_error ivas_read_format( case 3: if ( st_ivas->bit_stream[*num_bits_read] ) { - ( *num_bits_read )++; st_ivas->ivas_format = MASA_FORMAT; } else { - ( *num_bits_read )++; st_ivas->ivas_format = SBA_FORMAT; } + ( *num_bits_read )++; break; } @@ -1009,7 +1008,7 @@ ivas_error ivas_init_decoder( } } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { @@ -1237,7 +1236,7 @@ ivas_error ivas_init_decoder( return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { if ( ( error = create_cpe_dec( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) { @@ -1304,7 +1303,7 @@ ivas_error ivas_init_decoder( ivas_mcmasa_split_brate( st_ivas->hOutSetup.separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_dec( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { @@ -1314,7 +1313,7 @@ ivas_error ivas_init_decoder( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; /* element_mode_init was IVAS_SCE for SCE initialization */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6b8a947402..1251cecac3 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -309,6 +309,7 @@ ivas_error ivas_masa_decode( /* Remove already read bits from the bit budget */ hQMetaData->metadata_max_bits -= *nb_bits_read; + #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { @@ -351,6 +352,7 @@ ivas_error ivas_masa_decode( { total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); } + if ( total_brate >= IVAS_384k ) { if ( total_brate >= IVAS_512k ) diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 4e16edca30..61d8c68094 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -94,6 +94,7 @@ void ivas_mono_downmix_render_passive( MONO_DOWNMIX_RENDERER_HANDLE hDownmix; numInputChannels = st_ivas->nSCE; + #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index a198c6a774..40d505d5fc 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -183,6 +183,7 @@ ivas_error ivas_omasa_dec_config( /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ + old_renderer_type = st_ivas->renderer_type; #endif @@ -296,6 +297,7 @@ ivas_error ivas_omasa_dec_config( /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ + ivas_renderer_select( st_ivas ); /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_vbap.c b/lib_dec/ivas_vbap.c index e45d525fc3..dcc73907e2 100644 --- a/lib_dec/ivas_vbap.c +++ b/lib_dec/ivas_vbap.c @@ -163,7 +163,7 @@ ivas_error vbap_init_data( const int16_t num_speaker_nodes /* i : number of speaker nodes in the set */ #ifdef MASA_AND_OBJECTS , - const int16_t support_object_mode /* i : init VBAP also for object panning mode */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ #endif ) { @@ -242,14 +242,16 @@ ivas_error vbap_init_data( } set_zero( vbap->bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->bottom_virtual_speaker_node_division_gains != NULL; + #ifdef MASA_AND_OBJECTS - if ( support_object_mode ) + if ( ivas_format == MASA_ISM_FORMAT ) { vbap->object_mode_bottom_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->object_mode_bottom_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->object_mode_bottom_virtual_speaker_node_division_gains != NULL; } #endif + speaker_node_azi_deg_internal[vbap->bottom_virtual_speaker_node_index] = 0.0f; speaker_node_ele_deg_internal[vbap->bottom_virtual_speaker_node_index] = -90.0f; } @@ -262,14 +264,16 @@ ivas_error vbap_init_data( } set_zero( vbap->top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->top_virtual_speaker_node_division_gains != NULL; + #ifdef MASA_AND_OBJECTS - if ( support_object_mode ) + if ( ivas_format == MASA_ISM_FORMAT ) { vbap->object_mode_top_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->object_mode_top_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->object_mode_top_virtual_speaker_node_division_gains != NULL; } #endif + speaker_node_azi_deg_internal[vbap->top_virtual_speaker_node_index] = 0.0f; speaker_node_ele_deg_internal[vbap->top_virtual_speaker_node_index] = 90.0f; } @@ -283,7 +287,7 @@ ivas_error vbap_init_data( set_zero( vbap->back_virtual_speaker_node_division_gains, num_speaker_nodes ); is_success &= vbap->back_virtual_speaker_node_division_gains != NULL; #ifdef MASA_AND_OBJECTS - if ( support_object_mode ) + if ( ivas_format == MASA_ISM_FORMAT ) { vbap->object_mode_back_virtual_speaker_node_division_gains = (float *) malloc( num_speaker_nodes * sizeof( float ) ); set_zero( vbap->object_mode_back_virtual_speaker_node_division_gains, num_speaker_nodes ); @@ -383,7 +387,7 @@ ivas_error vbap_init_data( determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->top_virtual_speaker_node_division_gains, connections, virtual_top_type, max_num_connections, num_speaker_nodes, 0 ); determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type, max_num_connections, num_speaker_nodes, 0 ); determine_virtual_speaker_node_division_gains( vbap->back_virtual_speaker_node_index, vbap->back_virtual_speaker_node_division_gains, connections, virtual_back_type, max_num_connections, num_speaker_nodes, 0 ); - if ( support_object_mode ) + if ( ivas_format == MASA_ISM_FORMAT ) { determine_virtual_speaker_node_division_gains( vbap->top_virtual_speaker_node_index, vbap->object_mode_top_virtual_speaker_node_division_gains, connections, virtual_top_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); determine_virtual_speaker_node_division_gains( vbap->bottom_virtual_speaker_node_index, vbap->object_mode_bottom_virtual_speaker_node_division_gains, connections, virtual_bottom_type == NO_VIRTUAL_SPEAKER_NODE ? NO_VIRTUAL_SPEAKER_NODE : VIRTUAL_SPEAKER_NODE_DISTRIBUTE_ENERGY, max_num_connections, num_speaker_nodes, 1 ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index f573b4ac6e..f099d448f4 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -327,7 +327,6 @@ ivas_error ivas_cpe_enc( } else { - #endif stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); #ifdef MASA_AND_OBJECTS diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 115a7eecde..2db13f8ecf 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -424,6 +424,7 @@ void ivas_signaling_enc( /*-------------------------------------------------------------------------- * Write element mode info *--------------------------------------------------------------------------*/ + #ifdef MASA_AND_OBJECTS if ( ( st->element_mode == IVAS_CPE_DFT || st->element_mode == IVAS_CPE_TD ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ #else diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 734a0cbd14..fcceeca57d 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -341,11 +341,7 @@ ivas_error ivas_ism_metadata_enc( } /* write ISM metadata flag (one per object) */ -#ifdef MASA_AND_OBJECTS - for ( ch = 0; ch < nchan_transport; ch++ ) -#else for ( ch = 0; ch < nchan_transport; ch++ ) -#endif { #ifdef MASA_AND_OBJECTS if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 60e80bbfb3..4c1fd0644a 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -50,7 +50,6 @@ static void combine_freqbands_and_subframes( MASA_ENCODER_HANDLE hMasa ); #ifndef MASA_AND_OBJECTS static void combine_directions( MASA_ENCODER_HANDLE hMasa ); #endif - static void find_n_largest( const float *input, int16_t *largestIndices, const int16_t numElements, const int16_t numLargest ); static void move_metadata_to_qmetadata( const MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMeta ); @@ -140,6 +139,7 @@ ivas_error ivas_masa_enc_open( return error; } } + #ifdef MASA_AND_OBJECTS ism_total_brate = 0; if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 && ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) ) @@ -150,6 +150,7 @@ ivas_error ivas_masa_enc_open( } } #endif + ivas_masa_set_elements( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE #ifdef MASA_AND_OBJECTS @@ -248,7 +249,7 @@ ivas_error ivas_masa_encode( const int16_t ism_imp /* i : importance of separated object */ #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate /* i: flag for using less bitrate for objects in OMASA */ + const int16_t flag_omasa_brate /* i : flag for using less bitrate for objects in OMASA */ #endif #endif ) @@ -256,7 +257,6 @@ ivas_error ivas_masa_encode( MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; int16_t i, j; int16_t masa_sid_descriptor; - #ifdef MASA_AND_OBJECTS int16_t low_bitrate_mode; #endif @@ -265,6 +265,7 @@ ivas_error ivas_masa_encode( h_orig_metadata = NULL; #ifdef MASA_AND_OBJECTS low_bitrate_mode = 0; + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else if ( ivas_format == MASA_FORMAT ) @@ -317,6 +318,7 @@ ivas_error ivas_masa_encode( /* Combine frequency bands and sub-frames */ combine_freqbands_and_subframes( hMasa ); } + #ifdef MASA_AND_OBJECTS if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) #else @@ -333,6 +335,7 @@ ivas_error ivas_masa_encode( /* Combine directions */ combine_directions( hMasa ); #endif + /* If we joined all bands, then metadata is now one directional. */ if ( hMasa->config.numTwoDirBands == 0 ) { @@ -350,7 +353,6 @@ ivas_error ivas_masa_encode( if ( ivas_format == MASA_FORMAT ) #endif { - #ifndef MASA_AND_OBJECTS /* write the number of MASA transport channels */ push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); @@ -458,6 +460,7 @@ ivas_error ivas_masa_encode( #else reduce_metadata_further( hMasa, hQMetaData, ivas_format ); #endif + /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; @@ -476,6 +479,7 @@ ivas_error ivas_masa_encode( hQMetaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ } #endif + /* Encode metadata */ #ifdef MASA_AND_OBJECTS int32_t total_brate; @@ -484,6 +488,7 @@ ivas_error ivas_masa_encode( { total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); } + if ( total_brate >= IVAS_384k ) { if ( total_brate >= IVAS_512k ) @@ -559,6 +564,7 @@ ivas_error ivas_masa_encode( #else combine_directions( hMasa ); #endif + /* If we joined all bands, then metadata is now one directional. */ if ( hMasa->config.numTwoDirBands == 0 ) { diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 6af86d0098..628bbe6cb5 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -144,6 +144,7 @@ static int16_t find_optimal_GR_order( const int16_t *q_idx, const int16_t len, i static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, const int16_t len_max_GR1, int16_t *GR1, int16_t *GR2, int16_t *i_min ); #endif + /*-----------------------------------------------------------------------* * ivas_qmetadata_enc_encode() * @@ -3102,6 +3103,7 @@ static int16_t ivas_qmetadata_get_optimal_gr_param( * * *------------------------------------------------------------------------*/ + #ifndef MASA_AND_OBJECTS static #endif @@ -3248,6 +3250,7 @@ static int16_t ivas_qmetadata_reorder_azimuth_index( * * *------------------------------------------------------------------------*/ + #ifndef MASA_AND_OBJECTS static #endif diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 1b2542e757..4f3a1eb162 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1221,7 +1221,7 @@ typedef struct MC_PARAMUPMIX_ENC_HANDLE hMCParamUpmix; /* MC Param-Upmix handle */ MCMASA_ENC_HANDLE hMcMasa; /* Multi-channel MASA data handle */ #ifdef MASA_AND_OBJECTS - OMASA_ENC_HANDLE hOMasa; /* Object MASA data handle */ + OMASA_ENC_HANDLE hOMasa; /* Object-MASA data handle */ #endif LFE_ENC_HANDLE hLFE; /* LFE data handle */ diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 39d9f658cc..f47467aba8 100755 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -383,6 +383,7 @@ ivas_error IVAS_ENC_ConfigureForStereo( return error; } + #ifdef MASA_AND_OBJECTS /*---------------------------------------------------------------------* * IVAS_ENC_ConfigureForMASAObjects() @@ -439,6 +440,7 @@ ivas_error IVAS_ENC_ConfigureForMASAObjects( } #endif + /*---------------------------------------------------------------------* * IVAS_ENC_ConfigureForObjects() * @@ -504,6 +506,7 @@ ivas_error IVAS_ENC_FeedObjectMetadata( { return IVAS_ERR_NOT_CONFIGURED; } + #ifdef MASA_AND_OBJECTS if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != ISM_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) #else @@ -664,6 +667,7 @@ ivas_error IVAS_ENC_FeedMasaMetadata( { return IVAS_ERR_NOT_CONFIGURED; } + #ifdef MASA_AND_OBJECTS if ( hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_FORMAT && hIvasEnc->st_ivas->hEncoderConfig->ivas_format != MASA_ISM_FORMAT ) #else @@ -758,6 +762,7 @@ static ivas_error configureEncoder( #ifdef MASA_AND_OBJECTS int32_t cpe_brate; #endif + error = IVAS_ERR_OK; st_ivas = hIvasEnc->st_ivas; @@ -898,7 +903,6 @@ static ivas_error configureEncoder( } } } - #ifdef MASA_AND_OBJECTS else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index f2fe66d886..2c916691d0 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1067,6 +1067,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric spreadCoh = 0.0f; } #endif + diffuseness -= ratio; /* diffuseness = 1 - ratio1 - ratio2 */ #ifdef MASA_AND_OBJECTS @@ -1254,6 +1255,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Apply target spectrum that emphasizes low frequencies when the sound is surround coherent */ diffEne *= ( 1.0f - surCoh ) + surCoh * surCohEne[idx]; #endif + #ifdef MASA_AND_OBJECTS /* Modify also the value for decorrelation reduction */ diffEneValForDecorrelationReduction *= spectrumModVal; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index f9831d4ce5..82a08ef9d5 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -191,6 +191,7 @@ ivas_error ivas_td_binaural_open_unwrap( TDREND_MIX_SRC_SetDirAtten( pBinRendTd, nS, DirAtten_p ); } } + #ifdef MASA_AND_OBJECTS if ( ivas_format == ISM_FORMAT || ivas_format == MASA_ISM_FORMAT ) #else -- GitLab From 25903e4a4e1252a169c3e10218f9e6fbf4bd78ca Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 16:14:04 +0200 Subject: [PATCH 115/173] fix build warning --- lib_rend/lib_rend.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3ceb66f2c5..f57f06b887 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5125,13 +5125,6 @@ static ivas_error renderIsmToBinauralReverb( float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; - float *p_tmpRendBuffer[MAX_OUTPUT_CHANNELS]; - - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - p_tmpRendBuffer[i] = tmpRendBuffer[i]; - } - push_wmops( "renderIsmToBinauralRoom" ); copyBufferTo2dArray( ismInput->base.inputBuffer, tmpRendBuffer ); -- GitLab From c2e627b35c7f9f39e3e93a6ea306b194f149aaf9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 13 Jun 2023 16:34:35 +0200 Subject: [PATCH 116/173] fix ext renderer failures --- lib_rend/lib_rend.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f57f06b887..3d841fef0e 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5121,7 +5121,6 @@ static ivas_error renderIsmToBinauralReverb( input_ism *ismInput, IVAS_REND_AudioBuffer outAudio ) { - int16_t i; float tmpRendBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; ivas_error error; @@ -5444,6 +5443,13 @@ static ivas_error renderMcToBinaural( #else int8_t headRotEnabled; #endif + float *p_tmpRendBuffer[MAX_OUTPUT_CHANNELS]; + int16_t i; + + for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) + { + p_tmpRendBuffer[i] = tmpRendBuffer[i]; + } push_wmops( "renderMcToBinaural" ); @@ -5522,7 +5528,7 @@ static ivas_error renderMcToBinaural( /* call CREND */ if ( ( error = ivas_rend_crendProcess( mcInput->crendWrapper, getIvasAudioConfigFromRendAudioConfig( mcInput->base.inConfig ), getIvasAudioConfigFromRendAudioConfig( outConfig ), - NULL, NULL, NULL, NULL, NULL /* ToDo: TBV */, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + NULL, NULL, NULL, NULL, p_tmpRendBuffer, *mcInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 57f30a596e16da1dbf533fd751e4ba244922391d Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 14 Jun 2023 16:01:18 +0200 Subject: [PATCH 117/173] MASA_AND_OBJECTS fix within ISM_25k6_HZ_CORE --- lib_dec/ivas_sce_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 19c655c87a..9024e91e73 100755 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -380,7 +380,11 @@ ivas_error create_sce_dec( st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; #ifdef ISM_25k6_HZ_CORE st->is_ism_format = 0; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == ISM_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) +#else if ( st_ivas->ivas_format == ISM_FORMAT ) +#endif { st->is_ism_format = 1; } -- GitLab From 1e5e8f48f4d8da3d4955f7af0643808a166ba06d Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jun 2023 09:41:10 +0200 Subject: [PATCH 118/173] fix remaining issues with FIX_532_ISM_MD_INACTIVE in OMASA --- lib_enc/ivas_masa_enc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 349ffa9515..dab2c493e2 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -385,22 +385,28 @@ ivas_error ivas_masa_encode( { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; } else { push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; if ( hIsmMetaData[0]->ism_imp == ISM_NO_META ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[0]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; } } #else @@ -424,22 +430,28 @@ ivas_error ivas_masa_encode( { /* signal NULL metadata frame */ push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; /* write the ISM class to ISM_NO_META and again the true ISM class */ push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; } else { push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; if ( hIsmMetaData[i]->ism_imp == ISM_NO_META ) { /* signal low-rate ISM_NO_META frame */ push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; /* signal presence of MD in low-rate ISM_NO_META frame */ push_next_indice( hMetaData, hIsmMetaData[i]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; } } #else -- GitLab From f5da52905bf0dae41db283fb5d5a6d1f9efb53d9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jun 2023 10:16:37 +0200 Subject: [PATCH 119/173] update within FIX_511_OPTIMIZE_PARAMBIN_GAIN_FETCH for OMASA --- lib_enc/ivas_spar_md_enc.c | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index dbca3809cc..9ff27f82fc 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -45,7 +45,7 @@ /*------------------------------------------------------------------------------------------* * PreProcessor *------------------------------------------------------------------------------------------*/ -#define IVAS_MAX_MD_BYTES ( 1000 ) +#define IVAS_MAX_MD_BYTES ( 1000 ) // ToDo: not used static const float pr_boost_range[2] = { 0.1f, 0.4f }; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 2c916691d0..4b6e364200 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -53,8 +53,8 @@ *------------------------------------------------------------------------*/ #define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f -#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) -#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) // ToDo: not used +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) // ToDo: not used #ifdef MASA_AND_OBJECTS #define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) @@ -69,7 +69,11 @@ #define ADAPT_HTPROTO_ROT_LIM_1 0.8f #ifdef FIX_511_OPTIMIZE_PARAMBIN_GAIN_FETCH +#ifdef MASA_AND_OBJECTS +#define MAX_GAIN_CACHE_SIZE ( 5 * 3 ) /* == max number of simultaneous directions * 3 */ +#else #define MAX_GAIN_CACHE_SIZE 6 +#endif typedef struct hrtfGainCache { -- GitLab From 29a8aecfd90a08bac86b35d9c978d87be37f0018 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jun 2023 11:12:31 +0200 Subject: [PATCH 120/173] fix MAX_GAIN_CACHE_SIZE size --- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 1ca593f68e..fe2dc890b4 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -69,7 +69,7 @@ #define ADAPT_HTPROTO_ROT_LIM_1 0.8f #ifdef MASA_AND_OBJECTS -#define MAX_GAIN_CACHE_SIZE ( 5 * 3 ) /* == max number of simultaneous directions * 3 */ +#define MAX_GAIN_CACHE_SIZE ( ( MASA_MAXIMUM_DIRECTIONS + MAX_NUM_OBJECTS ) * 3 ) /* == max number of simultaneous directions * 3 */ #else #define MAX_GAIN_CACHE_SIZE 6 #endif -- GitLab From 9ea697c8c11d35546c396818ec1da181ab5628ff Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jun 2023 11:36:13 +0200 Subject: [PATCH 121/173] maintenance: new function ivas_omasa_ener_brate() + comments --- lib_com/ivas_prot.h | 16 ++++++++--- lib_enc/ivas_enc.c | 45 +++++++------------------------ lib_enc/ivas_ism_enc.c | 4 +-- lib_enc/ivas_ism_metadata_enc.c | 6 ++--- lib_enc/ivas_masa_enc.c | 4 +-- lib_enc/ivas_omasa_enc.c | 47 +++++++++++++++++++++++++++++++++ 6 files changed, 76 insertions(+), 46 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 69745469ac..e1263217f7 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -947,7 +947,7 @@ ivas_error ivas_ism_enc( int16_t *nb_bits_metadata /* i : number of metadata bits */ #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif ); @@ -971,7 +971,7 @@ ivas_error ivas_ism_metadata_enc( ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif #ifdef FIX_OMASA_STEREO_SWITCHING ,int16_t *omasa_stereo_sw_cnt @@ -5078,7 +5078,7 @@ ivas_error ivas_masa_encode( const int16_t ism_imp /* i : importance of separated object */ #ifdef OMASA_ENERGIES , - const int16_t flag_omasa_brate /* i : flag for using less bitrate for objects in OMASA*/ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif #endif ); @@ -5728,6 +5728,16 @@ void set_ism_importance_interformat( int16_t ism_imp[] /* o : ISM importance flags */ ); +#ifdef OMASA_ENERGIES +/*! r: flag for using less bitrate for objects in OMASA */ +int16_t ivas_omasa_ener_brate( + const int16_t nchan_ism, /* i : number of ISMs */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + float data_f[][L_FRAME48k], /* i : Input / transport audio signals */ + const int16_t input_frame /* i : Input frame size */ +); +#endif + /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( const ISM_MODE ism_mode, /* i : ISM mode */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 9a1ed1ae30..3898b44fc5 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -63,9 +63,6 @@ ivas_error ivas_enc( Encoder_State *st; /* used for bitstream handling */ #ifdef MASA_AND_OBJECTS int16_t nb_bits_metadata[MAX_SCE + 1]; -#ifdef OMASA_ENERGIES - int16_t flag_omasa_brate; -#endif #else int16_t nb_bits_metadata[MAX_SCE]; #endif @@ -92,9 +89,6 @@ ivas_error ivas_enc( #ifdef MASA_AND_OBJECTS set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); -#ifdef OMASA_ENERGIES - flag_omasa_brate = 0; -#endif #else set_s( nb_bits_metadata, 0, MAX_SCE ); #endif @@ -304,6 +298,11 @@ ivas_error ivas_enc( { float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; +#ifdef OMASA_ENERGIES + int16_t flag_omasa_ener_brate; + + flag_omasa_ener_brate = 0; +#endif if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -358,40 +357,14 @@ ivas_error ivas_enc( else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { #ifdef OMASA_ENERGIES - float energy_ism, energy_masa; - - energy_ism = 0.0f; - - if ( st_ivas->nSCE >= 3 && st_ivas->hEncoderConfig->ivas_total_brate == IVAS_128k ) - { - for ( i = 0; i < st_ivas->nSCE; i++ ) - { - energy_ism += sum2_f( data_f[i], input_frame ); - } - - energy_masa = 0.0f; - - for ( i = st_ivas->nSCE; i < st_ivas->nSCE + 2; i++ ) - { - energy_masa += sum2_f( data_f[i], input_frame ); - } - - energy_ism = energy_ism / ( energy_masa + 1.0f ) * 2.0f / (float) ( st_ivas->nSCE ); - flag_omasa_brate = 0; - if ( energy_ism < 1.0f ) - { - flag_omasa_brate = 1; - } -#ifdef DEBUG_MODE_INFO - dbgwrite( &energy_ism, sizeof( float ), 1, 1, "en_ratio.bin" ); -#endif - } + flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); #endif + /* Analysis, decision about bitrates per channel & core coding */ if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] #ifdef OMASA_ENERGIES , - flag_omasa_brate + flag_omasa_ener_brate #endif ) ) != IVAS_ERR_OK ) { @@ -416,7 +389,7 @@ ivas_error ivas_enc( st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp #ifdef OMASA_ENERGIES , - flag_omasa_brate + flag_omasa_ener_brate #endif ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index c9ce0e7721..f68940c9dd 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -55,7 +55,7 @@ ivas_error ivas_ism_enc( int16_t *nb_bits_metadata /* i : number of metadata bits */ #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif ) { @@ -288,7 +288,7 @@ ivas_error ivas_ism_enc( nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 #ifdef OMASA_ENERGIES , - flag_omasa_brate + flag_omasa_ener_brate #endif #ifdef FIX_OMASA_STEREO_SWITCHING , diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 97e10027a9..d9b3645358 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -194,7 +194,7 @@ ivas_error ivas_ism_metadata_enc( const float lp_noise_CPE #ifdef OMASA_ENERGIES , - int16_t flag_omasa_brate + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif #ifdef FIX_OMASA_STEREO_SWITCHING , @@ -704,9 +704,9 @@ ivas_error ivas_ism_metadata_enc( { *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); #ifdef OMASA_ENERGIES - if ( ism_imp[ch] > 1 && flag_omasa_brate == 1 && brate_limit_flag >= 0 ) + if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) { - *ism_total_brate -= flag_omasa_brate * ADJUST_ISM_BRATE_NEG; + *ism_total_brate -= ADJUST_ISM_BRATE_NEG; } if ( brate_limit_flag == -1 && ism_imp[ch] >= 1 && nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index dab2c493e2..6fa2d7885f 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -249,7 +249,7 @@ ivas_error ivas_masa_encode( const int16_t ism_imp /* i : importance of separated object */ #ifdef OMASA_ENERGIES , - const int16_t flag_omasa_brate /* i : flag for using less bitrate for objects in OMASA */ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif #endif ) @@ -470,7 +470,7 @@ ivas_error ivas_masa_encode( #ifdef OMASA_ENERGIES if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) { - push_next_indice( hMetaData, flag_omasa_brate, 1 ); + push_next_indice( hMetaData, flag_omasa_ener_brate, 1 ); hQMetaData->metadata_max_bits -= 1; } #endif diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 24d1cfe140..714054d977 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -727,6 +727,53 @@ void ivas_set_surplus_brate_enc( } +#ifdef OMASA_ENERGIES +/*--------------------------------------------------------------------------* + * ivas_omasa_ener_brate() + * + * + *--------------------------------------------------------------------------*/ + +/*! r: OMASA energy bitrate flag */ +int16_t ivas_omasa_ener_brate( + const int16_t nchan_ism, /* i : number of ISMs */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + float data_f[][L_FRAME48k], /* i : Input / transport audio signals */ + const int16_t input_frame /* i : Input frame size */ +) +{ + int16_t i, flag_omasa_ener_brate; + float energy_ism, energy_masa; + + flag_omasa_ener_brate = 0; + + if ( nchan_ism >= 3 && ivas_total_brate == IVAS_128k ) + { + energy_ism = 0.0f; + for ( i = 0; i < nchan_ism; i++ ) + { + energy_ism += sum2_f( data_f[i], input_frame ); + } + + energy_masa = 0.0f; + for ( i = nchan_ism; i < nchan_ism + MASA_MAXIMUM_DIRECTIONS; i++ ) + { + energy_masa += sum2_f( data_f[i], input_frame ); + } + + energy_ism = energy_ism / ( energy_masa + 1.0f ) * 2.0f / (float) ( nchan_ism ); + + if ( energy_ism < 1.0f ) + { + flag_omasa_ener_brate = 1; + } + } + + return flag_omasa_ener_brate; +} +#endif + + /*--------------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------------*/ -- GitLab From 09102fb7438713ae6f0d3e71fa3032b413c73f97 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 15 Jun 2023 14:22:46 +0300 Subject: [PATCH 122/173] Fix binaural gain cache in relation to OMASA --- lib_rend/ivas_dirac_dec_binaural_functions.c | 38 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index fe2dc890b4..e418af9d52 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -69,7 +69,7 @@ #define ADAPT_HTPROTO_ROT_LIM_1 0.8f #ifdef MASA_AND_OBJECTS -#define MAX_GAIN_CACHE_SIZE ( ( MASA_MAXIMUM_DIRECTIONS + MAX_NUM_OBJECTS ) * 3 ) /* == max number of simultaneous directions * 3 */ +#define MAX_GAIN_CACHE_SIZE ( ( MASA_MAXIMUM_DIRECTIONS * 3 ) + MAX_NUM_OBJECTS ) /* == different calls to get gains */ #else #define MAX_GAIN_CACHE_SIZE 6 #endif @@ -814,6 +814,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric int16_t dirac_read_idx; float subFrameTotalEne[CLDFB_NO_CHANNELS_MAX]; PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_GAIN_CACHE_SIZE]; +#ifdef MASA_AND_OBJECTS + int16_t gainCacheBaseIndex; +#endif hDirAC = st_ivas->hDirAC; h = st_ivas->hDiracDecBin; @@ -952,6 +955,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric eleDeg = hDirAC->elevation[dirac_read_idx][bin]; ratio = hDirAC->energy_ratio1[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence[dirac_read_idx][bin]; +#ifdef MASA_AND_OBJECTS + gainCacheBaseIndex = 0; +#endif } #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format != MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_ISM_FORMAT && dirIndex < hDirAC->numParametricDirections ) ) /* For second of the two simultaneous directions */ @@ -970,6 +976,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric aziDeg = hDirAC->azimuth2[dirac_read_idx][bin]; eleDeg = hDirAC->elevation2[dirac_read_idx][bin]; spreadCoh = hDirAC->spreadCoherence2[dirac_read_idx][bin]; +#ifdef MASA_AND_OBJECTS + gainCacheBaseIndex = 3; +#endif } #ifdef MASA_AND_OBJECTS else /* For object directions of MASA_ISM_FORMAT */ @@ -989,6 +998,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; spreadCoh = 0.0f; + gainCacheBaseIndex = 6 + ismDirIndex; } #endif @@ -1024,7 +1034,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric spreadCoh = max( spreadCoh, altSpreadCoh ); } +#ifdef MASA_AND_OBJECTS + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex], isHeadtracked ); +#else getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 )], isHeadtracked ); +#endif if ( h->renderStereoOutputInsteadOfBinaural ) { @@ -1067,7 +1081,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric rImagp *= centerMul; /* Apply the gain for the left source of the three coherent sources */ +#ifdef MASA_AND_OBJECTS + getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 1], isHeadtracked ); +#else getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 1 )], isHeadtracked ); +#endif hrtfEneSides = ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp ); lRealp += sidesMul * lRealpTmp; @@ -1077,7 +1095,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Apply the gain for the right source of the three coherent sources. * -30 degrees to 330 wrapping due to internal functions. */ +#ifdef MASA_AND_OBJECTS + getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 2], isHeadtracked ); +#else getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 2 )], isHeadtracked ); +#endif hrtfEneSides += ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp ); lRealp += sidesMul * lRealpTmp; @@ -1293,7 +1315,12 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( int16_t dirac_read_idx; #endif DIRAC_DEC_BIN_HANDLE h; +#ifdef MASA_AND_OBJECTS + PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_NUM_OBJECTS]; + int16_t idx; +#else PARAMBIN_HRTF_GAIN_CACHE gainCache; +#endif h = st_ivas->hDiracDecBin; #ifdef MASA_AND_OBJECTS @@ -1320,7 +1347,14 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; #endif +#ifdef MASA_AND_OBJECTS + for ( idx = 0; idx < MAX_NUM_OBJECTS; idx++ ) + { + gainCache[idx].azi = -1000; /* Use -1000 as value for uninitialized cache. */ + } +#else gainCache.azi = -1000; /* Use -1000 as value for uninitialized cache. */ +#endif for ( bin = 0; bin < nBins; bin++ ) { @@ -1491,7 +1525,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( h->processMtxImPrev[chA][chB + 2][bin] = h->processMtxIm[chA][chB + 2][bin]; } - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache, isHeadtracked ); + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); h->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; h->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; -- GitLab From 94397413be32f288f0dc137bfc88c759d18d1014 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 15 Jun 2023 15:21:41 +0300 Subject: [PATCH 123/173] Remove todo-comments as the related values are in use. --- lib_rend/ivas_dirac_dec_binaural_functions.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index e418af9d52..e4b70bf588 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -53,8 +53,8 @@ *------------------------------------------------------------------------*/ #define CLDFB_HALF_BIN_FREQUENCY_OFFSET 0.5f -#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) // ToDo: not used -#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) // ToDo: not used +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN ( 2.0f ) +#define IVAS_TDET_DUCK_MULT_FAC_PARA_BIN_LOW_BR ( 3.0f ) #ifdef MASA_AND_OBJECTS #define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) -- GitLab From 8e498c6fa40a3026d045487608c62b1971c4d3f9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 15 Jun 2023 18:50:43 +0200 Subject: [PATCH 124/173] clang-format --- lib_dec/ivas_masa_dec.c | 80 +++++++-------- lib_dec/ivas_stat_dec.h | 2 +- lib_enc/ivas_ism_metadata_enc.c | 22 ++--- lib_enc/ivas_omasa_enc.c | 2 +- lib_rend/lib_rend.c | 166 ++++++++++++++++---------------- 5 files changed, 136 insertions(+), 136 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index bec64941b9..8499f4504a 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -605,10 +605,10 @@ ivas_error ivas_masa_decode( /*-------------------------------------------------------------------* - * ivas_masa_dec_open() - * - * - *-------------------------------------------------------------------*/ + * ivas_masa_dec_open() + * + * + *-------------------------------------------------------------------*/ ivas_error ivas_masa_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ @@ -706,10 +706,10 @@ ivas_error ivas_masa_dec_open( /*-----------------------------------------------------------------------* - * ivas_masa_dec_close() - * - * close MASA decoder - *-----------------------------------------------------------------------*/ + * ivas_masa_dec_close() + * + * close MASA decoder + *-----------------------------------------------------------------------*/ void ivas_masa_dec_close( MASA_DECODER_HANDLE *hMasa_out /* i/o: MASA metadata structure */ @@ -771,10 +771,10 @@ void ivas_masa_dec_close( /*-------------------------------------------------------------------* - * ivas_masa_dec_config() - * - * Frame-by-frame configuration of MASA decoder - *-------------------------------------------------------------------*/ + * ivas_masa_dec_config() + * + * Frame-by-frame configuration of MASA decoder + *-------------------------------------------------------------------*/ static ivas_error ivas_masa_dec_config( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ @@ -884,10 +884,10 @@ static ivas_error ivas_masa_dec_config( /*-------------------------------------------------------------------* - * ivas_masa_prerender() - * - * Apply gaining and copying of transport signals when needed - *-------------------------------------------------------------------*/ + * ivas_masa_prerender() + * + * Apply gaining and copying of transport signals when needed + *-------------------------------------------------------------------*/ void ivas_masa_prerender( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -915,8 +915,8 @@ void ivas_masa_prerender( /*-------------------------------------------------------------------* - * Local functions - *-------------------------------------------------------------------*/ + * Local functions + *-------------------------------------------------------------------*/ static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, @@ -1074,7 +1074,7 @@ static ivas_error init_lfe_synth_data( int16_t slot_size; /* Ring buffer for the filterbank of the LFE synthesis. - * The filterbank is using moving average lowpass filter with the crossover of 120 Hz. */ + * The filterbank is using moving average lowpass filter with the crossover of 120 Hz. */ bufferSize = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES ); if ( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) { @@ -1087,7 +1087,7 @@ static ivas_error init_lfe_synth_data( hMasa->hMasaLfeSynth->ringBufferSize = bufferSize; /* Ring buffer for additional lowpass filter for the LFE signal. - * Moving average lowpass filter with the crossover of 240 Hz. */ + * Moving average lowpass filter with the crossover of 240 Hz. */ bufferSize /= 2; if ( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer2 = (float *) malloc( bufferSize * sizeof( float ) ) ) == NULL ) { @@ -1273,10 +1273,10 @@ static int16_t decode_lfe_to_total_energy_ratio( /*-------------------------------------------------------------------* - * ivas_masa_dec_reconfigure() - * - * Reconfigure IVAS MASA decoder - *-------------------------------------------------------------------*/ + * ivas_masa_dec_reconfigure() + * + * Reconfigure IVAS MASA decoder + *-------------------------------------------------------------------*/ ivas_error ivas_masa_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -1319,8 +1319,8 @@ ivas_error ivas_masa_dec_reconfigure( /* possible reconfigure is done later */ /*-----------------------------------------------------------------* - * Allocate and initialize SCE/CPE and other handles - *-----------------------------------------------------------------*/ + * Allocate and initialize SCE/CPE and other handles + *-----------------------------------------------------------------*/ bit_stream = st_ivas->hSCE[0] != NULL ? st_ivas->hSCE[0]->hCoreCoder[0]->bit_stream : st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream; @@ -1385,8 +1385,8 @@ ivas_error ivas_masa_dec_reconfigure( { #endif /*-----------------------------------------------------------------* - * TD Decorrelator - *-----------------------------------------------------------------*/ + * TD Decorrelator + *-----------------------------------------------------------------*/ if ( st_ivas->hDiracDecBin != NULL ) { @@ -1397,8 +1397,8 @@ ivas_error ivas_masa_dec_reconfigure( } /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ + * CLDFB instances + *-----------------------------------------------------------------*/ if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) { @@ -1406,8 +1406,8 @@ ivas_error ivas_masa_dec_reconfigure( } /*-----------------------------------------------------------------* - * Set-up MASA coding elements and bitrates - *-----------------------------------------------------------------*/ + * Set-up MASA coding elements and bitrates + *-----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS } #endif @@ -1467,10 +1467,10 @@ ivas_error ivas_masa_dec_reconfigure( /*-------------------------------------------------------------------* - * ivas_spar_param_to_masa_param_mapping() - * - * Determine MASA metadata from the SPAR metadata - *-------------------------------------------------------------------*/ + * ivas_spar_param_to_masa_param_mapping() + * + * Determine MASA metadata from the SPAR metadata + *-------------------------------------------------------------------*/ void ivas_spar_param_to_masa_param_mapping( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ @@ -2416,10 +2416,10 @@ static int16_t ivas_decode_masaism_metadata( /*-------------------------------------------------------------------* - * ivas_masa_ism_set_edited_objects() - * - * - *-------------------------------------------------------------------*/ + * ivas_masa_ism_set_edited_objects() + * + * + *-------------------------------------------------------------------*/ void ivas_masa_ism_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a551ab7f9b..74a757f0b5 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1237,7 +1237,7 @@ typedef struct decoder_config_structure int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ float non_diegetic_pan_gain; /* non diegetic panning gain*/ int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ + int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ /* temp. development parameters */ #ifdef DEBUGGING diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 199fd99098..53f0dd7941 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -452,8 +452,8 @@ ivas_error ivas_ism_metadata_enc( if ( ism_metadata_flag_global ) { /*----------------------------------------------------------------* - * Metadata quantization and coding, loop over all objects - *----------------------------------------------------------------*/ + * Metadata quantization and coding, loop over all objects + *----------------------------------------------------------------*/ int16_t total_bits_metadata = 0; int16_t bits_metadata_ism = 0; @@ -529,8 +529,8 @@ ivas_error ivas_ism_metadata_enc( encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); /*----------------------------------------------------------------* - * Quantize and encode radius, yaw, and pitch - *----------------------------------------------------------------*/ + * Quantize and encode radius, yaw, and pitch + *----------------------------------------------------------------*/ if ( ism_mode == ISM_MODE_DISC && ism_extended_metadata_flag ) { @@ -561,9 +561,9 @@ ivas_error ivas_ism_metadata_enc( } /*----------------------------------------------------------------* - * inter-object logic minimizing the use of several absolutely coded - * indexes in the same frame - *----------------------------------------------------------------*/ + * inter-object logic minimizing the use of several absolutely coded + * indexes in the same frame + *----------------------------------------------------------------*/ i = 0; while ( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) @@ -683,8 +683,8 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS /*----------------------------------------------------------------* - * Take into account the combined format bit-budget distribution - *----------------------------------------------------------------*/ + * Take into account the combined format bit-budget distribution + *----------------------------------------------------------------*/ if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { @@ -736,8 +736,8 @@ ivas_error ivas_ism_metadata_enc( #endif /*----------------------------------------------------------------* - * Configuration and decision about bitrates per channel - *----------------------------------------------------------------*/ + * Configuration and decision about bitrates per channel + *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 714054d977..c10ec862c5 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -731,7 +731,7 @@ void ivas_set_surplus_brate_enc( /*--------------------------------------------------------------------------* * ivas_omasa_ener_brate() * - * + * *--------------------------------------------------------------------------*/ /*! r: OMASA energy bitrate flag */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index fff3f11ce4..540072679f 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -4407,14 +4407,14 @@ static void renderBufferChannel( } static ivas_error rotateFrameMc( - IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ - IVAS_REND_AudioConfig inConfig, /* i : Input Audio config */ - LSSETUP_CUSTOM_STRUCT inCustomLs, /* i : Input Custom LS setup */ - const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ + IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ + IVAS_REND_AudioConfig inConfig, /* i : Input Audio config */ + LSSETUP_CUSTOM_STRUCT inCustomLs, /* i : Input Custom LS setup */ + const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ - rotation_gains gains_prev, /* i/o: Previous frame rotation gains */ - const EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ - IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ + rotation_gains gains_prev, /* i/o: Previous frame rotation gains */ + const EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ ) { int16_t i; @@ -4544,12 +4544,12 @@ static ivas_error rotateFrameMc( } static ivas_error rotateFrameSba( - IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ - IVAS_REND_AudioConfig inConfig, /* i : Input Audio config */ - const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ + IVAS_REND_AudioBuffer inAudio, /* i : Input Audio buffer */ + IVAS_REND_AudioConfig inConfig, /* i : Input Audio config */ + const IVAS_REND_HeadRotData *headRotData, /* i : Head rotation data */ const COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* i : Combined head and external orientations */ - rotation_gains gains_prev, /* i/o: Previous frame rotation gains */ - IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ + rotation_gains gains_prev, /* i/o: Previous frame rotation gains */ + IVAS_REND_AudioBuffer outAudio /* o : Output Audio buffer */ ) { int16_t i, l, n, m; @@ -4734,97 +4734,97 @@ static ivas_error renderIsmToBinauralRoom( } - if ( combinedOrientationEnabled ) + if ( combinedOrientationEnabled ) + { + subframe_len = ismInput->base.inputBuffer.config.numSamplesPerChannel / RENDERER_HEAD_POSITIONS_PER_FRAME; + // for ( subframe_idx = 0; subframe_idx < RENDERER_HEAD_POSITIONS_PER_FRAME; subframe_idx++ ) + for ( subframe_idx = 0; subframe_idx < 1; subframe_idx++ ) { - subframe_len = ismInput->base.inputBuffer.config.numSamplesPerChannel / RENDERER_HEAD_POSITIONS_PER_FRAME; - // for ( subframe_idx = 0; subframe_idx < RENDERER_HEAD_POSITIONS_PER_FRAME; subframe_idx++ ) - for ( subframe_idx = 0; subframe_idx < 1; subframe_idx++ ) + for ( i = 0; i < 3; i++ ) { - for ( i = 0; i < 3; i++ ) + if ( hCombinedOrientationData != NULL && ( *hCombinedOrientationData )->enableCombinedOrientation[subframe_idx] ) { - if ( hCombinedOrientationData != NULL && ( *hCombinedOrientationData )->enableCombinedOrientation[subframe_idx] ) - { - for ( j = 0; j < 3; j++ ) - { - Rmat[i][j] = ( *hCombinedOrientationData )->Rmat[subframe_idx][i][j]; - } - } - else + for ( j = 0; j < 3; j++ ) { - /* Set to identity */ - set_zero( Rmat[i], 3 ); - Rmat[i][i] = 1.0f; + Rmat[i][j] = ( *hCombinedOrientationData )->Rmat[subframe_idx][i][j]; } } + else + { + /* Set to identity */ + set_zero( Rmat[i], 3 ); + Rmat[i][i] = 1.0f; + } } - (void) subframe_len; // avoid warning } + (void) subframe_len; // avoid warning + } - /* TODO tmu : see issue #518 */ - /* Possible optimization: less processing needed if position didn't change - * needs a lot of cleanup, we could also add rot_gains_prev to ismInput and use that */ - /* previous position gains */ - if ( combinedOrientationEnabled ) - { - rotateAziEle( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &azi_rot, &ele_rot, ismInput->rot_mat_prev, 0 ); - rotatedPos.azimuth = (float) azi_rot; - rotatedPos.elevation = (float) ele_rot; - } + /* TODO tmu : see issue #518 */ + /* Possible optimization: less processing needed if position didn't change + * needs a lot of cleanup, we could also add rot_gains_prev to ismInput and use that */ + /* previous position gains */ + if ( combinedOrientationEnabled ) + { + rotateAziEle( ismInput->previousPos.azimuth, ismInput->previousPos.elevation, &azi_rot, &ele_rot, ismInput->rot_mat_prev, 0 ); + rotatedPos.azimuth = (float) azi_rot; + rotatedPos.elevation = (float) ele_rot; + } - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->previousPos.azimuth, - ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->previousPos.elevation, - previousPanGains ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->previousPos.azimuth, + ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->previousPos.elevation, + previousPanGains ) ) != IVAS_ERR_OK ) + { + return error; + } - /* current position gains */ - if ( combinedOrientationEnabled ) - { - rotateAziEle( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, &azi_rot, &ele_rot, Rmat, 0 ); - rotatedPos.azimuth = (float) azi_rot; - rotatedPos.elevation = (float) ele_rot; - } + /* current position gains */ + if ( combinedOrientationEnabled ) + { + rotateAziEle( ismInput->currentPos.azimuth, ismInput->currentPos.elevation, &azi_rot, &ele_rot, Rmat, 0 ); + rotatedPos.azimuth = (float) azi_rot; + rotatedPos.elevation = (float) ele_rot; + } - if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, - ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, - ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, - currentPanGains ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getEfapGains( *ismInput->base.ctx.pEfapOutWrapper, + ( combinedOrientationEnabled ) ? rotatedPos.azimuth : ismInput->currentPos.azimuth, + ( combinedOrientationEnabled ) ? rotatedPos.elevation : ismInput->currentPos.elevation, + currentPanGains ) ) != IVAS_ERR_OK ) + { + return error; + } - for ( i = 0; i < 3; i++ ) - { - mvr2r( Rmat[i], ismInput->rot_mat_prev[i], 3 ); - } + for ( i = 0; i < 3; i++ ) + { + mvr2r( Rmat[i], ismInput->rot_mat_prev[i], 3 ); + } - /* intermediate rendering to 7_1_4 */ - tmpMcBuffer = ismInput->base.inputBuffer; + /* intermediate rendering to 7_1_4 */ + tmpMcBuffer = ismInput->base.inputBuffer; - if ( ( error = getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = getAudioConfigNumChannels( IVAS_REND_AUDIO_CONFIG_7_1_4, &tmp ) ) != IVAS_ERR_OK ) + { + return error; + } - 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 ); + 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 ); - renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, tmpMcBuffer ); + renderBufferChannelLerp( ismInput->base.inputBuffer, 0, currentPanGains, previousPanGains, tmpMcBuffer ); - copyBufferTo2dArray( tmpMcBuffer, tmpRendBuffer ); + copyBufferTo2dArray( tmpMcBuffer, tmpRendBuffer ); - if ( ( error = ivas_rend_crendProcess( ismInput->crendWrapper, AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM_IR, - NULL, NULL, NULL, NULL, p_tmpRendBuffer, *ismInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_rend_crendProcess( ismInput->crendWrapper, AUDIO_CONFIG_7_1_4, AUDIO_CONFIG_BINAURAL_ROOM_IR, + NULL, NULL, NULL, NULL, p_tmpRendBuffer, *ismInput->base.ctx.pOutSampleRate ) ) != IVAS_ERR_OK ) + { + return error; + } - accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); + accumulate2dArrayToBuffer( tmpRendBuffer, &outAudio ); - free( tmpMcBuffer.data ); + free( tmpMcBuffer.data ); pop_wmops(); return IVAS_ERR_OK; @@ -5165,7 +5165,7 @@ static ivas_error renderMcToBinaural( if ( ( inConfig == IVAS_REND_AUDIO_CONFIG_LS_CUSTOM ) || ( combinedOrientationEnabled - && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) + && ( inConfig == IVAS_REND_AUDIO_CONFIG_5_1 || inConfig == IVAS_REND_AUDIO_CONFIG_7_1 ) ) ) { copyBufferTo2dArray( mcInput->base.inputBuffer, tmpRendBuffer ); -- GitLab From cc07d42d5bc298aaba4e866cea9acfcd65a7fb7e Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 16 Jun 2023 10:53:07 +0300 Subject: [PATCH 125/173] Adjust max indices for OMASA at 96 kbps --- lib_com/bitstream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index cfc353c1c1..07060b6dd9 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -888,7 +888,7 @@ int16_t get_ivas_max_num_indices_metadata( } else if ( ivas_total_brate <= IVAS_96k ) { - return 240 + 100; + return 240 + 150; } else if ( ivas_total_brate <= IVAS_128k ) { -- GitLab From 8895083f0953edb5c74481c8bd1f17b0cde75618 Mon Sep 17 00:00:00 2001 From: advasila Date: Fri, 16 Jun 2023 13:12:39 +0300 Subject: [PATCH 126/173] fixes 24.4 TD case --- lib_com/ivas_prot.h | 9 +++++++++ lib_com/ivas_stereo_td_bit_alloc.c | 9 ++++++++- lib_com/options.h | 1 + lib_dec/ivas_cpe_dec.c | 3 +++ lib_dec/ivas_stereo_td_dec.c | 9 ++++++++- lib_enc/ivas_cpe_enc.c | 3 +++ lib_enc/ivas_stereo_td_enc.c | 9 ++++++++- 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 487afa699e..11bbdf2616 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1967,6 +1967,9 @@ void stereo_td_init_dec( void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i: ISM mode in combined format */ +#endif #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ @@ -2019,6 +2022,9 @@ void tdm_ol_pitch_comparison( void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i: ISM mode in combined format */ +#endif #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ @@ -2038,6 +2044,9 @@ ivas_error signaling_enc_secondary( void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i: ISM mode in combined format */ +#endif #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index a2bbd93997..dfd004ab9b 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -75,7 +75,10 @@ void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS - const int16_t ivas_format, /* i : IVAS format */ + const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i: ISM mode in combined format */ +#endif #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ @@ -140,7 +143,11 @@ void tdm_bit_alloc( /* secondary channel bitrate allocation based on the energy scaling ratio */ #ifdef MASA_AND_OBJECTS +#ifdef FIX_OMASA_24_4k + if ( ( ( ivas_format != MASA_ISM_FORMAT || ism_mode == ISM_MODE_NONE ) && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && coder_type > UNVOICED ) ) +#else if ( ( ivas_format != MASA_ISM_FORMAT && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && coder_type > UNVOICED ) ) +#endif #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) #endif diff --git a/lib_com/options.h b/lib_com/options.h index 5719fe9db0..0bf36cfed3 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -168,6 +168,7 @@ #define FIX_OMASA_STEREO_SWITCHING /* VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps */ #define FIX_OMASA_BRSW /* Nokia + VA: Fix missing init of OMASA metadata delay buffers, brsw-related init fixes */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix +#define FIX_OMASA_24_4k /* Nokia: fix OMASA in TD mode at 24.4k */ #endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index d15eb5b6a1..c72b8564e1 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -439,6 +439,9 @@ ivas_error ivas_cpe_dec( tdm_configure_dec( #ifdef MASA_AND_OBJECTS st_ivas->ivas_format, +#ifdef FIX_OMASA_24_4k + st_ivas->ism_mode, +#endif #endif hCPE, &tdm_ratio_idx, nb_bits_metadata ); diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 1b90885b0f..424570ec50 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -86,6 +86,9 @@ void stereo_td_init_dec( void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i : ISM mode in combined format */ +#endif #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ @@ -308,7 +311,11 @@ void tdm_configure_dec( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( ivas_format, hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + tdm_bit_alloc( ivas_format, +#ifdef FIX_OMASA_24_4k + ism_mode, +#endif + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 92ef3e3ba7..95cf49d570 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -615,6 +615,9 @@ ivas_error ivas_cpe_enc( tdm_configure_enc( #ifdef MASA_AND_OBJECTS ivas_format, +#ifdef FIX_OMASA_24_4k + st_ivas->ism_mode, +#endif #endif hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 7124bb7171..b01be07253 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -312,6 +312,9 @@ ivas_error stereo_set_tdm( void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ +#ifdef FIX_OMASA_24_4k + const int16_t ism_mode, /* i : ISM mode in combined format */ +#endif #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ @@ -492,7 +495,11 @@ void tdm_configure_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( ivas_format, hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + tdm_bit_alloc( ivas_format, +#ifdef FIX_OMASA_24_4k + ism_mode, +#endif + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); -- GitLab From e1b789c6e73fba9bf90378a5764d03652008cf87 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 16 Jun 2023 13:33:03 +0300 Subject: [PATCH 127/173] Apply clang format --- lib_com/ivas_stereo_td_bit_alloc.c | 4 ++-- lib_dec/ivas_stereo_td_dec.c | 8 ++++---- lib_enc/ivas_stereo_td_enc.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index dfd004ab9b..345fef4b3a 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -75,9 +75,9 @@ void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS - const int16_t ivas_format, /* i : IVAS format */ + const int16_t ivas_format, /* i : IVAS format */ #ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i: ISM mode in combined format */ + const int16_t ism_mode, /* i: ISM mode in combined format */ #endif #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index 424570ec50..e90baa0dd8 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -87,7 +87,7 @@ void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i : ISM mode in combined format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ @@ -313,9 +313,9 @@ void tdm_configure_dec( #ifdef MASA_AND_OBJECTS tdm_bit_alloc( ivas_format, #ifdef FIX_OMASA_24_4k - ism_mode, -#endif - hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, + ism_mode, +#endif + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, tdm_inst_ratio_idx ); diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index b01be07253..071ef6d361 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -313,7 +313,7 @@ void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ #ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i : ISM mode in combined format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ @@ -495,11 +495,11 @@ void tdm_configure_enc( *----------------------------------------------------------------*/ #ifdef MASA_AND_OBJECTS - tdm_bit_alloc( ivas_format, + tdm_bit_alloc( ivas_format, #ifdef FIX_OMASA_24_4k ism_mode, -#endif - hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, +#endif + hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, sts[0]->bwidth, sts[1]->bwidth, sts[0]->flag_ACELP16k, hStereoTD->tdm_LRTD_flag, mod_ct, hStereoTD->tdm_inst_ratio_idx ); -- GitLab From 7f6ff11363698bb30ed211641bcc4427f8036af3 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Mon, 19 Jun 2023 22:38:25 +0300 Subject: [PATCH 128/173] Disable switch ISM_FB until fixed. --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 17d991b02e..6c21f34ee5 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,7 @@ #define FIX_549_DMX_GAIN /* FhG: issue 549: ParamISM output too quiet */ #define FIX_522_ISM_FIRST_SID /* VA: fix ISM decoder crash if first received frame is an SID */ #define FIX_470_MASA_JBM_EXT /* Nokia: Issue 470, fix MASA EXT output with JBM */ -#define ISM_FB /* issue 556: change SWB to FB coding in 1ISM at 24.4 kbps */ +//#define ISM_FB /* issue 556: change SWB to FB coding in 1ISM at 24.4 kbps */ #define FIX_558_PLC_DISCONT /* FhG: issue 558: fix discontinuities in DFT Stereo when switching from TCX concealment to ACELP */ #define FIX_564 /* Nokia: Issue 564: Fix gains in JBM path for SBA with parametric binaural renderer */ #define FIX_566_2DIR_MASA_384K /* Nokia: Issued 566: Bugfix in 384k MASA metadata encoding of second direction */ -- GitLab From 3ac4d187461327e099adc47006eef7e99472b882 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Jun 2023 13:16:18 +0200 Subject: [PATCH 129/173] - fix setting of "is_ism_flag" in CPE - activate ISM_FB --- lib_com/options.h | 2 +- lib_enc/ivas_cpe_enc.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 6c21f34ee5..17d991b02e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,7 @@ #define FIX_549_DMX_GAIN /* FhG: issue 549: ParamISM output too quiet */ #define FIX_522_ISM_FIRST_SID /* VA: fix ISM decoder crash if first received frame is an SID */ #define FIX_470_MASA_JBM_EXT /* Nokia: Issue 470, fix MASA EXT output with JBM */ -//#define ISM_FB /* issue 556: change SWB to FB coding in 1ISM at 24.4 kbps */ +#define ISM_FB /* issue 556: change SWB to FB coding in 1ISM at 24.4 kbps */ #define FIX_558_PLC_DISCONT /* FhG: issue 558: fix discontinuities in DFT Stereo when switching from TCX concealment to ACELP */ #define FIX_564 /* Nokia: Issue 564: Fix gains in JBM path for SBA with parametric binaural renderer */ #define FIX_566_2DIR_MASA_384K /* Nokia: Issued 566: Bugfix in 384k MASA metadata encoding of second direction */ diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index bb6db6d9a4..86e85b34e7 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -990,7 +990,13 @@ ivas_error create_cpe_enc( #ifdef IND_LIST_DYN st_ivas, #endif - n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, st_ivas->ism_mode ) ) != IVAS_ERR_OK ) + n, hEncoderConfig->var_SID_rate_flag, hEncoderConfig->interval_SID, 0, +#ifdef MASA_AND_OBJECTS + ISM_MODE_NONE +#else + st_ivas->ism_mode +#endif + ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 54b8badada65cb8251eb8d1e8c3dc4a051bbf04a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Jun 2023 13:37:53 +0200 Subject: [PATCH 130/173] intorduce funtions stereo_mode_combined_format_enc()/stereo_mode_combined_format_dec() make the code easier to read --- lib_dec/ivas_cpe_dec.c | 78 ++++++++++++++++++++---------- lib_enc/ivas_cpe_enc.c | 105 ++++++++++++++++++++++++++++------------- 2 files changed, 123 insertions(+), 60 deletions(-) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 989bc40b41..bc0bb3c5b4 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -52,6 +52,10 @@ static void read_stereo_mode_and_bwidth( CPE_DEC_HANDLE hCPE, const Decoder_Struct *st_ivas ); +#ifdef FIX_OMASA_STEREO_SWITCHING +static void stereo_mode_combined_format_dec( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE ); +#endif + /*--------------------------------------------------------------------------* * ivas_cpe_dec() @@ -98,9 +102,6 @@ ivas_error ivas_cpe_dec( sts[0]->BER_detect |= st_ivas->BER_detect; sts[1]->BER_detect |= st_ivas->BER_detect; -#ifdef FIX_OMASA_STEREO_SWITCHING - element_brate_ref = hCPE->element_brate; -#endif #ifdef FIX_OMASA_STEREO_SWITCHING element_brate_ref = hCPE->element_brate; @@ -109,31 +110,11 @@ ivas_error ivas_cpe_dec( /*------------------------------------------------------------------* * Read stereo technology info & audio bandwidth *-----------------------------------------------------------------*/ -#ifdef FIX_OMASA_STEREO_SWITCHING - if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) - { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && - ( ( st_ivas->nchan_ism == 3 && ivas_total_brate == IVAS_96k ) || - ( st_ivas->nchan_ism == 4 && ivas_total_brate == IVAS_128k ) ) ) - { - /* read OMASA stereo mode signalling */ - if ( get_next_indice( sts[0], NBITS_ELEMENT_MODE ) ) - { - hCPE->element_mode = IVAS_CPE_MDCT; - } - else - { - hCPE->element_mode = IVAS_CPE_DFT; - } - if ( hCPE->element_mode == IVAS_CPE_MDCT ) - { - hCPE->element_brate = IVAS_64k; - hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); - } - } - } +#ifdef FIX_OMASA_STEREO_SWITCHING + stereo_mode_combined_format_dec( st_ivas, hCPE ); #endif + read_stereo_mode_and_bwidth( hCPE, st_ivas ); /*----------------------------------------------------------------* @@ -1168,3 +1149,48 @@ static void read_stereo_mode_and_bwidth( return; } + + +#ifdef FIX_OMASA_STEREO_SWITCHING +/*------------------------------------------------------------------------- + * stereo_mode_combined_format_dec() + * + * Set stereo format in a combined format + *-------------------------------------------------------------------------*/ + +static void stereo_mode_combined_format_dec( + const Decoder_Struct *st_ivas, /* i : decoder main structure */ + CPE_DEC_HANDLE hCPE /* i/o: CPE handle */ +) +{ + int32_t element_brate_ref; + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + element_brate_ref = hCPE->element_brate; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && + ( ( st_ivas->nchan_ism == 3 && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_96k ) || + ( st_ivas->nchan_ism == 4 && st_ivas->hDecoderConfig->ivas_total_brate == IVAS_128k ) ) ) + { + /* read OMASA stereo mode signalling */ + if ( get_next_indice( hCPE->hCoreCoder[0], NBITS_ELEMENT_MODE ) ) + { + hCPE->element_mode = IVAS_CPE_MDCT; + } + else + { + hCPE->element_mode = IVAS_CPE_DFT; + } + + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + hCPE->element_brate = IVAS_64k; + hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); + } + } + } + + return; +} +#endif diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 86e85b34e7..84f28f28be 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -45,6 +45,15 @@ #include "wmc_auto.h" +#ifdef FIX_OMASA_STEREO_SWITCHING +/*--------------------------------------------------------------------------* + * Local function prototypes + *--------------------------------------------------------------------------*/ + +static void stereo_mode_combined_format_enc( const Encoder_Struct *st_ivas, CPE_ENC_HANDLE hCPE ); +#endif + + /*-------------------------------------------------------------------* * ivas_cpe_enc() * @@ -176,42 +185,11 @@ ivas_error ivas_cpe_enc( { hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } -#ifdef FIX_OMASA_STEREO_SWITCHING - if ( ivas_format == MASA_ISM_FORMAT ) - { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && - ( ( hEncoderConfig->nchan_ism == 3 && ivas_total_brate == IVAS_96k ) || - ( hEncoderConfig->nchan_ism == 4 && ivas_total_brate == IVAS_128k ) ) ) - { - if ( hCPE->element_brate + hCPE->brate_surplus > IVAS_64k ) - { - st_ivas->hMasa->data.omasa_stereo_sw_cnt = 0; - } - else - { - st_ivas->hMasa->data.omasa_stereo_sw_cnt++; - st_ivas->hMasa->data.omasa_stereo_sw_cnt = min( st_ivas->hMasa->data.omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); - } - if ( st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) - { - hCPE->element_mode = IVAS_CPE_MDCT; - hCPE->element_brate = IVAS_64k; - hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); - } - - /* write OMASA stereo mode signalling */ - if ( hCPE->element_mode == IVAS_CPE_MDCT ) - { - push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 1, NBITS_ELEMENT_MODE ); - } - else - { - push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 0, NBITS_ELEMENT_MODE ); - } - } - } +#ifdef FIX_OMASA_STEREO_SWITCHING + stereo_mode_combined_format_enc( st_ivas, hCPE ); #endif + if ( ( error = front_vad( hCPE, NULL, hEncoderConfig, &hCPE->hFrontVad[0], st_ivas->hMCT != NULL, input_frame, vad_flag_dtx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, vad_hover_flag, band_energies_LR, NULL, NULL ) ) != IVAS_ERR_OK ) { return error; @@ -1232,3 +1210,62 @@ void destroy_cpe_enc( return; } + + +#ifdef FIX_OMASA_STEREO_SWITCHING +/*------------------------------------------------------------------------- + * stereo_mode_combined_format_enc() + * + * Set stereo format in a combined format + *-------------------------------------------------------------------------*/ + +static void stereo_mode_combined_format_enc( + const Encoder_Struct *st_ivas, /* i : encoder main structure */ + CPE_ENC_HANDLE hCPE /* i/o: CPE handle */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + int32_t element_brate_ref; + + hEncoderConfig = st_ivas->hEncoderConfig; + + if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + element_brate_ref = hCPE->element_brate; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && + ( ( hEncoderConfig->nchan_ism == 3 && hEncoderConfig->ivas_total_brate == IVAS_96k ) || + ( hEncoderConfig->nchan_ism == 4 && hEncoderConfig->ivas_total_brate == IVAS_128k ) ) ) + { + if ( hCPE->element_brate + hCPE->brate_surplus > IVAS_64k ) + { + st_ivas->hMasa->data.omasa_stereo_sw_cnt = 0; + } + else + { + st_ivas->hMasa->data.omasa_stereo_sw_cnt++; + st_ivas->hMasa->data.omasa_stereo_sw_cnt = min( st_ivas->hMasa->data.omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); + } + + if ( st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + { + hCPE->element_mode = IVAS_CPE_MDCT; + hCPE->element_brate = IVAS_64k; + hCPE->brate_surplus -= ( hCPE->element_brate - element_brate_ref ); + } + + /* write OMASA stereo mode signalling */ + if ( hCPE->element_mode == IVAS_CPE_MDCT ) + { + push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 1, NBITS_ELEMENT_MODE ); + } + else + { + push_indice( hCPE->hCoreCoder[0]->hBstr, IND_SMODE_OMASA, 0, NBITS_ELEMENT_MODE ); + } + } + } + + return; +} +#endif -- GitLab From 4a43f57b7bef7696ef73dbeb96174471f252c1bc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 20 Jun 2023 15:15:01 +0200 Subject: [PATCH 131/173] clan-format --- lib_dec/lib_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 849cc416b4..e6b4f977f8 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2579,7 +2579,7 @@ static ivas_error printConfigInfo_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MC_FORMAT ) #else - else /* MC_FORMAT */ + else /* MC_FORMAT */ #endif { if ( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ) != IVAS_ERR_OK ) -- GitLab From 926dddd71f71da0be0357d789bd2a34cd554ba1a Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 21 Jun 2023 10:37:30 +0300 Subject: [PATCH 132/173] Consolidate switches within OMASA --- lib_com/cnst.h | 2 +- lib_com/ivas_cnst.h | 4 +-- lib_com/ivas_prot.h | 31 +++++++--------------- lib_com/ivas_stereo_td_bit_alloc.c | 6 ----- lib_com/options.h | 4 --- lib_dec/ivas_cpe_dec.c | 14 ++++------ lib_dec/ivas_init_dec.c | 2 +- lib_dec/ivas_masa_dec.c | 2 -- lib_dec/ivas_omasa_dec.c | 38 +-------------------------- lib_dec/ivas_stat_dec.h | 13 +++++----- lib_dec/ivas_stereo_td_dec.c | 4 --- lib_enc/ivas_cpe_enc.c | 14 ++++------ lib_enc/ivas_enc.c | 41 +++++------------------------- lib_enc/ivas_ism_enc.c | 24 +++-------------- lib_enc/ivas_ism_metadata_enc.c | 17 +++---------- lib_enc/ivas_masa_enc.c | 10 -------- lib_enc/ivas_omasa_enc.c | 2 -- lib_enc/ivas_stat_enc.h | 2 -- lib_enc/ivas_stereo_td_enc.c | 4 --- 19 files changed, 44 insertions(+), 190 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 9881b9d038..0f20b0a647 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -263,7 +263,7 @@ enum{ enum { IND_IVAS_FORMAT, -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS IND_SMODE_OMASA, #endif IND_SMODE, diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 3d5ee66a48..a6e80bb1a5 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -363,7 +363,7 @@ typedef enum #ifdef MASA_AND_OBJECTS #define BRATE_ISM_INACTIVE 2450 /* CoreCoder bitrate in ISM no meta / inactive frames */ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS #define ADJUST_ISM_BRATE_NEG 6000 #define ADJUST_ISM_BRATE_POS 8000 #endif @@ -1280,7 +1280,7 @@ enum #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #ifdef MASA_AND_OBJECTS #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS #define OMASA_STEREO_SW_CNT_MAX 100 #define OMASA_STEREO_SW_CNT_MAX2 5 #endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index f339361592..52ed50f3b9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -969,7 +969,7 @@ ivas_error ivas_ism_enc( float data[MAX_NUM_OBJECTS][L_FRAME48k], /* i : input signal */ const int16_t input_frame, /* i : input frame length per channel */ int16_t *nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS , const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif @@ -992,14 +992,10 @@ ivas_error ivas_ism_metadata_enc( const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Config Handle */ const int16_t ism_extended_metadata_flag /* i : Extended metadata flag */ #ifdef MASA_AND_OBJECTS - ,const float lp_noise_CPE /* i : LP filterend total noise estimation */ -#ifdef OMASA_ENERGIES , - const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ -#endif -#ifdef FIX_OMASA_STEREO_SWITCHING - ,int16_t *omasa_stereo_sw_cnt -#endif + const float lp_noise_CPE, /* i : LP filterend total noise estimation */ + const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + int16_t *omasa_stereo_sw_cnt #endif ); @@ -1988,9 +1984,7 @@ void stereo_td_init_dec( void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i: ISM mode in combined format */ -#endif + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ @@ -2043,9 +2037,7 @@ void tdm_ol_pitch_comparison( void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i: ISM mode in combined format */ -#endif + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ @@ -2065,9 +2057,7 @@ ivas_error signaling_enc_secondary( void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k - const int16_t ism_mode, /* i: ISM mode in combined format */ -#endif + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ @@ -5108,12 +5098,9 @@ ivas_error ivas_masa_encode( ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ - const int16_t ism_imp /* i : importance of separated object */ -#ifdef OMASA_ENERGIES - , + const int16_t ism_imp, /* i : importance of separated object */ const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif -#endif ); void ivas_masa_estimate_energy( @@ -5761,7 +5748,7 @@ void set_ism_importance_interformat( int16_t ism_imp[] /* o : ISM importance flags */ ); -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS /*! r: flag for using less bitrate for objects in OMASA */ int16_t ivas_omasa_ener_brate( const int16_t nchan_ism, /* i : number of ISMs */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 345fef4b3a..b09cfd5384 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -76,9 +76,7 @@ void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k const int16_t ism_mode, /* i: ISM mode in combined format */ -#endif #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ @@ -143,11 +141,7 @@ void tdm_bit_alloc( /* secondary channel bitrate allocation based on the energy scaling ratio */ #ifdef MASA_AND_OBJECTS -#ifdef FIX_OMASA_24_4k if ( ( ( ivas_format != MASA_ISM_FORMAT || ism_mode == ISM_MODE_NONE ) && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && coder_type > UNVOICED ) ) -#else - if ( ( ivas_format != MASA_ISM_FORMAT && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && coder_type > UNVOICED ) ) -#endif #else if ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) #endif diff --git a/lib_com/options.h b/lib_com/options.h index 17d991b02e..2ce5ec26a2 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -172,11 +172,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define OMASA_ENERGIES -#define FIX_OMASA_STEREO_SWITCHING /* VA: introduce Unified/MDCT stereo switching for 3ISM @96 kbps and 4ISM @128 kbps */ -#define FIX_OMASA_BRSW /* Nokia + VA: Fix missing init of OMASA metadata delay buffers, brsw-related init fixes */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix -#define FIX_OMASA_24_4k /* Nokia: fix OMASA in TD mode at 24.4k */ #endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index bc0bb3c5b4..45dfa3a0aa 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -52,7 +52,7 @@ static void read_stereo_mode_and_bwidth( CPE_DEC_HANDLE hCPE, const Decoder_Struct *st_ivas ); -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS static void stereo_mode_combined_format_dec( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE ); #endif @@ -83,9 +83,7 @@ ivas_error ivas_cpe_dec( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t cpe_brate; -#ifdef FIX_OMASA_STEREO_SWITCHING int32_t element_brate_ref; -#endif #endif error = IVAS_ERR_OK; @@ -103,7 +101,7 @@ ivas_error ivas_cpe_dec( sts[0]->BER_detect |= st_ivas->BER_detect; sts[1]->BER_detect |= st_ivas->BER_detect; -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS element_brate_ref = hCPE->element_brate; #endif @@ -111,7 +109,7 @@ ivas_error ivas_cpe_dec( * Read stereo technology info & audio bandwidth *-----------------------------------------------------------------*/ -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS stereo_mode_combined_format_dec( st_ivas, hCPE ); #endif @@ -420,9 +418,7 @@ ivas_error ivas_cpe_dec( tdm_configure_dec( #ifdef MASA_AND_OBJECTS st_ivas->ivas_format, -#ifdef FIX_OMASA_24_4k st_ivas->ism_mode, -#endif #endif hCPE, &tdm_ratio_idx, nb_bits_metadata ); @@ -570,7 +566,7 @@ ivas_error ivas_cpe_dec( hCPE->last_element_brate = hCPE->element_brate; hCPE->last_element_mode = hCPE->element_mode; -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { hCPE->element_brate = element_brate_ref; @@ -1151,7 +1147,7 @@ static void read_stereo_mode_and_bwidth( } -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------------- * stereo_mode_combined_format_dec() * diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ce637a3c2b..adb7e1006d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -957,7 +957,7 @@ ivas_error ivas_init_decoder( if ( st_ivas->ivas_format == MASA_FORMAT ) { -#ifdef FIX_OMASA_BRSW +#ifdef MASA_AND_OBJECTS /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ st_ivas->ism_extmeta_active = -1; st_ivas->ism_extmeta_cnt = 0; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b82f696e1e..0790b94244 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -266,14 +266,12 @@ ivas_error ivas_masa_decode( #endif } } -#ifdef OMASA_ENERGIES st_ivas->flag_omasa_brate = 0; if ( st_ivas->nchan_ism >= 3 && ivas_total_brate == IVAS_128k ) { st_ivas->flag_omasa_brate = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits_read ) += 1; } -#endif } } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b8aba3bacc..b419da1b59 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -55,9 +55,7 @@ ivas_error ivas_masa_ism_data_open( { MASA_ISM_DATA_HANDLE hMasaIsmData; int16_t ch, bin; -#ifdef FIX_OMASA_BRSW int16_t sf, obj_idx; -#endif if ( ( hMasaIsmData = (MASA_ISM_DATA_HANDLE) malloc( sizeof( MASA_ISM_DATA ) ) ) == NULL ) { @@ -86,7 +84,6 @@ ivas_error ivas_masa_ism_data_open( hMasaIsmData->q_azimuth_old[ch] = 0.0f; } -#ifdef FIX_OMASA_BRSW for ( obj_idx = 0; obj_idx < MAX_NUM_OBJECTS; obj_idx++ ) { set_s( hMasaIsmData->azimuth_ism[obj_idx], 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); @@ -98,7 +95,6 @@ ivas_error ivas_masa_ism_data_open( } set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); set_s( hMasaIsmData->elevation_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); -#endif st_ivas->hMasaIsmData = hMasaIsmData; @@ -155,10 +151,7 @@ ivas_error ivas_omasa_dec_config( ISM_MODE ism_mode_old; IVAS_FORMAT ivas_format_orig; ivas_error error; - -#ifdef FIX_OMASA_BRSW RENDERER_TYPE old_renderer_type; -#endif /* initializations */ ism_total_brate = 0; @@ -179,13 +172,11 @@ ivas_error ivas_omasa_dec_config( /* set ism_mode of current frame */ st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); -#ifdef FIX_OMASA_BRSW /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ old_renderer_type = st_ivas->renderer_type; -#endif /* MASA reconfig. */ cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); @@ -272,28 +263,8 @@ ivas_error ivas_omasa_dec_config( ivas_ism_metadata_close( st_ivas->hIsmMetaData, n_MD ); -#ifndef FIX_OMASA_BRSW -#ifdef FIX_417_TD_DECORR_BRATE_SW - /* TD Decorrelator */ - if ( st_ivas->hDiracDecBin != NULL ) - { - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif - - /* CLDFB instances */ - if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, 2, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif - st_ivas->hCPE[0]->element_brate = ivas_total_brate - ism_total_brate; -#ifdef FIX_OMASA_BRSW /*-----------------------------------------------------------------* * Renderer selection *-----------------------------------------------------------------*/ @@ -322,7 +293,6 @@ ivas_error ivas_omasa_dec_config( } } } -#endif /* objects renderer reconfig. */ if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) @@ -394,8 +364,6 @@ ivas_error ivas_omasa_dec_config( } } -#ifdef FIX_OMASA_BRSW -#ifdef FIX_417_TD_DECORR_BRATE_SW /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ @@ -407,7 +375,6 @@ ivas_error ivas_omasa_dec_config( return error; } } -#endif /*-----------------------------------------------------------------* * CLDFB instances @@ -417,7 +384,6 @@ ivas_error ivas_omasa_dec_config( { return error; } -#endif } return IVAS_ERR_OK; @@ -483,7 +449,7 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[n]->element_brate = element_brate[n]; *ism_total_brate += ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ); -#ifdef OMASA_ENERGIES + if ( ism_imp[n] > 1 && st_ivas->flag_omasa_brate == 1 && brate_limit_flag >= 0 ) { *ism_total_brate -= ADJUST_ISM_BRATE_NEG; @@ -493,8 +459,6 @@ void ivas_set_surplus_brate_dec( { *ism_total_brate += ADJUST_ISM_BRATE_POS; } - -#endif } st_ivas->hCPE[0]->brate_surplus = ism_total_brate_ref - *ism_total_brate; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 6bf14a6a38..d52cf0dc4f 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1381,17 +1381,16 @@ typedef struct Decoder_Struct RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ int32_t binaural_latency_ns; /* binauralization latency in ns */ #ifdef MASA_AND_OBJECTS - MASA_ISM_DATA_HANDLE hMasaIsmData; /* MASA_ISM rendering structure */ + MASA_ISM_DATA_HANDLE hMasaIsmData; /* MASA_ISM rendering structure */ EXTERNAL_ORIENTATION_HANDLE hExtOrientationData; /* External orientation data structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData; /* Combined external and head orientation data structure */ - uint8_t editing_ism_enabled; /* Todo Nokia: Temporary, used until proper ISM control available */ - int16_t index_of_edited_ism; /* Todo Nokia: Temporary, used until proper ISM control available */ - int16_t azimuth_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ - int16_t elevation_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ -#ifdef OMASA_ENERGIES + uint8_t editing_ism_enabled; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t index_of_edited_ism; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t azimuth_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t elevation_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ + int16_t flag_omasa_brate; -#endif #endif /* JBM module */ diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index e90baa0dd8..ed25bd1f81 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -86,9 +86,7 @@ void stereo_td_init_dec( void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k const int16_t ism_mode, /* i : ISM mode in combined format */ -#endif #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ @@ -312,9 +310,7 @@ void tdm_configure_dec( #ifdef MASA_AND_OBJECTS tdm_bit_alloc( ivas_format, -#ifdef FIX_OMASA_24_4k ism_mode, -#endif hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &hStereoTD->tdm_low_rate_mode, sts[1]->coder_type, *tdm_ratio_idx, hStereoTD->tdm_Pitch_reuse_flag, diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 84f28f28be..2631a7ca3e 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -45,7 +45,7 @@ #include "wmc_auto.h" -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS /*--------------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------------*/ @@ -112,9 +112,7 @@ ivas_error ivas_cpe_enc( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t cpe_brate; -#ifdef FIX_OMASA_STEREO_SWITCHING int32_t element_brate_ref; -#endif #endif error = IVAS_ERR_OK; @@ -128,7 +126,7 @@ ivas_error ivas_cpe_enc( ivas_format = hEncoderConfig->ivas_format; input_Fs = hEncoderConfig->input_Fs; ivas_total_brate = hEncoderConfig->ivas_total_brate; -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS element_brate_ref = hCPE->element_brate; #endif @@ -186,7 +184,7 @@ ivas_error ivas_cpe_enc( hCPE->element_mode = select_stereo_mode( hCPE, ivas_format, ivas_total_brate ); } -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS stereo_mode_combined_format_enc( st_ivas, hCPE ); #endif @@ -590,9 +588,7 @@ ivas_error ivas_cpe_enc( tdm_configure_enc( #ifdef MASA_AND_OBJECTS ivas_format, -#ifdef FIX_OMASA_24_4k st_ivas->ism_mode, -#endif #endif hCPE, Etot_last, tdm_SM_or_LRTD_Pri, tdm_ratio_idx, tdm_ratio_idx_SM, attack_flag[0], nb_bits_metadata ); @@ -747,7 +743,7 @@ ivas_error ivas_cpe_enc( hCPE->last_element_brate = hCPE->element_brate; hCPE->last_element_mode = hCPE->element_mode; -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT ) { hCPE->element_brate = element_brate_ref; @@ -1212,7 +1208,7 @@ void destroy_cpe_enc( } -#ifdef FIX_OMASA_STEREO_SWITCHING +#ifdef MASA_AND_OBJECTS /*------------------------------------------------------------------------- * stereo_mode_combined_format_enc() * diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 3898b44fc5..51f7269cc1 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -186,7 +186,7 @@ ivas_error ivas_enc( /* Core coding of Stereo DMX */ if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS , 0 #endif @@ -199,7 +199,7 @@ ivas_error ivas_enc( { /* Analysis, decision about bitrates per channel & core coding */ if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS , 0 #endif @@ -246,11 +246,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 -#endif -#ifdef OMASA_ENERGIES - , - 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0,0 #endif ) ) != IVAS_ERR_OK ) { @@ -298,11 +294,9 @@ ivas_error ivas_enc( { float data_separated_object[L_FRAME48k]; int16_t idx_separated_object; -#ifdef OMASA_ENERGIES int16_t flag_omasa_ener_brate; flag_omasa_ener_brate = 0; -#endif if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -344,29 +338,17 @@ ivas_error ivas_enc( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1] -#ifdef OMASA_ENERGIES - , - 0 -#endif - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1],0 ) ) != IVAS_ERR_OK ) { return error; } } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { -#ifdef OMASA_ENERGIES flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame ); -#endif /* Analysis, decision about bitrates per channel & core coding */ - if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1] -#ifdef OMASA_ENERGIES - , - flag_omasa_ener_brate -#endif - ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -386,12 +368,7 @@ ivas_error ivas_enc( /* Encode MASA parameters and write MASA metadata bitstream */ if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1, - st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp -#ifdef OMASA_ENERGIES - , - flag_omasa_ener_brate -#endif - ) ) != IVAS_ERR_OK ) + st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK ) { return error; } @@ -481,11 +458,7 @@ ivas_error ivas_enc( if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0 -#endif -#ifdef OMASA_ENERGIES - , - 0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 #endif ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index a4943c3a7d..60f3d62da2 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -53,7 +53,7 @@ ivas_error ivas_ism_enc( float data[MAX_NUM_OBJECTS][L_FRAME48k], /* i : input signal */ const int16_t input_frame, /* i : input frame length per channel */ int16_t *nb_bits_metadata /* i : number of metadata bits */ -#ifdef OMASA_ENERGIES +#ifdef MASA_AND_OBJECTS , const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif @@ -256,16 +256,7 @@ ivas_error ivas_ism_enc( { #ifdef MASA_AND_OBJECTS ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1 -#ifdef OMASA_ENERGIES - , - 0 -#endif -#ifdef FIX_OMASA_STEREO_SWITCHING - , - NULL -#endif - ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1,0,NULL ); #else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif @@ -289,16 +280,7 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0 -#ifdef OMASA_ENERGIES - , - flag_omasa_ener_brate -#endif -#ifdef FIX_OMASA_STEREO_SWITCHING - , - st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL -#endif - ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0, flag_omasa_ener_brate ,st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 53f0dd7941..07925a603a 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -191,16 +191,10 @@ ivas_error ivas_ism_metadata_enc( const int16_t ism_extended_metadata_flag /* i : Extended metadata flag */ #ifdef MASA_AND_OBJECTS , - const float lp_noise_CPE -#ifdef OMASA_ENERGIES - , - const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ -#endif -#ifdef FIX_OMASA_STEREO_SWITCHING - , + const float lp_noise_CPE, + const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ int16_t *omasa_stereo_sw_cnt #endif -#endif ) { int16_t i, ch, nb_bits_start = 0; @@ -703,7 +697,7 @@ ivas_error ivas_ism_metadata_enc( for ( ch = 0; ch < nchan_ism; ch++ ) { *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); -#ifdef OMASA_ENERGIES + if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) { *ism_total_brate -= ADJUST_ISM_BRATE_NEG; @@ -713,11 +707,9 @@ ivas_error ivas_ism_metadata_enc( { *ism_total_brate += ADJUST_ISM_BRATE_POS; } - -#endif } ism_metadata_flag_global = 1; -#ifdef FIX_OMASA_STEREO_SWITCHING + if ( ism_mode == ISM_MASA_MODE_DISC ) { brate_limit_flag = 0; @@ -731,7 +723,6 @@ ivas_error ivas_ism_metadata_enc( *omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; } } -#endif } #endif diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index ea01bf0dc9..7c3557332d 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -181,10 +181,8 @@ ivas_error ivas_masa_enc_open( #ifdef MASA_AND_OBJECTS hMasa->data.lp_noise_CPE = -1; -#ifdef FIX_OMASA_STEREO_SWITCHING hMasa->data.omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; hMasa->data.omasa_stereo_sw_cnt2 = OMASA_STEREO_SW_CNT_MAX2; -#endif #endif st_ivas->hMasa = hMasa; @@ -246,11 +244,9 @@ ivas_error ivas_masa_encode( const int16_t idx_separated_object, /* i : index of the separated object */ OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ const int16_t ism_imp /* i : importance of separated object */ -#ifdef OMASA_ENERGIES , const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif -#endif ) { MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; @@ -466,13 +462,11 @@ ivas_error ivas_masa_encode( #endif } -#ifdef OMASA_ENERGIES if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) { push_next_indice( hMetaData, flag_omasa_ener_brate, 1 ); hQMetaData->metadata_max_bits -= 1; } -#endif } } else @@ -966,11 +960,7 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { -#ifdef FIX_OMASA_STEREO_SWITCHING if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) -#else - if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT ) -#endif { st_ivas->hMasa->data.lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; } diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index c10ec862c5..d7bbe7bb6b 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -727,7 +727,6 @@ void ivas_set_surplus_brate_enc( } -#ifdef OMASA_ENERGIES /*--------------------------------------------------------------------------* * ivas_omasa_ener_brate() * @@ -771,7 +770,6 @@ int16_t ivas_omasa_ener_brate( return flag_omasa_ener_brate; } -#endif /*--------------------------------------------------------------------------* diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index c8c78d41b5..bc92b581aa 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -787,10 +787,8 @@ typedef struct ivas_masa_encoder_data_struct float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; int16_t nchan_ism; float lp_noise_CPE; /* LP filterend total noise estimation */ -#ifdef FIX_OMASA_STEREO_SWITCHING int16_t omasa_stereo_sw_cnt; int16_t omasa_stereo_sw_cnt2; -#endif #endif int16_t num_Cldfb_instances; diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 071ef6d361..35b2bd1b49 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -312,9 +312,7 @@ ivas_error stereo_set_tdm( void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ -#ifdef FIX_OMASA_24_4k const int16_t ism_mode, /* i : ISM mode in combined format */ -#endif #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ @@ -496,9 +494,7 @@ void tdm_configure_enc( #ifdef MASA_AND_OBJECTS tdm_bit_alloc( ivas_format, -#ifdef FIX_OMASA_24_4k ism_mode, -#endif hCPE->element_brate - nb_bits_metadata * FRAMES_PER_SEC + hCPE->brate_surplus, hStereoTD->tdm_lp_reuse_flag, &( sts[0]->total_brate ), &( sts[1]->total_brate ), &( hStereoTD->tdm_low_rate_mode ), sts[1]->coder_type, tdm_ratio_bit_alloc_idx, hStereoTD->tdm_Pitch_reuse_flag, -- GitLab From e14f1c10f3c7011bd4b71a528abbc8e748dc58f7 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 21 Jun 2023 11:37:54 +0300 Subject: [PATCH 133/173] Apply clang format --- lib_com/ivas_stereo_td_bit_alloc.c | 2 +- lib_dec/ivas_stereo_td_dec.c | 2 +- lib_dec/lib_dec.c | 2 +- lib_enc/ivas_enc.c | 4 ++-- lib_enc/ivas_ism_enc.c | 4 ++-- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_stereo_td_enc.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index b09cfd5384..823c1b1944 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -76,7 +76,7 @@ void tdm_bit_alloc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ - const int16_t ism_mode, /* i: ISM mode in combined format */ + const int16_t ism_mode, /* i: ISM mode in combined format */ #endif const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ const int16_t tdm_lp_reuse_flag, /* i : LPC reusage flag */ diff --git a/lib_dec/ivas_stereo_td_dec.c b/lib_dec/ivas_stereo_td_dec.c index ed25bd1f81..3b654960c1 100644 --- a/lib_dec/ivas_stereo_td_dec.c +++ b/lib_dec/ivas_stereo_td_dec.c @@ -86,7 +86,7 @@ void stereo_td_init_dec( void tdm_configure_dec( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ - const int16_t ism_mode, /* i : ISM mode in combined format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ int16_t *tdm_ratio_idx, /* o : ratio index */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 849cc416b4..e6b4f977f8 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2579,7 +2579,7 @@ static ivas_error printConfigInfo_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MC_FORMAT ) #else - else /* MC_FORMAT */ + else /* MC_FORMAT */ #endif { if ( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 51f7269cc1..8c58bdc083 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -246,7 +246,7 @@ ivas_error ivas_enc( ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1 #ifdef MASA_AND_OBJECTS , - ISM_MODE_NONE, -1, NULL, -1, NULL, 0,0 + ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 #endif ) ) != IVAS_ERR_OK ) { @@ -338,7 +338,7 @@ ivas_error ivas_enc( } else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) { - if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1],0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 60f3d62da2..3e0dd47585 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -256,7 +256,7 @@ ivas_error ivas_ism_enc( { #ifdef MASA_AND_OBJECTS ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1,0,NULL ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL ); #else ivas_ism_metadata_enc( st_ivas->hEncoderConfig->ivas_total_brate, nchan_ism, st_ivas->nchan_transport, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, nb_bits_metadata, vad_flag, st_ivas->ism_mode, st_ivas->hDirAC->hParamIsm, st_ivas->hEncoderConfig->ism_extended_metadata_flag ); #endif @@ -280,7 +280,7 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0, flag_omasa_ener_brate ,st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 9c0bb9ddc3..ea865461c4 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -192,7 +192,7 @@ ivas_error ivas_ism_metadata_enc( #ifdef MASA_AND_OBJECTS , const float lp_noise_CPE, - const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ int16_t *omasa_stereo_sw_cnt #endif ) diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index 35b2bd1b49..e11c0e7ebd 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -312,7 +312,7 @@ ivas_error stereo_set_tdm( void tdm_configure_enc( #ifdef MASA_AND_OBJECTS const int16_t ivas_format, /* i : IVAS format */ - const int16_t ism_mode, /* i : ISM mode in combined format */ + const int16_t ism_mode, /* i : ISM mode in combined format */ #endif CPE_ENC_HANDLE hCPE, /* i : CPE encoder structure */ const float Etot_last[CPE_CHANNELS], /* i/o: Energy of last frame */ -- GitLab From a53ad499ccb7ae26c047b2189475d5ac646f9cfb Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 21 Jun 2023 21:24:10 +0300 Subject: [PATCH 134/173] Set correct value in MASA external renderer for numParametricDirections --- lib_rend/lib_rend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 540072679f..6f88d3a37b 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5880,7 +5880,7 @@ static void copyMasaMetadataToDiracRenderer( int16_t meta_write_index; #ifdef MASA_AND_OBJECTS - hDirAC->numParametricDirections = meta->descriptive_meta.numberOfDirections; + hDirAC->numParametricDirections = meta->descriptive_meta.numberOfDirections + 1; #endif hDirAC->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1; -- GitLab From a54695e79a99dd2687ca5d0386b7fd51b187e0cf Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Wed, 21 Jun 2023 21:34:48 +0300 Subject: [PATCH 135/173] Apply clang format --- lib_enc/ivas_init_enc.c | 1 - lib_enc/ivas_omasa_enc.c | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 2266f40206..32403a9b31 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -597,7 +597,6 @@ ivas_error ivas_init_encoder( { return error; } - } if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 4792f64759..7b8206de4b 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -253,15 +253,11 @@ ivas_error ivas_omasa_enc_config( /* re-write IVAS format signalling - actual 'ism_mode' was not known before */ if ( st_ivas->nSCE > 0 ) { - reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, - st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot - ); + reset_indices_enc( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); } else { - reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, - st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot - ); + reset_indices_enc( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot ); } ivas_write_format( st_ivas ); -- GitLab From 5033c9e2996529bf41659c950a5b7275bff4159d Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 23 Jun 2023 16:22:25 +0200 Subject: [PATCH 136/173] rename parameter --- lib_dec/ivas_masa_dec.c | 10 +++++----- lib_enc/ivas_masa_enc.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a0f44e2345..10d90e9ee7 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -107,6 +107,7 @@ ivas_error ivas_masa_decode( int16_t obj; int16_t i, ch, ism_imp; int16_t dirac_bs_md_write_idx; + int32_t masa_total_brate; dirac_bs_md_write_idx = 0; ism_imp = 0; @@ -350,16 +351,15 @@ ivas_error ivas_masa_decode( #endif #ifdef MASA_AND_OBJECTS - int32_t total_brate; - total_brate = ivas_total_brate; + masa_total_brate = ivas_total_brate; if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); + masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); } - if ( total_brate >= IVAS_384k ) + if ( masa_total_brate >= IVAS_384k ) { - if ( total_brate >= IVAS_512k ) + if ( masa_total_brate >= IVAS_512k ) #else if ( ivas_total_brate >= IVAS_384k ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 7c3557332d..443c086a2a 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -254,6 +254,7 @@ ivas_error ivas_masa_encode( int16_t masa_sid_descriptor; #ifdef MASA_AND_OBJECTS int16_t low_bitrate_mode; + int32_t masa_total_brate; #endif masa_sid_descriptor = -1; @@ -538,16 +539,15 @@ ivas_error ivas_masa_encode( /* Encode metadata */ #ifdef MASA_AND_OBJECTS - int32_t total_brate; - total_brate = ivas_total_brate; + masa_total_brate = ivas_total_brate; if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_DISC ) { - total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); + masa_total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); } - if ( total_brate >= IVAS_384k ) + if ( masa_total_brate >= IVAS_384k ) { - if ( total_brate >= IVAS_512k ) + if ( masa_total_brate >= IVAS_512k ) { ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 16, 4 ); } -- GitLab From 75ca5d1f55693e9f1690a40d25b80bcbe8648c98 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 27 Jun 2023 09:09:12 +0300 Subject: [PATCH 137/173] Remove duplicate code --- lib_dec/ivas_ism_renderer.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index bc5170b4c6..9c4479374d 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -365,7 +365,6 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); } -#ifdef MASA_AND_OBJECTS // Todo OMASA JBM: This needs touches for VOIP path at least. Current version is mostly an adapted copy from ivas_ism_renderer_open() if ( st_ivas->hDecoderConfig->voip_active ) { @@ -378,13 +377,6 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( interpolator_length = init_interpolator_length; } st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * init_interpolator_length ); - for ( i = 0; i < interpolator_length; i++ ) - { - st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length - 1 ); - } -#else - interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); -#endif for ( i = 0; i < interpolator_length; i++ ) { -- GitLab From 06554bba18feafa8234bda4d5d672fb9a386ac78 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Mon, 3 Jul 2023 11:57:49 +0200 Subject: [PATCH 138/173] with MONO output, OMASA should not initialize hDirAC for rendering. this was triggered in bitrate switching. pre-compiler switch: OMASA_BRSW_MONO_FIX --- lib_com/options.h | 1 + lib_dec/ivas_masa_dec.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 8bb76b3452..3d341e277b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -166,6 +166,7 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix +#define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ #endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 10d90e9ee7..aec5991fbe 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1279,7 +1279,11 @@ ivas_error ivas_masa_dec_reconfigure( /* renderer might have changed, reselect */ ivas_renderer_select( st_ivas ); +#ifdef OMASA_BRSW_MONO_FIX + if ( ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) && st_ivas->hDirAC == NULL ) +#else if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->hDirAC == NULL ) +#endif { /* init a new DirAC dec */ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) @@ -1287,7 +1291,11 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } +#ifdef OMASA_BRSW_MONO_FIX + else if ( ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) && st_ivas->hDirAC != NULL ) +#else else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL ) +#endif { /* close unnecessary DirAC dec */ ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); -- GitLab From 2124631fa31de32f8d9348b45f8a2a66361f20f5 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 12 Jul 2023 14:40:45 +0200 Subject: [PATCH 139/173] fixes to handling of inputs with lower sampling rate: OMASA_FIX_LOW_FS. increase bitstream index buffer size to avoid reallocation that currently fails: OMASA_BIT_BUFF_SZ. --- lib_com/bitstream.c | 4 ++++ lib_com/options.h | 2 ++ lib_enc/ivas_enc.c | 7 +++++++ lib_enc/ivas_masa_enc.c | 17 ++++++++++++++++- lib_enc/ivas_omasa_enc.c | 12 ++++++++++-- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 97892f8771..2874e37ec1 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -434,7 +434,11 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_256k ) { +#ifdef OMASA_BIT_BUFF_SZ + return 1300; +#else return 1150; +#endif } else if ( ivas_total_brate <= IVAS_384k ) { diff --git a/lib_com/options.h b/lib_com/options.h index 3d341e277b..dfac881d21 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -167,6 +167,8 @@ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix #define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ +#define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ +#define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ #endif /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index a450be0ac4..10066a104e 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -298,6 +298,11 @@ ivas_error ivas_enc( flag_omasa_ener_brate = 0; +#ifdef OMASA_FIX_LOW_FS + /* Estimate TF-tile energy for the input MASA stream */ + ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif + if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -313,8 +318,10 @@ ivas_error ivas_enc( set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; +#ifndef OMASA_FIX_LOW_FS /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); +#endif /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 443c086a2a..abe899a794 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -745,6 +745,9 @@ ivas_error ivas_masa_enc_config( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t ism_total_brate; +#ifdef OMASA_FIX_LOW_FS + int32_t masa_total_brate; +#endif #endif error = IVAS_ERR_OK; @@ -900,8 +903,16 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; - +#ifdef OMASA_FIX_LOW_FS + masa_total_brate = ivas_total_brate; + if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + } + if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) +#else if ( ivas_total_brate > IVAS_256k && ivas_format == MASA_FORMAT ) +#endif #else if ( ivas_total_brate > IVAS_256k ) #endif @@ -933,8 +944,12 @@ ivas_error ivas_masa_enc_config( st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; } } +#ifdef OMASA_FIX_LOW_FS + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); +#else masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, ivas_total_brate > IVAS_256k, NULL ); +#endif if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 7b8206de4b..aaa4627361 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -60,7 +60,6 @@ static void computeIntensityVector_enc( const int16_t *band_grouping, float Cldf static void computeReferencePower_omasa( const int16_t *band_grouping, float Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], float *reference_power, const int16_t enc_param_start_band, const int16_t num_freq_bands ); - /*--------------------------------------------------------------------------* * ivas_omasa_enc_open() * @@ -532,10 +531,14 @@ void ivas_omasa_enc( } /* force computation into high resolution */ +#ifndef OMASA_FIX_LOW_FS n_bands_orig = hOMasa->nbands; +#endif n_subframes_orig = hOMasa->nSubframes; +#ifndef OMASA_FIX_LOW_FS hOMasa->nbands = MASA_FREQUENCY_BANDS; +#endif hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; /* Estimate MASA parameters from the objects */ @@ -553,14 +556,20 @@ void ivas_omasa_enc( } /* restore resolution parameters */ +#ifndef OMASA_FIX_LOW_FS hOMasa->nbands = n_bands_orig; +#endif hOMasa->nSubframes = n_subframes_orig; /* perform MASA+ISM merge in full resolution */ numCodingBands_orig = hMasa->config.numCodingBands; joinedSubframes_orig = hMasa->config.joinedSubframes; +#ifndef OMASA_FIX_LOW_FS hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; +#else + hMasa->config.numCodingBands = hOMasa->nbands; +#endif hMasa->config.joinedSubframes = 0; ivas_merge_masa_metadata( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ @@ -926,7 +935,6 @@ static void ivas_omasa_param_est_enc( } ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); } - /* Set coherences to zero, as this mode is used at lowest bit rates where the coherences are not transmitted */ for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { -- GitLab From 8aca3b9428976403361572764967fc047374c055 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Fri, 21 Jul 2023 14:08:36 +0200 Subject: [PATCH 140/173] apply clang formatting --- lib_dec/lib_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index c64816a0cd..9f121bb5c1 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2662,7 +2662,7 @@ static ivas_error printConfigInfo_dec( #ifdef MASA_AND_OBJECTS else if ( st_ivas->ivas_format == MC_FORMAT ) #else - else /* MC_FORMAT */ + else /* MC_FORMAT */ #endif { if ( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ) != IVAS_ERR_OK ) -- GitLab From 000d40099b78f5bd2a3c2439e8bebf06d9e35205 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Jul 2023 16:55:56 +0200 Subject: [PATCH 141/173] support of EXT output configuration for OMASA DISC mode; under OMASA_EXT_OUTPUT --- apps/decoder.c | 102 ++++++++++++++++++++++++++++++----- lib_com/bitstream.c | 2 +- lib_com/options.h | 1 + lib_dec/ivas_init_dec.c | 20 ++++++- lib_dec/ivas_masa_dec.c | 4 ++ lib_dec/ivas_output_config.c | 6 +++ lib_dec/lib_dec.c | 24 +++++++++ lib_dec/lib_dec.h | 3 ++ 8 files changed, 147 insertions(+), 15 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index d29f92417d..de686f756d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1742,7 +1742,11 @@ static ivas_error initOnFirstGoodFrame( } /* If outputting ISM, get number of objects, open output files and write zero metadata for initial bad frames */ +#ifdef OMASA_EXT_OUTPUT + if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM ) +#else if ( *pBsFormat == IVAS_DEC_BS_OBJ ) +#endif { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, pNumObj ) ) != IVAS_ERR_OK ) { @@ -1780,8 +1784,13 @@ static ivas_error initOnFirstGoodFrame( } } } + /* If outputting MASA, open output file and write metadata for initial bad frames */ +#ifdef OMASA_EXT_OUTPUT + if ( *pBsFormat == IVAS_DEC_BS_MASA || *pBsFormat == IVAS_DEC_BS_MASA_ISM ) +#else else if ( *pBsFormat == IVAS_DEC_BS_MASA ) +#endif { if ( ( error = MasaFileWriter_open( arg.outputWavFilename, arg.delayCompensationEnabled, ppMasaWriter ) ) != IVAS_ERR_OK ) { @@ -1789,26 +1798,33 @@ static ivas_error initOnFirstGoodFrame( return error; } - /* Duplicate good first frame metadata to fill the beginning of stream. */ - MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta = NULL; +#ifdef OMASA_EXT_OUTPUT + if ( numInitialBadFrames > 0 ) + { +#endif + /* Duplicate good first frame metadata to fill the beginning of stream. */ + MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta = NULL; #ifdef FIX_470_MASA_JBM_EXT - if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta, 0 ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_GetMasaMetadata( hIvasDec, &hMasaExtOutMeta ) ) != IVAS_ERR_OK ) #endif - { - fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); - return error; - } - - for ( int16_t j = 0; j < numInitialBadFrames; ++j ) - { - if ( ( error = MasaFileWriter_writeFrame( *ppMasaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK ) { - fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) ); + fprintf( stderr, "\nError in IVAS_DEC_GetMasaMetadata: %s\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } + + for ( int16_t j = 0; j < numInitialBadFrames; ++j ) + { + if ( ( error = MasaFileWriter_writeFrame( *ppMasaWriter, hMasaExtOutMeta ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nError writing MASA metadata to file: %s\n", MasaFileWriter_getFilePath( *ppMasaWriter ) ); + return error; + } + } +#ifdef OMASA_EXT_OUTPUT } +#endif } } @@ -2135,10 +2151,14 @@ static ivas_error decodeG192( #endif } - /* Write ISM metadata to external file(s) */ + /* Write MASA/ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { +#ifdef OMASA_EXT_OUTPUT + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else if ( bsFormat == IVAS_DEC_BS_OBJ ) +#endif { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2163,7 +2183,12 @@ static ivas_error decodeG192( } } } +#ifdef OMASA_EXT_OUTPUT + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else else if ( bsFormat == IVAS_DEC_BS_MASA ) +#endif { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; #ifdef FIX_470_MASA_JBM_EXT @@ -2250,6 +2275,18 @@ static ivas_error decodeG192( { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } +#ifdef OMASA_EXT_OUTPUT + else if ( bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + for ( i = 0; i < numObj; i++ ) + { + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + } + fprintf( stdout, "\n" ); + + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + } +#endif } /*------------------------------------------------------------------------------------------* @@ -2716,7 +2753,11 @@ static ivas_error decodeVoIP( { int16_t i; +#ifdef OMASA_EXT_OUTPUT + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else if ( bsFormat == IVAS_DEC_BS_OBJ ) +#endif { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -2741,7 +2782,12 @@ static ivas_error decodeVoIP( } } } +#ifdef OMASA_EXT_OUTPUT + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else else if ( bsFormat == IVAS_DEC_BS_MASA ) +#endif { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; #ifdef FIX_470_MASA_JBM_EXT @@ -3146,7 +3192,11 @@ static ivas_error decodeVariableSpeed( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { +#ifdef OMASA_EXT_OUTPUT + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else if ( bsFormat == IVAS_DEC_BS_OBJ ) +#endif { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -3171,7 +3221,12 @@ static ivas_error decodeVariableSpeed( } } } +#ifdef OMASA_EXT_OUTPUT + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else else if ( bsFormat == IVAS_DEC_BS_MASA ) +#endif { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; #ifdef FIX_470_MASA_JBM_EXT @@ -3325,7 +3380,11 @@ static ivas_error decodeVariableSpeed( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { +#ifdef OMASA_EXT_OUTPUT + if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else if ( bsFormat == IVAS_DEC_BS_OBJ ) +#endif { if ( ( error = IVAS_DEC_GetNumObjects( hIvasDec, &numObj ) ) != IVAS_ERR_OK ) { @@ -3350,7 +3409,12 @@ static ivas_error decodeVariableSpeed( } } } +#ifdef OMASA_EXT_OUTPUT + + if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) +#else else if ( bsFormat == IVAS_DEC_BS_MASA ) +#endif { MASA_DECODER_EXT_OUT_META_HANDLE hMasaExtOutMeta; #ifdef FIX_470_MASA_JBM_EXT @@ -3414,6 +3478,18 @@ static ivas_error decodeVariableSpeed( { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } +#ifdef OMASA_EXT_OUTPUT + else if ( bsFormat == IVAS_DEC_BS_MASA_ISM ) + { + for ( i = 0; i < numObj; i++ ) + { + fprintf( stdout, "\nOutput ISM metadata file: %s", IsmFileWriter_getFilePath( ismWriters[i] ) ); + } + fprintf( stdout, "\n" ); + + fprintf( stdout, "\nOutput MASA metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); + } +#endif } /* add zeros at the end to have equal length of synthesized signals */ diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index fb27e89e00..5e46868064 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -562,7 +562,7 @@ int16_t get_ivas_max_num_indices( else if ( ivas_total_brate <= IVAS_256k ) { #ifdef OMASA_BIT_BUFF_SZ - return 1300; + return 1450; #else return 1150; #endif diff --git a/lib_com/options.h b/lib_com/options.h index 82815ac317..1b47d0dd5c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -219,6 +219,7 @@ #define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ #define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ #define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ +#define OMASA_EXT_OUTPUT /* VA: support of EXT output configuration for OMASA DISC mode */ #endif /* #################### Start NON-BE CR switches ########################## */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9640e90253..111a9ab18b 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -784,10 +784,18 @@ ivas_error ivas_init_decoder( if ( output_config == AUDIO_CONFIG_EXTERNAL ) { - if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) +#ifdef OMASA_EXT_OUTPUT + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism; + } + else +#endif + if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; } + st_ivas->hOutSetup.nchan_out_woLFE = hDecoderConfig->nchan_out; } @@ -2559,5 +2567,15 @@ static ivas_error doSanityChecks_IVAS( } #endif +#ifdef OMASA_EXT_OUTPUT + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == AUDIO_CONFIG_EXTERNAL ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); + } + } +#endif + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index fb446cf11a..1c9cc56417 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -571,7 +571,11 @@ ivas_error ivas_masa_decode( } } +#ifdef OMASA_EXT_OUTPUT + if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) +#endif { create_masa_ext_out_meta( hMasa, hQMetaData, st_ivas->nchan_transport ); } diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index ec95f65428..fb5469fe43 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -441,6 +441,12 @@ void ivas_renderer_select( { *renderer_type = RENDERER_STEREO_PARAMETRIC; } +#ifdef OMASA_EXT_OUTPUT + else if ( output_config == AUDIO_CONFIG_EXTERNAL ) + { + *renderer_type = RENDERER_DISABLE; + } +#endif } #endif else if ( st_ivas->ivas_format == MC_FORMAT ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9f121bb5c1..470ed95f1a 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -408,6 +408,10 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( return IVAS_DEC_BS_SBA; case MASA_FORMAT: return IVAS_DEC_BS_MASA; +#ifdef OMASA_EXT_OUTPUT + case MASA_ISM_FORMAT: + return IVAS_DEC_BS_MASA_ISM; +#endif default: break; } @@ -1003,9 +1007,17 @@ ivas_error IVAS_DEC_GetNumObjects( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef OMASA_EXT_OUTPUT + if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT ) +#else if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT ) +#endif { +#ifdef OMASA_EXT_OUTPUT + *numObjects = hIvasDec->st_ivas->nchan_ism; +#else *numObjects = hIvasDec->st_ivas->hDecoderConfig->nchan_out; +#endif } else { @@ -1088,12 +1100,20 @@ ivas_error IVAS_DEC_GetObjectMetadata( st_ivas = hIvasDec->st_ivas; +#ifdef OMASA_EXT_OUTPUT + if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT ) +#else if ( st_ivas->ivas_format != ISM_FORMAT ) +#endif { return IVAS_ERR_WRONG_MODE; } +#ifdef OMASA_EXT_OUTPUT + if ( objectIdx >= st_ivas->nchan_ism ) +#else if ( objectIdx >= st_ivas->hDecoderConfig->nchan_out ) +#endif { return IVAS_ERR_INVALID_INDEX; } @@ -1149,7 +1169,11 @@ ivas_error IVAS_DEC_GetMasaMetadata( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef OMASA_EXT_OUTPUT + if ( hIvasDec->st_ivas->ivas_format != MASA_FORMAT && hIvasDec->st_ivas->ivas_format != MASA_ISM_FORMAT ) +#else if ( hIvasDec->st_ivas->ivas_format != MASA_FORMAT ) +#endif { return IVAS_ERR_WRONG_MODE; } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 18b37d7b80..e214796629 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -116,6 +116,9 @@ typedef enum _IVAS_DEC_BS_FORMAT IVAS_DEC_BS_SBA, IVAS_DEC_BS_OBJ, IVAS_DEC_BS_MASA, +#ifdef OMASA_EXT_OUTPUT + IVAS_DEC_BS_MASA_ISM, +#endif IVAS_DEC_BS_UNKOWN = 0xffff } IVAS_DEC_BS_FORMAT; -- GitLab From 6fabfe47b140f40358bee8c00d304576629c1179 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 24 Jul 2023 17:06:50 +0200 Subject: [PATCH 142/173] adapt FIX_562_ISM2_64KBPS for OMASA, fix is under MASA_AND_OBJECTS --- lib_com/bitstream.c | 2 +- lib_com/ivas_ism_com.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 5e46868064..fb27e89e00 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -562,7 +562,7 @@ int16_t get_ivas_max_num_indices( else if ( ivas_total_brate <= IVAS_256k ) { #ifdef OMASA_BIT_BUFF_SZ - return 1450; + return 1300; #else return 1150; #endif diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index e1c68593c5..1c25269f6b 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -120,7 +120,7 @@ ivas_error ivas_ism_config( error = IVAS_ERR_OK; #ifdef MASA_AND_OBJECTS - if ( combined_format_flag == 1 ) + if ( combined_format_flag ) { n_ISms = nchan_ism; } @@ -365,7 +365,7 @@ ivas_error ivas_ism_config( } #ifdef FIX_562_ISM2_64KBPS - /* limitaton to avoid too high bitrate in one active TCX channel */ + /* limitation to avoid too high bitrate in one active TCX channel */ if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k ) { diff = 0; @@ -402,6 +402,13 @@ ivas_error ivas_ism_config( printf( "\nWarning: ISM bitbudget equal to SID!\n" ); } #endif + +#ifdef MASA_AND_OBJECTS + if ( combined_format_flag ) + { + diff = 0; + } +#endif break; } } @@ -409,7 +416,7 @@ ivas_error ivas_ism_config( } #ifdef MASA_AND_OBJECTS - if ( combined_format_flag == 1 ) + if ( combined_format_flag ) { if ( diff > 0 ) { -- GitLab From ce7069c6fa31a88de97c55fa0a894457ff5d7f7f Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Wed, 26 Jul 2023 16:42:04 +0200 Subject: [PATCH 143/173] fix DirAC refactoring merge issues in OMASA branch. fix memory leak in separate object renderer. --- lib_com/bitstream.c | 4 + lib_com/ivas_ism_com.c | 5 + lib_com/ivas_prot.h | 283 +- lib_com/options.h | 3 + lib_dec/ivas_cpe_dec.c | 2 +- lib_dec/ivas_dec.c | 10 +- lib_dec/ivas_dirac_dec.c | 5105 ++++++----------- lib_dec/ivas_init_dec.c | 154 +- lib_dec/ivas_ism_dec.c | 26 +- lib_dec/ivas_ism_param_dec.c | 278 +- lib_dec/ivas_ism_renderer.c | 53 +- lib_dec/ivas_jbm_dec.c | 6 +- lib_dec/ivas_masa_dec.c | 88 +- lib_dec/ivas_mcmasa_dec.c | 48 +- lib_dec/ivas_mct_dec.c | 71 +- lib_dec/ivas_omasa_dec.c | 25 +- lib_dec/ivas_sba_dec.c | 63 +- lib_dec/ivas_spar_decoder.c | 12 +- lib_dec/ivas_spar_md_dec.c | 29 +- lib_dec/ivas_stat_dec.h | 397 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 736 ++- {lib_dec => lib_rend}/ivas_dirac_decorr_dec.c | 2 +- {lib_dec => lib_rend}/ivas_dirac_onsets_dec.c | 1 + .../ivas_dirac_output_synthesis_dec.c | 613 +- lib_rend/ivas_dirac_rend.c | 2061 +++++++ lib_rend/ivas_prot_rend.h | 325 +- lib_rend/ivas_stat_rend.h | 370 +- lib_rend/lib_rend.c | 61 +- 28 files changed, 5744 insertions(+), 5087 deletions(-) rename {lib_dec => lib_rend}/ivas_dirac_decorr_dec.c (99%) rename {lib_dec => lib_rend}/ivas_dirac_onsets_dec.c (99%) rename {lib_dec => lib_rend}/ivas_dirac_output_synthesis_dec.c (79%) create mode 100644 lib_rend/ivas_dirac_rend.c diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index fb27e89e00..6b5ea4d6e7 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -553,7 +553,11 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_160k ) { +#ifdef OMASA_BIT_BUFF_SZ1 + return 900; +#else return 850; +#endif } else if ( ivas_total_brate <= IVAS_192k ) { diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 1c25269f6b..46ca2e5c27 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -366,7 +366,12 @@ ivas_error ivas_ism_config( #ifdef FIX_562_ISM2_64KBPS /* limitation to avoid too high bitrate in one active TCX channel */ +#ifdef FIX_ISM2_64KBPS_COMBINED_FORMAT + /* Todo: the alternative is to make sure there are less than n_ism -1 objects inactive; but this way is simpler (Todo VE to check )*/ + if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k && combined_format_flag == 0 ) +#else if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k ) +#endif { diff = 0; limit_high = MAX_BRATE_TCX_32k / FRAMES_PER_SEC; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 63395cccd7..e7d52e0a9f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -789,8 +789,8 @@ ivas_error ivas_jbm_dec_flush_renderer( ivas_error ivas_jbm_dec_feed_tc_to_renderer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ - int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ + int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ float *data /* i/o: transport channels/output synthesis signal */ ); @@ -1074,6 +1074,7 @@ ivas_error ivas_param_ism_dec_open( void ivas_param_ism_dec_close( DIRAC_DEC_HANDLE *hDirAC, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ const AUDIO_CONFIG output_config /* i : output audio configuration */ ); @@ -1088,8 +1089,8 @@ void ivas_ism_dec_digest_tc( void ivas_param_ism_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ - float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */ + const uint16_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output */ ); void ivas_param_ism_dec_render( @@ -3215,8 +3216,9 @@ int16_t ivas_qmetadata_dec_sid_decode( void ivas_qmetadata_to_dirac( const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - DIRAC_DEC_HANDLE hDirAC, /* o : DirAC decoder structure */ + DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ @@ -3544,7 +3546,7 @@ void ivas_sba_dirac_stereo_smooth_parameters( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD handle for upmixing */ const int16_t cross_fade_start_offset, /* i : SPAR mixer delay compensation */ const int32_t output_Fs, /* i : Fs for delay calculation */ - const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix */ + const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix */ ); void ivas_sba2mc_cldfb( @@ -3580,12 +3582,12 @@ void ivas_dirac_enc( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ float data_f[][L_FRAME48k], /* i/o: SBA channels */ - float **ppIn_FR_real, /* o : real freq domain values */ - float **ppIn_FR_imag, /* o : imag freq domain values */ - const int16_t input_frame, /* i : input frame length */ - const int16_t dtx_vad, /* i : DTX vad flag */ - const IVAS_FORMAT ivas_format, /* i : ivas format */ - int16_t hodirac_flag /* i : hodirac flag */ + float **ppIn_FR_real, /* o : real freq domain values */ + float **ppIn_FR_imag, /* o : imag freq domain values */ + const int16_t input_frame, /* i : input frame length */ + const int16_t dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + int16_t hodirac_flag /* i : hodirac flag */ ); ivas_error ivas_dirac_config( void *st_ivas, /* i/o: IVAS encoder/decoder state structure */ @@ -3618,33 +3620,20 @@ ivas_error ivas_dirac_sba_config( const int16_t nbands /* i : number of frequency bands */ ); -ivas_error ivas_dirac_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -); - -ivas_error ivas_dirac_allocate_parameters( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - const int16_t params_flag /* i : set of parameters flag */ -); - ivas_error ivas_dirac_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const DIRAC_CONFIG_FLAG flag_configopen /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ ); void ivas_dirac_dec_close( - DIRAC_DEC_HANDLE *hDirAC /* i/o: decoder DirAC handle */ -); - -void ivas_dirac_deallocate_parameters( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - const int16_t params_flag /* i : set of parameters flag */ + DIRAC_DEC_HANDLE *hDirAC_out ); void ivas_dirac_dec_read_BS( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ Decoder_State *st, /* i/o: decoder Core state structure */ DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q metadata */ int16_t *nb_bits, /* o : number of bits read */ const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ @@ -3695,12 +3684,6 @@ ivas_error ivas_td_decorr_reconfig_dec( uint16_t *useTdDecorr /* i/o: TD decorrelator flag */ ); -/*! r: Configured reqularization factor value */ -float configure_reqularization_factor( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int32_t ivas_total_brate /* i : total IVAS bitrate */ -); - void computeDiffuseness_mdft( float **buffer_intensity[DIRAC_NUM_DIMS], const float *buffer_energy, @@ -3727,109 +3710,6 @@ void computeDiffuseness( float *diffuseness ); -ivas_error ivas_dirac_dec_onset_detection_open( - const int16_t num_channels, - const int16_t num_freq_bands, - const int16_t max_band_decorr, - DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, - DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state -); - -void ivas_dirac_dec_onset_detection_process( - const float *input_power_f, - float *onset_filter, - const int16_t num_protos_diff, - DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, - DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state -); - -ivas_error ivas_dirac_dec_decorr_open( - DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, - DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, - const int16_t num_freq_bands, - int16_t num_outputs_diff, - const int16_t num_protos_diff, - const DIRAC_SYNTHESIS_CONFIG synthesisConf, - float *frequency_axis, - const int16_t nchan_transport, /* i : number of transport channels */ - const int32_t output_Fs /* i : output sampling rate */ -); - -void ivas_dirac_dec_decorr_process( - const int16_t num_freq_bands, - int16_t num_channels, - const int16_t num_protos_diff, - const DIRAC_SYNTHESIS_CONFIG synthesisConf, - const int16_t nchan_transport, /* i : number of transport channels */ - const float *input_frame_f, - const int16_t num_protos_dir, - const int16_t *proto_index_dir, - float *frame_dec_f, - float *onset_filter, - HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state -); - -void ivas_dirac_dec_decorr_close( - HANDLE_DIRAC_DECORR_PARAMS *ph_dirac_decorr_params, - HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state -); - -ivas_error ivas_dirac_dec_output_synthesis_open( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int32_t output_Fs /* i : output sampling rate */ - , - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -); - -void ivas_dirac_dec_output_synthesis_init( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -); - -void ivas_dirac_dec_output_synthesis_close( - DIRAC_DEC_HANDLE hDirAC /* i/o: DirAC handle */ -); - -void ivas_dirac_dec_output_synthesis_process_slot( - const float *reference_power, /* i : Estimated power */ - const float *onset, /* i : onset filter */ - const int16_t *azimuth, - const int16_t *elevation, - const float *diffuseness, - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t sh_rot_max_order, - const float *p_Rmat, /* i : rotation matrix */ - const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ - const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int16_t ind_slot, /* i : index of the slot to be added to the input covariance */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -); - -void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int16_t nbslots, /* i : number of slots to process */ - const float *onset_filter, - float *diffuseness, - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -); - -void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t nbslots, /* i : number of slots to process */ - float *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/ - float *reference_power_smooth, - float qualityBasedSmFactor -); void ivas_dirac_dec_get_response( const int16_t azimuth, @@ -3838,99 +3718,54 @@ void ivas_dirac_dec_get_response( const int16_t ambisonics_order ); -void compute_hoa_encoder_mtx( - const float *azimuth, - const float *elevation, - float *response, - const int16_t num_responses, - const int16_t ambisonics_order ); - -void ivas_dirac_dec_compute_gain_factors( - const int16_t num_freq_bands, - const float *diffuseness, - const int16_t max_band_decorr, - float *direct_gain_factor, - float *diffuse_gain_factor -); - -void ivas_dirac_dec_compute_power_factors( - const int16_t num_freq_bands, - const float *diffuseness, - const int16_t max_band_decorr, - float *direct_power_factor, - float *diffuse_power_factor -); - -void ivas_dirac_dec_compute_directional_responses( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ - const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ -#ifdef MASA_AND_OBJECTS - MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ -#endif - const int16_t *azimuth, - const int16_t *elevation, - const int16_t md_idx, - const float *surCohRatio, - const int16_t shd_rot_max_order, /* i : split-order rotation method */ - const float *p_Rmat, /* i : rotation matrix */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -); - -void ivas_dirac_dec_get_frequency_axis( - float *frequency_axis, /* o : array of center frequencies of a real filter bank */ - const int32_t output_Fs, /* i : sampling frequency */ - const int16_t num_freq_bands /* i : number of frequency bands */ -); - void calculate_hodirac_sector_parameters( - DIRAC_ENC_HANDLE hDirAC, - float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ - float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector, imaginary part */ - const float beta, /* i : forgetting factor for average filtering */ - const int16_t *band_grouping, /* i : indices of band groups */ - const int16_t N_bands, /* i : number of bands (groups) */ - const int16_t enc_param_start_band, /* i : first band to process */ - float *azi, /* o : array of sector azimuth angles, flat */ - float *ele, /* o : array of sector elevation angles, flat */ - float *diff, /* o : array of sector diffuseness values, flat */ - float *ene /* o : array of sector energy values, flat */ + DIRAC_ENC_HANDLE hDirAC, + float RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector (L+1)^2 x N_bins, real part */ + float ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX],/* i : signal vector, imaginary part */ + const float beta, /* i : forgetting factor for average filtering */ + const int16_t *band_grouping, /* i : indices of band groups */ + const int16_t N_bands, /* i : number of bands (groups) */ + const int16_t enc_param_start_band, /* i : first band to process */ + float *azi, /* o : array of sector azimuth angles, flat */ + float *ele, /* o : array of sector elevation angles, flat */ + float *diff, /* o : array of sector diffuseness values, flat */ + float *ene /* o : array of sector energy values, flat */ ); void ivas_mc_paramupmix_enc( - Encoder_Struct *st_ivas, /* i/o: IVAS Encoder handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: IVAS Metadata bitstream handle */ + 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: MC data */ - const int16_t input_frame /* i : input frame length */ + const int16_t input_frame /* i : input frame length */ ); ivas_error ivas_mc_paramupmix_enc_open( - Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); void ivas_mc_paramupmix_enc_close( - MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ + MC_PARAMUPMIX_ENC_HANDLE *hMCParamUpmix, /* i/o: MC Param-Upmix encoder handle */ const int32_t input_Fs /* i : input sampling rate */ ); void ivas_mc_paramupmix_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output_f[][L_FRAME48k] /* i/o: synthesized core-coder transport channels/DirAC output */ ); ivas_error ivas_mc_paramupmix_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_mc_paramupmix_dec_close( - MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ + MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix_out /* i/o: Parametric MC decoder handle */ ); void ivas_mc_paramupmix_dec_read_BS( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Decoder_State *st, /* i/o: decoder state structure */ - MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ - int16_t *nb_bits /* o : number of bits written */ + Decoder_State *st, /* i/o: decoder state structure */ + MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */ + int16_t *nb_bits /* o : number of bits written */ ); #ifdef JBM_PARAMUPMIX @@ -4019,7 +3854,7 @@ void ivas_param_mc_dec_read_BS( void ivas_param_mc_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ float *transport_channels_f[] /* i : synthesized core-coder transport channels/DirAC output*/ ); @@ -4669,7 +4504,7 @@ void ivas_spar_to_dirac( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t dtx_vad, /* i : DTX frame flag */ const int16_t num_bands_out, /* i : number of output bands */ - const int16_t bw /* i : band joining factor */ + const int16_t bw /* i : band joining factor */ ); void ivas_spar_update_md_hist( @@ -4679,13 +4514,13 @@ void ivas_spar_update_md_hist( void ivas_spar_smooth_md_dtx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ - const int16_t num_md_sub_frames /* i : number of metadata subframes */ + const int16_t num_md_sub_frames /* i : number of metadata subframes */ ); void ivas_spar_setup_md_smoothing( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out, /* i : number of output bands */ - const int16_t num_md_sub_frames /* i : number of metadata subframes */ + const int16_t num_md_sub_frames /* i : number of metadata subframes */ ); void ivas_spar_dec_gen_umx_mat( @@ -4763,7 +4598,7 @@ void ivas_transient_det_close( void ivas_transient_det_process( ivas_trans_det_state_t *hTranDet, /* i/o: SPAR TD handle */ float *pIn_pcm, /* i : input audio channels */ - const int16_t frame_len, /* i : frame length in samples */ + const int16_t frame_len, /* i : frame length in samples */ int16_t transient_det[2] /* o : transient det outputs */ ); @@ -4954,14 +4789,14 @@ void ivas_spar_arith_coeffs_com_init( ); int16_t ivas_arith_encode_cmplx_cell_array( - ivas_arith_t *pArith_re, - ivas_arith_t *pArith_re_diff, - const int16_t *pDo_diff, - const int16_t nB, - int16_t *pSymbol_re, - int16_t *pSymbol_old_re, - ivas_cell_dim_t *pCell_dims, - BSTR_ENC_HANDLE hMetaData, + ivas_arith_t *pArith_re, + ivas_arith_t *pArith_re_diff, + const int16_t *pDo_diff, + const int16_t nB, + int16_t *pSymbol_re, + int16_t *pSymbol_old_re, + ivas_cell_dim_t *pCell_dims, + BSTR_ENC_HANDLE hMetaData, const int16_t any_diff , const int16_t wc_strat_arith ); @@ -5114,7 +4949,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 */ ); void ivas_masa_enc_reconfigure( @@ -5159,7 +4994,7 @@ ivas_error ivas_masa_enc_config( ); void ivas_masa_set_elements( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int32_t ivas_total_brate, /* i : codec total bitrate */ const int16_t mc_mode, /* i : MC format mode */ const int16_t nchan_transport, /* i : number of MASA input/transport channels */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -5261,7 +5096,7 @@ void ivas_get_stereo_panning_gains( void ivas_masa_set_coding_config( MASA_CODEC_CONFIG* config, /* i/o: MASA coding config structure */ int16_t* band_mapping, /* o : Band mapping used */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int32_t ivas_total_brate, /* i : codec total bitrate */ const int16_t nchan_transport, /* i : number of transport channel (mono/stereo) */ const uint8_t isMcMasa /* i : toggle for selecting McMASA specific config */ ); @@ -5599,7 +5434,7 @@ void ivas_mcmasa_set_separate_channel_mode( void ivas_mcmasa_split_brate( const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate available to be split */ + const int32_t ivas_total_brate, /* i : Total bitrate available to be split */ const int16_t nSCE, /* i : Number of SCEs in use (0 or 1) */ const int16_t nCPE, /* i : Number of CPEs in use (0 or 1) */ int32_t *brate_sce, /* o : Pointer to SCE element bitrate */ @@ -5930,6 +5765,12 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef OMASA_OBJ_REND_CLOSE +ivas_error ivas_masa_ism_separate_object_renderer_close( + Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ +); +#endif + void ivas_masa_ism_separate_object_render( Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ float input_f[][L_FRAME48k], /* i : separated object signal */ diff --git a/lib_com/options.h b/lib_com/options.h index 1b47d0dd5c..34396208ee 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -220,6 +220,9 @@ #define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ #define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ #define OMASA_EXT_OUTPUT /* VA: support of EXT output configuration for OMASA DISC mode */ +#define OMASA_BIT_BUFF_SZ1 /* Nokia: increase bitstream index buffer initial size */ +#define FIX_ISM2_64KBPS_COMBINED_FORMAT /* Nokia: Making the fix_562 work with combined format */ +#define OMASA_OBJ_REND_CLOSE /* Nokia: close OMASA separate object renderer */ #endif /* #################### Start NON-BE CR switches ########################## */ diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 365101b8bf..96542eb104 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -691,7 +691,7 @@ ivas_error create_cpe_dec( } #ifdef MASA_AND_OBJECTS - if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { cpe_brate = element_brate; } diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index facefc96cd..10e1aac313 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -452,7 +452,7 @@ ivas_error ivas_dec( { #ifdef FIX_564 /* loudness correction */ - ivas_dirac_dec_binaural_gain( output, nchan_remapped, output_frame ); + ivas_dirac_dec_binaural_sba_gain( output, nchan_remapped, output_frame ); #else float gain; @@ -508,15 +508,15 @@ ivas_error ivas_dec( /* Set the number of objects for the parametric rendering */ dirac_bs_md_write_idx = 0; - if ( st_ivas->hDirAC != NULL ) + if ( st_ivas->hDirAC != NULL ) /* TODO: should this check for st_ivas->hSpatParamRendCom != NULL ? */ { - st_ivas->hDirAC->numIsmDirections = 0; + st_ivas->hSpatParamRendCom->numIsmDirections = 0; if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { - st_ivas->hDirAC->numIsmDirections = st_ivas->nchan_ism; + st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism; } - dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ + dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ } /* MASA metadata decoding */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ef2ec470a2..ed17e9f090 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -51,206 +51,69 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static ivas_error ivas_dirac_alloc_mem( DIRAC_DEC_HANDLE hDirAC, const RENDERER_TYPE renderer_type, DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, const int16_t hodirac_flag ); - -static void ivas_dirac_free_mem( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ); - -static void initDiffuseResponses( float *diffuse_response_function, const int16_t num_channels, AUDIO_CONFIG output_config, IVAS_OUTPUT_SETUP hOutSetup, const int16_t ambisonics_order, const IVAS_FORMAT ivas_format, int16_t *num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG transport_config ); - -static void computeIntensityVector_dec( float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], const int16_t num_frequency_bands, float *intensity_real_x, float *intensity_real_y, float *intensity_real_z ); - -static void protoSignalComputation_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_direct_buffer_f, float *proto_diffuse_buffer_f, float *reference_power, const int16_t slot_index, const int16_t num_inputs, const int16_t num_outputs_diff, const int16_t num_freq_bands, float *p_Rmat ); - -static void protoSignalComputation1( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, float *proto_direct_buffer_f, float *reference_power, float *proto_power_smooth, const int16_t slot_index, const int16_t num_outputs_diff, const int16_t num_freq_bands ); - -static void protoSignalComputation2( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, float *proto_direct_buffer_f, float *reference_power, float *proto_power_smooth, const int16_t isloudspeaker, const int16_t slot_index, const int16_t num_freq_bands, MASA_STEREO_TYPE_DETECT *stereo_type_detect ); - -static void protoSignalComputation4( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float *proto_frame_f, float *proto_direct_buffer_f, float *reference_power, float *proto_power_smooth, const int16_t slot_index, const int16_t num_outputs_diff, const int16_t num_freq_bands, const float *mtx_hoa_decoder, const int16_t nchan_transport, const int16_t *sba_map_tc_ind ); - -static void ivas_dirac_dec_compute_diffuse_proto( DIRAC_DEC_HANDLE hDirAC, const int16_t slot_idx ); - -static void computeDirectionAngles( float *intensity_real_x, float *intensity_real_y, float *intensity_real_z, const int16_t num_frequency_bands, int16_t *azimuth, int16_t *elevation ); - -static void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); - -static void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); - -static void ivas_lfe_synth_with_cldfb( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], const int16_t slot_index, const int16_t subframe_index, const int16_t nchan_transport ); - -static void rotateAziEle_DirAC( int16_t *azi, int16_t *ele, const int16_t band1, const int16_t band2, const float *p_Rmat ); - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_open() - * - * Open decoder DirAC handle - *-------------------------------------------------------------------------*/ - -ivas_error ivas_dirac_dec_open( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +static ivas_error ivas_dirac_dec_config_internal( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ ) { + DIRAC_DEC_HANDLE hDirAC; ivas_error error; + DIRAC_CONFIG_FLAG flag_config; + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; - if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) - { - return error; - } - - return error; -} - - -/*------------------------------------------------------------------------- - * ivas_dirac_allocate_parameters() - * - * Allocate and initialize DirAC parameters - *-------------------------------------------------------------------------*/ - -ivas_error ivas_dirac_allocate_parameters( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - const int16_t params_flag /* i : set of parameters flag */ -) -{ - int16_t i; + hDirAC = NULL; - if ( params_flag == 1 ) + if ( flag_config == DIRAC_RECONFIGURE ) { - if ( ( hDirAC->azimuth = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - if ( ( hDirAC->elevation = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - if ( ( hDirAC->diffuseness_vector = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - if ( ( hDirAC->energy_ratio1 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - if ( ( hDirAC->spreadCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - if ( ( hDirAC->surroundingCoherence = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( ( hDirAC->azimuth[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hDirAC->azimuth[i], 0, hDirAC->num_freq_bands ); - - if ( ( hDirAC->elevation[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hDirAC->elevation[i], 0, hDirAC->num_freq_bands ); - - if ( ( hDirAC->diffuseness_vector[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->diffuseness_vector[i], 1.0f, hDirAC->num_freq_bands ); - - if ( ( hDirAC->energy_ratio1[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->energy_ratio1[i], 0.0f, hDirAC->num_freq_bands ); - - if ( ( hDirAC->spreadCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->spreadCoherence[i], 0.0f, hDirAC->num_freq_bands ); - - if ( ( hDirAC->surroundingCoherence[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->surroundingCoherence[i], 0.0f, hDirAC->num_freq_bands ); - } + hDirAC = st_ivas->hDirAC; } - else if ( params_flag == 2 ) + else if ( flag_config == DIRAC_OPEN ) { - if ( ( hDirAC->azimuth2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ - if ( ( hDirAC->elevation2 = (int16_t **) malloc( hDirAC->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - if ( ( hDirAC->energy_ratio2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + if ( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); } - if ( ( hDirAC->spreadCoherence2 = (float **) malloc( hDirAC->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + hDirAC->hParamIsm = NULL; + hDirAC->hParamIsmRendering = NULL; + st_ivas->hDirAC = hDirAC; + } - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( ( hDirAC->azimuth2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hDirAC->azimuth2[i], 0, hDirAC->num_freq_bands ); - if ( ( hDirAC->elevation2[i] = (int16_t *) malloc( hDirAC->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_s( hDirAC->elevation2[i], 0, hDirAC->num_freq_bands ); + /*-----------------------------------------------------------------* + * DirAC main configuration + *-----------------------------------------------------------------*/ - if ( ( hDirAC->energy_ratio2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->energy_ratio2[i], 0.0f, hDirAC->num_freq_bands ); + if ( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( hDirAC->spreadCoherence2[i] = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - set_f( hDirAC->spreadCoherence2[i], 0.0f, hDirAC->num_freq_bands ); - } + if ( flag_config == DIRAC_OPEN ) + { + hDirAC->spar_to_dirac_write_idx = st_ivas->ivas_format == SBA_FORMAT ? DELAY_DIRAC_PARAM_DEC_SFR : 0; + hDirAC->dithering_seed = DIRAC_DITH_SEED; + st_ivas->hDirAC = hDirAC; } - return IVAS_ERR_OK; + return error; } - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_config() - * - * Open or reconfigure decoder DirAC/MASA handle - *-------------------------------------------------------------------------*/ - -ivas_error ivas_dirac_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ -) +static ivas_error ivas_dirac_rend_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const int16_t dec_param_estim_old ) { DIRAC_DEC_HANDLE hDirAC; int16_t nchan_out_woLFE; @@ -262,27 +125,30 @@ ivas_error ivas_dirac_dec_config( float *proto_frame_f_old; int16_t proto_signal_decorr_on_old; uint16_t i, j, k; - int16_t dec_param_estim_old; float ls_azimuth[MAX_OUTPUT_CHANNELS]; float ls_elevation[MAX_OUTPUT_CHANNELS]; int32_t output_Fs, ivas_total_brate; ivas_error error; int16_t nchan_transport_orig; int16_t hodirac_flag; - int16_t map_idx; DIRAC_CONFIG_FLAG flag_config; + DIRAC_REND_HANDLE hDirACRend; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; error = IVAS_ERR_OK; - hDirAC = NULL; + hDirACRend = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + if ( flag_config == DIRAC_RECONFIGURE ) { - hDirAC = st_ivas->hDirAC; + hDirACRend = st_ivas->hDirACRend; } else if ( flag_config == DIRAC_OPEN ) { @@ -290,29 +156,21 @@ ivas_error ivas_dirac_dec_config( * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hDirAC = (DIRAC_DEC_HANDLE) malloc( sizeof( DIRAC_DEC_DATA ) ) ) == NULL ) + if ( ( hDirACRend = (DIRAC_REND_HANDLE) malloc( sizeof( DIRAC_REND_DATA ) ) ) == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC renderer\n" ) ); } - if ( ( hDirAC->hConfig = (DIRAC_CONFIG_DATA_HANDLE) malloc( sizeof( DIRAC_CONFIG_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC Config\n" ) ); - } nchan_transport_old = 0; - hDirAC->hParamIsm = NULL; - hDirAC->hParamIsmRendering = NULL; - st_ivas->hDirAC = hDirAC; } - dec_param_estim_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirAC->hConfig->dec_param_estim : FALSE; nchan_transport_old = 0; num_outputs_dir_old = 0; num_outputs_diff_old = 0; num_protos_diff_old = 0; nchan_transport_orig = st_ivas->nchan_transport; - if ( st_ivas->ivas_format == SBA_FORMAT && !( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + if ( st_ivas->ivas_format == SBA_FORMAT ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); } @@ -329,58 +187,40 @@ ivas_error ivas_dirac_dec_config( ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &nchan_transport_old, st_ivas->sba_planar, &tmp1, &tmp2, &tmp3 ); } - /*-----------------------------------------------------------------* - * DirAC main configuration - *-----------------------------------------------------------------*/ - - if ( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK ) - { - return error; - } - /*-----------------------------------------------------------------* * output setup: for parametric binaural renderer, use output setup, otherwise internal setup *-----------------------------------------------------------------*/ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - hDirAC->hOutSetup = st_ivas->hOutSetup; - - hDirAC->hConfig->dec_param_estim = FALSE; - } - else - { - hDirAC->hOutSetup = st_ivas->hIntSetup; - } - nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE; + hDirACRend->hOutSetup = st_ivas->hIntSetup; + nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - if ( hDirAC->hOutSetup.ls_azimuth != NULL && hDirAC->hOutSetup.ls_elevation != NULL ) + if ( hDirACRend->hOutSetup.ls_azimuth != NULL && hDirACRend->hOutSetup.ls_elevation != NULL ) { - mvr2r( hDirAC->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE ); - mvr2r( hDirAC->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE ); + mvr2r( hDirACRend->hOutSetup.ls_azimuth, ls_azimuth, nchan_out_woLFE ); + mvr2r( hDirACRend->hOutSetup.ls_elevation, ls_elevation, nchan_out_woLFE ); } - if ( hDirAC->hOutSetup.ambisonics_order == -1 ) + if ( hDirACRend->hOutSetup.ambisonics_order == -1 ) { - hDirAC->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ - if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_STEREO ) + hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ + if ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_STEREO ) { - hDirAC->hOutSetup.ambisonics_order = SBA_FOA_ORDER; + hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; } } - else if ( hDirAC->hOutSetup.ambisonics_order >= SBA_FOA_ORDER ) + else if ( hDirACRend->hOutSetup.ambisonics_order >= SBA_FOA_ORDER ) { mvr2r( ls_azimuth_4d4, ls_azimuth, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); mvr2r( ls_elevation_4d4, ls_elevation, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); } - if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) + if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ - hDirAC->hOutSetup.nchan_out_woLFE--; - nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE; - mvr2r( &ls_azimuth[hDirAC->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirAC->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirAC->hOutSetup.separateChannelIndex ); - mvr2r( &ls_elevation[hDirAC->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirAC->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirAC->hOutSetup.separateChannelIndex ); + hDirACRend->hOutSetup.nchan_out_woLFE--; + nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; + mvr2r( &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); + mvr2r( &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation[hDirACRend->hOutSetup.separateChannelIndex], nchan_out_woLFE - hDirACRend->hOutSetup.separateChannelIndex ); } /*-----------------------------------------------------------------* @@ -389,112 +229,74 @@ ivas_error ivas_dirac_dec_config( st_ivas->nchan_transport = nchan_transport_orig; - if ( flag_config == DIRAC_OPEN ) - { - hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); - set_s( hDirAC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hDirAC->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); - hDirAC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; - hDirAC->subframes_rendered = 0; - hDirAC->slots_rendered = 0; - hDirAC->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - } - - if ( st_ivas->ivas_format == SBA_FORMAT && flag_config == DIRAC_RECONFIGURE && ( ( ivas_total_brate > IVAS_256k && st_ivas->hDecoderConfig->last_ivas_total_brate <= IVAS_256k ) || ( ivas_total_brate <= IVAS_256k && st_ivas->hDecoderConfig->last_ivas_total_brate > IVAS_256k ) ) ) - { - if ( st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k && hDirAC->azimuth2 == NULL ) - { - if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hDecoderConfig->ivas_total_brate <= IVAS_256k && hDirAC->azimuth2 != NULL ) - { - ivas_dirac_deallocate_parameters( hDirAC, 2 ); - } - } - - /* band config needed only for SPAR with FOA output */ - if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) - { - return IVAS_ERR_OK; - } - - if ( nchan_transport_orig > 2 && hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag ) - { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; - hDirAC->panningConf = DIRAC_PANNING_VBAP; - } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + if ( nchan_transport_orig > 2 && hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC && !hodirac_flag ) { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; - hDirAC->panningConf = DIRAC_PANNING_VBAP; + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + hDirACRend->panningConf = DIRAC_PANNING_VBAP; } - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO ) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO ) { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_MONO; - hDirAC->panningConf = DIRAC_PANNING_HOA3; + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; nchan_out_woLFE = 1; } #ifdef MASA_AND_OBJECTS - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.is_loudspeaker_setup ) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) #else - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->hOutSetup.is_loudspeaker_setup ) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) #endif { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; - hDirAC->panningConf = DIRAC_PANNING_VBAP; + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + hDirACRend->panningConf = DIRAC_PANNING_VBAP; } #ifdef MASA_AND_OBJECTS - else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && !hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) + else if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) #else - else if ( st_ivas->ivas_format == MASA_FORMAT && !hDirAC->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) + else if ( st_ivas->ivas_format == MASA_FORMAT && !hDirACRend->hOutSetup.is_loudspeaker_setup && st_ivas->nchan_transport > 1 ) #endif { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; - hDirAC->panningConf = DIRAC_PANNING_HOA3; + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; } else { - hDirAC->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; - hDirAC->panningConf = DIRAC_PANNING_HOA3; + hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; + hDirACRend->panningConf = DIRAC_PANNING_HOA3; } if ( flag_config == DIRAC_OPEN ) { - hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); - if ( ( hDirAC->frequency_axis = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + if ( ( hDirACRend->frequency_axis = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f( hDirAC->frequency_axis, 0.0f, hDirAC->num_freq_bands ); + set_f( hDirACRend->frequency_axis, 0.0f, hSpatParamRendCom->num_freq_bands ); - ivas_dirac_dec_get_frequency_axis( hDirAC->frequency_axis, output_Fs, hDirAC->num_freq_bands ); + ivas_dirac_dec_get_frequency_axis( hDirACRend->frequency_axis, output_Fs, hSpatParamRendCom->num_freq_bands ); } - if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirAC->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 ) + if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->mc_mode == MC_MODE_MCMASA ) && hDirACRend->panningConf == DIRAC_PANNING_HOA3 && nchan_transport == 2 ) { - if ( ( flag_config == DIRAC_RECONFIGURE && hDirAC->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN ) + if ( ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect == NULL ) || flag_config == DIRAC_OPEN ) { - if ( ( hDirAC->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) + if ( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - ivas_masa_init_stereotype_detection( hDirAC->masa_stereo_type_detect ); + ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); } else { - if ( flag_config == DIRAC_RECONFIGURE && hDirAC->masa_stereo_type_detect != NULL ) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->masa_stereo_type_detect != NULL ) { - free( hDirAC->masa_stereo_type_detect ); + free( hDirACRend->masa_stereo_type_detect ); } - hDirAC->masa_stereo_type_detect = NULL; + hDirACRend->masa_stereo_type_detect = NULL; } #ifdef MASA_AND_OBJECTS - hDirAC->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ + hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ #endif /*-----------------------------------------------------------------* @@ -504,45 +306,39 @@ ivas_error ivas_dirac_dec_config( /* prototype signal computation */ if ( flag_config == DIRAC_RECONFIGURE ) { - num_outputs_dir_old = hDirAC->num_outputs_dir; - num_outputs_diff_old = hDirAC->num_outputs_diff; - num_protos_diff_old = hDirAC->num_protos_diff; + num_outputs_dir_old = hDirACRend->num_outputs_dir; + num_outputs_diff_old = hDirACRend->num_outputs_diff; + num_protos_diff_old = hDirACRend->num_protos_diff; } /* allocate output setup related arrays */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - /* Two channels in parametric binaural rendering */ - hDirAC->num_outputs_diff = 2; - hDirAC->num_outputs_dir = 2; - } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { /* Directional and diffuses components in output LS format */ - hDirAC->num_outputs_diff = nchan_out_woLFE; - hDirAC->num_outputs_dir = nchan_out_woLFE; + hDirACRend->num_outputs_diff = nchan_out_woLFE; + hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ - hDirAC->num_outputs_diff = ( min( hDirAC->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirAC->hOutSetup.ambisonics_order, 1 ) + 1 ); - if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ivas_total_brate >= IVAS_96k ) && ( hDirAC->hOutSetup.ambisonics_order > 1 ) && ( nchan_transport < 4 ) ) + hDirACRend->num_outputs_diff = ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ); + if ( ( st_ivas->ivas_format == SBA_FORMAT ) && ( ivas_total_brate >= IVAS_96k ) && ( hDirACRend->hOutSetup.ambisonics_order > 1 ) && ( nchan_transport < 4 ) ) { - hDirAC->num_outputs_diff += 2; /* Add 2nd-order planar components for HRs */ + hDirACRend->num_outputs_diff += 2; /* Add 2nd-order planar components for HRs */ } - hDirAC->num_outputs_dir = ivas_sba_get_nchan( hDirAC->hOutSetup.ambisonics_order, 0 ); + hDirACRend->num_outputs_dir = ivas_sba_get_nchan( hDirACRend->hOutSetup.ambisonics_order, 0 ); } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - hDirAC->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; - hDirAC->num_outputs_dir = nchan_out_woLFE; + hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; + hDirACRend->num_outputs_dir = nchan_out_woLFE; } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - hDirAC->num_outputs_diff = 1; /* There is one output channel in mono */ - hDirAC->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ } else { @@ -551,154 +347,135 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - num_outputs_dir_old = hDirAC->num_outputs_dir; - if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) + num_outputs_dir_old = hDirACRend->num_outputs_dir; + if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - num_outputs_diff_old = hDirAC->num_outputs_diff; - if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) + num_outputs_diff_old = hDirACRend->num_outputs_diff; + if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - if ( hDirAC->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) + if ( hDirACRend->num_outputs_dir != num_outputs_dir_old && flag_config == DIRAC_RECONFIGURE ) { - free( hDirAC->proto_index_dir ); - if ( ( hDirAC->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_dir ) ) == NULL ) + free( hDirACRend->proto_index_dir ); + if ( ( hDirACRend->proto_index_dir = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_s( hDirAC->proto_index_dir, 0, hDirAC->num_outputs_dir ); + set_s( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); - if ( hDirAC->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE ) + if ( hDirACRend->num_outputs_diff != num_outputs_diff_old && flag_config == DIRAC_RECONFIGURE ) { - free( hDirAC->proto_index_diff ); - if ( ( hDirAC->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirAC->num_outputs_diff ) ) == NULL ) + free( hDirACRend->proto_index_diff ); + if ( ( hDirACRend->proto_index_diff = (int16_t *) malloc( sizeof( int16_t ) * hDirACRend->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_s( hDirAC->proto_index_diff, 0, hDirAC->num_outputs_diff ); + set_s( hDirACRend->proto_index_diff, 0, hDirACRend->num_outputs_diff ); - hDirAC->sba_map_tc = sba_map_tc; + hDirACRend->sba_map_tc = sba_map_tc; if ( st_ivas->ivas_format == SBA_FORMAT ) { if ( st_ivas->sba_order > SBA_FOA_ORDER && ivas_total_brate >= IVAS_512k ) { - hDirAC->sba_map_tc = sba_map_tc_512; + hDirACRend->sba_map_tc = sba_map_tc_512; } } if ( nchan_transport == 1 ) { - hDirAC->num_protos_ambi = 1; - hDirAC->num_protos_dir = 1; - hDirAC->num_protos_diff = 1; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - hDirAC->num_protos_dir = 2; - hDirAC->num_protos_diff = 2; - hDirAC->proto_index_dir[0] = 0; - hDirAC->proto_index_dir[1] = 1; - hDirAC->proto_index_diff[0] = 0; - hDirAC->proto_index_diff[1] = 1; - } + hDirACRend->num_protos_ambi = 1; + hDirACRend->num_protos_dir = 1; + hDirACRend->num_protos_diff = 1; } else if ( nchan_transport == 2 ) { - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - hDirAC->num_protos_ambi = 2; - hDirAC->num_protos_diff = 1; - hDirAC->num_protos_dir = 2; - hDirAC->proto_index_dir[1] = 1; - } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - hDirAC->num_protos_dir = 2; - hDirAC->num_protos_diff = 2; - hDirAC->proto_index_dir[0] = 0; - hDirAC->proto_index_dir[1] = 1; - hDirAC->proto_index_diff[0] = 0; - hDirAC->proto_index_diff[1] = 1; + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_diff = 1; + hDirACRend->num_protos_dir = 2; + hDirACRend->proto_index_dir[1] = 1; } - else if ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_MONO ) + else if ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_MONO ) { /* Following the foa rendering for code compatibility */ - hDirAC->num_protos_ambi = 2; - hDirAC->num_protos_dir = 2; - hDirAC->num_protos_diff = 3; - hDirAC->proto_index_dir[0] = 0; - hDirAC->proto_index_diff[0] = 0; + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_dir = 2; + hDirACRend->num_protos_diff = 3; + hDirACRend->proto_index_dir[0] = 0; + hDirACRend->proto_index_diff[0] = 0; } else { - hDirAC->num_protos_ambi = 2; - hDirAC->num_protos_diff = 3; + hDirACRend->num_protos_ambi = 2; + hDirACRend->num_protos_diff = 3; - for ( k = 0; k < hDirAC->num_outputs_diff; k++ ) + for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { if ( ls_azimuth[k] > 0.0f ) { - hDirAC->proto_index_diff[k] = 1; + hDirACRend->proto_index_diff[k] = 1; } else if ( ls_azimuth[k] < 0.0f ) { - hDirAC->proto_index_diff[k] = 2; + hDirACRend->proto_index_diff[k] = 2; } else { - hDirAC->proto_index_diff[k] = 0; + hDirACRend->proto_index_diff[k] = 0; } } - if ( hDirAC->hOutSetup.is_loudspeaker_setup ) + if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) { - hDirAC->num_protos_dir = 3; - mvs2s( hDirAC->proto_index_diff, hDirAC->proto_index_dir, nchan_out_woLFE ); + hDirACRend->num_protos_dir = 3; + mvs2s( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); } else { - hDirAC->num_protos_dir = 2; - hDirAC->proto_index_dir[1] = 1; + hDirACRend->num_protos_dir = 2; + hDirACRend->proto_index_dir[1] = 1; } } } else /* nchan_transport > 2 */ { - hDirAC->num_protos_ambi = 4; - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + hDirACRend->num_protos_ambi = 4; + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { - hDirAC->num_protos_diff = hDirAC->num_outputs_diff; - for ( k = 0; k < hDirAC->num_outputs_diff; k++ ) + hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; + for ( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { - hDirAC->proto_index_diff[k] = k; + hDirACRend->proto_index_diff[k] = k; } - hDirAC->num_protos_dir = hDirAC->num_outputs_dir; - for ( k = 0; k < hDirAC->num_outputs_dir; k++ ) + hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; + for ( k = 0; k < hDirACRend->num_outputs_dir; k++ ) { - hDirAC->proto_index_dir[k] = k; + hDirACRend->proto_index_dir[k] = k; } } else { - hDirAC->num_protos_diff = 1; - hDirAC->num_protos_dir = nchan_transport; - if ( ( st_ivas->sba_planar ) && ( !( st_ivas->ivas_format == SBA_FORMAT ) ) ) + hDirACRend->num_protos_diff = 1; + hDirACRend->num_protos_dir = nchan_transport; + if ( ( st_ivas->sba_planar ) && ( !( st_ivas->ivas_format == SBA_FORMAT ) ) ) // Todo Dolby/FhG refactor: Is this ever true? { - hDirAC->num_protos_dir++; + hDirACRend->num_protos_dir++; } - for ( k = 0; k < min( hDirAC->num_outputs_dir, hDirAC->num_protos_dir ); k++ ) + for ( k = 0; k < min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) { - if ( hDirAC->sba_map_tc[k] < hDirAC->num_outputs_dir ) + if ( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) { - hDirAC->proto_index_dir[hDirAC->sba_map_tc[k]] = k; + hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; } } } @@ -707,61 +484,61 @@ ivas_error ivas_dirac_dec_config( /* direct/diffuse responses */ if ( flag_config == DIRAC_OPEN ) { - if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) + if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } /* reallocate static memory */ - else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->num_outputs_dir != num_outputs_dir_old ) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->num_outputs_dir != num_outputs_dir_old ) { - free( hDirAC->diffuse_response_function ); - hDirAC->diffuse_response_function = NULL; - if ( ( hDirAC->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirAC->num_outputs_dir ) ) == NULL ) + free( hDirACRend->diffuse_response_function ); + hDirACRend->diffuse_response_function = NULL; + if ( ( hDirACRend->diffuse_response_function = (float *) malloc( sizeof( float ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - if ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) + if ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) || ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) ) { - initDiffuseResponses( hDirAC->diffuse_response_function, nchan_out_woLFE, hDirAC->hOutSetup.output_config, - hDirAC->hOutSetup, hDirAC->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirAC->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); + initDiffuseResponses( hDirACRend->diffuse_response_function, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, st_ivas->transport_config ); } else { - initDiffuseResponses( hDirAC->diffuse_response_function, hDirAC->num_outputs_dir, AUDIO_CONFIG_FOA, - hDirAC->hOutSetup, hDirAC->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirAC->num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG_INVALID ); + initDiffuseResponses( hDirACRend->diffuse_response_function, hDirACRend->num_outputs_dir, AUDIO_CONFIG_FOA, + hDirACRend->hOutSetup, hDirACRend->hOutSetup.ambisonics_order, st_ivas->ivas_format, &hDirACRend->num_ele_spk_no_diffuse_rendering, AUDIO_CONFIG_INVALID ); } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { if ( flag_config == DIRAC_OPEN ) { - if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder && ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder && ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) { - free( hDirAC->hoa_encoder ); - hDirAC->hoa_encoder = NULL; - if ( ( hDirAC->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + free( hDirACRend->hoa_encoder ); + hDirACRend->hoa_encoder = NULL; + if ( ( hDirACRend->hoa_encoder = (float *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_f( hDirAC->hoa_encoder, 0.0f, nchan_out_woLFE * hDirAC->num_outputs_diff ); - compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirAC->hoa_encoder, hDirAC->num_outputs_diff, hDirAC->hOutSetup.ambisonics_order ); + set_f( hDirACRend->hoa_encoder, 0.0f, nchan_out_woLFE * hDirACRend->num_outputs_diff ); + compute_hoa_encoder_mtx( ls_azimuth, ls_elevation, hDirACRend->hoa_encoder, hDirACRend->num_outputs_diff, hDirACRend->hOutSetup.ambisonics_order ); } else { - if ( flag_config == DIRAC_RECONFIGURE && hDirAC->hoa_encoder ) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->hoa_encoder ) { - free( hDirAC->hoa_encoder ); + free( hDirACRend->hoa_encoder ); } - hDirAC->hoa_encoder = NULL; + hDirACRend->hoa_encoder = NULL; } /* VBAP */ @@ -770,7 +547,7 @@ ivas_error ivas_dirac_dec_config( st_ivas->hVBAPdata = NULL; } - if ( hDirAC->panningConf == DIRAC_PANNING_VBAP ) + if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) { if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { @@ -789,13 +566,13 @@ ivas_error ivas_dirac_dec_config( } #endif } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { vbap_free_data( &( st_ivas->hVBAPdata ) ); } - hDirAC->hoa_decoder = NULL; + hDirACRend->hoa_decoder = NULL; } else if ( flag_config == DIRAC_RECONFIGURE && st_ivas->hVBAPdata != NULL ) { @@ -805,67 +582,67 @@ ivas_error ivas_dirac_dec_config( /* HOA panning/dec */ if ( flag_config == DIRAC_OPEN ) { - hDirAC->hoa_decoder = NULL; - if ( ( hDirAC->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) ) + hDirACRend->hoa_decoder = NULL; + if ( ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) || st_ivas->ivas_format == SBA_FORMAT || ( nchan_transport > 2 ) ) { - if ( hDirAC->hOutSetup.is_loudspeaker_setup ) + if ( hDirACRend->hOutSetup.is_loudspeaker_setup ) { if ( st_ivas->hoa_dec_mtx != NULL ) { free( st_ivas->hoa_dec_mtx ); st_ivas->hoa_dec_mtx = NULL; } - if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirAC->hOutSetup, &st_ivas->hoa_dec_mtx, hDirAC->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sba_get_hoa_dec_matrix( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } - hDirAC->hoa_decoder = st_ivas->hoa_dec_mtx; + hDirACRend->hoa_decoder = st_ivas->hoa_dec_mtx; } } } /* decorrelation */ - proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirAC->proto_signal_decorr_on : 0; - hDirAC->proto_signal_decorr_on = 1; - if ( ( nchan_transport > 2 ) && ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) ) + proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; + hDirACRend->proto_signal_decorr_on = 1; + if ( ( nchan_transport > 2 ) && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) ) { /*switch off decorrelation for 4 transport channels*/ - hDirAC->proto_signal_decorr_on = 0; + hDirACRend->proto_signal_decorr_on = 0; } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { - hDirAC->proto_signal_decorr_on = 0; + hDirACRend->proto_signal_decorr_on = 0; } - if ( ( flag_config == DIRAC_OPEN && hDirAC->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) + if ( ( flag_config == DIRAC_OPEN && hDirACRend->proto_signal_decorr_on ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { - if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), - &( hDirAC->h_freq_domain_decorr_ap_state ), - hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - hDirAC->frequency_axis, + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), + &( hDirACRend->h_freq_domain_decorr_ap_state ), + hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; } } - else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) + else if ( flag_config == DIRAC_RECONFIGURE && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { - ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); } - else if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_signal_decorr_on && proto_signal_decorr_on_old ) + else if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) { - if ( nchan_transport != nchan_transport_old || hDirAC->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) + if ( nchan_transport != nchan_transport_old || hDirACRend->num_outputs_diff != num_outputs_diff_old || flag_config_inp == DIRAC_RECONFIGURE_MODE ) { /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); - if ( ( error = ivas_dirac_dec_decorr_open( &( hDirAC->h_freq_domain_decorr_ap_params ), &( hDirAC->h_freq_domain_decorr_ap_state ), hDirAC->num_freq_bands, hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, hDirAC->synthesisConf, hDirAC->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -875,54 +652,54 @@ ivas_error ivas_dirac_dec_config( /* output synthesis */ if ( flag_config == DIRAC_OPEN ) { - if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } - hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on; + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirAC->num_outputs_diff != num_outputs_diff_old ) ) ) + else if ( ( flag_config == DIRAC_RECONFIGURE ) && ( ( nchan_transport != nchan_transport_old ) || ( hDirACRend->num_outputs_diff != num_outputs_diff_old ) ) ) { - ivas_dirac_dec_output_synthesis_close( hDirAC ); + ivas_dirac_dec_output_synthesis_close( hDirACRend ); - if ( ( ivas_dirac_dec_output_synthesis_open( hDirAC, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + if ( ( ivas_dirac_dec_output_synthesis_open( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } - hDirAC->h_output_synthesis_psd_params.use_onset_filters = hDirAC->proto_signal_decorr_on; + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - hDirAC->h_output_synthesis_psd_params.use_onset_filters = 0; + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; } /*-----------------------------------------------------------------* * memory allocation *-----------------------------------------------------------------*/ - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - if ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_frame_f ) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f ) { - free( hDirAC->proto_frame_f ); + free( hDirACRend->proto_frame_f ); } - hDirAC->proto_frame_f = NULL; + hDirACRend->proto_frame_f = NULL; } else { - if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirAC->proto_frame_f == NULL ) ) + if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) { - if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - else if ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->num_protos_diff != num_protos_diff_old ) ) + else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) { - proto_frame_f_old = hDirAC->proto_frame_f; + proto_frame_f_old = hDirACRend->proto_frame_f; free( proto_frame_f_old ); - if ( ( hDirAC->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirAC->num_protos_diff * hDirAC->num_freq_bands ) ) == NULL ) + if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } @@ -932,31 +709,31 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->buffer_energy = NULL; + hDirACRend->buffer_energy = NULL; } if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == TRUE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) { - hDirAC->index_buffer_intensity = 0; + hDirACRend->index_buffer_intensity = 0; for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - if ( ( hDirAC->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + if ( ( hDirACRend->buffer_intensity_real[i][j] = (float *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set_f( hDirAC->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); + set_f( hDirACRend->buffer_intensity_real[i][j], 0.0f, CLDFB_NO_CHANNELS_MAX ); } } - if ( hDirAC->buffer_energy == NULL ) + if ( hDirACRend->buffer_energy == NULL ) { - if ( ( hDirAC->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) + if ( ( hDirACRend->buffer_energy = (float *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } - set_f( hDirAC->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set_f( hDirACRend->buffer_energy, 0.0f, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); } else if ( ( flag_config == DIRAC_OPEN && hDirAC->hConfig->dec_param_estim == FALSE ) || ( flag_config == DIRAC_RECONFIGURE && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) { @@ -964,132 +741,227 @@ ivas_error ivas_dirac_dec_config( { for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) { - if ( flag_config == DIRAC_RECONFIGURE && hDirAC->buffer_intensity_real[i][j] ) + if ( flag_config == DIRAC_RECONFIGURE && hDirACRend->buffer_intensity_real[i][j] ) { - free( hDirAC->buffer_intensity_real[i][j] ); + free( hDirACRend->buffer_intensity_real[i][j] ); } - hDirAC->buffer_intensity_real[i][j] = NULL; + hDirACRend->buffer_intensity_real[i][j] = NULL; } } - if ( hDirAC->buffer_energy != NULL ) + if ( hDirACRend->buffer_energy != NULL ) { - free( hDirAC->buffer_energy ); - hDirAC->buffer_energy = NULL; + free( hDirACRend->buffer_energy ); + hDirACRend->buffer_energy = NULL; } } /* output synthesis */ - ivas_dirac_dec_output_synthesis_init( hDirAC, nchan_out_woLFE, hodirac_flag ); + ivas_dirac_dec_output_synthesis_init( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); /* Allocate stack memory */ if ( flag_config != DIRAC_OPEN ) { - ivas_dirac_free_mem( &( hDirAC->stack_mem ) ); + ivas_dirac_free_mem( &( hDirACRend->stack_mem ) ); } - if ( ( error = ivas_dirac_alloc_mem( hDirAC, st_ivas->renderer_type, &( hDirAC->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) { return error; } - mvs2s( DirAC_block_grouping, hDirAC->block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); - if ( flag_config == DIRAC_OPEN ) { - hDirAC->dirac_md_buffer_length = 0; - hDirAC->dirac_bs_md_write_idx = 0; - hDirAC->dirac_read_idx = 0; - hDirAC->spar_to_dirac_write_idx = 0; - if ( st_ivas->mc_mode == MC_MODE_MCMASA ) - { - hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + st_ivas->hDirACRend = hDirACRend; + } - set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) - { - hDirAC->render_to_md_map[map_idx] = map_idx; - } - } -#ifdef MASA_AND_OBJECTS - else if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) -#else - else if ( st_ivas->ivas_format == MASA_FORMAT ) -#endif - { - hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; - hDirAC->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; + return error; +} - set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) - { - hDirAC->render_to_md_map[map_idx] = map_idx; - } - } - else - { - int16_t num_slots_in_subfr; - num_slots_in_subfr = hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; - hDirAC->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ); - hDirAC->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; - hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; - hDirAC->dirac_read_idx = 0; - hDirAC->dirac_estimator_idx = 0; - - set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) - { - hDirAC->render_to_md_map[map_idx] = hDirAC->dirac_read_idx + map_idx / num_slots_in_subfr; - } - } - if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK ) - { - return error; - } +/*------------------------------------------------------------------------- + * ivas_dirac_dec_config() + * + * Open or reconfigure decoder DirAC/MASA handle + *-------------------------------------------------------------------------*/ -#ifdef MASA_AND_OBJECTS - if ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ) ) -#else - if ( st_ivas->ivas_format == MASA_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_256k ) ) -#endif - { - if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else - { - hDirAC->azimuth2 = NULL; - hDirAC->elevation2 = NULL; - hDirAC->energy_ratio2 = NULL; - hDirAC->spreadCoherence2 = NULL; - } +ivas_error ivas_dirac_dec_config( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ +) +{ + ivas_error error; + int32_t output_Fs; + int16_t hodirac_flag; + int16_t sparfoa_flag; + DIRAC_CONFIG_FLAG dec_config_flag; + DIRAC_CONFIG_FLAG rend_config_flag; + DIRAC_CONFIG_FLAG common_rend_config_flag; + int16_t need_dirac_rend; + int16_t need_parambin; + int16_t dec_param_estim_old; + int16_t dec_param_estim_new; - hDirAC->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */ + error = IVAS_ERR_OK; - hDirAC->dithering_seed = DIRAC_DITH_SEED; - st_ivas->hDirAC = hDirAC; - } + /* Solve and setup flags for inits */ + dec_config_flag = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; - /* allocate transport channels*/ - if ( flag_config == DIRAC_OPEN ) + output_Fs = st_ivas->hDecoderConfig->output_Fs; + hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; + + + sparfoa_flag = 0; + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) + { + sparfoa_flag = 1; + } + + if ( ( error = ivas_dirac_dec_config_internal( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* This is required for parambin */ + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; + } + + dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; + + /* Setup renderers and meta */ + /* First, free everything if in reconfig and not the active renderer */ + need_parambin = 0; + switch ( st_ivas->renderer_type ) + { + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + case RENDERER_STEREO_PARAMETRIC: + need_parambin = 1; + break; + default: + need_parambin = 0; + } + + if ( !need_parambin ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + + need_dirac_rend = 0; + switch ( st_ivas->renderer_type ) + { + case RENDERER_DIRAC: + case RENDERER_BINAURAL_FASTCONV: + case RENDERER_BINAURAL_FASTCONV_ROOM: + case RENDERER_SBA_LINEAR_ENC: + case RENDERER_SBA_LINEAR_DEC: + need_dirac_rend = 1; + break; + default: + need_dirac_rend = 0; + } + + if ( !need_dirac_rend ) + { + ivas_dirac_rend_close( &st_ivas->hDirACRend ); + } + + if ( !sparfoa_flag ) + { + common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; + if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( need_dirac_rend ) + { + rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; + if ( ( error = ivas_dirac_rend_config( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( need_parambin ) + { + if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->hDiracDecBin == NULL ) + { + if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ + /* TODO: refactor merge: does this need to be adapted for OMASA? */ + if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) + { + ivas_dirac_dec_decorr_close( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); + } + + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( !st_ivas->hDiracDecBin->useTdDecorr ) + { + if ( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL ) + { + float frequency_axis[CLDFB_NO_CHANNELS_MAX]; + ivas_dirac_dec_get_frequency_axis( frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); + if ( ( error = ivas_dirac_dec_decorr_open( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), + &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), + st_ivas->hSpatParamRendCom->num_freq_bands, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, + frequency_axis, + BINAURAL_CHANNELS, + st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); + } + } + } + + /* Allocate transport channel buffers for SBA format when in JBM */ + if ( dec_config_flag == DIRAC_OPEN ) { if ( st_ivas->hDecoderConfig->voip_active == 1 && st_ivas->hTcBuffer == NULL ) { if ( st_ivas->ivas_format == SBA_FORMAT ) { int16_t nchan_to_allocate; + int16_t nchan_transport; + + nchan_transport = st_ivas->nchan_transport; nchan_to_allocate = nchan_transport; - if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { nchan_to_allocate++; /* we need a channel for the CNG in this case*/ } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { nchan_to_allocate = 2 * BINAURAL_CHANNELS; } - if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_to_allocate, nchan_to_allocate, hDirAC->slot_size ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_to_allocate, nchan_to_allocate, st_ivas->hSpatParamRendCom->slot_size ) ) != IVAS_ERR_OK ) { return error; } @@ -1108,10 +980,8 @@ ivas_error ivas_dirac_dec_config( *------------------------------------------------------------------------*/ void ivas_dirac_dec_close( - DIRAC_DEC_HANDLE *hDirAC_out /* i/o: decoder DirAC handle */ -) + DIRAC_DEC_HANDLE *hDirAC_out ) { - int16_t i, j; DIRAC_DEC_HANDLE hDirAC; if ( hDirAC_out == NULL || *hDirAC_out == NULL ) @@ -1128,86 +998,6 @@ void ivas_dirac_dec_close( hDirAC->hConfig = NULL; } - /* close Output synthesis sub-module */ - ivas_dirac_dec_output_synthesis_close( hDirAC ); - - /* close Decorrelator sub-module */ - if ( hDirAC->proto_signal_decorr_on ) - { - ivas_dirac_dec_decorr_close( &hDirAC->h_freq_domain_decorr_ap_params, &hDirAC->h_freq_domain_decorr_ap_state ); - } - - /* Params */ - - /* free frequency axis buffer */ - if ( hDirAC->frequency_axis != NULL ) - { - free( hDirAC->frequency_axis ); - hDirAC->frequency_axis = NULL; - } - - if ( hDirAC->diffuse_response_function != NULL ) - { - free( hDirAC->diffuse_response_function ); - hDirAC->diffuse_response_function = NULL; - } - - if ( hDirAC->hoa_encoder != NULL ) - { - free( hDirAC->hoa_encoder ); - hDirAC->hoa_encoder = NULL; - } - - /* prototype indexing */ - if ( hDirAC->proto_index_dir != NULL ) - { - free( hDirAC->proto_index_dir ); - hDirAC->proto_index_dir = NULL; - } - - if ( hDirAC->proto_index_diff != NULL ) - { - free( hDirAC->proto_index_diff ); - hDirAC->proto_index_dir = NULL; - } - - /* States */ - - /* free prototype signal buffers */ - if ( hDirAC->proto_frame_f != NULL ) - { - free( hDirAC->proto_frame_f ); - hDirAC->proto_frame_f = NULL; - } - - for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) - { - for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) - { - if ( hDirAC->buffer_intensity_real[i][j] != NULL ) - { - free( hDirAC->buffer_intensity_real[i][j] ); - hDirAC->buffer_intensity_real[i][j] = NULL; - } - } - } - if ( hDirAC->buffer_energy != NULL ) - { - free( hDirAC->buffer_energy ); - hDirAC->buffer_energy = NULL; - } - - ivas_dirac_deallocate_parameters( hDirAC, 1 ); - ivas_dirac_deallocate_parameters( hDirAC, 2 ); - - if ( hDirAC->masa_stereo_type_detect != NULL ) - { - free( hDirAC->masa_stereo_type_detect ); - hDirAC->masa_stereo_type_detect = NULL; - } - - ivas_dirac_free_mem( &( hDirAC->stack_mem ) ); - free( *hDirAC_out ); *hDirAC_out = NULL; @@ -1216,2019 +1006,562 @@ void ivas_dirac_dec_close( /*------------------------------------------------------------------------- - * ivas_dirac_deallocate_parameters() + * ivas_dirac_dec_read_BS() * - * Deallocate DirAC parameters - *-------------------------------------------------------------------------*/ + * Read DirAC parameters from the bitstream + *------------------------------------------------------------------------*/ -void ivas_dirac_deallocate_parameters( - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - const int16_t params_flag /* i : set of parameters flag */ +void ivas_dirac_dec_read_BS( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Decoder_State *st, /* i/o: decoder state structure */ + DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial rendering data handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */ + int16_t *nb_bits, /* o : number of bits read */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ ) { - int16_t i; - - if ( params_flag == 1 ) + int16_t i, j, b, dir, orig_dirac_bands; + int16_t next_bit_pos_orig; + *nb_bits = 0; + if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 ) { - if ( hDirAC->azimuth != NULL ) - { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->azimuth[i] != NULL ) - { - free( hDirAC->azimuth[i] ); - hDirAC->azimuth[i] = NULL; - } - } + next_bit_pos_orig = st->next_bit_pos; + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); - free( hDirAC->azimuth ); - hDirAC->azimuth = NULL; - } + /* 1 bit flag for signaling metadata to read */ + b = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits )++; - if ( hDirAC->elevation != NULL ) + if ( b == 1 ) /* WB 4TCs condition, no other metadata to read*/ { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->elevation[i] != NULL ) - { - free( hDirAC->elevation[i] ); - hDirAC->elevation[i] = NULL; - } - } + orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - free( hDirAC->elevation ); - hDirAC->elevation = NULL; - } + hQMetaData->sba_inactive_mode = 1; - if ( hDirAC->energy_ratio1 != NULL ) - { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + /* if we start with a SID frame, we need to init the azi/ele arrays.*/ + if ( st->ini_frame == 0 ) { - if ( hDirAC->energy_ratio1[i] != NULL ) + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { - free( hDirAC->energy_ratio1[i] ); - hDirAC->energy_ratio1[i] = NULL; + set_zero( hQMetaData->q_direction[0].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[0].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - free( hDirAC->energy_ratio1 ); - hDirAC->energy_ratio1 = NULL; - } - if ( hDirAC->diffuseness_vector != NULL ) - { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; + } + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - if ( hDirAC->diffuseness_vector[i] != NULL ) + for ( j = orig_dirac_bands - 2; j >= 0; j-- ) { - free( hDirAC->diffuseness_vector[i] ); - hDirAC->diffuseness_vector[i] = NULL; + hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; + hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } } - free( hDirAC->diffuseness_vector ); - hDirAC->diffuseness_vector = NULL; + hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } - - if ( hDirAC->spreadCoherence != NULL ) + else { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + hQMetaData->sba_inactive_mode = 0; + hQMetaData->is_masa_ivas_format = 0; + if ( hQMetaData->useLowerRes ) { - if ( hDirAC->spreadCoherence[i] != NULL ) - { - free( hDirAC->spreadCoherence[i] ); - hDirAC->spreadCoherence[i] = NULL; - } + hQMetaData->q_direction[0].cfg.nblocks = 1; } - free( hDirAC->spreadCoherence ); - hDirAC->spreadCoherence = NULL; - } - - if ( hDirAC->surroundingCoherence != NULL ) - { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + else { - if ( hDirAC->surroundingCoherence[i] != NULL ) - { - free( hDirAC->surroundingCoherence[i] ); - hDirAC->surroundingCoherence[i] = NULL; - } + hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; } - free( hDirAC->surroundingCoherence ); - hDirAC->surroundingCoherence = NULL; + + *nb_bits += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ); } + +#ifdef DEBUGGING + assert( *nb_bits >= 0 ); +#endif + + st->next_bit_pos = next_bit_pos_orig; } - else if ( params_flag == 2 ) + else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 ) { - if ( hDirAC->azimuth2 != NULL ) - { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->azimuth2[i] != NULL ) - { - free( hDirAC->azimuth2[i] ); - hDirAC->azimuth2[i] = NULL; - } - } - free( hDirAC->azimuth2 ); - hDirAC->azimuth2 = NULL; - } + next_bit_pos_orig = st->next_bit_pos; + + /* subtract mode signaling bits, since bitstream was moved after mode reading */ + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); +#ifndef SBA_MODE_CLEANUP_2 + /* 1 bit flag for SPAR/DirAC, already read in read format function */ +#else + /* 1 bit flag for signaling metadata to read */ +#endif + b = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits )++; + hQMetaData->sba_inactive_mode = 1; + orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - if ( hDirAC->elevation2 != NULL ) + /* if we start with a SID frame, we need to init the azi/ele arrays.*/ + if ( st->ini_frame == 0 ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + for ( dir = 0; dir < hQMetaData->no_directions; dir++ ) { - if ( hDirAC->elevation2[i] != NULL ) + for ( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ ) { - free( hDirAC->elevation2[i] ); - hDirAC->elevation2[i] = NULL; + set_zero( hQMetaData->q_direction[dir].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[dir].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); } } - free( hDirAC->elevation2 ); - hDirAC->elevation2 = NULL; } - if ( hDirAC->energy_ratio2 != NULL ) + *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ); + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) - { - if ( hDirAC->energy_ratio2[i] != NULL ) - { - free( hDirAC->energy_ratio2[i] ); - hDirAC->energy_ratio2[i] = NULL; - } - } - free( hDirAC->energy_ratio2 ); - hDirAC->energy_ratio2 = NULL; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; } - - if ( hDirAC->spreadCoherence2 != NULL ) + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - for ( i = 0; i < hDirAC->dirac_md_buffer_length; i++ ) + for ( j = orig_dirac_bands - 2; j >= 0; j-- ) { - if ( hDirAC->spreadCoherence2[i] != NULL ) - { - free( hDirAC->spreadCoherence2[i] ); - hDirAC->spreadCoherence2[i] = NULL; - } + hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; + hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; } - free( hDirAC->spreadCoherence2 ); - hDirAC->spreadCoherence2 = NULL; } + + hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + + st->next_bit_pos = next_bit_pos_orig; + } + + if ( hDirAC != NULL && hSpatParamRendCom != NULL ) + { + ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); } return; } -/*------------------------------------------------------------------------- - * ivas_dirac_alloc_mem() +/*-----------------------------------------------------------------------* + * ivas_qmetadata_to_dirac() * - * Allocate stack memory for DirAC renderer - *------------------------------------------------------------------------*/ + * Copy qmetedata to DirAC parameters for rendering + *-----------------------------------------------------------------------*/ -static ivas_error ivas_dirac_alloc_mem( - DIRAC_DEC_HANDLE hDirAC, - const RENDERER_TYPE renderer_type, - DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, - const int16_t hodirac_flag ) +void ivas_qmetadata_to_dirac( + const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ + DIRAC_DEC_HANDLE hDirAC, /* i : DirAC decoder structure */ + MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ +) { - int16_t num_freq_bands, num_freq_bands_diff, size; - int16_t size_ho; - int16_t size_pf; - int16_t num_outputs_dir, num_outputs_diff; - int16_t num_protos_dir; + int16_t block, band; + int16_t *seed_ptr; + int16_t band_start, band_end, diff_idx; + float diffuseness; + int16_t b, ele, azi; + float azimuth, elevation; + IVAS_QDIRECTION *q_direction; + int16_t *band_mapping; + int16_t *band_grouping; + int16_t start_band; + int16_t nbands = 0; + int16_t nblocks = 0; + int16_t qBand_idx; + int16_t idx_sec = 0; + int16_t no_secs = 1; - num_protos_dir = hDirAC->num_protos_dir; - - num_freq_bands = hDirAC->num_freq_bands; - num_freq_bands_diff = hDirAC->h_output_synthesis_psd_params.max_band_decorr; - - num_outputs_dir = hDirAC->num_outputs_dir; - num_outputs_diff = hDirAC->num_outputs_diff; + q_direction = &( hQMetaData->q_direction[0] ); +#ifdef MASA_AND_OBJECTS + hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; + hSpatParamRendCom->numSimultaneousDirections = hSpatParamRendCom->numParametricDirections + hSpatParamRendCom->numIsmDirections; +#else + hSpatParamRendCom->numSimultaneousDirections = hQMetaData->no_directions; +#endif - size = num_freq_bands * num_outputs_dir; - if ( hodirac_flag ) - { - size_ho = size * DIRAC_HO_NUMSECTORS; - size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS; - } - else + if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) { - size_ho = size; - size_pf = num_freq_bands; - } + int16_t meta_write_index; + band_mapping = hMasa->data.band_mapping; - /* PSD related buffers */ - hDirAC_mem->cy_auto_dir_smooth = NULL; - hDirAC_mem->proto_power_smooth = NULL; - hDirAC_mem->proto_power_diff_smooth = NULL; - hDirAC_mem->direct_responses_square = NULL; - hDirAC_mem->frame_dec_f = NULL; - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; - if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->proto_power_smooth, size ); + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + hSpatParamRendCom->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hSpatParamRendCom->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; + hSpatParamRendCom->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; + hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block]; - if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->proto_power_diff_smooth, size ); + if ( q_direction->coherence_band_data != NULL ) + { + hSpatParamRendCom->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; + } + else + { + hSpatParamRendCom->spreadCoherence[meta_write_index][b] = 0.0f; + } - if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + if ( hQMetaData->surcoh_band_data != NULL ) + { + hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f; + } + else + { + hSpatParamRendCom->surroundingCoherence[meta_write_index][b] = 0.0f; + } + } + } } - set_zero( hDirAC_mem->direct_responses_square, size ); - if ( hDirAC->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + + if ( hQMetaData->no_directions == 2 ) { - if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) + q_direction = &( hQMetaData->q_direction[1] ); + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - } - } - hDirAC->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; - hDirAC->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; - hDirAC->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; - hDirAC->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; - /* Target and smoothed nrg factors/gains */ - if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); + for ( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + hSpatParamRendCom->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; + hSpatParamRendCom->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; + hSpatParamRendCom->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; + hSpatParamRendCom->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block]; - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + if ( q_direction->coherence_band_data != NULL ) + { + hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; + } + else + { + hSpatParamRendCom->spreadCoherence2[meta_write_index][b] = 0.0f; + } + } + } + } } - set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); - } - else - { - if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) + else if ( hSpatParamRendCom->azimuth2 != NULL && hSpatParamRendCom->elevation2 != NULL && hSpatParamRendCom->energy_ratio2 != NULL && hSpatParamRendCom->spreadCoherence2 != NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + /* zero out old dir2 data */ + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) + { + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + block ) % hSpatParamRendCom->dirac_md_buffer_length; + set_s( hSpatParamRendCom->azimuth2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands ); + set_s( hSpatParamRendCom->elevation2[meta_write_index], 0, hSpatParamRendCom->num_freq_bands ); + set_zero( hSpatParamRendCom->energy_ratio2[meta_write_index], hSpatParamRendCom->num_freq_bands ); + set_zero( hSpatParamRendCom->spreadCoherence2[meta_write_index], hSpatParamRendCom->num_freq_bands ); + } } - set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); } - hDirAC->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; - hDirAC->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; - - /*Responses (gains/factors)*/ - if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) + else /* SBA mode/SID/Zero frame*/ { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - set_zero( hDirAC_mem->direct_responses, size ); - + int16_t tmp_write_idx_param_band; + int16_t tmp_write_idx_band; + float diffuseness_sec = 0.f; - hDirAC->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; + /* ungroup */ + seed_ptr = &hDirAC->dithering_seed; + nblocks = q_direction->cfg.nblocks; + nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands]; + band_grouping = hDirAC->band_grouping; - /* Prototypes */ - hDirAC_mem->proto_direct_buffer_f = NULL; - hDirAC_mem->proto_diffuse_buffer_f = NULL; - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) - { - if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) + if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/ + start_band = 0; + hDirAC->hConfig->nbands = 5; + ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL ); + nbands = 5; } - - if ( hDirAC->proto_signal_decorr_on ) + else { - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + start_band = hDirAC->hConfig->enc_param_start_band; + if ( ivas_format == SBA_FORMAT ) { - if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS; } else { - if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + hDirAC->hConfig->nbands = q_direction->cfg.nbands; } - } - } - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; - hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; - /* Gains/power factors*/ - hDirAC_mem->direct_power_factor = NULL; - hDirAC_mem->diffuse_power_factor = NULL; + ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft ); - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) - { - if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + nbands = hDirAC->hConfig->nbands; + if ( hQMetaData->q_direction[0].cfg.nblocks == 0 ) + { + /* No transmission -> no copy from qmetadata buffers*/ + nbands = start_band; + } } - } - - hDirAC->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; - hDirAC->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; - hDirAC_mem->reference_power = NULL; - hDirAC_mem->onset_filter = NULL; - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + /* Low-Bands with no spatial data transmitted, analysis at decoder side */ + for ( band = 0; band < start_band; band++ ) { - if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - if ( hDirAC->proto_signal_decorr_on ) + band_start = band_grouping[band]; + band_end = band_grouping[band + 1]; + tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx; + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) + for ( b = band_start; b < band_end; b++ ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + tmp_write_idx_band = tmp_write_idx_param_band; + hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; + hSpatParamRendCom->surroundingCoherence[block][b] = 0.0f; + + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = 0.f; + + hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; + hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; + hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } } - } - else - { - if ( num_protos_dir > 2 ) + + /* Bands with spatial data transmitted */ + if ( hodirac_flag ) { - if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } + no_secs = DIRAC_HO_NUMSECTORS; } - if ( hDirAC->proto_signal_decorr_on ) + for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ ) { - if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + for ( band = start_band; band < nbands; band++ ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); - } - } - } - - return IVAS_ERR_OK; -} - + band_start = band_grouping[band]; + band_end = band_grouping[band + 1]; + tmp_write_idx_param_band = hSpatParamRendCom->dirac_bs_md_write_idx; -static void ivas_dirac_free_mem( - DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) -{ - if ( hDirAC_mem->cy_auto_dir_smooth != NULL ) - { - free( hDirAC_mem->cy_auto_dir_smooth ); - } - if ( hDirAC_mem->proto_power_smooth != NULL ) - { - free( hDirAC_mem->proto_power_smooth ); - } - if ( hDirAC_mem->proto_power_diff_smooth != NULL ) - { - free( hDirAC_mem->proto_power_diff_smooth ); - } - if ( hDirAC_mem->direct_responses_square != NULL ) - { - free( hDirAC_mem->direct_responses_square ); - } - if ( hDirAC_mem->frame_dec_f != NULL ) - { - free( hDirAC_mem->frame_dec_f ); - } - if ( hDirAC_mem->cy_cross_dir_smooth != NULL ) - { - free( hDirAC_mem->cy_cross_dir_smooth ); - } - if ( hDirAC_mem->cy_auto_diff_smooth != NULL ) - { - free( hDirAC_mem->cy_auto_diff_smooth ); - } - if ( hDirAC_mem->direct_responses != NULL ) - { - free( hDirAC_mem->direct_responses ); - } - if ( hDirAC_mem->proto_direct_buffer_f != NULL ) - { - free( hDirAC_mem->proto_direct_buffer_f ); - } - if ( hDirAC_mem->proto_diffuse_buffer_f != NULL ) - { - free( hDirAC_mem->proto_diffuse_buffer_f ); - } - if ( hDirAC_mem->direct_power_factor != NULL ) - { - free( hDirAC_mem->direct_power_factor ); - } - if ( hDirAC_mem->diffuse_power_factor != NULL ) - { - free( hDirAC_mem->diffuse_power_factor ); - } - if ( hDirAC_mem->reference_power != NULL ) - { - free( hDirAC_mem->reference_power ); - } - if ( hDirAC_mem->onset_filter != NULL ) - { - free( hDirAC_mem->onset_filter ); - } + if ( ivas_format == SBA_FORMAT ) + { + qBand_idx = dirac_to_spar_md_bands[band] - start_band; + } + else + { + qBand_idx = band; + } + diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0]; +#ifdef DEBUG_MODE_DIRAC + dbgwrite( &diffuseness, sizeof( float ), 1, 1, "./res/dirac_dec_diffuseness.dat" ); +#endif + diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0]; - return; -} + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + { + int16_t block_qmetadata; + block_qmetadata = min( block, nblocks - 1 ); + block_qmetadata = max( block_qmetadata, 0 ); -/*------------------------------------------------------------------------- - * ivas_dirac_dec_read_BS() - * - * Read DirAC parameters from the bitstream - *------------------------------------------------------------------------*/ + if ( q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f ) + { + q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] += 360.f; + } -void ivas_dirac_dec_read_BS( - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - Decoder_State *st, /* i/o: decoder state structure */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: decoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata */ - int16_t *nb_bits, /* o : number of bits read */ - const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ -) -{ - int16_t i, j, b, dir, orig_dirac_bands; - int16_t next_bit_pos_orig; - *nb_bits = 0; - if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 ) - { - next_bit_pos_orig = st->next_bit_pos; - st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); + if ( hMasa == NULL && hodirac_flag ) + { + azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata]; + elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata]; + diffuseness = 1.f - q_direction[0].band_data[qBand_idx].energy_ratio[block_qmetadata]; + diffuseness_sec = q_direction[1].band_data[qBand_idx].energy_ratio[block_qmetadata]; + assert( diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f ); + } + else + { + azimuth = q_direction->band_data[qBand_idx].azimuth[block_qmetadata]; + elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata]; + } - /* 1 bit flag for signaling metadata to read */ - b = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits )++; + for ( b = band_start; b < band_end; b++ ) + { + tmp_write_idx_band = tmp_write_idx_param_band; - if ( b == 1 ) /* WB 4TCs condition, no other metadata to read*/ - { - orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; + if ( hodirac_flag ) + { + azi = (int16_t) ( azimuth + 0.5f ); + ele = (int16_t) ( elevation + 0.5f ); + } + else + { + azi = (int16_t) ( azimuth + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f ); + ele = (int16_t) ( elevation + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f ); + /* limit the elevation to [-90, 90] */ + ele = min( 90, ele ); + ele = max( -90, ele ); + } - hQMetaData->sba_inactive_mode = 1; + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) + { + hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f; + } + else + { + hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; + } - /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - if ( st->ini_frame == 0 ) - { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - set_zero( hQMetaData->q_direction[0].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[0].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - - *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) - { - hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; - hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; - hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; - } - } - - hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; - } - else - { - hQMetaData->sba_inactive_mode = 0; - hQMetaData->is_masa_ivas_format = 0; - if ( hQMetaData->useLowerRes ) - { - hQMetaData->q_direction[0].cfg.nblocks = 1; - } - else - { - hQMetaData->q_direction[0].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; - } - - *nb_bits += ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ); - } - -#ifdef DEBUGGING - assert( *nb_bits >= 0 ); -#endif - - st->next_bit_pos = next_bit_pos_orig; - } - else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 ) - { - next_bit_pos_orig = st->next_bit_pos; - - /* subtract mode signaling bits, since bitstream was moved after mode reading */ - st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); -#ifndef SBA_MODE_CLEANUP_2 - /* 1 bit flag for SPAR/DirAC, already read in read format function */ -#else - /* 1 bit flag for signaling metadata to read */ -#endif - b = st->bit_stream[( st->next_bit_pos )--]; - ( *nb_bits )++; - hQMetaData->sba_inactive_mode = 1; - orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; - - /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - if ( st->ini_frame == 0 ) - { - for ( dir = 0; dir < hQMetaData->no_directions; dir++ ) - { - for ( b = 0; b < hQMetaData->q_direction[dir].cfg.nbands; b++ ) - { - set_zero( hQMetaData->q_direction[dir].band_data[b].azimuth, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[dir].band_data[b].elevation, MAX_PARAM_SPATIAL_SUBFRAMES ); - } - } - } - - *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ); - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; - hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; - } - for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) - { - for ( j = orig_dirac_bands - 2; j >= 0; j-- ) - { - hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; - hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; - hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; - } - } - - hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; - - st->next_bit_pos = next_bit_pos_orig; - } - - if ( hDirAC != NULL ) - { - ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); - } - - return; -} - - -/*-----------------------------------------------------------------------* - * ivas_qmetadata_to_dirac() - * - * Copy qmetedata to DirAC parameters for rendering - *-----------------------------------------------------------------------*/ - -void ivas_qmetadata_to_dirac( - const IVAS_QMETADATA_HANDLE hQMetaData, /* i : frame of MASA q_metadata */ - DIRAC_DEC_HANDLE hDirAC, /* o : DirAC decoder structure */ - MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ - int16_t *dirac_to_spar_md_bands /* o : DirAC->SPAR MD bands */ -) -{ - int16_t block, band; - int16_t *seed_ptr; - int16_t band_start, band_end, diff_idx; - float diffuseness; - int16_t b, ele, azi; - float azimuth, elevation; - IVAS_QDIRECTION *q_direction; - int16_t *band_mapping; - int16_t *band_grouping; - int16_t start_band; - int16_t nbands = 0; - int16_t nblocks = 0; - int16_t qBand_idx; - int16_t idx_sec = 0; - int16_t no_secs = 1; - - q_direction = &( hQMetaData->q_direction[0] ); -#ifdef MASA_AND_OBJECTS - hDirAC->numParametricDirections = hQMetaData->no_directions; - hDirAC->numSimultaneousDirections = hDirAC->numParametricDirections + hDirAC->numIsmDirections; -#else - hDirAC->numSimultaneousDirections = hQMetaData->no_directions; -#endif - - if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) - { - int16_t meta_write_index; - band_mapping = hMasa->data.band_mapping; - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) - { - meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) - { - hDirAC->azimuth[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; - hDirAC->elevation[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; - hDirAC->energy_ratio1[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; - hDirAC->diffuseness_vector[meta_write_index][b] = 1.0f - q_direction->band_data[band].energy_ratio[block]; - - if ( q_direction->coherence_band_data != NULL ) - { - hDirAC->spreadCoherence[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; - } - else - { - hDirAC->spreadCoherence[meta_write_index][b] = 0.0f; - } - - if ( hQMetaData->surcoh_band_data != NULL ) - { - hDirAC->surroundingCoherence[meta_write_index][b] = hQMetaData->surcoh_band_data[band].surround_coherence[block] / 255.0f; - } - else - { - hDirAC->surroundingCoherence[meta_write_index][b] = 0.0f; - } - } - } - } - - if ( hQMetaData->no_directions == 2 ) - { - q_direction = &( hQMetaData->q_direction[1] ); - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) - { - meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - - for ( band = 0; band < hMasa->config.numCodingBands; ++band ) - { - for ( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) - { - hDirAC->azimuth2[meta_write_index][b] = (int16_t) q_direction->band_data[band].azimuth[block]; - hDirAC->elevation2[meta_write_index][b] = (int16_t) q_direction->band_data[band].elevation[block]; - hDirAC->energy_ratio2[meta_write_index][b] = q_direction->band_data[band].energy_ratio[block]; - hDirAC->diffuseness_vector[meta_write_index][b] -= q_direction->band_data[band].energy_ratio[block]; - - if ( q_direction->coherence_band_data != NULL ) - { - hDirAC->spreadCoherence2[meta_write_index][b] = q_direction->coherence_band_data[band].spread_coherence[block] / 255.0f; - } - else - { - hDirAC->spreadCoherence2[meta_write_index][b] = 0.0f; - } - } - } - } - } - else if ( hDirAC->azimuth2 != NULL && hDirAC->elevation2 != NULL && hDirAC->energy_ratio2 != NULL && hDirAC->spreadCoherence2 != NULL ) - { - /* zero out old dir2 data */ - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) - { - meta_write_index = ( hDirAC->dirac_bs_md_write_idx + block ) % hDirAC->dirac_md_buffer_length; - set_s( hDirAC->azimuth2[meta_write_index], 0, hDirAC->num_freq_bands ); - set_s( hDirAC->elevation2[meta_write_index], 0, hDirAC->num_freq_bands ); - set_zero( hDirAC->energy_ratio2[meta_write_index], hDirAC->num_freq_bands ); - set_zero( hDirAC->spreadCoherence2[meta_write_index], hDirAC->num_freq_bands ); - } - } - } - else /* SBA mode/SID/Zero frame*/ - { - int16_t tmp_write_idx_param_band; - int16_t tmp_write_idx_band; - float diffuseness_sec = 0.f; - - /* ungroup */ - seed_ptr = &hDirAC->dithering_seed; - nblocks = q_direction->cfg.nblocks; - nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands]; - band_grouping = hDirAC->band_grouping; - - if ( ivas_total_brate <= IVAS_SID_5k2 && ivas_format != SBA_FORMAT ) - { - /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/ - start_band = 0; - hDirAC->hConfig->nbands = 5; - ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, NULL, 0, 0, NULL ); - nbands = 5; - } - else - { - start_band = hDirAC->hConfig->enc_param_start_band; - if ( ivas_format == SBA_FORMAT ) - { - hDirAC->hConfig->nbands = IVAS_MAX_NUM_BANDS; - } - else - { - hDirAC->hConfig->nbands = q_direction->cfg.nbands; - } - - ivas_dirac_config_bands( hDirAC->band_grouping, hDirAC->hConfig->nbands, nbands, dirac_to_spar_md_bands, hQMetaData->useLowerBandRes, hDirAC->hConfig->enc_param_start_band, hDirAC->hFbMdft ); - - nbands = hDirAC->hConfig->nbands; - if ( hQMetaData->q_direction[0].cfg.nblocks == 0 ) - { - /* No transmission -> no copy from qmetadata buffers*/ - nbands = start_band; - } - } - - /* Low-Bands with no spatial data transmitted, analysis at decoder side */ - for ( band = 0; band < start_band; band++ ) - { - band_start = band_grouping[band]; - band_end = band_grouping[band + 1]; - tmp_write_idx_param_band = hDirAC->dirac_bs_md_write_idx; - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - for ( b = band_start; b < band_end; b++ ) - { - tmp_write_idx_band = tmp_write_idx_param_band; - hDirAC->spreadCoherence[block][b] = 0.0f; - hDirAC->surroundingCoherence[block][b] = 0.0f; - - hDirAC->elevation[tmp_write_idx_band][b] = 0; - hDirAC->azimuth[tmp_write_idx_band][b] = 0; - hDirAC->diffuseness_vector[tmp_write_idx_band][b] = 0.f; - - hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f; - hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; - hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0; - tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length; - } - } - } - - /* Bands with spatial data transmitted */ - if ( hodirac_flag ) - { - no_secs = DIRAC_HO_NUMSECTORS; - } - - for ( idx_sec = 0; idx_sec < no_secs; idx_sec++ ) - { - for ( band = start_band; band < nbands; band++ ) - { - band_start = band_grouping[band]; - band_end = band_grouping[band + 1]; - tmp_write_idx_param_band = hDirAC->dirac_bs_md_write_idx; - - if ( ivas_format == SBA_FORMAT ) - { - qBand_idx = dirac_to_spar_md_bands[band] - start_band; - } - else - { - qBand_idx = band; - } - diffuseness = 1.0f - q_direction->band_data[qBand_idx].energy_ratio[0]; -#ifdef DEBUG_MODE_DIRAC - dbgwrite( &diffuseness, sizeof( float ), 1, 1, "./res/dirac_dec_diffuseness.dat" ); -#endif - diff_idx = q_direction->band_data[qBand_idx].energy_ratio_index[0]; - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - int16_t block_qmetadata; - - block_qmetadata = min( block, nblocks - 1 ); - block_qmetadata = max( block_qmetadata, 0 ); - - if ( q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] < 0.f ) - { - q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata] += 360.f; - } - - if ( hMasa == NULL && hodirac_flag ) - { - azimuth = q_direction[idx_sec].band_data[qBand_idx].azimuth[block_qmetadata]; - elevation = q_direction[idx_sec].band_data[qBand_idx].elevation[block_qmetadata]; - diffuseness = 1.f - q_direction[0].band_data[qBand_idx].energy_ratio[block_qmetadata]; - diffuseness_sec = q_direction[1].band_data[qBand_idx].energy_ratio[block_qmetadata]; - assert( diffuseness_sec < 1.0001f && diffuseness_sec > -0.0001f ); - } - else - { - azimuth = q_direction->band_data[qBand_idx].azimuth[block_qmetadata]; - elevation = q_direction->band_data[qBand_idx].elevation[block_qmetadata]; - } - - for ( b = band_start; b < band_end; b++ ) - { - tmp_write_idx_band = tmp_write_idx_param_band; - - if ( hodirac_flag ) - { - azi = (int16_t) ( azimuth + 0.5f ); - ele = (int16_t) ( elevation + 0.5f ); - } - else - { - azi = (int16_t) ( azimuth + rand_triangular_signed( seed_ptr ) * dirac_dithering_azi_scale[diff_idx] + 0.5f ); - ele = (int16_t) ( elevation + rand_triangular_signed( seed_ptr ) * dirac_dithering_ele_scale[diff_idx] + 0.5f ); - /* limit the elevation to [-90, 90] */ - ele = min( 90, ele ); - ele = max( -90, ele ); - } - - if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) - { - hDirAC->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f; - } - else - { - hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f; - } - - if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) - { - hDirAC->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f; - } - else - { - hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; - } - - hDirAC->energy_ratio1[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio[0]; - - hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness; - - if ( hodirac_flag ) - { - if ( idx_sec == 0 ) - { - hDirAC->elevation[tmp_write_idx_band][b] = ele; - hDirAC->azimuth[tmp_write_idx_band][b] = azi; - hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0.f; // not in use - } - else - { - assert( idx_sec == 1 ); - hDirAC->elevation2[tmp_write_idx_band][b] = ele; - hDirAC->azimuth2[tmp_write_idx_band][b] = azi; - hDirAC->energy_ratio2[tmp_write_idx_band][b] = 1.f - diffuseness_sec; - } - } - else - { - hDirAC->elevation[tmp_write_idx_band][b] = ele; - hDirAC->azimuth[tmp_write_idx_band][b] = azi; - } - } - tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hDirAC->dirac_md_buffer_length; - - } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ - - /* Bands not transmitted -> zeroed*/ - for ( b = band_grouping[band]; b < hDirAC->num_freq_bands; b++ ) - { - tmp_write_idx_band = hDirAC->dirac_bs_md_write_idx; - - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) - { - - hDirAC->spreadCoherence[block][b] = 0.0f; - hDirAC->surroundingCoherence[block][b] = 0.0f; - hDirAC->energy_ratio1[block][b] = 0; - - hDirAC->elevation[tmp_write_idx_band][b] = 0; - hDirAC->azimuth[tmp_write_idx_band][b] = 0; - hDirAC->diffuseness_vector[tmp_write_idx_band][b] = 0.f; - hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f; - hDirAC->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; - hDirAC->energy_ratio1[tmp_write_idx_band][b] = 0; - tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length; - } - } - } - - /* update buffer write index */ - hDirAC->dirac_bs_md_write_idx = ( hDirAC->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length; - - return; -} - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_set_md_map() - * - * Set metadata index mapping for DirAC - *------------------------------------------------------------------------*/ - -void ivas_dirac_dec_set_md_map( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nCldfbTs /* i : number of CLDFB time slots */ -) -{ - int16_t num_slots_in_subfr; - DIRAC_DEC_HANDLE hDirAC; - - hDirAC = st_ivas->hDirAC; -#ifdef DEBUGGING - assert( hDirAC ); -#endif - - /* adapt subframes */ - hDirAC->num_slots = nCldfbTs; - hDirAC->slots_rendered = 0; - num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->subframes_rendered = 0; - - ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hDirAC->subframe_nbslots, &hDirAC->nb_subframes ); - - /* set mapping according to dirac_read_idx */ - - set_s( hDirAC->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - -#ifdef FIX_470_MASA_JBM_EXT - if ( st_ivas->ivas_format == MASA_FORMAT ) - { - ivas_jbm_dec_get_md_map_even_spacing( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map ); - } - else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) -#else - if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) -#endif - { - ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map ); - } - else - { - ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hDirAC->dirac_read_idx, hDirAC->dirac_md_buffer_length, hDirAC->render_to_md_map ); - } - - if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) - { - float tmp; - int16_t sf_idx, slot_idx, slot_idx_abs; - - slot_idx_abs = 0; - for ( sf_idx = 0; sf_idx < hDirAC->nb_subframes; sf_idx++ ) - { - tmp = 0.0f; - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[sf_idx]; slot_idx++ ) - { - tmp += (float) hDirAC->render_to_md_map[slot_idx_abs]; - slot_idx_abs++; - } - hDirAC->render_to_md_map[sf_idx] = ( (int16_t) roundf( tmp / (float) hDirAC->subframe_nbslots[sf_idx] ) + hDirAC->dirac_read_idx ) % hDirAC->dirac_md_buffer_length; - } - - set_s( &hDirAC->render_to_md_map[hDirAC->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hDirAC->nb_subframes ); - } - - return; -} - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec() - * - * DirAC decoding process - *------------------------------------------------------------------------*/ - -void ivas_dirac_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ - const int16_t nchan_transport /* i : number of transport channels */ -) -{ - int16_t subframe_idx; - float *output_f_local[MAX_OUTPUT_CHANNELS]; - float cng_td_buffer[L_FRAME16k]; - int16_t nchan_out, n, n_samples_sf; - nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; - - n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * st_ivas->hDirAC->slot_size; - - for ( n = 0; n < nchan_out; n++ ) - { - output_f_local[n] = &output_f[n][0]; - } - - for ( n = 0; n < nchan_transport; n++ ) - { - st_ivas->hTcBuffer->tc[n] = output_f[n]; - } - - if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) - { - Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; - st_ivas->hTcBuffer->tc[nchan_transport] = &cng_td_buffer[0]; - generate_masking_noise_lb_dirac( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc[1], DEFAULT_JBM_CLDFB_TIMESLOTS, st->cna_dirac_flag && st->flag_cna ); - } - - ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); - - for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) - { - ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); - for ( n = 0; n < nchan_out; n++ ) - { - output_f_local[n] += n_samples_sf; - } - } - - if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) - { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length; - } - else - { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length; - } - - for ( n = 0; n < nchan_transport; n++ ) - { - st_ivas->hTcBuffer->tc[n] = NULL; - } - - if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) - { - st_ivas->hTcBuffer->tc[nchan_transport] = NULL; - } - - return; -} - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec_render() - * - * DirAC decoding renderer process - *------------------------------------------------------------------------*/ - -void ivas_dirac_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const int16_t nchan_transport, /* i : number of transport channels */ - const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ - uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ - uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - float *output_f[] /* o : rendered time signal */ -) -{ - int16_t slots_to_render, first_sf, last_sf, subframe_idx; - uint16_t slot_size, n_samples_sf, ch, nchan_intern; - DIRAC_DEC_HANDLE hDirAC; - float *output_f_local[MAX_OUTPUT_CHANNELS]; - - hDirAC = st_ivas->hDirAC; - - nchan_intern = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; -#ifdef DEBUGGING - assert( hDirAC ); -#endif - for ( ch = 0; ch < nchan_intern; ch++ ) - { - output_f_local[ch] = output_f[ch]; - } - slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - - /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size ); - *nSamplesRendered = slots_to_render * slot_size; - first_sf = hDirAC->subframes_rendered; - last_sf = first_sf; - - while ( slots_to_render > 0 ) - { - slots_to_render -= hDirAC->subframe_nbslots[last_sf]; - last_sf++; - } - -#ifdef DEBUGGING - assert( slots_to_render == 0 ); -#endif - for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) - { - ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); - n_samples_sf = hDirAC->subframe_nbslots[subframe_idx] * st_ivas->hDirAC->slot_size; - for ( ch = 0; ch < nchan_intern; ch++ ) - { - output_f_local[ch] += n_samples_sf; - } - } - - if ( hDirAC->slots_rendered == hDirAC->num_slots ) - { - if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) - { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length; - } - else - { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length; - } - } - - *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size; - - return; -} - - -/*------------------------------------------------------------------------- - * ivas_dirac_dec() - * - * DirAC decoding process - *------------------------------------------------------------------------*/ - -void ivas_dirac_dec_render_sf( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ - const int16_t nchan_transport, /* i : number of transport channels */ - float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], - float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) -{ - int16_t i, ch, idx_in, idx_lfe; - DIRAC_DEC_HANDLE hDirAC; - float dirEne; - float surCohEner; - float surCohRatio[CLDFB_NO_CHANNELS_MAX]; - int16_t subframe_idx; - int16_t slot_idx, index_slot; - int16_t hodirac_flag; - float *p_Rmat; - int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; - - /*CLDFB: last output channels reserved to LFT for CICPx*/ - float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; -#ifdef SPLIT_REND_WITH_HEAD_ROT - float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; -#else - float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; -#endif -#ifdef MASA_AND_OBJECTS - float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ - float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ -#endif - int16_t index, num_freq_bands; - - /* local copies of azi, ele, diffuseness */ - int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; - int16_t elevation[CLDFB_NO_CHANNELS_MAX]; - float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; - - DIRAC_DEC_STACK_MEM DirAC_mem; - float *reference_power, *reference_power_smooth; - float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; - uint16_t coherence_flag; - - push_wmops( "ivas_dirac_dec_render" ); - - /* Initialize aux buffers */ - hDirAC = st_ivas->hDirAC; - - DirAC_mem = st_ivas->hDirAC->stack_mem; - - reference_power = DirAC_mem.reference_power; - reference_power_smooth = DirAC_mem.reference_power + hDirAC->num_freq_bands; - onset_filter = DirAC_mem.onset_filter; -#ifdef FIX_614_ADD_TO_NULL_PTR_DIRAC_SETUP - onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hDirAC->num_freq_bands; -#else - onset_filter_subframe = DirAC_mem.onset_filter + hDirAC->num_freq_bands; -#endif - - hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - - if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT ) - { - coherence_flag = st_ivas->hQMetaData->coherence_flag; - } - else - { - coherence_flag = 0; - } - -#ifdef DEBUG_MODE_DIRAC - { - int16_t n, tmp[IVAS_SPAR_MAX_CH * L_FRAME48k]; - char file_name[50] = { 0 }; - const int16_t output_frame = st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; - - for ( n = 0; n < nchan_transport; n++ ) - { - for ( i = 0; i < output_frame; i++ ) - { - tmp[nchan_transport * i + n] = (int16_t) ( output_f[n][i] + 0.5f ); - } - } - sprintf( file_name, "./res/ivas_dirac_dec_DMX%d.%d.pcm", nchan_transport, (int16_t) ( output_frame * 0.05 ) ); - dbgwrite( tmp, sizeof( int16_t ), nchan_transport * output_frame, 1, file_name ); - } -#endif - - /* Subframe loop */ - slot_idx_start = hDirAC->slots_rendered; - slot_idx_start_cldfb_synth = 0; - - subframe_idx = hDirAC->subframes_rendered; - if ( hDirAC->hConfig->dec_param_estim == FALSE ) - { - md_idx = hDirAC->render_to_md_map[subframe_idx]; - } - else - { - md_idx = hDirAC->render_to_md_map[slot_idx_start]; - } - /* ToDo: Another workaround for self test BE */ - - /* copy parameters into local buffers*/ - if ( hDirAC->hConfig->dec_param_estim == FALSE ) - { - mvs2s( hDirAC->azimuth[hDirAC->render_to_md_map[subframe_idx]], azimuth, hDirAC->num_freq_bands ); - mvs2s( hDirAC->elevation[hDirAC->render_to_md_map[subframe_idx]], elevation, hDirAC->num_freq_bands ); - mvr2r( hDirAC->diffuseness_vector[hDirAC->render_to_md_map[subframe_idx]], diffuseness_vector, hDirAC->num_freq_bands ); - } - else - { - set_zero( diffuseness_vector, hDirAC->num_freq_bands ); - } - - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_zero( reference_power_smooth, hDirAC->num_freq_bands ); - } - else - { - set_zero( onset_filter_subframe, hDirAC->num_freq_bands ); - } - - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] ) - { - p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[subframe_idx][0][0]; - - if ( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) - { - num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; - if ( hDirAC->hConfig->dec_param_estim == FALSE ) - { - rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hDirAC->num_freq_bands, p_Rmat ); - } - } - } - else - { - p_Rmat = 0; - } - - if ( hDirAC->hConfig->dec_param_estim == FALSE ) - { - /* compute response */ - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_compute_power_factors( hDirAC->num_freq_bands, - diffuseness_vector, - hDirAC->h_output_synthesis_psd_params.max_band_decorr, - hDirAC->h_output_synthesis_psd_state.direct_power_factor, - hDirAC->h_output_synthesis_psd_state.diffuse_power_factor ); - - if ( coherence_flag ) - { - for ( i = 0; i < hDirAC->num_freq_bands; i++ ) - { - dirEne = hDirAC->h_output_synthesis_psd_state.direct_power_factor[i]; - surCohEner = hDirAC->h_output_synthesis_psd_state.diffuse_power_factor[i] * hDirAC->surroundingCoherence[md_idx][i]; - hDirAC->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; - hDirAC->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; - - surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); - } - } - else - { - set_zero( surCohRatio, hDirAC->num_freq_bands ); - } - } - else - { - ivas_dirac_dec_compute_gain_factors( hDirAC->num_freq_bands, - hDirAC->diffuseness_vector[md_idx], - hDirAC->h_output_synthesis_psd_params.max_band_decorr, - hDirAC->h_output_synthesis_psd_state.direct_power_factor, - hDirAC->h_output_synthesis_psd_state.diffuse_power_factor ); - - if ( coherence_flag ) - { - for ( i = 0; i < hDirAC->num_freq_bands; i++ ) - { - surCohRatio[i] = hDirAC->surroundingCoherence[md_idx][i]; - } - } - else - { - set_zero( surCohRatio, hDirAC->num_freq_bands ); - } - } - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 1 ) - { - ivas_dirac_dec_compute_directional_responses( hDirAC, - st_ivas->hVBAPdata, - st_ivas->hMasa, -#ifdef MASA_AND_OBJECTS - st_ivas->hMasaIsmData, -#endif - azimuth, - elevation, - md_idx, - surCohRatio, - st_ivas->hCombinedOrientationData->shd_rot_max_order, - p_Rmat, - hodirac_flag ); - } - else - { - ivas_dirac_dec_compute_directional_responses( hDirAC, - st_ivas->hVBAPdata, - st_ivas->hMasa, -#ifdef MASA_AND_OBJECTS - st_ivas->hMasaIsmData, -#endif - azimuth, - elevation, - md_idx, - surCohRatio, - 0, - NULL, - hodirac_flag ); - } - } - -#ifdef MASA_AND_OBJECTS - // Todo OMASA JBM: This might need adjustments - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) - { - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - index_slot = slot_idx_start + slot_idx; - - /* CLDFB Analysis*/ - for ( ch = 0; ch < nchan_transport; ch++ ) - { - cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirAC->sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), - Cldfb_RealBuffer_Temp[ch][slot_idx], - Cldfb_ImagBuffer_Temp[ch][slot_idx], - hDirAC->num_freq_bands, - st_ivas->cldfbAnaDec[ch] ); - } - } - - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) - { - preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, hDirAC->num_freq_bands, subframe_idx ); - } - } -#endif - - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - index_slot = slot_idx_start + slot_idx; - if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { - md_idx = hDirAC->render_to_md_map[index_slot]; - } - else - { - md_idx = hDirAC->render_to_md_map[subframe_idx]; - } - - if ( st_ivas->ivas_format == SBA_FORMAT ) - { - for ( ch = 0; ch < nchan_transport; ch++ ) - { - mvr2r( pppQMfFrame_ts_re[ch][slot_idx], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands ); - mvr2r( pppQMfFrame_ts_im[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); - } - } -#ifdef MASA_AND_OBJECTS - // Todo OMASA JBM: This might need adjustments - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) - { - for ( ch = 0; ch < nchan_transport; ch++ ) - { - mvr2r( Cldfb_RealBuffer_Temp[ch][slot_idx], Cldfb_RealBuffer[ch][0], hDirAC->num_freq_bands ); - mvr2r( Cldfb_ImagBuffer_Temp[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hDirAC->num_freq_bands ); - } - } -#endif - else - { - /* CLDFB Analysis*/ - for ( ch = 0; ch < nchan_transport; ch++ ) - { - cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirAC->sba_map_tc[ch]][hDirAC->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hDirAC->num_freq_bands, - st_ivas->cldfbAnaDec[ch] ); - } - } - - /* CNG in DirAC, extra CLDFB ana for CNA*/ - if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) - { - Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; - - generate_masking_noise_dirac( st->hFdCngDec->hFdCngCom, - st_ivas->cldfbAnaDec[1], - st_ivas->hTcBuffer->tc[1], - Cldfb_RealBuffer[1][0], - Cldfb_ImagBuffer[1][0], - index_slot, - st->cna_dirac_flag && st->flag_cna, - ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == FD_CNG && st->cng_sba_flag ); - } - - /* LFE synthesis */ - if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirAC->hOutSetup.separateChannelEnabled && !( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && hDirAC->hOutSetup.num_lfe == 0 ) ) - { - ivas_lfe_synth_with_cldfb( st_ivas->hMasa->hMasaLfeSynth, - Cldfb_RealBuffer, Cldfb_ImagBuffer, - Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1], - slot_idx, - md_idx, - nchan_transport ); - } - - /*-----------------------------------------------------------------* - * protoype signal computation - *-----------------------------------------------------------------*/ - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) - { - protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f, - reference_power, slot_idx, nchan_transport, - hDirAC->num_outputs_diff, - hDirAC->num_freq_bands, - p_Rmat ); - } - else - { - protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f, - reference_power, slot_idx, nchan_transport, - hDirAC->num_outputs_diff, - hDirAC->num_freq_bands, - 0 ); - } - } - else if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) - { - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirAC->proto_frame_f, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, hDirAC->h_output_synthesis_psd_state.proto_power_smooth, - 0, slot_idx, hDirAC->num_freq_bands, hDirAC->masa_stereo_type_detect ); - } - else - { - switch ( nchan_transport ) - { - case 11: - case 8: - case 6: - case 4: - protoSignalComputation4( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirAC->proto_frame_f, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirAC->h_output_synthesis_psd_state.proto_power_smooth, - slot_idx, hDirAC->num_outputs_diff, - hDirAC->num_freq_bands, - hDirAC->hoa_decoder, - nchan_transport, - hDirAC->sba_map_tc ); - break; - case 2: - protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirAC->proto_frame_f, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirAC->h_output_synthesis_psd_state.proto_power_smooth, - hDirAC->hOutSetup.is_loudspeaker_setup, - slot_idx, - hDirAC->num_freq_bands, - hDirAC->masa_stereo_type_detect ); - break; - case 1: - protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, - hDirAC->proto_frame_f, - hDirAC->h_output_synthesis_psd_state.proto_direct_buffer_f, - reference_power, - hDirAC->h_output_synthesis_psd_state.proto_power_smooth, - slot_idx, - hDirAC->num_protos_diff, - hDirAC->num_freq_bands ); - break; - default: - return; - } - } - - - /*-----------------------------------------------------------------* - * Compute DirAC parameters at decoder side - *-----------------------------------------------------------------*/ - - if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { - mvs2s( &hDirAC->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], hDirAC->num_freq_bands - hDirAC->hConfig->enc_param_start_band ); - mvs2s( &hDirAC->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], hDirAC->num_freq_bands - hDirAC->hConfig->enc_param_start_band ); - if ( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) - { - num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; - rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hDirAC->num_freq_bands, p_Rmat ); - } - - hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ - - index = hDirAC->index_buffer_intensity; - - num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; - - computeIntensityVector_dec( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - num_freq_bands, - hDirAC->buffer_intensity_real[0][index - 1], - hDirAC->buffer_intensity_real[1][index - 1], - hDirAC->buffer_intensity_real[2][index - 1] ); - - computeDirectionAngles( hDirAC->buffer_intensity_real[0][index - 1], - hDirAC->buffer_intensity_real[1][index - 1], - hDirAC->buffer_intensity_real[2][index - 1], - num_freq_bands, - azimuth, - elevation ); - - mvr2r( reference_power, &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); - - computeDiffuseness( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->diffuseness_vector[md_idx] ); - } - -#ifdef DEBUG_MODE_DIRAC - { - static FILE *fp_direction_vector = NULL, *fp_diffuseness = NULL, *fp_referencePower = NULL; - - - if ( fp_direction_vector == NULL ) - fp_direction_vector = fopen( "./res/dbg_direction_vector_C_dec.bin", "wb" ); - if ( fp_diffuseness == NULL ) - fp_diffuseness = fopen( "./res/dbg_diffuseness_C_dec.bin", "wb" ); - if ( fp_referencePower == NULL ) - fp_referencePower = fopen( "./res/dbg_reference_power_C_dec.bin", "wb" ); - - - for ( i = 0; i < hDirAC->num_freq_bands; i++ ) - { - float radius_length; - float dv[3]; - - if ( hDirAC->hConfig->dec_param_estim == FALSE ) - { - radius_length = cos( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 ); - dv[0] = radius_length * cos( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 ); - dv[1] = radius_length * sin( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 ); - dv[2] = sin( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 ); - - fwrite( dv, sizeof( float ), 3, fp_direction_vector ); - fwrite( &( hDirAC->diffuseness_vector[0][i] ), sizeof( float ), 1, fp_diffuseness ); - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - reference_power[i] = Cldfb_RealBuffer[0][0][i] * Cldfb_RealBuffer[0][0][i] + Cldfb_ImagBuffer[0][0][i] * Cldfb_ImagBuffer[0][0][i]; - } - fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower ); - } - else - { - radius_length = cos( hDirAC->elevation[index_slot][i] * PI_OVER_180 ); - dv[0] = radius_length * cos( hDirAC->azimuth[index_slot][i] * PI_OVER_180 ); - dv[1] = radius_length * sin( hDirAC->azimuth[index_slot][i] * PI_OVER_180 ); - dv[2] = sin( hDirAC->elevation[index_slot][i] * PI_OVER_180 ); - - fwrite( dv, sizeof( float ), 3, fp_direction_vector ); - fwrite( &( hDirAC->diffuseness_vector[index_slot][i] ), sizeof( float ), 1, fp_diffuseness ); - fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower ); - } - } - } -#endif - - /*-----------------------------------------------------------------* - * frequency domain decorrelation - *-----------------------------------------------------------------*/ - - if ( hDirAC->proto_signal_decorr_on == 1 ) - { - /* decorrelate prototype frame */ - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - nchan_transport, - hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hDirAC->num_freq_bands * hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->proto_index_diff, - hDirAC->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hDirAC->num_freq_bands * hDirAC->num_outputs_diff + 2 * hDirAC->num_freq_bands * min( 4, nchan_transport ), - onset_filter, - hDirAC->h_freq_domain_decorr_ap_params, - hDirAC->h_freq_domain_decorr_ap_state ); - - v_multc( onset_filter, 0.25f, onset_filter, hDirAC->num_freq_bands ); - v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hDirAC->num_freq_bands ); - p_onset_filter = onset_filter_subframe; - } - else - { - ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, - nchan_transport, - hDirAC->proto_frame_f, - hDirAC->num_protos_diff, - hDirAC->proto_index_diff, - DirAC_mem.frame_dec_f, - onset_filter, - hDirAC->h_freq_domain_decorr_ap_params, - hDirAC->h_freq_domain_decorr_ap_state ); - - hDirAC->proto_frame_dec_f = DirAC_mem.frame_dec_f; - p_onset_filter = onset_filter; - } - } - else - { - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_f( onset_filter_subframe, 1.f, hDirAC->num_freq_bands ); - p_onset_filter = onset_filter_subframe; - } - else - { - /* no frequency domain decorrelation: use prototype frame */ - hDirAC->proto_frame_dec_f = hDirAC->proto_frame_f; - p_onset_filter = NULL; - } - } - - /*-----------------------------------------------------------------* - * output synthesis - *-----------------------------------------------------------------*/ - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) - { - /*Compute diffuse prototypes*/ - ivas_dirac_dec_compute_diffuse_proto( hDirAC, slot_idx ); - } - - /*Compute PSDs*/ - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 ) - { - ivas_dirac_dec_output_synthesis_process_slot( reference_power, - p_onset_filter, - azimuth, - elevation, - hDirAC->diffuseness_vector[md_idx], - hDirAC, - st_ivas->hCombinedOrientationData->shd_rot_max_order, - p_Rmat, - st_ivas->hVBAPdata, - hDirAC->hOutSetup, - nchan_transport, - md_idx, - hodirac_flag ); - } - else - { - ivas_dirac_dec_output_synthesis_process_slot( reference_power, - p_onset_filter, - azimuth, - elevation, - hDirAC->diffuseness_vector[md_idx], - hDirAC, - 0, - 0, - st_ivas->hVBAPdata, - hDirAC->hOutSetup, - nchan_transport, - md_idx, - hodirac_flag ); - } - - if ( hDirAC->hConfig->dec_param_estim ) - { - float fac = 1.0f / (float) hDirAC->subframe_nbslots[subframe_idx]; - v_multc_acc( hDirAC->diffuseness_vector[md_idx], fac, diffuseness_vector, hDirAC->num_freq_bands ); - } - - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - v_add( reference_power, reference_power_smooth, reference_power_smooth, hDirAC->num_freq_bands ); - } - } - - ivas_dirac_dec_output_synthesis_get_interpolator( &hDirAC->h_output_synthesis_psd_params, hDirAC->subframe_nbslots[subframe_idx] ); - - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC, - nchan_transport, - hDirAC->subframe_nbslots[subframe_idx], - p_onset_filter, - diffuseness_vector, - hodirac_flag ); - } - else - { - /* Determine encoding quality based additional smoothing factor */ - float qualityBasedSmFactor = 1.0f; - - if ( st_ivas->hMasa != NULL ) - { - qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality; - qualityBasedSmFactor *= qualityBasedSmFactor; - } - - - ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, - Cldfb_ImagBuffer, - hDirAC, - hDirAC->subframe_nbslots[subframe_idx], - diffuseness_vector, - reference_power_smooth, - qualityBasedSmFactor ); - } - - /*-----------------------------------------------------------------* - * CLDFB synthesis (and binaural rendering) - *-----------------------------------------------------------------*/ - - index_slot = slot_idx_start_cldfb_synth; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) - { - /* Perform binaural rendering */ - ivas_binRenderer( st_ivas->hBinRenderer, -#ifdef SPLIT_REND_WITH_HEAD_ROT - &st_ivas->splitBinRend.splitrend.multiBinPoseData, -#endif - st_ivas->hCombinedOrientationData, - subframe_idx, - hDirAC->subframe_nbslots[subframe_idx], - Cldfb_RealBuffer_Binaural, - Cldfb_ImagBuffer_Binaural, - Cldfb_RealBuffer, - Cldfb_ImagBuffer ); - -#ifdef SPLIT_REND_WITH_HEAD_ROT - if ( ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || - ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) - { - int16_t pos_idx; -#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG - for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ ) -#else - for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ ) -#endif - { - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) - { - mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hDirAC->num_freq_bands ); - mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hDirAC->num_freq_bands ); - } - } - } - } -#endif - /* Inverse CLDFB*/ - for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) - { - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) - { -#ifdef SPLIT_REND_WITH_HEAD_ROT - RealBuffer[i] = Cldfb_RealBuffer_Binaural[0][ch][i]; - ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[0][ch][i]; -#else - RealBuffer[i] = Cldfb_RealBuffer_Binaural[ch][i]; - ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[ch][i]; -#endif - } - - cldfbSynthesis( RealBuffer, - ImagBuffer, - &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), - hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], - st_ivas->cldfbSynDec[ch] ); - } - } - else if ( st_ivas->ivas_format == SBA_FORMAT ) - { - for ( ch = 0; ch < hDirAC->hOutSetup.nchan_out_woLFE; ch++ ) - { - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) - { - mvr2r( Cldfb_RealBuffer[ch][slot_idx], pppQMfFrame_ts_re[ch][slot_idx], hDirAC->num_freq_bands ); - mvr2r( Cldfb_ImagBuffer[ch][slot_idx], pppQMfFrame_ts_im[ch][slot_idx], hDirAC->num_freq_bands ); - } - } - } - else - { - float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t outchannels; - - idx_in = 0; - idx_lfe = 0; - - outchannels = hDirAC->hOutSetup.nchan_out_woLFE + hDirAC->hOutSetup.num_lfe; - if ( hDirAC->hOutSetup.separateChannelEnabled && ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1 || - hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1 || - hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || - hDirAC->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || - hDirAC->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || - ( hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) - { - outchannels++; - } - - if ( hDirAC->hOutSetup.separateChannelEnabled && hDirAC->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM ) - { - float tmp_separated[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - float tmp_lfe[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; - const int16_t subframe_start_sample = index_slot * hDirAC->num_freq_bands; - const int16_t num_samples_subframe = hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx]; + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) + { + hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f; + } + else + { + hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; + } - /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */ - mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe ); - mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe ); + hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = q_direction->band_data[qBand_idx].energy_ratio[0]; - for ( ch = 0; ch < outchannels; ch++ ) - { - if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) - { - /* Move the LFE channel to the correct place */ - mvr2r( tmp_lfe, &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness; - if ( idx_lfe < ( hDirAC->hOutSetup.num_lfe - 1 ) ) - { - idx_lfe++; - } - } - else if ( ( st_ivas->hLsSetupCustom->separate_ch_found ) && ( hDirAC->hOutSetup.separateChannelIndex == ch ) ) - { - /* Move the separated channel to the correct place. Thus, the separated channel is - * combined with the synthesized channels here when there is a matching channel. */ - mvr2r( tmp_separated, &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); - } - else - { - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) - { - RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + if ( hodirac_flag ) + { + if ( idx_sec == 0 ) + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; + hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0.f; // not in use + } + else + { + assert( idx_sec == 1 ); + hSpatParamRendCom->elevation2[tmp_write_idx_band][b] = ele; + hSpatParamRendCom->azimuth2[tmp_write_idx_band][b] = azi; + hSpatParamRendCom->energy_ratio2[tmp_write_idx_band][b] = 1.f - diffuseness_sec; + } + } + else + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi; + } } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][subframe_start_sample] ), num_samples_subframe, st_ivas->cldfbSynDec[idx_in] ); + tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; - if ( !st_ivas->hLsSetupCustom->separate_ch_found ) - { - /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel - * is combined with the synthesized channels here when there is no matching channel. */ - v_multc_acc( tmp_separated, st_ivas->hLsSetupCustom->separate_ch_gains[idx_in], &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); - } + } /* for ( block =...) */ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ - idx_in++; - } - } - } - else + /* Bands not transmitted -> zeroed*/ + for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) { - for ( ch = 0; ch < outchannels; ch++ ) + tmp_write_idx_band = hSpatParamRendCom->dirac_bs_md_write_idx; + + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - if ( ( hDirAC->hOutSetup.num_lfe > 0 ) && ( hDirAC->hOutSetup.index_lfe[idx_lfe] == ch ) ) - { - if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirAC->hOutSetup.separateChannelEnabled ) - { - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) - { - RealBuffer[i] = Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][i]; - } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[hDirAC->hOutSetup.nchan_out_woLFE + idx_lfe] ); - } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA && hDirAC->hOutSetup.separateChannelEnabled ) - { - /* LFE has been synthesized in the time domain, do nothing. */ - } - else - { - set_zero( &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands ); - } - if ( idx_lfe < ( hDirAC->hOutSetup.num_lfe - 1 ) ) - { - idx_lfe++; - } - } - else if ( ( hDirAC->hOutSetup.separateChannelEnabled ) && ( hDirAC->hOutSetup.separateChannelIndex == ch ) ) - { - /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated - * channel is combined with the synthesized channels here. */ - } - else - { - /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) - { - RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; - } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hDirAC->num_freq_bands] ), hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[idx_in] ); - idx_in++; - } + hSpatParamRendCom->spreadCoherence[block][b] = 0.0f; + hSpatParamRendCom->surroundingCoherence[block][b] = 0.0f; + hSpatParamRendCom->energy_ratio1[block][b] = 0; + + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = 0; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = 0.f; + hSpatParamRendCom->spreadCoherence[tmp_write_idx_band][b] = 0.0f; + hSpatParamRendCom->surroundingCoherence[tmp_write_idx_band][b] = 0.0f; + hSpatParamRendCom->energy_ratio1[tmp_write_idx_band][b] = 0; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } } - hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe_idx]; - hDirAC->subframes_rendered++; - pop_wmops(); + /* update buffer write index */ + hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; return; } /*------------------------------------------------------------------------- - * compute_hoa_encoder_mtx() - * + * ivas_dirac_dec_set_md_map() * + * Set metadata index mapping for DirAC *------------------------------------------------------------------------*/ -void compute_hoa_encoder_mtx( - const float *azimuth, - const float *elevation, - float *response, - const int16_t num_responses, - const int16_t ambisonics_order ) +void ivas_dirac_dec_set_md_map( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nCldfbTs /* i : number of CLDFB time slots */ +) { - int16_t k, num_sh; + int16_t num_slots_in_subfr; + DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - num_sh = ivas_sba_get_nchan( ambisonics_order, 0 ); + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; +#ifdef DEBUGGING + assert( hDirAC ); + assert( hSpatParamRendCom ); +#endif + + /* adapt subframes */ + hSpatParamRendCom->num_slots = nCldfbTs; + hSpatParamRendCom->slots_rendered = 0; + num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + hSpatParamRendCom->subframes_rendered = 0; + + ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); + + /* set mapping according to dirac_read_idx */ + + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + +#ifdef FIX_470_MASA_JBM_EXT + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + ivas_jbm_dec_get_md_map_even_spacing( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + } + else if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#else + if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) +#endif + { + ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + } + else + { + ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); + } - for ( k = 0; k < num_responses; k++ ) + if ( hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { - ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order ); + float tmp; + int16_t sf_idx, slot_idx, slot_idx_abs; + + slot_idx_abs = 0; + for ( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) + { + tmp = 0.0f; + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) + { + tmp += (float) hSpatParamRendCom->render_to_md_map[slot_idx_abs]; + slot_idx_abs++; + } + hSpatParamRendCom->render_to_md_map[sf_idx] = ( (int16_t) roundf( tmp / (float) hSpatParamRendCom->subframe_nbslots[sf_idx] ) + hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + } + + set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); } return; @@ -3236,1138 +1569,1012 @@ void compute_hoa_encoder_mtx( /*------------------------------------------------------------------------- - * ivas_dirac_dec_get_frequency_axis() + * ivas_dirac_dec() * - * DirAC decoding initialization + * DirAC decoding process *------------------------------------------------------------------------*/ -void ivas_dirac_dec_get_frequency_axis( - float *frequency_axis, - const int32_t output_Fs, - const int16_t num_freq_bands ) +void ivas_dirac_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float output_f[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ + const int16_t nchan_transport /* i : number of transport channels */ +) { - int16_t k; - float const_part; + int16_t subframe_idx; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + float cng_td_buffer[L_FRAME16k]; + int16_t nchan_out, n, n_samples_sf; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - /* calc cldfb frequency axis */ - const_part = (float) output_Fs / ( 2.0f * (float) num_freq_bands ); - for ( k = 0; k < num_freq_bands; ++k ) + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + + n_samples_sf = JBM_CLDFB_SLOTS_IN_SUBFRAME * hSpatParamRendCom->slot_size; + + for ( n = 0; n < nchan_out; n++ ) { - frequency_axis[k] = ( (float) k + 0.5f ) * const_part; + output_f_local[n] = &output_f[n][0]; } - return; -} + for ( n = 0; n < nchan_transport; n++ ) + { + st_ivas->hTcBuffer->tc[n] = output_f[n]; + } + if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + st_ivas->hTcBuffer->tc[nchan_transport] = &cng_td_buffer[0]; + generate_masking_noise_lb_dirac( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc[1], DEFAULT_JBM_CLDFB_TIMESLOTS, st->cna_dirac_flag && st->flag_cna ); + } -/*------------------------------------------------------------------------- - * Local functions - *-------------------------------------------------------------------------*/ + ivas_dirac_dec_set_md_map( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS ); -static void initDiffuseResponses( - float *diffuse_response_function, - const int16_t num_channels, - AUDIO_CONFIG output_config, - IVAS_OUTPUT_SETUP hOutSetup, - const int16_t ambisonics_order, - const IVAS_FORMAT ivas_format, - int16_t *num_ele_spk_no_diffuse_rendering, - AUDIO_CONFIG transport_config ) -{ - int16_t i, l, k, idx, num_horizontal_speakers; - *num_ele_spk_no_diffuse_rendering = 0; + for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) + { + ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); + for ( n = 0; n < nchan_out; n++ ) + { + output_f_local[n] += n_samples_sf; + } + } - if ( output_config == AUDIO_CONFIG_MONO ) + if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) { - diffuse_response_function[0] = 1.0f; - diffuse_response_function[1] = inv_sqrt( 3.0f ); + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; } - else if ( !( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 ) ) + else { - /* set diffuse response function */ - if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 ) - { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; - - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); - set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); - *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; - } - else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 ) - { - num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + } - set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers ); - set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); - *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; - } -#ifdef MASA_AND_OBJECTS - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) -#else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) -#endif - { - mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); - } -#ifdef MASA_AND_OBJECTS - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_2 ) && ( num_channels == 7 ) ) -#else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) -#endif - { - mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); - } -#ifdef MASA_AND_OBJECTS - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) -#else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) -#endif - { - mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); - } -#ifdef MASA_AND_OBJECTS - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) -#else - else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) -#endif - { - if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) - { - /* Detect loudspeakers with elevation */ - for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ ) - { - if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) - { - num_horizontal_speakers++; - diffuse_response_function[i] = 1.f; - } - else - { - *num_ele_spk_no_diffuse_rendering += 1; - diffuse_response_function[i] = 0.f; - } - } - /* Diffuse only to horizontal plane if enough loudspeakers */ - if ( num_horizontal_speakers > 2 ) - { - for ( i = 0; i < num_channels; i++ ) - { - diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); - } - } - else - { - *num_ele_spk_no_diffuse_rendering = 0; - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); - } - } - else - { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); - } - } - else - { - set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); - } + for ( n = 0; n < nchan_transport; n++ ) + { + st_ivas->hTcBuffer->tc[n] = NULL; } - else + + if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) { - idx = 0; - for ( l = 0; l <= ambisonics_order; l++ ) - { - for ( k = 0; k < ( 2 * l + 1 ); k++ ) - { - diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f ); - } - } + st_ivas->hTcBuffer->tc[nchan_transport] = NULL; } return; } -static void protoSignalComputation_shd( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_direct_buffer_f, - float *proto_diffuse_buffer_f, - float *reference_power, - const int16_t slot_index, - const int16_t num_inputs, - const int16_t num_outputs_diff, - const int16_t num_freq_bands, - float *p_Rmat ) -{ - int16_t l, k; - float *p_proto_direct_buffer; - float *p_proto_diffuse_buffer; - int16_t Rmat_k[4]; - float W_real, W_imag; - float Y_real, Y_imag; - float *p_k[4]; +/*------------------------------------------------------------------------- + * ivas_dirac_dec_render() + * + * DirAC decoding renderer process + *------------------------------------------------------------------------*/ - k = 0; /* to avoid compilation warning */ +void ivas_dirac_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +) +{ + int16_t slots_to_render, first_sf, last_sf, subframe_idx; + uint16_t slot_size, n_samples_sf, ch, nchan_intern; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + float *output_f_local[MAX_OUTPUT_CHANNELS]; - p_proto_direct_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_inputs; - p_proto_diffuse_buffer = proto_diffuse_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; - if ( num_inputs == 1 ) + nchan_intern = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; +#ifdef DEBUGGING + assert( hSpatParamRendCom ); +#endif + for ( ch = 0; ch < nchan_intern; ch++ ) { - for ( l = 0; l < num_freq_bands; l++ ) - { - p_proto_direct_buffer[2 * l] = RealBuffer[0][0][l]; - p_proto_direct_buffer[2 * l + 1] = ImagBuffer[0][0][l]; - } + output_f_local[ch] = output_f[ch]; } - else if ( num_inputs == 2 ) - { - if ( p_Rmat != 0 ) - { - assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" ); + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - for ( l = 0; l < num_freq_bands; l++ ) - { - W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); + *nSamplesRendered = slots_to_render * slot_size; + first_sf = hSpatParamRendCom->subframes_rendered; + last_sf = first_sf; - Y_real = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - Y_imag = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + while ( slots_to_render > 0 ) + { + slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf]; + last_sf++; + } - p_proto_direct_buffer[2 * l] = W_real; - p_proto_direct_buffer[2 * l + 1] = W_imag; - p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = p_Rmat[0] * Y_real; - p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = p_Rmat[0] * Y_imag; - } - } - else +#ifdef DEBUGGING + assert( slots_to_render == 0 ); +#endif + for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); + n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + for ( ch = 0; ch < nchan_intern; ch++ ) { - for ( l = 0; l < num_freq_bands; l++ ) - { - W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - - p_proto_direct_buffer[2 * l] = W_real; - p_proto_direct_buffer[2 * l + 1] = W_imag; - { - p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - } - } + output_f_local[ch] += n_samples_sf; } } - else if ( num_inputs >= 4 ) + + if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { - p_k[0] = p_proto_direct_buffer; - p_k[1] = p_proto_direct_buffer + 2 * num_freq_bands; - p_k[2] = p_proto_direct_buffer + 4 * num_freq_bands; - p_k[3] = p_proto_direct_buffer + 6 * num_freq_bands; - Rmat_k[0] = 0; - Rmat_k[1] = 1; - Rmat_k[2] = 2; - Rmat_k[3] = 0; - - if ( p_Rmat != 0 ) + if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) { - assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" ); - - for ( l = 0; l < num_freq_bands; l++ ) - { - *( p_k[0] ) = RealBuffer[0][0][l]; - reference_power[l + num_freq_bands] = *( p_k[0] ) * *( p_k[0] ); - p_k[0]++; - *( p_k[0] ) = ImagBuffer[0][0][l]; - reference_power[l + num_freq_bands] += *( p_k[0] ) * *( p_k[0] ); - p_k[0]++; - reference_power[l] = 0.5f * reference_power[l + num_freq_bands]; - - for ( k = 1; k < 4; k++ ) - { - *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * RealBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * RealBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * RealBuffer[3][0][l]; - reference_power[l + ( k + 1 ) * num_freq_bands] = *( p_k[k] ) * *( p_k[k] ); - p_k[k]++; - *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * ImagBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * ImagBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * ImagBuffer[3][0][l]; - reference_power[l + ( k + 1 ) * num_freq_bands] += *( p_k[k] ) * *( p_k[k] ); - p_k[k]++; - reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] ); - } - - for ( k = 1; k < 4; k++ ) - { - RealBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l]; - ImagBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1]; - } - } + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; } else { - set_zero( reference_power, num_freq_bands ); - for ( k = 0; k < 4; k++ ) - { - for ( l = 0; l < num_freq_bands; l++ ) - { - p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l]; - p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l]; - reference_power[l + ( k + 1 ) * num_freq_bands] = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; - reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] ); - } - } - } - - /* Additional transport channels = planar SBA components of degree higher than 1*/ - for ( ; k < num_inputs; k++ ) - { - for ( l = 0; l < num_freq_bands; l++ ) - { - p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l]; - p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l]; - } + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; } } - - /*Copy direct to diffuse proto*/ - mvr2r( p_proto_direct_buffer, p_proto_diffuse_buffer, 2 * num_freq_bands * min( num_outputs_diff, num_inputs ) ); - - if ( num_inputs == 1 ) - { - /* Add comfort noise addition (CNA) to diffuse proto only*/ - for ( l = 0; l < num_freq_bands; l++ ) - { - p_proto_diffuse_buffer[2 * l] += RealBuffer[1][0][l]; - p_proto_diffuse_buffer[2 * l + 1] += ImagBuffer[1][0][l]; - } - } + *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; return; } -static void protoSignalComputation1( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_frame_f, - float *proto_direct_buffer_f, - float *reference_power, - float *proto_power_smooth, - const int16_t slot_index, - const int16_t num_outputs_diff, - const int16_t num_freq_bands ) -{ - int16_t l, k; - float *p_proto_buffer; - - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands; - - for ( l = 0; l < num_freq_bands; l++ ) - { - reference_power[l] = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - proto_power_smooth[l] += reference_power[l]; - p_proto_buffer[2 * l] = RealBuffer[0][0][l]; - p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l]; - - for ( k = 0; k < num_outputs_diff; k++ ) - { - proto_frame_f[2 * k * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * k * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - } - } +/*------------------------------------------------------------------------- + * ivas_dirac_dec() + * + * DirAC decoding process + *------------------------------------------------------------------------*/ - return; -} +void ivas_dirac_dec_render_sf( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], + float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) +{ + int16_t i, ch, idx_in, idx_lfe; + DIRAC_DEC_HANDLE hDirAC; + DIRAC_REND_HANDLE hDirACRend; + float dirEne; + float surCohEner; + float surCohRatio[CLDFB_NO_CHANNELS_MAX]; + int16_t subframe_idx; + int16_t slot_idx, index_slot; + int16_t hodirac_flag; + float *p_Rmat; + int16_t slot_idx_start, slot_idx_start_cldfb_synth, md_idx; + /*CLDFB: last output channels reserved to LFT for CICPx*/ + float Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +#ifdef SPLIT_REND_WITH_HEAD_ROT + float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +#else + float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; +#endif +#ifdef MASA_AND_OBJECTS + float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ + float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; /* Todo Nokia: Temporary, to be removed once function calls have been refactored to accept another size */ +#endif + int16_t index, num_freq_bands; -static void protoSignalComputation2( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_frame_f, - float *proto_direct_buffer_f, - float *reference_power, - float *proto_power_smooth, - const int16_t isloudspeaker, - const int16_t slot_index, - const int16_t num_freq_bands, - MASA_STEREO_TYPE_DETECT *stereo_type_detect ) -{ - int16_t l; - float *p_proto_buffer; - float Real_aux, Imag_aux; + /* local copies of azi, ele, diffuseness */ + int16_t azimuth[CLDFB_NO_CHANNELS_MAX]; + int16_t elevation[CLDFB_NO_CHANNELS_MAX]; + float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; - float left_bb_power, right_bb_power, total_bb_power, lr_bb_power; - float lr_total_bb_ratio; - float a, b; + DIRAC_DEC_STACK_MEM DirAC_mem; + float *reference_power, *reference_power_smooth; + float *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; + uint16_t coherence_flag; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - float left_hi_power, right_hi_power, total_hi_power, lr_hi_power; - float lr_total_hi_ratio; - float a2, b2; + push_wmops( "ivas_dirac_dec_render" ); - float sum_power; - float sum_total_ratio[MASA_SUM_FREQ_RANGE_BINS]; - float min_sum_total_ratio; - float min_sum_total_ratio_db; + /* Initialize aux buffers */ + hDirAC = st_ivas->hDirAC; + hDirACRend = st_ivas->hDirACRend; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; - float RealSubtract, ImagSubtract; + DirAC_mem = hDirACRend->stack_mem; - float interpolatorSpaced = 0.0f; - float interpolatorDmx = 1.0f; + reference_power = DirAC_mem.reference_power; + reference_power_smooth = DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; + onset_filter = DirAC_mem.onset_filter; +#ifdef FIX_614_ADD_TO_NULL_PTR_DIRAC_SETUP + onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; +#else + onset_filter_subframe = DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; +#endif - int16_t dipole_freq_range[2]; - float tempSpaced, tempDmx; + hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - if ( isloudspeaker ) + if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT ) { - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 3; - - for ( l = 0; l < num_freq_bands; l++ ) - { - float Left_power; - float Right_power; - Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - - Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; - - reference_power[l] = Left_power + Right_power; - proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; - - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; - proto_power_smooth[l + num_freq_bands] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - - proto_power_smooth[l + 2 * num_freq_bands] += RealBuffer[1][0][l] * RealBuffer[1][0][l]; - proto_power_smooth[l + 2 * num_freq_bands] += ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; - p_proto_buffer[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - p_proto_buffer[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; - - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; - - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; - } + coherence_flag = st_ivas->hQMetaData->coherence_flag; } - else if ( stereo_type_detect != NULL ) + else { - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; - - left_bb_power = 0.0f; - right_bb_power = 0.0f; - total_bb_power = 0.0f; - - left_hi_power = 0.0f; - right_hi_power = 0.0f; - total_hi_power = 0.0f; - - dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0]; - dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1]; + coherence_flag = 0; + } - a = 0.01f; /* Temporal smoothing coefficient */ - b = 1.0f - a; /* Temporal smoothing coefficient */ - a2 = 0.1f; /* Temporal smoothing coefficient */ - b2 = 1.0f - a2; /* Temporal smoothing coefficient */ +#ifdef DEBUG_MODE_DIRAC + { + int16_t n, tmp[IVAS_SPAR_MAX_CH * L_FRAME48k]; + char file_name[50] = { 0 }; + const int16_t output_frame = st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; - if ( stereo_type_detect->interpolator > 0 ) + for ( n = 0; n < nchan_transport; n++ ) { - if ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS ) - { - interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); - interpolatorDmx = 1.0f - interpolatorSpaced; - } - else + for ( i = 0; i < output_frame; i++ ) { - interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); - interpolatorSpaced = 1.0f - interpolatorDmx; + tmp[nchan_transport * i + n] = (int16_t) ( output_f[n][i] + 0.5f ); } } + sprintf( file_name, "./res/ivas_dirac_dec_DMX%d.%d.pcm", nchan_transport, (int16_t) ( output_frame * 0.05 ) ); + dbgwrite( tmp, sizeof( int16_t ), nchan_transport * output_frame, 1, file_name ); + } +#endif - for ( l = 0; l < num_freq_bands; l++ ) - { - float Left_power; - float Right_power; - - /* Compute sum signal */ - Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - - /* Compute reference power */ - Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; - - reference_power[l] = Left_power + Right_power; - - left_bb_power += Left_power; - right_bb_power += Right_power; - total_bb_power += reference_power[l]; + /* Subframe loop */ + slot_idx_start = hSpatParamRendCom->slots_rendered; + slot_idx_start_cldfb_synth = 0; - if ( l > MASA_HI_FREQ_START_BIN ) - { - left_hi_power += Left_power; - right_hi_power += Right_power; - total_hi_power += reference_power[l]; - } + subframe_idx = hSpatParamRendCom->subframes_rendered; + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + } + else + { + md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start]; + } + /* ToDo: Another workaround for self test BE */ - if ( l < min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) - { - sum_power = Real_aux * Real_aux + Imag_aux * Imag_aux; + /* copy parameters into local buffers*/ + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + mvs2s( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); + mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); + mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + } + else + { + set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + } - stereo_type_detect->sum_power[l] = a * sum_power + b * stereo_type_detect->sum_power[l]; - stereo_type_detect->total_power[l] = a * reference_power[l] + b * stereo_type_detect->total_power[l]; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + } + else + { + set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + } - sum_total_ratio[l] = stereo_type_detect->sum_power[l] / ( stereo_type_detect->total_power[l] + EPSILON ); - } + if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] ) + { + p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[subframe_idx][0][0]; - if ( l == 0 ) + if ( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) + { + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + if ( hDirAC->hConfig->dec_param_estim == FALSE ) { - RealSubtract = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - ImagSubtract = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - stereo_type_detect->subtract_power_y += RealSubtract * RealSubtract + ImagSubtract * ImagSubtract; + rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat ); } + } + } + else + { + p_Rmat = 0; + } - /* Compute protos (and their power) for direct sound rendering */ + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + /* compute response */ + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_power_factors( hSpatParamRendCom->num_freq_bands, + diffuseness_vector, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - /* W prototype */ - if ( stereo_type_detect->interpolator > 0 ) - { - if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) - { - Real_aux = interpolatorSpaced * 0.5f * Real_aux + interpolatorDmx * Real_aux; - Imag_aux = interpolatorSpaced * 0.5f * Imag_aux + interpolatorDmx * Imag_aux; - proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; - } - else - { - tempSpaced = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - tempDmx = Real_aux * Real_aux + Imag_aux * Imag_aux; - proto_power_smooth[l] += interpolatorSpaced * tempSpaced + interpolatorDmx * tempDmx; - p_proto_buffer[2 * l] = interpolatorSpaced * RealBuffer[0][0][l] + interpolatorDmx * Real_aux; - p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDmx * Imag_aux; - } - } - else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + if ( coherence_flag ) { - if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) - { - Real_aux *= 0.5f; - Imag_aux *= 0.5f; - proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; - } - else + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - proto_power_smooth[l] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; - p_proto_buffer[2 * l] = RealBuffer[0][0][l]; - p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l]; + dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i]; + surCohEner = hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] * hSpatParamRendCom->surroundingCoherence[md_idx][i]; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] -= surCohEner; + hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] += surCohEner; + + surCohRatio[i] = surCohEner / ( 1e-12f + dirEne + surCohEner ); } } else { - proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); } + } + else + { + ivas_dirac_dec_compute_gain_factors( hSpatParamRendCom->num_freq_bands, + hSpatParamRendCom->diffuseness_vector[md_idx], + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor ); - /* Y prototype */ - if ( stereo_type_detect->interpolator > 0 ) - { - if ( l < ( dipole_freq_range[0] ) ) - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - } - else if ( l < ( dipole_freq_range[1] ) ) - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ) + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * ( -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ) ) + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - } - else - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - } - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } - else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + if ( coherence_flag ) { - if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; - } - else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ - { - p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; - } - else /* proto = W */ + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; - proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + surCohRatio[i] = hSpatParamRendCom->surroundingCoherence[md_idx][i]; } } else { - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + set_zero( surCohRatio, hSpatParamRendCom->num_freq_bands ); } - - /* Compute protos for decorrelation */ - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; } - - if ( stereo_type_detect->interpolator > 0 ) + if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 1 ) { - stereo_type_detect->interpolator++; - if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) - { - stereo_type_detect->interpolator = 0; - stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; - } + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa, +#ifdef MASA_AND_OBJECTS + st_ivas->hMasaIsmData, +#endif + azimuth, + elevation, + md_idx, + surCohRatio, + st_ivas->hCombinedOrientationData->shd_rot_max_order, + p_Rmat, + hodirac_flag ); + } + else + { + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa, +#ifdef MASA_AND_OBJECTS + st_ivas->hMasaIsmData, +#endif + azimuth, + elevation, + md_idx, + surCohRatio, + 0, + NULL, + hodirac_flag ); } - - stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; - stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; - stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; - - lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; - lr_bb_power *= 2.0f; - lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); - - stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; - stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; - stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; - - lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; - lr_hi_power *= 2.0f; - lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); - - minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); - min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); - - stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; - stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; - stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; - - ivas_masa_stereotype_detection( stereo_type_detect ); } - else - { - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; - for ( l = 0; l < num_freq_bands; l++ ) +#ifdef MASA_AND_OBJECTS + // Todo OMASA JBM: This might need adjustments + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) + { + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; - Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; - - reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; - proto_power_smooth[l] += reference_power[l]; - p_proto_buffer[2 * l] = Real_aux; - p_proto_buffer[2 * l + 1] = Imag_aux; - - p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; - p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; - proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + index_slot = slot_idx_start + slot_idx; - proto_frame_f[2 * l] = Real_aux; - proto_frame_f[2 * l + 1] = Imag_aux; + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), + Cldfb_RealBuffer_Temp[ch][slot_idx], + Cldfb_ImagBuffer_Temp[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); + } + } - proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; - proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; - proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) + { + preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, hSpatParamRendCom->num_freq_bands, subframe_idx ); } } +#endif - return; -} - - -static void protoSignalComputation4( - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float *proto_frame_f, - float *proto_direct_buffer_f, - float *reference_power, - float *proto_power_smooth, - const int16_t slot_index, - const int16_t num_outputs_diff, - const int16_t num_freq_bands, - const float *mtx_hoa_decoder, - const int16_t nchan_transport, - const int16_t *sba_map_tc_ind ) -{ - int16_t k, l; - int16_t n; - float sq_tmp; - float *p_proto_buffer; - - set_zero( reference_power, num_freq_bands ); - for ( k = 0; k < 4; k++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - for ( l = 0; l < num_freq_bands; l++ ) + index_slot = slot_idx_start + slot_idx; + if ( hDirAC->hConfig->dec_param_estim == TRUE ) { - sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; - reference_power[l] += 0.5f * sq_tmp; + md_idx = hSpatParamRendCom->render_to_md_map[index_slot]; + } + else + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; } - } - /*For decorrelated diffuseness*/ - for ( l = 0; l < num_outputs_diff; l++ ) - { - for ( k = 0; k < num_freq_bands; k++ ) + if ( st_ivas->ivas_format == SBA_FORMAT ) { - proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; - for ( n = 0; n < nchan_transport; n++ ) + for ( ch = 0; ch < nchan_transport; ch++ ) { - proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + mvr2r( pppQMfFrame_ts_re[ch][slot_idx], Cldfb_RealBuffer[ch][0], hSpatParamRendCom->num_freq_bands ); + mvr2r( pppQMfFrame_ts_im[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hSpatParamRendCom->num_freq_bands ); } } - } - - p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; - for ( k = 0; k < num_outputs_diff; k++ ) - { - for ( l = 0; l < num_freq_bands; l++ ) +#ifdef MASA_AND_OBJECTS + // Todo OMASA JBM: This might need adjustments + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 ) { - sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; - proto_power_smooth[l + k * num_freq_bands] += sq_tmp; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; - p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + for ( ch = 0; ch < nchan_transport; ch++ ) + { + mvr2r( Cldfb_RealBuffer_Temp[ch][slot_idx], Cldfb_RealBuffer[ch][0], hSpatParamRendCom->num_freq_bands ); + mvr2r( Cldfb_ImagBuffer_Temp[ch][slot_idx], Cldfb_ImagBuffer[ch][0], hSpatParamRendCom->num_freq_bands ); + } + } +#endif + else + { + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + cldfbAnalysis_ts( &( st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][hSpatParamRendCom->num_freq_bands * index_slot] ), + Cldfb_RealBuffer[ch][0], + Cldfb_ImagBuffer[ch][0], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch] ); + } } - } - return; -} + /* CNG in DirAC, extra CLDFB ana for CNA*/ + if ( st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && st_ivas->ivas_format != SBA_FORMAT ) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + generate_masking_noise_dirac( st->hFdCngDec->hFdCngCom, + st_ivas->cldfbAnaDec[1], + st_ivas->hTcBuffer->tc[1], + Cldfb_RealBuffer[1][0], + Cldfb_ImagBuffer[1][0], + index_slot, + st->cna_dirac_flag && st->flag_cna, + ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == FD_CNG && st->cng_sba_flag ); + } -/*------------------------------------------------------------------------- - * ivas_dirac_dec_compute_diffuse_proto() - * - * Compute diffuse prototype buffer and smooth power, only for decorrelated bands - *------------------------------------------------------------------------*/ + /* LFE synthesis */ + if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled && !( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && hDirACRend->hOutSetup.num_lfe == 0 ) ) + { + ivas_lfe_synth_with_cldfb( st_ivas->hMasa->hMasaLfeSynth, + Cldfb_RealBuffer, Cldfb_ImagBuffer, + Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1], + slot_idx, + md_idx, + nchan_transport ); + } -static void ivas_dirac_dec_compute_diffuse_proto( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t slot_idx /* i : slot index */ -) -{ - int16_t k, l; - int16_t num_freq_bands, num_freq_bands_diff; - float *p_diff_buffer, *p_diff_buffer_1; - float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; - DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; - DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - int16_t m; - float *p_hoa_enc; - - proto_frame_dec_f = hDirAC->proto_frame_dec_f; - h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); - - num_freq_bands = hDirAC->num_freq_bands; - num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; - - p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirAC->hOutSetup.nchan_out_woLFE; - p_diff_buffer_1 = p_diff_buffer + 1; - p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; - - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) - { - for ( k = 0; k < hDirAC->hOutSetup.nchan_out_woLFE; k++ ) + /*-----------------------------------------------------------------* + * protoype signal computation + *-----------------------------------------------------------------*/ + + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; - for ( l = 0; l < num_freq_bands_diff; l++ ) + if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) + { + protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, + reference_power, slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + p_Rmat ); + } + else { - *p_diff_buffer = *( p_proto_diff++ ); - *p_diff_buffer_1 = *( p_proto_diff++ ); - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; + protoSignalComputation_shd( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, + reference_power, slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0 ); } } - } - else - { - /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ - for ( k = 0; k < hDirAC->hOutSetup.nchan_out_woLFE; k++ ) + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); + } + else { - for ( l = 0; l < num_freq_bands_diff; l++ ) + switch ( nchan_transport ) { - p_hoa_enc = hDirAC->hoa_encoder + k; - p_proto_diff = proto_frame_dec_f + 2 * l; - - *p_diff_buffer = 0.f; - *p_diff_buffer_1 = 0.f; - - /*LS to HOA*/ - for ( m = 0; m < hDirAC->num_outputs_diff; m++ ) - { - *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); - *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); - p_hoa_enc += hDirAC->hOutSetup.nchan_out_woLFE; - p_proto_diff += 2 * num_freq_bands; - } - - *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); - p_diff_buffer += 2; - p_diff_buffer_1 += 2; + case 11: + case 8: + case 6: + case 4: + protoSignalComputation4( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + slot_idx, hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + hDirACRend->hoa_decoder, + nchan_transport, + hDirACRend->sba_map_tc ); + break; + case 2: + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect ); + break; + case 1: + protoSignalComputation1( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands ); + break; + default: + return; } } - } - - return; -} - -/*------------------------------------------------------------------------- - * computeDirectionAngles() - * - *------------------------------------------------------------------------*/ -static void computeDirectionAngles( - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z, - const int16_t num_frequency_bands, - int16_t *azimuth, - int16_t *elevation ) -{ - int16_t k; - float intensityNorm; - float x, y, z, radius; + /*-----------------------------------------------------------------* + * Compute DirAC parameters at decoder side + *-----------------------------------------------------------------*/ - for ( k = 0; k < num_frequency_bands; ++k ) + if ( hDirAC->hConfig->dec_param_estim == TRUE ) + { + mvs2s( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], hSpatParamRendCom->num_freq_bands - hDirAC->hConfig->enc_param_start_band ); + mvs2s( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], hSpatParamRendCom->num_freq_bands - hDirAC->hConfig->enc_param_start_band ); + if ( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) + { + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + rotateAziEle_DirAC( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat ); + } - { - intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + - *( intensity_real_y ) * *( intensity_real_y ) + - *( intensity_real_z ) * *( intensity_real_z ); + hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ - if ( intensityNorm <= EPSILON ) - { - intensityNorm = 1.0f; - x = 1.0f; - y = 0.0f; - z = 0.0f; - intensity_real_x++; - intensity_real_y++; - intensity_real_z++; - } - else - { - intensityNorm = sqrtf( 1.f / intensityNorm ); - x = *( intensity_real_x++ ) * intensityNorm; - y = *( intensity_real_y++ ) * intensityNorm; - z = *( intensity_real_z++ ) * intensityNorm; - } - radius = sqrtf( x * x + y * y ); - azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); - elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); - } + index = hDirACRend->index_buffer_intensity; - return; -} + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + computeIntensityVector_dec( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + num_freq_bands, + hDirACRend->buffer_intensity_real[0][index - 1], + hDirACRend->buffer_intensity_real[1][index - 1], + hDirACRend->buffer_intensity_real[2][index - 1] ); -/*------------------------------------------------------------------------- - * ivas_masa_init_stereotype_detection() - * - * Initialize stereo transport signal type detection - *------------------------------------------------------------------------*/ + computeDirectionAngles( hDirACRend->buffer_intensity_real[0][index - 1], + hDirACRend->buffer_intensity_real[1][index - 1], + hDirACRend->buffer_intensity_real[2][index - 1], + num_freq_bands, + azimuth, + elevation ); -static void ivas_masa_init_stereotype_detection( - MASA_STEREO_TYPE_DETECT *stereo_type_detect ) -{ - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; - stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; + mvr2r( reference_power, &( hDirACRend->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); - stereo_type_detect->counter = 0; - stereo_type_detect->interpolator = 0; + computeDiffuseness( hDirACRend->buffer_intensity_real, hDirACRend->buffer_energy, num_freq_bands, hSpatParamRendCom->diffuseness_vector[md_idx] ); + } - stereo_type_detect->dipole_freq_range[0] = 1; - stereo_type_detect->dipole_freq_range[1] = 3; +#ifdef DEBUG_MODE_DIRAC + { + static FILE *fp_direction_vector = NULL, *fp_diffuseness = NULL, *fp_referencePower = NULL; - stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ - stereo_type_detect->right_bb_power = 0.0f; - stereo_type_detect->total_bb_power = 0.0f; - stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ - stereo_type_detect->right_hi_power = 0.0f; - stereo_type_detect->total_hi_power = 0.0f; + if ( fp_direction_vector == NULL ) + fp_direction_vector = fopen( "./res/dbg_direction_vector_C_dec.bin", "wb" ); + if ( fp_diffuseness == NULL ) + fp_diffuseness = fopen( "./res/dbg_diffuseness_C_dec.bin", "wb" ); + if ( fp_referencePower == NULL ) + fp_referencePower = fopen( "./res/dbg_reference_power_C_dec.bin", "wb" ); - set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); - set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); - stereo_type_detect->subtract_power_y = 0.0f; - stereo_type_detect->subtract_power_y_smooth = 0.0f; - stereo_type_detect->target_power_y_smooth = 0.0f; + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + float radius_length; + float dv[3]; - stereo_type_detect->lr_total_bb_ratio_db = 0.0f; - stereo_type_detect->lr_total_hi_ratio_db = 0.0f; - stereo_type_detect->min_sum_total_ratio_db = 0.0f; - stereo_type_detect->subtract_target_ratio_db = 0.0f; + if ( hDirAC->hConfig->dec_param_estim == FALSE ) + { + radius_length = cos( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 ); + dv[0] = radius_length * cos( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 ); + dv[1] = radius_length * sin( hDirAC->azimuth[subframe_idx][i] * PI_OVER_180 ); + dv[2] = sin( hDirAC->elevation[subframe_idx][i] * PI_OVER_180 ); - return; -} + fwrite( dv, sizeof( float ), 3, fp_direction_vector ); + fwrite( &( hDirAC->diffuseness_vector[0][i] ), sizeof( float ), 1, fp_diffuseness ); + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + reference_power[i] = Cldfb_RealBuffer[0][0][i] * Cldfb_RealBuffer[0][0][i] + Cldfb_ImagBuffer[0][0][i] * Cldfb_ImagBuffer[0][0][i]; + } + fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower ); + } + else + { + radius_length = cos( hDirAC->elevation[index_slot][i] * PI_OVER_180 ); + dv[0] = radius_length * cos( hDirAC->azimuth[index_slot][i] * PI_OVER_180 ); + dv[1] = radius_length * sin( hDirAC->azimuth[index_slot][i] * PI_OVER_180 ); + dv[2] = sin( hDirAC->elevation[index_slot][i] * PI_OVER_180 ); + fwrite( dv, sizeof( float ), 3, fp_direction_vector ); + fwrite( &( hDirAC->diffuseness_vector[index_slot][i] ), sizeof( float ), 1, fp_diffuseness ); + fwrite( &( reference_power[i] ), sizeof( float ), 1, fp_referencePower ); + } + } + } +#endif -/*------------------------------------------------------------------------- - * ivas_masa_stereotype_detection() - * - * Detect the type of the transport audio signals - *------------------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * frequency domain decorrelation + *-----------------------------------------------------------------*/ -static void ivas_masa_stereotype_detection( - MASA_STEREO_TYPE_DETECT *stereo_type_detect ) -{ - float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; - float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; - float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; - float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; - float change_to_spaced; - int16_t change_to_spaced_selection; - float change_to_downmix; - float change_to_downmix2; - int16_t change_to_downmix_selection; - float subtract_temp; - float min_sum_temp; - float lr_total_bb_temp; - float lr_total_hi_temp; - - /* Determine if the determined features match the spaced mic type */ - change_to_spaced_selection = 0; - if ( subtract_target_ratio_db < -3.0f ) - { - subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; - min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); - lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; + if ( hDirACRend->proto_signal_decorr_on == 1 ) + { + /* decorrelate prototype frame */ + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); - change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; + v_multc( onset_filter, 0.25f, onset_filter, hSpatParamRendCom->num_freq_bands ); + v_add( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; + } + else + { + ivas_dirac_dec_decorr_process( hSpatParamRendCom->num_freq_bands, + hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, + hDirACRend->synthesisConf, + nchan_transport, + hDirACRend->proto_frame_f, + hDirACRend->num_protos_diff, + hDirACRend->proto_index_diff, + DirAC_mem.frame_dec_f, + onset_filter, + hDirACRend->h_freq_domain_decorr_ap_params, + hDirACRend->h_freq_domain_decorr_ap_state ); - if ( change_to_spaced >= 1.0f ) + hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f; + p_onset_filter = onset_filter; + } + } + else { - change_to_spaced_selection = 1; + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_f( onset_filter_subframe, 1.f, hSpatParamRendCom->num_freq_bands ); + p_onset_filter = onset_filter_subframe; + } + else + { + /* no frequency domain decorrelation: use prototype frame */ + hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; + p_onset_filter = NULL; + } } - } - - /* Determine if the determined features match the downmix type, according to a metric */ - change_to_downmix_selection = 0; - if ( subtract_target_ratio_db > 0.0f ) - { - subtract_temp = subtract_target_ratio_db / 3.0f; - min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; - lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; - change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; + /*-----------------------------------------------------------------* + * output synthesis + *-----------------------------------------------------------------*/ - if ( change_to_downmix >= 1.0f ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - change_to_downmix_selection = 1; + /*Compute diffuse prototypes*/ + ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); } - } - - /* Determine if the determined features match the downmix type, according to another metric */ - if ( lr_total_hi_ratio_db < -12.0f ) - { - subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; - min_sum_temp = min_sum_total_ratio_db / 6.0f; - lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; - change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; - - if ( change_to_downmix2 >= 1.0f ) + /*Compute PSDs*/ + if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 ) { - change_to_downmix_selection = 1; + ivas_dirac_dec_output_synthesis_process_slot( reference_power, + p_onset_filter, + azimuth, + elevation, + hSpatParamRendCom->diffuseness_vector[md_idx], + hSpatParamRendCom, + hDirACRend, + st_ivas->hCombinedOrientationData->shd_rot_max_order, + p_Rmat, + st_ivas->hVBAPdata, + hDirACRend->hOutSetup, + nchan_transport, + md_idx, + hodirac_flag, + hDirAC->hConfig->dec_param_estim ); } - } - - if ( stereo_type_detect->counter < 400 ) - { - stereo_type_detect->counter++; - } - else - { - if ( change_to_spaced_selection == 1 ) + else { - stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; + ivas_dirac_dec_output_synthesis_process_slot( reference_power, + p_onset_filter, + azimuth, + elevation, + hSpatParamRendCom->diffuseness_vector[md_idx], + hSpatParamRendCom, + hDirACRend, + 0, + 0, + st_ivas->hVBAPdata, + hDirACRend->hOutSetup, + nchan_transport, + md_idx, + hodirac_flag, + hDirAC->hConfig->dec_param_estim ); } - else if ( change_to_downmix_selection == 1 ) + + if ( hDirAC->hConfig->dec_param_estim ) { - stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + float fac = 1.0f / (float) hSpatParamRendCom->subframe_nbslots[subframe_idx]; + v_multc_acc( hSpatParamRendCom->diffuseness_vector[md_idx], fac, diffuseness_vector, hSpatParamRendCom->num_freq_bands ); } - } - if ( stereo_type_detect->interpolator == 0 ) - { - if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - stereo_type_detect->interpolator = 1; - stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; + v_add( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands ); } } - return; -} + ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); -/*------------------------------------------------------------------------- - * computeIntensityVector_dec() - * - * - *------------------------------------------------------------------------*/ - -static void computeIntensityVector_dec( - float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t num_frequency_bands, - float *intensity_real_x, - float *intensity_real_y, - float *intensity_real_z ) -{ - /* - * W = a + ib; Y = c + id - * real(W*Y') = ac + bd - */ - int16_t i; - float real, img; - - for ( i = 0; i < num_frequency_bands; ++i ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - real = Cldfb_RealBuffer[0][0][i]; - img = Cldfb_ImagBuffer[0][0][i]; - intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; - intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; - intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + nchan_transport, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + p_onset_filter, + diffuseness_vector, + hodirac_flag, + hDirAC->hConfig->dec_param_estim ); } + else + { + /* Determine encoding quality based additional smoothing factor */ + float qualityBasedSmFactor = 1.0f; - return; -} - + if ( st_ivas->hMasa != NULL ) + { + qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality; + qualityBasedSmFactor *= qualityBasedSmFactor; + } -/*------------------------------------------------------------------------- - * ivas_lfe_synth_with_cldfb() - * - * - *------------------------------------------------------------------------*/ -static void ivas_lfe_synth_with_cldfb( - MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, - float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], - const int16_t slot_index, - const int16_t subframe_index, - const int16_t nchan_transport ) -{ - float lfeGain; - float transportGain; - float protoLfeReal, protoLfeImag; - int16_t i; - float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; - - set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); - - protoLfeReal = RealBuffer[0][0][0]; - protoLfeImag = ImagBuffer[0][0][0]; - transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; - for ( i = 1; i < nchan_transport; i++ ) - { - protoLfeReal += RealBuffer[i][0][0]; - protoLfeImag += ImagBuffer[i][0][0]; - transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; + ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hSpatParamRendCom, + hDirACRend, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + diffuseness_vector, + reference_power_smooth, + qualityBasedSmFactor, + hDirAC->hConfig->enc_param_start_band ); } - protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; - targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; - targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); + /*-----------------------------------------------------------------* + * CLDFB synthesis (and binaural rendering) + *-----------------------------------------------------------------*/ - hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; - hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; + index_slot = slot_idx_start_cldfb_synth; - hMasaLfeSynth->transportEneSmooth += transportEne; - hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; - hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; - hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; + if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + { + /* Perform binaural rendering */ + ivas_binRenderer( st_ivas->hBinRenderer, +#ifdef SPLIT_REND_WITH_HEAD_ROT + &st_ivas->splitBinRend.splitrend.multiBinPoseData, +#endif + st_ivas->hCombinedOrientationData, + subframe_idx, + hSpatParamRendCom->subframe_nbslots[subframe_idx], + Cldfb_RealBuffer_Binaural, + Cldfb_ImagBuffer_Binaural, + Cldfb_RealBuffer, + Cldfb_ImagBuffer ); - lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); - transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); +#ifdef SPLIT_REND_WITH_HEAD_ROT + if ( ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || + ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) + { + int16_t pos_idx; +#ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG + for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ ) +#else + for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ ) +#endif + { + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) + { + mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands ); + mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->splitBinRend.hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_idx_start + slot_idx], hSpatParamRendCom->num_freq_bands ); + } + } + } + } +#endif + /* Inverse CLDFB*/ + for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) + { + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; - ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { +#ifdef SPLIT_REND_WITH_HEAD_ROT + RealBuffer[i] = Cldfb_RealBuffer_Binaural[0][ch][i]; + ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[0][ch][i]; +#else + RealBuffer[i] = Cldfb_RealBuffer_Binaural[ch][i]; + ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[ch][i]; +#endif + } - RealBuffer[0][0][0] *= transportGain; - ImagBuffer[0][0][0] *= transportGain; - for ( i = 1; i < nchan_transport; i++ ) + cldfbSynthesis( RealBuffer, + ImagBuffer, + &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], + st_ivas->cldfbSynDec[ch] ); + } + } + else if ( st_ivas->ivas_format == SBA_FORMAT ) { - RealBuffer[i][0][0] *= transportGain; - ImagBuffer[i][0][0] *= transportGain; + for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) + { + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + mvr2r( Cldfb_RealBuffer[ch][slot_idx], pppQMfFrame_ts_re[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); + mvr2r( Cldfb_ImagBuffer[ch][slot_idx], pppQMfFrame_ts_im[ch][slot_idx], hSpatParamRendCom->num_freq_bands ); + } + } } + else + { + float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t outchannels; - return; -} + idx_in = 0; + idx_lfe = 0; + outchannels = hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; + if ( hDirACRend->hOutSetup.separateChannelEnabled && ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1 || + hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1 || + hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_2 || + hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_5_1_4 || + hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_7_1_4 || + ( hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) + { + outchannels++; + } -/*------------------------------------------------------------------------- - * rotateAziEle_DirAC() - * - * Apply rotation to DirAC DOAs - *------------------------------------------------------------------------*/ + if ( hDirACRend->hOutSetup.separateChannelEnabled && hDirACRend->hOutSetup.output_config == AUDIO_CONFIG_LS_CUSTOM ) + { + float tmp_separated[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + float tmp_lfe[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + const int16_t subframe_start_sample = index_slot * hSpatParamRendCom->num_freq_bands; + const int16_t num_samples_subframe = hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]; -static void rotateAziEle_DirAC( - int16_t *azi, /* i/o: array of azimuth values */ - int16_t *ele, /* i/o: array of elevation values */ - const int16_t band1, /* i : bands to work on (lower limit) */ - const int16_t band2, /* i : bands to work on (upper bound) */ - const float *p_Rmat /* i : pointer to real-space rotation matrix */ -) -{ - int16_t b; - float dv_0, dv_1, dv_2; - float dv_r_0, dv_r_1, dv_r_2; - float w; + /* Move the separated and the LFE channels to temporary variables as spatial synthesis may overwrite current channels */ + mvr2r( &( output_f[st_ivas->hOutSetup.separateChannelIndex][subframe_start_sample] ), tmp_separated, num_samples_subframe ); + mvr2r( &( output_f[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe, num_samples_subframe ); - push_wmops( "rotateAziEle_DirAC" ); + for ( ch = 0; ch < outchannels; ch++ ) + { + if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) + { + /* Move the LFE channel to the correct place */ + mvr2r( tmp_lfe, &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); - for ( b = band1; b < band2; b++ ) - { + if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) + { + idx_lfe++; + } + } + else if ( ( st_ivas->hLsSetupCustom->separate_ch_found ) && ( hDirACRend->hOutSetup.separateChannelIndex == ch ) ) + { + /* Move the separated channel to the correct place. Thus, the separated channel is + * combined with the synthesized channels here when there is a matching channel. */ + mvr2r( tmp_separated, &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); + } + else + { + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + } + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][subframe_start_sample] ), num_samples_subframe, st_ivas->cldfbSynDec[idx_in] ); - /*Conversion spherical to cartesian coordinates*/ - w = cosf( ele[b] * PI_OVER_180 ); - dv_0 = w * cosf( azi[b] * PI_OVER_180 ); - dv_1 = w * sinf( azi[b] * PI_OVER_180 ); - dv_2 = sinf( ele[b] * PI_OVER_180 ); + if ( !st_ivas->hLsSetupCustom->separate_ch_found ) + { + /* Pan the separated channel and mix with the synthesized channels. Thus, the separated channel + * is combined with the synthesized channels here when there is no matching channel. */ + v_multc_acc( tmp_separated, st_ivas->hLsSetupCustom->separate_ch_gains[idx_in], &( output_f[ch][subframe_start_sample] ), num_samples_subframe ); + } - dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; - dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; - dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; + idx_in++; + } + } + } + else + { + for ( ch = 0; ch < outchannels; ch++ ) + { + if ( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( hDirACRend->hOutSetup.index_lfe[idx_lfe] == ch ) ) + { + if ( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled ) + { + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][i]; + } + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[hDirACRend->hOutSetup.nchan_out_woLFE + idx_lfe] ); + } + else if ( st_ivas->mc_mode == MC_MODE_MCMASA && hDirACRend->hOutSetup.separateChannelEnabled ) + { + /* LFE has been synthesized in the time domain, do nothing. */ + } + else + { + set_zero( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + } - /*Conversion spherical to cartesian coordinates*/ - azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); - ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); + if ( idx_lfe < ( hDirACRend->hOutSetup.num_lfe - 1 ) ) + { + idx_lfe++; + } + } + else if ( ( hDirACRend->hOutSetup.separateChannelEnabled ) && ( hDirACRend->hOutSetup.separateChannelIndex == ch ) ) + { + /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated + * channel is combined with the synthesized channels here. */ + } + else + { + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) + { + RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + } + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[idx_in] ); + idx_in++; + } + } + } } + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; + hSpatParamRendCom->subframes_rendered++; pop_wmops(); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 111a9ab18b..b8d708b261 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -959,82 +959,57 @@ ivas_error ivas_init_decoder( st_ivas->hSCE[1]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed3 = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->seed2; } } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) + else if ( st_ivas->ivas_format == SBA_FORMAT ) { - if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { return error; } - if ( st_ivas->ivas_format == MASA_FORMAT ) + if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) { -#ifdef MASA_AND_OBJECTS - /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ - st_ivas->ism_extmeta_active = -1; - st_ivas->ism_extmeta_cnt = 0; -#endif - if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } - else if ( st_ivas->ivas_format == SBA_FORMAT ) + + if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) { - if ( ( error = ivas_spar_dec_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) { return error; } + } - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC && st_ivas->hOutSetup.is_loudspeaker_setup ) - { - if ( ( error = ivas_sba_get_hoa_dec_matrix( st_ivas->hOutSetup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) - { - return error; - } - } + if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK ) + { + return error; + } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK ) + if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } - if ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO && st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) - { - if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + } + else + { + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; - st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; - } - else + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { - int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; - - st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) - { - st_ivas->hSpar->enc_param_start_band = 0; - - set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); - st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; - } + st_ivas->hSpar->enc_param_start_band = 0; - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), - st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); + set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; } - st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); - } - if ( st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV && st_ivas->renderer_type != RENDERER_BINAURAL_MIXER_CONV_ROOM && - st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && st_ivas->ivas_format != SBA_FORMAT ) - { - if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } + st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -1079,6 +1054,57 @@ ivas_error ivas_init_decoder( } } + /* set CNA/CNG flags */ + ivas_sba_set_cna_cng_flag( st_ivas ); + } + else if ( st_ivas->ivas_format == MASA_FORMAT ) + { +#ifdef MASA_AND_OBJECTS + /* if we start in ISM_MODE_NONE in MASA_ISM, that appears as normal MASA, but we may change to a mode with ISMs */ + st_ivas->ism_extmeta_active = -1; + st_ivas->ism_extmeta_cnt = 0; +#endif + if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ( error = ivas_masa_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) + { + if ( ( error = create_sce_dec( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } + + reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); + } + + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + if ( ( error = create_cpe_dec( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + reset_indices_dec( st_ivas->hCPE[cpe_id]->hCoreCoder[n] ); + } + } + /* set CNA/CNG flags */ ivas_sba_set_cna_cng_flag( st_ivas ); } @@ -1152,9 +1178,14 @@ ivas_error ivas_init_decoder( return error; } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) +#if 0 + /* TODO: dirac refactor merge: check! */ + if (st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX) +#else + if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) +#endif { - if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -1277,7 +1308,7 @@ ivas_error ivas_init_decoder( } } - if ( st_ivas->nCPE > 1 ) // VE: TBV - is this needed? + if ( st_ivas->nCPE > 1 ) { if ( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) { @@ -1305,7 +1336,7 @@ ivas_error ivas_init_decoder( if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MCMASA_MONO_STEREO ) { - if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -1453,7 +1484,8 @@ ivas_error ivas_init_decoder( } #endif } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + /* ParamISM is handled separately from other common config */ + else if ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) { if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) { @@ -1986,6 +2018,8 @@ void ivas_initialize_handles_dec( ivas_init_split_rend_handles( &st_ivas->splitBinRend.splitrend ); #endif st_ivas->hDiracDecBin = NULL; + st_ivas->hDirACRend = NULL; + st_ivas->hSpatParamRendCom = NULL; st_ivas->hLsSetUpConversion = NULL; st_ivas->hEFAPdata = NULL; st_ivas->hVBAPdata = NULL; @@ -2103,10 +2137,12 @@ void ivas_destroy_dec( /* DirAC handle */ if ( st_ivas->ivas_format == ISM_FORMAT ) { - ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config ); + ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); } else { + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); } @@ -2354,7 +2390,7 @@ void ivas_init_dec_get_num_cldfb_instances( { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } - else if ( st_ivas->nchan_transport == 1 && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + else if ( st_ivas->nchan_transport == 1 && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { *numCldfbAnalyses = st_ivas->nchan_transport + 1; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index d3d3baa85e..7d96cf605e 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -127,13 +127,13 @@ static ivas_error ivas_ism_bitrate_switching( if ( st_ivas->hDecoderConfig->voip_active ) { /* transfer subframe info from DirAC or ParamMC to central tc buffer */ - if ( last_ism_mode == ISM_MODE_PARAM && st_ivas->hDirAC != NULL && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) ) + if ( last_ism_mode == ISM_MODE_PARAM && st_ivas->hSpatParamRendCom != NULL && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) ) { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered; - st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered; - mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv @@ -174,7 +174,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 */ - ivas_param_ism_dec_close( &( st_ivas->hDirAC ), st_ivas->hDecoderConfig->output_config ); + ivas_param_ism_dec_close( &( st_ivas->hDirAC ), &( st_ivas->hSpatParamRendCom ), st_ivas->hDecoderConfig->output_config ); #ifdef FIX_568_ISM_BITRATE_SWITCHING if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL || st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) @@ -374,14 +374,14 @@ static ivas_error ivas_ism_bitrate_switching( } /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hDirAC != NULL ) + if ( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 2497f5ab98..4662304a4a 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -287,6 +287,7 @@ static void ivas_param_ism_compute_mixing_matrix( static void ivas_param_ism_render_slot( DIRAC_DEC_HANDLE hDirAC, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX], float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX], float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -302,7 +303,7 @@ static void ivas_param_ism_render_slot( tmp_1 = hDirAC->hParamIsmRendering->interpolator[interpolator_idx]; - for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { /* smooth the mixing matrix */ for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) @@ -324,6 +325,7 @@ static void ivas_param_ism_render_slot( static void ivas_param_ism_rendering( DIRAC_DEC_HANDLE hDirAC, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, float Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_RealBuffer[PARAM_ISM_MAX_CHAN][4][CLDFB_NO_CHANNELS_MAX], @@ -339,7 +341,7 @@ static void ivas_param_ism_rendering( tmp_1 = hDirAC->hParamIsmRendering->interpolator[slot_idx]; - for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { /* smooth the mixing matrix */ for ( outchIdx = 0; outchIdx < num_ch_LS; outchIdx++ ) @@ -440,6 +442,7 @@ ivas_error ivas_param_ism_dec_open( int16_t i; DIRAC_DEC_HANDLE hDirAC; IVAS_OUTPUT_SETUP hOutSetup; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; AUDIO_CONFIG output_config; int32_t output_Fs; ivas_error error; @@ -457,6 +460,11 @@ ivas_error ivas_param_ism_dec_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } + if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + /* Assign memory to Param Object handle */ if ( ( hDirAC->hParamIsm = (PARAM_ISM_CONFIG_HANDLE) malloc( sizeof( PARAM_ISM_CONFIG_DATA ) ) ) == NULL ) { @@ -477,15 +485,15 @@ ivas_error ivas_param_ism_dec_open( * set input parameters *-----------------------------------------------------------------*/ - hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); hDirAC->hConfig = NULL; - set_s( hDirAC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hDirAC->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); - hDirAC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; - hDirAC->subframes_rendered = 0; - hDirAC->slots_rendered = 0; - hDirAC->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + hSpatParamRendCom->subframes_rendered = 0; + hSpatParamRendCom->slots_rendered = 0; + hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); hDirAC->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; @@ -493,9 +501,9 @@ ivas_error ivas_param_ism_dec_open( { hDirAC->hParamIsm->band_grouping[i] = Param_ISM_band_grouping[i]; - if ( hDirAC->hParamIsm->band_grouping[i] > hDirAC->num_freq_bands ) + if ( hDirAC->hParamIsm->band_grouping[i] > hSpatParamRendCom->num_freq_bands ) { - hDirAC->hParamIsm->band_grouping[i] = hDirAC->num_freq_bands; + hDirAC->hParamIsm->band_grouping[i] = hSpatParamRendCom->num_freq_bands; } } @@ -546,19 +554,19 @@ ivas_error ivas_param_ism_dec_open( set_zero( hDirAC->azimuth_values, MAX_NUM_OBJECTS ); set_zero( hDirAC->elevation_values, MAX_NUM_OBJECTS ); - hDirAC->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; - hDirAC->dirac_bs_md_write_idx = 0; - hDirAC->dirac_read_idx = 0; + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + hSpatParamRendCom->dirac_bs_md_write_idx = 0; + hSpatParamRendCom->dirac_read_idx = 0; hDirAC->spar_to_dirac_write_idx = 0; if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 1 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = ivas_dirac_allocate_parameters( hDirAC, 2 ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) { return error; } @@ -567,6 +575,7 @@ ivas_error ivas_param_ism_dec_open( st_ivas->hISMDTX.dtx_flag = 0; st_ivas->hDirAC = hDirAC; + st_ivas->hSpatParamRendCom = hSpatParamRendCom; if ( st_ivas->hDecoderConfig->voip_active ) { @@ -582,17 +591,17 @@ ivas_error ivas_param_ism_dec_open( } else { - if ( ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + if ( ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } - set_zero( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands ); + set_zero( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands ); - if ( ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + if ( ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param ISM JBM Rendering handle\n" ) ); } - set_zero( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hDirAC->num_freq_bands ); + set_zero( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc, MAX_JBM_CLDFB_TIMESLOTS * nchan_transport * hSpatParamRendCom->num_freq_bands ); } if ( st_ivas->hTcBuffer == NULL ) { @@ -634,66 +643,70 @@ ivas_error ivas_param_ism_dec_open( *-------------------------------------------------------------------------*/ void ivas_param_ism_dec_close( - DIRAC_DEC_HANDLE *hDirAC_out, /* i/o: decoder DirAC handle */ - AUDIO_CONFIG output_config /* i : output audio configuration */ + DIRAC_DEC_HANDLE *hDirAC_out, /* i/o: decoder DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: common spatial renderer data */ + AUDIO_CONFIG output_config /* i : output audio configuration */ ) { - DIRAC_DEC_HANDLE hDirAC; - - if ( hDirAC_out == NULL || *hDirAC_out == NULL ) + if ( hDirAC_out != NULL && *hDirAC_out != NULL ) { - return; - } - - hDirAC = *hDirAC_out; + DIRAC_DEC_HANDLE hDirAC; + hDirAC = *hDirAC_out; - /* Config & CLDFB */ - if ( hDirAC->hParamIsm != NULL ) - { - free( hDirAC->hParamIsm ); - hDirAC->hParamIsm = NULL; - } + /* Config & CLDFB */ + if ( hDirAC->hParamIsm != NULL ) + { + free( hDirAC->hParamIsm ); + hDirAC->hParamIsm = NULL; + } - if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) - { - ivas_dirac_deallocate_parameters( hDirAC, 1 ); - ivas_dirac_deallocate_parameters( hDirAC, 2 ); - } + if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) + { + /* Param ISM Rendering */ + if ( hDirAC->hParamIsmRendering->interpolator != NULL ) + { + free( hDirAC->hParamIsmRendering->interpolator ); + hDirAC->hParamIsmRendering->interpolator = NULL; + } + if ( hDirAC->hParamIsmRendering->proto_matrix != NULL ) + { + free( hDirAC->hParamIsmRendering->proto_matrix ); + hDirAC->hParamIsmRendering->proto_matrix = NULL; + } + } - if ( !( output_config == AUDIO_CONFIG_MONO || output_config == AUDIO_CONFIG_STEREO ) ) - { - /* Param ISM Rendering */ - if ( hDirAC->hParamIsmRendering->interpolator != NULL ) + if ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL ) { - free( hDirAC->hParamIsmRendering->interpolator ); - hDirAC->hParamIsmRendering->interpolator = NULL; + free( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc ); + hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; } - if ( hDirAC->hParamIsmRendering->proto_matrix != NULL ) + if ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL ) { - free( hDirAC->hParamIsmRendering->proto_matrix ); - hDirAC->hParamIsmRendering->proto_matrix = NULL; + free( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc ); + hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; } - } - if ( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc != NULL ) - { - free( hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc ); - hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc = NULL; - } - if ( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc != NULL ) - { - free( hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc ); - hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc = NULL; + if ( hDirAC->hParamIsmRendering != NULL ) + { + free( hDirAC->hParamIsmRendering ); + hDirAC->hParamIsmRendering = NULL; + } + + free( *hDirAC_out ); + *hDirAC_out = NULL; } - if ( hDirAC->hParamIsmRendering != NULL ) + if ( hSpatParamRendCom_out != NULL && *hSpatParamRendCom_out != NULL ) { - free( hDirAC->hParamIsmRendering ); - hDirAC->hParamIsmRendering = NULL; - } + if ( output_config == AUDIO_CONFIG_BINAURAL || output_config == AUDIO_CONFIG_BINAURAL_ROOM_IR || output_config == AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); + } - free( *hDirAC_out ); - *hDirAC_out = NULL; + free( *hSpatParamRendCom_out ); + *hSpatParamRendCom_out = NULL; + } return; } @@ -735,12 +748,15 @@ void ivas_param_ism_dec( float mixing_matrix[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; IVAS_OUTPUT_SETUP hSetup; /* Initialization */ hDirAC = st_ivas->hDirAC; assert( hDirAC ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + assert( hSpatParamRendCom ); #ifdef FIX_549_DMX_GAIN ene_tc = 0.0f; ene_sum = 0.0f; @@ -873,14 +889,14 @@ void ivas_param_ism_dec( *-----------------------------------------------------------------*/ for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ ) { - cldfbAnalysis_ts( &( output_f[ch][hDirAC->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hDirAC->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + cldfbAnalysis_ts( &( output_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); ivas_param_ism_collect_slot( hDirAC, Cldfb_RealBuffer_in[ch][slot_idx], Cldfb_ImagBuffer_in[ch][slot_idx], ch, ref_power, cx_diag ); } } /* Obtain Mixing Matrix on a frame-level */ - for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { set_f( mixing_matrix[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE ); } @@ -888,28 +904,28 @@ void ivas_param_ism_dec( /* Compute mixing matrix */ ivas_param_ism_compute_mixing_matrix( st_ivas->nchan_ism, hDirAC, st_ivas->hISMDTX, direct_response, nchan_transport, nchan_out_woLFE, cx_diag, ref_power, mixing_matrix ); /* subframe loop for synthesis*/ - for ( subframe_idx = 0; subframe_idx < hDirAC->nb_subframes; subframe_idx++ ) + for ( subframe_idx = 0; subframe_idx < hSpatParamRendCom->nb_subframes; subframe_idx++ ) { - uint16_t slot_idx_start = subframe_idx * hDirAC->subframe_nbslots[subframe_idx]; + uint16_t slot_idx_start = subframe_idx * hSpatParamRendCom->subframe_nbslots[subframe_idx]; uint16_t idx_in; uint16_t idx_lfe; /* Set some memories to zero */ for ( ch = 0; ch < nchan_out_woLFE; ch++ ) { - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands ); - set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands ); + set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); } } - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { index_slot = slot_idx_start + slot_idx; /* Compute bandwise rendering to target LS using covariance rendering */ - ivas_param_ism_rendering( hDirAC, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, + ivas_param_ism_rendering( hDirAC, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Cldfb_RealBuffer, Cldfb_ImagBuffer, mixing_matrix, slot_idx, index_slot, nchan_out_woLFE, nchan_transport ); } @@ -922,7 +938,7 @@ void ivas_param_ism_dec( { if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) { - set_zero( &( output_f[ch][slot_idx_start * hDirAC->num_freq_bands] ), hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands ); + set_zero( &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); if ( idx_lfe < ( hSetup.num_lfe - 1 ) ) { idx_lfe++; @@ -934,14 +950,14 @@ void ivas_param_ism_dec( float *ImagBuffer[16]; /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; } - cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][slot_idx_start * hDirAC->num_freq_bands] ), - hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][slot_idx_start * hSpatParamRendCom->num_freq_bands] ), + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); idx_in++; } @@ -1091,10 +1107,13 @@ void ivas_param_ism_dec_digest_tc( /* Direct Response/EFAP Gains */ float direct_response[MAX_NUM_OBJECTS][PARAM_ISM_MAX_CHAN]; DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; /* Initialization */ hDirAC = st_ivas->hDirAC; assert( hDirAC ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + assert( hSpatParamRendCom ); #ifdef FIX_549_DMX_GAIN ene_tc = 0.0f; ene_sum = 0.0f; @@ -1233,16 +1252,16 @@ void ivas_param_ism_dec_digest_tc( float RealBuffer[CLDFB_NO_CHANNELS_MAX]; float ImagBuffer[CLDFB_NO_CHANNELS_MAX]; - cldfbAnalysis_ts( &( transport_channels_f[ch][hDirAC->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hDirAC->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); - mvr2r( RealBuffer, &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands], hDirAC->num_freq_bands ); - mvr2r( ImagBuffer, &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands], hDirAC->num_freq_bands ); + cldfbAnalysis_ts( &( transport_channels_f[ch][hSpatParamRendCom->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hSpatParamRendCom->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + mvr2r( RealBuffer, &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); + mvr2r( ImagBuffer, &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[slot_idx * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands], hSpatParamRendCom->num_freq_bands ); ivas_param_ism_collect_slot( hDirAC, RealBuffer, ImagBuffer, ch, ref_power, cx_diag ); } } /* Obtain Mixing Matrix on a frame-level */ - for ( bin_idx = 0; bin_idx < hDirAC->num_freq_bands; bin_idx++ ) + for ( bin_idx = 0; bin_idx < hSpatParamRendCom->num_freq_bands; bin_idx++ ) { set_f( hDirAC->hParamIsmRendering->mixing_matrix_lin[bin_idx], 0.0f, nchan_transport * nchan_out_woLFE ); } @@ -1278,6 +1297,7 @@ static void ivas_ism_param_dec_render_sf( float *Cldfb_RealBuffer_in[PARAM_ISM_MAX_DMX]; float *Cldfb_ImagBuffer_in[PARAM_ISM_MAX_DMX]; DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; int16_t slot_idx_start; int16_t idx_in; @@ -1285,31 +1305,32 @@ static void ivas_ism_param_dec_render_sf( int16_t subframe_idx; hDirAC = st_ivas->hDirAC; - slot_idx_start = hDirAC->slots_rendered; - subframe_idx = hDirAC->subframes_rendered; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + slot_idx_start = hSpatParamRendCom->slots_rendered; + subframe_idx = hSpatParamRendCom->subframes_rendered; /* Set some memories to zero */ for ( ch = 0; ch < nchan_out_woLFE; ch++ ) { - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands ); - set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hDirAC->num_freq_bands ); + set_f( Cldfb_RealBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); + set_f( Cldfb_ImagBuffer[ch][slot_idx], 0.0f, hSpatParamRendCom->num_freq_bands ); } } - for ( slot_idx = 0; slot_idx < hDirAC->subframe_nbslots[subframe_idx]; slot_idx++ ) + for ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { index_slot = slot_idx_start + slot_idx; for ( ch = 0; ch < nchan_transport; ch++ ) { - Cldfb_RealBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands]; - Cldfb_ImagBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hDirAC->num_freq_bands * nchan_transport + ch * hDirAC->num_freq_bands]; + Cldfb_RealBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_RealBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; + Cldfb_ImagBuffer_in[ch] = &hDirAC->hParamIsmRendering->Cldfb_ImagBuffer_tc[index_slot * hSpatParamRendCom->num_freq_bands * nchan_transport + ch * hSpatParamRendCom->num_freq_bands]; } /* Compute bandwise rendering to target LS using covariance rendering */ - ivas_param_ism_render_slot( hDirAC, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, + ivas_param_ism_render_slot( hDirAC, hSpatParamRendCom, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirAC->hParamIsmRendering->mixing_matrix_lin, index_slot, slot_idx, nchan_out_woLFE, nchan_transport ); } @@ -1322,7 +1343,7 @@ static void ivas_ism_param_dec_render_sf( { if ( ( hSetup.num_lfe > 0 ) && ( hSetup.index_lfe[idx_lfe] == ch ) ) { - set_zero( output_f[ch], hDirAC->subframe_nbslots[subframe_idx] * hDirAC->num_freq_bands ); + set_zero( output_f[ch], hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); if ( idx_lfe < ( hSetup.num_lfe - 1 ) ) { idx_lfe++; @@ -1334,19 +1355,19 @@ static void ivas_ism_param_dec_render_sf( float *ImagBuffer[16]; /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < hDirAC->subframe_nbslots[subframe_idx]; i++ ) + for ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; } cldfbSynthesis( RealBuffer, ImagBuffer, output_f[ch], - hDirAC->num_freq_bands * hDirAC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); idx_in++; } } - hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe_idx]; - hDirAC->subframes_rendered++; + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe_idx]; + hSpatParamRendCom->subframes_rendered++; return; } @@ -1369,14 +1390,17 @@ void ivas_param_ism_dec_render( int16_t ch, slots_to_render, first_sf, last_sf, subframe_idx; uint16_t slot_size, n_samples_sf; DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; IVAS_OUTPUT_SETUP hSetup; int16_t nchan_transport, nchan_out, nchan_out_woLFE; float *output_f_local[MAX_OUTPUT_CHANNELS]; hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; hSetup = st_ivas->hIntSetup; #ifdef DEBUGGING assert( hDirAC ); + assert( hSpatParamRendCom ); #endif nchan_transport = st_ivas->nchan_transport; if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) @@ -1393,14 +1417,14 @@ void ivas_param_ism_dec_render( slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size ); + slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); *nSamplesRendered = slots_to_render * slot_size; - first_sf = hDirAC->subframes_rendered; + first_sf = hSpatParamRendCom->subframes_rendered; last_sf = first_sf; while ( slots_to_render > 0 ) { - slots_to_render -= hDirAC->subframe_nbslots[last_sf]; + slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf]; last_sf++; } #ifdef DEBUGGING @@ -1415,14 +1439,14 @@ void ivas_param_ism_dec_render( for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { ivas_ism_param_dec_render_sf( st_ivas, hSetup, nchan_transport, nchan_out, nchan_out_woLFE, output_f_local ); - n_samples_sf = hDirAC->subframe_nbslots[subframe_idx] * st_ivas->hDirAC->slot_size; + n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; for ( ch = 0; ch < nchan_out; ch++ ) { output_f_local[ch] += n_samples_sf; } } - if ( hDirAC->slots_rendered == hDirAC->num_slots ) + if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { /* copy the memories */ /* store mixing matrix for next subframe */ @@ -1444,7 +1468,7 @@ void ivas_param_ism_dec_render( } } - *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size; + *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; return; } @@ -1461,6 +1485,7 @@ void ivas_param_ism_params_to_masa_param_mapping( ) { DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; int16_t nBins; int16_t band_idx, bin_idx, sf_idx; int16_t brange[2]; @@ -1470,7 +1495,8 @@ void ivas_param_ism_params_to_masa_param_mapping( int32_t ivas_total_brate; hDirAC = st_ivas->hDirAC; - nBins = hDirAC->num_freq_bands; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nBins = hSpatParamRendCom->num_freq_bands; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -1492,7 +1518,7 @@ void ivas_param_ism_params_to_masa_param_mapping( float energy_ratio; energy_ratio = powf( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence, 2.0f ); - hDirAC->numSimultaneousDirections = 1; + hSpatParamRendCom->numSimultaneousDirections = 1; azimuth[0] = (int16_t) roundf( hDirAC->azimuth_values[0] ); elevation[0] = (int16_t) roundf( hDirAC->elevation_values[0] ); @@ -1500,19 +1526,19 @@ void ivas_param_ism_params_to_masa_param_mapping( { for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { - hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0]; - hDirAC->elevation[sf_idx][bin_idx] = elevation[0]; + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; - hDirAC->energy_ratio1[sf_idx][bin_idx] = energy_ratio; + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = energy_ratio; - hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f; - hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0; + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; } } } else { - hDirAC->numSimultaneousDirections = 2; + hSpatParamRendCom->numSimultaneousDirections = 2; for ( band_idx = 0; band_idx < hDirAC->hParamIsm->nbands; band_idx++ ) { brange[0] = hDirAC->hParamIsm->band_grouping[band_idx]; @@ -1530,12 +1556,12 @@ void ivas_param_ism_params_to_masa_param_mapping( { for ( bin_idx = brange[0]; bin_idx < brange[1]; bin_idx++ ) { - hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0]; - hDirAC->elevation[sf_idx][bin_idx] = elevation[0]; - hDirAC->energy_ratio1[sf_idx][bin_idx] = power_ratio[0]; - hDirAC->azimuth2[sf_idx][bin_idx] = azimuth[1]; - hDirAC->elevation2[sf_idx][bin_idx] = elevation[1]; - hDirAC->energy_ratio2[sf_idx][bin_idx] = power_ratio[1]; + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = power_ratio[0]; + hSpatParamRendCom->azimuth2[sf_idx][bin_idx] = azimuth[1]; + hSpatParamRendCom->elevation2[sf_idx][bin_idx] = elevation[1]; + hSpatParamRendCom->energy_ratio2[sf_idx][bin_idx] = power_ratio[1]; } } } @@ -1544,16 +1570,16 @@ void ivas_param_ism_params_to_masa_param_mapping( { for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { - hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f; - hDirAC->spreadCoherence2[sf_idx][bin_idx] = 0.0f; - hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0; + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->spreadCoherence2[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; } } } } else { - hDirAC->numSimultaneousDirections = 1; + hSpatParamRendCom->numSimultaneousDirections = 1; azimuth[0] = (int16_t) roundf( hDirAC->azimuth_values[0] ); elevation[0] = (int16_t) roundf( hDirAC->elevation_values[0] ); @@ -1561,11 +1587,11 @@ void ivas_param_ism_params_to_masa_param_mapping( { for ( bin_idx = 0; bin_idx < nBins; bin_idx++ ) { - hDirAC->azimuth[sf_idx][bin_idx] = azimuth[0]; - hDirAC->elevation[sf_idx][bin_idx] = elevation[0]; - hDirAC->energy_ratio1[sf_idx][bin_idx] = 1.0f; - hDirAC->spreadCoherence[sf_idx][bin_idx] = 0.0f; - hDirAC->surroundingCoherence[sf_idx][bin_idx] = 0.0; + hSpatParamRendCom->azimuth[sf_idx][bin_idx] = azimuth[0]; + hSpatParamRendCom->elevation[sf_idx][bin_idx] = elevation[0]; + hSpatParamRendCom->energy_ratio1[sf_idx][bin_idx] = 1.0f; + hSpatParamRendCom->spreadCoherence[sf_idx][bin_idx] = 0.0f; + hSpatParamRendCom->surroundingCoherence[sf_idx][bin_idx] = 0.0; } } } diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 9c4479374d..24ce4e86a9 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -412,6 +412,49 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( } +#ifdef OMASA_OBJ_REND_CLOSE +/*-------------------------------------------------------------------------* + * ivas_masa_ism_separate_object_renderer_close() + * + * Close structures, reserve memory, and init values. + *-------------------------------------------------------------------------*/ + +ivas_error ivas_masa_ism_separate_object_renderer_close( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t i; + if ( st_ivas->hMasaIsmData != NULL ) + { + if ( st_ivas->hMasaIsmData->delayBuffer != NULL ) + { + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { + if ( st_ivas->hMasaIsmData->delayBuffer[i] != NULL ) + { + free(st_ivas->hMasaIsmData->delayBuffer[i] ); + st_ivas->hMasaIsmData->delayBuffer[i] = NULL; + } + } + free( st_ivas->hMasaIsmData->delayBuffer ); + st_ivas->hMasaIsmData->delayBuffer = NULL; + } + } + if ( st_ivas->hIsmRendererData != NULL ) + { + if ( st_ivas->hIsmRendererData->interpolator != NULL ) + { + free( st_ivas->hIsmRendererData->interpolator ); + st_ivas->hIsmRendererData->interpolator = NULL; + } + free( st_ivas->hIsmRendererData ); + st_ivas->hIsmRendererData = NULL; + } + + return IVAS_ERR_OK; +} +#endif + /*-------------------------------------------------------------------------* * ivas_masa_ism_separate_object_render() * @@ -445,7 +488,7 @@ void ivas_masa_ism_separate_object_render( hVBAPdata = st_ivas->hVBAPdata; nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; hRendererData = st_ivas->hIsmRendererData; - lfe_index = st_ivas->hDirAC->hOutSetup.index_lfe[0]; + lfe_index = st_ivas->hDirACRend->hOutSetup.index_lfe[0]; subframe_len = output_frame / MAX_PARAM_SPATIAL_SUBFRAMES; if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) @@ -466,7 +509,7 @@ void ivas_masa_ism_separate_object_render( for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { idx_offset = block * subframe_len; - dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + dirac_read_idx = ( st_ivas->hSpatParamRendCom->dirac_read_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; if ( single_separated ) { @@ -491,12 +534,12 @@ void ivas_masa_ism_separate_object_render( } else { - ivas_dirac_dec_get_response( azimuth, elevation, gains, st_ivas->hDirAC->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response( azimuth, elevation, gains, st_ivas->hDirACRend->hOutSetup.ambisonics_order ); } for ( j = 0; j < nchan_out_woLFE; j++ ) { - if ( st_ivas->hDirAC->hOutSetup.num_lfe > 0 ) + if ( st_ivas->hDirACRend->hOutSetup.num_lfe > 0 ) { j2 = j + ( j >= lfe_index ); } @@ -519,7 +562,7 @@ void ivas_masa_ism_separate_object_render( } } - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % st_ivas->hDirAC->dirac_md_buffer_length; + st_ivas->hSpatParamRendCom->dirac_read_idx = ( st_ivas->hSpatParamRendCom->dirac_read_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; return; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 98b0672af3..e1a7a9cbd2 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -320,7 +320,7 @@ ivas_error ivas_jbm_dec_tc( { #ifdef FIX_564 /* loudness correction */ - ivas_dirac_dec_binaural_gain( output, nchan_remapped, output_frame ); + ivas_dirac_dec_binaural_sba_gain( output, nchan_remapped, output_frame ); #else float gain = 0.8414f; /* Todo: Temporary gain for roughly matching the loudness. To be tuned later together with other outputs. Also, this is not inline with ivas_dec() */ @@ -691,6 +691,7 @@ ivas_error ivas_jbm_dec_render( ivas_error error; float *p_output[MAX_OUTPUT_CHANNELS]; float *p_tc[MAX_TRANSPORT_CHANNELS]; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; error = IVAS_ERR_OK; @@ -700,6 +701,7 @@ ivas_error ivas_jbm_dec_render( * Initialization of local vars after struct has been set *----------------------------------------------------------------*/ + hSpatParamRendCom = st_ivas->hSpatParamRendCom; output_Fs = st_ivas->hDecoderConfig->output_Fs; nchan_out = st_ivas->hDecoderConfig->nchan_out; nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm; @@ -967,7 +969,7 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { - int16_t offset = st_ivas->hDirAC->slots_rendered * st_ivas->hDirAC->slot_size; + int16_t offset = hSpatParamRendCom->slots_rendered * hSpatParamRendCom->slot_size; nchan_remapped = st_ivas->nchan_transport; if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 1c9cc56417..a0d98f56dc 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -35,6 +35,7 @@ #include #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_rend.h" #include "ivas_rom_com.h" #include "ivas_stat_dec.h" #include "prot.h" @@ -323,7 +324,7 @@ ivas_error ivas_masa_decode( if ( st_ivas->hDirAC != NULL ) { *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, - st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hDirAC->dirac_bs_md_write_idx, st_ivas->hDirAC->dirac_md_buffer_length ); + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx, st_ivas->hSpatParamRendCom->dirac_md_buffer_length ); for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { @@ -334,7 +335,7 @@ ivas_error ivas_masa_decode( for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - meta_write_index = ( st_ivas->hDirAC->dirac_bs_md_write_idx + sf ) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx + sf ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->azimuth_ism[obj][meta_write_index]; st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = st_ivas->hMasaIsmData->elevation_ism[obj][meta_write_index]; } @@ -473,10 +474,9 @@ ivas_error ivas_masa_decode( { #ifdef MASA_AND_OBJECTS // Todo OMASA JBM: This might need adjustments - dirac_bs_md_write_idx = st_ivas->hDirAC->dirac_bs_md_write_idx; /* Store the write-index for this frame */ + dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ #endif - - ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, ivas_total_brate, ivas_format, 0, 0 ); + ivas_qmetadata_to_dirac( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0 ); } #ifdef MASA_AND_OBJECTS @@ -496,26 +496,26 @@ ivas_error ivas_masa_decode( int16_t block; int16_t meta_write_index; - for ( i = 0; i < st_ivas->hDirAC->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ + for ( i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { // Todo OMASA JBM: This might need adjustments - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { - st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][meta_write_index][b]; + st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][meta_write_index][b]; } } } for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) { - st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] = max( 0.0f, st_ivas->hDirAC->diffuseness_vector[meta_write_index][b] ); + st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = max( 0.0f, st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] ); } } } @@ -795,6 +795,7 @@ static ivas_error ivas_masa_dec_config( } #else ivas_masa_set_elements( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); + ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); #endif #ifdef MASA_AND_OBJECTS @@ -1291,10 +1292,13 @@ ivas_error ivas_masa_dec_reconfigure( /* renderer might have changed, reselect */ ivas_renderer_select( st_ivas ); -#ifdef OMASA_BRSW_MONO_FIX - if ( ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) && st_ivas->hDirAC == NULL ) +/* Todo: Check this */ +#if 0 && defined(OMASA_BRSW_MONO_FIX) /* TODO */ + if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || + ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) ) #else - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->hDirAC == NULL ) + if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || + ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) ) #endif { /* init a new DirAC dec */ @@ -1303,14 +1307,20 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } -#ifdef OMASA_BRSW_MONO_FIX - else if ( ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) && st_ivas->hDirAC != NULL ) +#if 0 && defined(OMASA_BRSW_MONO_FIX) + else if ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) #else - else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL ) + else if ( st_ivas->renderer_type == RENDERER_DISABLE ) #endif { - /* close unnecessary DirAC dec */ - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); + if ( st_ivas->hDirAC != NULL ) + { + /* close all unnecessary parametric decoding and rendering */ + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); + } } /* possible reconfigure is done later */ @@ -1329,6 +1339,15 @@ ivas_error ivas_masa_dec_reconfigure( sts = st_ivas->hSCE[sce_id]->hCoreCoder; sts[0]->bit_stream = bit_stream + num_bits; num_bits += (int16_t) ( st_ivas->hSCE[sce_id]->element_brate / FRAMES_PER_SEC ); + + /* TODO refactor merge: this is not in the pre-refactor version */ + if ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) + { + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + { + return error; + } + } } for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -1349,7 +1368,7 @@ ivas_error ivas_masa_dec_reconfigure( { st_ivas->hCPE[cpe_id]->nchan_out = 1; - if ( st_ivas->hDirAC != NULL ) + if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend != NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) ) { if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { @@ -1361,7 +1380,7 @@ ivas_error ivas_masa_dec_reconfigure( { st_ivas->hCPE[cpe_id]->nchan_out = CPE_CHANNELS; - if ( st_ivas->hDirAC != NULL ) + if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend != NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) ) { if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) { @@ -1370,6 +1389,7 @@ ivas_error ivas_masa_dec_reconfigure( } } } + if ( st_ivas->hDiracDecBin != NULL ) { /* regularization factor is bitrate-dependent */ @@ -1380,6 +1400,8 @@ ivas_error ivas_masa_dec_reconfigure( if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ { #endif +#if 1 + /* TODO refactor merge: do we need this or similar?*/ /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ @@ -1391,7 +1413,7 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } - +#endif /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ @@ -1494,18 +1516,20 @@ void ivas_spar_param_to_masa_param_mapping( int16_t slot_idx, slot_idx_start, sf; SPAR_DEC_HANDLE hSpar; float slot_fac; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; /* Set values */ hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; #ifdef MASA_AND_OBJECTS - hDirAC->numParametricDirections = 1; + hSpatParamRendCom->numParametricDirections = 1; #endif - hDirAC->numSimultaneousDirections = 1; - hDiffuseDist = st_ivas->hDirAC->hDiffuseDist; + hSpatParamRendCom->numSimultaneousDirections = 1; + hDiffuseDist = st_ivas->hDiracDecBin->hDiffuseDist; nchan_transport = st_ivas->nchan_transport; band_grouping = hDirAC->band_grouping; hSpar = st_ivas->hSpar; - dirac_write_idx = hDirAC->render_to_md_map[subframe]; + dirac_write_idx = hSpatParamRendCom->render_to_md_map[subframe]; /* Init arrays */ for ( i = 0; i < FOA_CHANNELS; i++ ) @@ -1590,7 +1614,7 @@ void ivas_spar_param_to_masa_param_mapping( set_zero( transportSignalEnergies[1], nBins ); set_zero( transportSignalCrossCorrelation, nBins ); - for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ ) + for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { for ( bin = 0; bin < nBins; bin++ ) { @@ -1650,13 +1674,13 @@ void ivas_spar_param_to_masa_param_mapping( ratio = I / fmaxf( 1e-12f, E ); /* Energy ratio */ ratio = fmaxf( 0.0f, fminf( 1.0f, ratio ) ); - hDirAC->azimuth[dirac_write_idx][bin] = (int16_t) roundf( azi / PI_OVER_180 ); - hDirAC->elevation[dirac_write_idx][bin] = (int16_t) roundf( ele / PI_OVER_180 ); - hDirAC->energy_ratio1[dirac_write_idx][bin] = ratio; - hDirAC->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio; + hSpatParamRendCom->azimuth[dirac_write_idx][bin] = (int16_t) roundf( azi / PI_OVER_180 ); + hSpatParamRendCom->elevation[dirac_write_idx][bin] = (int16_t) roundf( ele / PI_OVER_180 ); + hSpatParamRendCom->energy_ratio1[dirac_write_idx][bin] = ratio; + hSpatParamRendCom->diffuseness_vector[dirac_write_idx][bin] = 1.0f - ratio; - hDirAC->spreadCoherence[dirac_write_idx][bin] = 0.0f; - hDirAC->surroundingCoherence[dirac_write_idx][bin] = 0.0f; + hSpatParamRendCom->spreadCoherence[dirac_write_idx][bin] = 0.0f; + hSpatParamRendCom->surroundingCoherence[dirac_write_idx][bin] = 0.0f; /* Determine directional distribution of the indirect audio based on the SPAR mixing matrices (and the transport audio signals when 2 TC) */ if ( hDiffuseDist != NULL ) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 99b3ff6874..efdb0a8122 100755 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -82,7 +82,7 @@ ivas_error ivas_mcmasa_dec_reconfig( { if ( st_ivas->hDirAC == NULL ) { - if ( ( error = ivas_dirac_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } @@ -96,51 +96,5 @@ ivas_error ivas_mcmasa_dec_reconfig( } } - /*-------------------------------------------------------------------* - * Close binaural rendering handles and re-allocate proper ones - * in McMASA renderer_type can be only RENDERER_BINAURAL_PARAMETRIC, RENDERER_BINAURAL_PARAMETRIC_ROOM - *--------------------------------------------------------------------*/ - - if ( st_ivas->hBinRenderer != NULL ) - { - ivas_binRenderer_close( &st_ivas->hBinRenderer ); - } - - if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - /* open parametric binaural renderer */ - if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) - { - if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } - else if ( st_ivas->hDiracDecBin != NULL ) - { - if ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) - { - /* close unneeded renderer */ - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - } - else - { - /* if necessary, close/open td-decorrs */ - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) - { - return error; - } - - /* regularization factor is bitrate-dependent */ - st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); - } - } - return error; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 1350b9656c..e99cf63fa6 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -737,13 +737,13 @@ static ivas_error ivas_mc_dec_reconfig( st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; mvs2s( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - else if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->hDirAC != NULL ) + else if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered; - st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered; - mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv @@ -800,7 +800,9 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hDirAC != NULL ) { - ivas_dirac_dec_close( &st_ivas->hDirAC ); + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); } @@ -884,7 +886,9 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hDirAC != NULL ) { - ivas_dirac_dec_close( &st_ivas->hDirAC ); + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); + ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); } @@ -1115,6 +1119,8 @@ static ivas_error ivas_mc_dec_reconfig( } else if ( st_ivas->renderer_type == RENDERER_DISABLE && st_ivas->hDirAC != NULL ) { + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); @@ -1161,16 +1167,6 @@ static ivas_error ivas_mc_dec_reconfig( { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } - else - { - /* useTdDecorr may change => close and re-open */ - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } } /* init necessary new renderers */ @@ -1181,21 +1177,6 @@ static ivas_error ivas_mc_dec_reconfig( return error; } } - else if ( st_ivas->hDiracDecBin == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) - { - if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) - { - if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } else if ( st_ivas->hBinRendererTd == NULL && st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) { if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -1267,18 +1248,6 @@ static ivas_error ivas_mc_dec_reconfig( #endif } - /*-----------------------------------------------------------------* - * TD Decorrelator - *-----------------------------------------------------------------*/ - - if ( st_ivas->hDiracDecBin != NULL ) - { - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) - { - return error; - } - } - /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ @@ -1324,13 +1293,13 @@ static ivas_error ivas_mc_dec_reconfig( } /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hDirAC != NULL ) + if ( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } else if ( st_ivas->hParamMC != NULL ) { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b419da1b59..326fc64674 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -329,12 +329,19 @@ ivas_error ivas_omasa_dec_config( st_ivas->hHrtfTD = NULL; } +#ifdef OMASA_OBJ_REND_CLOSE + if ( ( error = ivas_masa_ism_separate_object_renderer_close( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else /* ISM renderer handle */ if ( st_ivas->hIsmRendererData != NULL ) { free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } +#endif } } @@ -355,12 +362,19 @@ ivas_error ivas_omasa_dec_config( } else { +#ifdef OMASA_OBJ_REND_CLOSE + if ( ( error = ivas_masa_ism_separate_object_renderer_close( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } +#else /* ISM renderer handle */ if ( st_ivas->hIsmRendererData != NULL ) { free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } +#endif } } @@ -368,6 +382,8 @@ ivas_error ivas_omasa_dec_config( * TD Decorrelator *-----------------------------------------------------------------*/ +#if 1 + /* TODO: executed already in ivas_masa_dec_reconfigure */ if ( st_ivas->hDiracDecBin != NULL ) { if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) @@ -384,6 +400,7 @@ ivas_error ivas_omasa_dec_config( { return error; } +#endif } return IVAS_ERR_OK; @@ -526,7 +543,7 @@ ivas_error ivas_omasa_ism_metadata_dec( for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; st_ivas->hMasaIsmData->azimuth_ism[n][meta_write_index] = azimuth_ism; st_ivas->hMasaIsmData->elevation_ism[n][meta_write_index] = elevation_ism; } @@ -539,7 +556,7 @@ ivas_error ivas_omasa_ism_metadata_dec( for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hDirAC->dirac_md_buffer_length; + meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; st_ivas->hMasaIsmData->azimuth_separated_ism[meta_write_index] = azimuth_ism; st_ivas->hMasaIsmData->elevation_separated_ism[meta_write_index] = elevation_ism; } @@ -579,11 +596,11 @@ void ivas_omasa_dirac_rend( } } - dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; + dirac_read_idx = st_ivas->hSpatParamRendCom->dirac_read_idx; ivas_dirac_dec( st_ivas, output, st_ivas->nchan_transport ); - st_ivas->hDirAC->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ + st_ivas->hSpatParamRendCom->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index fb97faf0de..763a1b222f 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -65,7 +65,7 @@ void ivas_sba_set_cna_cng_flag( /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */ /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */ } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; @@ -114,8 +114,6 @@ ivas_error ivas_sba_dec_reconfigure( int16_t num_channels, num_md_sub_frames; #endif - RENDERER_TYPE old_renderer_type; - DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; error = IVAS_ERR_OK; @@ -147,13 +145,13 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered; mvs2s( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - else if ( st_ivas->hDirAC != NULL ) + else if ( st_ivas->hSpatParamRendCom != NULL ) { - st_ivas->hTcBuffer->num_slots = st_ivas->hDirAC->num_slots; - st_ivas->hTcBuffer->nb_subframes = st_ivas->hDirAC->nb_subframes; - st_ivas->hTcBuffer->slots_rendered = st_ivas->hDirAC->slots_rendered; - st_ivas->hTcBuffer->subframes_rendered = st_ivas->hDirAC->subframes_rendered; - mvs2s( st_ivas->hDirAC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /*-----------------------------------------------------------------* @@ -240,7 +238,6 @@ ivas_error ivas_sba_dec_reconfigure( /* renderer might have changed */ intern_config_old = st_ivas->intern_config; - old_renderer_type = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); /* side effect of the renderer selection can be a changed internal config */ @@ -293,29 +290,6 @@ ivas_error ivas_sba_dec_reconfigure( #endif } - if ( st_ivas->renderer_type != old_renderer_type ) - { - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - if ( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) - { - if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } - - if ( ( error = ivas_dirac_dec_init_binaural_data( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) - { - return error; - } - } - } - else if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - } - if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != AUDIO_CONFIG_MONO ) ) || ( last_ivas_total_brate > IVAS_256k && ivas_total_brate <= IVAS_256k ) || ( last_ivas_total_brate <= IVAS_256k && ivas_total_brate > IVAS_256k ) ) { DIRAC_CONFIG_FLAG flag_config; @@ -332,11 +306,14 @@ ivas_error ivas_sba_dec_reconfigure( } /* synchronize subframe info */ - st_ivas->hDirAC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hDirAC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hDirAC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - st_ivas->hDirAC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hDirAC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } } if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) ) != IVAS_ERR_OK ) @@ -346,6 +323,8 @@ ivas_error ivas_sba_dec_reconfigure( if ( st_ivas->renderer_type == RENDERER_DISABLE ) { + ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); vbap_free_data( &( st_ivas->hVBAPdata ) ); @@ -424,7 +403,7 @@ ivas_error ivas_sba_dec_reconfigure( } else { - if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) { tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/ } @@ -531,9 +510,11 @@ void ivas_sba_dec_render( uint16_t slot_size, ch; uint16_t nchan_internal, nchan_out; SPAR_DEC_HANDLE hSpar; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; float *output_f_local[MAX_OUTPUT_CHANNELS]; hSpar = st_ivas->hSpar; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; @@ -582,11 +563,11 @@ void ivas_sba_dec_render( { if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; } else { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; } } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 79ed6c7cf3..dd8fbdc851 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -325,7 +325,7 @@ ivas_error ivas_spar_dec( /* read DirAC bitstream */ if ( st_ivas->hQMetaData != NULL ) { - ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hQMetaData, nb_bits_read, + ivas_dirac_dec_read_BS( hDecoderConfig->ivas_total_brate, st0, st_ivas->hDirAC, st_ivas->hSpatParamRendCom, st_ivas->hQMetaData, nb_bits_read, ivas_get_hodirac_flag( hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ), st_ivas->hSpar->dirac_to_spar_md_bands ); } @@ -1313,6 +1313,7 @@ void ivas_spar_dec_upmixer( ) { SPAR_DEC_HANDLE hSpar; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; int16_t nchan_transport, nchan_out; int16_t subframe_idx, n, i; int16_t n_samples_sf; @@ -1392,15 +1393,16 @@ void ivas_spar_dec_upmixer( st_ivas->hTcBuffer->tc[n] = NULL; } - if ( st_ivas->hDirAC != 0 ) + if ( st_ivas->hDirAC != NULL && st_ivas->hSpatParamRendCom != NULL ) { + hSpatParamRendCom = st_ivas->hSpatParamRendCom; if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; } else { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; } } @@ -1689,7 +1691,7 @@ void ivas_spar_dec_upmixer_sf( if ( ( st_ivas->hOutSetup.num_lfe > 0 ) && ( st_ivas->hOutSetup.index_lfe[idx_lfe] == ch ) ) { set_zero( output[ch], hSpar->subframe_nbslots[hSpar->subframes_rendered] * num_cldfb_bands ); - if ( idx_lfe < ( st_ivas->hDirAC->hOutSetup.num_lfe - 1 ) ) + if ( idx_lfe < ( st_ivas->hDirACRend->hOutSetup.num_lfe - 1 ) ) { idx_lfe++; } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index a1d3e98392..c61effd673 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -3051,6 +3051,9 @@ void ivas_spar_to_dirac( end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ) / bw; hDirAC = st_ivas->hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; @@ -3145,46 +3148,46 @@ void ivas_spar_to_dirac( { int16_t ts_start, ts_end, ts; - ts_start = hDirAC->block_grouping[block]; - ts_end = hDirAC->block_grouping[block + 1]; + ts_start = DirAC_block_grouping[block]; + ts_end = DirAC_block_grouping[block + 1]; for ( b = qmf_band_start; b < qmf_band_end; b++ ) { azi_dith = azi[band]; ele_dith = ele[band]; - hDirAC->energy_ratio1[block][b] = en_ratio; + hSpatParamRendCom->energy_ratio1[block][b] = en_ratio; tmp_write_idx_band = tmp_write_idx_param_band; if ( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->elevation[tmp_write_idx_band][b] = ele_dith; - hDirAC->azimuth[tmp_write_idx_band][b] = azi_dith; - hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; } else { for ( ts = ts_start; ts < ts_end; ts++ ) { - hDirAC->elevation[tmp_write_idx_band][b] = ele_dith; - hDirAC->azimuth[tmp_write_idx_band][b] = azi_dith; - hDirAC->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; - tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + tmp_write_idx_band = ( tmp_write_idx_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } } } - tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hDirAC->dirac_md_buffer_length; + tmp_write_idx_param_band = ( tmp_write_idx_param_band + num_slots_in_subfr ) % hSpatParamRendCom->dirac_md_buffer_length; } } /* update buffer write index */ if ( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; } else { - hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hDirAC->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = ( hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; } } else diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index d5144018e5..4706c6d89b 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -396,40 +396,9 @@ typedef struct } ISM_DTX_DATA_DEC; /*----------------------------------------------------------------------------------* - * DirAC decoder structure + * DirAC decoder structures *----------------------------------------------------------------------------------*/ -typedef struct dirac_dec_stack_mem -{ - /*Decorrelator*/ - float *frame_dec_f; - - /*Prototypes*/ - float *proto_direct_buffer_f; - float *proto_diffuse_buffer_f; - - /*Prototype NRGs*/ - float *proto_power_smooth; - float *proto_power_diff_smooth; - - /*Gain or power factors for directional and diffuse streams*/ - float *direct_power_factor; - float *diffuse_power_factor; - - /*Directional responses (gains & Nrg)*/ - float *direct_responses; - float *direct_responses_square; - - /* Target co-variance mtx */ - float *cy_auto_dir_smooth; - float *cy_cross_dir_smooth; - float *cy_auto_diff_smooth; - - float *reference_power; - float *onset_filter; - -} DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE; - typedef struct param_ism_rendering { float *proto_matrix; @@ -442,115 +411,32 @@ typedef struct param_ism_rendering } PARAM_ISM_RENDERING_DATA, *PARAM_ISM_RENDERING_HANDLE; -/*Onset detector*/ -typedef struct dirac_onset_detection_params_structure -{ - int16_t num_freq_bands; - int16_t max_band_decorr; - -} DIRAC_ONSET_DETECTION_PARAMS; - -typedef struct dirac_onset_detection_state_structure -{ - float *onset_detector_1; - float *onset_detector_2; - -} DIRAC_ONSET_DETECTION_STATE; - -/*Decorrelator*/ -typedef struct dirac_decorr_params_structure -{ - int16_t max_band_decorr; - int16_t max_frequency; - - int16_t *pre_delay; - int16_t *filter_length; - float *filter_coeff_num_real; - float *filter_coeff_den_real; - float *phase_coeff_real; - float *phase_coeff_imag; - int16_t *split_frequency_bands; - int16_t num_split_frequency_bands; - - int16_t use_ducker; - int16_t add_back_onsets_on; - - DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params; - -} DIRAC_DECORR_PARAMS, *HANDLE_DIRAC_DECORR_PARAMS; - -typedef struct dirac_decorr_state_structure -{ - float *decorr_buffer; - float *direct_energy_smooth; - float *reverb_energy_smooth; - - DIRAC_ONSET_DETECTION_STATE h_onset_detection_power_state; - -} DIRAC_DECORR_STATE, *HANDLE_DIRAC_DECORR_STATE; - -/*Output synthesis*/ -typedef struct dirac_output_synthesis_params_structure -{ - int16_t max_band_decorr; - - int16_t use_onset_filters; - - float *interpolator; - float *alpha_synthesis; - float *alpha_synthesis_fast; - int16_t numAlphas; - int16_t numAlphasFast; - - float *proto_matrix; - - float diffuse_compensation_factor; - float diffuse_compensation_factor_decorr; - -} DIRAC_OUTPUT_SYNTHESIS_PARAMS; - -typedef struct dirac_output_synthesis_state_structure +/* ===== DirAC main structure ===== */ +typedef struct ivas_dirac_dec_data_structure { - /* only pointer to local buffers */ - float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ - float *direct_responses_square; - float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ - - /* only pointer to local buffers */ - float *direct_power_factor; - float *diffuse_power_factor; - - float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ - float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ - - float *proto_power_diff_smooth; - float *proto_power_diff_smooth_prev; + DIRAC_CONFIG_DATA_HANDLE hConfig; - /* only pointer to local buffers */ - float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + /*Parameter decoding*/ + float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; + float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; + int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; - /* Output gain memories */ - float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ - float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ + int16_t dithering_seed; + int16_t spar_to_dirac_write_idx; - /* only pointer to local buffers */ - float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + /*sub-modules*/ + PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */ + float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; + PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; - /* PSD memories */ - float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ - float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + IVAS_FB_MIXER_HANDLE hFbMdft; - const float *onset_filter; +} DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE; - /* Temporal smoothing memories */ - float *reference_power_smooth_prev; - float *direction_smoothness_prev; -} DIRAC_OUTPUT_SYNTHESIS_STATE; +/*----------------------------------------------------------------------------------* + * ParamMC structures + *----------------------------------------------------------------------------------*/ typedef struct dirac_output_synthesis_cov_state_structure { @@ -579,160 +465,6 @@ typedef struct dirac_output_synthesis_cov_state_structure } DIRAC_OUTPUT_SYNTHESIS_COV_STATE; -/* MASA stereo transport signal type detection structure */ -typedef struct -{ - MASA_TRANSPORT_SIGNAL_TYPE masa_stereo_type; - MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type; - MASA_TRANSPORT_SIGNAL_TYPE type_change_direction; - - int16_t dipole_freq_range[2]; - - float left_bb_power; - float right_bb_power; - float total_bb_power; - - float left_hi_power; - float right_hi_power; - float total_hi_power; - - float sum_power[MASA_SUM_FREQ_RANGE_BINS]; - float total_power[MASA_SUM_FREQ_RANGE_BINS]; - - float subtract_power_y; - float subtract_power_y_smooth; - float target_power_y_smooth; - - float lr_total_bb_ratio_db; - float lr_total_hi_ratio_db; - float min_sum_total_ratio_db; - float subtract_target_ratio_db; - - int16_t counter; - int16_t interpolator; - -} MASA_STEREO_TYPE_DETECT; - -/* Diffuse sound directional distribution data structure */ -typedef struct ivas_diffuse_distribution_data_structure -{ - float diffuseRatioX[CLDFB_NO_CHANNELS_MAX]; - float diffuseRatioY[CLDFB_NO_CHANNELS_MAX]; - float diffuseRatioZ[CLDFB_NO_CHANNELS_MAX]; - -} DIFFUSE_DISTRIBUTION_DATA, *DIFFUSE_DISTRIBUTION_HANDLE; - - -/* ===== DirAC main structure ===== */ -typedef struct ivas_dirac_dec_data_structure -{ - DIRAC_CONFIG_DATA_HANDLE hConfig; - IVAS_OUTPUT_SETUP hOutSetup; - - int16_t slot_size; - int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; - int16_t subframes_rendered; - int16_t slots_rendered; - int16_t num_slots; - int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; - int16_t nb_subframes; - int16_t num_freq_bands; - - /*Parameter decoding*/ - float azimuth_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; - float elevation_values[MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS]; - int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; - - int16_t block_grouping[5]; - /* decoded, ungrouped and rounded values, we have 1 degree resolution anyway */ - int16_t **azimuth; - int16_t **elevation; - int16_t **azimuth2; - int16_t **elevation2; - - float **diffuseness_vector; - float **energy_ratio1; - float **energy_ratio2; - - float **spreadCoherence; - float **spreadCoherence2; - float **surroundingCoherence; - - int16_t dithering_seed; - int16_t dirac_bs_md_write_idx; - int16_t dirac_read_idx; - int16_t dirac_estimator_idx; - int16_t spar_to_dirac_write_idx; - int16_t dirac_md_buffer_length; - -#ifdef MASA_AND_OBJECTS - int16_t numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ - int16_t numParametricDirections; /* 1 or 2 */ - int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ -#else - int16_t numSimultaneousDirections; /* 1 or 2 */ -#endif - DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; - - /*Parameter estimation*/ - int16_t index_buffer_intensity; - float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; - float *buffer_energy; - - /*Decoder parameters */ - /*Prototypes*/ - int16_t num_outputs_dir; - int16_t num_outputs_diff; - int16_t num_protos_dir; - int16_t num_protos_diff; - int16_t num_protos_ambi; - DIRAC_SYNTHESIS_CONFIG synthesisConf; - DIRAC_PANNING_CONFIG panningConf; - - float *frequency_axis; - float *diffuse_response_function; - float *hoa_encoder; - const float *hoa_decoder; - - /*Options*/ - /* Decorrelator options */ - int16_t max_band_decorr; - - /* prototype computing */ - int16_t *proto_index_dir; - int16_t *proto_index_diff; - - int16_t proto_signal_decorr_on; - - /*Decoder states=memories*/ - float *proto_frame_f; - float *proto_frame_dec_f; - - DIRAC_DEC_STACK_MEM stack_mem; - MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect; - - int16_t num_ele_spk_no_diffuse_rendering; - - /*sub-modules*/ - HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params; - HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state; - - DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params; - DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state; - - PARAM_ISM_CONFIG_HANDLE hParamIsm; /* Parametric ISM handle */ - float power_ratios[MAX_PARAM_ISM_NBANDS][MAX_PARAM_ISM_NBLOCKS][MAX_PARAM_ISM_WAVE]; - PARAM_ISM_RENDERING_HANDLE hParamIsmRendering; - IVAS_FB_MIXER_HANDLE hFbMdft; - const int16_t *sba_map_tc; - -} DIRAC_DEC_DATA, *DIRAC_DEC_HANDLE; - - -/*----------------------------------------------------------------------------------* - * ParamMC structures - *----------------------------------------------------------------------------------*/ - typedef struct ivas_param_mc_diff_proto_info_structure { int16_t num_protos_diff; @@ -1037,53 +769,6 @@ typedef struct ivas_lfe_dec_data_structure } LFE_DEC_DATA, *LFE_DEC_HANDLE; -// Note: the following structures are used only in lib_dec but this would likely change in the future -/*----------------------------------------------------------------------------------* - * VBAP structures - *----------------------------------------------------------------------------------*/ - -/* Defines a single virtual surface triplet of loudspeakers - * with a precalculated inverse matrix */ -typedef struct vbap_vs_triplet_structure -{ - uint8_t speaker_node[3]; - float inverse_matrix[3][3]; - -} VBAP_VS_TRIPLET; - - -/* Storage structure for fast runtime triplet search */ -typedef struct triplet_search_structure -{ - VBAP_VS_TRIPLET *triplets; - int16_t num_triplets; - int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; - -} VBAP_SEARCH_STRUCT; - - -/* VBAP data structure. Contains the formed virtual surface arrangement * and supporting data. */ -typedef struct vbap_data_structure -{ - VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */ - int16_t num_search_structs; - int16_t num_speaker_nodes; - int16_t num_speaker_nodes_internal; - int16_t top_virtual_speaker_node_index; /* These indices can be negative */ - int16_t bottom_virtual_speaker_node_index; - int16_t back_virtual_speaker_node_index; - float *bottom_virtual_speaker_node_division_gains; - float *top_virtual_speaker_node_division_gains; - float *back_virtual_speaker_node_division_gains; -#ifdef MASA_AND_OBJECTS - float *object_mode_bottom_virtual_speaker_node_division_gains; - float *object_mode_top_virtual_speaker_node_division_gains; - float *object_mode_back_virtual_speaker_node_division_gains; -#endif - -} VBAP_DATA, *VBAP_HANDLE; - - /*----------------------------------------------------------------------------------* * renderer structures *----------------------------------------------------------------------------------*/ @@ -1128,39 +813,6 @@ typedef struct ivas_binaural_rendering_struct * MASA decoder structures *----------------------------------------------------------------------------------*/ -/* McMASA LFE synthesis structure */ -typedef struct ivas_mcmasa_lfe_synth_struct -{ - float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t lfeGainPrevIndex; - float transportEneSmooth; - float protoLfeEneSmooth; - float targetEneLfeSmooth; - float targetEneTransSmooth; - - float *lfeSynthRingBuffer; - int16_t ringBufferLoPointer; - int16_t ringBufferHiPointer; - float lowpassSum; - int16_t ringBufferSize; - - float *lfeSynthRingBuffer2; - int16_t ringBufferLoPointer2; - float lowpassSum2; - int16_t ringBufferSize2; - - float *delayBuffer_syncLp; - int16_t delayBuffer_syncLp_size; - - float *delayBuffer_syncDirAC; - int16_t delayBuffer_syncDirAC_size; - - float lfeGainPrev; - float transportGainPrev; - float interpolator[CLDFB_NO_CHANNELS_MAX]; - -} MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE; - typedef struct ivas_masa_decoder_ext_out_meta_struct { MASA_DECRIPTIVE_META descriptiveMeta; @@ -1393,19 +1045,20 @@ typedef struct Decoder_Struct MONO_DOWNMIX_RENDERER_HANDLE hMonoDmxRenderer; /* Mono downmix structure */ CREND_WRAPPER_HANDLE hCrendWrapper; /* Crend handle */ REVERB_HANDLE hReverb; /* Reverb handle */ - HRTFS_CREND_HANDLE hSetOfHRTF; /* Set of HRTFs handle (CRend) */ + HRTFS_CREND_HANDLE hSetOfHRTF; /* Set of HRTFs handle (CRend) */ HRTFS_FASTCONV_HANDLE hHrtfFastConv; /* FASTCONV HRTF tables for binaural rendering */ HRTFS_PARAMBIN_HANDLE hHrtfParambin; /* HRTF tables for parametric binauralizer */ LSSETUP_CUSTOM_HANDLE hLsSetupCustom; /* Custom LS configuration handle */ float *hoa_dec_mtx; /* Pointer to decoder matrix for SBA */ HEAD_TRACK_DATA_HANDLE hHeadTrackData; /* Head tracking data structure */ RENDER_CONFIG_DATA *hRenderConfig; /* Renderer config pointer */ - int32_t binaural_latency_ns; /* binauralization latency in ns */ -#ifdef MASA_AND_OBJECTS - MASA_ISM_DATA_HANDLE hMasaIsmData; /* MASA_ISM rendering structure */ + int32_t binaural_latency_ns; /* Binauralization latency in ns */ EXTERNAL_ORIENTATION_HANDLE hExtOrientationData; /* External orientation data structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData; /* Combined external and head orientation data structure */ - + DIRAC_REND_HANDLE hDirACRend; /* DirAC renderer handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; /* Spatial parametric (DirAC rend, ParamBin, ParamISM) rendering common data handle. */ +#ifdef MASA_AND_OBJECTS + MASA_ISM_DATA_HANDLE hMasaIsmData; /* MASA_ISM rendering structure */ uint8_t editing_ism_enabled; /* Todo Nokia: Temporary, used until proper ISM control available */ int16_t index_of_edited_ism; /* Todo Nokia: Temporary, used until proper ISM control available */ int16_t azimuth_edited; /* Todo Nokia: Temporary, used until proper ISM control available */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 5ca721b331..7e30145256 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -82,6 +82,20 @@ typedef struct hrtfGainCache float shVec[HRTF_SH_CHANNELS]; } PARAMBIN_HRTF_GAIN_CACHE; +typedef struct parambin_rend_config_data +{ + int16_t separateCenterChannelRendering; + IVAS_FORMAT ivas_format; + MC_MODE mc_mode; + int32_t ivas_total_brate; + int16_t nchan_transport; + float qualityBasedSmFactor; + int16_t processReverb; +#ifdef MASA_AND_OBJECTS + ISM_MODE ism_mode; +#endif +} PARAMBIN_REND_CONFIG, *PARAMBIN_REND_CONFIG_HANDLE; + /*------------------------------------------------------------------------- * Local function prototypes @@ -89,13 +103,21 @@ typedef struct hrtfGainCache static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t nchan_transport, const int16_t subframe ); -static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_HANDLE hDirAC, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] ); +static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const int16_t num_freq_bands, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] ); -static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked ); +#ifdef MASA_AND_OBJECTS +static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const MASA_ISM_DATA_HANDLE hMasaIsmData ); +#else +static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked ); +#endif -static void ivas_dirac_dec_binaural_determine_processing_matrices( Decoder_Struct *st_ivas, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked ); +#ifdef MASA_AND_OBJECTS +static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); +#else +static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked ); +#endif -static void ivas_dirac_dec_binaural_process_output( Decoder_Struct *st_ivas, float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t subframe ); +static void ivas_dirac_dec_binaural_process_output( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, const int16_t processReverb, const int16_t subframe ); static void adaptTransportSignalsHeadtracked( COMBINED_ORIENTATION_HANDLE hHeadTrackData, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t nSlots, float Rmat[3][3] ); @@ -112,40 +134,46 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); +// Todo Tapani refactor: Create separate init & render functions for MASA external renderer. The decoder versions would become too complex if generalized. + /*------------------------------------------------------------------------- * ivas_dirac_dec_init_binaural_data() * * Initialize parametric binaural renderer *------------------------------------------------------------------------*/ +// Todo Tapani refactor: To be moved to lib_dec ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ ) { - DIRAC_DEC_BIN_HANDLE hBinaural; + DIRAC_DEC_BIN_HANDLE hDiracDecBin; int16_t nBins; int32_t output_Fs; RENDERER_TYPE renderer_type; int16_t j, k, bin; float binCenterFreq, tmpFloat; ivas_error error; + float frequency_axis[CLDFB_NO_CHANNELS_MAX]; - hBinaural = st_ivas->hDiracDecBin; + hDiracDecBin = st_ivas->hDiracDecBin; - if ( hBinaural == NULL ) + if ( hDiracDecBin == NULL ) { - if ( ( hBinaural = (DIRAC_DEC_BIN_HANDLE) malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) + if ( ( hDiracDecBin = (DIRAC_DEC_BIN_HANDLE) malloc( sizeof( DIRAC_DEC_BIN_DATA ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC binaural handle " ); } - hBinaural->hTdDecorr = NULL; - hBinaural->hReverb = NULL; + hDiracDecBin->hTdDecorr = NULL; + hDiracDecBin->hReverb = NULL; + hDiracDecBin->h_freq_domain_decorr_ap_params = NULL; + hDiracDecBin->h_freq_domain_decorr_ap_state = NULL; } - nBins = st_ivas->hDirAC->num_freq_bands; output_Fs = st_ivas->hDecoderConfig->output_Fs; + nBins = st_ivas->hSpatParamRendCom->num_freq_bands; renderer_type = st_ivas->renderer_type; for ( j = 0; j < BINAURAL_CHANNELS; j++ ) @@ -156,23 +184,23 @@ ivas_error ivas_dirac_dec_init_binaural_data( for ( k = 0; k < BINAURAL_CHANNELS + 1; k++ ) #endif { - set_zero( hBinaural->processMtxRe[j][k], nBins ); - set_zero( hBinaural->processMtxIm[j][k], nBins ); + set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); + set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); } for ( k = 0; k < BINAURAL_CHANNELS; k++ ) { - set_zero( hBinaural->processMtxDecRe[j][k], nBins ); - set_zero( hBinaural->processMtxDecIm[j][k], nBins ); + set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins ); + set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins ); } - set_zero( hBinaural->ChEnePrev[j], nBins ); - set_zero( hBinaural->ChEneOutPrev[j], nBins ); + set_zero( hDiracDecBin->ChEnePrev[j], nBins ); + set_zero( hDiracDecBin->ChEneOutPrev[j], nBins ); } - set_zero( hBinaural->ChCrossRePrev, nBins ); - set_zero( hBinaural->ChCrossImPrev, nBins ); - set_zero( hBinaural->ChCrossReOutPrev, nBins ); - set_zero( hBinaural->ChCrossImOutPrev, nBins ); - hBinaural->renderStereoOutputInsteadOfBinaural = 0; + set_zero( hDiracDecBin->ChCrossRePrev, nBins ); + set_zero( hDiracDecBin->ChCrossImPrev, nBins ); + set_zero( hDiracDecBin->ChCrossReOutPrev, nBins ); + set_zero( hDiracDecBin->ChCrossImOutPrev, nBins ); + hDiracDecBin->renderStereoOutputInsteadOfBinaural = 0; for ( bin = 0; bin < nBins; bin++ ) @@ -180,35 +208,35 @@ ivas_error ivas_dirac_dec_init_binaural_data( binCenterFreq = ( (float) bin + CLDFB_HALF_BIN_FREQUENCY_OFFSET ) / (float) nBins * ( (float) output_Fs / 2.0f ); /* These formulas and values are from Christian Borss's publication for binaural diffuse field coherence */ tmpFloat = max( 0.0f, 1.0f - binCenterFreq / 2700.0f ); - hBinaural->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f ); + hDiracDecBin->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f ); } for ( bin = 0; bin < BINAURAL_COHERENCE_DIFFERENCE_BINS; bin++ ) { - hBinaural->diffuseFieldCoherenceX[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin]; - hBinaural->diffuseFieldCoherenceY[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin]; - hBinaural->diffuseFieldCoherenceZ[bin] = hBinaural->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin]; + hDiracDecBin->diffuseFieldCoherenceX[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin]; + hDiracDecBin->diffuseFieldCoherenceY[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin]; + hDiracDecBin->diffuseFieldCoherenceZ[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin]; } if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC ) /* Indication of binaural rendering without room effect */ { - set_f( hBinaural->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); - hBinaural->hReverb = NULL; + set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->hReverb = NULL; } else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */ { - mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hBinaural->earlyPartEneCorrection, nBins ); + mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection, nBins ); /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ - if ( hBinaural->hReverb != NULL && ( ( hBinaural->hReverb->numBins != nBins ) || - ( hBinaural->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) + if ( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) || + ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) { - ivas_binaural_reverb_close( &( hBinaural->hReverb ) ); + ivas_binaural_reverb_close( &( hDiracDecBin->hReverb ) ); } - if ( hBinaural->hReverb == NULL ) + if ( hDiracDecBin->hReverb == NULL ) { - if ( ( error = ivas_binaural_reverb_open( &hBinaural->hReverb, + if ( ( error = ivas_binaural_reverb_open( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, st_ivas->hIntSetup.output_config, @@ -223,28 +251,52 @@ ivas_error ivas_dirac_dec_init_binaural_data( } else if ( renderer_type == RENDERER_STEREO_PARAMETRIC ) { - set_f( hBinaural->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); - hBinaural->hReverb = NULL; - hBinaural->renderStereoOutputInsteadOfBinaural = 1; + set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->hReverb = NULL; + hDiracDecBin->renderStereoOutputInsteadOfBinaural = 1; } else /* Not valid renderer type for this renderer */ { assert( false ); } - if ( hBinaural->hTdDecorr == NULL ) + hDiracDecBin->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */ + + if ( hDiracDecBin->hTdDecorr == NULL ) + { + hDiracDecBin->useTdDecorr = 0; + } + + if ( hDiracDecBin->h_freq_domain_decorr_ap_params != NULL ) { - hBinaural->useTdDecorr = 0; + ivas_dirac_dec_decorr_close( &hDiracDecBin->h_freq_domain_decorr_ap_params, &hDiracDecBin->h_freq_domain_decorr_ap_state ); } - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hBinaural->hTdDecorr ), &( hBinaural->useTdDecorr ) ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hDiracDecBin->hTdDecorr ), &( hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) { return error; } - hBinaural->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); + if ( !hDiracDecBin->useTdDecorr && !( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) + { + ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, nBins ); + if ( ( error = ivas_dirac_dec_decorr_open( &( hDiracDecBin->h_freq_domain_decorr_ap_params ), + &( hDiracDecBin->h_freq_domain_decorr_ap_state ), + nBins, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, + frequency_axis, + BINAURAL_CHANNELS, + output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); - st_ivas->hDiracDecBin = hBinaural; + st_ivas->hDiracDecBin = hDiracDecBin; /* allocate transport channels*/ if ( st_ivas->hDecoderConfig->voip_active == 1 && st_ivas->hTcBuffer == NULL ) @@ -283,6 +335,10 @@ void ivas_dirac_dec_close_binaural_data( } ivas_td_decorr_dec_close( &( ( *hBinaural )->hTdDecorr ) ); + if ( ( *hBinaural )->h_freq_domain_decorr_ap_params != NULL ) + { + ivas_dirac_dec_decorr_close( &( *hBinaural )->h_freq_domain_decorr_ap_params, &( *hBinaural )->h_freq_domain_decorr_ap_state ); + } free( *hBinaural ); *hBinaural = NULL; @@ -343,6 +399,7 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( * *------------------------------------------------------------------------*/ +// Todo Tapani refactor: To be moved to lib_dec void ivas_dirac_dec_binaural_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -355,13 +412,13 @@ void ivas_dirac_dec_binaural_render( int16_t slots_to_render, first_sf, last_sf, subframe_idx; uint16_t slot_size, ch; uint16_t nchan_out; - DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; float *output_f_local[MAX_OUTPUT_CHANNELS]; - hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_out = BINAURAL_CHANNELS; #ifdef DEBUGGING - assert( hDirAC ); + assert( hSpatParamRendCom ); #endif for ( ch = 0; ch < nchan_out; ch++ ) { @@ -370,14 +427,14 @@ void ivas_dirac_dec_binaural_render( slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( hDirAC->num_slots - hDirAC->slots_rendered, nSamplesAsked / slot_size ); + slots_to_render = min( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered, nSamplesAsked / slot_size ); *nSamplesRendered = slots_to_render * slot_size; - first_sf = hDirAC->subframes_rendered; + first_sf = hSpatParamRendCom->subframes_rendered; last_sf = first_sf; while ( slots_to_render > 0 ) { - slots_to_render -= hDirAC->subframe_nbslots[last_sf]; + slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf]; last_sf++; } @@ -386,7 +443,7 @@ void ivas_dirac_dec_binaural_render( #endif for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - int16_t n_samples_sf = slot_size * hDirAC->subframe_nbslots[subframe_idx]; + int16_t n_samples_sf = slot_size * hSpatParamRendCom->subframe_nbslots[subframe_idx]; ivas_dirac_dec_binaural_internal( st_ivas, st_ivas->hCombinedOrientationData, output_f_local, nchan_transport, subframe_idx ); for ( ch = 0; ch < nchan_out; ch++ ) { @@ -394,12 +451,12 @@ void ivas_dirac_dec_binaural_render( } } - if ( hDirAC->slots_rendered == hDirAC->num_slots ) + if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; } - *nSamplesAvailable = ( hDirAC->num_slots - hDirAC->slots_rendered ) * slot_size; + *nSamplesAvailable = ( hSpatParamRendCom->num_slots - hSpatParamRendCom->slots_rendered ) * slot_size; return; } @@ -407,12 +464,13 @@ void ivas_dirac_dec_binaural_render( #ifdef FIX_564 /*------------------------------------------------------------------------- - * ivas_dirac_dec_binaural_gain() + * ivas_dirac_dec_binaural_sba_gain() * * loudness correction for parametric binaural renderer *------------------------------------------------------------------------*/ -void ivas_dirac_dec_binaural_gain( +// Todo Tapani refactor: To be moved to lib_dec +void ivas_dirac_dec_binaural_sba_gain( float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ const int16_t output_frame /* i : output frame length */ @@ -446,6 +504,7 @@ void ivas_dirac_dec_binaural_gain( * Parametric binaural renderer main function *------------------------------------------------------------------------*/ +// Todo Tapani refactor: To be moved to lib_dec void ivas_dirac_dec_binaural( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ @@ -454,11 +513,13 @@ void ivas_dirac_dec_binaural( ) { int16_t subframe; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; float cng_td_buffer[L_FRAME16k]; float *p_output[MAX_OUTPUT_CHANNELS]; int16_t ch; int16_t slot_size; int16_t numInChannels; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); for ( ch = 0; ch < 2 * BINAURAL_CHANNELS; ch++ ) @@ -517,7 +578,7 @@ void ivas_dirac_dec_binaural( for ( subframe = 0; subframe < MAX_PARAM_SPATIAL_SUBFRAMES; subframe++ ) { - int16_t n_samples_sf = slot_size * st_ivas->hDirAC->subframe_nbslots[subframe]; + int16_t n_samples_sf = slot_size * hSpatParamRendCom->subframe_nbslots[subframe]; ivas_dirac_dec_binaural_internal( st_ivas, hCombinedOrientationData, p_output, nchan_transport, subframe ); @@ -525,7 +586,7 @@ void ivas_dirac_dec_binaural( { p_output[ch] += n_samples_sf; } - st_ivas->hDirAC->dirac_read_idx = ( st_ivas->hDirAC->dirac_read_idx + 1 ) % st_ivas->hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } for ( ch = 0; ch < 2 * BINAURAL_CHANNELS; ch++ ) @@ -541,7 +602,7 @@ void ivas_dirac_dec_binaural( * Local functions *------------------------------------------------------------------------*/ - +// Todo refactor: To be moved to lib_dec static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, @@ -549,11 +610,14 @@ static void ivas_dirac_dec_binaural_internal( const int16_t nchan_transport, const int16_t subframe ) { - DIRAC_DEC_HANDLE hDirAC; + DIRAC_DEC_BIN_HANDLE hDiracDecBin; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + PARAMBIN_REND_CONFIG config_data; int16_t slot, ch, numInChannels; #ifdef MASA_AND_OBJECTS float Cldfb_RealBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_in[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + int16_t nchanSeparateChannels; #else float Cldfb_RealBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_in[4][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; @@ -564,14 +628,35 @@ static void ivas_dirac_dec_binaural_internal( int16_t nBins, offsetSamples; int16_t i, j; - hDirAC = st_ivas->hDirAC; - nBins = hDirAC->num_freq_bands; - offsetSamples = hDirAC->slots_rendered * nBins; + hDiracDecBin = st_ivas->hDiracDecBin; + assert( hDiracDecBin ); + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nBins = hSpatParamRendCom->num_freq_bands; + offsetSamples = hSpatParamRendCom->slots_rendered * nBins; + + /* Setuo internal config */ + config_data.separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; + config_data.ivas_format = st_ivas->ivas_format; + config_data.mc_mode = st_ivas->mc_mode; + config_data.ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + config_data.nchan_transport = st_ivas->nchan_transport; + config_data.qualityBasedSmFactor = st_ivas->hMasa != NULL ? st_ivas->hMasa->data.dir_decode_quality : 1.0f; + config_data.processReverb = st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + config_data.ism_mode = st_ivas->ism_mode; + } + else + { + config_data.ism_mode = ISM_MODE_NONE; + } +#endif /* The input channel number at this processing function (not nchan_transport) */ numInChannels = BINAURAL_CHANNELS; #ifdef MASA_AND_OBJECTS - if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + if ( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { numInChannels++; } @@ -580,7 +665,7 @@ static void ivas_dirac_dec_binaural_internal( numInChannels += (uint8_t) st_ivas->nchan_ism; } #else - if ( st_ivas->hOutSetup.separateChannelEnabled ) + if ( config_data.separateCenterChannelRendering ) { numInChannels++; } @@ -599,7 +684,7 @@ static void ivas_dirac_dec_binaural_internal( Rmat[2][2] = 1.0f; /* CLDFB Analysis of input */ - for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ ) + for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { for ( ch = 0; ch < numInChannels; ch++ ) { @@ -611,7 +696,7 @@ static void ivas_dirac_dec_binaural_internal( Cldfb_ImagBuffer_in[ch][slot], nBins, st_ivas->cldfbAnaDec[ch] ); } - else if ( st_ivas->nchan_transport == 2 ) /* Stereo signal transmitted as mono with DFT stereo */ + else if ( config_data.nchan_transport == 2 ) /* Stereo signal transmitted as mono with DFT stereo */ { /* At mono input duplicate the channel to dual-mono */ mvr2r( Cldfb_RealBuffer_in[0][slot], Cldfb_RealBuffer_in[1][slot], nBins ); @@ -626,7 +711,7 @@ static void ivas_dirac_dec_binaural_internal( int16_t slotInFrame; numCoreBands = st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->numCoreBands; - slotInFrame = hDirAC->slots_rendered + slot; + slotInFrame = hSpatParamRendCom->slots_rendered + slot; generate_masking_noise_dirac( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], @@ -678,7 +763,7 @@ static void ivas_dirac_dec_binaural_internal( } } - if ( st_ivas->hDiracDecBin->useTdDecorr ) + if ( hDiracDecBin->useTdDecorr ) { for ( ch = BINAURAL_CHANNELS; ch < ( 2 * BINAURAL_CHANNELS ); ch++ ) { @@ -688,7 +773,7 @@ static void ivas_dirac_dec_binaural_internal( Cldfb_ImagBuffer_in[ch][slot], nBins, st_ivas->cldfbAnaDec[ch] ); - if ( st_ivas->nchan_transport == 1 && st_ivas->ivas_format == SBA_FORMAT ) + if ( config_data.nchan_transport == 1 && config_data.ivas_format == SBA_FORMAT ) { v_multc( Cldfb_RealBuffer_in[ch][slot], INV_SQRT_2, Cldfb_RealBuffer_in[ch][slot], nBins ); v_multc( Cldfb_ImagBuffer_in[ch][slot], INV_SQRT_2, Cldfb_ImagBuffer_in[ch][slot], nBins ); @@ -697,9 +782,9 @@ static void ivas_dirac_dec_binaural_internal( } } - if ( st_ivas->ivas_format == SBA_FORMAT ) + if ( config_data.ivas_format == SBA_FORMAT ) { - st_ivas->hDirAC->hDiffuseDist = &diffuseDistData; + hDiracDecBin->hDiffuseDist = &diffuseDistData; ivas_spar_param_to_masa_param_mapping( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, subframe ); @@ -725,44 +810,67 @@ static void ivas_dirac_dec_binaural_internal( if ( nchan_transport == 2 ) { - adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hDirAC->subframe_nbslots[subframe], Rmat ); + adaptTransportSignalsHeadtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); - ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hDirAC->subframe_nbslots[subframe], Rmat ); + ivas_dirac_dec_binaural_check_and_switch_transports_headtracked( hCombinedOrientationData, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, hSpatParamRendCom->subframe_nbslots[subframe], Rmat ); } } - ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe, +#ifdef MASA_AND_OBJECTS + ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, st_ivas->hMasaIsmData ); +#else + ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, Rmat, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0 ); +#endif - if ( st_ivas->ivas_format == ISM_FORMAT ) + if ( config_data.ivas_format == ISM_FORMAT ) { max_band_decorr = 0; } - else if ( st_ivas->hDiracDecBin->useTdDecorr ) + else if ( hDiracDecBin->useTdDecorr ) { max_band_decorr = CLDFB_NO_CHANNELS_MAX; } else { - max_band_decorr = st_ivas->hDirAC->h_freq_domain_decorr_ap_params->max_band_decorr; + max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; } - ivas_dirac_dec_binaural_determine_processing_matrices( st_ivas, max_band_decorr, Rmat, +#ifdef MASA_AND_OBJECTS + nchanSeparateChannels = 0; + if ( config_data.separateCenterChannelRendering || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) + { + nchanSeparateChannels = 1; + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; + } + ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, + nchanSeparateChannels, st_ivas->hMasaIsmData ); +#else + ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0 ); - ivas_dirac_dec_binaural_process_output( st_ivas, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, subframe ); +#endif + ivas_dirac_dec_binaural_process_output( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_f, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, max_band_decorr, numInChannels, config_data.processReverb, subframe ); - st_ivas->hDirAC->hDiffuseDist = NULL; + hDiracDecBin->hDiffuseDist = NULL; +#ifdef MASA_AND_OBJECTS // Todo OMASA JBM: This change could have some side effects - hDirAC->slots_rendered += hDirAC->subframe_nbslots[subframe]; - hDirAC->subframes_rendered++; +#endif + hSpatParamRendCom->slots_rendered += hSpatParamRendCom->subframe_nbslots[subframe]; + hSpatParamRendCom->subframes_rendered++; return; } static void ivas_dirac_dec_decorrelate_slot( - DIRAC_DEC_HANDLE hDirAC, + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + const int16_t num_freq_bands, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -772,37 +880,39 @@ static void ivas_dirac_dec_decorrelate_slot( int16_t offset, ch, bin; float onset_filter[BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, 60 bins */ float decorrelatedFrameInterleaved[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */ + float protoFrameF[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */ + const int16_t protoIndexDir[BINAURAL_CHANNELS] = { 0, 1 }; /* Decorrelation needs interleaved data. Copy left and right signals to proto_frame_f */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - offset = hDirAC->num_freq_bands * BINAURAL_CHANNELS * ch; - for ( bin = 0; bin < hDirAC->num_freq_bands; bin++ ) + offset = num_freq_bands * BINAURAL_CHANNELS * ch; + for ( bin = 0; bin < num_freq_bands; bin++ ) { - hDirAC->proto_frame_f[( bin * BINAURAL_CHANNELS ) + offset] = inRe[ch][slot][bin]; - hDirAC->proto_frame_f[( bin * BINAURAL_CHANNELS ) + offset + 1] = inIm[ch][slot][bin]; + protoFrameF[( bin * BINAURAL_CHANNELS ) + offset] = inRe[ch][slot][bin]; + protoFrameF[( bin * BINAURAL_CHANNELS ) + offset + 1] = inIm[ch][slot][bin]; } } /* Decorrelate proto signal to decorrelatedFrameInterleaved */ - ivas_dirac_dec_decorr_process( hDirAC->num_freq_bands, - hDirAC->num_outputs_diff, - hDirAC->num_protos_diff, - hDirAC->synthesisConf, + ivas_dirac_dec_decorr_process( num_freq_bands, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, BINAURAL_CHANNELS, - hDirAC->proto_frame_f, - hDirAC->num_protos_diff, - hDirAC->proto_index_diff, + protoFrameF, + BINAURAL_CHANNELS, + protoIndexDir, decorrelatedFrameInterleaved, onset_filter, - hDirAC->h_freq_domain_decorr_ap_params, - hDirAC->h_freq_domain_decorr_ap_state ); + hDiracDecBin->h_freq_domain_decorr_ap_params, + hDiracDecBin->h_freq_domain_decorr_ap_state ); /* De-interleave decorrelated signals*/ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - offset = hDirAC->num_freq_bands * BINAURAL_CHANNELS * ch; - for ( bin = 0; bin < hDirAC->num_freq_bands; bin++ ) + offset = num_freq_bands * BINAURAL_CHANNELS * ch; + for ( bin = 0; bin < num_freq_bands; bin++ ) { decRe[ch][bin] = decorrelatedFrameInterleaved[( bin * BINAURAL_CHANNELS ) + offset]; decIm[ch][bin] = decorrelatedFrameInterleaved[( bin * BINAURAL_CHANNELS ) + offset + 1]; @@ -814,19 +924,23 @@ static void ivas_dirac_dec_decorrelate_slot( static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( - Decoder_Struct *st_ivas, + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, - const int16_t isHeadtracked ) + const int16_t isHeadtracked +#ifdef MASA_AND_OBJECTS + , const MASA_ISM_DATA_HANDLE hMasaIsmData +#endif +) { int16_t ch, slot, bin; - uint8_t separateCenterChannelRendering; + int16_t separateCenterChannelRendering; int16_t nBins, idx; float frameMeanDiffusenessEneWeight[CLDFB_NO_CHANNELS_MAX]; - DIRAC_DEC_HANDLE hDirAC; - DIRAC_DEC_BIN_HANDLE h; float IIReneLimiterFactor; float qualityBasedSmFactor; float lowBitRateEQ[CLDFB_NO_CHANNELS_MAX]; @@ -834,25 +948,33 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric int16_t dirac_read_idx; float subFrameTotalEne[CLDFB_NO_CHANNELS_MAX]; PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_GAIN_CACHE_SIZE]; + IVAS_FORMAT ivas_format; + MC_MODE mc_mode; + int32_t ivas_total_brate; + int16_t nchan_transport; #ifdef MASA_AND_OBJECTS int16_t gainCacheBaseIndex; #endif - hDirAC = st_ivas->hDirAC; - h = st_ivas->hDiracDecBin; - separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; - nBins = hDirAC->num_freq_bands; /* Actually bins */ - - set_zero( h->ChCrossRe, nBins ); - set_zero( h->ChCrossIm, nBins ); - set_zero( h->ChCrossReOut, nBins ); - set_zero( h->ChCrossImOut, nBins ); + separateCenterChannelRendering = hConfig->separateCenterChannelRendering; + ivas_format = hConfig->ivas_format; + mc_mode = hConfig->mc_mode; + ivas_total_brate = hConfig->ivas_total_brate; + nchan_transport = hConfig->nchan_transport; + qualityBasedSmFactor = hConfig->qualityBasedSmFactor; + qualityBasedSmFactor *= qualityBasedSmFactor; + nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */ + + set_zero( hDiracDecBin->ChCrossRe, nBins ); + set_zero( hDiracDecBin->ChCrossIm, nBins ); + set_zero( hDiracDecBin->ChCrossReOut, nBins ); + set_zero( hDiracDecBin->ChCrossImOut, nBins ); for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - set_zero( h->ChEne[ch], nBins ); - set_zero( h->ChEneOut[ch], nBins ); + set_zero( hDiracDecBin->ChEne[ch], nBins ); + set_zero( hDiracDecBin->ChEneOut[ch], nBins ); } - set_zero( h->frameMeanDiffuseness, nBins ); + set_zero( hDiracDecBin->frameMeanDiffuseness, nBins ); set_zero( frameMeanDiffusenessEneWeight, CLDFB_NO_CHANNELS_MAX ); @@ -863,10 +985,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Determine EQ for low bit rates (13.2 and 16.4 kbps) */ applyLowBitRateEQ = 0; - if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MC_FORMAT ) && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) { applyLowBitRateEQ = 1; - if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_16k4 ) + if ( ivas_total_brate == IVAS_16k4 ) { for ( bin = 0; bin < LOW_BIT_RATE_BINAURAL_EQ_BINS; bin++ ) { @@ -884,10 +1006,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Formulate input and target covariance matrices for this subframe */ set_zero( subFrameTotalEne, CLDFB_NO_CHANNELS_MAX ); - dirac_read_idx = hDirAC->render_to_md_map[subframe]; + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; /* Calculate input covariance matrix */ - for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ ) + for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { for ( bin = 0; bin < nBins; bin++ ) { @@ -897,13 +1019,13 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric instEne = ( inRe[ch][slot][bin] * inRe[ch][slot][bin] ); instEne += ( inIm[ch][slot][bin] * inIm[ch][slot][bin] ); - h->ChEne[ch][bin] += instEne; + hDiracDecBin->ChEne[ch][bin] += instEne; subFrameTotalEne[bin] += instEne; } - h->ChCrossRe[bin] += inRe[0][slot][bin] * inRe[1][slot][bin]; - h->ChCrossRe[bin] += inIm[0][slot][bin] * inIm[1][slot][bin]; - h->ChCrossIm[bin] += inRe[0][slot][bin] * inIm[1][slot][bin]; - h->ChCrossIm[bin] -= inIm[0][slot][bin] * inRe[1][slot][bin]; + hDiracDecBin->ChCrossRe[bin] += inRe[0][slot][bin] * inRe[1][slot][bin]; + hDiracDecBin->ChCrossRe[bin] += inIm[0][slot][bin] * inIm[1][slot][bin]; + hDiracDecBin->ChCrossIm[bin] += inRe[0][slot][bin] * inIm[1][slot][bin]; + hDiracDecBin->ChCrossIm[bin] -= inIm[0][slot][bin] * inRe[1][slot][bin]; } } @@ -922,13 +1044,13 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } } - if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 2 ) + if ( ivas_format == SBA_FORMAT && nchan_transport == 2 ) { float tempRe, tempIm; set_zero( subFrameTotalEne, CLDFB_NO_CHANNELS_MAX ); - for ( slot = 0; slot < hDirAC->subframe_nbslots[subframe]; slot++ ) + for ( slot = 0; slot < hSpatParamRendCom->subframe_nbslots[subframe]; slot++ ) { for ( bin = 0; bin < nBins; bin++ ) { @@ -956,10 +1078,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric * HRTF data set and a BRIR-based data set. The HRTF data set is spectrally corrected to match * the early spectrum of the BRIR data, using the spectral correction data in * hBinaural->earlyPartEneCorrection[bin], based on the BRIR set. */ - meanEnePerCh = h->earlyPartEneCorrection[bin] * subFrameTotalEne[bin] / 2.0f; + meanEnePerCh = hDiracDecBin->earlyPartEneCorrection[bin] * subFrameTotalEne[bin] / 2.0f; /* Determine direct part target covariance matrix (for 1 or 2 directions) */ - for ( dirIndex = 0; dirIndex < hDirAC->numSimultaneousDirections; dirIndex++ ) + for ( dirIndex = 0; dirIndex < hSpatParamRendCom->numSimultaneousDirections; dirIndex++ ) { int16_t aziDeg, eleDeg; float lRealp, lImagp, rRealp, rImagp; @@ -971,21 +1093,21 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric if ( dirIndex == 0 ) /* For first of the two simultaneous directions */ { - aziDeg = hDirAC->azimuth[dirac_read_idx][bin]; - eleDeg = hDirAC->elevation[dirac_read_idx][bin]; - ratio = hDirAC->energy_ratio1[dirac_read_idx][bin]; - spreadCoh = hDirAC->spreadCoherence[dirac_read_idx][bin]; + aziDeg = hSpatParamRendCom->azimuth[dirac_read_idx][bin]; + eleDeg = hSpatParamRendCom->elevation[dirac_read_idx][bin]; + ratio = hSpatParamRendCom->energy_ratio1[dirac_read_idx][bin]; + spreadCoh = hSpatParamRendCom->spreadCoherence[dirac_read_idx][bin]; #ifdef MASA_AND_OBJECTS gainCacheBaseIndex = 0; #endif } #ifdef MASA_AND_OBJECTS - else if ( st_ivas->ivas_format != MASA_ISM_FORMAT || ( st_ivas->ivas_format == MASA_ISM_FORMAT && dirIndex < hDirAC->numParametricDirections ) ) /* For second of the two simultaneous directions */ + else if ( ivas_format != MASA_ISM_FORMAT || ( ivas_format == MASA_ISM_FORMAT && dirIndex < hSpatParamRendCom->numParametricDirections ) ) /* For second of the two simultaneous directions */ #else else /* For second of the two simultaneous directions */ #endif { - if ( ( ratio = hDirAC->energy_ratio2[dirac_read_idx][bin] ) < 0.001 ) + if ( ( ratio = hSpatParamRendCom->energy_ratio2[dirac_read_idx][bin] ) < 0.001 ) { /* This touches only MASA path where second direction always has smaller ratio and * for non-2dir it is zero. As the whole direction contribution is multiplied with @@ -993,9 +1115,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric * it is better to save complexity. */ continue; } - aziDeg = hDirAC->azimuth2[dirac_read_idx][bin]; - eleDeg = hDirAC->elevation2[dirac_read_idx][bin]; - spreadCoh = hDirAC->spreadCoherence2[dirac_read_idx][bin]; + aziDeg = hSpatParamRendCom->azimuth2[dirac_read_idx][bin]; + eleDeg = hSpatParamRendCom->elevation2[dirac_read_idx][bin]; + spreadCoh = hSpatParamRendCom->spreadCoherence2[dirac_read_idx][bin]; #ifdef MASA_AND_OBJECTS gainCacheBaseIndex = 3; #endif @@ -1005,18 +1127,19 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric { isIsmDirection = 1; uint16_t ismDirIndex; - ismDirIndex = dirIndex - hDirAC->numParametricDirections; - if ( st_ivas->hMasaIsmData->ism_is_edited[ismDirIndex] ) + ismDirIndex = dirIndex - hSpatParamRendCom->numParametricDirections; + assert( hMasaIsmData != NULL && "hMasaIsmData should not be NULL if we use it"); + if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) { - aziDeg = st_ivas->hMasaIsmData->azimuth_ism_edited[ismDirIndex]; - eleDeg = st_ivas->hMasaIsmData->elevation_ism_edited[ismDirIndex]; + aziDeg = hMasaIsmData->azimuth_ism_edited[ismDirIndex]; + eleDeg = hMasaIsmData->elevation_ism_edited[ismDirIndex]; } else { - aziDeg = st_ivas->hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx]; - eleDeg = st_ivas->hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx]; + aziDeg = hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx]; + eleDeg = hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx]; } - ratio = st_ivas->hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; + ratio = hMasaIsmData->energy_ratio_ism[ismDirIndex][dirac_read_idx][bin]; spreadCoh = 0.0f; gainCacheBaseIndex = 6 + ismDirIndex; } @@ -1055,12 +1178,12 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } #ifdef MASA_AND_OBJECTS - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex], isHeadtracked ); + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex], isHeadtracked ); #else - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 )], isHeadtracked ); + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 )], isHeadtracked ); #endif - if ( h->renderStereoOutputInsteadOfBinaural ) + if ( hDiracDecBin->renderStereoOutputInsteadOfBinaural ) { /* Synthesizing spread coherence is not needed for stereo loudspeaker output, * as directional sound is reproduced with two loudspeakers in any case */ @@ -1102,9 +1225,9 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Apply the gain for the left source of the three coherent sources */ #ifdef MASA_AND_OBJECTS - getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 1], isHeadtracked ); + getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 1], isHeadtracked ); #else - getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 1 )], isHeadtracked ); + getDirectPartGains( bin, aziDeg + 30, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 1 )], isHeadtracked ); #endif hrtfEneSides = ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp ); @@ -1116,11 +1239,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Apply the gain for the right source of the three coherent sources. * -30 degrees to 330 wrapping due to internal functions. */ #ifdef MASA_AND_OBJECTS - getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 2], isHeadtracked ); + getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[gainCacheBaseIndex + 2], isHeadtracked ); #else - getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 2 )], isHeadtracked ); + getDirectPartGains( bin, aziDeg + 330, eleDeg, &lRealpTmp, &lImagpTmp, &rRealpTmp, &rImagpTmp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[( dirIndex * 3 + 2 )], isHeadtracked ); #endif - hrtfEneSides += ( lRealpTmp * lRealpTmp ) + ( lImagpTmp * lImagpTmp ) + ( rRealpTmp * rRealpTmp ) + ( rImagpTmp * rImagpTmp ); lRealp += sidesMul * lRealpTmp; lImagp += sidesMul * lImagpTmp; @@ -1147,7 +1269,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric w3 = 2.0f * spreadCoh - 1.0f; } - if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) + if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) ) { idx = min( bin, MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS - 1 ); @@ -1177,25 +1299,25 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Add direct part (1 or 2) covariance matrix */ dirEne = ratio * meanEnePerCh; - h->ChEneOut[0][bin] += dirEne * hrtfEne[0]; /* Dir ene part*/ - h->ChEneOut[1][bin] += dirEne * hrtfEne[1]; - h->ChCrossReOut[bin] += dirEne * hrtfCrossRe; /* Dir cross re */ - h->ChCrossImOut[bin] += dirEne * hrtfCrossIm; /* Dir cross im */ + hDiracDecBin->ChEneOut[0][bin] += dirEne * hrtfEne[0]; /* Dir ene part*/ + hDiracDecBin->ChEneOut[1][bin] += dirEne * hrtfEne[1]; + hDiracDecBin->ChCrossReOut[bin] += dirEne * hrtfCrossRe; /* Dir cross re */ + hDiracDecBin->ChCrossImOut[bin] += dirEne * hrtfCrossIm; /* Dir cross im */ } /* Add diffuse / ambient part covariance matrix */ diffuseness = max( 0.0f, diffuseness ); diffEne = diffuseness * meanEnePerCh; - surCoh = hDirAC->surroundingCoherence[dirac_read_idx][bin]; + surCoh = hSpatParamRendCom->surroundingCoherence[dirac_read_idx][bin]; #ifdef MASA_AND_OBJECTS diffusenessValForDecorrelationReduction = max( 0.0f, diffusenessValForDecorrelationReduction ); diffEneValForDecorrelationReduction = diffusenessValForDecorrelationReduction * meanEnePerCh; #endif - if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) + if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) ) { - if ( !h->renderStereoOutputInsteadOfBinaural ) + if ( !hDiracDecBin->renderStereoOutputInsteadOfBinaural ) { #ifdef MASA_AND_OBJECTS float spectrumModVal; @@ -1216,33 +1338,33 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric #endif } } - h->ChEneOut[0][bin] += diffEne; /* Diff ene part*/ - h->ChEneOut[1][bin] += diffEne; + hDiracDecBin->ChEneOut[0][bin] += diffEne; /* Diff ene part*/ + hDiracDecBin->ChEneOut[1][bin] += diffEne; - if ( h->renderStereoOutputInsteadOfBinaural ) + if ( hDiracDecBin->renderStereoOutputInsteadOfBinaural ) { /* When rendering stereo, ambience (except for surround coherent sound) has zero ICC. */ - h->ChCrossReOut[bin] += surCoh * diffEne; + hDiracDecBin->ChCrossReOut[bin] += surCoh * diffEne; } else /* When rendering binaural, ambience has frequency dependent ICC. */ { - if ( st_ivas->ivas_format == SBA_FORMAT && bin < BINAURAL_COHERENCE_DIFFERENCE_BINS ) + if ( ivas_format == SBA_FORMAT && bin < BINAURAL_COHERENCE_DIFFERENCE_BINS ) { float diffuseFieldCoherence; - diffuseFieldCoherence = hDirAC->hDiffuseDist->diffuseRatioX[bin] * h->diffuseFieldCoherenceX[bin] + hDirAC->hDiffuseDist->diffuseRatioY[bin] * h->diffuseFieldCoherenceY[bin] + hDirAC->hDiffuseDist->diffuseRatioZ[bin] * h->diffuseFieldCoherenceZ[bin]; - h->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * diffuseFieldCoherence + surCoh ) * diffEne; + diffuseFieldCoherence = hDiracDecBin->hDiffuseDist->diffuseRatioX[bin] * hDiracDecBin->diffuseFieldCoherenceX[bin] + hDiracDecBin->hDiffuseDist->diffuseRatioY[bin] * hDiracDecBin->diffuseFieldCoherenceY[bin] + hDiracDecBin->hDiffuseDist->diffuseRatioZ[bin] * hDiracDecBin->diffuseFieldCoherenceZ[bin]; + hDiracDecBin->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * diffuseFieldCoherence + surCoh ) * diffEne; } else { - h->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * h->diffuseFieldCoherence[bin] + surCoh ) * diffEne; + hDiracDecBin->ChCrossReOut[bin] += ( ( 1.0f - surCoh ) * hDiracDecBin->diffuseFieldCoherence[bin] + surCoh ) * diffEne; } } /* Store parameters for formulating average diffuseness over frame */ #ifdef MASA_AND_OBJECTS - h->frameMeanDiffuseness[bin] += diffEneValForDecorrelationReduction; + hDiracDecBin->frameMeanDiffuseness[bin] += diffEneValForDecorrelationReduction; #else - h->frameMeanDiffuseness[bin] += diffEne; + hDiracDecBin->frameMeanDiffuseness[bin] += diffEne; #endif frameMeanDiffusenessEneWeight[bin] += meanEnePerCh; } @@ -1250,19 +1372,11 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Formulate average diffuseness over frame */ for ( bin = 0; bin < nBins; bin++ ) { - h->frameMeanDiffuseness[bin] /= fmaxf( 1e-12f, frameMeanDiffusenessEneWeight[bin] ); + hDiracDecBin->frameMeanDiffuseness[bin] /= fmaxf( 1e-12f, frameMeanDiffusenessEneWeight[bin] ); } - /* Determine encoding quality based additional smoothing factor */ - qualityBasedSmFactor = 1.0f; - if ( st_ivas->hMasa != NULL ) - { - qualityBasedSmFactor = st_ivas->hMasa->data.dir_decode_quality; - qualityBasedSmFactor *= qualityBasedSmFactor; - } - - /* Temporal IIR-type smoothing of covariance matrices */ - if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + /* Temporal IIR-type smoothing of covariance matrices. Also apply encoding quality based smoothing factor. */ + if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) { IIReneLimiterFactor = 16.0f + ( 1.0f - qualityBasedSmFactor ); } @@ -1277,41 +1391,41 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric /* Temporally smooth cov mtx estimates for resulting mixing matrix stability. The design principle is that * the energy history (IIR) must not be more than double of the current frame energy. This provides more * robust performance at energy offsets when compared to typical IIR averaging. */ - eneRatio = ( h->ChEne[0][bin] + h->ChEne[1][bin] ) / fmaxf( 1e-12f, ( h->ChEnePrev[0][bin] + h->ChEnePrev[1][bin] ) ); + eneRatio = ( hDiracDecBin->ChEne[0][bin] + hDiracDecBin->ChEne[1][bin] ) / fmaxf( 1e-12f, ( hDiracDecBin->ChEnePrev[0][bin] + hDiracDecBin->ChEnePrev[1][bin] ) ); IIReneLimiter = fminf( 1.0f, eneRatio * IIReneLimiterFactor ); - h->ChCrossRe[bin] *= qualityBasedSmFactor; - h->ChCrossIm[bin] *= qualityBasedSmFactor; - h->ChCrossReOut[bin] *= qualityBasedSmFactor; - h->ChCrossImOut[bin] *= qualityBasedSmFactor; + hDiracDecBin->ChCrossRe[bin] *= qualityBasedSmFactor; + hDiracDecBin->ChCrossIm[bin] *= qualityBasedSmFactor; + hDiracDecBin->ChCrossReOut[bin] *= qualityBasedSmFactor; + hDiracDecBin->ChCrossImOut[bin] *= qualityBasedSmFactor; for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - h->ChEne[ch][bin] *= qualityBasedSmFactor; - h->ChEneOut[ch][bin] *= qualityBasedSmFactor; + hDiracDecBin->ChEne[ch][bin] *= qualityBasedSmFactor; + hDiracDecBin->ChEneOut[ch][bin] *= qualityBasedSmFactor; } - h->ChCrossRe[bin] += IIReneLimiter * h->ChCrossRePrev[bin]; - h->ChCrossIm[bin] += IIReneLimiter * h->ChCrossImPrev[bin]; - h->ChCrossReOut[bin] += IIReneLimiter * h->ChCrossReOutPrev[bin]; - h->ChCrossImOut[bin] += IIReneLimiter * h->ChCrossImOutPrev[bin]; + hDiracDecBin->ChCrossRe[bin] += IIReneLimiter * hDiracDecBin->ChCrossRePrev[bin]; + hDiracDecBin->ChCrossIm[bin] += IIReneLimiter * hDiracDecBin->ChCrossImPrev[bin]; + hDiracDecBin->ChCrossReOut[bin] += IIReneLimiter * hDiracDecBin->ChCrossReOutPrev[bin]; + hDiracDecBin->ChCrossImOut[bin] += IIReneLimiter * hDiracDecBin->ChCrossImOutPrev[bin]; for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - h->ChEne[ch][bin] += IIReneLimiter * h->ChEnePrev[ch][bin]; - h->ChEneOut[ch][bin] += IIReneLimiter * h->ChEneOutPrev[ch][bin]; + hDiracDecBin->ChEne[ch][bin] += IIReneLimiter * hDiracDecBin->ChEnePrev[ch][bin]; + hDiracDecBin->ChEneOut[ch][bin] += IIReneLimiter * hDiracDecBin->ChEneOutPrev[ch][bin]; } /* Store energy values and coefficients for next round */ - h->ChCrossRePrev[bin] = h->ChCrossRe[bin]; - h->ChCrossImPrev[bin] = h->ChCrossIm[bin]; - h->ChCrossReOutPrev[bin] = h->ChCrossReOut[bin]; - h->ChCrossImOutPrev[bin] = h->ChCrossImOut[bin]; + hDiracDecBin->ChCrossRePrev[bin] = hDiracDecBin->ChCrossRe[bin]; + hDiracDecBin->ChCrossImPrev[bin] = hDiracDecBin->ChCrossIm[bin]; + hDiracDecBin->ChCrossReOutPrev[bin] = hDiracDecBin->ChCrossReOut[bin]; + hDiracDecBin->ChCrossImOutPrev[bin] = hDiracDecBin->ChCrossImOut[bin]; for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - h->ChEnePrev[ch][bin] = h->ChEne[ch][bin]; - h->ChEneOutPrev[ch][bin] = h->ChEneOut[ch][bin]; + hDiracDecBin->ChEnePrev[ch][bin] = hDiracDecBin->ChEne[ch][bin]; + hDiracDecBin->ChEneOutPrev[ch][bin] = hDiracDecBin->ChEneOut[ch][bin]; } } @@ -1320,51 +1434,52 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric static void ivas_dirac_dec_binaural_determine_processing_matrices( - Decoder_Struct *st_ivas, + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], - const int16_t isHeadtracked ) -{ - int16_t chA, chB, bin; - uint8_t separateCenterChannelRendering; + const int16_t isHeadtracked #ifdef MASA_AND_OBJECTS - uint8_t nchanSeparateChannels; + , const int16_t nchanSeparateChannels, + const MASA_ISM_DATA_HANDLE hMasaIsmData #endif + ) +{ + int16_t chA, chB, bin; + int16_t separateCenterChannelRendering; int16_t nBins; #ifdef MASA_AND_OBJECTS int16_t dirac_read_idx; #endif - DIRAC_DEC_BIN_HANDLE h; #ifdef MASA_AND_OBJECTS PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_NUM_OBJECTS]; int16_t idx; + ISM_MODE ism_mode; #else PARAMBIN_HRTF_GAIN_CACHE gainCache; #endif + IVAS_FORMAT ivas_format; + MC_MODE mc_mode; + int32_t ivas_total_brate; + int16_t nchan_transport; - h = st_ivas->hDiracDecBin; + ivas_format = hConfig->ivas_format; #ifdef MASA_AND_OBJECTS - separateCenterChannelRendering = 0; - nchanSeparateChannels = 0; - - if ( st_ivas->hOutSetup.separateChannelEnabled || ( st_ivas->ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) - { - separateCenterChannelRendering = 1; - nchanSeparateChannels = 1; - } - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - separateCenterChannelRendering = 1; - nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; - } + separateCenterChannelRendering = nchanSeparateChannels > 0; #else - separateCenterChannelRendering = st_ivas->hOutSetup.separateChannelEnabled; + separateCenterChannelRendering = hConfig->separateCenterChannelRendering; #endif + mc_mode = hConfig->mc_mode; + ivas_total_brate = hConfig->ivas_total_brate; + nchan_transport = hConfig->nchan_transport; + nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */ - nBins = st_ivas->hDirAC->num_freq_bands; /* Actually bins */ #ifdef MASA_AND_OBJECTS + ism_mode = hConfig->ism_mode; + // Todo OMASA JBM: This is probably not correct now. We should get the index from JBM - dirac_read_idx = st_ivas->hDirAC->dirac_read_idx; + dirac_read_idx = hSpatParamRendCom->dirac_read_idx; #endif #ifdef MASA_AND_OBJECTS @@ -1390,21 +1505,21 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( CrEneR = 0.0f; /* Formulate main processing matrix M */ - formulate2x2MixingMatrix( h->ChEne[0][bin], h->ChEne[1][bin], - h->ChCrossRe[bin], h->ChCrossIm[bin], - h->ChEneOut[0][bin], h->ChEneOut[1][bin], - h->ChCrossReOut[bin], h->ChCrossImOut[bin], - prototypeMtx, Mre, Mim, h->reqularizationFactor ); + formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin], + hDiracDecBin->ChCrossRe[bin], hDiracDecBin->ChCrossIm[bin], + hDiracDecBin->ChEneOut[0][bin], hDiracDecBin->ChEneOut[1][bin], + hDiracDecBin->ChCrossReOut[bin], hDiracDecBin->ChCrossImOut[bin], + prototypeMtx, Mre, Mim, hDiracDecBin->reqularizationFactor ); /* Load estimated covariance matrix to the [2][2] matrix form */ - CxRe[0][0] = h->ChEne[0][bin]; - CxRe[1][1] = h->ChEne[1][bin]; - CxRe[1][0] = h->ChCrossRe[bin]; - CxRe[0][1] = h->ChCrossRe[bin]; + CxRe[0][0] = hDiracDecBin->ChEne[0][bin]; + CxRe[1][1] = hDiracDecBin->ChEne[1][bin]; + CxRe[1][0] = hDiracDecBin->ChCrossRe[bin]; + CxRe[0][1] = hDiracDecBin->ChCrossRe[bin]; CxIm[0][0] = 0.0f; CxIm[1][1] = 0.0f; - CxIm[1][0] = h->ChCrossIm[bin]; - CxIm[0][1] = -h->ChCrossIm[bin]; + CxIm[1][0] = hDiracDecBin->ChCrossIm[bin]; + CxIm[0][1] = -hDiracDecBin->ChCrossIm[bin]; /* Make matrix multiplication M*Cx*M' to determine resulting covariance matrix of processing input with M */ matrixMul( Mre, Mim, CxRe, CxIm, tmpMtxRe, tmpMtxIm ); @@ -1420,30 +1535,30 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( /* Subtract the resulting covariance matrix from the target covariance matrix to determine * what signal component is missing. The result is the target covariance matrix for the residual signal, i.e., * a residual covariance matrix. */ - CrEneL = max( 0.0f, h->ChEneOut[0][bin] - resultMtxRe[0][0] ); - CrEneR = max( 0.0f, h->ChEneOut[1][bin] - resultMtxRe[1][1] ); - CrCrossRe = h->ChCrossReOut[bin] - resultMtxRe[1][0]; - CrCrossIm = h->ChCrossImOut[bin] - resultMtxIm[1][0]; + CrEneL = max( 0.0f, hDiracDecBin->ChEneOut[0][bin] - resultMtxRe[0][0] ); + CrEneR = max( 0.0f, hDiracDecBin->ChEneOut[1][bin] - resultMtxRe[1][1] ); + CrCrossRe = hDiracDecBin->ChCrossReOut[bin] - resultMtxRe[1][0]; + CrCrossIm = hDiracDecBin->ChCrossImOut[bin] - resultMtxIm[1][0]; /* The amount of the decorrelated sound is further controlled based on the spatial metadata, * by determining an energy-suppressed residual covariance matrix that is a control parameter * that guides the processing of the decorrelated sound to a residual signal. * The procedure improves quality in e.g. double-talk 2-direction rendering situations.*/ - if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) { decorrelationReductionFactor = 1.0f; } - else if ( ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) || ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nchan_transport == 1 ) ) + else if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) || ( ivas_format == MASA_FORMAT && nchan_transport == 1 ) ) { - decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, h->frameMeanDiffuseness[bin] ) ); + decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ) ); } - else if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 1 ) + else if ( ivas_format == SBA_FORMAT && nchan_transport == 1 ) { decorrelationReductionFactor = 1.0f; } else { - decorrelationReductionFactor = fmaxf( 0.0f, h->frameMeanDiffuseness[bin] ); + decorrelationReductionFactor = fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ); } CrEneL *= decorrelationReductionFactor; CrEneR *= decorrelationReductionFactor; @@ -1452,7 +1567,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( /* Determine a residual mixing matrix Mdec for processing the decorrelated signal to obtain * the residual signal (that has the residual covariance matrix) */ - formulate2x2MixingMatrix( h->ChEne[0][bin], h->ChEne[1][bin], + formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin], 0.0f, 0.0f, /* Decorrelated signal has ideally no cross-terms */ CrEneL, CrEneR, CrCrossRe, CrCrossIm, @@ -1469,7 +1584,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( /* The regularizations at determining mixing matrices cause signal energy to be lost to some degree, which is compensated for here */ realizedOutputEne = CrEneL + CrEneR + resultMtxRe[0][0] + resultMtxRe[1][1]; - targetOutputEne = h->ChEneOut[0][bin] + h->ChEneOut[1][bin]; + targetOutputEne = hDiracDecBin->ChEneOut[0][bin] + hDiracDecBin->ChEneOut[1][bin]; missingOutputEne = fmaxf( 0.0f, targetOutputEne - realizedOutputEne ); gain = sqrtf( ( resultMtxRe[0][0] + resultMtxRe[1][1] + missingOutputEne ) / @@ -1490,15 +1605,15 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( { for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - h->processMtxRePrev[chA][chB][bin] = h->processMtxRe[chA][chB][bin]; - h->processMtxImPrev[chA][chB][bin] = h->processMtxIm[chA][chB][bin]; - h->processMtxDecRePrev[chA][chB][bin] = h->processMtxDecRe[chA][chB][bin]; - h->processMtxDecImPrev[chA][chB][bin] = h->processMtxDecIm[chA][chB][bin]; - - h->processMtxRe[chA][chB][bin] = Mre[chA][chB]; - h->processMtxIm[chA][chB][bin] = Mim[chA][chB]; - h->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB]; - h->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB]; + hDiracDecBin->processMtxRePrev[chA][chB][bin] = hDiracDecBin->processMtxRe[chA][chB][bin]; + hDiracDecBin->processMtxImPrev[chA][chB][bin] = hDiracDecBin->processMtxIm[chA][chB][bin]; + hDiracDecBin->processMtxDecRePrev[chA][chB][bin] = hDiracDecBin->processMtxDecRe[chA][chB][bin]; + hDiracDecBin->processMtxDecImPrev[chA][chB][bin] = hDiracDecBin->processMtxDecIm[chA][chB][bin]; + + hDiracDecBin->processMtxRe[chA][chB][bin] = Mre[chA][chB]; + hDiracDecBin->processMtxIm[chA][chB][bin] = Mim[chA][chB]; + hDiracDecBin->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB]; + hDiracDecBin->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB]; } } @@ -1513,68 +1628,68 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #ifdef MASA_AND_OBJECTS uint8_t instantChange = 0; - if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + if ( ivas_format == MASA_ISM_FORMAT ) { - gainFactor = 0.7943f * sqrtf( h->earlyPartEneCorrection[bin] ); /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ + gainFactor = 0.7943f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ } else { - gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); + gainFactor = 0.8414f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); } for ( chB = 0; chB < nchanSeparateChannels; chB++ ) { - if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + if ( ivas_format == MASA_ISM_FORMAT ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + if ( ism_mode == ISM_MASA_MODE_DISC ) { - aziDeg = st_ivas->hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; - eleDeg = st_ivas->hMasaIsmData->elevation_ism[chB][dirac_read_idx]; + aziDeg = hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; + eleDeg = hMasaIsmData->elevation_ism[chB][dirac_read_idx]; } else { - aziDeg = st_ivas->hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; - eleDeg = st_ivas->hMasaIsmData->elevation_separated_ism[dirac_read_idx]; + aziDeg = hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; + eleDeg = hMasaIsmData->elevation_separated_ism[dirac_read_idx]; instantChange = 1; } } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - h->processMtxRePrev[chA][chB + 2][bin] = h->processMtxRe[chA][chB + 2][bin]; - h->processMtxImPrev[chA][chB + 2][bin] = h->processMtxIm[chA][chB + 2][bin]; + hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; + hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; } - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); - h->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; - h->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; - h->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; - h->processMtxIm[1][chB + 2][bin] = rImagp * gainFactor; + hDiracDecBin->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; + hDiracDecBin->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; + hDiracDecBin->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; + hDiracDecBin->processMtxIm[1][chB + 2][bin] = rImagp * gainFactor; if ( instantChange ) { for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - h->processMtxRePrev[chA][chB + 2][bin] = h->processMtxRe[chA][chB + 2][bin]; - h->processMtxImPrev[chA][chB + 2][bin] = h->processMtxIm[chA][chB + 2][bin]; + hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; + hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; } } } #else - gainFactor = 0.8414f * sqrtf( h->earlyPartEneCorrection[bin] ); + gainFactor = 0.8414f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - h->processMtxRePrev[chA][2][bin] = h->processMtxRe[chA][2][bin]; - h->processMtxImPrev[chA][2][bin] = h->processMtxIm[chA][2][bin]; + hDiracDecBin->processMtxRePrev[chA][2][bin] = hDiracDecBin->processMtxRe[chA][2][bin]; + hDiracDecBin->processMtxImPrev[chA][2][bin] = hDiracDecBin->processMtxIm[chA][2][bin]; } - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, h->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache, isHeadtracked ); + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache, isHeadtracked ); - h->processMtxRe[0][2][bin] = lRealp * gainFactor; - h->processMtxIm[0][2][bin] = lImagp * gainFactor; - h->processMtxRe[1][2][bin] = rRealp * gainFactor; - h->processMtxIm[1][2][bin] = rImagp * gainFactor; + hDiracDecBin->processMtxRe[0][2][bin] = lRealp * gainFactor; + hDiracDecBin->processMtxIm[0][2][bin] = lImagp * gainFactor; + hDiracDecBin->processMtxRe[1][2][bin] = rRealp * gainFactor; + hDiracDecBin->processMtxIm[1][2][bin] = rImagp * gainFactor; #endif } } @@ -1584,12 +1699,15 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( static void ivas_dirac_dec_binaural_process_output( - Decoder_Struct *st_ivas, + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], float *output_f[], float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t max_band_decorr, const int16_t numInChannels, + const int16_t processReverb, const int16_t subframe ) { int16_t slot, bin, chA, chB; @@ -1598,31 +1716,29 @@ static void ivas_dirac_dec_binaural_process_output( float decSlotRe[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float reverbRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; float reverbIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - DIRAC_DEC_BIN_HANDLE h; float interpVal; float *decSlotRePointer; float *decSlotImPointer; int16_t offsetSamples; int16_t nSlots; - h = st_ivas->hDiracDecBin; - nBins = st_ivas->hDirAC->num_freq_bands; + nBins = hSpatParamRendCom->num_freq_bands; offsetSamples = 0; - nSlots = st_ivas->hDirAC->subframe_nbslots[subframe]; + nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + if ( processReverb ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processSubframe( st_ivas->hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); + ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); } interpVal = 0.0f; for ( slot = 0; slot < nSlots; slot++ ) { interpVal += 1.0f / (float) nSlots; - if ( !st_ivas->hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) + if ( !hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) { - ivas_dirac_dec_decorrelate_slot( st_ivas->hDirAC, slot, inRe, inIm, decSlotRe, decSlotIm ); + ivas_dirac_dec_decorrelate_slot( hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm ); } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) @@ -1635,7 +1751,7 @@ static void ivas_dirac_dec_binaural_process_output( /* Processing of the first / HRTF part of the binaural output. */ for ( chB = 0; chB < numInChannels; chB++ ) { - if ( st_ivas->hDiracDecBin->useTdDecorr ) + if ( hDiracDecBin->useTdDecorr ) { decSlotRePointer = inRe[chB + 2][slot]; decSlotImPointer = inIm[chB + 2][slot]; @@ -1651,33 +1767,33 @@ static void ivas_dirac_dec_binaural_process_output( float gain; /* Mixing using the formulated processing matrix M */ - gain = ( 1.0f - interpVal ) * h->processMtxRePrev[chA][chB][bin] + - interpVal * h->processMtxRe[chA][chB][bin]; + gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxRePrev[chA][chB][bin] + + interpVal * hDiracDecBin->processMtxRe[chA][chB][bin]; outSlotRe[bin] += gain * inRe[chB][slot][bin]; outSlotIm[bin] += gain * inIm[chB][slot][bin]; - gain = ( 1.0f - interpVal ) * h->processMtxImPrev[chA][chB][bin] + - interpVal * h->processMtxIm[chA][chB][bin]; + gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxImPrev[chA][chB][bin] + + interpVal * hDiracDecBin->processMtxIm[chA][chB][bin]; outSlotRe[bin] -= gain * inIm[chB][slot][bin]; outSlotIm[bin] += gain * inRe[chB][slot][bin]; /* Mixing decorrelated signals using the formulated residual processing matrix Mdec */ if ( bin < max_band_decorr && chB < 2 ) { - gain = ( 1.0f - interpVal ) * h->processMtxDecRePrev[chA][chB][bin] + - interpVal * h->processMtxDecRe[chA][chB][bin]; + gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxDecRePrev[chA][chB][bin] + + interpVal * hDiracDecBin->processMtxDecRe[chA][chB][bin]; outSlotRe[bin] += gain * decSlotRePointer[bin]; outSlotIm[bin] += gain * decSlotImPointer[bin]; - gain = ( 1.0f - interpVal ) * h->processMtxDecImPrev[chA][chB][bin] + - interpVal * h->processMtxDecIm[chA][chB][bin]; + gain = ( 1.0f - interpVal ) * hDiracDecBin->processMtxDecImPrev[chA][chB][bin] + + interpVal * hDiracDecBin->processMtxDecIm[chA][chB][bin]; outSlotRe[bin] -= gain * decSlotImPointer[bin]; outSlotIm[bin] += gain * decSlotRePointer[bin]; } } } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + if ( processReverb ) { /* Combine second (reverb) part with the first (HRTF) part to obtain binaural output signal with room effect */ v_add( outSlotRe, reverbRe[chA][slot], outSlotRe, CLDFB_NO_CHANNELS_MAX ); @@ -1688,7 +1804,7 @@ static void ivas_dirac_dec_binaural_process_output( outSlotImPr = &( outSlotIm[0] ); /* Inverse filter bank */ - cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( output_f[chA][nBins * slot + offsetSamples] ), nBins, st_ivas->cldfbSynDec[chA] ); + cldfbSynthesis( &outSlotRePr, &outSlotImPr, &( output_f[chA][nBins * slot + offsetSamples] ), nBins, cldfbSynDec[chA] ); } } @@ -2365,7 +2481,10 @@ static void hrtfShGetHrtf( { float shVec[HRTF_SH_CHANNELS]; - ivas_dirac_dec_get_response( aziDeg, eleDeg, shVec, HRTF_SH_ORDER ); + ivas_dirac_dec_get_response( aziDeg, + eleDeg, + shVec, + HRTF_SH_ORDER ); for ( k = 0; k < HRTF_SH_CHANNELS; k++ ) { @@ -2396,7 +2515,6 @@ float configure_reqularization_factor( ) { float reqularizationFactor; - reqularizationFactor = 1.0f; /* Default value */ if ( ivas_format == MASA_FORMAT ) @@ -2447,7 +2565,7 @@ float configure_reqularization_factor( } } - /* For SBA and parametric ISM, default value of 1.0f. */ + /* For SBA and parametric ISM, currently in default value of 1.0f. */ return reqularizationFactor; } @@ -2468,13 +2586,13 @@ void preProcessStereoTransportsForMovedObjects( const int16_t subframe ) { int16_t bin, ch, inCh, outCh, ismDirIndex, slot; - DIRAC_DEC_HANDLE hDirAC; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; MASA_ISM_DATA_HANDLE hMasaIsmData; uint8_t enableCentering; int16_t dirac_read_idx; int16_t nSlots; - hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; hMasaIsmData = st_ivas->hMasaIsmData; if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_HOA2 || st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_HOA3 ) @@ -2489,7 +2607,7 @@ void preProcessStereoTransportsForMovedObjects( /* Bypass processing until first object is moved */ if ( hMasaIsmData->objectsMoved == 0 ) { - for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) + for ( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) { if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) { @@ -2505,8 +2623,8 @@ void preProcessStereoTransportsForMovedObjects( /* Perform object-movement based processing */ // Todo OMASA JBM: Fixed but might be still wrong somehow - nSlots = st_ivas->hDirAC->subframe_nbslots[subframe]; - dirac_read_idx = st_ivas->hDirAC->render_to_md_map[subframe]; + nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; for ( bin = 0; bin < nBins; bin++ ) { @@ -2544,7 +2662,7 @@ void preProcessStereoTransportsForMovedObjects( /* For each ismDir, formulate a mix-matrix that moves object audio signals between * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ - for ( ismDirIndex = 0; ismDirIndex < hDirAC->numIsmDirections; ismDirIndex++ ) + for ( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) { float panGainsOut[2]; float panGainsIn[2]; diff --git a/lib_dec/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c similarity index 99% rename from lib_dec/ivas_dirac_decorr_dec.c rename to lib_rend/ivas_dirac_decorr_dec.c index 3687ed53b1..e831188881 100644 --- a/lib_dec/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -37,9 +37,9 @@ #include "cnst.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" -#include "ivas_rom_com.h" #include "ivas_rom_dec.h" #ifdef DEBUGGING #include "debug.h" diff --git a/lib_dec/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c similarity index 99% rename from lib_dec/ivas_dirac_onsets_dec.c rename to lib_rend/ivas_dirac_onsets_dec.c index c094b45ff6..8a03dc2c50 100644 --- a/lib_dec/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -36,6 +36,7 @@ #include "cnst.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_rend.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "ivas_rom_dec.h" diff --git a/lib_dec/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c similarity index 79% rename from lib_dec/ivas_dirac_output_synthesis_dec.c rename to lib_rend/ivas_dirac_output_synthesis_dec.c index 68bd32528f..b4b9f71e01 100644 --- a/lib_dec/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -37,6 +37,7 @@ #include "cnst.h" #include "prot.h" #include "ivas_prot.h" +#include "ivas_prot_rend.h" #include "ivas_stat_dec.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -87,11 +88,12 @@ static void normalizePanningGains( float *direct_response, const int16_t num_cha *------------------------------------------------------------------------*/ ivas_error ivas_dirac_dec_output_synthesis_open( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t nchan_transport, /* i : number of transport channels */ - const int32_t output_Fs, /* i : output sampling rate */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + RENDERER_TYPE renderer_type, /* i : renderer type */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { int16_t idx, ch_idx; @@ -101,20 +103,20 @@ ivas_error ivas_dirac_dec_output_synthesis_open( float temp_alpha_synthesis[CLDFB_NO_CHANNELS_MAX]; /* pointers to structs for allocation */ - DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /* check / set input parameters */ - assert( hDirAC->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" ); - assert( hDirAC->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!" ); - assert( hDirAC->num_outputs_diff > 0 ); - assert( hDirAC->slot_size > 0 ); - assert( hDirAC->hOutSetup.is_loudspeaker_setup == 0 || hDirAC->hOutSetup.is_loudspeaker_setup == 1 ); - assert( hDirAC->diffuse_response_function != NULL ); + assert( hSpatParamRendCom->num_freq_bands > 0 && "Error: Number of frequency bands <= 0!" ); + assert( hDirACRend->hOutSetup.nchan_out_woLFE > 0 && "Error: Number of output channels > 0!" ); + assert( hDirACRend->num_outputs_diff > 0 ); + assert( hSpatParamRendCom->slot_size > 0 ); + assert( hDirACRend->hOutSetup.is_loudspeaker_setup == 0 || hDirACRend->hOutSetup.is_loudspeaker_setup == 1 ); + assert( hDirACRend->diffuse_response_function != NULL ); - if ( hDirAC->proto_signal_decorr_on ) + if ( hDirACRend->proto_signal_decorr_on ) { - dirac_output_synthesis_params->max_band_decorr = hDirAC->h_freq_domain_decorr_ap_params->max_band_decorr; + dirac_output_synthesis_params->max_band_decorr = hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr; } else { @@ -126,16 +128,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *-----------------------------------------------------------------*/ dirac_output_synthesis_state->diffuse_responses_square = NULL; - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( 2 * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->diffuse_responses_square = (float *) malloc( hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } @@ -143,16 +145,16 @@ ivas_error ivas_dirac_dec_output_synthesis_open( /* prototype power buffers */ dirac_output_synthesis_state->proto_power_smooth_prev = NULL; - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_protos_dir * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->proto_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) + if ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { - if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->proto_power_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } @@ -171,42 +173,42 @@ ivas_error ivas_dirac_dec_output_synthesis_open( /* target PSD buffers */ if ( hodirac_flag ) { - size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS; + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } else { - size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir; + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } @@ -219,23 +221,23 @@ ivas_error ivas_dirac_dec_output_synthesis_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } - else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirAC->synthesisConf != DIRAC_SYNTHESIS_MONO ) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_diff * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } } else { - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hDirAC->num_freq_bands * hDirAC->num_outputs_dir * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } @@ -246,32 +248,32 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *-----------------------------------------------------------------*/ /* compute alpha */ - if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) + if ( !( renderer_type == RENDERER_BINAURAL_PARAMETRIC || renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { - computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs ); + computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS, DIRAC_ALPHA_MAX, &dirac_output_synthesis_params->numAlphas, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); if ( ( dirac_output_synthesis_params->alpha_synthesis = (float *) malloc( dirac_output_synthesis_params->numAlphas * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis, dirac_output_synthesis_params->numAlphas ); - computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hDirAC->slot_size, hDirAC->num_freq_bands, hDirAC->frequency_axis, output_Fs ); + computeAlphaSynthesis( temp_alpha_synthesis, DIRAC_AVG_LENGTH_SYNTH_MS_FAST, DIRAC_ALPHA_MAX_FAST, &dirac_output_synthesis_params->numAlphasFast, hSpatParamRendCom->slot_size, hSpatParamRendCom->num_freq_bands, hDirACRend->frequency_axis, output_Fs ); if ( ( dirac_output_synthesis_params->alpha_synthesis_fast = (float *) malloc( dirac_output_synthesis_params->numAlphasFast * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } mvr2r( temp_alpha_synthesis, dirac_output_synthesis_params->alpha_synthesis_fast, dirac_output_synthesis_params->numAlphasFast ); - if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->reference_power_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hDirAC->num_freq_bands * sizeof( float ) ) ) == NULL ) + if ( ( dirac_output_synthesis_state->direction_smoothness_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hDirAC->num_freq_bands ); - set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hDirAC->num_freq_bands ); + set_zero( dirac_output_synthesis_state->reference_power_smooth_prev, hSpatParamRendCom->num_freq_bands ); + set_zero( dirac_output_synthesis_state->direction_smoothness_prev, hSpatParamRendCom->num_freq_bands ); } else { @@ -288,13 +290,13 @@ ivas_error ivas_dirac_dec_output_synthesis_open( } /* prepare diffuse response function */ - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { num_diffuse_responses = 2; } else { - num_diffuse_responses = hDirAC->hOutSetup.nchan_out_woLFE; + num_diffuse_responses = hDirACRend->hOutSetup.nchan_out_woLFE; } if ( dirac_output_synthesis_state->diffuse_responses_square != NULL ) @@ -302,34 +304,34 @@ ivas_error ivas_dirac_dec_output_synthesis_open( for ( ch_idx = 0; ch_idx < num_diffuse_responses; ++ch_idx ) { /*dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = pow(dirac_output_synthesis_params->diffuse_response_function[ch_idx]/max_response, 2.0f);*/ - tmp = hDirAC->diffuse_response_function[ch_idx]; + tmp = hDirACRend->diffuse_response_function[ch_idx]; dirac_output_synthesis_state->diffuse_responses_square[ch_idx] = tmp * tmp; } } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { int16_t diff_compensation_order; float diff_nrg_total, diff_nrg, diff_nrg_trans, diff_nrg_decorr; diff_compensation_order = nchan_transport >= 3 ? 3 : 2; /* compensate missing diffuseness modelling up order 2, except for HR*/ - diff_compensation_order = min( diff_compensation_order, hDirAC->hOutSetup.ambisonics_order ); + diff_compensation_order = min( diff_compensation_order, hDirACRend->hOutSetup.ambisonics_order ); diff_nrg_total = 0; diff_nrg_trans = 0; diff_nrg_decorr = 0; for ( ch_idx = 0; ch_idx < ( diff_compensation_order + 1 ) * ( diff_compensation_order + 1 ); ch_idx++ ) { - diff_nrg = hDirAC->diffuse_response_function[ch_idx] * hDirAC->diffuse_response_function[ch_idx]; + diff_nrg = hDirACRend->diffuse_response_function[ch_idx] * hDirACRend->diffuse_response_function[ch_idx]; diff_nrg_total += diff_nrg; /* is it a transport channel?*/ - if ( ch_idx == 0 || hDirAC->proto_index_dir[ch_idx] != 0 ) + if ( ch_idx == 0 || hDirACRend->proto_index_dir[ch_idx] != 0 ) { diff_nrg_trans += diff_nrg; } /* is it a decorrelated or transport channel?*/ - if ( ch_idx < hDirAC->num_outputs_diff ) + if ( ch_idx < hDirACRend->num_outputs_diff ) { diff_nrg_decorr += diff_nrg; } @@ -354,9 +356,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open( *------------------------------------------------------------------------*/ void ivas_dirac_dec_output_synthesis_init( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */ - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { int16_t size; @@ -364,8 +367,8 @@ void ivas_dirac_dec_output_synthesis_init( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /*-----------------------------------------------------------------* * init outputSynthesisPSD_Init @@ -374,45 +377,45 @@ void ivas_dirac_dec_output_synthesis_init( /* initialize buffers */ if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL ) { - set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir ); + set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } if ( hodirac_flag ) { - size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir * DIRAC_HO_NUMSECTORS; + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; } else { - size = hDirAC->num_freq_bands * hDirAC->num_outputs_dir; + size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff ); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); } - else if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_diff ); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); } else { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir ); + set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } if ( h_dirac_output_synthesis_state->proto_power_smooth_prev != NULL ) { - set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hDirAC->num_freq_bands * hDirAC->num_protos_dir ); + set_zero( h_dirac_output_synthesis_state->proto_power_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir ); } set_zero( h_dirac_output_synthesis_state->gains_dir_prev, size ); - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirAC->num_outputs_diff ); + set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); } else { - set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hDirAC->num_freq_bands * hDirAC->num_outputs_dir ); + set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); } if ( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev != NULL ) @@ -431,12 +434,12 @@ void ivas_dirac_dec_output_synthesis_init( *------------------------------------------------------------------------*/ void ivas_dirac_dec_output_synthesis_close( - DIRAC_DEC_HANDLE hDirAC /* i/o: DirAC handle */ + DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */ ) { /* pointers to structs for allocation */ - DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); + DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + DIRAC_OUTPUT_SYNTHESIS_STATE *dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); /*-----------------------------------------------------------------* * memory deallocation @@ -537,15 +540,16 @@ void ivas_dirac_dec_output_synthesis_process_slot( const int16_t *azimuth, const int16_t *elevation, const float *diffuseness, - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const int16_t sh_rot_max_order, const float *p_Rmat, /* i : rotation matrix */ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ const int16_t nchan_transport, /* i : number of transport channels*/ const int16_t md_idx, - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -) + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const int16_t dec_param_estim ) { int16_t num_freq_bands, num_channels_dir; int16_t num_freq_bands_diff, num_channels_diff; @@ -555,8 +559,8 @@ void ivas_dirac_dec_output_synthesis_process_slot( DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; - h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); h_dirac_output_synthesis_state->onset_filter = onset; @@ -565,19 +569,20 @@ void ivas_dirac_dec_output_synthesis_process_slot( *-----------------------------------------------------------------*/ /* collect some often used parameters */ - num_freq_bands = hDirAC->num_freq_bands; - num_channels_dir = hDirAC->num_outputs_dir; - num_channels_diff = hDirAC->num_outputs_diff; + num_freq_bands = hSpatParamRendCom->num_freq_bands; + num_channels_dir = hDirACRend->num_outputs_dir; + num_channels_diff = hDirACRend->num_outputs_diff; num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { num_channels_dir = hOutSetup.nchan_out_woLFE; } - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac_flag ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD && hodirac_flag ) { - ivas_dirac_dec_compute_directional_responses( hDirAC, + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, hVBAPdata, NULL, #ifdef MASA_AND_OBJECTS @@ -592,157 +597,160 @@ void ivas_dirac_dec_output_synthesis_process_slot( hodirac_flag ); } - if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac_flag ) + if ( dec_param_estim == FALSE && hodirac_flag ) { - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - v_multc( hDirAC->energy_ratio1[md_idx], -1.f, aux_buf, num_freq_bands ); + v_multc( hSpatParamRendCom->energy_ratio1[md_idx], -1.f, aux_buf, num_freq_bands ); v_addc( aux_buf, 1.f, aux_buf, num_freq_bands ); - mvr2r( hDirAC->energy_ratio1[md_idx], + mvr2r( hSpatParamRendCom->energy_ratio1[md_idx], h_dirac_output_synthesis_state->direct_power_factor, num_freq_bands ); mvr2r( aux_buf, h_dirac_output_synthesis_state->diffuse_power_factor, num_freq_bands ); - v_multc( hDirAC->energy_ratio2[md_idx], -1.f, aux_buf, num_freq_bands ); + v_multc( hSpatParamRendCom->energy_ratio2[md_idx], -1.f, aux_buf, num_freq_bands ); v_addc( aux_buf, 1.f, aux_buf, num_freq_bands ); - mvr2r( hDirAC->energy_ratio2[md_idx], - &h_dirac_output_synthesis_state->direct_power_factor[hDirAC->num_freq_bands], + mvr2r( hSpatParamRendCom->energy_ratio2[md_idx], + &h_dirac_output_synthesis_state->direct_power_factor[hSpatParamRendCom->num_freq_bands], num_freq_bands ); mvr2r( aux_buf, - &h_dirac_output_synthesis_state->diffuse_power_factor[hDirAC->num_freq_bands], + &h_dirac_output_synthesis_state->diffuse_power_factor[hSpatParamRendCom->num_freq_bands], num_freq_bands ); } else { ivas_dirac_dec_compute_gain_factors( num_freq_bands, - hDirAC->diffuseness_vector[md_idx], + hSpatParamRendCom->diffuseness_vector[md_idx], h_dirac_output_synthesis_params->max_band_decorr, h_dirac_output_synthesis_state->direct_power_factor, h_dirac_output_synthesis_state->diffuse_power_factor ); } } - else if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { - /* compute direct responses */ - ivas_dirac_dec_compute_directional_responses( hDirAC, - hVBAPdata, - NULL, + else // ( dec_param_estim == TRUE ) + if ( dec_param_estim == TRUE ) + { + + /* compute direct responses */ + ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, + hDirACRend, + hVBAPdata, + NULL, #ifdef MASA_AND_OBJECTS - NULL, + NULL, #endif - azimuth, - elevation, - md_idx, - NULL, - sh_rot_max_order, - p_Rmat, - hodirac_flag ); - - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - ivas_dirac_dec_compute_gain_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); + azimuth, + elevation, + md_idx, + NULL, + sh_rot_max_order, + p_Rmat, + hodirac_flag ); + + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_gain_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); - v_multc( h_dirac_output_synthesis_state->direct_power_factor, - 0.25f, - h_dirac_output_synthesis_state->direct_power_factor, - num_freq_bands ); - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - 0.25f, - h_dirac_output_synthesis_state->diffuse_power_factor, - num_freq_bands ); + v_multc( h_dirac_output_synthesis_state->direct_power_factor, + 0.25f, + h_dirac_output_synthesis_state->direct_power_factor, + num_freq_bands ); + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + 0.25f, + h_dirac_output_synthesis_state->diffuse_power_factor, + num_freq_bands ); - /*Direct gain*/ - for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) - { - int16_t k; - if ( ch_idx != 0 ) + /*Direct gain*/ + for ( ch_idx = 0; ch_idx < min( 4, nchan_transport ); ch_idx++ ) { - float a, b, c; - - /*Directonal sound gain nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) + int16_t k; + if ( ch_idx != 0 ) { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + float a, b, c; + + /*Directonal sound gain nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + } + for ( ; k < num_freq_bands; k++ ) + { + a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; + b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); + c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + } } - for ( ; k < num_freq_bands; k++ ) + else { - a = h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands + k]; - b = reference_power[k + num_freq_bands] / ( reference_power[k + ( ch_idx + 1 ) * num_freq_bands] + EPSILON ); - c = 1.f + ( 1.f / 6.f ) * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ); /*Diffuseness modellling nrg compensation*/ - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( diffuseness[k] * c + ( ( 1.f - diffuseness[k] ) * a * a * b ) ); + /*Diffuseness modellling nrg compensation*/ + for ( k = 0; k < num_freq_bands_diff; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); + } + for ( ; k < num_freq_bands; k++ ) + { + h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); + } } } - else + + /*Directional gain (panning)*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) { - /*Diffuseness modellling nrg compensation*/ - for ( k = 0; k < num_freq_bands_diff; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor_decorr - 1.f ) ); - } - for ( ; k < num_freq_bands; k++ ) - { - h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands + k] += 0.25f * sqrtf( 1.0f + diffuseness[k] * 0.5f * ( h_dirac_output_synthesis_params->diffuse_compensation_factor - 1.f ) ); - } + v_mult( h_dirac_output_synthesis_state->direct_power_factor, + &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], + aux_buf, + num_freq_bands ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], + num_freq_bands ); } - } - /*Directional gain (panning)*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_dir; ch_idx++ ) - { - v_mult( h_dirac_output_synthesis_state->direct_power_factor, - &h_dirac_output_synthesis_state->direct_responses[ch_idx * num_freq_bands], - aux_buf, - num_freq_bands ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - &h_dirac_output_synthesis_state->cy_cross_dir_smooth[ch_idx * num_freq_bands], - num_freq_bands ); - } + /*Diffuse gain*/ + for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + { + v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, + hDirACRend->diffuse_response_function[ch_idx], + aux_buf, + num_freq_bands_diff ); + + v_add( aux_buf, + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], + num_freq_bands_diff ); + } - /*Diffuse gain*/ - for ( ch_idx = min( 4, nchan_transport ); ch_idx < num_channels_diff; ch_idx++ ) + return; + } + else { - v_multc( h_dirac_output_synthesis_state->diffuse_power_factor, - hDirAC->diffuse_response_function[ch_idx], - aux_buf, - num_freq_bands_diff ); - - v_add( aux_buf, - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - &h_dirac_output_synthesis_state->cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], - num_freq_bands_diff ); + /* compute reference and diffuse power factor for this frame */ + ivas_dirac_dec_compute_power_factors( num_freq_bands, + diffuseness, + h_dirac_output_synthesis_params->max_band_decorr, + h_dirac_output_synthesis_state->direct_power_factor, + h_dirac_output_synthesis_state->diffuse_power_factor ); } - - return; - } - else - { - /* compute reference and diffuse power factor for this frame */ - ivas_dirac_dec_compute_power_factors( num_freq_bands, - diffuseness, - h_dirac_output_synthesis_params->max_band_decorr, - h_dirac_output_synthesis_state->direct_power_factor, - h_dirac_output_synthesis_state->diffuse_power_factor ); } - } diff_start_band = 0; if ( h_dirac_output_synthesis_params->use_onset_filters ) { computeTargetPSDs_diffuse_with_onsets( num_channels_dir, num_freq_bands, h_dirac_output_synthesis_params->max_band_decorr, - hDirAC->proto_index_diff, + hDirACRend->proto_index_diff, h_dirac_output_synthesis_state->diffuse_power_factor, reference_power, h_dirac_output_synthesis_state->diffuse_responses_square, @@ -753,7 +761,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( } /* process other PSDs only slot wise for 4 transport channels */ - if ( hDirAC->hConfig->dec_param_estim == TRUE ) + if ( dec_param_estim == TRUE ) { computeTargetPSDs_direct( num_channels_dir, num_freq_bands, h_dirac_output_synthesis_state->direct_power_factor, reference_power, h_dirac_output_synthesis_state->direct_responses, h_dirac_output_synthesis_state->direct_responses_square, h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth ); @@ -773,13 +781,14 @@ void ivas_dirac_dec_output_synthesis_process_slot( void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const int16_t nchan_transport, /* i : number of transport channels */ const int16_t nbslots, /* i : number of slots to process */ const float *onset_filter, float *diffuseness, - const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ -) + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const int16_t dec_param_estim ) { int16_t buf_idx, ch_idx, i, l; int16_t num_freq_bands, num_freq_bands_diff; @@ -802,15 +811,15 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( float ratio[DIRAC_HO_NUMSECTORS * CLDFB_NO_CHANNELS_MAX]; /* collect some often used parameters */ - h_dirac_output_synthesis_params = hDirAC->h_output_synthesis_psd_params; - h_dirac_output_synthesis_state = hDirAC->h_output_synthesis_psd_state; - proto_direct_index = hDirAC->proto_index_dir; + h_dirac_output_synthesis_params = hDirACRend->h_output_synthesis_psd_params; + h_dirac_output_synthesis_state = hDirACRend->h_output_synthesis_psd_state; + proto_direct_index = hDirACRend->proto_index_dir; - num_protos_dir = hDirAC->num_protos_dir; - num_freq_bands = hDirAC->num_freq_bands; + num_protos_dir = hDirACRend->num_protos_dir; + num_freq_bands = hSpatParamRendCom->num_freq_bands; num_freq_bands_diff = h_dirac_output_synthesis_params.max_band_decorr; - num_channels_dir = hDirAC->num_outputs_dir; - num_channels_diff = hDirAC->num_outputs_diff; + num_channels_dir = hDirACRend->num_outputs_dir; + num_channels_diff = hDirACRend->num_outputs_diff; nchan_transport_foa = min( 4, nchan_transport ); @@ -820,7 +829,6 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( if ( hodirac_flag ) { - assert( hDirAC->hConfig->dec_param_estim == FALSE ); /*Direct gain*/ for ( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) { @@ -845,7 +853,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( for ( l = 0; l < num_freq_bands; l++ ) { aux_buf[l] = 1.f - diffuseness[l]; - ratio[l] = 1.f - h_dirac_output_synthesis_state.direct_power_factor[hDirAC->num_freq_bands + l]; + ratio[l] = 1.f - h_dirac_output_synthesis_state.direct_power_factor[hSpatParamRendCom->num_freq_bands + l]; ratio[l + num_freq_bands] = 1.f - ratio[l]; } @@ -866,12 +874,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( for ( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { v_multc( h_dirac_output_synthesis_state.diffuse_power_factor, - hDirAC->diffuse_response_function[ch_idx], + hDirACRend->diffuse_response_function[ch_idx], &h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], num_freq_bands_diff ); } } - else if ( hDirAC->hConfig->dec_param_estim == FALSE ) + else if ( dec_param_estim == FALSE ) { /*Direct gain*/ for ( ch_idx = 0; ch_idx < nchan_transport_foa; ch_idx++ ) @@ -906,7 +914,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( /*Diffuse gain*/ for ( ch_idx = nchan_transport_foa; ch_idx < num_channels_diff; ch_idx++ ) { - v_multc( h_dirac_output_synthesis_state.diffuse_power_factor, hDirAC->diffuse_response_function[ch_idx], &h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], num_freq_bands_diff ); + v_multc( h_dirac_output_synthesis_state.diffuse_power_factor, hDirACRend->diffuse_response_function[ch_idx], &h_dirac_output_synthesis_state.cy_auto_diff_smooth[ch_idx * num_freq_bands_diff], num_freq_bands_diff ); } } @@ -1120,8 +1128,8 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( for ( l = 0; l < num_freq_bands_diff; l++ ) { g = g1 * ( *( p_gains_diff++ ) ) + g2 * ( *( p_gains_diff_prev++ ) ); - output_real[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); /* maps ch_idx 5 to 8 */ - output_imag[l * num_channels_dir + hDirAC->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); + output_real[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); /* maps ch_idx 5 to 8 */ + output_imag[l * num_channels_dir + hDirACRend->sba_map_tc[ch_idx]] += g * ( *( p_proto++ ) ); } } else @@ -1138,14 +1146,14 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( * Copy output or HOA decoder *-----------------------------------------------------------------*/ - if ( hDirAC->hOutSetup.is_loudspeaker_setup && hDirAC->hoa_decoder != NULL ) + if ( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { float *p_real, *p_imag; const float *hoa_decoder; - hoa_decoder = hDirAC->hoa_decoder; + hoa_decoder = hDirACRend->hoa_decoder; - for ( ch_idx = 0; ch_idx < hDirAC->hOutSetup.nchan_out_woLFE; ch_idx++ ) + for ( ch_idx = 0; ch_idx < hDirACRend->hOutSetup.nchan_out_woLFE; ch_idx++ ) { p_real = RealBuffer[ch_idx][buf_idx]; p_imag = ImagBuffer[ch_idx][buf_idx]; @@ -1219,11 +1227,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const int16_t nbslots, /* i : number of slots to process */ float *diffuseness_vector, float *reference_power_smooth, - float qualityBasedSmFactor ) + float qualityBasedSmFactor, + const int16_t enc_param_start_band ) { int16_t buf_idx, num_freq_bands; int16_t diff_start_band; @@ -1256,24 +1266,24 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( push_wmops( "dirac_out_synth_sfr" ); - h_dirac_output_synthesis_params = &( hDirAC->h_output_synthesis_psd_params ); - h_dirac_output_synthesis_state = &( hDirAC->h_output_synthesis_psd_state ); - proto_direct_index = hDirAC->proto_index_dir; - num_protos_dir = hDirAC->num_protos_dir; - nchan_out_woLFE = hDirAC->hOutSetup.nchan_out_woLFE; + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); + proto_direct_index = hDirACRend->proto_index_dir; + num_protos_dir = hDirACRend->num_protos_dir; + nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; /* collect some often used parameters */ - num_freq_bands = hDirAC->num_freq_bands; + num_freq_bands = hSpatParamRendCom->num_freq_bands; /*-----------------------------------------------------------------* * compute target PSDs *-----------------------------------------------------------------*/ - if ( hDirAC->hConfig->enc_param_start_band == 0 ) + if ( enc_param_start_band == 0 ) { diff_start_band = h_dirac_output_synthesis_params->use_onset_filters == 1 ? h_dirac_output_synthesis_params->max_band_decorr : 0; - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { nchan_target_psds = 2; } @@ -1301,11 +1311,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( * compute variables for stereo transport signal type detection *-----------------------------------------------------------------*/ - if ( hDirAC->masa_stereo_type_detect != NULL ) + if ( hDirACRend->masa_stereo_type_detect != NULL ) { + MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect = hDirACRend->masa_stereo_type_detect; + p_cy_auto_dir_smooth = h_dirac_output_synthesis_state->cy_auto_dir_smooth; p_cy_auto_diff_smooth = h_dirac_output_synthesis_state->cy_auto_diff_smooth; - if ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { target_power_y = p_cy_auto_dir_smooth[num_freq_bands] / ( sqrtf( h_dirac_output_synthesis_state->direct_power_factor[0] ) + EPSILON ); target_power_y += p_cy_auto_diff_smooth[num_freq_bands] / ( sqrtf( h_dirac_output_synthesis_state->diffuse_power_factor[0] ) + EPSILON ); @@ -1314,19 +1326,19 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( { target_power_y = p_cy_auto_dir_smooth[num_freq_bands] + p_cy_auto_diff_smooth[num_freq_bands]; } - subtract_power_y = hDirAC->masa_stereo_type_detect->subtract_power_y; + subtract_power_y = masa_stereo_type_detect->subtract_power_y; a = 0.0004f; /* Temporal smoothing coefficient */ b = 1.0f - a; /* Temporal smoothing coefficient */ - hDirAC->masa_stereo_type_detect->target_power_y_smooth = a * target_power_y + b * hDirAC->masa_stereo_type_detect->target_power_y_smooth; - hDirAC->masa_stereo_type_detect->subtract_power_y_smooth = a * subtract_power_y + b * hDirAC->masa_stereo_type_detect->subtract_power_y_smooth; + masa_stereo_type_detect->target_power_y_smooth = a * target_power_y + b * masa_stereo_type_detect->target_power_y_smooth; + masa_stereo_type_detect->subtract_power_y_smooth = a * subtract_power_y + b * masa_stereo_type_detect->subtract_power_y_smooth; - subtract_target_ratio = hDirAC->masa_stereo_type_detect->subtract_power_y_smooth / ( hDirAC->masa_stereo_type_detect->target_power_y_smooth + EPSILON ); + subtract_target_ratio = masa_stereo_type_detect->subtract_power_y_smooth / ( masa_stereo_type_detect->target_power_y_smooth + EPSILON ); subtract_target_ratio_db = 10.0f * log10f( subtract_target_ratio ); - hDirAC->masa_stereo_type_detect->subtract_target_ratio_db = subtract_target_ratio_db; + masa_stereo_type_detect->subtract_target_ratio_db = subtract_target_ratio_db; - hDirAC->masa_stereo_type_detect->subtract_power_y = 0.0f; + masa_stereo_type_detect->subtract_power_y = 0.0f; } /*-----------------------------------------------------------------* @@ -1735,9 +1747,10 @@ static void ivas_dirac_dec_get_response_split_order( *------------------------------------------------------------------------*/ void ivas_dirac_dec_compute_directional_responses( - DIRAC_DEC_HANDLE hDirAC, /* i/o: DirAC handle */ - const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ - const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ + const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ #ifdef MASA_AND_OBJECTS MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ #endif @@ -1768,29 +1781,29 @@ void ivas_dirac_dec_compute_directional_responses( elevation2 = NULL; transport_signal_type = MASA_STEREO_NOT_DEFINED; - if ( hDirAC->masa_stereo_type_detect != NULL ) + if ( hDirACRend->masa_stereo_type_detect != NULL ) { - dipole_freq_range[0] = hDirAC->masa_stereo_type_detect->dipole_freq_range[0]; - dipole_freq_range[1] = hDirAC->masa_stereo_type_detect->dipole_freq_range[1]; - transport_signal_type = hDirAC->masa_stereo_type_detect->masa_stereo_type; + dipole_freq_range[0] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[0]; + dipole_freq_range[1] = hDirACRend->masa_stereo_type_detect->dipole_freq_range[1]; + transport_signal_type = hDirACRend->masa_stereo_type_detect->masa_stereo_type; } - num_channels_dir = hDirAC->num_outputs_dir; + num_channels_dir = hDirACRend->num_outputs_dir; #ifdef MASA_AND_OBJECTS - if ( hDirAC->numParametricDirections == 2 ) + if ( hSpatParamRendCom->numParametricDirections == 2 ) #else - if ( hDirAC->numSimultaneousDirections == 2 ) + if ( hSpatParamRendCom->numSimultaneousDirections == 2 ) #endif { - azimuth2 = hDirAC->azimuth2[md_idx]; - elevation2 = hDirAC->elevation2[md_idx]; + azimuth2 = hSpatParamRendCom->azimuth2[md_idx]; + elevation2 = hSpatParamRendCom->elevation2[md_idx]; } codingBand = -1; assert( num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high" ); - for ( k = 0; k < hDirAC->num_freq_bands; ++k ) + for ( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { if ( hMasa != NULL && k == MASA_band_grouping_24[hMasa->data.band_mapping[codingBand + 1]] ) { @@ -1799,24 +1812,24 @@ void ivas_dirac_dec_compute_directional_responses( if ( hMasa != NULL && k > MASA_band_grouping_24[hMasa->data.band_mapping[codingBand]] && k < MASA_band_grouping_24[hMasa->data.band_mapping[codingBand + 1]] && - k != hDirAC->h_output_synthesis_psd_params.max_band_decorr ) + k != hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) { /* Panning gains have to be computed only for the first bin of the coding band in MASA, for other bins the previous values can be used */ - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - mvr2r_inc( &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k - 1], - hDirAC->num_freq_bands, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k], - hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k - 1], + hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } - mvr2r_inc( &hDirAC->h_output_synthesis_psd_state.direct_responses[k - 1], - hDirAC->num_freq_bands, - &hDirAC->h_output_synthesis_psd_state.direct_responses[k], - hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses[k - 1], + hSpatParamRendCom->num_freq_bands, + &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { /* HOA3 PANNING */ - if ( hDirAC->panningConf == DIRAC_PANNING_HOA3 ) + if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) { set_f( direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS ); set_f( direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS ); @@ -1832,41 +1845,40 @@ void ivas_dirac_dec_compute_directional_responses( } else { - ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirAC->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response( azimuth[k], elevation[k], direct_response_hoa, hDirACRend->hOutSetup.ambisonics_order ); if ( hodirac_flag ) { - ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirAC->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response( azimuth2[k], elevation2[k], direct_response_dir2, hDirACRend->hOutSetup.ambisonics_order ); } } - if ( hMasa == NULL && hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hMasa == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - mvr2r_inc( direct_response_hoa, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response_hoa, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); if ( hodirac_flag ) { - mvr2r_inc( direct_response_dir2, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k + hDirAC->num_freq_bands * num_channels_dir], hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response_dir2, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } } - else if ( ( ( hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( hMasa != NULL ) ) || - hDirAC->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirAC->synthesisConf == DIRAC_SYNTHESIS_MONO ) + else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( hMasa != NULL ) ) || + hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { /* Synthesize the first direction */ - spreadCoherencePanningHoa( azimuth[k], elevation[k], hDirAC->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirAC->hOutSetup.ambisonics_order ); - + spreadCoherencePanningHoa( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_hoa, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); /* Synthesize the second direction and combine the gains */ #ifdef MASA_AND_OBJECTS - if ( hDirAC->numParametricDirections == 2 ) + if ( hSpatParamRendCom->numParametricDirections == 2 ) #else - if ( hDirAC->numSimultaneousDirections == 2 ) + if ( hSpatParamRendCom->numSimultaneousDirections == 2 ) #endif { - spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirAC->hOutSetup.ambisonics_order ); + spreadCoherencePanningHoa( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hDirACRend->hOutSetup.ambisonics_order ); /* Combine gains from the two directions */ - totalDirect = hDirAC->energy_ratio1[md_idx][k] + hDirAC->energy_ratio2[md_idx][k] + EPSILON; - directRatio[0] = hDirAC->energy_ratio1[md_idx][k] / totalDirect; - directRatio[1] = hDirAC->energy_ratio2[md_idx][k] / totalDirect; + totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON; + directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect; + directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect; for ( l = 0; l < num_channels_dir; l++ ) { direct_response_hoa[l] *= directRatio[0]; @@ -1876,7 +1888,7 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef MASA_AND_OBJECTS // Todo OMASA JBM: Here we probably need to use md_idx for meta access - if ( hDirAC->numIsmDirections > 0 ) + if ( hSpatParamRendCom->numIsmDirections > 0 ) { int16_t dir; float direct_response_temp[MAX_OUTPUT_CHANNELS]; @@ -1886,33 +1898,33 @@ void ivas_dirac_dec_compute_directional_responses( set_zero( direct_response_ism, num_channels_dir ); - for ( dir = 0; dir < hDirAC->numIsmDirections; dir++ ) + for ( dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { if ( hMasaIsm->ism_is_edited[dir] ) { - ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order ); } else { - ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], direct_response_temp, hDirAC->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response( hMasaIsm->azimuth_ism[dir][hSpatParamRendCom->dirac_read_idx], hMasaIsm->elevation_ism[dir][hSpatParamRendCom->dirac_read_idx], direct_response_temp, hDirACRend->hOutSetup.ambisonics_order ); } for ( l = 0; l < num_channels_dir; l++ ) { - direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hSpatParamRendCom->dirac_read_idx][k]; } } - masaDirect = hDirAC->energy_ratio1[hDirAC->dirac_read_idx][k] + EPSILON; - if ( hDirAC->numParametricDirections == 2 ) + masaDirect = hSpatParamRendCom->energy_ratio1[hSpatParamRendCom->dirac_read_idx][k] + EPSILON; + if ( hSpatParamRendCom->numParametricDirections == 2 ) { - masaDirect += hDirAC->energy_ratio2[hDirAC->dirac_read_idx][k]; + masaDirect += hSpatParamRendCom->energy_ratio2[hSpatParamRendCom->dirac_read_idx][k]; } - ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; - for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) + ismDirect = hMasaIsm->energy_ratio_ism[0][hSpatParamRendCom->dirac_read_idx][k]; + for ( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; + ismDirect += hMasaIsm->energy_ratio_ism[dir][hSpatParamRendCom->dirac_read_idx][k]; } totalDirect = masaDirect + ismDirect; @@ -1937,10 +1949,10 @@ void ivas_dirac_dec_compute_directional_responses( /* Set computed gains */ direct_response = direct_response_hoa; - if ( hDirAC->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); - mvr2r_inc( direct_response_square, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k], hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); if ( transport_signal_type == MASA_STEREO_SPACED_MICS ) { @@ -1952,38 +1964,37 @@ void ivas_dirac_dec_compute_directional_responses( } else { - set_f( direct_response, 1.0f, hDirAC->num_protos_ambi ); + set_f( direct_response, 1.0f, hDirACRend->num_protos_ambi ); } } - mvr2r_inc( direct_response, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { assert( 0 && "Not supported synthesis method!" ); } } - else if ( hDirAC->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ + else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ { /* Synthesize the first direction */ - spreadCoherencePanningVbap( azimuth[k], elevation[k], hDirAC->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata ); + spreadCoherencePanningVbap( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], direct_response_ls, num_channels_dir, hVBAPdata ); normalizePanningGains( direct_response_ls, num_channels_dir ); /* Synthesize the second direction and combine the gains */ #ifdef MASA_AND_OBJECTS - if ( hDirAC->numParametricDirections == 2 ) + if ( hSpatParamRendCom->numParametricDirections == 2 ) #else - if ( hDirAC->numSimultaneousDirections == 2 ) + if ( hSpatParamRendCom->numSimultaneousDirections == 2 ) #endif - { - spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hDirAC->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata ); + spreadCoherencePanningVbap( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], direct_response_dir2, num_channels_dir, hVBAPdata ); normalizePanningGains( direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ - totalDirect = hDirAC->energy_ratio1[md_idx][k] + hDirAC->energy_ratio2[md_idx][k] + EPSILON; - directRatio[0] = hDirAC->energy_ratio1[md_idx][k] / totalDirect; - directRatio[1] = hDirAC->energy_ratio2[md_idx][k] / totalDirect; + totalDirect = hSpatParamRendCom->energy_ratio1[md_idx][k] + hSpatParamRendCom->energy_ratio2[md_idx][k] + EPSILON; + directRatio[0] = hSpatParamRendCom->energy_ratio1[md_idx][k] / totalDirect; + directRatio[1] = hSpatParamRendCom->energy_ratio2[md_idx][k] / totalDirect; for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ls[l] *= directRatio[0]; @@ -1994,7 +2005,7 @@ void ivas_dirac_dec_compute_directional_responses( #ifdef MASA_AND_OBJECTS // Todo OMASA JBM: Here we also probably need md_idx - if ( hDirAC->numIsmDirections > 0 ) + if ( hSpatParamRendCom->numIsmDirections > 0 ) { int16_t dir; float direct_response_temp[MAX_OUTPUT_CHANNELS]; @@ -2004,7 +2015,7 @@ void ivas_dirac_dec_compute_directional_responses( set_zero( direct_response_ism, num_channels_dir ); - for ( dir = 0; dir < hDirAC->numIsmDirections; dir++ ) + for ( dir = 0; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { if ( hMasaIsm->ism_is_edited[dir] ) { @@ -2012,26 +2023,26 @@ void ivas_dirac_dec_compute_directional_responses( } else { - vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][hDirAC->dirac_read_idx], hMasaIsm->elevation_ism[dir][hDirAC->dirac_read_idx], 1 ); + vbap_determine_gains( hVBAPdata, direct_response_temp, hMasaIsm->azimuth_ism[dir][hSpatParamRendCom->dirac_read_idx], hMasaIsm->elevation_ism[dir][hSpatParamRendCom->dirac_read_idx], 1 ); } for ( l = 0; l < num_channels_dir; l++ ) { - direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; + direct_response_ism[l] += direct_response_temp[l] * hMasaIsm->energy_ratio_ism[dir][hSpatParamRendCom->dirac_read_idx][k]; } } normalizePanningGains( direct_response_ism, num_channels_dir ); - masaDirect = hDirAC->energy_ratio1[hDirAC->dirac_read_idx][k] + EPSILON; - if ( hDirAC->numParametricDirections == 2 ) + masaDirect = hSpatParamRendCom->energy_ratio1[hSpatParamRendCom->dirac_read_idx][k] + EPSILON; + if ( hSpatParamRendCom->numParametricDirections == 2 ) { - masaDirect += hDirAC->energy_ratio2[hDirAC->dirac_read_idx][k]; + masaDirect += hSpatParamRendCom->energy_ratio2[hSpatParamRendCom->dirac_read_idx][k]; } - ismDirect = hMasaIsm->energy_ratio_ism[0][hDirAC->dirac_read_idx][k]; - for ( dir = 1; dir < hDirAC->numIsmDirections; dir++ ) + ismDirect = hMasaIsm->energy_ratio_ism[0][hSpatParamRendCom->dirac_read_idx][k]; + for ( dir = 1; dir < hSpatParamRendCom->numIsmDirections; dir++ ) { - ismDirect += hMasaIsm->energy_ratio_ism[dir][hDirAC->dirac_read_idx][k]; + ismDirect += hMasaIsm->energy_ratio_ism[dir][hSpatParamRendCom->dirac_read_idx][k]; } totalDirect = masaDirect + ismDirect; @@ -2051,12 +2062,12 @@ void ivas_dirac_dec_compute_directional_responses( int16_t num_channels_surrCoh; num_channels_surrCoh = num_channels_dir; - num_channels_surrCoh -= hDirAC->num_ele_spk_no_diffuse_rendering; + num_channels_surrCoh -= hDirACRend->num_ele_spk_no_diffuse_rendering; for ( l = 0; l < num_channels_dir; l++ ) { direct_response_ls[l] *= sqrtf( 1.0f - surCohRatio[k] ); - if ( hDirAC->diffuse_response_function[l] > 0.f ) + if ( hDirACRend->diffuse_response_function[l] > 0.f ) { direct_response_ls[l] += sqrtf( surCohRatio[k] / (float) num_channels_surrCoh ); } @@ -2067,8 +2078,8 @@ void ivas_dirac_dec_compute_directional_responses( /* Set computed gains */ direct_response = direct_response_ls; v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); - mvr2r_inc( direct_response_square, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses_square[k], hDirAC->num_freq_bands, num_channels_dir ); - mvr2r_inc( direct_response, 1, &hDirAC->h_output_synthesis_psd_state.direct_responses[k], hDirAC->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } else { diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c new file mode 100644 index 0000000000..d5bb1052c0 --- /dev/null +++ b/lib_rend/ivas_dirac_rend.c @@ -0,0 +1,2061 @@ +/****************************************************************************************************** + +(C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository. All Rights Reserved. + +This software is protected by copyright law and by international treaties. +The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, +Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +contributors to this repository retain full ownership rights in their respective contributions in +the software. This notice grants no license of any kind, including but not limited to patent +license, nor is any license granted by implication, estoppel or otherwise. + +Contributors are required to enter into the IVAS codec Public Collaboration agreement before making +contributions. + +This software is provided "AS IS", without any express or implied warranties. The software is in the +development stage. It is intended exclusively for experts who have experience with such software and +solely for the purpose of inspection. All implied warranties of non-infringement, merchantability +and fitness for a particular purpose are hereby disclaimed and excluded. + +Any dispute, controversy or claim arising under or in relation to providing this software shall be +submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in +accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and +the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include +#include "options.h" +#include +#include "cnst.h" +#include "prot.h" +#include "ivas_prot.h" +#include "ivas_prot_rend.h" +#include "ivas_cnst.h" +#include "ivas_rom_dec.h" +#ifdef DEBUGGING +#include "debug.h" +#endif +#include "wmc_auto.h" + + +/*------------------------------------------------------------------------- + * ivas_dirac_allocate_parameters() + * + * Allocate and initialize DirAC parameters + *-------------------------------------------------------------------------*/ + +ivas_error ivas_dirac_allocate_parameters( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ + const int16_t params_flag /* i : set of parameters flag */ +) +{ + int16_t i; + + if ( params_flag == 1 ) + { + if ( ( hSpatParamRendCom->azimuth = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->elevation = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->diffuseness_vector = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->energy_ratio1 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->spreadCoherence = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->surroundingCoherence = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) + { + if ( ( hSpatParamRendCom->azimuth[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hSpatParamRendCom->azimuth[i], 0, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->elevation[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hSpatParamRendCom->elevation[i], 0, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->diffuseness_vector[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->diffuseness_vector[i], 1.0f, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->energy_ratio1[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->energy_ratio1[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->spreadCoherence[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->spreadCoherence[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->surroundingCoherence[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->surroundingCoherence[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + } + } + else if ( params_flag == 2 ) + { + if ( ( hSpatParamRendCom->azimuth2 = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->elevation2 = (int16_t **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( int16_t * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->energy_ratio2 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + if ( ( hSpatParamRendCom->spreadCoherence2 = (float **) malloc( hSpatParamRendCom->dirac_md_buffer_length * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + + for ( i = 0; i < hSpatParamRendCom->dirac_md_buffer_length; i++ ) + { + if ( ( hSpatParamRendCom->azimuth2[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hSpatParamRendCom->azimuth2[i], 0, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->elevation2[i] = (int16_t *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( int16_t ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_s( hSpatParamRendCom->elevation2[i], 0, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->energy_ratio2[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->energy_ratio2[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + + if ( ( hSpatParamRendCom->spreadCoherence2[i] = (float *) malloc( hSpatParamRendCom->num_freq_bands * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set_f( hSpatParamRendCom->spreadCoherence2[i], 0.0f, hSpatParamRendCom->num_freq_bands ); + } + } + + return IVAS_ERR_OK; +} + + +ivas_error ivas_spat_hSpatParamRendCom_config( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const int16_t dec_param_estim_flag, + const IVAS_FORMAT ivas_format, + const MC_MODE mc_mode, + const int32_t output_Fs, + const int16_t hodirac_flag ) +{ + ivas_error error; + int16_t map_idx; + DIRAC_CONFIG_FLAG flag_config; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + error = IVAS_ERR_OK; + + hSpatParamRendCom = NULL; + + if ( flag_config == DIRAC_RECONFIGURE ) + { + hSpatParamRendCom = *hSpatParamRendCom_out; + } + else if ( flag_config == DIRAC_OPEN ) + { + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + if ( ( hSpatParamRendCom = (SPAT_PARAM_REND_COMMON_DATA_HANDLE) malloc( sizeof( SPAT_PARAM_REND_COMMON_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC meta\n" ) ); + } + + *hSpatParamRendCom_out = hSpatParamRendCom; + } + + + if ( flag_config == DIRAC_OPEN ) + { + hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + hSpatParamRendCom->subframes_rendered = 0; + hSpatParamRendCom->slots_rendered = 0; + hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; + hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); +#ifdef MASA_AND_OBJECTS + hSpatParamRendCom->numSimultaneousDirections = 0; + hSpatParamRendCom->numParametricDirections = 0; + hSpatParamRendCom->numIsmDirections = 0; +#else + hSpatParamRendCom->numSimultaneousDirections = 0; +#endif + } + + /*-----------------------------------------------------------------* + * set input parameters + *-----------------------------------------------------------------*/ + + if ( ivas_format == SBA_FORMAT && flag_config == DIRAC_RECONFIGURE ) + { + if ( hodirac_flag && hSpatParamRendCom->azimuth2 == NULL ) + { + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else if ( !hodirac_flag && hSpatParamRendCom->azimuth2 != NULL ) + { + ivas_dirac_deallocate_parameters( hSpatParamRendCom, 2 ); + } + } + + if ( flag_config == DIRAC_OPEN ) + { + hSpatParamRendCom->dirac_md_buffer_length = 0; + hSpatParamRendCom->dirac_bs_md_write_idx = 0; + hSpatParamRendCom->dirac_read_idx = 0; + if ( mc_mode == MC_MODE_MCMASA ) + { + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES; + + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; + } + } +#ifdef MASA_AND_OBJECTS + else if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) +#else + else if ( ivas_format == MASA_FORMAT ) +#endif + { + hSpatParamRendCom->dirac_md_buffer_length = MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; + hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_MASA_PARAM_DEC_SFR; + + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = map_idx; + } + } + else + { + int16_t num_slots_in_subfr; + num_slots_in_subfr = dec_param_estim_flag ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + hSpatParamRendCom->dirac_md_buffer_length = ( MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_DIRAC_PARAM_DEC_SFR ); + hSpatParamRendCom->dirac_bs_md_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; + hSpatParamRendCom->dirac_read_idx = 0; + + set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + for ( map_idx = 0; map_idx < DEFAULT_JBM_SUBFRAMES_5MS * num_slots_in_subfr; map_idx++ ) + { + hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; + } + } + + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + +#ifdef MASA_AND_OBJECTS + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ( ivas_format == SBA_FORMAT && hodirac_flag ) ) +#else + if ( ivas_format == MASA_FORMAT || ( ivas_format == SBA_FORMAT && hodirac_flag ) ) +#endif + { + if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + hSpatParamRendCom->azimuth2 = NULL; + hSpatParamRendCom->elevation2 = NULL; + hSpatParamRendCom->energy_ratio2 = NULL; + hSpatParamRendCom->spreadCoherence2 = NULL; + } + } + + return error; +} + + +void ivas_spat_hSpatParamRendCom_close( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out ) +{ + if ( hSpatParamRendCom_out == NULL || *hSpatParamRendCom_out == NULL ) + { + return; + } + + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 1 ); + ivas_dirac_deallocate_parameters( *hSpatParamRendCom_out, 2 ); + + free( *hSpatParamRendCom_out ); + *hSpatParamRendCom_out = NULL; + + return; +} + +void ivas_dirac_rend_close( + DIRAC_REND_HANDLE *hDirACRend_out ) +{ + int16_t i, j; + DIRAC_REND_HANDLE hDirACRend; + + if ( hDirACRend_out == NULL || *hDirACRend_out == NULL ) + { + return; + } + + hDirACRend = *hDirACRend_out; + + /* close Output synthesis sub-module */ + ivas_dirac_dec_output_synthesis_close( hDirACRend ); + + /* close Decorrelator sub-module */ + if ( hDirACRend->proto_signal_decorr_on ) + { + ivas_dirac_dec_decorr_close( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + } + + /* Params */ + + /* free frequency axis buffer */ + if ( hDirACRend->frequency_axis != NULL ) + { + free( hDirACRend->frequency_axis ); + hDirACRend->frequency_axis = NULL; + } + + if ( hDirACRend->diffuse_response_function != NULL ) + { + free( hDirACRend->diffuse_response_function ); + hDirACRend->diffuse_response_function = NULL; + } + + if ( hDirACRend->hoa_encoder != NULL ) + { + free( hDirACRend->hoa_encoder ); + hDirACRend->hoa_encoder = NULL; + } + + /* prototype indexing */ + if ( hDirACRend->proto_index_dir != NULL ) + { + free( hDirACRend->proto_index_dir ); + hDirACRend->proto_index_dir = NULL; + } + + if ( hDirACRend->proto_index_diff != NULL ) + { + free( hDirACRend->proto_index_diff ); + hDirACRend->proto_index_dir = NULL; + } + + /* States */ + + /* free prototype signal buffers */ + if ( hDirACRend->proto_frame_f != NULL ) + { + free( hDirACRend->proto_frame_f ); + hDirACRend->proto_frame_f = NULL; + } + + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + for ( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + if ( hDirACRend->buffer_intensity_real[i][j] != NULL ) + { + free( hDirACRend->buffer_intensity_real[i][j] ); + hDirACRend->buffer_intensity_real[i][j] = NULL; + } + } + } + if ( hDirACRend->buffer_energy != NULL ) + { + free( hDirACRend->buffer_energy ); + hDirACRend->buffer_energy = NULL; + } + + if ( hDirACRend->masa_stereo_type_detect != NULL ) + { + free( hDirACRend->masa_stereo_type_detect ); + hDirACRend->masa_stereo_type_detect = NULL; + } + + ivas_dirac_free_mem( &( hDirACRend->stack_mem ) ); + + free( *hDirACRend_out ); + *hDirACRend_out = NULL; + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_dirac_deallocate_parameters() + * + * Deallocate DirAC parameters + *-------------------------------------------------------------------------*/ + +void ivas_dirac_deallocate_parameters( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ + const int16_t params_flag /* i : set of parameters flag */ +) +{ + int16_t i; + int16_t md_buffer_length; + + if ( hSpatParamRendCom == NULL ) + { + return; + } + + md_buffer_length = hSpatParamRendCom->dirac_md_buffer_length; + + if ( params_flag == 1 ) + { + if ( hSpatParamRendCom->azimuth != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->azimuth[i] != NULL ) + { + free( hSpatParamRendCom->azimuth[i] ); + hSpatParamRendCom->azimuth[i] = NULL; + } + } + + free( hSpatParamRendCom->azimuth ); + hSpatParamRendCom->azimuth = NULL; + } + + if ( hSpatParamRendCom->elevation != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->elevation[i] != NULL ) + { + free( hSpatParamRendCom->elevation[i] ); + hSpatParamRendCom->elevation[i] = NULL; + } + } + + free( hSpatParamRendCom->elevation ); + hSpatParamRendCom->elevation = NULL; + } + + if ( hSpatParamRendCom->energy_ratio1 != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->energy_ratio1[i] != NULL ) + { + free( hSpatParamRendCom->energy_ratio1[i] ); + hSpatParamRendCom->energy_ratio1[i] = NULL; + } + } + free( hSpatParamRendCom->energy_ratio1 ); + hSpatParamRendCom->energy_ratio1 = NULL; + } + + if ( hSpatParamRendCom->diffuseness_vector != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->diffuseness_vector[i] != NULL ) + { + free( hSpatParamRendCom->diffuseness_vector[i] ); + hSpatParamRendCom->diffuseness_vector[i] = NULL; + } + } + + free( hSpatParamRendCom->diffuseness_vector ); + hSpatParamRendCom->diffuseness_vector = NULL; + } + + if ( hSpatParamRendCom->spreadCoherence != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->spreadCoherence[i] != NULL ) + { + free( hSpatParamRendCom->spreadCoherence[i] ); + hSpatParamRendCom->spreadCoherence[i] = NULL; + } + } + free( hSpatParamRendCom->spreadCoherence ); + hSpatParamRendCom->spreadCoherence = NULL; + } + + if ( hSpatParamRendCom->surroundingCoherence != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->surroundingCoherence[i] != NULL ) + { + free( hSpatParamRendCom->surroundingCoherence[i] ); + hSpatParamRendCom->surroundingCoherence[i] = NULL; + } + } + free( hSpatParamRendCom->surroundingCoherence ); + hSpatParamRendCom->surroundingCoherence = NULL; + } + } + else if ( params_flag == 2 ) + { + if ( hSpatParamRendCom->azimuth2 != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->azimuth2[i] != NULL ) + { + free( hSpatParamRendCom->azimuth2[i] ); + hSpatParamRendCom->azimuth2[i] = NULL; + } + } + free( hSpatParamRendCom->azimuth2 ); + hSpatParamRendCom->azimuth2 = NULL; + } + + if ( hSpatParamRendCom->elevation2 != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->elevation2[i] != NULL ) + { + free( hSpatParamRendCom->elevation2[i] ); + hSpatParamRendCom->elevation2[i] = NULL; + } + } + free( hSpatParamRendCom->elevation2 ); + hSpatParamRendCom->elevation2 = NULL; + } + + if ( hSpatParamRendCom->energy_ratio2 != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->energy_ratio2[i] != NULL ) + { + free( hSpatParamRendCom->energy_ratio2[i] ); + hSpatParamRendCom->energy_ratio2[i] = NULL; + } + } + free( hSpatParamRendCom->energy_ratio2 ); + hSpatParamRendCom->energy_ratio2 = NULL; + } + + if ( hSpatParamRendCom->spreadCoherence2 != NULL ) + { + for ( i = 0; i < md_buffer_length; i++ ) + { + if ( hSpatParamRendCom->spreadCoherence2[i] != NULL ) + { + free( hSpatParamRendCom->spreadCoherence2[i] ); + hSpatParamRendCom->spreadCoherence2[i] = NULL; + } + } + free( hSpatParamRendCom->spreadCoherence2 ); + hSpatParamRendCom->spreadCoherence2 = NULL; + } + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_dirac_alloc_mem() + * + * Allocate stack memory for DirAC renderer + *------------------------------------------------------------------------*/ + +ivas_error ivas_dirac_alloc_mem( + DIRAC_REND_HANDLE hDirACRend, + const RENDERER_TYPE renderer_type, + const int16_t num_freq_bands, + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, + const int16_t hodirac_flag ) +{ + int16_t num_freq_bands_diff, size; + int16_t size_ho; + int16_t size_pf; + int16_t num_outputs_dir, num_outputs_diff; + int16_t num_protos_dir; + + num_protos_dir = hDirACRend->num_protos_dir; + + num_freq_bands_diff = hDirACRend->h_output_synthesis_psd_params.max_band_decorr; + + num_outputs_dir = hDirACRend->num_outputs_dir; + num_outputs_diff = hDirACRend->num_outputs_diff; + + size = num_freq_bands * num_outputs_dir; + if ( hodirac_flag ) + { + size_ho = size * DIRAC_HO_NUMSECTORS; + size_pf = num_freq_bands * DIRAC_HO_NUMSECTORS; + } + else + { + size_ho = size; + size_pf = num_freq_bands; + } + + /* PSD related buffers */ + hDirAC_mem->cy_auto_dir_smooth = NULL; + hDirAC_mem->proto_power_smooth = NULL; + hDirAC_mem->proto_power_diff_smooth = NULL; + hDirAC_mem->direct_responses_square = NULL; + hDirAC_mem->frame_dec_f = NULL; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); + + if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_smooth, size ); + + if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_diff_smooth, size ); + + if ( ( hDirAC_mem->direct_responses_square = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->direct_responses_square, size ); + if ( hDirACRend->proto_signal_decorr_on && ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) ) + { + if ( ( hDirAC_mem->frame_dec_f = (float *) malloc( sizeof( float ) * 2 * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; + hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; + hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; + + /* Target and smoothed nrg factors/gains */ + if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); + + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); + } + else + { + if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); + } + hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; + + /*Responses (gains/factors)*/ + if ( ( hDirAC_mem->direct_responses = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->direct_responses, size ); + + + hDirACRend->h_output_synthesis_psd_state.direct_responses = hDirAC_mem->direct_responses; + + /* Prototypes */ + hDirAC_mem->proto_direct_buffer_f = NULL; + hDirAC_mem->proto_diffuse_buffer_f = NULL; + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + + if ( hDirACRend->proto_signal_decorr_on ) + { + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) + { + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + else + { + if ( ( hDirAC_mem->proto_diffuse_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + } + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; + + /* Gains/power factors*/ + hDirAC_mem->direct_power_factor = NULL; + hDirAC_mem->diffuse_power_factor = NULL; + + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + if ( ( hDirAC_mem->diffuse_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + + hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; + + hDirAC_mem->reference_power = NULL; + hDirAC_mem->onset_filter = NULL; + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) + { + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + if ( hDirACRend->proto_signal_decorr_on ) + { + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + } + else + { + if ( num_protos_dir > 2 ) + { + if ( ( hDirAC_mem->reference_power = (float *) malloc( sizeof( float ) * 5 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + + if ( hDirACRend->proto_signal_decorr_on ) + { + if ( ( hDirAC_mem->onset_filter = (float *) malloc( sizeof( float ) * 2 * num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + } + } + + return IVAS_ERR_OK; +} + + +void ivas_dirac_free_mem( + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) +{ + if ( hDirAC_mem->cy_auto_dir_smooth != NULL ) + { + free( hDirAC_mem->cy_auto_dir_smooth ); + } + if ( hDirAC_mem->proto_power_smooth != NULL ) + { + free( hDirAC_mem->proto_power_smooth ); + } + if ( hDirAC_mem->proto_power_diff_smooth != NULL ) + { + free( hDirAC_mem->proto_power_diff_smooth ); + } + if ( hDirAC_mem->direct_responses_square != NULL ) + { + free( hDirAC_mem->direct_responses_square ); + } + if ( hDirAC_mem->frame_dec_f != NULL ) + { + free( hDirAC_mem->frame_dec_f ); + } + if ( hDirAC_mem->cy_cross_dir_smooth != NULL ) + { + free( hDirAC_mem->cy_cross_dir_smooth ); + } + if ( hDirAC_mem->cy_auto_diff_smooth != NULL ) + { + free( hDirAC_mem->cy_auto_diff_smooth ); + } + if ( hDirAC_mem->direct_responses != NULL ) + { + free( hDirAC_mem->direct_responses ); + } + if ( hDirAC_mem->proto_direct_buffer_f != NULL ) + { + free( hDirAC_mem->proto_direct_buffer_f ); + } + if ( hDirAC_mem->proto_diffuse_buffer_f != NULL ) + { + free( hDirAC_mem->proto_diffuse_buffer_f ); + } + if ( hDirAC_mem->direct_power_factor != NULL ) + { + free( hDirAC_mem->direct_power_factor ); + } + if ( hDirAC_mem->diffuse_power_factor != NULL ) + { + free( hDirAC_mem->diffuse_power_factor ); + } + if ( hDirAC_mem->reference_power != NULL ) + { + free( hDirAC_mem->reference_power ); + } + if ( hDirAC_mem->onset_filter != NULL ) + { + free( hDirAC_mem->onset_filter ); + } + + return; +} + + +/*------------------------------------------------------------------------- + * compute_hoa_encoder_mtx() + * + * + *------------------------------------------------------------------------*/ + +void compute_hoa_encoder_mtx( + const float *azimuth, + const float *elevation, + float *response, + const int16_t num_responses, + const int16_t ambisonics_order ) +{ + int16_t k, num_sh; + + num_sh = ivas_sba_get_nchan( ambisonics_order, 0 ); + + for ( k = 0; k < num_responses; k++ ) + { + ivas_dirac_dec_get_response( (const int16_t) azimuth[k], (const int16_t) elevation[k], &response[k * num_sh], ambisonics_order ); + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_dirac_dec_get_frequency_axis() + * + * DirAC decoding initialization + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_get_frequency_axis( + float *frequency_axis, + const int32_t output_Fs, + const int16_t num_freq_bands ) +{ + int16_t k; + float const_part; + + /* calc cldfb frequency axis */ + const_part = (float) output_Fs / ( 2.0f * (float) num_freq_bands ); + for ( k = 0; k < num_freq_bands; ++k ) + { + frequency_axis[k] = ( (float) k + 0.5f ) * const_part; + } + + return; +} + + +/*------------------------------------------------------------------------- + * Local functions + *-------------------------------------------------------------------------*/ + +void initDiffuseResponses( + float *diffuse_response_function, + const int16_t num_channels, + AUDIO_CONFIG output_config, + IVAS_OUTPUT_SETUP hOutSetup, + const int16_t ambisonics_order, + const IVAS_FORMAT ivas_format, + int16_t *num_ele_spk_no_diffuse_rendering, + AUDIO_CONFIG transport_config ) +{ + int16_t i, l, k, idx, num_horizontal_speakers; + *num_ele_spk_no_diffuse_rendering = 0; + + if ( output_config == AUDIO_CONFIG_MONO ) + { + diffuse_response_function[0] = 1.0f; + diffuse_response_function[1] = inv_sqrt( 3.0f ); + } + else if ( !( output_config == AUDIO_CONFIG_FOA || output_config == AUDIO_CONFIG_HOA2 || output_config == AUDIO_CONFIG_HOA3 ) ) + { + /* set diffuse response function */ + if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_5_1_4 ) + { + num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + + mvr2r( diffuse_response_CICP6, diffuse_response_function, num_horizontal_speakers ); + set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); + *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + } + else if ( ivas_format == MC_FORMAT && ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) && output_config == AUDIO_CONFIG_7_1_4 ) + { + num_horizontal_speakers = num_channels - NUM_ELEVATED_SPEAKERS; + + set_f( diffuse_response_function, sqrtf( 1.f / ( (float) num_horizontal_speakers ) ), num_horizontal_speakers ); + set_zero( &diffuse_response_function[num_horizontal_speakers], NUM_ELEVATED_SPEAKERS ); + *num_ele_spk_no_diffuse_rendering = NUM_ELEVATED_SPEAKERS; + } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) +#else + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1 && num_channels == 5 ) +#endif + { + mvr2r( diffuse_response_CICP6, diffuse_response_function, num_channels ); + } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) +#else + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && output_config == AUDIO_CONFIG_5_1_2 && num_channels == 7 ) +#endif + { + mvr2r( diffuse_response_CICP14, diffuse_response_function, num_channels ); + } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) +#else + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_5_1_4 ) && ( num_channels == 9 ) ) +#endif + { + mvr2r( diffuse_response_CICP16, diffuse_response_function, num_channels ); + } +#ifdef MASA_AND_OBJECTS + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) +#else + else if ( ( ivas_format == MASA_FORMAT || ivas_format == MC_FORMAT ) && ( output_config == AUDIO_CONFIG_LS_CUSTOM ) ) +#endif + { + if ( transport_config == AUDIO_CONFIG_5_1 || transport_config == AUDIO_CONFIG_7_1 ) + { + /* Detect loudspeakers with elevation */ + for ( i = 0, num_horizontal_speakers = 0; i < num_channels; i++ ) + { + if ( fabsf( hOutSetup.ls_elevation[i] ) <= 5.f ) + { + num_horizontal_speakers++; + diffuse_response_function[i] = 1.f; + } + else + { + *num_ele_spk_no_diffuse_rendering += 1; + diffuse_response_function[i] = 0.f; + } + } + /* Diffuse only to horizontal plane if enough loudspeakers */ + if ( num_horizontal_speakers > 2 ) + { + for ( i = 0; i < num_channels; i++ ) + { + diffuse_response_function[i] *= sqrtf( 1.f / (float) num_horizontal_speakers ); + } + } + else + { + *num_ele_spk_no_diffuse_rendering = 0; + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + } + } + else + { + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + } + } + else + { + set_f( diffuse_response_function, sqrtf( 1.f / (float) num_channels ), num_channels ); + } + } + else + { + idx = 0; + for ( l = 0; l <= ambisonics_order; l++ ) + { + for ( k = 0; k < ( 2 * l + 1 ); k++ ) + { + diffuse_response_function[idx++] = inv_sqrt( 2.0f * l + 1.0f ); + } + } + } + + return; +} + + +void protoSignalComputation_shd( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_direct_buffer_f, + float *proto_diffuse_buffer_f, + float *reference_power, + const int16_t slot_index, + const int16_t num_inputs, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + float *p_Rmat ) +{ + int16_t l, k; + float *p_proto_direct_buffer; + float *p_proto_diffuse_buffer; + int16_t Rmat_k[4]; + float W_real, W_imag; + float Y_real, Y_imag; + float *p_k[4]; + + k = 0; /* to avoid compilation warning */ + + p_proto_direct_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_inputs; + p_proto_diffuse_buffer = proto_diffuse_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; + + if ( num_inputs == 1 ) + { + for ( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer[2 * l] = RealBuffer[0][0][l]; + p_proto_direct_buffer[2 * l + 1] = ImagBuffer[0][0][l]; + } + } + else if ( num_inputs == 2 ) + { + if ( p_Rmat != 0 ) + { + assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" ); + + for ( l = 0; l < num_freq_bands; l++ ) + { + W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + + Y_real = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + Y_imag = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + + p_proto_direct_buffer[2 * l] = W_real; + p_proto_direct_buffer[2 * l + 1] = W_imag; + p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = p_Rmat[0] * Y_real; + p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = p_Rmat[0] * Y_imag; + } + } + else + { + for ( l = 0; l < num_freq_bands; l++ ) + { + W_real = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + W_imag = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + + p_proto_direct_buffer[2 * l] = W_real; + p_proto_direct_buffer[2 * l + 1] = W_imag; + { + p_proto_direct_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_direct_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + } + } + } + } + else if ( num_inputs >= 4 ) + { + p_k[0] = p_proto_direct_buffer; + p_k[1] = p_proto_direct_buffer + 2 * num_freq_bands; + p_k[2] = p_proto_direct_buffer + 4 * num_freq_bands; + p_k[3] = p_proto_direct_buffer + 6 * num_freq_bands; + Rmat_k[0] = 0; + Rmat_k[1] = 1; + Rmat_k[2] = 2; + Rmat_k[3] = 0; + + if ( p_Rmat != 0 ) + { + assert( num_inputs == 4 && "This code block should never be run with num_inputs != 4!" ); + + for ( l = 0; l < num_freq_bands; l++ ) + { + *( p_k[0] ) = RealBuffer[0][0][l]; + reference_power[l + num_freq_bands] = *( p_k[0] ) * *( p_k[0] ); + p_k[0]++; + *( p_k[0] ) = ImagBuffer[0][0][l]; + reference_power[l + num_freq_bands] += *( p_k[0] ) * *( p_k[0] ); + p_k[0]++; + reference_power[l] = 0.5f * reference_power[l + num_freq_bands]; + + for ( k = 1; k < 4; k++ ) + { + *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * RealBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * RealBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * RealBuffer[3][0][l]; + reference_power[l + ( k + 1 ) * num_freq_bands] = *( p_k[k] ) * *( p_k[k] ); + p_k[k]++; + *( p_k[k] ) = p_Rmat[3 * Rmat_k[k] + 1] * ImagBuffer[1][0][l] + p_Rmat[3 * Rmat_k[k] + 2] * ImagBuffer[2][0][l] + p_Rmat[3 * Rmat_k[k] + 0] * ImagBuffer[3][0][l]; + reference_power[l + ( k + 1 ) * num_freq_bands] += *( p_k[k] ) * *( p_k[k] ); + p_k[k]++; + reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] ); + } + + for ( k = 1; k < 4; k++ ) + { + RealBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l]; + ImagBuffer[k][0][l] = p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1]; + } + } + } + else + { + set_zero( reference_power, num_freq_bands ); + for ( k = 0; k < 4; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l]; + p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l]; + reference_power[l + ( k + 1 ) * num_freq_bands] = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; + reference_power[l] += 0.5f * ( reference_power[l + ( k + 1 ) * num_freq_bands] ); + } + } + } + + /* Additional transport channels = planar SBA components of degree higher than 1*/ + for ( ; k < num_inputs; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l] = RealBuffer[k][0][l]; + p_proto_direct_buffer[k * 2 * num_freq_bands + 2 * l + 1] = ImagBuffer[k][0][l]; + } + } + } + + + /*Copy direct to diffuse proto*/ + mvr2r( p_proto_direct_buffer, p_proto_diffuse_buffer, 2 * num_freq_bands * min( num_outputs_diff, num_inputs ) ); + + if ( num_inputs == 1 ) + { + /* Add comfort noise addition (CNA) to diffuse proto only*/ + for ( l = 0; l < num_freq_bands; l++ ) + { + p_proto_diffuse_buffer[2 * l] += RealBuffer[1][0][l]; + p_proto_diffuse_buffer[2 * l + 1] += ImagBuffer[1][0][l]; + } + } + + return; +} + + +void protoSignalComputation1( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands ) +{ + int16_t l, k; + float *p_proto_buffer; + + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands; + + for ( l = 0; l < num_freq_bands; l++ ) + { + reference_power[l] = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + proto_power_smooth[l] += reference_power[l]; + p_proto_buffer[2 * l] = RealBuffer[0][0][l]; + p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l]; + + for ( k = 0; k < num_outputs_diff; k++ ) + { + proto_frame_f[2 * k * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * k * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + } + } + + return; +} + + +void protoSignalComputation2( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t isloudspeaker, + const int16_t slot_index, + const int16_t num_freq_bands, + MASA_STEREO_TYPE_DETECT *stereo_type_detect ) +{ + int16_t l; + float *p_proto_buffer; + float Real_aux, Imag_aux; + + float left_bb_power, right_bb_power, total_bb_power, lr_bb_power; + float lr_total_bb_ratio; + float a, b; + + float left_hi_power, right_hi_power, total_hi_power, lr_hi_power; + float lr_total_hi_ratio; + float a2, b2; + + float sum_power; + float sum_total_ratio[MASA_SUM_FREQ_RANGE_BINS]; + float min_sum_total_ratio; + float min_sum_total_ratio_db; + + float RealSubtract, ImagSubtract; + + float interpolatorSpaced = 0.0f; + float interpolatorDmx = 1.0f; + + int16_t dipole_freq_range[2]; + float tempSpaced, tempDmx; + + if ( isloudspeaker ) + { + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 3; + + for ( l = 0; l < num_freq_bands; l++ ) + { + float Left_power; + float Right_power; + Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + + Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; + + reference_power[l] = Left_power + Right_power; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + proto_power_smooth[l + num_freq_bands] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + + proto_power_smooth[l + 2 * num_freq_bands] += RealBuffer[1][0][l] * RealBuffer[1][0][l]; + proto_power_smooth[l + 2 * num_freq_bands] += ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; + p_proto_buffer[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + p_proto_buffer[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } + } + else if ( stereo_type_detect != NULL ) + { + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; + + left_bb_power = 0.0f; + right_bb_power = 0.0f; + total_bb_power = 0.0f; + + left_hi_power = 0.0f; + right_hi_power = 0.0f; + total_hi_power = 0.0f; + + dipole_freq_range[0] = stereo_type_detect->dipole_freq_range[0]; + dipole_freq_range[1] = stereo_type_detect->dipole_freq_range[1]; + + a = 0.01f; /* Temporal smoothing coefficient */ + b = 1.0f - a; /* Temporal smoothing coefficient */ + a2 = 0.1f; /* Temporal smoothing coefficient */ + b2 = 1.0f - a2; /* Temporal smoothing coefficient */ + + if ( stereo_type_detect->interpolator > 0 ) + { + if ( stereo_type_detect->type_change_direction == MASA_STEREO_SPACED_MICS ) + { + interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); + interpolatorDmx = 1.0f - interpolatorSpaced; + } + else + { + interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); + interpolatorSpaced = 1.0f - interpolatorDmx; + } + } + + for ( l = 0; l < num_freq_bands; l++ ) + { + float Left_power; + float Right_power; + + /* Compute sum signal */ + Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + + /* Compute reference power */ + Left_power = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + Right_power = RealBuffer[1][0][l] * RealBuffer[1][0][l] + ImagBuffer[1][0][l] * ImagBuffer[1][0][l]; + + reference_power[l] = Left_power + Right_power; + + left_bb_power += Left_power; + right_bb_power += Right_power; + total_bb_power += reference_power[l]; + + if ( l > MASA_HI_FREQ_START_BIN ) + { + left_hi_power += Left_power; + right_hi_power += Right_power; + total_hi_power += reference_power[l]; + } + + if ( l < min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ) ) + { + sum_power = Real_aux * Real_aux + Imag_aux * Imag_aux; + + stereo_type_detect->sum_power[l] = a * sum_power + b * stereo_type_detect->sum_power[l]; + stereo_type_detect->total_power[l] = a * reference_power[l] + b * stereo_type_detect->total_power[l]; + + sum_total_ratio[l] = stereo_type_detect->sum_power[l] / ( stereo_type_detect->total_power[l] + EPSILON ); + } + + if ( l == 0 ) + { + RealSubtract = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + ImagSubtract = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + stereo_type_detect->subtract_power_y += RealSubtract * RealSubtract + ImagSubtract * ImagSubtract; + } + + /* Compute protos (and their power) for direct sound rendering */ + + /* W prototype */ + if ( stereo_type_detect->interpolator > 0 ) + { + if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) + { + Real_aux = interpolatorSpaced * 0.5f * Real_aux + interpolatorDmx * Real_aux; + Imag_aux = interpolatorSpaced * 0.5f * Imag_aux + interpolatorDmx * Imag_aux; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + else + { + tempSpaced = RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + tempDmx = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += interpolatorSpaced * tempSpaced + interpolatorDmx * tempDmx; + p_proto_buffer[2 * l] = interpolatorSpaced * RealBuffer[0][0][l] + interpolatorDmx * Real_aux; + p_proto_buffer[2 * l + 1] = interpolatorSpaced * ImagBuffer[0][0][l] + interpolatorDmx * Imag_aux; + } + } + else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + { + if ( l < ( dipole_freq_range[1] - 1 ) || l >= MASA_SUM_PROTO_START_BIN ) + { + Real_aux *= 0.5f; + Imag_aux *= 0.5f; + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + else + { + proto_power_smooth[l] += RealBuffer[0][0][l] * RealBuffer[0][0][l] + ImagBuffer[0][0][l] * ImagBuffer[0][0][l]; + p_proto_buffer[2 * l] = RealBuffer[0][0][l]; + p_proto_buffer[2 * l + 1] = ImagBuffer[0][0][l]; + } + } + else + { + proto_power_smooth[l] += Real_aux * Real_aux + Imag_aux * Imag_aux; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + } + + /* Y prototype */ + if ( stereo_type_detect->interpolator > 0 ) + { + if ( l < ( dipole_freq_range[0] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + else if ( l < ( dipole_freq_range[1] ) ) + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ) + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * ( -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ) ) + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + else + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = interpolatorSpaced * p_proto_buffer[2 * l] + interpolatorDmx * ( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = interpolatorSpaced * p_proto_buffer[2 * l + 1] + interpolatorDmx * ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + } + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } + else if ( stereo_type_detect->masa_stereo_type == MASA_STEREO_SPACED_MICS ) + { + if ( l < ( dipole_freq_range[0] ) ) /* proto = W */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } + else if ( l < ( dipole_freq_range[1] ) ) /* proto = -i * (x1-x2) * eq */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = ( ImagBuffer[0][0][l] - ImagBuffer[1][0][l] ); + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = -( RealBuffer[0][0][l] - RealBuffer[1][0][l] ); + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } + else /* proto = W */ + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = p_proto_buffer[2 * l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = p_proto_buffer[2 * l + 1]; + proto_power_smooth[l + num_freq_bands] = proto_power_smooth[l]; + } + } + else + { + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + } + + /* Compute protos for decorrelation */ + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } + + if ( stereo_type_detect->interpolator > 0 ) + { + stereo_type_detect->interpolator++; + if ( stereo_type_detect->interpolator == MASA_STEREO_INTERPOLATION_SLOTS ) + { + stereo_type_detect->interpolator = 0; + stereo_type_detect->current_stereo_type = stereo_type_detect->type_change_direction; + } + } + + stereo_type_detect->left_bb_power = a * left_bb_power + b * stereo_type_detect->left_bb_power; + stereo_type_detect->right_bb_power = a * right_bb_power + b * stereo_type_detect->right_bb_power; + stereo_type_detect->total_bb_power = a * total_bb_power + b * stereo_type_detect->total_bb_power; + + lr_bb_power = ( stereo_type_detect->left_bb_power < stereo_type_detect->right_bb_power ) ? stereo_type_detect->left_bb_power : stereo_type_detect->right_bb_power; + lr_bb_power *= 2.0f; + lr_total_bb_ratio = 10.0f * log10f( lr_bb_power / ( stereo_type_detect->total_bb_power + EPSILON ) ); + + stereo_type_detect->left_hi_power = a2 * left_hi_power + b2 * stereo_type_detect->left_hi_power; + stereo_type_detect->right_hi_power = a2 * right_hi_power + b2 * stereo_type_detect->right_hi_power; + stereo_type_detect->total_hi_power = a2 * total_hi_power + b2 * stereo_type_detect->total_hi_power; + + lr_hi_power = ( stereo_type_detect->left_hi_power < stereo_type_detect->right_hi_power ) ? stereo_type_detect->left_hi_power : stereo_type_detect->right_hi_power; + lr_hi_power *= 2.0f; + lr_total_hi_ratio = 10.0f * log10f( lr_hi_power / ( stereo_type_detect->total_hi_power + EPSILON ) ); + + minimum( sum_total_ratio, min( num_freq_bands, MASA_SUM_FREQ_RANGE_BINS ), &min_sum_total_ratio ); + min_sum_total_ratio_db = 10.0f * log10f( min_sum_total_ratio ); + + stereo_type_detect->lr_total_bb_ratio_db = lr_total_bb_ratio; + stereo_type_detect->lr_total_hi_ratio_db = lr_total_hi_ratio; + stereo_type_detect->min_sum_total_ratio_db = min_sum_total_ratio_db; + + ivas_masa_stereotype_detection( stereo_type_detect ); + } + else + { + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * 2; + + for ( l = 0; l < num_freq_bands; l++ ) + { + Real_aux = RealBuffer[0][0][l] + RealBuffer[1][0][l]; + Imag_aux = ImagBuffer[0][0][l] + ImagBuffer[1][0][l]; + + reference_power[l] = Real_aux * Real_aux + Imag_aux * Imag_aux; + proto_power_smooth[l] += reference_power[l]; + p_proto_buffer[2 * l] = Real_aux; + p_proto_buffer[2 * l + 1] = Imag_aux; + + p_proto_buffer[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l] - RealBuffer[1][0][l]; + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l] - ImagBuffer[1][0][l]; + proto_power_smooth[l + num_freq_bands] += p_proto_buffer[2 * num_freq_bands + 2 * l] * p_proto_buffer[2 * num_freq_bands + 2 * l] + p_proto_buffer[2 * num_freq_bands + 2 * l + 1] * p_proto_buffer[2 * num_freq_bands + 2 * l + 1]; + + proto_frame_f[2 * l] = Real_aux; + proto_frame_f[2 * l + 1] = Imag_aux; + + proto_frame_f[2 * num_freq_bands + 2 * l] = RealBuffer[0][0][l]; + proto_frame_f[2 * num_freq_bands + 2 * l + 1] = ImagBuffer[0][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l] = RealBuffer[1][0][l]; + proto_frame_f[4 * num_freq_bands + 2 * l + 1] = ImagBuffer[1][0][l]; + } + } + + return; +} + + +void protoSignalComputation4( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + const float *mtx_hoa_decoder, + const int16_t nchan_transport, + const int16_t *sba_map_tc_ind ) +{ + int16_t k, l; + int16_t n; + float sq_tmp; + float *p_proto_buffer; + + set_zero( reference_power, num_freq_bands ); + for ( k = 0; k < 4; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) + { + sq_tmp = RealBuffer[k][0][l] * RealBuffer[k][0][l] + ImagBuffer[k][0][l] * ImagBuffer[k][0][l]; + reference_power[l] += 0.5f * sq_tmp; + } + } + + /*For decorrelated diffuseness*/ + for ( l = 0; l < num_outputs_diff; l++ ) + { + for ( k = 0; k < num_freq_bands; k++ ) + { + proto_frame_f[2 * l * num_freq_bands + 2 * k] = 0.f; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; + for ( n = 0; n < nchan_transport; n++ ) + { + proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; + } + } + } + + p_proto_buffer = proto_direct_buffer_f + slot_index * 2 * num_freq_bands * num_outputs_diff; + for ( k = 0; k < num_outputs_diff; k++ ) + { + for ( l = 0; l < num_freq_bands; l++ ) + { + sq_tmp = proto_frame_f[k * 2 * num_freq_bands + 2 * l] * proto_frame_f[k * 2 * num_freq_bands + 2 * l] + proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1] * proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + proto_power_smooth[l + k * num_freq_bands] += sq_tmp; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l] = proto_frame_f[k * 2 * num_freq_bands + 2 * l]; + p_proto_buffer[k * 2 * num_freq_bands + 2 * l + 1] = proto_frame_f[k * 2 * num_freq_bands + 2 * l + 1]; + } + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_dirac_dec_compute_diffuse_proto() + * + * Compute diffuse prototype buffer and smooth power, only for decorrelated bands + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_compute_diffuse_proto( + DIRAC_REND_HANDLE hDirACRend, + const int16_t num_freq_bands, + const int16_t slot_idx /* i : slot index */ +) +{ + int16_t k, l; + int16_t num_freq_bands_diff; + float *p_diff_buffer, *p_diff_buffer_1; + float *p_proto_diff, *p_power_smooth, *proto_frame_dec_f; + DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + int16_t m; + float *p_hoa_enc; + + proto_frame_dec_f = hDirACRend->proto_frame_dec_f; + h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); + + num_freq_bands_diff = h_dirac_output_synthesis_params->max_band_decorr; + + p_diff_buffer = h_dirac_output_synthesis_state->proto_diffuse_buffer_f + slot_idx * 2 * num_freq_bands_diff * hDirACRend->hOutSetup.nchan_out_woLFE; + p_diff_buffer_1 = p_diff_buffer + 1; + p_power_smooth = h_dirac_output_synthesis_state->proto_power_diff_smooth; + + if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) + { + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + { + p_proto_diff = proto_frame_dec_f + k * 2 * num_freq_bands; + for ( l = 0; l < num_freq_bands_diff; l++ ) + { + *p_diff_buffer = *( p_proto_diff++ ); + *p_diff_buffer_1 = *( p_proto_diff++ ); + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; + } + } + } + else + { + /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ + for ( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) + { + for ( l = 0; l < num_freq_bands_diff; l++ ) + { + p_hoa_enc = hDirACRend->hoa_encoder + k; + p_proto_diff = proto_frame_dec_f + 2 * l; + + *p_diff_buffer = 0.f; + *p_diff_buffer_1 = 0.f; + + /*LS to HOA*/ + for ( m = 0; m < hDirACRend->num_outputs_diff; m++ ) + { + *p_diff_buffer += ( *p_hoa_enc ) * ( *p_proto_diff ); + *p_diff_buffer_1 += ( *p_hoa_enc ) * ( *( p_proto_diff + 1 ) ); + p_hoa_enc += hDirACRend->hOutSetup.nchan_out_woLFE; + p_proto_diff += 2 * num_freq_bands; + } + + *( p_power_smooth++ ) += ( *p_diff_buffer ) * ( *p_diff_buffer ) + ( *p_diff_buffer_1 ) * ( *p_diff_buffer_1 ); + p_diff_buffer += 2; + p_diff_buffer_1 += 2; + } + } + } + + return; +} + + +/*------------------------------------------------------------------------- + * computeDirectionAngles() + * + *------------------------------------------------------------------------*/ + +void computeDirectionAngles( + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z, + const int16_t num_frequency_bands, + int16_t *azimuth, + int16_t *elevation ) +{ + int16_t k; + float intensityNorm; + float x, y, z, radius; + + for ( k = 0; k < num_frequency_bands; ++k ) + + { + intensityNorm = *( intensity_real_x ) * *( intensity_real_x ) + + *( intensity_real_y ) * *( intensity_real_y ) + + *( intensity_real_z ) * *( intensity_real_z ); + + if ( intensityNorm <= EPSILON ) + { + intensityNorm = 1.0f; + x = 1.0f; + y = 0.0f; + z = 0.0f; + intensity_real_x++; + intensity_real_y++; + intensity_real_z++; + } + else + { + intensityNorm = sqrtf( 1.f / intensityNorm ); + x = *( intensity_real_x++ ) * intensityNorm; + y = *( intensity_real_y++ ) * intensityNorm; + z = *( intensity_real_z++ ) * intensityNorm; + } + radius = sqrtf( x * x + y * y ); + azimuth[k] = (int16_t) ( max( -180.0f, min( 180.0f, atan2f( y, x ) / EVS_PI * 180.0f ) ) + 0.5f ); + elevation[k] = (int16_t) ( max( -90.0f, min( 180.0f, atan2f( z, radius ) / EVS_PI * 180.0f ) ) + 0.5f ); + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_masa_init_stereotype_detection() + * + * Initialize stereo transport signal type detection + *------------------------------------------------------------------------*/ + +void ivas_masa_init_stereotype_detection( + MASA_STEREO_TYPE_DETECT *stereo_type_detect ) +{ + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->current_stereo_type = MASA_STEREO_DOWNMIX; + stereo_type_detect->type_change_direction = MASA_STEREO_DOWNMIX; + + stereo_type_detect->counter = 0; + stereo_type_detect->interpolator = 0; + + stereo_type_detect->dipole_freq_range[0] = 1; + stereo_type_detect->dipole_freq_range[1] = 3; + + stereo_type_detect->left_bb_power = 0.0f; /* Broadband estimates */ + stereo_type_detect->right_bb_power = 0.0f; + stereo_type_detect->total_bb_power = 0.0f; + + stereo_type_detect->left_hi_power = 0.0f; /* High-frequency estimates */ + stereo_type_detect->right_hi_power = 0.0f; + stereo_type_detect->total_hi_power = 0.0f; + + set_zero( stereo_type_detect->sum_power, MASA_SUM_FREQ_RANGE_BINS ); + set_zero( stereo_type_detect->total_power, MASA_SUM_FREQ_RANGE_BINS ); + + stereo_type_detect->subtract_power_y = 0.0f; + stereo_type_detect->subtract_power_y_smooth = 0.0f; + stereo_type_detect->target_power_y_smooth = 0.0f; + + stereo_type_detect->lr_total_bb_ratio_db = 0.0f; + stereo_type_detect->lr_total_hi_ratio_db = 0.0f; + stereo_type_detect->min_sum_total_ratio_db = 0.0f; + stereo_type_detect->subtract_target_ratio_db = 0.0f; + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_masa_stereotype_detection() + * + * Detect the type of the transport audio signals + *------------------------------------------------------------------------*/ + +void ivas_masa_stereotype_detection( + MASA_STEREO_TYPE_DETECT *stereo_type_detect ) +{ + float lr_total_bb_ratio_db = stereo_type_detect->lr_total_bb_ratio_db; + float lr_total_hi_ratio_db = stereo_type_detect->lr_total_hi_ratio_db; + float min_sum_total_ratio_db = stereo_type_detect->min_sum_total_ratio_db; + float subtract_target_ratio_db = stereo_type_detect->subtract_target_ratio_db; + float change_to_spaced; + int16_t change_to_spaced_selection; + float change_to_downmix; + float change_to_downmix2; + int16_t change_to_downmix_selection; + float subtract_temp; + float min_sum_temp; + float lr_total_bb_temp; + float lr_total_hi_temp; + + /* Determine if the determined features match the spaced mic type */ + change_to_spaced_selection = 0; + if ( subtract_target_ratio_db < -3.0f ) + { + subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; + min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); + lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; + + change_to_spaced = subtract_temp + min_sum_temp + lr_total_bb_temp; + + if ( change_to_spaced >= 1.0f ) + { + change_to_spaced_selection = 1; + } + } + + /* Determine if the determined features match the downmix type, according to a metric */ + change_to_downmix_selection = 0; + if ( subtract_target_ratio_db > 0.0f ) + { + subtract_temp = subtract_target_ratio_db / 3.0f; + min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; + lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; + + change_to_downmix = subtract_temp + min_sum_temp + lr_total_bb_temp; + + if ( change_to_downmix >= 1.0f ) + { + change_to_downmix_selection = 1; + } + } + + /* Determine if the determined features match the downmix type, according to another metric */ + if ( lr_total_hi_ratio_db < -12.0f ) + { + subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; + min_sum_temp = min_sum_total_ratio_db / 6.0f; + lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; + + change_to_downmix2 = subtract_temp + min_sum_temp + lr_total_hi_temp; + + if ( change_to_downmix2 >= 1.0f ) + { + change_to_downmix_selection = 1; + } + } + + if ( stereo_type_detect->counter < 400 ) + { + stereo_type_detect->counter++; + } + else + { + if ( change_to_spaced_selection == 1 ) + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_SPACED_MICS; + } + else if ( change_to_downmix_selection == 1 ) + { + stereo_type_detect->masa_stereo_type = MASA_STEREO_DOWNMIX; + } + } + + if ( stereo_type_detect->interpolator == 0 ) + { + if ( stereo_type_detect->current_stereo_type != stereo_type_detect->masa_stereo_type ) + { + stereo_type_detect->interpolator = 1; + stereo_type_detect->type_change_direction = stereo_type_detect->masa_stereo_type; + } + } + + return; +} + + +/*------------------------------------------------------------------------- + * computeIntensityVector_dec() + * + * + *------------------------------------------------------------------------*/ + +void computeIntensityVector_dec( + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t num_frequency_bands, + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z ) +{ + /* + * W = a + ib; Y = c + id + * real(W*Y') = ac + bd + */ + int16_t i; + float real, img; + + for ( i = 0; i < num_frequency_bands; ++i ) + { + real = Cldfb_RealBuffer[0][0][i]; + img = Cldfb_ImagBuffer[0][0][i]; + intensity_real_x[i] = Cldfb_RealBuffer[3][0][i] * real + Cldfb_ImagBuffer[3][0][i] * img; + intensity_real_y[i] = Cldfb_RealBuffer[1][0][i] * real + Cldfb_ImagBuffer[1][0][i] * img; + intensity_real_z[i] = Cldfb_RealBuffer[2][0][i] * real + Cldfb_ImagBuffer[2][0][i] * img; + } + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_lfe_synth_with_cldfb() + * + * + *------------------------------------------------------------------------*/ + +void ivas_lfe_synth_with_cldfb( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t slot_index, + const int16_t subframe_index, + const int16_t nchan_transport ) +{ + float lfeGain; + float transportGain; + float protoLfeReal, protoLfeImag; + int16_t i; + float transportEne, protoLfeEne, targetEneLfe, targetEneTrans; + + set_zero( RealBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + set_zero( ImagBufferLfe[slot_index], CLDFB_NO_CHANNELS_MAX ); + + protoLfeReal = RealBuffer[0][0][0]; + protoLfeImag = ImagBuffer[0][0][0]; + transportEne = RealBuffer[0][0][0] * RealBuffer[0][0][0] + ImagBuffer[0][0][0] * ImagBuffer[0][0][0]; + for ( i = 1; i < nchan_transport; i++ ) + { + protoLfeReal += RealBuffer[i][0][0]; + protoLfeImag += ImagBuffer[i][0][0]; + transportEne += RealBuffer[i][0][0] * RealBuffer[i][0][0] + ImagBuffer[i][0][0] * ImagBuffer[i][0][0]; + } + protoLfeEne = protoLfeReal * protoLfeReal + protoLfeImag * protoLfeImag; + + targetEneLfe = transportEne * hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index]; + targetEneTrans = transportEne * max( ( 1.0f - hMasaLfeSynth->lfeToTotalEnergyRatio[subframe_index] ), 0.01f ); + + hMasaLfeSynth->transportEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->protoLfeEneSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneLfeSmooth *= MCMASA_LFE_SYNTH_ALPHA; + hMasaLfeSynth->targetEneTransSmooth *= MCMASA_LFE_SYNTH_ALPHA; + + hMasaLfeSynth->transportEneSmooth += transportEne; + hMasaLfeSynth->protoLfeEneSmooth += protoLfeEne; + hMasaLfeSynth->targetEneLfeSmooth += targetEneLfe; + hMasaLfeSynth->targetEneTransSmooth += targetEneTrans; + + lfeGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneLfeSmooth / ( EPSILON + hMasaLfeSynth->protoLfeEneSmooth ) ) ); + transportGain = min( 1.0f, sqrtf( hMasaLfeSynth->targetEneTransSmooth / ( EPSILON + hMasaLfeSynth->transportEneSmooth ) ) ); + + RealBufferLfe[slot_index][0] = protoLfeReal * lfeGain; + ImagBufferLfe[slot_index][0] = protoLfeImag * lfeGain; + + RealBuffer[0][0][0] *= transportGain; + ImagBuffer[0][0][0] *= transportGain; + for ( i = 1; i < nchan_transport; i++ ) + { + RealBuffer[i][0][0] *= transportGain; + ImagBuffer[i][0][0] *= transportGain; + } + + return; +} + + +/*------------------------------------------------------------------------- + * rotateAziEle_DirAC() + * + * Apply rotation to DirAC DOAs + *------------------------------------------------------------------------*/ + +void rotateAziEle_DirAC( + int16_t *azi, /* i/o: array of azimuth values */ + int16_t *ele, /* i/o: array of elevation values */ + const int16_t band1, /* i : bands to work on (lower limit) */ + const int16_t band2, /* i : bands to work on (upper bound) */ + const float *p_Rmat /* i : pointer to real-space rotation matrix */ +) +{ + int16_t b; + float dv_0, dv_1, dv_2; + float dv_r_0, dv_r_1, dv_r_2; + float w; + + push_wmops( "rotateAziEle_DirAC" ); + + for ( b = band1; b < band2; b++ ) + { + + /*Conversion spherical to cartesian coordinates*/ + w = cosf( ele[b] * PI_OVER_180 ); + dv_0 = w * cosf( azi[b] * PI_OVER_180 ); + dv_1 = w * sinf( azi[b] * PI_OVER_180 ); + dv_2 = sinf( ele[b] * PI_OVER_180 ); + + dv_r_0 = p_Rmat[0] * dv_0 + p_Rmat[1] * dv_1 + p_Rmat[2] * dv_2; + dv_r_1 = p_Rmat[3] * dv_0 + p_Rmat[4] * dv_1 + p_Rmat[5] * dv_2; + dv_r_2 = p_Rmat[6] * dv_0 + p_Rmat[7] * dv_1 + p_Rmat[8] * dv_2; + + /*Conversion spherical to cartesian coordinates*/ + azi[b] = (int16_t) ( atan2f( dv_r_1, dv_r_0 ) * _180_OVER_PI ); + ele[b] = (int16_t) ( atan2f( dv_r_2, sqrtf( dv_r_0 * dv_r_0 + dv_r_1 * dv_r_1 ) ) * _180_OVER_PI ); + } + + pop_wmops(); + + return; +} diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index e64fdce77a..13daf58297 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -37,6 +37,7 @@ #include "options.h" #include "ivas_error.h" #include "lib_rend.h" +#include "ivas_stat_rend.h" #include "ivas_stat_dec.h" // Note: needed until #156 is resolved /* clang-format off */ @@ -133,7 +134,7 @@ void efap_determine_gains( /*----------------------------------------------------------------------------------* - * SBA rendering + * DirAC/MASA rendering *----------------------------------------------------------------------------------*/ void ivas_sba_prototype_renderer( @@ -151,7 +152,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix( #ifdef FIX_564 -void ivas_dirac_dec_binaural_gain( +void ivas_dirac_dec_binaural_sba_gain( float output[][L_FRAME48k], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ const int16_t output_frame /* i : output frame length */ @@ -187,6 +188,326 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( HRTFS_PARAMBIN_HANDLE *hHrtfParambin /* i/o: HRTF structure for rendering */ ); +/*! r: Configured reqularization factor value */ +float configure_reqularization_factor( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate /* i : total IVAS bitrate */ +); + +ivas_error ivas_dirac_alloc_mem( + DIRAC_REND_HANDLE hDirACRend, + const RENDERER_TYPE renderer_type, + const int16_t num_freq_bands, + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem, + const int16_t hodirac_flag +); + +void ivas_dirac_free_mem( + DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem +); + +void initDiffuseResponses( + float *diffuse_response_function, + const int16_t num_channels, + AUDIO_CONFIG output_config, + IVAS_OUTPUT_SETUP hOutSetup, + const int16_t ambisonics_order, + const IVAS_FORMAT ivas_format, + int16_t *num_ele_spk_no_diffuse_rendering, + AUDIO_CONFIG transport_config +); + +void computeIntensityVector_dec( + float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t num_frequency_bands, + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z +); + +void protoSignalComputation_shd( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_direct_buffer_f, + float *proto_diffuse_buffer_f, + float *reference_power, + const int16_t slot_index, + const int16_t num_inputs, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + float *p_Rmat +); + +void protoSignalComputation1( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands +); + +void protoSignalComputation2( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t isloudspeaker, + const int16_t slot_index, + const int16_t num_freq_bands, + MASA_STEREO_TYPE_DETECT *stereo_type_detect +); + +void protoSignalComputation4( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float *proto_frame_f, + float *proto_direct_buffer_f, + float *reference_power, + float *proto_power_smooth, + const int16_t slot_index, + const int16_t num_outputs_diff, + const int16_t num_freq_bands, + const + float *mtx_hoa_decoder, + const int16_t nchan_transport, + const int16_t *sba_map_tc_ind +); + +void ivas_dirac_dec_compute_diffuse_proto( + DIRAC_REND_HANDLE hDirACRend, + const int16_t num_freq_bands, + const int16_t slot_idx +); + +void computeDirectionAngles( + float *intensity_real_x, + float *intensity_real_y, + float *intensity_real_z, + const int16_t num_frequency_bands, + int16_t *azimuth, + int16_t *elevation +); + +void ivas_masa_init_stereotype_detection( + MASA_STEREO_TYPE_DETECT *stereo_type_detect +); + +void ivas_masa_stereotype_detection( + MASA_STEREO_TYPE_DETECT *stereo_type_detect +); + +void ivas_lfe_synth_with_cldfb( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float RealBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + float ImagBufferLfe[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const int16_t slot_index, + const int16_t subframe_index, + const int16_t nchan_transport +); + +void rotateAziEle_DirAC( + int16_t *azi, + int16_t *ele, + const int16_t band1, + const int16_t band2, + const float *p_Rmat +); + +ivas_error ivas_dirac_dec_onset_detection_open( + const int16_t num_channels, + const int16_t num_freq_bands, + const int16_t max_band_decorr, + DIRAC_ONSET_DETECTION_PARAMS *ph_dirac_onset_detection_params, + DIRAC_ONSET_DETECTION_STATE *ph_dirac_onset_detection_state +); + +void ivas_dirac_dec_onset_detection_process( + const float *input_power_f, + float *onset_filter, + const int16_t num_protos_diff, + DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, + DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state +); + +ivas_error ivas_dirac_dec_decorr_open( + DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, + DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, + const int16_t num_freq_bands, + int16_t num_outputs_diff, + const int16_t num_protos_diff, + const DIRAC_SYNTHESIS_CONFIG synthesisConf, + float *frequency_axis, + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs /* i : output sampling rate */ +); + +void ivas_dirac_dec_decorr_process( + const int16_t num_freq_bands, + int16_t num_channels, + const int16_t num_protos_diff, + const DIRAC_SYNTHESIS_CONFIG synthesisConf, + const int16_t nchan_transport, /* i : number of transport channels */ + const float *input_frame_f, + const int16_t num_protos_dir, + const int16_t *proto_index_dir, + float *frame_dec_f, + float *onset_filter, + HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state +); + +void ivas_dirac_dec_decorr_close( + HANDLE_DIRAC_DECORR_PARAMS *ph_dirac_decorr_params, + HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state +); + +ivas_error ivas_dirac_dec_output_synthesis_open( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_dirac_dec_output_synthesis_init( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const int16_t nchan_out_woLFE, /* i : number of output audio channels without LFE */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_dirac_dec_output_synthesis_close( + DIRAC_REND_HANDLE hDirACRend /* i/o: DirAC handle */ +); + +void ivas_dirac_dec_output_synthesis_process_slot( + const float *reference_power, /* i : Estimated power */ + const float *onset, /* i : onset filter */ + const int16_t *azimuth, + const int16_t *elevation, + const float *diffuseness, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const int16_t sh_rot_max_order, + const float *p_Rmat, /* i : rotation matrix */ + const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ + const IVAS_OUTPUT_SETUP hOutSetup, /* i : output setup structure */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t ind_slot, /* i : index of the slot to be added to the input covariance */ + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const int16_t dec_param_estim /* i : flag to indicate parameter estimation mode */ +); + +void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t nbslots, /* i : number of slots to process */ + const float *onset_filter, + float *diffuseness, + const int16_t hodirac_flag, /* i : flag to indicate HO-DirAC mode */ + const int16_t dec_param_estim /* i : flag to indicate parameter estimation mode */ +); + +void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( + float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX],/* i : LS signals */ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const int16_t nbslots, /* i : number of slots to process */ + float *diffuseness_vector, /* i : diffuseness (needed for direction smoothing)*/ + float *reference_power_smooth, + float qualityBasedSmFactor, + const int16_t enc_param_start_band +); + +void compute_hoa_encoder_mtx( + const float *azimuth, + const float *elevation, + float *response, + const int16_t num_responses, + const int16_t ambisonics_order ); + +void ivas_dirac_dec_compute_gain_factors( + const int16_t num_freq_bands, + const float *diffuseness, + const int16_t max_band_decorr, + float *direct_gain_factor, + float *diffuse_gain_factor +); + +void ivas_dirac_dec_compute_power_factors( + const int16_t num_freq_bands, + const float *diffuseness, + const int16_t max_band_decorr, + float *direct_power_factor, + float *diffuse_power_factor +); + +void ivas_dirac_dec_compute_directional_responses( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ + DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ + const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ + const MASA_DECODER_HANDLE hMasa, /* i : MASA decoder structure */ +#ifdef MASA_AND_OBJECTS + MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ +#endif + const int16_t *azimuth, + const int16_t *elevation, + const int16_t md_idx, + const float *surCohRatio, + const int16_t shd_rot_max_order, /* i : split-order rotation method */ + const float *p_Rmat, /* i : rotation matrix */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +); + +void ivas_dirac_dec_get_frequency_axis( + float *frequency_axis, /* o : array of center frequencies of a real filter bank */ + const int32_t output_Fs, /* i : sampling frequency */ + const int16_t num_freq_bands /* i : number of frequency bands */ +); + +ivas_error ivas_spat_hSpatParamRendCom_config( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out, /* i/o: IVAS decoder structure */ + const DIRAC_CONFIG_FLAG flag_config_inp, /* i/ : Flag determining if we open or reconfigure the DirAC decoder */ + const int16_t dec_param_estim_flag, + const IVAS_FORMAT ivas_format, + const MC_MODE mc_mode, + const int32_t output_Fs, + const int16_t hodirac_flag +); + +void ivas_spat_hSpatParamRendCom_close( + SPAT_PARAM_REND_COMMON_DATA_HANDLE *hSpatParamRendCom_out +); + +void ivas_dirac_rend_close( + DIRAC_REND_HANDLE *hDirACRend_out +); + +ivas_error ivas_dirac_allocate_parameters( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ + const int16_t params_flag /* i : set of parameters flag */ +); + +void ivas_dirac_deallocate_parameters( + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ + const int16_t params_flag /* i : set of parameters flag */ +); + + /*----------------------------------------------------------------------------------* * HRTF diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 40d8127437..2878c78cbc 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -72,6 +72,359 @@ typedef struct ivas_output_setup_structure } IVAS_OUTPUT_SETUP, *IVAS_OUTPUT_SETUP_HANDLE; +/*----------------------------------------------------------------------------------* + * Spatial parametric rendering common structures + *----------------------------------------------------------------------------------*/ + +/*Onset detector*/ +typedef struct dirac_onset_detection_params_structure +{ + int16_t num_freq_bands; + int16_t max_band_decorr; + +} DIRAC_ONSET_DETECTION_PARAMS; + +typedef struct dirac_onset_detection_state_structure +{ + float *onset_detector_1; + float *onset_detector_2; + +} DIRAC_ONSET_DETECTION_STATE; + +/*Decorrelator*/ +typedef struct dirac_decorr_params_structure +{ + int16_t max_band_decorr; + int16_t max_frequency; + + int16_t *pre_delay; + int16_t *filter_length; + float *filter_coeff_num_real; + float *filter_coeff_den_real; + float *phase_coeff_real; + float *phase_coeff_imag; + int16_t *split_frequency_bands; + int16_t num_split_frequency_bands; + + int16_t use_ducker; + int16_t add_back_onsets_on; + + DIRAC_ONSET_DETECTION_PARAMS h_onset_detection_power_params; + +} DIRAC_DECORR_PARAMS, *HANDLE_DIRAC_DECORR_PARAMS; + +typedef struct dirac_decorr_state_structure +{ + float *decorr_buffer; + float *direct_energy_smooth; + float *reverb_energy_smooth; + + DIRAC_ONSET_DETECTION_STATE h_onset_detection_power_state; + +} DIRAC_DECORR_STATE, *HANDLE_DIRAC_DECORR_STATE; + +typedef struct ivas_spatial_parametric_rend_common_data_structure +{ + int16_t slot_size; + int16_t subframe_nbslots[MAX_JBM_SUBFRAMES_5MS]; + int16_t subframes_rendered; + int16_t slots_rendered; + int16_t num_slots; + int16_t render_to_md_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME]; + int16_t nb_subframes; + + int16_t num_freq_bands; +#ifdef MASA_AND_OBJECTS + int16_t numSimultaneousDirections; /* From 1 to 2 + MAX_NUM_OBJECTS */ + int16_t numParametricDirections; /* 1 or 2 */ + int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ +#else + int16_t numSimultaneousDirections; /* 1 or 2 */ +#endif + + int16_t **azimuth; + int16_t **elevation; + int16_t **azimuth2; + int16_t **elevation2; + + float **diffuseness_vector; + float **energy_ratio1; + float **energy_ratio2; + + float **spreadCoherence; + float **spreadCoherence2; + float **surroundingCoherence; + + /* Metadata access indices and buffer size */ + int16_t dirac_bs_md_write_idx; + int16_t dirac_read_idx; + int16_t dirac_md_buffer_length; + +} SPAT_PARAM_REND_COMMON_DATA, *SPAT_PARAM_REND_COMMON_DATA_HANDLE; + + +/*----------------------------------------------------------------------------------* + * DirAC rendering structures + *----------------------------------------------------------------------------------*/ + +typedef struct dirac_dec_stack_mem +{ + /*Decorrelator*/ + float *frame_dec_f; + + /*Prototypes*/ + float *proto_direct_buffer_f; + float *proto_diffuse_buffer_f; + + /*Prototype NRGs*/ + float *proto_power_smooth; + float *proto_power_diff_smooth; + + /*Gain or power factors for directional and diffuse streams*/ + float *direct_power_factor; + float *diffuse_power_factor; + + /*Directional responses (gains & Nrg)*/ + float *direct_responses; + float *direct_responses_square; + + /* Target co-variance mtx */ + float *cy_auto_dir_smooth; + float *cy_cross_dir_smooth; + float *cy_auto_diff_smooth; + + float *reference_power; + float *onset_filter; + +} DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE; + +/*Output synthesis*/ +typedef struct dirac_output_synthesis_params_structure +{ + int16_t max_band_decorr; + + int16_t use_onset_filters; + + float *interpolator; + float *alpha_synthesis; + float *alpha_synthesis_fast; + int16_t numAlphas; + int16_t numAlphasFast; + + float *proto_matrix; + + float diffuse_compensation_factor; + float diffuse_compensation_factor_decorr; + +} DIRAC_OUTPUT_SYNTHESIS_PARAMS; + +typedef struct dirac_output_synthesis_state_structure +{ + /* only pointer to local buffers */ + float *direct_responses; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + float *direct_responses_square; + float *diffuse_responses_square; /* squared diffuse responses. Size: num_channels. */ + + /* only pointer to local buffers */ + float *direct_power_factor; + float *diffuse_power_factor; + + float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + float *proto_power_smooth_prev; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ + + float *proto_power_diff_smooth; + float *proto_power_diff_smooth_prev; + + /* only pointer to local buffers */ + float *proto_direct_buffer_f; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + float *proto_diffuse_buffer_f; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + + /* Output gain memories */ + float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ + float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ + + /* only pointer to local buffers */ + float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ + float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ + float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + + /* PSD memories */ + float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ + + const float *onset_filter; + + /* Temporal smoothing memories */ + float *reference_power_smooth_prev; + float *direction_smoothness_prev; + +} DIRAC_OUTPUT_SYNTHESIS_STATE; + +/* MASA stereo transport signal type detection structure */ +typedef struct +{ + MASA_TRANSPORT_SIGNAL_TYPE masa_stereo_type; + MASA_TRANSPORT_SIGNAL_TYPE current_stereo_type; + MASA_TRANSPORT_SIGNAL_TYPE type_change_direction; + + int16_t dipole_freq_range[2]; + + float left_bb_power; + float right_bb_power; + float total_bb_power; + + float left_hi_power; + float right_hi_power; + float total_hi_power; + + float sum_power[MASA_SUM_FREQ_RANGE_BINS]; + float total_power[MASA_SUM_FREQ_RANGE_BINS]; + + float subtract_power_y; + float subtract_power_y_smooth; + float target_power_y_smooth; + + float lr_total_bb_ratio_db; + float lr_total_hi_ratio_db; + float min_sum_total_ratio_db; + float subtract_target_ratio_db; + + int16_t counter; + int16_t interpolator; + +} MASA_STEREO_TYPE_DETECT; + +/* McMASA LFE synthesis structure */ +typedef struct ivas_mcmasa_lfe_synth_struct +{ + float lfeToTotalEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t lfeGainPrevIndex; + float transportEneSmooth; + float protoLfeEneSmooth; + float targetEneLfeSmooth; + float targetEneTransSmooth; + + float *lfeSynthRingBuffer; + int16_t ringBufferLoPointer; + int16_t ringBufferHiPointer; + float lowpassSum; + int16_t ringBufferSize; + + float *lfeSynthRingBuffer2; + int16_t ringBufferLoPointer2; + float lowpassSum2; + int16_t ringBufferSize2; + + float *delayBuffer_syncLp; + int16_t delayBuffer_syncLp_size; + + float *delayBuffer_syncDirAC; + int16_t delayBuffer_syncDirAC_size; + + float lfeGainPrev; + float transportGainPrev; + float interpolator[CLDFB_NO_CHANNELS_MAX]; + +} MCMASA_LFE_SYNTH_DATA, *MCMASA_LFE_SYNTH_DATA_HANDLE; + +/* DirAC renderer main structure */ +typedef struct ivas_dirac_rend_data_structure +{ + IVAS_OUTPUT_SETUP hOutSetup; + + /*Parameter estimation*/ + int16_t index_buffer_intensity; + float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + float *buffer_energy; + + float *frequency_axis; + float *diffuse_response_function; + float *hoa_encoder; + const float *hoa_decoder; + + /*Decoder parameters */ + /*Prototypes*/ + int16_t num_outputs_dir; + int16_t num_outputs_diff; + int16_t num_protos_dir; + int16_t num_protos_diff; + int16_t num_protos_ambi; + DIRAC_SYNTHESIS_CONFIG synthesisConf; + DIRAC_PANNING_CONFIG panningConf; + + /* prototype computing */ + int16_t *proto_index_dir; + int16_t *proto_index_diff; + + int16_t proto_signal_decorr_on; + + /*Decoder states=memories*/ + float *proto_frame_f; + float *proto_frame_dec_f; + + DIRAC_DEC_STACK_MEM stack_mem; + MASA_STEREO_TYPE_DETECT *masa_stereo_type_detect; + + int16_t num_ele_spk_no_diffuse_rendering; + + const int16_t *sba_map_tc; + + DIRAC_OUTPUT_SYNTHESIS_PARAMS h_output_synthesis_psd_params; + DIRAC_OUTPUT_SYNTHESIS_STATE h_output_synthesis_psd_state; + + HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params; + HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state; + +} DIRAC_REND_DATA, *DIRAC_REND_HANDLE; + + +/*----------------------------------------------------------------------------------* + * VBAP structures + *----------------------------------------------------------------------------------*/ + +/* Defines a single virtual surface triplet of loudspeakers + * with a precalculated inverse matrix */ +typedef struct vbap_vs_triplet_structure +{ + uint8_t speaker_node[3]; + float inverse_matrix[3][3]; + +} VBAP_VS_TRIPLET; + + +/* Storage structure for fast runtime triplet search */ +typedef struct triplet_search_structure +{ + VBAP_VS_TRIPLET *triplets; + int16_t num_triplets; + int16_t initial_search_indices[VBAP_NUM_SEARCH_SECTORS]; + +} VBAP_SEARCH_STRUCT; + + +/* VBAP data structure. Contains the formed virtual surface arrangement * and supporting data. */ +typedef struct vbap_data_structure +{ + VBAP_SEARCH_STRUCT search_struct[2]; /* Default to max two groups in this implementation */ + int16_t num_search_structs; + int16_t num_speaker_nodes; + int16_t num_speaker_nodes_internal; + int16_t top_virtual_speaker_node_index; /* These indices can be negative */ + int16_t bottom_virtual_speaker_node_index; + int16_t back_virtual_speaker_node_index; + float *bottom_virtual_speaker_node_division_gains; + float *top_virtual_speaker_node_division_gains; + float *back_virtual_speaker_node_division_gains; +#ifdef MASA_AND_OBJECTS + float *object_mode_bottom_virtual_speaker_node_division_gains; + float *object_mode_top_virtual_speaker_node_division_gains; + float *object_mode_back_virtual_speaker_node_division_gains; +#endif + +} VBAP_DATA, *VBAP_HANDLE; + + /*----------------------------------------------------------------------------------* * Binaural FastConv Rendering structure *----------------------------------------------------------------------------------*/ @@ -114,6 +467,17 @@ typedef struct ivas_binaural_reverb_struct } REVERB_STRUCT, *REVERB_STRUCT_HANDLE; + +/* Diffuse sound directional distribution data structure */ +typedef struct ivas_diffuse_distribution_data_structure +{ + float diffuseRatioX[CLDFB_NO_CHANNELS_MAX]; + float diffuseRatioY[CLDFB_NO_CHANNELS_MAX]; + float diffuseRatioZ[CLDFB_NO_CHANNELS_MAX]; + +} DIFFUSE_DISTRIBUTION_DATA, *DIFFUSE_DISTRIBUTION_HANDLE; + + /* Parametric binaural data structure */ typedef struct ivas_dirac_dec_binaural_data_structure { @@ -155,11 +519,15 @@ typedef struct ivas_dirac_dec_binaural_data_structure #endif float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; - uint16_t useSubframeMode; /* 0 = process in 20 ms frames, 1 = process in 5 ms subframes */ uint16_t useTdDecorr; ivas_td_decorr_state_t *hTdDecorr; float reqularizationFactor; + DIFFUSE_DISTRIBUTION_HANDLE hDiffuseDist; + + HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params; + HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state; + } DIRAC_DEC_BIN_DATA, *DIRAC_DEC_BIN_HANDLE; typedef struct ivas_binaural_rendering_conv_module_struct diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 6ad462c711..1a40a57bf2 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2994,11 +2994,11 @@ static ivas_error initMasaDummyDecForMcOut( } decDummy->hQMetaData->coherence_flag = 1; - if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } - decDummy->hDirAC->dirac_bs_md_write_idx = 0; + decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0; if ( decDummy->renderer_type == RENDERER_STEREO_PARAMETRIC ) { @@ -3072,11 +3072,11 @@ static ivas_error initMasaDummyDecForSbaOut( } decDummy->hQMetaData->coherence_flag = 1; - if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } - decDummy->hDirAC->dirac_bs_md_write_idx = 0; + decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0; numCldfbAnalyses = decDummy->nchan_transport; numCldfbSyntheses = decDummy->hDecoderConfig->nchan_out; @@ -3146,11 +3146,11 @@ static ivas_error initMasaDummyDecForBinauralOut( decDummy->ivas_format = MASA_FORMAT; decDummy->transport_config = AUDIO_CONFIG_INVALID; - if ( ( error = ivas_dirac_dec_open( decDummy ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_dirac_dec_config( decDummy, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { return error; } - decDummy->hDirAC->dirac_bs_md_write_idx = 0; + decDummy->hSpatParamRendCom->dirac_bs_md_write_idx = 0; if ( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &decDummy->hHrtfParambin ) ) != IVAS_ERR_OK ) { @@ -3245,6 +3245,8 @@ static DecoderDummy *initDecoderDummy( decDummy->hVBAPdata = NULL; // note: not used at the moment decDummy->hMasa = NULL; decDummy->hDiracDecBin = NULL; + decDummy->hDirACRend = NULL; + decDummy->hSpatParamRendCom = NULL; decDummy->hQMetaData = NULL; decDummy->hHrtfParambin = NULL; decDummy->hHeadTrackData = NULL; @@ -3432,6 +3434,8 @@ static void freeDecoderDummy( } /* DirAC handle */ + ivas_dirac_rend_close( &( pDecDummy->hDirACRend ) ); + ivas_spat_hSpatParamRendCom_close( &( pDecDummy->hSpatParamRendCom ) ); ivas_dirac_dec_close( &( pDecDummy->hDirAC ) ); /* Qmetadata handle */ @@ -3447,6 +3451,9 @@ static void freeDecoderDummy( pDecDummy->hoa_dec_mtx = NULL; } + /* Parametric binaural renderer HRTF structure */ + free( pDecDummy->hHrtfParambin ); + /* Parametric binaural renderer handle */ ivas_dirac_dec_close_binaural_data( &pDecDummy->hDiracDecBin ); @@ -7821,44 +7828,44 @@ static ivas_error renderActiveInputsSba( static void copyMasaMetadataToDiracRenderer( MASA_METADATA_FRAME *meta, - DIRAC_DEC_HANDLE hDirAC ) + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom ) { int16_t band, sf, bin; int16_t meta_write_index; #ifdef MASA_AND_OBJECTS - hDirAC->numParametricDirections = meta->descriptive_meta.numberOfDirections + 1; + hSpatParamRendCom->numParametricDirections = meta->descriptive_meta.numberOfDirections + 1; #endif - hDirAC->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1; + hSpatParamRendCom->numSimultaneousDirections = meta->descriptive_meta.numberOfDirections + 1; for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { - meta_write_index = ( hDirAC->dirac_bs_md_write_idx + sf ) % hDirAC->dirac_md_buffer_length; + meta_write_index = ( hSpatParamRendCom->dirac_bs_md_write_idx + sf ) % hSpatParamRendCom->dirac_md_buffer_length; for ( band = 0; band < MASA_MAXIMUM_CODING_SUBBANDS; band++ ) { for ( bin = MASA_band_grouping_24[band]; bin < MASA_band_grouping_24[band + 1]; bin++ ) { - hDirAC->azimuth[meta_write_index][bin] = (int16_t) meta->directional_meta[0].azimuth[sf][band]; - hDirAC->elevation[meta_write_index][bin] = (int16_t) meta->directional_meta[0].elevation[sf][band]; - hDirAC->energy_ratio1[meta_write_index][bin] = meta->directional_meta[0].energy_ratio[sf][band]; - hDirAC->diffuseness_vector[meta_write_index][bin] = 1.0f - meta->directional_meta[0].energy_ratio[sf][band]; - hDirAC->spreadCoherence[meta_write_index][bin] = meta->directional_meta[0].spread_coherence[sf][band]; - hDirAC->surroundingCoherence[meta_write_index][bin] = meta->common_meta.surround_coherence[sf][band]; - - if ( hDirAC->numSimultaneousDirections == 2 ) + hSpatParamRendCom->azimuth[meta_write_index][bin] = (int16_t) meta->directional_meta[0].azimuth[sf][band]; + hSpatParamRendCom->elevation[meta_write_index][bin] = (int16_t) meta->directional_meta[0].elevation[sf][band]; + hSpatParamRendCom->energy_ratio1[meta_write_index][bin] = meta->directional_meta[0].energy_ratio[sf][band]; + hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] = 1.0f - meta->directional_meta[0].energy_ratio[sf][band]; + hSpatParamRendCom->spreadCoherence[meta_write_index][bin] = meta->directional_meta[0].spread_coherence[sf][band]; + hSpatParamRendCom->surroundingCoherence[meta_write_index][bin] = meta->common_meta.surround_coherence[sf][band]; + + if ( hSpatParamRendCom->numSimultaneousDirections == 2 ) { - hDirAC->azimuth2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].azimuth[sf][band]; - hDirAC->elevation2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].elevation[sf][band]; - hDirAC->energy_ratio2[meta_write_index][bin] = meta->directional_meta[1].energy_ratio[sf][band]; - hDirAC->diffuseness_vector[meta_write_index][bin] -= meta->directional_meta[1].energy_ratio[sf][band]; - hDirAC->spreadCoherence2[meta_write_index][bin] = meta->directional_meta[1].spread_coherence[sf][band]; + hSpatParamRendCom->azimuth2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].azimuth[sf][band]; + hSpatParamRendCom->elevation2[meta_write_index][bin] = (int16_t) meta->directional_meta[1].elevation[sf][band]; + hSpatParamRendCom->energy_ratio2[meta_write_index][bin] = meta->directional_meta[1].energy_ratio[sf][band]; + hSpatParamRendCom->diffuseness_vector[meta_write_index][bin] -= meta->directional_meta[1].energy_ratio[sf][band]; + hSpatParamRendCom->spreadCoherence2[meta_write_index][bin] = meta->directional_meta[1].spread_coherence[sf][band]; } } } } - hDirAC->dirac_bs_md_write_idx = ( hDirAC->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hDirAC->dirac_md_buffer_length; + hSpatParamRendCom->dirac_bs_md_write_idx = ( hSpatParamRendCom->dirac_bs_md_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; return; } @@ -7870,7 +7877,7 @@ static void renderMasaToMc( float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer ); - copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC ); + copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom ); if ( masaInput->decDummy->renderer_type == RENDERER_STEREO_PARAMETRIC ) { @@ -7893,7 +7900,7 @@ static void renderMasaToSba( float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer ); - copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC ); + copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom ); ivas_dirac_dec( masaInput->decDummy, tmpBuffer, masaInput->base.inputBuffer.config.numChannels ); @@ -7909,7 +7916,7 @@ static void renderMasaToBinaural( float tmpBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k]; copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer ); - copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hDirAC ); + copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->decDummy->hSpatParamRendCom ); ivas_dirac_dec_binaural( masaInput->decDummy, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer, masaInput->base.inputBuffer.config.numChannels ); -- GitLab From 230ea69f335a799a3b36a3398a5e3d1f5e069310 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 18:28:10 +0200 Subject: [PATCH 144/173] - fix logic around FIX_ISM2_64KBPS / FIX_ISM2_64KBPS_COMBINED_FORMAT - clang format --- lib_com/ivas_ism_com.c | 47 +++++++++----------- lib_com/options.h | 6 ++- lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_ism_renderer.c | 2 +- lib_dec/ivas_masa_dec.c | 4 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 10 +++-- lib_rend/ivas_stat_rend.h | 2 +- lib_rend/lib_rend.c | 2 +- 8 files changed, 37 insertions(+), 38 deletions(-) diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 0af16be8a6..b01577dacd 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -363,10 +363,6 @@ ivas_error ivas_ism_config( } /* limitation to avoid too high bitrate in one active TCX channel */ -#ifdef FIX_ISM2_64KBPS_COMBINED_FORMAT - /* Todo: the alternative is to make sure there are less than n_ism -1 objects inactive; but this way is simpler (Todo VE to check )*/ - if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k && combined_format_flag == 0 ) -#else if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k ) { diff = 0; @@ -380,41 +376,40 @@ ivas_error ivas_ism_config( bits_CoreCoder[ch] = tmp; } } -#endif - if ( diff > 0 ) + if ( diff > 0 ) + { + ch = 0; + for ( ch = 0; ch < n_ISms; ch++ ) { - ch = 0; - for ( ch = 0; ch < n_ISms; ch++ ) + if ( flag_higher[ch] == 0 ) { - if ( flag_higher[ch] == 0 ) + if ( diff > limit_high ) { - if ( diff > limit_high ) + diff += bits_CoreCoder[ch] - limit_high; + bits_CoreCoder[ch] = limit_high; + } + else + { + bits_CoreCoder[ch] += diff; +#ifdef DEBUGGING + if ( bits_CoreCoder[ch] == SID_2k40 / FRAMES_PER_SEC ) { - diff += bits_CoreCoder[ch] - limit_high; - bits_CoreCoder[ch] = limit_high; + printf( "\nWarning: ISM bitbudget equal to SID!\n" ); } - else - { - bits_CoreCoder[ch] += diff; -#ifdef DEBUGGING - if ( bits_CoreCoder[ch] == SID_2k40 / FRAMES_PER_SEC ) - { - printf( "\nWarning: ISM bitbudget equal to SID!\n" ); - } #endif #ifdef MASA_AND_OBJECTS - if ( combined_format_flag ) - { - diff = 0; - } -#endif - break; + if ( combined_format_flag ) + { + diff = 0; } +#endif + break; } } } + } #ifdef MASA_AND_OBJECTS if ( combined_format_flag ) diff --git a/lib_com/options.h b/lib_com/options.h index aca3c591a0..749f328875 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -210,7 +210,8 @@ #define FIX_626_VARIABLE_TYPE_MDCT_CONC /* FhG: trivial fix to fix USAN error */ #define FIX_616_DIV_ZERO_MCT /*FhG : Fix UBSAN division by zero error of issue 616*/ -/* ################## End BE DEVELOPMENT switches ######################### */ + +/* OMASA */ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ @@ -220,10 +221,11 @@ #define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ #define OMASA_EXT_OUTPUT /* VA: support of EXT output configuration for OMASA DISC mode */ #define OMASA_BIT_BUFF_SZ1 /* Nokia: increase bitstream index buffer initial size */ -#define FIX_ISM2_64KBPS_COMBINED_FORMAT /* Nokia: Making the fix_562 work with combined format */ #define OMASA_OBJ_REND_CLOSE /* Nokia: close OMASA separate object renderer */ #endif +/* ################## End BE DEVELOPMENT switches ######################### */ + /* #################### Start NON-BE CR switches ########################## */ /* any switch which is non-be wrt operation points tested in selection */ /* all switches in this category should start with "CR_" */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 10e1aac313..495a117bef 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -508,7 +508,7 @@ ivas_error ivas_dec( /* Set the number of objects for the parametric rendering */ dirac_bs_md_write_idx = 0; - if ( st_ivas->hDirAC != NULL ) /* TODO: should this check for st_ivas->hSpatParamRendCom != NULL ? */ + if ( st_ivas->hDirAC != NULL ) /* TODO: should this check for st_ivas->hSpatParamRendCom != NULL ? */ { st_ivas->hSpatParamRendCom->numIsmDirections = 0; if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 24ce4e86a9..e977f99b88 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -432,7 +432,7 @@ ivas_error ivas_masa_ism_separate_object_renderer_close( { if ( st_ivas->hMasaIsmData->delayBuffer[i] != NULL ) { - free(st_ivas->hMasaIsmData->delayBuffer[i] ); + free( st_ivas->hMasaIsmData->delayBuffer[i] ); st_ivas->hMasaIsmData->delayBuffer[i] = NULL; } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a0d98f56dc..eadfbd594b 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1293,7 +1293,7 @@ ivas_error ivas_masa_dec_reconfigure( ivas_renderer_select( st_ivas ); /* Todo: Check this */ -#if 0 && defined(OMASA_BRSW_MONO_FIX) /* TODO */ +#if 0 && defined( OMASA_BRSW_MONO_FIX ) /* TODO */ if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) ) #else @@ -1307,7 +1307,7 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } -#if 0 && defined(OMASA_BRSW_MONO_FIX) +#if 0 && defined( OMASA_BRSW_MONO_FIX ) else if ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) #else else if ( st_ivas->renderer_type == RENDERER_DISABLE ) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 7e30145256..33fec578c3 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -933,7 +933,8 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric const int16_t subframe, const int16_t isHeadtracked #ifdef MASA_AND_OBJECTS - , const MASA_ISM_DATA_HANDLE hMasaIsmData + , + const MASA_ISM_DATA_HANDLE hMasaIsmData #endif ) { @@ -1128,7 +1129,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric isIsmDirection = 1; uint16_t ismDirIndex; ismDirIndex = dirIndex - hSpatParamRendCom->numParametricDirections; - assert( hMasaIsmData != NULL && "hMasaIsmData should not be NULL if we use it"); + assert( hMasaIsmData != NULL && "hMasaIsmData should not be NULL if we use it" ); if ( hMasaIsmData->ism_is_edited[ismDirIndex] ) { aziDeg = hMasaIsmData->azimuth_ism_edited[ismDirIndex]; @@ -1441,10 +1442,11 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( float Rmat[3][3], const int16_t isHeadtracked #ifdef MASA_AND_OBJECTS - , const int16_t nchanSeparateChannels, + , + const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData #endif - ) +) { int16_t chA, chB, bin; int16_t separateCenterChannelRendering; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 2878c78cbc..7311d72778 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -139,7 +139,7 @@ typedef struct ivas_spatial_parametric_rend_common_data_structure int16_t numParametricDirections; /* 1 or 2 */ int16_t numIsmDirections; /* From 0 to MAX_NUM_OBJECTS */ #else - int16_t numSimultaneousDirections; /* 1 or 2 */ + int16_t numSimultaneousDirections; /* 1 or 2 */ #endif int16_t **azimuth; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 582e0d8bfd..24ef348af9 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -8534,7 +8534,7 @@ ivas_error IVAS_REND_GetSamples( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, td_input, -- GitLab From 3fddf874fc1e37d0415ed1081a69b508849a3eca Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 19:41:29 +0200 Subject: [PATCH 145/173] accept OMASA_EXT_OUTPUT --- apps/decoder.c | 28 ++++++++++++++-------------- lib_com/options.h | 1 - lib_dec/ivas_dec.c | 3 +-- lib_dec/ivas_init_dec.c | 23 +++++++++-------------- lib_dec/ivas_masa_dec.c | 4 ---- lib_dec/ivas_output_config.c | 2 -- lib_dec/lib_dec.c | 12 ++++++------ lib_dec/lib_dec.h | 2 +- 8 files changed, 31 insertions(+), 44 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index bcd54f56f1..cb39dd0f1e 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1742,7 +1742,7 @@ static ivas_error initOnFirstGoodFrame( } /* If outputting ISM, get number of objects, open output files and write zero metadata for initial bad frames */ -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( *pBsFormat == IVAS_DEC_BS_OBJ || *pBsFormat == IVAS_DEC_BS_MASA_ISM ) #else if ( *pBsFormat == IVAS_DEC_BS_OBJ ) @@ -1786,7 +1786,7 @@ static ivas_error initOnFirstGoodFrame( } /* If outputting MASA, open output file and write metadata for initial bad frames */ -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( *pBsFormat == IVAS_DEC_BS_MASA || *pBsFormat == IVAS_DEC_BS_MASA_ISM ) #else else if ( *pBsFormat == IVAS_DEC_BS_MASA ) @@ -1798,7 +1798,7 @@ static ivas_error initOnFirstGoodFrame( return error; } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( numInitialBadFrames > 0 ) { #endif @@ -1822,7 +1822,7 @@ static ivas_error initOnFirstGoodFrame( return error; } } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS } #endif } @@ -2154,7 +2154,7 @@ static ivas_error decodeG192( /* Write MASA/ISM metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else if ( bsFormat == IVAS_DEC_BS_OBJ ) @@ -2183,7 +2183,7 @@ static ivas_error decodeG192( } } } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else @@ -2275,7 +2275,7 @@ static ivas_error decodeG192( { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS else if ( bsFormat == IVAS_DEC_BS_MASA_ISM ) { for ( i = 0; i < numObj; i++ ) @@ -2750,7 +2750,7 @@ static ivas_error decodeVoIP( { int16_t i; -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else if ( bsFormat == IVAS_DEC_BS_OBJ ) @@ -2779,7 +2779,7 @@ static ivas_error decodeVoIP( } } } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else @@ -3188,7 +3188,7 @@ static ivas_error decodeVariableSpeed( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else if ( bsFormat == IVAS_DEC_BS_OBJ ) @@ -3217,7 +3217,7 @@ static ivas_error decodeVariableSpeed( } } } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else @@ -3376,7 +3376,7 @@ static ivas_error decodeVariableSpeed( /* Write ISm metadata to external file(s) */ if ( decodedGoodFrame && arg.outputFormat == IVAS_DEC_OUTPUT_EXT ) { -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_OBJ || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else if ( bsFormat == IVAS_DEC_BS_OBJ ) @@ -3405,7 +3405,7 @@ static ivas_error decodeVariableSpeed( } } } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( bsFormat == IVAS_DEC_BS_MASA || bsFormat == IVAS_DEC_BS_MASA_ISM ) #else @@ -3474,7 +3474,7 @@ static ivas_error decodeVariableSpeed( { fprintf( stdout, "\nOutput metadata file: %s\n", MasaFileWriter_getFilePath( masaWriter ) ); } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS else if ( bsFormat == IVAS_DEC_BS_MASA_ISM ) { for ( i = 0; i < numObj; i++ ) diff --git a/lib_com/options.h b/lib_com/options.h index 749f328875..3f2547b42b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -219,7 +219,6 @@ #define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ #define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ #define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ -#define OMASA_EXT_OUTPUT /* VA: support of EXT output configuration for OMASA DISC mode */ #define OMASA_BIT_BUFF_SZ1 /* Nokia: increase bitstream index buffer initial size */ #define OMASA_OBJ_REND_CLOSE /* Nokia: close OMASA separate object renderer */ #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 495a117bef..bd0f071ab9 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -589,7 +589,7 @@ ivas_error ivas_dec( ivas_omasa_dirac_rend( st_ivas, output, output_frame ); } -#ifdef OMASA_EXT_OUTPUT + /* external output */ if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) { /* sanity check in case of bitrate switching */ @@ -609,7 +609,6 @@ ivas_error ivas_dec( mvr2r( output[MAX_OUTPUT_CHANNELS - 2], output[n], output_frame ); mvr2r( output[MAX_OUTPUT_CHANNELS - 1], output[++n], output_frame ); } -#endif } #endif else if ( st_ivas->ivas_format == MC_FORMAT ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b8d708b261..5bf780788f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -784,14 +784,11 @@ ivas_error ivas_init_decoder( if ( output_config == AUDIO_CONFIG_EXTERNAL ) { -#ifdef OMASA_EXT_OUTPUT if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism; } - else -#endif - if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) + else if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; } @@ -2591,6 +2588,14 @@ static ivas_error doSanityChecks_IVAS( } } + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == AUDIO_CONFIG_EXTERNAL ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); + } + } + #ifdef DEBUGGING if ( ( st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || ( output_config != AUDIO_CONFIG_BINAURAL && output_config != AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) ) { @@ -2603,15 +2608,5 @@ static ivas_error doSanityChecks_IVAS( } #endif -#ifdef OMASA_EXT_OUTPUT - if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) - { - if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == AUDIO_CONFIG_EXTERNAL ) - { - return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); - } - } -#endif - return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index eadfbd594b..6306881c9c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -571,11 +571,7 @@ ivas_error ivas_masa_decode( } } -#ifdef OMASA_EXT_OUTPUT if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) -#else - if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) -#endif { create_masa_ext_out_meta( hMasa, hQMetaData, st_ivas->nchan_transport ); } diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index fb5469fe43..60ec7bb665 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -441,12 +441,10 @@ void ivas_renderer_select( { *renderer_type = RENDERER_STEREO_PARAMETRIC; } -#ifdef OMASA_EXT_OUTPUT else if ( output_config == AUDIO_CONFIG_EXTERNAL ) { *renderer_type = RENDERER_DISABLE; } -#endif } #endif else if ( st_ivas->ivas_format == MC_FORMAT ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index d32b153035..64a3a2b2af 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -408,7 +408,7 @@ static IVAS_DEC_BS_FORMAT mapIvasFormat( return IVAS_DEC_BS_SBA; case MASA_FORMAT: return IVAS_DEC_BS_MASA; -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS case MASA_ISM_FORMAT: return IVAS_DEC_BS_MASA_ISM; #endif @@ -1007,13 +1007,13 @@ ivas_error IVAS_DEC_GetNumObjects( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT ) #else if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT ) #endif { -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS *numObjects = hIvasDec->st_ivas->nchan_ism; #else *numObjects = hIvasDec->st_ivas->hDecoderConfig->nchan_out; @@ -1100,7 +1100,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( st_ivas = hIvasDec->st_ivas; -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format != ISM_FORMAT && st_ivas->ivas_format != MASA_ISM_FORMAT ) #else if ( st_ivas->ivas_format != ISM_FORMAT ) @@ -1109,7 +1109,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( return IVAS_ERR_WRONG_MODE; } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( objectIdx >= st_ivas->nchan_ism ) #else if ( objectIdx >= st_ivas->hDecoderConfig->nchan_out ) @@ -1169,7 +1169,7 @@ ivas_error IVAS_DEC_GetMasaMetadata( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS if ( hIvasDec->st_ivas->ivas_format != MASA_FORMAT && hIvasDec->st_ivas->ivas_format != MASA_ISM_FORMAT ) #else if ( hIvasDec->st_ivas->ivas_format != MASA_FORMAT ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index e214796629..52155ec89e 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -116,7 +116,7 @@ typedef enum _IVAS_DEC_BS_FORMAT IVAS_DEC_BS_SBA, IVAS_DEC_BS_OBJ, IVAS_DEC_BS_MASA, -#ifdef OMASA_EXT_OUTPUT +#ifdef MASA_AND_OBJECTS IVAS_DEC_BS_MASA_ISM, #endif IVAS_DEC_BS_UNKOWN = 0xffff -- GitLab From 84c744e657a484b3ab7ffaa956fa8ac6067d1efb Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 19:46:21 +0200 Subject: [PATCH 146/173] accept OMASA_OBJ_REND_CLOSE (with simplification), OMASA_BIT_BUFF_SZ and OMASA_BIT_BUFF_SZ1 --- lib_com/bitstream.c | 8 -------- lib_com/ivas_prot.h | 4 +--- lib_com/options.h | 3 --- lib_dec/ivas_ism_renderer.c | 11 +++++++---- lib_dec/ivas_omasa_dec.c | 30 ++++-------------------------- 5 files changed, 12 insertions(+), 44 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 6b5ea4d6e7..604ddc2b96 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -553,11 +553,7 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_160k ) { -#ifdef OMASA_BIT_BUFF_SZ1 - return 900; -#else return 850; -#endif } else if ( ivas_total_brate <= IVAS_192k ) { @@ -565,11 +561,7 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_256k ) { -#ifdef OMASA_BIT_BUFF_SZ return 1300; -#else - return 1150; -#endif } else if ( ivas_total_brate <= IVAS_384k ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 9cce927c29..3080698450 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5763,11 +5763,9 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ ); -#ifdef OMASA_OBJ_REND_CLOSE -ivas_error ivas_masa_ism_separate_object_renderer_close( +void ivas_masa_ism_separate_object_renderer_close( Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ ); -#endif void ivas_masa_ism_separate_object_render( Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_com/options.h b/lib_com/options.h index 3f2547b42b..ac72906433 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -218,9 +218,6 @@ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix #define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ #define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ -#define OMASA_BIT_BUFF_SZ /* Nokia: increase bitstream index buffer initial size */ -#define OMASA_BIT_BUFF_SZ1 /* Nokia: increase bitstream index buffer initial size */ -#define OMASA_OBJ_REND_CLOSE /* Nokia: close OMASA separate object renderer */ #endif /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index e977f99b88..08017af46f 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -412,18 +412,18 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( } -#ifdef OMASA_OBJ_REND_CLOSE /*-------------------------------------------------------------------------* * ivas_masa_ism_separate_object_renderer_close() * * Close structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ -ivas_error ivas_masa_ism_separate_object_renderer_close( +void ivas_masa_ism_separate_object_renderer_close( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { int16_t i; + if ( st_ivas->hMasaIsmData != NULL ) { if ( st_ivas->hMasaIsmData->delayBuffer != NULL ) @@ -436,10 +436,12 @@ ivas_error ivas_masa_ism_separate_object_renderer_close( st_ivas->hMasaIsmData->delayBuffer[i] = NULL; } } + free( st_ivas->hMasaIsmData->delayBuffer ); st_ivas->hMasaIsmData->delayBuffer = NULL; } } + if ( st_ivas->hIsmRendererData != NULL ) { if ( st_ivas->hIsmRendererData->interpolator != NULL ) @@ -447,13 +449,14 @@ ivas_error ivas_masa_ism_separate_object_renderer_close( free( st_ivas->hIsmRendererData->interpolator ); st_ivas->hIsmRendererData->interpolator = NULL; } + free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } - return IVAS_ERR_OK; + return; } -#endif + /*-------------------------------------------------------------------------* * ivas_masa_ism_separate_object_render() diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 326fc64674..e8add408ef 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -329,19 +329,8 @@ ivas_error ivas_omasa_dec_config( st_ivas->hHrtfTD = NULL; } -#ifdef OMASA_OBJ_REND_CLOSE - if ( ( error = ivas_masa_ism_separate_object_renderer_close( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - /* ISM renderer handle */ - if ( st_ivas->hIsmRendererData != NULL ) - { - free( st_ivas->hIsmRendererData ); - st_ivas->hIsmRendererData = NULL; - } -#endif + /* ISM renderer handle + ISM data handle */ + ivas_masa_ism_separate_object_renderer_close( st_ivas ); } } @@ -362,19 +351,8 @@ ivas_error ivas_omasa_dec_config( } else { -#ifdef OMASA_OBJ_REND_CLOSE - if ( ( error = ivas_masa_ism_separate_object_renderer_close( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - /* ISM renderer handle */ - if ( st_ivas->hIsmRendererData != NULL ) - { - free( st_ivas->hIsmRendererData ); - st_ivas->hIsmRendererData = NULL; - } -#endif + /* ISM renderer handle + ISM data handle */ + ivas_masa_ism_separate_object_renderer_close( st_ivas ); } } -- GitLab From 7bc3e3643ad6c35308beb8cdb8267f16cabf5bff Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 20:06:07 +0200 Subject: [PATCH 147/173] accept switches from #637 --- lib_com/ivas_cnst.h | 13 -- lib_com/options.h | 15 -- lib_dec/dec_tcx.c | 28 ---- lib_dec/gs_dec.c | 4 - lib_dec/ivas_mc_param_dec.c | 10 -- lib_enc/ivas_decision_matrix_enc.c | 31 ---- lib_enc/ivas_mc_param_enc.c | 8 -- lib_enc/ivas_stereo_classifier.c | 5 +- lib_rend/ivas_objectRenderer.c | 48 +------ lib_rend/ivas_objectRenderer_hrFilt.c | 21 +-- lib_rend/ivas_objectRenderer_mix.c | 5 - lib_rend/ivas_objectRenderer_sources.c | 191 ++++++++++--------------- lib_rend/ivas_prot_rend.h | 2 - 13 files changed, 83 insertions(+), 298 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 7790b6d9c1..c747e2e143 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -318,11 +318,7 @@ typedef enum #define MIN_BRATE_SWB_SCE ACELP_9k60 /* min. SCE bitrate where SWB is supported */ #define MIN_BRATE_SWB_STEREO IVAS_13k2 /* min. stereo bitrate where SWB is supported */ #define MIN_BRATE_FB_STEREO IVAS_32k /* min. SCE and stereo bitrate where FB is supported */ -#ifdef ISM_FB_16k4 #define MIN_BRATE_FB_ISM 16000 /* min. SCE bitrate where FB is supported in ISM format */ -#else -#define MIN_BRATE_FB_ISM 24000 /* min. SCE bitrate where FB is supported in ISM format */ -#endif #define MIN_TDM_BRATE_WB_TBE_1k05 12000 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */ #define MIN_BRATE_WB_TBE_1k05 9650 /* min. per channel bitrate where WB TBE @1.05 kbps is supported (0.35kbs at lower bitrates) */ @@ -1678,22 +1674,13 @@ typedef enum typedef enum { TDREND_POSTYPE_ABSOLUTE, /* The source position is in absolute coordinates */ -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT TDREND_POSTYPE_NON_DIEGETIC /* The source position is non-diegetic */ -#else - TDREND_POSTYPE_RELATIVE_TO_LISTENER /* The source position is relative to the listener */ -#endif } TDREND_PosType_t; typedef enum { TDREND_PLAYSTATUS_INITIAL, -#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT - TDREND_PLAYSTATUS_PLAYING, - TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC -#else TDREND_PLAYSTATUS_PLAYING -#endif } TDREND_PlayStatus_t; typedef enum diff --git a/lib_com/options.h b/lib_com/options.h index ac72906433..dd46315152 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,25 +159,10 @@ #define FIX_571_REVERB_NOT_ACTIVATED_ISM /* Philips: Issue 571: Reverb not activated for discrete and parametric ISM */ #define FIX_QMETA_SID_5k2 /* Nokia: Issue 137: enable using full 5.2k bitrate in MASA SID */ -#define FIX_578_PARAMMC_ILD_BS /* FhG: Issue 578: transmitt also center ILD in band 0 when LFE is active in 3TC ParamMC */ -#define FIX_UNCLR_ISSUE /* VoiceAge: issue 574: Fix UNCLR mis-classifications in noisy speech stereo */ -#define FIX_TCX_LOWRATE_LIMITATION /* VA: issue 577: TCX bitrate limitation only when DEBUGGING is active */ -#define FIX_575_LOW_OVERLAP_PLC_RECOVERY /* FhG: Issue 575 fix for PLC and transistion to TCX5*/ - #define FIX_488_SYNC_DELAY /* Eri: Issue 488: Waveform and MD desynchronized in external renderer */ -#define FIX_550_FIRST_FRAME_ACCESS /* Eri: Issue 550: TD Object renderer: first frame accesses wrong transport channel offsets */ -#define FIX_550_FIRST_FRAME_ACCESS_ALT /* Eri: Issue 550: Should be merged with FIX_550_FIRST_FRAME_ACCESS above, or accepted at the same time */ -#define FIX_569_TD_FILTER_LENGTH /* Eri: Issue 569: If an HRTF binary file exceeds the SFX_SPAT_BIN_MAX_FILTER_LENGTH the decoder crashes. This truncates the filter when generated from the model. */ - -#define ISM_FB_16k4 /* VA: Issue: 579: change BW from SWB to FB in NxISM conditions to match the EVS codec */ - #define FIX_580_PARAMMC_ENER_BURSTS /* FhG: issue 580: energy bursts due to ILD holding when energy relations change too much */ -#define FIX_550_FIRST_FRAME_ACCESS /* Eri: Issue 550: TD Object renderer: first frame accesses wrong transport channel offsets */ -#define FIX_550_FIRST_FRAME_ACCESS_ALT /* Eri: Issue 550: Should be merged with FIX_550_FIRST_FRAME_ACCESS above, or accepted at the same time */ -#define FIX_569_TD_FILTER_LENGTH /* Eri: Issue 569: If an HRTF binary file exceeds the SFX_SPAT_BIN_MAX_FILTER_LENGTH the decoder crashes. This truncates the filter when generated from the model. */ - #define FIX_595_SHL_NOGLOB /* FhG: Issue 595: compilation with BASOP_NOGLOB disabled */ #define UPDATE_FASTCONV_SBA_FILTER /* Dlb: Issue 584: Update SBA CLDFB-Domain HRTFs */ #define FIX_570_SF_EXT_ORIENTATION diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index dd10cef293..cffb6a1092 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -377,11 +377,7 @@ void IMDCT( TCX_MDCT_Inverse( x + w * L_spec_TCX5, win, L_ola, L_win - L_ola, L_ola, st->element_mode ); } -#ifndef FIX_575_LOW_OVERLAP_PLC_RECOVERY - tcx_windowing_synthesis_current_frame( win, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( w > 0 ) ? 0 : left_rect, ( w > 0 ) || ( w == 0 && index == 2 ) ? MIN_OVERLAP : hTcxCfg->tcx_last_overlap_mode, acelp_zir, hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, tcx_offset < 0 ? -tcx_offset : 0, ( w > 0 ) || ( frame_cnt > 0 ) ? 1 : st->last_core_bfi, ( w > 0 ) || ( frame_cnt > 0 ) ? 0 : st->last_is_cng, fullbandScale ); -#else tcx_windowing_synthesis_current_frame( win, tcx_aldo_window_2, tcx_mdct_window_half, tcx_mdct_window_minimum, L_ola, tcx_mdct_window_half_length, tcx_mdct_window_min_length, ( w > 0 ) ? 0 : left_rect, ( w > 0 ) || ( w == 0 && index == 2 ) ? MIN_OVERLAP : hTcxCfg->tcx_last_overlap_mode, acelp_zir, hTcxDec->old_syn_Overl, syn_Overl_TDAC, st->old_Aq_12_8, tcx_mdct_window_trans, L_win, tcx_offset < 0 ? -tcx_offset : 0, ( w > 0 ) || ( frame_cnt > 0 ) ? 1 : st->last_core, ( w > 0 ) || ( frame_cnt > 0 ) ? 0 : st->last_is_cng, fullbandScale ); -#endif if ( w > 0 ) { @@ -398,13 +394,11 @@ void IMDCT( /* To assure that no garbage values are passed to overlap */ set_zero( xn_buf + L_frame + tcx_offset + ( L_ola >> 1 ), overlap - tcx_offset - ( L_ola >> 1 ) ); -#ifdef FIX_575_LOW_OVERLAP_PLC_RECOVERY if ( st->prev_bfi && frame_cnt == 0 && st->last_core != st->last_core_bfi && st->last_core_bfi == ACELP_CORE ) { tcx_windowing_synthesis_past_frame( old_syn_overl, tcx_aldo_window_1_trunc, tcx_mdct_window_half, tcx_mdct_window_minimum, overlap, tcx_mdct_window_half_length, tcx_mdct_window_min_length, hTcxCfg->tcx_last_overlap_mode ); v_add( xn_buf, old_syn_overl, xn_buf, overlap ); } -#endif } else if ( !bfi && ( frame_cnt == 0 ) && ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) ) @@ -1252,7 +1246,6 @@ void decoder_tcx_noisefilling( if ( ( frame_cnt == 0 ) && ( L_frameTCX == hTcxDec->L_frameTCX >> 1 ) && ( st->tcxonly ) && ( !st->tonal_mdct_plc_active ) && ( st->nbLostCmpt == 1 ) && ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) { E_2ndlast = E_last = EPSILON; -#ifdef FIX_575_LOW_OVERLAP_PLC_RECOVERY if ( st->element_mode > EVS_MONO ) { for ( i = 0; i < L_frameTCX; i = i + 2 ) @@ -1269,19 +1262,11 @@ void decoder_tcx_noisefilling( E_last += st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] * st->hTonalMDCTConc->lastBlockData.spectralData[i + 1]; } } -#else - for ( i = 0; i < infoIGFStartLine; i = i + 2 ) - { - E_2ndlast += st->hTonalMDCTConc->lastBlockData.spectralData[i] * st->hTonalMDCTConc->lastBlockData.spectralData[i]; - E_last += st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] * st->hTonalMDCTConc->lastBlockData.spectralData[i + 1]; - } -#endif tmp2 = E_2ndlast / E_last; /* replace higher energy TCX5 frame by lower one to avoid energy fluctuation */ if ( tmp2 > 2 ) { -#ifdef FIX_575_LOW_OVERLAP_PLC_RECOVERY if ( st->element_mode > EVS_MONO ) { for ( i = 0; i < L_frameTCX; i = i + 2 ) @@ -1296,16 +1281,9 @@ void decoder_tcx_noisefilling( st->hTonalMDCTConc->lastBlockData.spectralData[i] = st->hTonalMDCTConc->lastBlockData.spectralData[i + 1]; } } -#else - for ( i = 0; i < infoIGFStartLine; i = i + 2 ) - { - st->hTonalMDCTConc->lastBlockData.spectralData[i] = st->hTonalMDCTConc->lastBlockData.spectralData[i + 1]; - } -#endif } else if ( tmp2 < 0.5 ) { -#ifdef FIX_575_LOW_OVERLAP_PLC_RECOVERY if ( st->element_mode > EVS_MONO ) { for ( i = 0; i < L_frameTCX; i = i + 2 ) @@ -1320,12 +1298,6 @@ void decoder_tcx_noisefilling( st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] = st->hTonalMDCTConc->lastBlockData.spectralData[i]; } } -#else - for ( i = 0; i < infoIGFStartLine; i = i + 2 ) - { - st->hTonalMDCTConc->lastBlockData.spectralData[i + 1] = st->hTonalMDCTConc->lastBlockData.spectralData[i]; - } -#endif } } diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index 1244f97793..5ed7aa92c4 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -104,11 +104,7 @@ void decod_audio( } /* safety check in case of bit errors */ -#ifdef ISM_FB_16k4 if ( st->GSC_noisy_speech && st->bwidth < SWB && st->GSC_IVAS_mode == 0 ) -#else - if ( st->GSC_noisy_speech && st->bwidth != SWB && st->GSC_IVAS_mode == 0 ) -#endif { st->BER_detect = 1; st->GSC_noisy_speech = 0; diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 8f750fa819..0ba001d415 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -3090,19 +3090,13 @@ static void ivas_param_mc_bs_decode_parameter_values( int16_t i, j, k; float dequant_seq[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE]; float dequant_ordered[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE]; -#ifdef FIX_578_PARAMMC_ILD_BS int16_t n_lfe_idx; -#endif range_coding = bit_buffer[( *bit_pos )++]; /* Decoding the sequence */ -#ifdef FIX_578_PARAMMC_ILD_BS n_lfe_idx = map_size - map_size_wo_lfe; sz_seq = num_param_bands * ( map_size_wo_lfe ) + num_lfe_bands * n_lfe_idx; -#else - sz_seq = num_param_bands * ( map_size_wo_lfe ) + num_lfe_bands; -#endif set_s( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); set_zero( dequant_ordered, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); @@ -3163,14 +3157,10 @@ static void ivas_param_mc_bs_decode_parameter_values( for ( i = 0; i < num_lfe_bands; i++ ) { -#ifdef FIX_578_PARAMMC_ILD_BS for ( j = 0; j < n_lfe_idx; j++ ) { dequant_ordered[map_size - n_lfe_idx + j + i * map_size] = dequant_seq[k++]; } -#else - dequant_ordered[map_size - 1 + i * map_size] = dequant_seq[k++]; -#endif } if ( !( *BER_detect ) ) diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index ec4cae5845..a30ae27740 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -164,20 +164,6 @@ void ivas_decision_matrix_enc( /* select TCX core or HQ core using bits_frame_nominal to match the TCX configuration bitrate */ st->core = mdct_classifier( st, fft_buff, enerBuffer, st->bits_frame_nominal * FRAMES_PER_SEC ); } - -#ifndef FIX_TCX_LOWRATE_LIMITATION - /* Warning: TCX not available at low bitrates -> replace it by GSC */ - if ( st->core == TCX_20_CORE && st->total_brate < STEREO_TCX_MIN_RATE ) - { - st->core = ACELP_CORE; - st->coder_type = AUDIO; - st->sp_aud_decision2 = 0; - if ( st->low_rate_mode ) - { - st->coder_type = INACTIVE; - } - } -#endif } /* do not allow TD stereo ACELP core -> DFT stereo TCX core switching as it is on the WC complexity path */ @@ -223,24 +209,8 @@ void ivas_decision_matrix_enc( st->core = HQ_CORE; } } - -#ifndef FIX_TCX_LOWRATE_LIMITATION - /* TCX not available at low bitrates -> replace it by GSC */ - if ( st->core == TCX_20_CORE && st->total_brate < STEREO_TCX_MIN_RATE ) - { - st->core = ACELP_CORE; - st->coder_type = AUDIO; - st->sp_aud_decision2 = 0; - - if ( st->low_rate_mode ) - { - st->coder_type = INACTIVE; - } - } -#endif #endif -#ifdef FIX_TCX_LOWRATE_LIMITATION /* TCX not available at low bitrates -> replace it by GSC */ if ( st->core == TCX_20_CORE && st->total_brate < STEREO_TCX_MIN_RATE ) { @@ -253,7 +223,6 @@ void ivas_decision_matrix_enc( st->coder_type = INACTIVE; } } -#endif /*---------------------------------------------------------------------* * Select ACELP and GSC extension layer diff --git a/lib_enc/ivas_mc_param_enc.c b/lib_enc/ivas_mc_param_enc.c index 95bb61c12d..248cae9e4d 100644 --- a/lib_enc/ivas_mc_param_enc.c +++ b/lib_enc/ivas_mc_param_enc.c @@ -1734,7 +1734,6 @@ static void ivas_param_mc_encode_parameter( if ( hMetadataPMC->bAttackPresent || hMetadataPMC->param_frame_idx == hMetadataPMC->coding_band_mapping[i] ) { /* LFE ICC/ILDs are always the last ones in coding band 0 */ -#ifdef FIX_578_PARAMMC_ILD_BS int16_t n_lfe_idx, k; n_lfe_idx = map_size - map_size_wo_lfe; for ( k = 0; k < n_lfe_idx; k++ ) @@ -1745,13 +1744,6 @@ static void ivas_param_mc_encode_parameter( idx_prev = idx; sz_seq++; } -#else - idx = quant_idx[( i + 1 ) * map_size - 1]; - seq[sz_seq] = idx; - seq_delta[sz_seq] = idx - idx_prev + idx_offset; - idx_prev = idx; - sz_seq++; -#endif } } } diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 5d672616fc..cedccea00e 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -107,10 +107,7 @@ int16_t select_stereo_mode( /* set binary flag indicating LRTD mode based on unclr/xtalk classifiers' decisions */ hStereoClassif->prev_lrtd_mode = hStereoClassif->lrtd_mode; -#ifdef FIX_UNCLR_ISSUE - hStereoClassif->unclr_decision = ( hStereoClassif->unclr_decision && hCPE->hCoreCoder[0]->flag_noisy_speech_snr == 0 && - hCPE->element_brate > IVAS_16k4 ); -#endif + hStereoClassif->unclr_decision = ( hStereoClassif->unclr_decision && hCPE->hCoreCoder[0]->flag_noisy_speech_snr == 0 && hCPE->element_brate > IVAS_16k4 ); hStereoClassif->lrtd_mode = ( ( hStereoClassif->unclr_decision | hStereoClassif->xtalk_decision ) && is_speech ); stereo_switching_flag = 1; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index fc7f3b8f9a..be161c50e9 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -307,21 +307,6 @@ ivas_error ivas_td_binaural_renderer_unwrap( hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; c_indx++; } -#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT -#ifdef FIX_550_FIRST_FRAME_ACCESS - if ( ivas_format == ISM_FORMAT ) - { - if ( hIsmMetaData[nS]->non_diegetic_flag ) - { - TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ); - } - else - { - TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING ); - } - } -#endif -#endif } for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) @@ -348,7 +333,6 @@ ivas_error ivas_td_binaural_renderer_unwrap( return error; } -#ifdef FIX_550_FIRST_FRAME_ACCESS /* Advance subframe pointer */ c_indx = 0; for ( nS = 0; nS < num_src; nS++ ) @@ -359,7 +343,6 @@ ivas_error ivas_td_binaural_renderer_unwrap( c_indx++; } } -#endif } if ( hReverb != NULL ) @@ -396,9 +379,6 @@ ivas_error TDREND_GetMix( float hrf_left_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; float hrf_right_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; int16_t intp_count; -#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT - float pan_left, pan_right; -#endif int16_t subframe_update_flag; subframe_update_flag = subframe_idx == ism_md_subframe_update; @@ -434,21 +414,6 @@ ivas_error TDREND_GetMix( { error = TDREND_REND_RenderSourceHRFilt( Src_p, hrf_left_delta, hrf_right_delta, intp_count, output_buf, subframe_length ); } - -#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT - if ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ) ) - { - pan_left = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; - pan_right = 1.f - pan_left; -#ifdef FIX_550_FIRST_FRAME_ACCESS - v_multc_acc( Src_p->InputFrame_p, pan_left, output_buf[0], subframe_length ); - v_multc_acc( Src_p->InputFrame_p, pan_right, output_buf[1], subframe_length ); -#else - v_multc_acc( &Src_p->InputFrame_p[subframe_idx * subframe_length], pan_left, output_buf[0], subframe_length ); - v_multc_acc( &Src_p->InputFrame_p[subframe_idx * subframe_length], pan_right, output_buf[1], subframe_length ); -#endif - } -#endif } /* Populate output variable */ @@ -529,24 +494,13 @@ void TDREND_Update_object_positions( Pos[1] = hIsmMetaData[nS]->azimuth / 90.f; Pos[2] = 0; TDREND_MIX_SRC_SetPos( hBinRendererTd, nS, Pos ); -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_NON_DIEGETIC; -#else -#ifndef FIX_550_FIRST_FRAME_ACCESS - TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ); -#endif -#endif } else { -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_ABSOLUTE; -#else -#ifndef FIX_550_FIRST_FRAME_ACCESS - TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING ); -#endif -#endif } + TDREND_MIX_SRC_SetDir( hBinRendererTd, nS, Dir ); } } diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index 8fb081da22..c73b28a531 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -79,11 +79,6 @@ ivas_error TDREND_REND_RenderSourceHRFilt( v_add( LeftOutputFrame, output_buf[0], output_buf[0], subframe_length ); v_add( RightOutputFrame, output_buf[1], output_buf[1], subframe_length ); -#ifndef FIX_550_FIRST_FRAME_ACCESS - Src_p->InputFrame_p += subframe_length; /* Increment input pointer */ -#endif - - return IVAS_ERR_OK; } @@ -99,24 +94,18 @@ void GetFilterFromAngle( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* i/o: HR filter set structure */ const float Elev, /* i : Elevation, degrees */ float Azim, /* i : Azimuth, degrees */ -#ifdef FIX_569_TD_FILTER_LENGTH - const int16_t filterlength, /* i : Filter length */ -#endif - float *hrf_left, /* o : Left HR filter */ - float *hrf_right, /* o : Right HR filter */ - int16_t *itd /* o : ITD value */ + const int16_t filterlength, /* i : Filter length */ + float *hrf_left, /* o : Left HR filter */ + float *hrf_right, /* o : Right HR filter */ + int16_t *itd /* o : ITD value */ ) { GenerateFilter( Elev, Azim, &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ); -#ifdef FIX_569_TD_FILTER_LENGTH mvr2r( HrFiltSet_p->ModelEval.hrfModL, hrf_left, filterlength ); mvr2r( HrFiltSet_p->ModelEval.hrfModR, hrf_right, filterlength ); -#else - mvr2r( HrFiltSet_p->ModelEval.hrfModL, hrf_left, HrFiltSet_p->ModelParams.K ); - mvr2r( HrFiltSet_p->ModelEval.hrfModR, hrf_right, HrFiltSet_p->ModelParams.K ); -#endif + /* 4. Evaluate the ITD */ if ( HrFiltSet_p->ModelParams.UseItdModel ) { diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index e218002345..60a66b168c 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -309,17 +309,12 @@ ivas_error TDREND_MIX_AddSrc( } else { -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT if ( ( PosType < TDREND_POSTYPE_ABSOLUTE ) || ( PosType > TDREND_POSTYPE_NON_DIEGETIC ) ) -#else - if ( ( PosType < TDREND_POSTYPE_ABSOLUTE ) || ( PosType > TDREND_POSTYPE_RELATIVE_TO_LISTENER ) ) -#endif { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid position type!\n" ) ); } else { - /* Alloc and init a complete source: signal+spatial+rend components */ if ( ( error = TDREND_SRC_Alloc( &Src_p ) ) != IVAS_ERR_OK ) { diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 72fc1b4da4..50d68e8944 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -218,11 +218,8 @@ static void TDREND_SRC_REND_Init( /* Internal state */ SrcRend_p->InputAvailable = FALSE; -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT SrcRend_p->PlayStatus = TDREND_PLAYSTATUS_PLAYING; -#else - SrcRend_p->PlayStatus = TDREND_PLAYSTATUS_INITIAL; -#endif + /* SrcGain */ for ( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { @@ -279,132 +276,101 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams( Listener_p = hBinRendererTd->Listener_p; HrFiltSet_p = hBinRendererTd->HrFiltSet_p; -#ifdef FIX_569_TD_FILTER_LENGTH *filterlength = min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); -#else - *filterlength = HrFiltSet_p->FiltLength; -#endif -#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT - /* 1. Map source pos to the coordinate system of the listener */ - switch ( SrcSpatial_p->PosType ) - { - case TDREND_POSTYPE_RELATIVE_TO_LISTENER: - /* Listener relative position */ - mvr2r( SrcSpatial_p->Pos_p, ListRelPos, 3 ); - break; - case TDREND_POSTYPE_ABSOLUTE: - /* Absolute position */ - TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); - break; - default: /* Illegal position type */ -#ifdef DEBUGGING - printf( "Warning! TDREND_SRC_REND_UpdateFiltersFromSpatialParams: Invalid position type. Assuming absolute position!\n" ); -#endif - /* Assume absolute position */ - TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); - break; - } -#else if ( SrcSpatial_p->PosType == TDREND_POSTYPE_ABSOLUTE ) { /* Absolute position */ TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); -#endif - ListRelDist = TDREND_SPATIAL_VecNorm( ListRelPos ); + ListRelDist = TDREND_SPATIAL_VecNorm( ListRelPos ); - /* 2. Evaluate the Elevation and Azimuth angles */ - if ( ( ListRelPos[0] == 0 ) && ( ListRelPos[1] == 0 ) && ( ListRelPos[2] == 0 ) ) - { - Elev = 0.0; - Azim = 0.0; - } - else - { - Elev = _180_OVER_PI * atan2f( ListRelPos[2], sqrtf( ListRelPos[0] * ListRelPos[0] + ListRelPos[1] * ListRelPos[1] ) ); - /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ - Azim = -1.0f * _180_OVER_PI * (float) atan2f( ListRelPos[1], ListRelPos[0] ); - } + /* 2. Evaluate the Elevation and Azimuth angles */ + if ( ( ListRelPos[0] == 0 ) && ( ListRelPos[1] == 0 ) && ( ListRelPos[2] == 0 ) ) + { + Elev = 0.0; + Azim = 0.0; + } + else + { + Elev = _180_OVER_PI * atan2f( ListRelPos[2], sqrtf( ListRelPos[0] * ListRelPos[0] + ListRelPos[1] * ListRelPos[1] ) ); + /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ + Azim = -1.0f * _180_OVER_PI * (float) atan2f( ListRelPos[1], ListRelPos[0] ); + } -#ifdef FIX_569_TD_FILTER_LENGTH - GetFilterFromAngle( HrFiltSet_p, Elev, Azim, *filterlength, hrf_left, hrf_right, itd ); -#else - GetFilterFromAngle( HrFiltSet_p, Elev, Azim, hrf_left, hrf_right, itd ); -#endif + GetFilterFromAngle( HrFiltSet_p, Elev, Azim, *filterlength, hrf_left, hrf_right, itd ); - /* 6. Evaluate the directional and distance gains */ - /* Directional gain */ - *SrcRend_p->DirGain_p = 1.0f; - if ( SrcSpatial_p->DirAttenEnabled ) - { - *SrcRend_p->DirGain_p = TDREND_SRC_SPATIAL_GetDirGain( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p, ListRelPosAbs ); - } + /* 6. Evaluate the directional and distance gains */ + /* Directional gain */ + *SrcRend_p->DirGain_p = 1.0f; + if ( SrcSpatial_p->DirAttenEnabled ) + { + *SrcRend_p->DirGain_p = TDREND_SRC_SPATIAL_GetDirGain( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p, ListRelPosAbs ); + } - /* Distance gain */ - *SrcRend_p->DistGain_p = 1.0f; - if ( hBinRendererTd->UseCommonDistAttenModel ) - { - if ( hBinRendererTd->DistAttenEnabled ) + /* Distance gain */ + *SrcRend_p->DistGain_p = 1.0f; + if ( hBinRendererTd->UseCommonDistAttenModel ) { - SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; - *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); + if ( hBinRendererTd->DistAttenEnabled ) + { + SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); + } } - } - else - { - if ( SrcSpatial_p->DistAttenEnabled ) + else { - *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); + if ( SrcSpatial_p->DistAttenEnabled ) + { + *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); + } } - } - /* Update total gains */ - *Gain = ( *SrcRend_p->SrcGain_p ) * ( *SrcRend_p->DirGain_p ) * ( *SrcRend_p->DistGain_p ) * hBinRendererTd->Gain; + /* Update total gains */ + *Gain = ( *SrcRend_p->SrcGain_p ) * ( *SrcRend_p->DirGain_p ) * ( *SrcRend_p->DistGain_p ) * hBinRendererTd->Gain; - /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ - elev_delta = Elev - Src_p->elev_prev; - azim_delta = Azim - Src_p->azim_prev; - Src_p->elev_prev = Elev; - Src_p->azim_prev = Azim; + /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ + elev_delta = Elev - Src_p->elev_prev; + azim_delta = Azim - Src_p->azim_prev; + Src_p->elev_prev = Elev; + Src_p->azim_prev = Azim; - azim_delta = ( azim_delta > 180.0f ) ? ( azim_delta - 360 ) : ( ( azim_delta < -180.0f ) ? ( azim_delta + 360 ) : ( azim_delta ) ); /* map to -180:180 range */ - *intp_count = min( MAX_INTERPOLATION_STEPS, max( (int16_t) ( fabsf( azim_delta ) * MAX_ANGULAR_STEP_INV ), (int16_t) ( fabsf( elev_delta ) * MAX_ANGULAR_STEP_INV ) ) ); -#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT -} -else /* TDREND_POSTYPE_NON_DIEGETIC */ -{ - *itd = 0; - *Gain = 1.0f; - set_f( hrf_left, 0.0f, *filterlength ); - set_f( hrf_right, 0.0f, *filterlength ); - hrf_left[0] = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; - hrf_right[0] = 1.f - hrf_left[0]; - *intp_count = MAX_INTERPOLATION_STEPS; - Src_p->elev_prev = 0; - Src_p->azim_prev = 360.0f; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ -} -#endif + azim_delta = ( azim_delta > 180.0f ) ? ( azim_delta - 360 ) : ( ( azim_delta < -180.0f ) ? ( azim_delta + 360 ) : ( azim_delta ) ); /* map to -180:180 range */ + *intp_count = min( MAX_INTERPOLATION_STEPS, max( (int16_t) ( fabsf( azim_delta ) * MAX_ANGULAR_STEP_INV ), (int16_t) ( fabsf( elev_delta ) * MAX_ANGULAR_STEP_INV ) ) ); + } + else /* TDREND_POSTYPE_NON_DIEGETIC */ + { + *itd = 0; + *Gain = 1.0f; + set_f( hrf_left, 0.0f, *filterlength ); + set_f( hrf_right, 0.0f, *filterlength ); + hrf_left[0] = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; + hrf_right[0] = 1.f - hrf_left[0]; + *intp_count = MAX_INTERPOLATION_STEPS; + Src_p->elev_prev = 0; + Src_p->azim_prev = 360.0f; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ + } -if ( ( *intp_count > 0 ) && subframe_update_flag ) -{ - /* Set deltas for interpolation */ - v_sub( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); - v_multc( hrf_left_delta, 1.0f / *intp_count, hrf_left_delta, *filterlength ); - v_sub( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); - v_multc( hrf_right_delta, 1.0f / *intp_count, hrf_right_delta, *filterlength ); -} -else -{ - /* No interpolation, just set the new filters and reset deltas */ - mvr2r( hrf_left, hrf_left_prev, *filterlength ); - mvr2r( hrf_right, hrf_right_prev, *filterlength ); - set_f( hrf_left_delta, 0.0f, *filterlength ); - set_f( hrf_right_delta, 0.0f, *filterlength ); -} -return; + if ( ( *intp_count > 0 ) && subframe_update_flag ) + { + /* Set deltas for interpolation */ + v_sub( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + v_multc( hrf_left_delta, 1.0f / *intp_count, hrf_left_delta, *filterlength ); + v_sub( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + v_multc( hrf_right_delta, 1.0f / *intp_count, hrf_right_delta, *filterlength ); + } + else + { + /* No interpolation, just set the new filters and reset deltas */ + mvr2r( hrf_left, hrf_left_prev, *filterlength ); + mvr2r( hrf_right, hrf_right_prev, *filterlength ); + set_f( hrf_left_delta, 0.0f, *filterlength ); + set_f( hrf_right_delta, 0.0f, *filterlength ); + } + + return; } @@ -709,11 +675,8 @@ void TDREND_SRC_Init( /* Reset memory buffers */ Src_p->itd = 0; Src_p->previtd = 0; -#ifdef FIX_550_FIRST_FRAME_ACCESS Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ -#else - Src_p->filterlength = -1; -#endif + set_f( Src_p->mem_itd, 0.0f, ITD_MEM_LEN ); set_f( Src_p->mem_hrf_left, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); set_f( Src_p->mem_hrf_right, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); @@ -724,9 +687,7 @@ void TDREND_SRC_Init( Src_p->hrf_right_prev[0] = 1; Src_p->azim_prev = 0.0f; Src_p->elev_prev = 0.0f; -#ifdef FIX_550_FIRST_FRAME_ACCESS Src_p->Gain = 1; -#endif Src_p->prevGain = 1.0f; return; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b6045045a8..f12c4597c8 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -647,9 +647,7 @@ void GetFilterFromAngle( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* i/o: HR filter set structure */ const float Elev, /* i : Elevation, degrees */ float Azim, /* i : Azimuth, degrees */ -#ifdef FIX_569_TD_FILTER_LENGTH const int16_t filterlength, /* i : Filter length */ -#endif float *LeftFilter, /* o : Left HR filter */ float *RightFilter, /* o : Right HR filter */ int16_t *itd /* o : ITD value */ -- GitLab From bc344f842cafcd5a273f40de438fe59c73ccc66c Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 20:32:40 +0200 Subject: [PATCH 148/173] revert unintentional changes in scripts --- .gitlab-ci.yml | 354 +----------------- Makefile | 2 +- tests/codec_be_on_mr_selection/__init__.py | 29 +- .../test_experiments.py | 6 + tests/conftest.py | 12 + tests/testconfig.py | 2 + 6 files changed, 47 insertions(+), 358 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f4ea77138a..881da24acb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -281,11 +281,13 @@ build-codec-instrumented-linux: # make sure that the codec builds with msan, asan and usan build-codec-sanitizers-linux: extends: - - .build-job-linux + - .build-job-with-check-for-warnings - .rules-basis script: - *print-common-info - bash ci/build_codec_sanitizers_linux.sh + # need to use the "|| exit $?" suffix to get the allowed_failure return code, otherwise the job fails with code 1...< + - ci/check_for_warnings.py $BUILD_OUTPUT || exit $? build-codec-windows-cmake: extends: @@ -696,286 +698,6 @@ evs-pytest-on-merge-request: script: - *print-common-info - *merge-request-comparison-setup-codec - - # some helper variables - "|| true" to prevent failures from grep not finding anything - - non_be_flag=$(echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[evs[ -]*non[ -]*be\]") || true - - ref_using_main=$(echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[ref[ -]*using[ -]*main\]") || true - - ### If ref_using_main is not set, checkoug the source branch to use scripts and input from there - - if [ $ref_using_main == 0 ]; then git checkout $source_branch_commit_sha; fi - - ### prepare pytest - # create references - - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR/test_param_file.py -v --update_ref 1 -m create_ref --param_file scripts/config/self_test_evs.prm - - ### Run test using branch scripts and input - - if [ $ref_using_main == 1 ]; then git checkout $source_branch_commit_sha; fi - - ### run pytest for EVS cases - - exit_code=0 - - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR/test_param_file.py -v --param_file scripts/config/self_test_evs.prm --html=report.html --self-contained-html --junit-xml=report-junit-evs.xml || exit_code=$? - - zero_errors=$(cat report-junit-evs.xml | grep -c 'errors="0"') || true - - - *merge-request-comparison-check - - allow_failure: - exit_codes: - - 123 - artifacts: - name: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--stage-$CI_JOB_STAGE--results" - expire_in: 1 week - when: always - paths: - - report-junit-evs.xml - - report.html - expose_as: "pytest evs results" - reports: - junit: - - report-junit-evs.xml - -voip-be-on-merge-request: - extends: - - .test-job-linux-needs-testv-dir - - .rules-merge-request - stage: compare # Or should it be test? Comparison is done within one git revision - needs: ["build-codec-linux-make", codec-smoke-test] - timeout: "10 minutes" - script: - - *print-common-info - - bash ci/ivas_voip_be_test.sh - -clang-format-check: - extends: - - .test-job-linux - - .rules-merge-request - variables: - ARTIFACT_BASE_NAME: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--formatting-fix" - stage: validate - needs: [] - timeout: "5 minutes" - script: - # Set up variables. This can't be done in the "variables" section because variables are not expanded properly there - - PATCH_FILE_NAME="$ARTIFACT_BASE_NAME".patch - - > - INSTRUCTIONS_GITLAB="To fix formatting issues:\n - - download the diff patch available as artifact of this job\n - - unzip the artifact and place the patch file in the root directory of your local IVAS repo\n - - run: git apply $PATCH_FILE_NAME\n - - commit new changes" - - > - INSTRUCTIONS_README="To fix formatting issues:\n - - place the patch file in the root directory of your local IVAS repo\n - - run: git apply $PATCH_FILE_NAME\n - - commit new changes" - - - scripts/check-format.sh -af -p 8 || format_problems=$? - - if [ $format_problems == 0 ] ; then exit 0; fi - - - mkdir tmp-formatting-fix - - git diff > "tmp-formatting-fix/$PATCH_FILE_NAME" - - # Print instructions to job output - - echo -e "$INSTRUCTIONS_GITLAB" - - # Include readme in the artifact, in case someone misses the job printout (e.g. getting the artifact via MR interface) - - echo -e "$INSTRUCTIONS_README" > "tmp-formatting-fix/readme.txt" - - - exit $format_problems - artifacts: - expire_in: 1 day - paths: - - tmp-formatting-fix/ - when: on_failure - name: "$ARTIFACT_BASE_NAME" - expose_as: 'formatting patch' - -# check for crashes if first received frame on decoder side is an SID -check-first-frame-is-sid: - extends: - - .test-job-linux-needs-testv-dir - - .rules-merge-request - tags: - - ivas-linux - stage: test - # needs: ["build-codec-linux-cmake"] - script: - - *print-common-info - - *update-ltv-repo - - *check-for-testvectors - - cmake . - - make -j - - # TODO: for some MASA modes, we currently do not have testvectors that actually trigger DTX - # SBA is run separately to use shorter part of file - - modes=$(scripts/runIvasCodec.py -l | grep dtx | grep -v MASA | grep -v SBA) - - scripts/runIvasCodec.py -p scripts/config/ci_linux_sidstart_test.json -m $modes -s --bs_length 500 -U 0:20 || exit_code_no_sba=$? - - modes=$(scripts/runIvasCodec.py -l | grep dtx | grep SBA) - - scripts/runIvasCodec.py -p scripts/config/ci_linux_sidstart_test.json -m $modes -s --bs_length 500 -U 70:80 || exit_code_sba=$? - - if [ $exit_code_no_sba != 0 || $exit_code_sba != 0]; then exit 1; fi - artifacts: - paths: - - out/logs - when: on_failure - name: "$CI_JOB_NAME--$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--sidstart" - expose_as: "logs-sidstart" - expire_in: "5 days" - -selection-test-processing: - extends: - - .test-job-linux-needs-testv-dir - - .rules-merge-request - tags: - - processing-scripts-linux - stage: test - needs: ["build-codec-linux-make"] - script: - # get processing script code - - git clone https://forge.3gpp.org/rep/ivas-codec-pc/ivas-processing-scripts.git --single-branch -b main - - - mkdir -p ivas-processing-scripts/tests/data/testv - - cp -r scripts/testv/* ivas-processing-scripts/tests/data/testv/ - - # copy binaries into local bin dir, those should take precendence over PATH - - cp $PROCESSING_SCRIPTS_BIN_DIR/* ivas-processing-scripts/ivas_processing_scripts/bin/ - # for testing with native binaries - - rm ivas-processing-scripts/ivas_processing_scripts/bin/IVAS*.exe - - rm ivas-processing-scripts/ivas_processing_scripts/bin/EVS*.exe - - # build codec and put into bin dir - - make -j - - cp ./IVAS_* ivas-processing-scripts/ivas_processing_scripts/bin/ - - # patch the use_windows_codec_binaries key (weird folding is needed so colons are accepted) - - > - sed -i "s/use_windows_codec_binaries: true/use_windows_codec_binaries: false/" ivas-processing-scripts/experiments/selection/*/config/*.yml - - # run experiments test - - cd ivas-processing-scripts - - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto | tee log.txt - artifacts: - paths: - - ivas-processing-scripts/experiments/selection/*/proc_output/*.log - - log.txt - when: on_failure - expire_in: 1 week - -lc3plus-ensure-no-code-changes: - extends: - - .test-job-linux - - .rules-merge-request - stage: validate - needs: [] - timeout: "5 minutes" - script: - # Replace code commited to repo with code downloaded from ETSI - - ./scripts/lc3plus_lib_setup/get_lc3plus.sh - - # Ensure git reports no changes - - modified_files=$(git status -s) - - if [[ $modified_files ]]; then printf 'LC3plus codebase was modified!\n\n'"$modified_files"'\n\n'; exit $EXIT_CODE_FAIL; fi - - -# --------------------------------------------------------------- -# Test jobs for main branch -# --------------------------------------------------------------- - -# check bitexactness to EVS windows binaries -be-2-evs-windows: - extends: - - .rules-main-push - tags: - - ivas-windows - stage: test - needs: ["build-codec-windows-msbuild"] - timeout: "20 minutes" # To be revisited - script: - - *print-common-info-windows - - - $winoutdata = $null - - MSBuild.exe .\Workspace_msvc\Workspace_msvc.sln /property:Configuration=Release | tee -variable winoutdata - - $winoutdata | Out-File $BUILD_OUTPUT -Encoding Utf8 - - # copy over to never change the testvector dir - - cp -r $EVS_BE_WIN_TEST_DIR ./evs_be_win_test - - cp IVAS_cod.exe ./evs_be_win_test/bin/IVAS_cod.exe - - cp IVAS_dec.exe ./evs_be_win_test/bin/IVAS_dec.exe - - - cd evs_be_win_test - - python ../ci/run_evs_be_win_test.py - -# check bitexactness to EVS -be-2-evs-linux: - extends: - - .test-job-linux - - .rules-main-push - tags: - - be-2-evs-temp - stage: test - needs: ["build-codec-linux-cmake"] - timeout: "20 minutes" # To be revisited - script: - - *print-common-info - - - mkdir build - - cd build - - cmake .. - - make -j - - cd .. - - # copy over to never change the testvector dir - - cp -r $EVS_BE_TEST_DIR ./evs_be_test - - cp build/IVAS_cod ./evs_be_test/bin/EVS_cod - - cp build/IVAS_dec ./evs_be_test/bin/EVS_dec - - - cd evs_be_test - - python3 ../ci/run_evs_be_test.py - -codec-comparison-on-main-push: - extends: - - .test-job-linux - - .rules-main-push - stage: compare - needs: ["build-codec-linux-cmake"] - timeout: "30 minutes" # To be revisited - script: - - *print-common-info - - latest_commit=$(git rev-parse HEAD) # Latest commit - - *get-previous-merge-commit-sha # Stored in previous_merge_commit shell variable now - - echo "Comparing changes from $previous_merge_commit to $latest_commit" - - git --no-pager diff --stat $previous_merge_commit..$latest_commit - - # Rest is more or less placeholder adapted from MR self test. This should be replaced with more complex tests. - - ### build test binaries, initial clean for paranoia reasons - - make clean - - mkdir build - - cd build - - cmake .. - - make -j - - mv IVAS_cod ../IVAS_cod_test - - mv IVAS_dec ../IVAS_dec_test - - cd .. - - rm -rf build/* - - ### compare to the previous merge commit in the main branch - - git fetch origin main - - git checkout $previous_merge_commit - - ### build reference binaries - - cd build - - cmake .. - - make -j - - mv IVAS_cod ../IVAS_cod_ref - - mv IVAS_dec ../IVAS_dec_ref - - cd .. - - # helper variable - "|| true" to prevent failures from grep not finding anything - - non_be_flag=$(echo $CI_COMMIT_MESSAGE | grep -c --ignore-case "\[non[ -]*be\]") || true - - ref_using_main=$(echo $CI_COMMIT_MESSAGE | grep -c --ignore-case "\[ref[ -]*using[ -]*main\]") || true - - ### re-checkout the latest commit in the main branch, if ref_using_main is not set - - if [ $ref_using_main == 0 ]; then git checkout $latest_commit;fi - ### prepare pytest # create short test vectors - python3 tests/create_short_testvectors.py @@ -1116,76 +838,6 @@ sanitizer-test-masa: extends: .sanitizer-test-schedule-A rules: - if: $SANITIZER_SCHEDULE_A - when: delayed - start_in: 21 hours - timeout: 3 hours - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py MASA $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL EXT --tests $SANITIZER_TESTS - -### --- sanitizer schedule B --- - -.sanitizer-test-schedule-B: - extends: - - .sanitizer-test-template - timeout: 4 hours - -sanitizer-test-mc-5_1: - extends: .sanitizer-test-schedule-B - rules: - - if: $SANITIZER_SCHEDULE_B - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py 5_1 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS - -sanitizer-test-mc-5_1_2: - extends: .sanitizer-test-schedule-B - rules: - - if: $SANITIZER_SCHEDULE_B - when: delayed - start_in: 4 hours - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py 5_1_2 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS - -sanitizer-test-mc-5_1_4: - extends: .sanitizer-test-schedule-B - rules: - - if: $SANITIZER_SCHEDULE_B - when: delayed - start_in: 8 hours - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py 5_1_4 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS - -sanitizer-test-mc-7_1: - extends: .sanitizer-test-schedule-B - rules: - - if: $SANITIZER_SCHEDULE_B - when: delayed - start_in: 12 hours - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py 7_1 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS - -sanitizer-test-mc-7_1_4: - extends: .sanitizer-test-schedule-B - rules: - - if: $SANITIZER_SCHEDULE_B - when: delayed - start_in: 16 hours - script: - - *update-ltv-repo - - python3 ci/run_scheduled_sanitizer_test.py 7_1_4 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS - -### --- sanitizer schedule C --- - -.sanitizer-test-schedule-C: - extends: - - .sanitizer-test-template - timeout: 6 hours - -sanitizer-test-sba: extends: .sanitizer-test-schedule-C rules: - if: $SANITIZER_SCHEDULE_C diff --git a/Makefile b/Makefile index b63c3a6873..138a4cdaed 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ LDLIBS += -lm CCCLANG = clang ifeq "$(CLANG)" "1" CC = $(CCCLANG) -CFLAGS += -fsanitize=memory -fsanitize-memory-track-origins +CFLAGS += -fsanitize=memory LDFLAGS += -fsanitize=memory endif ifeq "$(CLANG)" "2" diff --git a/tests/codec_be_on_mr_selection/__init__.py b/tests/codec_be_on_mr_selection/__init__.py index acfa6c2336..da1d8c3578 100644 --- a/tests/codec_be_on_mr_selection/__init__.py +++ b/tests/codec_be_on_mr_selection/__init__.py @@ -35,6 +35,7 @@ import filecmp from pathlib import Path import subprocess from .constants import OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT, DTX_ON, FER_5PERC +from ..testconfig import MD5_REF_DICT HERE = Path(__file__).parent # set environment variables in CI job @@ -98,8 +99,20 @@ def apply_error_pattern_on_bitstream( subprocess.run(cmd) -def files_equal(dut_file, ref_file): - return filecmp.cmp(dut_file, ref_file) +def is_be_to_ref(dut_file): + """ + Check bitexactness either by comparing files directly or by comparing MD5 sums + """ + if MD5_REF_DICT == dict(): + ref_file = REF_PATH.joinpath(dut_file.name) + is_be = filecmp.cmp(dut_file, ref_file) + else: + md5_ref = MD5_REF_DICT[dut_file.name] + cmd = f"powershell.exe (Get-FileHash {str(dut_file)} -Algorithm MD5).Hash" + md5_dut = subprocess.check_output(cmd, shell=True).decode().splitlines()[-1] + is_be = md5_ref == md5_dut + + return is_be def run_check( @@ -113,6 +126,7 @@ def run_check( decoder_frontend, is_ref_creation, input_file_num=None, + keep_files=True, ): sampling_rate = 48 output_mode, options = OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT[experiment] @@ -168,12 +182,15 @@ def run_check( # this should not be a problem as both the reference and the tdut output was generated by the codec, so # diverging headers should also indicate a problem - still, keep in mind if something bogus happens if not is_ref_creation: - ref_output = REF_PATH.joinpath(dut_output.name) - if not files_equal(dut_output, ref_output): + if not is_be_to_ref(dut_output): pytest.fail("Decoder output differs from reference") + elif not keep_files: + os.remove(dut_output) + os.remove(dut_bitstream) for md in metadata: md_suffix = "".join(md.suffixes) dut_md = DUT_PATH.joinpath(dut_output.with_suffix(md_suffix).name) - ref_md = REF_PATH.joinpath(dut_output.with_suffix(md_suffix).name) - if not files_equal(dut_md, ref_md): + if not is_be_to_ref(dut_md): pytest.fail("Metadata file {md.name} differs from reference") + elif not keep_files: + os.remove(dut_md) diff --git a/tests/codec_be_on_mr_selection/test_experiments.py b/tests/codec_be_on_mr_selection/test_experiments.py index a0a4aa780a..5b2f516893 100644 --- a/tests/codec_be_on_mr_selection/test_experiments.py +++ b/tests/codec_be_on_mr_selection/test_experiments.py @@ -52,6 +52,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): run_check( experiment, @@ -63,6 +64,7 @@ def test_p800( dut_encoder_frontend, dut_decoder_frontend, update_ref == 1, + keep_files=keep_files, ) @@ -79,6 +81,7 @@ def test_bs1534_no_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): category = "" run_check( @@ -92,6 +95,7 @@ def test_bs1534_no_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, + keep_files=keep_files, ) @@ -111,6 +115,7 @@ def test_bs1534_masa( dut_encoder_frontend, dut_decoder_frontend, update_ref, + keep_files, ): run_check( experiment, @@ -123,4 +128,5 @@ def test_bs1534_masa( dut_decoder_frontend, update_ref == 1, input_file_num=input_file_num, + keep_files=keep_files, ) diff --git a/tests/conftest.py b/tests/conftest.py index 12b62caccd..e4de453b0e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -133,6 +133,12 @@ def pytest_addoption(parser): " Use --keep_files to prevent these deletions.", ) + parser.addoption( + "--selection_be_md5_file", + type=Path, + help="Path to file with md5 sums for the reference signals of the selection-BE test" + ) + @pytest.fixture(scope="session", autouse=True) def update_ref(request): @@ -513,3 +519,9 @@ def pytest_configure(config): ) if config.option.param_file: testconfig.PARAM_FILE = config.option.param_file + if config.option.selection_be_md5_file: + md5_file_path = config.option.selection_be_md5_file + if not platform.system() == "Windows": + raise NotImplementedError("MD5 comparison is currently hardcoded for windows") + with open(md5_file_path) as f: + testconfig.MD5_REF_DICT = {line.split()[0]: line.split()[1] for line in f.readlines()} diff --git a/tests/testconfig.py b/tests/testconfig.py index 12d170ba8d..404073b08e 100644 --- a/tests/testconfig.py +++ b/tests/testconfig.py @@ -35,3 +35,5 @@ To configure test modules. """ PARAM_FILE = "scripts/config/self_test.prm" + +MD5_REF_DICT = dict() -- GitLab From cfc64ddf603cb3329707309279c90d687caaac5a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 20:42:43 +0200 Subject: [PATCH 149/173] revert unintentional changes in scripts --- .gitlab-ci.yml | 350 ++++++++++++++++++++++++++++++ scripts/config/self_test.prm | 409 ++--------------------------------- tests/testconfig.py | 2 +- 3 files changed, 372 insertions(+), 389 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 881da24acb..cc24ab729e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -698,6 +698,286 @@ evs-pytest-on-merge-request: script: - *print-common-info - *merge-request-comparison-setup-codec + + # some helper variables - "|| true" to prevent failures from grep not finding anything + - non_be_flag=$(echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[evs[ -]*non[ -]*be\]") || true + - ref_using_main=$(echo $CI_MERGE_REQUEST_TITLE | grep -c --ignore-case "\[ref[ -]*using[ -]*main\]") || true + + ### If ref_using_main is not set, checkoug the source branch to use scripts and input from there + - if [ $ref_using_main == 0 ]; then git checkout $source_branch_commit_sha; fi + + ### prepare pytest + # create references + - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR/test_param_file.py -v --update_ref 1 -m create_ref --param_file scripts/config/self_test_evs.prm + + ### Run test using branch scripts and input + - if [ $ref_using_main == 1 ]; then git checkout $source_branch_commit_sha; fi + + ### run pytest for EVS cases + - exit_code=0 + - python3 -m pytest $TESTS_DIR_CODEC_BE_ON_MR/test_param_file.py -v --param_file scripts/config/self_test_evs.prm --html=report.html --self-contained-html --junit-xml=report-junit-evs.xml || exit_code=$? + - zero_errors=$(cat report-junit-evs.xml | grep -c 'errors="0"') || true + + - *merge-request-comparison-check + + allow_failure: + exit_codes: + - 123 + artifacts: + name: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--stage-$CI_JOB_STAGE--results" + expire_in: 1 week + when: always + paths: + - report-junit-evs.xml + - report.html + expose_as: "pytest evs results" + reports: + junit: + - report-junit-evs.xml + +voip-be-on-merge-request: + extends: + - .test-job-linux-needs-testv-dir + - .rules-merge-request + stage: compare # Or should it be test? Comparison is done within one git revision + needs: ["build-codec-linux-make", codec-smoke-test] + timeout: "10 minutes" + script: + - *print-common-info + - bash ci/ivas_voip_be_test.sh + +clang-format-check: + extends: + - .test-job-linux + - .rules-merge-request + variables: + ARTIFACT_BASE_NAME: "mr-$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--formatting-fix" + stage: validate + needs: [] + timeout: "5 minutes" + script: + # Set up variables. This can't be done in the "variables" section because variables are not expanded properly there + - PATCH_FILE_NAME="$ARTIFACT_BASE_NAME".patch + - > + INSTRUCTIONS_GITLAB="To fix formatting issues:\n + - download the diff patch available as artifact of this job\n + - unzip the artifact and place the patch file in the root directory of your local IVAS repo\n + - run: git apply $PATCH_FILE_NAME\n + - commit new changes" + - > + INSTRUCTIONS_README="To fix formatting issues:\n + - place the patch file in the root directory of your local IVAS repo\n + - run: git apply $PATCH_FILE_NAME\n + - commit new changes" + + - scripts/check-format.sh -af -p 8 || format_problems=$? + - if [ $format_problems == 0 ] ; then exit 0; fi + + - mkdir tmp-formatting-fix + - git diff > "tmp-formatting-fix/$PATCH_FILE_NAME" + + # Print instructions to job output + - echo -e "$INSTRUCTIONS_GITLAB" + + # Include readme in the artifact, in case someone misses the job printout (e.g. getting the artifact via MR interface) + - echo -e "$INSTRUCTIONS_README" > "tmp-formatting-fix/readme.txt" + + - exit $format_problems + artifacts: + expire_in: 1 day + paths: + - tmp-formatting-fix/ + when: on_failure + name: "$ARTIFACT_BASE_NAME" + expose_as: 'formatting patch' + +# check for crashes if first received frame on decoder side is an SID +check-first-frame-is-sid: + extends: + - .test-job-linux-needs-testv-dir + - .rules-merge-request + tags: + - ivas-linux + stage: test + # needs: ["build-codec-linux-cmake"] + script: + - *print-common-info + - *update-ltv-repo + - *check-for-testvectors + - cmake . + - make -j + + # TODO: for some MASA modes, we currently do not have testvectors that actually trigger DTX + # SBA is run separately to use shorter part of file + - modes=$(scripts/runIvasCodec.py -l | grep dtx | grep -v MASA | grep -v SBA) + - scripts/runIvasCodec.py -p scripts/config/ci_linux_sidstart_test.json -m $modes -s --bs_length 500 -U 0:20 || exit_code_no_sba=$? + - modes=$(scripts/runIvasCodec.py -l | grep dtx | grep SBA) + - scripts/runIvasCodec.py -p scripts/config/ci_linux_sidstart_test.json -m $modes -s --bs_length 500 -U 70:80 || exit_code_sba=$? + - if [ $exit_code_no_sba != 0 || $exit_code_sba != 0]; then exit 1; fi + artifacts: + paths: + - out/logs + when: on_failure + name: "$CI_JOB_NAME--$CI_MERGE_REQUEST_IID--sha-$CI_COMMIT_SHORT_SHA--sidstart" + expose_as: "logs-sidstart" + expire_in: "5 days" + +selection-test-processing: + extends: + - .test-job-linux-needs-testv-dir + - .rules-merge-request + tags: + - processing-scripts-linux + stage: test + needs: ["build-codec-linux-make"] + script: + # get processing script code + - git clone https://forge.3gpp.org/rep/ivas-codec-pc/ivas-processing-scripts.git --single-branch -b main + + - mkdir -p ivas-processing-scripts/tests/data/testv + - cp -r scripts/testv/* ivas-processing-scripts/tests/data/testv/ + + # copy binaries into local bin dir, those should take precendence over PATH + - cp $PROCESSING_SCRIPTS_BIN_DIR/* ivas-processing-scripts/ivas_processing_scripts/bin/ + # for testing with native binaries + - rm ivas-processing-scripts/ivas_processing_scripts/bin/IVAS*.exe + - rm ivas-processing-scripts/ivas_processing_scripts/bin/EVS*.exe + + # build codec and put into bin dir + - make -j + - cp ./IVAS_* ivas-processing-scripts/ivas_processing_scripts/bin/ + + # patch the use_windows_codec_binaries key (weird folding is needed so colons are accepted) + - > + sed -i "s/use_windows_codec_binaries: true/use_windows_codec_binaries: false/" ivas-processing-scripts/experiments/selection/*/config/*.yml + + # run experiments test + - cd ivas-processing-scripts + - python3 -m pytest tests/test_experiments.py::test_generate_test_items -n auto | tee log.txt + artifacts: + paths: + - ivas-processing-scripts/experiments/selection/*/proc_output/*.log + - log.txt + when: on_failure + expire_in: 1 week + +lc3plus-ensure-no-code-changes: + extends: + - .test-job-linux + - .rules-merge-request + stage: validate + needs: [] + timeout: "5 minutes" + script: + # Replace code commited to repo with code downloaded from ETSI + - ./scripts/lc3plus_lib_setup/get_lc3plus.sh + + # Ensure git reports no changes + - modified_files=$(git status -s) + - if [[ $modified_files ]]; then printf 'LC3plus codebase was modified!\n\n'"$modified_files"'\n\n'; exit $EXIT_CODE_FAIL; fi + + +# --------------------------------------------------------------- +# Test jobs for main branch +# --------------------------------------------------------------- + +# check bitexactness to EVS windows binaries +be-2-evs-windows: + extends: + - .rules-main-push + tags: + - ivas-windows + stage: test + needs: ["build-codec-windows-msbuild"] + timeout: "20 minutes" # To be revisited + script: + - *print-common-info-windows + + - $winoutdata = $null + - MSBuild.exe .\Workspace_msvc\Workspace_msvc.sln /property:Configuration=Release | tee -variable winoutdata + - $winoutdata | Out-File $BUILD_OUTPUT -Encoding Utf8 + + # copy over to never change the testvector dir + - cp -r $EVS_BE_WIN_TEST_DIR ./evs_be_win_test + - cp IVAS_cod.exe ./evs_be_win_test/bin/IVAS_cod.exe + - cp IVAS_dec.exe ./evs_be_win_test/bin/IVAS_dec.exe + + - cd evs_be_win_test + - python ../ci/run_evs_be_win_test.py + +# check bitexactness to EVS +be-2-evs-linux: + extends: + - .test-job-linux + - .rules-main-push + tags: + - be-2-evs-temp + stage: test + needs: ["build-codec-linux-cmake"] + timeout: "20 minutes" # To be revisited + script: + - *print-common-info + + - mkdir build + - cd build + - cmake .. + - make -j + - cd .. + + # copy over to never change the testvector dir + - cp -r $EVS_BE_TEST_DIR ./evs_be_test + - cp build/IVAS_cod ./evs_be_test/bin/EVS_cod + - cp build/IVAS_dec ./evs_be_test/bin/EVS_dec + + - cd evs_be_test + - python3 ../ci/run_evs_be_test.py + +codec-comparison-on-main-push: + extends: + - .test-job-linux + - .rules-main-push + stage: compare + needs: ["build-codec-linux-cmake"] + timeout: "30 minutes" # To be revisited + script: + - *print-common-info + - latest_commit=$(git rev-parse HEAD) # Latest commit + - *get-previous-merge-commit-sha # Stored in previous_merge_commit shell variable now + - echo "Comparing changes from $previous_merge_commit to $latest_commit" + - git --no-pager diff --stat $previous_merge_commit..$latest_commit + + # Rest is more or less placeholder adapted from MR self test. This should be replaced with more complex tests. + + ### build test binaries, initial clean for paranoia reasons + - make clean + - mkdir build + - cd build + - cmake .. + - make -j + - mv IVAS_cod ../IVAS_cod_test + - mv IVAS_dec ../IVAS_dec_test + - cd .. + - rm -rf build/* + + ### compare to the previous merge commit in the main branch + - git fetch origin main + - git checkout $previous_merge_commit + + ### build reference binaries + - cd build + - cmake .. + - make -j + - mv IVAS_cod ../IVAS_cod_ref + - mv IVAS_dec ../IVAS_dec_ref + - cd .. + + # helper variable - "|| true" to prevent failures from grep not finding anything + - non_be_flag=$(echo $CI_COMMIT_MESSAGE | grep -c --ignore-case "\[non[ -]*be\]") || true + - ref_using_main=$(echo $CI_COMMIT_MESSAGE | grep -c --ignore-case "\[ref[ -]*using[ -]*main\]") || true + + ### re-checkout the latest commit in the main branch, if ref_using_main is not set + - if [ $ref_using_main == 0 ]; then git checkout $latest_commit;fi + ### prepare pytest # create short test vectors - python3 tests/create_short_testvectors.py @@ -838,6 +1118,76 @@ sanitizer-test-masa: extends: .sanitizer-test-schedule-A rules: - if: $SANITIZER_SCHEDULE_A + when: delayed + start_in: 21 hours + timeout: 3 hours + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py MASA $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL EXT --tests $SANITIZER_TESTS + +### --- sanitizer schedule B --- + +.sanitizer-test-schedule-B: + extends: + - .sanitizer-test-template + timeout: 4 hours + +sanitizer-test-mc-5_1: + extends: .sanitizer-test-schedule-B + rules: + - if: $SANITIZER_SCHEDULE_B + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py 5_1 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS + +sanitizer-test-mc-5_1_2: + extends: .sanitizer-test-schedule-B + rules: + - if: $SANITIZER_SCHEDULE_B + when: delayed + start_in: 4 hours + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py 5_1_2 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS + +sanitizer-test-mc-5_1_4: + extends: .sanitizer-test-schedule-B + rules: + - if: $SANITIZER_SCHEDULE_B + when: delayed + start_in: 8 hours + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py 5_1_4 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS + +sanitizer-test-mc-7_1: + extends: .sanitizer-test-schedule-B + rules: + - if: $SANITIZER_SCHEDULE_B + when: delayed + start_in: 12 hours + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py 7_1 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS + +sanitizer-test-mc-7_1_4: + extends: .sanitizer-test-schedule-B + rules: + - if: $SANITIZER_SCHEDULE_B + when: delayed + start_in: 16 hours + script: + - *update-ltv-repo + - python3 ci/run_scheduled_sanitizer_test.py 7_1_4 $OUT_FORMATS_CHANNEL_BASED $OUT_FORMATS_SCENE_BASED $OUT_FORMATS_BINAURAL --tests $SANITIZER_TESTS + +### --- sanitizer schedule C --- + +.sanitizer-test-schedule-C: + extends: + - .sanitizer-test-template + timeout: 6 hours + +sanitizer-test-sba: extends: .sanitizer-test-schedule-C rules: - if: $SANITIZER_SCHEDULE_C diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index a4e3fd041f..aff7ebcc99 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -418,286 +418,6 @@ ../IVAS_dec -fec 5 BINAURAL_ROOM_IR 48 bit testv/stv4ISM48n.wav_48000_48-48_DTX_TD_binaural_room_FEC5.tst // 4 ISM with metadata at 64 kbps, 48 kHz in, 48 kHz out, BINAURAL ROOM out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 64000 48 testv/stv4ISM48s.wav bit -../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv4ISM48s.wav_64000_48-48_binaural_room.tst - -// 4 ISM with metadata at 80 kbps, 48 kHz in, 48 kHz out, HOA2 out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 80000 48 testv/stv4ISM48s.wav bit -../IVAS_dec HOA2 48 bit testv/stv4ISM48s.wav_80000_48-48_HOA2.tst - -// 4 ISM with metadata at 96 kbps, 48 kHz in, 48 kHz out, Custom LS setup out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 96000 48 testv/stv4ISM48s.wav bit -../IVAS_dec testv/ls_setup_16ch_8+4+4.txt 48 bit testv/stv4ISM48s.wav_96000_48-48_MC_custom_setup.tst - -// 4 ISM with metadata at 96 kbps, 48 kHz in, 48 kHz out, EXT out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 96000 48 testv/stv4ISM48s.wav bit -../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_96000_48-48_EXT.tst - -// 4 ISM with metadata at 128 kbps, 48 kHz in, 48 kHz out, EXT out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 128000 48 testv/stv4ISM48s.wav bit -../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_128000_48-48_EXT.tst - -// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, EXT out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_256000_48-48_EXT.tst - -// 4 ISM with metadata at 160 kbps, 48 kHz in, 48 kHz out, STEREO out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 160000 48 testv/stv4ISM48s.wav bit -../IVAS_dec STEREO 48 bit testv/stv4ISM48s.wav_160000_48-48_STEREO.tst - -// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural.tst - -// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -t testv/headrot_case03_3000_q.csv BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural_file_TDHR.tst - -// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, external orientation -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -t testv/headrot_case03_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural_file_TDHR_EXOF.tst - -// 4 ISM with metadata at 512 kbps, 48 kHz in, 48 kHz out, 5_1 -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 512000 48 testv/stv4ISM48s.wav bit -../IVAS_dec 5_1 48 bit testv/stv4ISM48s.wav_512000_48-48_5_1.tst - -// 4 ISm with metadata at 256 kbps, 48 kHz in, 48 kHz out, TD BINAURAL out, head rotation, Orientation tracking -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL 48 bit testv/stv4ISM48s.pcm_256000_48-48_TDHR_OtrAvg.tst - -// 4 ISm with metadata at 256 kbps, 48 kHz in, 48 kHz out, TD BINAURAL out, head rotation, external orientation, Orientation tracking -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL 48 bit testv/stv4ISM48s.pcm_256000_48-48_TDHR_EXOF_OtrAvg.tst - -// 4 ISM with metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, EXT out -../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit -../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_brate_sw_48-48_EXT.tst - -// 4 ISm with and without metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, DTX on, HOA3 out -../IVAS_cod -dtx -ism 4 testv/stvISM1.csv NULL NULL testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit -../IVAS_dec HOA3 48 bit testv/stv4ISM48s.wav_brate_sw_48-48_DTX_hoa3.tst - -// 4 ISM with extended metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, directivity configuration, random FEC at 5% -../IVAS_cod -ism +4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -fec 5 -render_config testv/config_directivity.cfg -t testv/headrot_case04_3000_q.csv BINAURAL 48 bit testv/stv+4ISM48s.wav_256000_48-48_binaural_file_TDHR_DirConfig_FEC5.tst - -// 4 ISM with extended metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, external orientation, directivity configuration, random FEC at 5% -../IVAS_cod -ism +4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec -fec 5 -render_config testv/config_directivity.cfg -t testv/headrot_case04_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv+4ISM48s.wav_256000_48-48_binaural_file_TDHR_EXOF_DirConfig_FEC5.tst - -// 4 ISM with and without extended metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, DTX on, EXT out -../IVAS_cod -dtx -ism +4 testv/stvISM1.csv NULL testv/stvISM3.csv testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit -../IVAS_dec EXT 48 bit testv/stv+4ISM48s.wav_brate_sw_48-48_DTX_EXT.tst - -// 4 ISM with extended metadata and non diegetic pan object switching bitrate 256 kbps, 48 kHz in, 48 kHz out, DTX on, BINAURAL out -../IVAS_cod -dtx -ism +4 testv/stvISM1.csv NULL testv/stvISM_with_no_diegetic_switch.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit -../IVAS_dec BINAURAL 48 bit testv/stv+4ISM48s+non_diegetic_pan.wav_brate_256000-48_DTX_binaural.tst - - -// SBA at 13.2 kbps, 32kHz in, 32kHz out, HOA3 out -../IVAS_cod -sba 3 13200 32 testv/stv3OA32c.wav bit -../IVAS_dec HOA3 32 bit testv/stv3OA32c.wav_SBA_13200_32-32_HOA3.tst - -// SBA at 13.2 kbps, 32kHz in, 32kHz out, STEREO out -../IVAS_cod -sba 3 13200 32 testv/stv3OA32c.wav bit -../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_13200_32-32_stereo.tst - -// SBA at 16.4 kbps, 32kHz in, 32kHz out, 7_1_4 out -../IVAS_cod -sba 3 16400 32 testv/stv3OA32c.wav bit -../IVAS_dec 7_1_4 32 bit testv/stv3OA32c.wav_SBA_16400_32-32_7_1_4.tst - -// SBA at 16.4 kbps, 32kHz in, 32kHz out, BINAURAL out -../IVAS_cod -sba 3 16400 32 testv/stv3OA32c.wav bit -../IVAS_dec BINAURAL 32 bit testv/stv3OA32c.wav_SBA_16400_32-32_Binaural.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, STEREO out -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_stereo.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, random FEC at 5% -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Subframe_FEC5.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Headrot.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Headrot_EXOF.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, Orientation tracking -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL 32 bit testv/stv3OA32c.pcm_SBA_24400_32-32_Binaural_Headrot_OtrAvg.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation, Orientation tracking -../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL 32 bit testv/stv3OA32c.pcm_SBA_24400_32-32_Binaural_Headrot_EXOF_OtrAvg.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, random FEC at 5% -../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_FEC5.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation -../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_Headrot.tst - -// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation, external orientation -../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_Headrot_EXOF.tst - -// SBA at 32 kbps, 32kHz in, 32kHz out, FOA out -../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit -../IVAS_dec FOA 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_FOA.tst - -// SBA at 32 kbps, 32kHz in, 32kHz out, BINAURAL out, 6% FEC pattern -../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit -../IVAS_dec -fec testv/FEC_6pct.bin BINAURAL 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_BINAURAL_FEC6.tst - -// SBA at 32 kbps, 32kHz in, 32kHz out, BINAURAL_ROOM out -../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_BINAURAL_ROOM.tst - -// SBA at 32 kbps, 48kHz in, 48kHz out, MONO out, DTX -../IVAS_cod -dtx -sba 1 32000 48 testv/stvFOA48c.wav bit -../IVAS_dec MONO 48 bit testv/stvFOA48c.wav_SBA_32000_48-48_DTX_MONO.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, MONO out, random FEC at 5% -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -fec 5 MONO 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_MONO_FEC5.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, STEREO out -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_stereo.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Subframe.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Headrot.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, external orientation -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Headrot_EXOF.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrAvg.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrAvg.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t ../scripts/trajectories/full-circle-4s.csv -rvf ../scripts/trajectories/full-circle-4s-Vector3.csv -otr ref_vec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrRefPos.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking, external orientation -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t ../scripts/trajectories/full-circle-4s.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -rvf ../scripts/trajectories/full-circle-4s-Vector3.csv -otr ref_vec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrRefPos.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking in level mode -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t ../scripts/trajectories/full-circle-with-up-and-down-4s.csv -rvf ../scripts/trajectories/full-circle-with-up-and-down-4s-Vector3.csv -otr ref_vec_lev BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrRefPosLev.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking in level mode, external orientation -../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t ../scripts/trajectories/full-circle-with-up-and-down-4s.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -rvf ../scripts/trajectories/full-circle-with-up-and-down-4s-Vector3.csv -otr ref_vec_lev BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrRefPosLev.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, random FEC at 5% -../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_FEC5.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation -../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_Headrot.tst - -// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation, external orientation -../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_Headrot_EXOF.tst - -// SBA at 48 kbps, 48kHz in, 48kHz out, 5_1_2 out -../IVAS_cod -sba 3 48000 48 testv/stv3OA48c.wav bit -../IVAS_dec 5_1_2 48 bit testv/stv3OA48c.wav_SBA_48000_48-48_5_1_2.tst - -// SBA at 64 kbps, 32kHz in, 32kHz out, FOA out, DTX, random FEC at 5% -../IVAS_cod -dtx -sba 1 64000 32 testv/stvFOA32c.wav bit -../IVAS_dec -fec 5 FOA 32 bit testv/stvFOA32c.wav_SBA_64000_32-32_DTX_FOA.tst - -// SBA at 64 kbps, 48kHz in, 48kHz out, 5_1_4 out -../IVAS_cod -sba 1 64000 48 testv/stvFOA48c.wav bit -../IVAS_dec 5_1_4 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_5_1_4.tst - -// SBA at 64 kbps, 48kHz in, 48kHz out, 7_1_4 out -../IVAS_cod -sba 1 64000 48 testv/stvFOA48c.wav bit -../IVAS_dec 7_1_4 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_7_1_4.tst - -// SBA at 64 kpbs, 48kHz in, 48kHz out, BINAURAL out, DTX -../IVAS_cod -dtx -sba 1 64000 48 testv/stvFOA48c.wav bit -../IVAS_dec BINAURAL 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_DTX_BINAURAL.tst - -// SBA at 64 kpbs, 48kHz in, 48kHz out, BINAURAL_ROOM out, DTX -../IVAS_cod -dtx -sba 1 64000 48 testv/stvFOA48c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_DTX_BINAURAL_ROOM.tst - -// SBA at 80 kbps, 32kHz in, 32kHz out, HOA3 out -../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit -../IVAS_dec HOA3 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_HOA3.tst - -// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, random FEC at 5% -../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit -../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_FEC5.tst - -// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation -../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_Headrot.tst - -// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation -../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_Headrot_EXOF.tst - -// SBA at 96 kbps, 32kHz in, 32kHz out, STEREO out -../IVAS_cod -sba 1 96000 32 testv/stvFOA32c.wav bit -../IVAS_dec STEREO 32 bit testv/stvFOA32c.wav_SBA_96000_32-32_STEREO.tst - -// SBA at 96 kbps, 48kHz in, 48kHz out, FOA out -../IVAS_cod -sba 1 96000 48 testv/stvFOA48c.wav bit -../IVAS_dec FOA 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_FOA.tst - -// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation -../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot_case00_3000_q.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot.tst - -// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, external orientation -../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot_case00_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot_EXOF.tst - -// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking -../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_128000_32-32_Binaural_room_Headrot_OtrAvg.tst - -// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation -../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_128000_32-32_Binaural_room_Headrot_EXOF_OtrAvg.tst - -// SBA at 192 kbps, 48kHz in, 48kHz out, HOA2 out, random FEC at 5% -../IVAS_cod -sba 3 192000 48 testv/stv3OA48c.wav bit -../IVAS_dec -fec 5 HOA2 48 bit testv/stv3OA48c.wav_SBA_192000_48-48_HOA2_FEC5.tst - -// SBA at 48 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out -../IVAS_cod -sba 3 -dtx 48000 48 testv/stv3OA48c.wav bit -../IVAS_dec 5_1 48 bit testv/stv3OA48c.wav_SBA_48000_48-48_DTX_5_1.tst - // SBA at 160 kbps, 32kHz in, 32kHz out, FOA out ../IVAS_cod -sba 1 160000 32 testv/stvFOA32c.wav bit ../IVAS_dec FOA 32 bit testv/stvFOA32c.wav_SBA_160000_32-32_FOA.tst @@ -754,6 +474,22 @@ ../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit ../IVAS_dec HOA3 48 bit testv/stv3OA48c.wav_sw_48-48_HOA3.tst +// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out +../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit +../IVAS_dec MONO 48 bit testv/stv3OA48c.wav_sw_48-48_MONO.tst + +// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, STEREO out +../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit +../IVAS_dec STEREO 48 bit testv/stv3OA48c.wav_sw_48-48_STEREO.tst + +// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out +../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv3OA48c.wav_sw_48-48_BINAURAL.tst + +// SBA 3OA bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, FOA out +../IVAS_cod -sba 3 ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv3OA48c.wav bit +../IVAS_dec FOA 48 bit testv/stv3OA48c.wav_sw_48-48_FOA.tst + // SBA planar 3OA bitrate switching from 24.4 kbps to 256 kbps, 48kHz in, 48kHz out, 7_1_4 out ../IVAS_cod -sba -3 ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv3OA48c.wav bit ../IVAS_dec 7_1_4 48 bit testv/stv3OA48c.wav_sw_48-48_7_1_4.tst @@ -822,115 +558,8 @@ // MASA 1dir 2TC at 13.2 kbps, 48kHz in, 48kHz out, 5_1 out, random FEC at 5% ../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 13200 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -fec 5 5_1 48 bit testv/stv1MASA2TC48c.wav_13200_48-48_5_1_FEC5.tst - -// MASA 1dir 2TC at 16.4 kbps, 48kHz in, 48kHz out, 5_1 out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 16400 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48c.wav_16400_48-48_5_1.tst +../IVAS_dec BINAURAL 48 bit testv/stv2MASA2TC48c.wav_sw_48-48_BINAURAL.tst -// MASA 1dir 2TC at 24.4 kbps, 48kHz in, 48kHz out, STEREO out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 24400 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec STEREO 48 bit testv/stv1MASA2TC48c.wav_24400_48-48_STEREO.tst - -// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom.tst - -// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom_Headrot.tst - -// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, external orientation -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom_Headrot_EXOF.tst - -// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 48 bit testv/stv_IVASMASA_1dir2TC.pcm_32000_48-48_BinauralRoom_Headrot_OtrAvg.tst - -// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 48 bit testv/stv_IVASMASA_1dir2TC.pcm_32000_48-48_BinauralRoom_Headrot_EXOF_OtrAvg.tst - -// MASA 1dir 2TC at 48 kbps, 48kHz in, 48kHz out, 7_1_4 out, random FEC at 5% -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 48000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -fec 5 7_1_4 48 bit testv/stv1MASA2TC48c.wav_48000_48-48_7_1_4_FEC5.tst - -// MASA 1dir 2TC at 80 kbps, 48kHz in, 48kHz out, STEREO out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 80000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec STEREO 48 bit testv/stv1MASA2TC48c.wav_80000_48-48_STEREO.tst - -// MASA 1dir 2TC at 96 kbps, 48kHz in, 48kHz out, MONO out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 96000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec MONO 48 bit testv/stv1MASA2TC48c.wav_96000_48-48_MONO.tst - -// MASA 1dir 2TC at 160 kbps, 48kHz in, 48kHz out, HOA3 out, random FEC at 5% -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 160000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec -fec 5 HOA3 48 bit testv/stv1MASA2TC48c.wav_160000_48-48_HOA3_FEC5.tst - -// MASA 1dir 2TC at 256 kbps, 48kHz in, 48kHz out, 5_1 out -../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 256000 48 testv/stv1MASA2TC48c.wav bit -../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48c.wav_256000_48-48_5_1.tst - -// MASA 2dir 2TC at 48 kbps, 48kHz in, 48kHz out, 5_1 out -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 48000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec 5_1 48 bit testv/stv2MASA2TC48c.wav_48000_48-48_5_1.tst - -// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, EXTERNAL out, random FEC at 5% -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec -fec 5 EXT 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_external_FEC5.tst - -// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, BINAURAL out, Headrotation -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv BINAURAL 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_BINAURAL_Headrot.tst - -// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, BINAURAL out, Headrotation, external orientation -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_BINAURAL_Headrot_EXOF.tst - -// MASA 2dir 2TC at 128 kbps, 48kHz in, 48kHz out, FOA out -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 128000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec FOA 48 bit testv/stv2MASA2TC48c.wav_128000_48-48_FOA.tst - -// MASA 2dir 2TC at 192 kbps, 48kHz in, 48kHz out, 5_1_4 out, random FEC at 5% -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 192000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec -fec 5 5_1_4 48 bit testv/stv2MASA2TC48c.wav_192000_48-48_5_1_4_FEC5.tst - -// MASA 2dir 2TC at 384 kbps, 48kHz in, 48kHz out, BINAURAL_ROOM out -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 384000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv2MASA2TC48c.wav_384000_48-48_BinauralRoom.tst - -// MASA 2dir 2TC at 384 kbps, 48kHz in, 48kHz out, BINAURAL_ROOM out -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 384000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv2MASA2TC48c.wav_384000_48-48_BinauralRoom_Subframe.tst - -// MASA 2dir 2TC at 512 kbps, 48kHz in, 48kHz out, 5_1 out -../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 512000 48 testv/stv2MASA2TC48c.wav bit -../IVAS_dec 5_1 48 bit testv/stv2MASA2TC48c.wav_512000_48-48_5_1.tst - -// MASA 1dir 1TC at 13.2 kbps, 48kHz in, 48kHz out, DTX on, 7_1_4 out -../IVAS_cod -dtx -masa 1 testv/stv1MASA1TC48n.met 13200 48 testv/stv1MASA1TC48n.wav bit -../IVAS_dec 7_1_4 48 bit testv/stv1MASA1TC48n.wav_13200_48-48_DTX_7_1_4.tst - -// MASA 1dir 1TC at 24.4 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out -../IVAS_cod -dtx -masa 1 testv/stv1MASA1TC48n.met 24400 48 testv/stv1MASA1TC48n.wav bit -../IVAS_dec 5_1 48 bit testv/stv1MASA1TC48n.wav_24400_48-48_DTX_5_1.tst - -// MASA 1dir 2TC at 16.4 kbps, 48kHz in, 48kHz out, DTX on, 7_1_4 out -../IVAS_cod -dtx -masa 2 testv/stv1MASA2TC48n.met 16400 48 testv/stv1MASA2TC48n.wav bit -../IVAS_dec 7_1_4 48 bit testv/stv1MASA2TC48n.wav_16400_48-48_DTX_7_1_4.tst - -// MASA 1dir 2TC at 32.0 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out -../IVAS_cod -dtx -masa 2 testv/stv1MASA2TC48n.met 32000 48 testv/stv1MASA2TC48n.wav bit -../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48n.wav_32000_48-48_DTX_5_1.tst - -// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, 5_1 out -../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit -../IVAS_dec 5_1 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_5_1.tst - -// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out -../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit -../IVAS_dec BINAURAL 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_BINAURAL.tst @@ -1138,6 +767,10 @@ ../IVAS_cod -mc 7_1_4 ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv714MC48c.wav bit ../IVAS_dec -FEC 5 STEREO 32 bit testv/stv714MC48c.wav_sw_48-32_stereo.tst +// Multi-channel 7_1_4 bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out +../IVAS_cod -mc 7_1_4 ../scripts/switchPaths/sw_mctech_5fr.bin 48 testv/stv714MC48c.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv51MC48c.wav_sw_48-48_BINAURAL.tst + // Multi-channel 5_1_4 at 512 kbps, 48kHz in, 16kHz out, BINAURAL_ROOM out (Model from file) ../IVAS_cod -mc 5_1_4 512000 48 testv/stv514MC48c.wav bit diff --git a/tests/testconfig.py b/tests/testconfig.py index 404073b08e..1dbfbb8403 100644 --- a/tests/testconfig.py +++ b/tests/testconfig.py @@ -36,4 +36,4 @@ To configure test modules. PARAM_FILE = "scripts/config/self_test.prm" -MD5_REF_DICT = dict() +MD5_REF_DICT = dict() \ No newline at end of file -- GitLab From 15689a0c5f8dec823e431f48a233870d46e87b22 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 26 Jul 2023 20:51:06 +0200 Subject: [PATCH 150/173] revert unintentional changes in scripts --- ci/build_codec_sanitizers_linux.sh | 3 +- scripts/config/self_test.prm | 420 +++++++++++++++++++++++++++++ 2 files changed, 422 insertions(+), 1 deletion(-) diff --git a/ci/build_codec_sanitizers_linux.sh b/ci/build_codec_sanitizers_linux.sh index d352fa32ec..4e40f89b9a 100755 --- a/ci/build_codec_sanitizers_linux.sh +++ b/ci/build_codec_sanitizers_linux.sh @@ -40,4 +40,5 @@ make CLANG=1 -j make clean make CLANG=2 -j make clean -make CLANG=3 -j +# write out one build for warnings check +make CLANG=3 -j 2>&1 | tee build_output.txt diff --git a/scripts/config/self_test.prm b/scripts/config/self_test.prm index aff7ebcc99..f0b30c28cf 100644 --- a/scripts/config/self_test.prm +++ b/scripts/config/self_test.prm @@ -418,6 +418,286 @@ ../IVAS_dec -fec 5 BINAURAL_ROOM_IR 48 bit testv/stv4ISM48n.wav_48000_48-48_DTX_TD_binaural_room_FEC5.tst // 4 ISM with metadata at 64 kbps, 48 kHz in, 48 kHz out, BINAURAL ROOM out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 64000 48 testv/stv4ISM48s.wav bit +../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv4ISM48s.wav_64000_48-48_binaural_room.tst + +// 4 ISM with metadata at 80 kbps, 48 kHz in, 48 kHz out, HOA2 out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 80000 48 testv/stv4ISM48s.wav bit +../IVAS_dec HOA2 48 bit testv/stv4ISM48s.wav_80000_48-48_HOA2.tst + +// 4 ISM with metadata at 96 kbps, 48 kHz in, 48 kHz out, Custom LS setup out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 96000 48 testv/stv4ISM48s.wav bit +../IVAS_dec testv/ls_setup_16ch_8+4+4.txt 48 bit testv/stv4ISM48s.wav_96000_48-48_MC_custom_setup.tst + +// 4 ISM with metadata at 96 kbps, 48 kHz in, 48 kHz out, EXT out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 96000 48 testv/stv4ISM48s.wav bit +../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_96000_48-48_EXT.tst + +// 4 ISM with metadata at 128 kbps, 48 kHz in, 48 kHz out, EXT out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 128000 48 testv/stv4ISM48s.wav bit +../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_128000_48-48_EXT.tst + +// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, EXT out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_256000_48-48_EXT.tst + +// 4 ISM with metadata at 160 kbps, 48 kHz in, 48 kHz out, STEREO out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 160000 48 testv/stv4ISM48s.wav bit +../IVAS_dec STEREO 48 bit testv/stv4ISM48s.wav_160000_48-48_STEREO.tst + +// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural.tst + +// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -t testv/headrot_case03_3000_q.csv BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural_file_TDHR.tst + +// 4 ISM with metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, external orientation +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -t testv/headrot_case03_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv4ISM48s.wav_256000_48-48_binaural_file_TDHR_EXOF.tst + +// 4 ISM with metadata at 512 kbps, 48 kHz in, 48 kHz out, 5_1 +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 512000 48 testv/stv4ISM48s.wav bit +../IVAS_dec 5_1 48 bit testv/stv4ISM48s.wav_512000_48-48_5_1.tst + +// 4 ISm with metadata at 256 kbps, 48 kHz in, 48 kHz out, TD BINAURAL out, head rotation, Orientation tracking +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL 48 bit testv/stv4ISM48s.pcm_256000_48-48_TDHR_OtrAvg.tst + +// 4 ISm with metadata at 256 kbps, 48 kHz in, 48 kHz out, TD BINAURAL out, head rotation, external orientation, Orientation tracking +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL 48 bit testv/stv4ISM48s.pcm_256000_48-48_TDHR_EXOF_OtrAvg.tst + +// 4 ISM with metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, EXT out +../IVAS_cod -ism 4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit +../IVAS_dec EXT 48 bit testv/stv4ISM48s.wav_brate_sw_48-48_EXT.tst + +// 4 ISm with and without metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, DTX on, HOA3 out +../IVAS_cod -dtx -ism 4 testv/stvISM1.csv NULL NULL testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit +../IVAS_dec HOA3 48 bit testv/stv4ISM48s.wav_brate_sw_48-48_DTX_hoa3.tst + +// 4 ISM with extended metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, directivity configuration, random FEC at 5% +../IVAS_cod -ism +4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -fec 5 -render_config testv/config_directivity.cfg -t testv/headrot_case04_3000_q.csv BINAURAL 48 bit testv/stv+4ISM48s.wav_256000_48-48_binaural_file_TDHR_DirConfig_FEC5.tst + +// 4 ISM with extended metadata at 256 kbps, 48 kHz in, 48 kHz out, BINAURAL out, head rotation, external orientation, directivity configuration, random FEC at 5% +../IVAS_cod -ism +4 testv/stvISM1.csv testv/stvISM2.csv testv/stvISM3.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec -fec 5 -render_config testv/config_directivity.cfg -t testv/headrot_case04_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv+4ISM48s.wav_256000_48-48_binaural_file_TDHR_EXOF_DirConfig_FEC5.tst + +// 4 ISM with and without extended metadata bitrate switching from 24.4 kbps to 256 kbps, 48 kHz in, 48 kHz out, DTX on, EXT out +../IVAS_cod -dtx -ism +4 testv/stvISM1.csv NULL testv/stvISM3.csv testv/stvISM4.csv ../scripts/switchPaths/sw_24k4_256k.bin 48 testv/stv4ISM48s.wav bit +../IVAS_dec EXT 48 bit testv/stv+4ISM48s.wav_brate_sw_48-48_DTX_EXT.tst + +// 4 ISM with extended metadata and non diegetic pan object switching bitrate 256 kbps, 48 kHz in, 48 kHz out, DTX on, BINAURAL out +../IVAS_cod -dtx -ism +4 testv/stvISM1.csv NULL testv/stvISM_with_no_diegetic_switch.csv testv/stvISM4.csv 256000 48 testv/stv4ISM48s.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv+4ISM48s+non_diegetic_pan.wav_brate_256000-48_DTX_binaural.tst + + +// SBA at 13.2 kbps, 32kHz in, 32kHz out, HOA3 out +../IVAS_cod -sba 3 13200 32 testv/stv3OA32c.wav bit +../IVAS_dec HOA3 32 bit testv/stv3OA32c.wav_SBA_13200_32-32_HOA3.tst + +// SBA at 13.2 kbps, 32kHz in, 32kHz out, STEREO out +../IVAS_cod -sba 3 13200 32 testv/stv3OA32c.wav bit +../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_13200_32-32_stereo.tst + +// SBA at 16.4 kbps, 32kHz in, 32kHz out, 7_1_4 out +../IVAS_cod -sba 3 16400 32 testv/stv3OA32c.wav bit +../IVAS_dec 7_1_4 32 bit testv/stv3OA32c.wav_SBA_16400_32-32_7_1_4.tst + +// SBA at 16.4 kbps, 32kHz in, 32kHz out, BINAURAL out +../IVAS_cod -sba 3 16400 32 testv/stv3OA32c.wav bit +../IVAS_dec BINAURAL 32 bit testv/stv3OA32c.wav_SBA_16400_32-32_Binaural.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, STEREO out +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_stereo.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, random FEC at 5% +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Subframe_FEC5.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Headrot.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_Binaural_Headrot_EXOF.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, Orientation tracking +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL 32 bit testv/stv3OA32c.pcm_SBA_24400_32-32_Binaural_Headrot_OtrAvg.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation, Orientation tracking +../IVAS_cod -sba 3 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL 32 bit testv/stv3OA32c.pcm_SBA_24400_32-32_Binaural_Headrot_EXOF_OtrAvg.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, random FEC at 5% +../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_FEC5.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation +../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_Headrot.tst + +// SBA at 24.4 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation, external orientation +../IVAS_cod -sba 3 -dtx 24400 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_24400_32-32_DTX_Binaural_Headrot_EXOF.tst + +// SBA at 32 kbps, 32kHz in, 32kHz out, FOA out +../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit +../IVAS_dec FOA 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_FOA.tst + +// SBA at 32 kbps, 32kHz in, 32kHz out, BINAURAL out, 6% FEC pattern +../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit +../IVAS_dec -fec testv/FEC_6pct.bin BINAURAL 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_BINAURAL_FEC6.tst + +// SBA at 32 kbps, 32kHz in, 32kHz out, BINAURAL_ROOM out +../IVAS_cod -sba 1 32000 32 testv/stvFOA32c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stvFOA32c.wav_SBA_32000_32-32_BINAURAL_ROOM.tst + +// SBA at 32 kbps, 48kHz in, 48kHz out, MONO out, DTX +../IVAS_cod -dtx -sba 1 32000 48 testv/stvFOA48c.wav bit +../IVAS_dec MONO 48 bit testv/stvFOA48c.wav_SBA_32000_48-48_DTX_MONO.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, MONO out, random FEC at 5% +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -fec 5 MONO 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_MONO_FEC5.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, STEREO out +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec STEREO 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_stereo.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Subframe.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Headrot.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, external orientation +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_BinauralRoom_Headrot_EXOF.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrAvg.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrAvg.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t ../scripts/trajectories/full-circle-4s.csv -rvf ../scripts/trajectories/full-circle-4s-Vector3.csv -otr ref_vec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrRefPos.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking, external orientation +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t ../scripts/trajectories/full-circle-4s.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -rvf ../scripts/trajectories/full-circle-4s-Vector3.csv -otr ref_vec BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrRefPos.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking in level mode +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t ../scripts/trajectories/full-circle-with-up-and-down-4s.csv -rvf ../scripts/trajectories/full-circle-with-up-and-down-4s-Vector3.csv -otr ref_vec_lev BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_OtrRefPosLev.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, reference vector tracking in level mode, external orientation +../IVAS_cod -sba 3 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t ../scripts/trajectories/full-circle-with-up-and-down-4s.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -rvf ../scripts/trajectories/full-circle-with-up-and-down-4s-Vector3.csv -otr ref_vec_lev BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_48000_32-32_BinauralRoom_Headrot_EXOF_OtrRefPosLev.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, random FEC at 5% +../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_FEC5.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation +../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_Headrot.tst + +// SBA at 48 kbps, 32kHz in, 32kHz out, DTX on, BINAURAL out, DTX on, Headrotation, external orientation +../IVAS_cod -sba 3 -dtx 48000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_48000_32-32_DTX_Binaural_Headrot_EXOF.tst + +// SBA at 48 kbps, 48kHz in, 48kHz out, 5_1_2 out +../IVAS_cod -sba 3 48000 48 testv/stv3OA48c.wav bit +../IVAS_dec 5_1_2 48 bit testv/stv3OA48c.wav_SBA_48000_48-48_5_1_2.tst + +// SBA at 64 kbps, 32kHz in, 32kHz out, FOA out, DTX, random FEC at 5% +../IVAS_cod -dtx -sba 1 64000 32 testv/stvFOA32c.wav bit +../IVAS_dec -fec 5 FOA 32 bit testv/stvFOA32c.wav_SBA_64000_32-32_DTX_FOA.tst + +// SBA at 64 kbps, 48kHz in, 48kHz out, 5_1_4 out +../IVAS_cod -sba 1 64000 48 testv/stvFOA48c.wav bit +../IVAS_dec 5_1_4 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_5_1_4.tst + +// SBA at 64 kbps, 48kHz in, 48kHz out, 7_1_4 out +../IVAS_cod -sba 1 64000 48 testv/stvFOA48c.wav bit +../IVAS_dec 7_1_4 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_7_1_4.tst + +// SBA at 64 kpbs, 48kHz in, 48kHz out, BINAURAL out, DTX +../IVAS_cod -dtx -sba 1 64000 48 testv/stvFOA48c.wav bit +../IVAS_dec BINAURAL 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_DTX_BINAURAL.tst + +// SBA at 64 kpbs, 48kHz in, 48kHz out, BINAURAL_ROOM out, DTX +../IVAS_cod -dtx -sba 1 64000 48 testv/stvFOA48c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stvFOA48c.wav_SBA_64000_48-48_DTX_BINAURAL_ROOM.tst + +// SBA at 80 kbps, 32kHz in, 32kHz out, HOA3 out +../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit +../IVAS_dec HOA3 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_HOA3.tst + +// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, random FEC at 5% +../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit +../IVAS_dec -fec 5 BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_FEC5.tst + +// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation +../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_Headrot.tst + +// SBA at 80 kbps, 32kHz in, 32kHz out, BINAURAL out, Headrotation, external orientation +../IVAS_cod -sba 3 80000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 32 bit testv/stv3OA32c.wav_SBA_80000_32-32_Binaural_Headrot_EXOF.tst + +// SBA at 96 kbps, 32kHz in, 32kHz out, STEREO out +../IVAS_cod -sba 1 96000 32 testv/stvFOA32c.wav bit +../IVAS_dec STEREO 32 bit testv/stvFOA32c.wav_SBA_96000_32-32_STEREO.tst + +// SBA at 96 kbps, 48kHz in, 48kHz out, FOA out +../IVAS_cod -sba 1 96000 48 testv/stvFOA48c.wav bit +../IVAS_dec FOA 48 bit testv/stvFOA48c.wav_SBA_96000_48-48_FOA.tst + +// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation +../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot_case00_3000_q.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot.tst + +// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, external orientation +../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot_case00_3000_q.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.wav_SBA_128000_32-32_Binaural_room_Headrot_EXOF.tst + +// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking +../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_128000_32-32_Binaural_room_Headrot_OtrAvg.tst + +// SBA at 128 kbps, 32kHz in, 32kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation +../IVAS_cod -sba 3 128000 32 testv/stv3OA32c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 32 bit testv/stv3OA32c.pcm_SBA_128000_32-32_Binaural_room_Headrot_EXOF_OtrAvg.tst + +// SBA at 192 kbps, 48kHz in, 48kHz out, HOA2 out, random FEC at 5% +../IVAS_cod -sba 3 192000 48 testv/stv3OA48c.wav bit +../IVAS_dec -fec 5 HOA2 48 bit testv/stv3OA48c.wav_SBA_192000_48-48_HOA2_FEC5.tst + +// SBA at 48 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out +../IVAS_cod -sba 3 -dtx 48000 48 testv/stv3OA48c.wav bit +../IVAS_dec 5_1 48 bit testv/stv3OA48c.wav_SBA_48000_48-48_DTX_5_1.tst + // SBA at 160 kbps, 32kHz in, 32kHz out, FOA out ../IVAS_cod -sba 1 160000 32 testv/stvFOA32c.wav bit ../IVAS_dec FOA 32 bit testv/stvFOA32c.wav_SBA_160000_32-32_FOA.tst @@ -558,6 +838,146 @@ // MASA 1dir 2TC at 13.2 kbps, 48kHz in, 48kHz out, 5_1 out, random FEC at 5% ../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 13200 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -fec 5 5_1 48 bit testv/stv1MASA2TC48c.wav_13200_48-48_5_1_FEC5.tst + +// MASA 1dir 2TC at 16.4 kbps, 48kHz in, 48kHz out, 5_1 out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 16400 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48c.wav_16400_48-48_5_1.tst + +// MASA 1dir 2TC at 24.4 kbps, 48kHz in, 48kHz out, STEREO out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 24400 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec STEREO 48 bit testv/stv1MASA2TC48c.wav_24400_48-48_STEREO.tst + +// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom.tst + +// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom_Headrot.tst + +// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, external orientation +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL_ROOM_IR 48 bit testv/stv1MASA2TC48c.wav_32000_48-48_BinauralRoom_Headrot_EXOF.tst + +// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv -otr avg BINAURAL_ROOM_IR 48 bit testv/stv_IVASMASA_1dir2TC.pcm_32000_48-48_BinauralRoom_Headrot_OtrAvg.tst + +// MASA 1dir 2TC at 32 kbps, 48kHz in, 48kHz out, BINAURAL ROOM out, Headrotation, Orientation tracking, external orientation +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 32000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv -otr avg BINAURAL_ROOM_IR 48 bit testv/stv_IVASMASA_1dir2TC.pcm_32000_48-48_BinauralRoom_Headrot_EXOF_OtrAvg.tst + +// MASA 1dir 2TC at 48 kbps, 48kHz in, 48kHz out, 7_1_4 out, random FEC at 5% +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 48000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -fec 5 7_1_4 48 bit testv/stv1MASA2TC48c.wav_48000_48-48_7_1_4_FEC5.tst + +// MASA 1dir 2TC at 80 kbps, 48kHz in, 48kHz out, STEREO out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 80000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec STEREO 48 bit testv/stv1MASA2TC48c.wav_80000_48-48_STEREO.tst + +// MASA 1dir 2TC at 96 kbps, 48kHz in, 48kHz out, MONO out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 96000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec MONO 48 bit testv/stv1MASA2TC48c.wav_96000_48-48_MONO.tst + +// MASA 1dir 2TC at 160 kbps, 48kHz in, 48kHz out, HOA3 out, random FEC at 5% +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 160000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec -fec 5 HOA3 48 bit testv/stv1MASA2TC48c.wav_160000_48-48_HOA3_FEC5.tst + +// MASA 1dir 2TC at 256 kbps, 48kHz in, 48kHz out, 5_1 out +../IVAS_cod -masa 2 testv/stv1MASA2TC48c.met 256000 48 testv/stv1MASA2TC48c.wav bit +../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48c.wav_256000_48-48_5_1.tst + +// MASA 2dir 2TC at 48 kbps, 48kHz in, 48kHz out, 5_1 out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 48000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec 5_1 48 bit testv/stv2MASA2TC48c.wav_48000_48-48_5_1.tst + +// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, EXTERNAL out, random FEC at 5% +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec -fec 5 EXT 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_external_FEC5.tst + +// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, BINAURAL out, Headrotation +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv BINAURAL 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_BINAURAL_Headrot.tst + +// MASA 2dir 2TC at 64 kbps, 48kHz in, 48kHz out, BINAURAL out, Headrotation, external orientation +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 64000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec -t testv/headrot.csv -exof testv/headrot_case00_3000_q_combinedRotationTest.csv BINAURAL 48 bit testv/stv2MASA2TC48c.wav_64000_48-48_BINAURAL_Headrot_EXOF.tst + +// MASA 2dir 2TC at 128 kbps, 48kHz in, 48kHz out, FOA out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 128000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec FOA 48 bit testv/stv2MASA2TC48c.wav_128000_48-48_FOA.tst + +// MASA 2dir 2TC at 192 kbps, 48kHz in, 48kHz out, 5_1_4 out, random FEC at 5% +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 192000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec -fec 5 5_1_4 48 bit testv/stv2MASA2TC48c.wav_192000_48-48_5_1_4_FEC5.tst + +// MASA 2dir 2TC at 384 kbps, 48kHz in, 48kHz out, BINAURAL_ROOM out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 384000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv2MASA2TC48c.wav_384000_48-48_BinauralRoom.tst + +// MASA 2dir 2TC at 384 kbps, 48kHz in, 48kHz out, BINAURAL_ROOM out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 384000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec BINAURAL_ROOM_IR 48 bit testv/stv2MASA2TC48c.wav_384000_48-48_BinauralRoom_Subframe.tst + +// MASA 2dir 2TC at 512 kbps, 48kHz in, 48kHz out, 5_1 out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met 512000 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec 5_1 48 bit testv/stv2MASA2TC48c.wav_512000_48-48_5_1.tst + +// MASA 1dir 1TC at 13.2 kbps, 48kHz in, 48kHz out, DTX on, 7_1_4 out +../IVAS_cod -dtx -masa 1 testv/stv1MASA1TC48n.met 13200 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec 7_1_4 48 bit testv/stv1MASA1TC48n.wav_13200_48-48_DTX_7_1_4.tst + +// MASA 1dir 1TC at 24.4 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out +../IVAS_cod -dtx -masa 1 testv/stv1MASA1TC48n.met 24400 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec 5_1 48 bit testv/stv1MASA1TC48n.wav_24400_48-48_DTX_5_1.tst + +// MASA 1dir 2TC at 16.4 kbps, 48kHz in, 48kHz out, DTX on, 7_1_4 out +../IVAS_cod -dtx -masa 2 testv/stv1MASA2TC48n.met 16400 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec 7_1_4 48 bit testv/stv1MASA2TC48n.wav_16400_48-48_DTX_7_1_4.tst + +// MASA 1dir 2TC at 32.0 kbps, 48kHz in, 48kHz out, DTX on, 5_1 out +../IVAS_cod -dtx -masa 2 testv/stv1MASA2TC48n.met 32000 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec 5_1 48 bit testv/stv1MASA2TC48n.wav_32000_48-48_DTX_5_1.tst + +// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, 5_1 out +../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec 5_1 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_5_1.tst + +// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, STEREO out +../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec STEREO 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_STEREO.tst + +// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, BINAURAL out +../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_BINAURAL.tst + +// MASA 1dir 1TC bitrate switching from 13.2 kbps to 128 kbps, 48kHz in, 48kHz out, FOA out +../IVAS_cod -masa 1 testv/stv1MASA1TC48n.met ../scripts/switchPaths/sw_13k2_to_128k_10fr.bin 48 testv/stv1MASA1TC48n.wav bit +../IVAS_dec FOA 48 bit testv/stv1MASA1TC48n.wav_sw_48-48_FOA.tst + +// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out +../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec BINAURAL 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_BINAURAL.tst + +// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out +../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec MONO 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_MONO.tst + +// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1 out +../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec 7_1 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_7_1.tst + +// MASA 1dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, MONO out +../IVAS_cod -masa 2 testv/stv1MASA2TC48n.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv1MASA2TC48n.wav bit +../IVAS_dec MONO 48 bit testv/stv1MASA2TC48n.wav_sw_48-48_MONO.tst + +// MASA 2dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, 7_1 out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv2MASA2TC48c.wav bit +../IVAS_dec 7_1 48 bit testv/stv2MASA2TC48c.wav_sw_48-48_7_1.tst + +// MASA 2dir 2TC bitrate switching from 13.2 kbps to 512 kbps, 48kHz in, 48kHz out, BINAURAL out +../IVAS_cod -masa 2 testv/stv2MASA2TC48c.met ../scripts/switchPaths/sw_13k2_512k.bin 48 testv/stv2MASA2TC48c.wav bit ../IVAS_dec BINAURAL 48 bit testv/stv2MASA2TC48c.wav_sw_48-48_BINAURAL.tst -- GitLab From 27c6afaecf76581fcba4a0000ce5c3597fd5572a Mon Sep 17 00:00:00 2001 From: advasila Date: Thu, 27 Jul 2023 11:43:50 +0300 Subject: [PATCH 151/173] merge switch OMASA_FIX_LOW_FS --- lib_com/options.h | 1 - lib_enc/ivas_enc.c | 6 ------ lib_enc/ivas_masa_enc.c | 12 +----------- lib_enc/ivas_omasa_enc.c | 15 +-------------- 4 files changed, 2 insertions(+), 32 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index dd46315152..ae51810807 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -202,7 +202,6 @@ #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix #define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ -#define OMASA_FIX_LOW_FS /* Nokia: fixes related to lower input signal sampling rates */ #endif /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 33ab5a156b..429a18e0d2 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -298,10 +298,8 @@ ivas_error ivas_enc( flag_omasa_ener_brate = 0; -#ifdef OMASA_FIX_LOW_FS /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#endif if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK ) { @@ -318,10 +316,6 @@ ivas_error ivas_enc( set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; -#ifndef OMASA_FIX_LOW_FS - /* Estimate TF-tile energy for the input MASA stream */ - ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); -#endif /* put audio object data in SCE's */ if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC ) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index abe899a794..f717f1c174 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -745,9 +745,7 @@ ivas_error ivas_masa_enc_config( ivas_error error; #ifdef MASA_AND_OBJECTS int32_t ism_total_brate; -#ifdef OMASA_FIX_LOW_FS int32_t masa_total_brate; -#endif #endif error = IVAS_ERR_OK; @@ -903,16 +901,12 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; -#ifdef OMASA_FIX_LOW_FS masa_total_brate = ivas_total_brate; if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); } if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) -#else - if ( ivas_total_brate > IVAS_256k && ivas_format == MASA_FORMAT ) -#endif #else if ( ivas_total_brate > IVAS_256k ) #endif @@ -944,12 +938,8 @@ ivas_error ivas_masa_enc_config( st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; } } -#ifdef OMASA_FIX_LOW_FS - masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); -#else - masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, ivas_total_brate > IVAS_256k, NULL ); -#endif + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index aaa4627361..503eeb4732 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -531,14 +531,8 @@ void ivas_omasa_enc( } /* force computation into high resolution */ -#ifndef OMASA_FIX_LOW_FS - n_bands_orig = hOMasa->nbands; -#endif - n_subframes_orig = hOMasa->nSubframes; -#ifndef OMASA_FIX_LOW_FS - hOMasa->nbands = MASA_FREQUENCY_BANDS; -#endif + n_subframes_orig = hOMasa->nSubframes; hOMasa->nSubframes = MAX_PARAM_SPATIAL_SUBFRAMES; /* Estimate MASA parameters from the objects */ @@ -556,20 +550,13 @@ void ivas_omasa_enc( } /* restore resolution parameters */ -#ifndef OMASA_FIX_LOW_FS - hOMasa->nbands = n_bands_orig; -#endif hOMasa->nSubframes = n_subframes_orig; /* perform MASA+ISM merge in full resolution */ numCodingBands_orig = hMasa->config.numCodingBands; joinedSubframes_orig = hMasa->config.joinedSubframes; -#ifndef OMASA_FIX_LOW_FS - hMasa->config.numCodingBands = MASA_FREQUENCY_BANDS; -#else hMasa->config.numCodingBands = hOMasa->nbands; -#endif hMasa->config.joinedSubframes = 0; ivas_merge_masa_metadata( hMasa, hOMasaMeta ); /* => merge result in hMasa->masaMetadata */ -- GitLab From 6c4ccc90972eb31acea61f23f7f849c6c12a829e Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Thu, 27 Jul 2023 11:10:36 +0200 Subject: [PATCH 152/173] remove OMASA_BRSW_MONO_FIX since this was made unnecessary by the DirAC refactoring. close function comment fix. remove unnecessary "#if 1" and "#if 0". remove refactoring TODOs. --- lib_com/options.h | 1 - lib_dec/ivas_init_dec.c | 5 ----- lib_dec/ivas_ism_renderer.c | 2 +- lib_dec/ivas_masa_dec.c | 15 +-------------- lib_dec/ivas_omasa_dec.c | 4 +--- 5 files changed, 3 insertions(+), 24 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index ae51810807..f08ad0edc1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -201,7 +201,6 @@ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ #define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix -#define OMASA_BRSW_MONO_FIX /* Nokia: fix renderer config under rateswitching and MONO output */ #endif /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5bf780788f..247174990d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1175,12 +1175,7 @@ ivas_error ivas_init_decoder( return error; } -#if 0 - /* TODO: dirac refactor merge: check! */ - if (st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_MONO_DOWNMIX) -#else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) -#endif { if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 08017af46f..6e776d3577 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -415,7 +415,7 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( /*-------------------------------------------------------------------------* * ivas_masa_ism_separate_object_renderer_close() * - * Close structures, reserve memory, and init values. + * Close structures, free memory. *-------------------------------------------------------------------------*/ void ivas_masa_ism_separate_object_renderer_close( diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6306881c9c..7ee3fad666 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1288,14 +1288,8 @@ ivas_error ivas_masa_dec_reconfigure( /* renderer might have changed, reselect */ ivas_renderer_select( st_ivas ); -/* Todo: Check this */ -#if 0 && defined( OMASA_BRSW_MONO_FIX ) /* TODO */ if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) ) -#else - if ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend == NULL ) || - ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin == NULL ) ) -#endif { /* init a new DirAC dec */ if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) @@ -1303,11 +1297,7 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } -#if 0 && defined( OMASA_BRSW_MONO_FIX ) - else if ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) -#else else if ( st_ivas->renderer_type == RENDERER_DISABLE ) -#endif { if ( st_ivas->hDirAC != NULL ) { @@ -1336,7 +1326,6 @@ ivas_error ivas_masa_dec_reconfigure( sts[0]->bit_stream = bit_stream + num_bits; num_bits += (int16_t) ( st_ivas->hSCE[sce_id]->element_brate / FRAMES_PER_SEC ); - /* TODO refactor merge: this is not in the pre-refactor version */ if ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) && st_ivas->hDiracDecBin != NULL ) { if ( ( error = ivas_dirac_dec_config( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) @@ -1396,8 +1385,6 @@ ivas_error ivas_masa_dec_reconfigure( if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ { #endif -#if 1 - /* TODO refactor merge: do we need this or similar?*/ /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ @@ -1409,7 +1396,7 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } -#endif + /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index e8add408ef..2f3af704b1 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -360,8 +360,6 @@ ivas_error ivas_omasa_dec_config( * TD Decorrelator *-----------------------------------------------------------------*/ -#if 1 - /* TODO: executed already in ivas_masa_dec_reconfigure */ if ( st_ivas->hDiracDecBin != NULL ) { if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) @@ -378,7 +376,7 @@ ivas_error ivas_omasa_dec_config( { return error; } -#endif + } return IVAS_ERR_OK; -- GitLab From 0bf80e6c45ac4e92efbe333f49e04e9692f69a04 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 27 Jul 2023 11:53:29 +0200 Subject: [PATCH 153/173] - accept FIX_356_ISM_METADATA_SYNC_OMASA - fix compilation without MASA_AND_OBJECTS --- lib_com/options.h | 1 - lib_dec/ivas_init_dec.c | 7 ++++++- lib_dec/ivas_masa_dec.c | 4 ++++ lib_dec/ivas_objectRenderer_internal.c | 4 ++-- lib_dec/ivas_omasa_dec.c | 1 - lib_enc/ivas_ism_metadata_enc.c | 3 ++- lib_enc/ivas_masa_enc.c | 4 ++++ 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index f08ad0edc1..468cdbfed5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -200,7 +200,6 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #ifdef MASA_AND_OBJECTS #define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#define FIX_356_ISM_METADATA_SYNC_OMASA // temp. fix #endif /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 247174990d..0ee4567521 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -784,11 +784,14 @@ ivas_error ivas_init_decoder( if ( output_config == AUDIO_CONFIG_EXTERNAL ) { +#ifdef MASA_AND_OBJECTS if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport + st_ivas->nchan_ism; } - else if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) + else +#endif + if ( !( st_ivas->ism_mode == ISM_MODE_PARAM ) ) { hDecoderConfig->nchan_out = st_ivas->nchan_transport; } @@ -2583,6 +2586,7 @@ static ivas_error doSanityChecks_IVAS( } } +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && output_config == AUDIO_CONFIG_EXTERNAL ) @@ -2590,6 +2594,7 @@ static ivas_error doSanityChecks_IVAS( return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" ); } } +#endif #ifdef DEBUGGING if ( ( st_ivas->hDecoderConfig->force_rend == FORCE_TD_RENDERER ) && ( ( st_ivas->ivas_format != MC_FORMAT && st_ivas->ivas_format != ISM_FORMAT ) || ( output_config != AUDIO_CONFIG_BINAURAL && output_config != AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || ( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) || ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode != MC_MODE_MCT ) ) ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 7ee3fad666..c63f4af93f 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -571,7 +571,11 @@ ivas_error ivas_masa_decode( } } +#ifdef MASA_AND_OBJECTS if ( ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) +#else + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) +#endif { create_masa_ext_out_meta( hMasa, hQMetaData, st_ivas->nchan_transport ); } diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 95ffee7423..497ae240f2 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -107,10 +107,10 @@ ivas_error ivas_td_binaural_renderer( ism_md_subframe_update = 2; } -#ifdef FIX_356_ISM_METADATA_SYNC_OMASA +#ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { - ism_md_subframe_update = 0; + ism_md_subframe_update = 0; // ToDo (for Mikko-Ville): verify whether it should not be 2 } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 2f3af704b1..3a41019ccb 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -376,7 +376,6 @@ ivas_error ivas_omasa_dec_config( { return error; } - } return IVAS_ERR_OK; diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 52a6a634dc..301576d870 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -747,7 +747,8 @@ ivas_error ivas_ism_metadata_enc( hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; if ( ism_mode == ISM_MODE_DISC ) { - if ( hIsmMeta[ch]->ism_metadata_flag == 0 && localVAD[ch] == 0 && ism_metadata_flag_global ) + if ( ism_imp[ch] == ISM_NO_META && ( ( total_brate[ch] < ACELP_8k00 && element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) || + ( total_brate[ch] <= ACELP_16k_LOW_LIMIT && element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) ) ) { hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index f717f1c174..d86b52e9b5 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -939,7 +939,11 @@ ivas_error ivas_masa_enc_config( } } +#ifdef MASA_AND_OBJECTS masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); +#else + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, ivas_total_brate > IVAS_256k, NULL ); +#endif if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) { -- GitLab From f84b1fba0ee64475eef93e3f89fefee1d19483f2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 28 Jul 2023 11:48:02 +0200 Subject: [PATCH 154/173] fix differences wrt. main --- lib_com/ivas_cnst.h | 9 ++ lib_rend/ivas_objectRenderer.c | 47 ++++++ lib_rend/ivas_objectRenderer_hrFilt.c | 20 ++- lib_rend/ivas_objectRenderer_mix.c | 4 + lib_rend/ivas_objectRenderer_sources.c | 192 +++++++++++++++---------- lib_rend/ivas_prot_rend.h | 2 + 6 files changed, 193 insertions(+), 81 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index e5f2b270d6..d19c779269 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1672,13 +1672,22 @@ typedef enum typedef enum { TDREND_POSTYPE_ABSOLUTE, /* The source position is in absolute coordinates */ +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT TDREND_POSTYPE_NON_DIEGETIC /* The source position is non-diegetic */ +#else + TDREND_POSTYPE_RELATIVE_TO_LISTENER /* The source position is relative to the listener */ +#endif } TDREND_PosType_t; typedef enum { TDREND_PLAYSTATUS_INITIAL, +#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT + TDREND_PLAYSTATUS_PLAYING, + TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC +#else TDREND_PLAYSTATUS_PLAYING +#endif } TDREND_PlayStatus_t; typedef enum diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index be161c50e9..3aa9e6d80b 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -307,6 +307,21 @@ ivas_error ivas_td_binaural_renderer_unwrap( hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; c_indx++; } +#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT +#ifdef FIX_550_FIRST_FRAME_ACCESS + if ( ivas_format == ISM_FORMAT ) + { + if ( hIsmMetaData[nS]->non_diegetic_flag ) + { + TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ); + } + else + { + TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING ); + } + } +#endif +#endif } for ( subframe_idx = 0; subframe_idx < MAX_PARAM_SPATIAL_SUBFRAMES; subframe_idx++ ) @@ -333,6 +348,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( return error; } +#ifdef FIX_550_FIRST_FRAME_ACCESS /* Advance subframe pointer */ c_indx = 0; for ( nS = 0; nS < num_src; nS++ ) @@ -343,6 +359,7 @@ ivas_error ivas_td_binaural_renderer_unwrap( c_indx++; } } +#endif } if ( hReverb != NULL ) @@ -379,6 +396,9 @@ ivas_error TDREND_GetMix( float hrf_left_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; float hrf_right_delta[SFX_SPAT_BIN_MAX_FILTER_LENGTH]; int16_t intp_count; +#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT + float pan_left, pan_right; +#endif int16_t subframe_update_flag; subframe_update_flag = subframe_idx == ism_md_subframe_update; @@ -414,6 +434,21 @@ ivas_error TDREND_GetMix( { error = TDREND_REND_RenderSourceHRFilt( Src_p, hrf_left_delta, hrf_right_delta, intp_count, output_buf, subframe_length ); } + +#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT + if ( ( SrcRend_p->InputAvailable == TRUE ) && ( SrcRend_p->PlayStatus == TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ) ) + { + pan_left = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; + pan_right = 1.f - pan_left; +#ifdef FIX_550_FIRST_FRAME_ACCESS + v_multc_acc( Src_p->InputFrame_p, pan_left, output_buf[0], subframe_length ); + v_multc_acc( Src_p->InputFrame_p, pan_right, output_buf[1], subframe_length ); +#else + v_multc_acc( &Src_p->InputFrame_p[subframe_idx * subframe_length], pan_left, output_buf[0], subframe_length ); + v_multc_acc( &Src_p->InputFrame_p[subframe_idx * subframe_length], pan_right, output_buf[1], subframe_length ); +#endif + } +#endif } /* Populate output variable */ @@ -494,11 +529,23 @@ void TDREND_Update_object_positions( Pos[1] = hIsmMetaData[nS]->azimuth / 90.f; Pos[2] = 0; TDREND_MIX_SRC_SetPos( hBinRendererTd, nS, Pos ); +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_NON_DIEGETIC; +#else +#ifndef FIX_550_FIRST_FRAME_ACCESS + TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING_NON_DIEGETIC ); +#endif +#endif } else { +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT hBinRendererTd->Sources[nS]->SrcSpatial_p->PosType = TDREND_POSTYPE_ABSOLUTE; +#else +#ifndef FIX_550_FIRST_FRAME_ACCESS + TDREND_MIX_SRC_SetPlayState( hBinRendererTd, nS, TDREND_PLAYSTATUS_PLAYING ); +#endif +#endif } TDREND_MIX_SRC_SetDir( hBinRendererTd, nS, Dir ); diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index c73b28a531..0f8904e2aa 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -79,6 +79,11 @@ ivas_error TDREND_REND_RenderSourceHRFilt( v_add( LeftOutputFrame, output_buf[0], output_buf[0], subframe_length ); v_add( RightOutputFrame, output_buf[1], output_buf[1], subframe_length ); +#ifndef FIX_550_FIRST_FRAME_ACCESS + Src_p->InputFrame_p += subframe_length; /* Increment input pointer */ +#endif + + return IVAS_ERR_OK; } @@ -94,17 +99,24 @@ void GetFilterFromAngle( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* i/o: HR filter set structure */ const float Elev, /* i : Elevation, degrees */ float Azim, /* i : Azimuth, degrees */ - const int16_t filterlength, /* i : Filter length */ - float *hrf_left, /* o : Left HR filter */ - float *hrf_right, /* o : Right HR filter */ - int16_t *itd /* o : ITD value */ +#ifdef FIX_569_TD_FILTER_LENGTH + const int16_t filterlength, /* i : Filter length */ +#endif + float *hrf_left, /* o : Left HR filter */ + float *hrf_right, /* o : Right HR filter */ + int16_t *itd /* o : ITD value */ ) { GenerateFilter( Elev, Azim, &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ); +#ifdef FIX_569_TD_FILTER_LENGTH mvr2r( HrFiltSet_p->ModelEval.hrfModL, hrf_left, filterlength ); mvr2r( HrFiltSet_p->ModelEval.hrfModR, hrf_right, filterlength ); +#else + mvr2r( HrFiltSet_p->ModelEval.hrfModL, hrf_left, HrFiltSet_p->ModelParams.K ); + mvr2r( HrFiltSet_p->ModelEval.hrfModR, hrf_right, HrFiltSet_p->ModelParams.K ); +#endif /* 4. Evaluate the ITD */ if ( HrFiltSet_p->ModelParams.UseItdModel ) diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 60a66b168c..7f3edb41af 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -309,7 +309,11 @@ ivas_error TDREND_MIX_AddSrc( } else { +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT if ( ( PosType < TDREND_POSTYPE_ABSOLUTE ) || ( PosType > TDREND_POSTYPE_NON_DIEGETIC ) ) +#else + if ( ( PosType < TDREND_POSTYPE_ABSOLUTE ) || ( PosType > TDREND_POSTYPE_RELATIVE_TO_LISTENER ) ) +#endif { return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid position type!\n" ) ); } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 50d68e8944..438c1e0f0a 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -218,8 +218,11 @@ static void TDREND_SRC_REND_Init( /* Internal state */ SrcRend_p->InputAvailable = FALSE; +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT SrcRend_p->PlayStatus = TDREND_PLAYSTATUS_PLAYING; - +#else + SrcRend_p->PlayStatus = TDREND_PLAYSTATUS_INITIAL; +#endif /* SrcGain */ for ( nC = 0; nC < SPAT_BIN_MAX_INPUT_CHANNELS; nC++ ) { @@ -276,101 +279,131 @@ void TDREND_SRC_REND_UpdateFiltersFromSpatialParams( Listener_p = hBinRendererTd->Listener_p; HrFiltSet_p = hBinRendererTd->HrFiltSet_p; +#ifdef FIX_569_TD_FILTER_LENGTH *filterlength = min( HrFiltSet_p->FiltLength, SFX_SPAT_BIN_MAX_FILTER_LENGTH ); +#else + *filterlength = HrFiltSet_p->FiltLength; +#endif +#ifndef FIX_550_FIRST_FRAME_ACCESS_ALT + /* 1. Map source pos to the coordinate system of the listener */ + switch ( SrcSpatial_p->PosType ) + { + case TDREND_POSTYPE_RELATIVE_TO_LISTENER: + /* Listener relative position */ + mvr2r( SrcSpatial_p->Pos_p, ListRelPos, 3 ); + break; + case TDREND_POSTYPE_ABSOLUTE: + /* Absolute position */ + TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); + break; + default: /* Illegal position type */ +#ifdef DEBUGGING + printf( "Warning! TDREND_SRC_REND_UpdateFiltersFromSpatialParams: Invalid position type. Assuming absolute position!\n" ); +#endif + /* Assume absolute position */ + TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); + break; + } +#else if ( SrcSpatial_p->PosType == TDREND_POSTYPE_ABSOLUTE ) { /* Absolute position */ TDREND_SPATIAL_VecMapToNewCoordSystem( SrcSpatial_p->Pos_p, Listener_p->Pos, Listener_p->Front, Listener_p->Up, Listener_p->Right, ListRelPos, ListRelPosAbs ); +#endif + ListRelDist = TDREND_SPATIAL_VecNorm( ListRelPos ); - ListRelDist = TDREND_SPATIAL_VecNorm( ListRelPos ); - - /* 2. Evaluate the Elevation and Azimuth angles */ - if ( ( ListRelPos[0] == 0 ) && ( ListRelPos[1] == 0 ) && ( ListRelPos[2] == 0 ) ) - { - Elev = 0.0; - Azim = 0.0; - } - else - { - Elev = _180_OVER_PI * atan2f( ListRelPos[2], sqrtf( ListRelPos[0] * ListRelPos[0] + ListRelPos[1] * ListRelPos[1] ) ); - /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ - Azim = -1.0f * _180_OVER_PI * (float) atan2f( ListRelPos[1], ListRelPos[0] ); - } + /* 2. Evaluate the Elevation and Azimuth angles */ + if ( ( ListRelPos[0] == 0 ) && ( ListRelPos[1] == 0 ) && ( ListRelPos[2] == 0 ) ) + { + Elev = 0.0; + Azim = 0.0; + } + else + { + Elev = _180_OVER_PI * atan2f( ListRelPos[2], sqrtf( ListRelPos[0] * ListRelPos[0] + ListRelPos[1] * ListRelPos[1] ) ); + /* Basis set is [front, right, up], which is a left-handed coordinate system. Minus sign here is to change to a positive-left system for azimuth */ + Azim = -1.0f * _180_OVER_PI * (float) atan2f( ListRelPos[1], ListRelPos[0] ); + } - GetFilterFromAngle( HrFiltSet_p, Elev, Azim, *filterlength, hrf_left, hrf_right, itd ); +#ifdef FIX_569_TD_FILTER_LENGTH + GetFilterFromAngle( HrFiltSet_p, Elev, Azim, *filterlength, hrf_left, hrf_right, itd ); +#else + GetFilterFromAngle( HrFiltSet_p, Elev, Azim, hrf_left, hrf_right, itd ); +#endif - /* 6. Evaluate the directional and distance gains */ - /* Directional gain */ - *SrcRend_p->DirGain_p = 1.0f; - if ( SrcSpatial_p->DirAttenEnabled ) - { - *SrcRend_p->DirGain_p = TDREND_SRC_SPATIAL_GetDirGain( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p, ListRelPosAbs ); - } + /* 6. Evaluate the directional and distance gains */ + /* Directional gain */ + *SrcRend_p->DirGain_p = 1.0f; + if ( SrcSpatial_p->DirAttenEnabled ) + { + *SrcRend_p->DirGain_p = TDREND_SRC_SPATIAL_GetDirGain( &SrcSpatial_p->DirAtten, SrcSpatial_p->Front_p, ListRelPosAbs ); + } - /* Distance gain */ - *SrcRend_p->DistGain_p = 1.0f; - if ( hBinRendererTd->UseCommonDistAttenModel ) + /* Distance gain */ + *SrcRend_p->DistGain_p = 1.0f; + if ( hBinRendererTd->UseCommonDistAttenModel ) + { + if ( hBinRendererTd->DistAttenEnabled ) { - if ( hBinRendererTd->DistAttenEnabled ) - { - SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; - *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); - } + SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; + *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); } - else + } + else + { + if ( SrcSpatial_p->DistAttenEnabled ) { - if ( SrcSpatial_p->DistAttenEnabled ) - { - *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); - } + *SrcRend_p->DistGain_p = TDREND_SRC_SPATIAL_GetDistGain( &SrcSpatial_p->DistAtten, ListRelDist ); } + } - /* Update total gains */ - *Gain = ( *SrcRend_p->SrcGain_p ) * ( *SrcRend_p->DirGain_p ) * ( *SrcRend_p->DistGain_p ) * hBinRendererTd->Gain; - - /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ - elev_delta = Elev - Src_p->elev_prev; - azim_delta = Azim - Src_p->azim_prev; - Src_p->elev_prev = Elev; - Src_p->azim_prev = Azim; + /* Update total gains */ + *Gain = ( *SrcRend_p->SrcGain_p ) * ( *SrcRend_p->DirGain_p ) * ( *SrcRend_p->DistGain_p ) * hBinRendererTd->Gain; - azim_delta = ( azim_delta > 180.0f ) ? ( azim_delta - 360 ) : ( ( azim_delta < -180.0f ) ? ( azim_delta + 360 ) : ( azim_delta ) ); /* map to -180:180 range */ - *intp_count = min( MAX_INTERPOLATION_STEPS, max( (int16_t) ( fabsf( azim_delta ) * MAX_ANGULAR_STEP_INV ), (int16_t) ( fabsf( elev_delta ) * MAX_ANGULAR_STEP_INV ) ) ); - } - else /* TDREND_POSTYPE_NON_DIEGETIC */ - { - *itd = 0; - *Gain = 1.0f; - set_f( hrf_left, 0.0f, *filterlength ); - set_f( hrf_right, 0.0f, *filterlength ); - hrf_left[0] = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; - hrf_right[0] = 1.f - hrf_left[0]; - *intp_count = MAX_INTERPOLATION_STEPS; - Src_p->elev_prev = 0; - Src_p->azim_prev = 360.0f; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ - } + /* Delta for interpolation, in case the angular step exceeds MAX_ANGULAR_STEP */ + elev_delta = Elev - Src_p->elev_prev; + azim_delta = Azim - Src_p->azim_prev; + Src_p->elev_prev = Elev; + Src_p->azim_prev = Azim; + azim_delta = ( azim_delta > 180.0f ) ? ( azim_delta - 360 ) : ( ( azim_delta < -180.0f ) ? ( azim_delta + 360 ) : ( azim_delta ) ); /* map to -180:180 range */ + *intp_count = min( MAX_INTERPOLATION_STEPS, max( (int16_t) ( fabsf( azim_delta ) * MAX_ANGULAR_STEP_INV ), (int16_t) ( fabsf( elev_delta ) * MAX_ANGULAR_STEP_INV ) ) ); +#ifdef FIX_550_FIRST_FRAME_ACCESS_ALT +} +else /* TDREND_POSTYPE_NON_DIEGETIC */ +{ + *itd = 0; + *Gain = 1.0f; + set_f( hrf_left, 0.0f, *filterlength ); + set_f( hrf_right, 0.0f, *filterlength ); + hrf_left[0] = ( SrcSpatial_p->Pos_p[1] + 1.f ) * 0.5f; + hrf_right[0] = 1.f - hrf_left[0]; + *intp_count = MAX_INTERPOLATION_STEPS; + Src_p->elev_prev = 0; + Src_p->azim_prev = 360.0f; /* Dummy angle -- sets max interpolation if switching to TDREND_POSTYPE_ABSOLUTE */ +} +#endif - if ( ( *intp_count > 0 ) && subframe_update_flag ) - { - /* Set deltas for interpolation */ - v_sub( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); - v_multc( hrf_left_delta, 1.0f / *intp_count, hrf_left_delta, *filterlength ); - v_sub( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); - v_multc( hrf_right_delta, 1.0f / *intp_count, hrf_right_delta, *filterlength ); - } - else - { - /* No interpolation, just set the new filters and reset deltas */ - mvr2r( hrf_left, hrf_left_prev, *filterlength ); - mvr2r( hrf_right, hrf_right_prev, *filterlength ); - set_f( hrf_left_delta, 0.0f, *filterlength ); - set_f( hrf_right_delta, 0.0f, *filterlength ); - } +if ( ( *intp_count > 0 ) && subframe_update_flag ) +{ + /* Set deltas for interpolation */ + v_sub( hrf_left, hrf_left_prev, hrf_left_delta, *filterlength ); + v_multc( hrf_left_delta, 1.0f / *intp_count, hrf_left_delta, *filterlength ); + v_sub( hrf_right, hrf_right_prev, hrf_right_delta, *filterlength ); + v_multc( hrf_right_delta, 1.0f / *intp_count, hrf_right_delta, *filterlength ); +} +else +{ + /* No interpolation, just set the new filters and reset deltas */ + mvr2r( hrf_left, hrf_left_prev, *filterlength ); + mvr2r( hrf_right, hrf_right_prev, *filterlength ); + set_f( hrf_left_delta, 0.0f, *filterlength ); + set_f( hrf_right_delta, 0.0f, *filterlength ); +} - return; +return; } @@ -675,8 +708,11 @@ void TDREND_SRC_Init( /* Reset memory buffers */ Src_p->itd = 0; Src_p->previtd = 0; +#ifdef FIX_550_FIRST_FRAME_ACCESS Src_p->filterlength = 1; /* Init to unit impulse of length 1 */ - +#else + Src_p->filterlength = -1; +#endif set_f( Src_p->mem_itd, 0.0f, ITD_MEM_LEN ); set_f( Src_p->mem_hrf_left, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); set_f( Src_p->mem_hrf_right, 0.0f, SFX_SPAT_BIN_MAX_FILTER_LENGTH - 1 ); @@ -687,7 +723,9 @@ void TDREND_SRC_Init( Src_p->hrf_right_prev[0] = 1; Src_p->azim_prev = 0.0f; Src_p->elev_prev = 0.0f; +#ifdef FIX_550_FIRST_FRAME_ACCESS Src_p->Gain = 1; +#endif Src_p->prevGain = 1.0f; return; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index f12c4597c8..b6045045a8 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -647,7 +647,9 @@ void GetFilterFromAngle( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, /* i/o: HR filter set structure */ const float Elev, /* i : Elevation, degrees */ float Azim, /* i : Azimuth, degrees */ +#ifdef FIX_569_TD_FILTER_LENGTH const int16_t filterlength, /* i : Filter length */ +#endif float *LeftFilter, /* o : Left HR filter */ float *RightFilter, /* o : Right HR filter */ int16_t *itd /* o : ITD value */ -- GitLab From 24966dbcd46d0fed8e0476fa5548a718ac5313f0 Mon Sep 17 00:00:00 2001 From: advasila Date: Mon, 31 Jul 2023 12:00:16 +0300 Subject: [PATCH 155/173] fix OMASA for MASA 1 TC --- lib_enc/ivas_enc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 429a18e0d2..4a54136079 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -298,6 +298,14 @@ ivas_error ivas_enc( flag_omasa_ener_brate = 0; + /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ + if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) + { + v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); + mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); + } + + /* Estimate TF-tile energy for the input MASA stream */ ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport ); @@ -306,13 +314,6 @@ ivas_error ivas_enc( return error; } - /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */ - if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 ) - { - v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame ); - mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame ); - } - set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); idx_separated_object = 0; -- GitLab From 6983ec746dba0d008db709fdbdbc2fec81910011 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 31 Jul 2023 18:17:17 +0200 Subject: [PATCH 156/173] properly exit when DTX operation is requested on the command-line --- lib_enc/ivas_init_enc.c | 5 ----- lib_enc/lib_enc.c | 6 +++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index b678125363..f3eada2892 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -178,11 +178,6 @@ void ivas_write_format_sid( ind = SID_MASA_2TC; } break; -#ifdef MASA_AND_OBJECTS - case MASA_ISM_FORMAT: /* TODO Nokia: Finalize for SID case */ - ind = 8; - break; -#endif default: assert( !"Reserved SID format symbol written." ); break; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 249d243fe6..1d80309090 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -941,7 +941,11 @@ static ivas_error configureEncoder( if ( hEncoderConfig->Opt_DTX_ON && hEncoderConfig->ivas_format != MONO_FORMAT && ( ( hEncoderConfig->ivas_format == SBA_FORMAT && ivas_get_sba_num_TCs( hEncoderConfig->ivas_total_brate, 1 ) > 2 ) || - hEncoderConfig->ivas_format == MC_FORMAT ) ) + hEncoderConfig->ivas_format == MC_FORMAT +#ifdef MASA_AND_OBJECTS + || hEncoderConfig->ivas_format == MASA_ISM_FORMAT +#endif + ) ) { return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." ); } -- GitLab From 2e84f606bfe778894af8258537c59009f468beb4 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 31 Jul 2023 18:33:17 +0200 Subject: [PATCH 157/173] replace a magic number by macro IVAS_BRATE_OMASA_STEREO_SW_THR --- lib_enc/ivas_stereo_td_analysis.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_stereo_td_analysis.c b/lib_enc/ivas_stereo_td_analysis.c index 8f86f25986..92bcd319d2 100644 --- a/lib_enc/ivas_stereo_td_analysis.c +++ b/lib_enc/ivas_stereo_td_analysis.c @@ -82,6 +82,10 @@ #define RMS_THR 100 #define RATIO_PG_LRTD 0.96f +#ifdef MASA_AND_OBJECTS +#define IVAS_BRATE_OMASA_STEREO_SW_THR 15000 +#endif + /*-------------------------------------------------------------------* * Local function prototypes @@ -202,7 +206,7 @@ int16_t stereo_tdm_ener_analysis( if ( ivas_format == MASA_ISM_FORMAT ) { - if ( ( hCPE->hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < 15000 ) ) + if ( ( hCPE->hStereoClassif->lrtd_mode == 1 || hCPE->hStereoTD->prev_fr_LRTD_TD_dec == 1 ) && ( hCPE->element_brate - 50 * FRAMES_PER_SEC + hCPE->brate_surplus + hCPE->brate_surplus < IVAS_BRATE_OMASA_STEREO_SW_THR ) ) { hStereoTD->prev_fr_LRTD_TD_dec = 0; } -- GitLab From e7a6d9e4b7bdd0d0acd77221e0d9970f55f77265 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 1 Aug 2023 10:49:28 +0200 Subject: [PATCH 158/173] remove outdated comments --- lib_dec/ivas_masa_dec.c | 4 ++-- lib_enc/ivas_init_enc.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index c63f4af93f..62b642f449 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -496,7 +496,7 @@ ivas_error ivas_masa_decode( int16_t block; int16_t meta_write_index; - for ( i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++ ) /* Todo Nokia: Probably there is a better place for this eventually */ + for ( i = 0; i < st_ivas->hSpatParamRendCom->numIsmDirections; i++ ) { for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -509,6 +509,7 @@ ivas_error ivas_masa_decode( } } } + for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; @@ -2235,7 +2236,6 @@ static void decode_ism_ratios( /* save previous subframe index values */ if ( sf < numSf - 1 ) { - /* Todo Nokia: can be moved to the read_ism_ratio ... function */ for ( band = 0; band < nbands; band++ ) { mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], n_ism ); diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index f3eada2892..330046a5cd 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -528,7 +528,7 @@ ivas_error ivas_init_encoder( } } - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { @@ -707,7 +707,7 @@ ivas_error ivas_init_encoder( return error; } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK ) { @@ -746,7 +746,7 @@ ivas_error ivas_init_encoder( ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); - for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) // VE: TBV - is this loop needed? + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK ) { @@ -754,7 +754,7 @@ ivas_error ivas_init_encoder( } } - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) // VE: TBV - is this loop needed? + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; -- GitLab From 44fdd16d51e5cefc0d282ee0d96c4f6c746597c2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 1 Aug 2023 11:48:46 +0200 Subject: [PATCH 159/173] address todo: introduce handle 'hOmasaData' --- lib_com/ivas_cnst.h | 2 +- lib_enc/ivas_cpe_enc.c | 8 +-- lib_enc/ivas_ism_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 131 +++++++++++++++++++++++---------------- lib_enc/ivas_omasa_enc.c | 48 +++++++------- lib_enc/ivas_sce_enc.c | 2 +- lib_enc/ivas_stat_enc.h | 106 ++++++++++++++++--------------- 7 files changed, 164 insertions(+), 135 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index d19c779269..ad50e34a72 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1270,13 +1270,13 @@ enum #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ #ifdef MASA_AND_OBJECTS #define OMASA_STEREO_SW_CNT_MAX 100 -#define OMASA_STEREO_SW_CNT_MAX2 5 #endif #endif #define MASA_BIT_REDUCT_PARAM 10 #define MASA_MAXIMUM_TWO_DIR_BANDS 24 #define NBITS_HR_COH 4 + typedef enum { MASA_STEREO_NOT_DEFINED, diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index e45949bbb2..2d7c49c781 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -1230,15 +1230,15 @@ static void stereo_mode_combined_format_enc( { if ( hCPE->element_brate + hCPE->brate_surplus > IVAS_64k ) { - st_ivas->hMasa->data.omasa_stereo_sw_cnt = 0; + st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = 0; } else { - st_ivas->hMasa->data.omasa_stereo_sw_cnt++; - st_ivas->hMasa->data.omasa_stereo_sw_cnt = min( st_ivas->hMasa->data.omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); + st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt++; + st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt = min( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt, OMASA_STEREO_SW_CNT_MAX ); } - if ( st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + if ( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) { hCPE->element_mode = IVAS_CPE_MDCT; hCPE->element_brate = IVAS_64k; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 472ff1a642..6dbc40f1b4 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -273,7 +273,7 @@ ivas_error ivas_ism_enc( ism_total_brate_ref = ism_total_brate; ivas_ism_metadata_enc( &ism_total_brate, nchan_ism, nchan_transport_ism, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData, - nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.omasa_stereo_sw_cnt ) : NULL ); + nb_bits_metadata, vad_flag, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, st_ivas->hMasa != NULL ? st_ivas->hMasa->data.hOmasaData->lp_noise_CPE : 0, flag_omasa_ener_brate, st_ivas->hMasa != NULL ? &( st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt ) : NULL ); if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index d86b52e9b5..6b2db322ca 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -61,7 +61,7 @@ static void compensate_energy_ratios( MASA_ENCODER_HANDLE hMasa ); static int16_t encode_lfe_to_total_energy_ratio( MASA_ENCODER_HANDLE hMasa, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate ); #ifdef MASA_AND_OBJECTS -static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); +static void ivas_encode_masaism_metadata( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, ISM_METADATA_HANDLE hIsmMeta[], const int16_t nchan_ism, const int16_t low_bitrate_mode, const int16_t omasa_nbands, const int16_t omasa_nblocks, const int16_t idx_separated_object, const int16_t ism_imp ); static void reduce_metadata_further( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hqmetadata, const IVAS_FORMAT ivas_format ); #else @@ -180,9 +180,24 @@ ivas_error ivas_masa_enc_open( set_zero( hMasa->data.dir_align_state.previous_ele_dir2, MASA_FREQUENCY_BANDS ); #ifdef MASA_AND_OBJECTS - hMasa->data.lp_noise_CPE = -1; - hMasa->data.omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; - hMasa->data.omasa_stereo_sw_cnt2 = OMASA_STEREO_SW_CNT_MAX2; + if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) + { + OMASA_ENCODER_DATA_HANDLE hOmasaData; + + if ( ( hOmasaData = (OMASA_ENCODER_DATA_HANDLE) malloc( sizeof( OMASA_ENCODER_DATA_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA data encoder\n" ) ); + } + + hOmasaData->lp_noise_CPE = -1; + hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; + + hMasa->data.hOmasaData = hOmasaData; + } + else + { + hMasa->data.hOmasaData = NULL; + } #endif st_ivas->hMasa = hMasa; @@ -213,6 +228,14 @@ void ivas_masa_enc_close( deleteCldfb( &( ( *hMasa )->data.cldfbAnaEnc[i] ) ); } +#ifdef MASA_AND_OBJECTS + if ( ( *hMasa )->data.hOmasaData == NULL ) + { + free( ( *hMasa )->data.hOmasaData ); + ( *hMasa )->data.hOmasaData = NULL; + } +#endif + free( ( *hMasa ) ); ( *hMasa ) = NULL; @@ -238,14 +261,13 @@ ivas_error ivas_masa_encode( const int16_t element_mode /* i : element mode */ #ifdef MASA_AND_OBJECTS , - const ISM_MODE ism_mode, /* i : ISM format mode */ - const int16_t nchan_ism, /* i : number of ISM channels */ - ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ - const int16_t idx_separated_object, /* i : index of the separated object */ - OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ - const int16_t ism_imp /* i : importance of separated object */ - , - const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const int16_t ism_imp, /* i : importance of separated object */ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ #endif ) { @@ -362,7 +384,7 @@ ivas_error ivas_masa_encode( hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; /* write index of separated object if needed */ - if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && hMasa->data.nchan_ism > 1 ) + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && nchan_ism > 1 ) { push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; @@ -528,7 +550,7 @@ ivas_error ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* encode MASA/ISM energy ratios */ - ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); } else @@ -969,13 +991,13 @@ ivas_error ivas_masa_enc_config( #ifdef MASA_AND_OBJECTS if ( ivas_format == MASA_ISM_FORMAT && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { - if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) + if ( st_ivas->hCPE[0]->element_mode == IVAS_CPE_DFT || st_ivas->hMasa->data.hOmasaData->omasa_stereo_sw_cnt < OMASA_STEREO_SW_CNT_MAX ) { - st_ivas->hMasa->data.lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise; } else { - st_ivas->hMasa->data.lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; + st_ivas->hMasa->data.hOmasaData->lp_noise_CPE = ( st_ivas->hCPE[0]->hCoreCoder[0]->lp_noise + st_ivas->hCPE[0]->hCoreCoder[1]->lp_noise ) / CPE_CHANNELS; } } #endif @@ -2728,7 +2750,6 @@ void ivas_merge_masa_metadata( numSf = hMasa->config.joinedSubframes == TRUE ? 1 : 4; hMeta = &( hMasa->masaMetadata ); - for ( sf = 0; sf < numSf; sf++ ) { for ( band = 0; band < numCodingBands; band++ ) @@ -2755,7 +2776,7 @@ void ivas_merge_masa_metadata( { eneBand += hMasa->data.energy[sf][bin]; } - energyMerged[sf][band] = eneBand + hMasa->data.energy_ism[sf][band]; + energyMerged[sf][band] = eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]; /* Compute weights */ energyTimesRatioMASA[0] = eneBand * hMeta->directional_meta[0].energy_ratio[sf][band]; @@ -2770,7 +2791,7 @@ void ivas_merge_masa_metadata( /* target is original MASA diffuseness */ total_diff_nrg = eneBand * hMeta->common_meta.diffuse_to_total_ratio[sf][band]; /* criterion is mean of ISM ratio and new ratio */ - energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.energy_ism[sf][band]; + energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band]; /* Determine combined metadata based on the weights */ merge_dest = -1; @@ -2791,7 +2812,7 @@ void ivas_merge_masa_metadata( hMeta->directional_meta[merge_dest].azimuth[sf][band] = hOMasaMeta->directional_meta[0].azimuth[sf][band]; hMeta->directional_meta[merge_dest].elevation[sf][band] = hOMasaMeta->directional_meta[0].elevation[sf][band]; /* limit with the earlier direct-energy ratio */ - dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.energy_ism[sf][band] ); /* new dir ratio */ + dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ); /* new dir ratio */ hMeta->directional_meta[merge_dest].energy_ratio[sf][band] = min( dir_sum, hOMasaMeta->directional_meta[0].energy_ratio[sf][band] ); /* clip with original ISM dir */ hMeta->common_meta.diffuse_to_total_ratio[sf][band] = 1.0f - hMeta->directional_meta[merge_dest].energy_ratio[sf][band]; @@ -3475,6 +3496,7 @@ static void ivas_encode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t nchan_ism, /* i : number of ISM channels */ const int16_t low_bitrate_mode, /* i : is low bitrate more? 1/0 */ const int16_t omasa_nbands, const int16_t omasa_nblocks, @@ -3499,7 +3521,7 @@ static void ivas_encode_masaism_metadata( float energy_ism, energy_ism_ind[MAX_NUM_OBJECTS]; int16_t tmp, rotate; int16_t n_ism_tmp, i; - + OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; @@ -3511,7 +3533,7 @@ static void ivas_encode_masaism_metadata( for ( sf = 0; sf < numSf; sf++ ) { - if ( sum_f( hMasa->data.energy_ism[sf], omasa_nbands ) == 0.0f ) + if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) { hQMetaData->masa_to_total_energy_ratio[sf][0] = 1.0f; } @@ -3526,23 +3548,23 @@ static void ivas_encode_masaism_metadata( } energy_ism = 0.0f; - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { energy_ism_ind[obj] = 0.0f; } for ( band = 0; band < omasa_nbands; band++ ) { - energy_ism += hMasa->data.energy_ism[sf][band]; - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + energy_ism += hOmasaData->energy_ism[sf][band]; + for ( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] += hMasa->data.energy_ism[sf][band] * hMasa->data.energy_ratio_ism[sf][band][obj]; + energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; } } - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { - hMasa->data.energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; + hOmasaData->energy_ratio_ism[sf][0][obj] = energy_ism_ind[obj] / energy_ism; } hQMetaData->masa_to_total_energy_ratio[sf][0] = eneBand / ( eneBand + energy_ism + EPSILON ); } @@ -3555,16 +3577,16 @@ static void ivas_encode_masaism_metadata( for ( band = 0; band < numCodingBands; band++ ) { energy_ism = 0.0f; /* ISM energy for current subband */ - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { energy_ism_ind[obj] = 0.0f; } for ( sf = 0; sf < omasa_nblocks; sf++ ) { - energy_ism += hMasa->data.energy_ism[sf][band]; - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + energy_ism += hOmasaData->energy_ism[sf][band]; + for ( obj = 0; obj < nchan_ism; obj++ ) { - energy_ism_ind[obj] += hMasa->data.energy_ism[sf][band] * hMasa->data.energy_ratio_ism[sf][band][obj]; + energy_ism_ind[obj] += hOmasaData->energy_ism[sf][band] * hOmasaData->energy_ratio_ism[sf][band][obj]; } } @@ -3574,9 +3596,9 @@ static void ivas_encode_masaism_metadata( } else { - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { - hMasa->data.energy_ratio_ism[0][band][obj] = energy_ism_ind[obj] / energy_ism; + hOmasaData->energy_ratio_ism[0][band][obj] = energy_ism_ind[obj] / energy_ism; } brange[0] = hMasa->data.band_mapping[band]; brange[1] = hMasa->data.band_mapping[band + 1]; @@ -3599,7 +3621,7 @@ static void ivas_encode_masaism_metadata( { for ( band = 0; band < numCodingBands; band++ ) { - if ( hMasa->data.energy_ism[sf][band] == 0.0f ) + if ( hOmasaData->energy_ism[sf][band] == 0.0f ) { hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; } @@ -3613,7 +3635,7 @@ static void ivas_encode_masaism_metadata( { eneBand += hMasa->data.energy[sf][bin]; } - hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hMasa->data.energy_ism[sf][band] + EPSILON ); + hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); } } } @@ -3622,7 +3644,7 @@ static void ivas_encode_masaism_metadata( encode_masa_to_total( hQMetaData, hMetaData, low_bitrate_mode, numCodingBands, numSf ); /* quantize ism_ratios */ - if ( hMasa->data.nchan_ism > 1 ) + if ( nchan_ism > 1 ) { inv_step = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); step = 1.0f / inv_step; @@ -3634,14 +3656,14 @@ static void ivas_encode_masaism_metadata( { for ( band = 0; band < numCodingBands; band++ ) { - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { - assert( ( hMasa->data.energy_ratio_ism[sf][band][obj] >= 0 ) && ( hMasa->data.energy_ratio_ism[sf][band][obj] <= 1 ) ); - ratio_ism[band][obj] = hMasa->data.energy_ratio_ism[sf][band][obj]; + assert( ( hOmasaData->energy_ratio_ism[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism[sf][band][obj] <= 1 ) ); + ratio_ism[band][obj] = hOmasaData->energy_ratio_ism[sf][band][obj]; } /* Quantize ISM ratios */ - quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], hMasa->data.nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); + quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { @@ -3654,7 +3676,7 @@ static void ivas_encode_masaism_metadata( ratio_ism_idx[band][idx_separated_object]--; } i++; - if ( i == hMasa->data.nchan_ism ) + if ( i == nchan_ism ) { i = 0; } @@ -3662,11 +3684,10 @@ static void ivas_encode_masaism_metadata( } /* reconstructed values */ - reconstruct_ism_ratios( ratio_ism_idx[band], hMasa->data.nchan_ism, step, hMasa->data.q_energy_ratio_ism[sf][band] ); - /* encode vector */ + reconstruct_ism_ratios( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band] ); } - if ( ( hMasa->data.nchan_ism > 2 ) && ( idx_separated_object == hMasa->data.nchan_ism - 1 ) ) + if ( ( nchan_ism > 2 ) && ( idx_separated_object == nchan_ism - 1 ) ) { /* rotate components */ rotate = 1; @@ -3674,8 +3695,8 @@ static void ivas_encode_masaism_metadata( { if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { - tmp = ratio_ism_idx[band][hMasa->data.nchan_ism - 1]; - ratio_ism_idx[band][hMasa->data.nchan_ism - 1] = ratio_ism_idx[band][0]; + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; ratio_ism_idx[band][0] = tmp; if ( sf == 0 && tmp == 0 ) { @@ -3709,18 +3730,18 @@ static void ivas_encode_masaism_metadata( /* encode data for current subframe */ if ( sf > 0 && n_ism_tmp == numCodingBands ) { - encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 1, idx_separated_object ); } else { - encode_ratio_ism_subframe( ratio_ism_idx, hMasa->data.nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); + encode_ratio_ism_subframe( ratio_ism_idx, nchan_ism, numCodingBands, sf, ratio_ism_idx_prev_sf, hMetaData, hQMetaData->masa_to_total_energy_ratio[sf], 0, idx_separated_object ); } /* calculate quantized ISM ratios */ /* save previous subframe indexes */ for ( band = 0; band < numCodingBands; band++ ) { - mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], hMasa->data.nchan_ism ); + mvs2s( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], nchan_ism ); } if ( rotate ) @@ -3729,8 +3750,8 @@ static void ivas_encode_masaism_metadata( { if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { - tmp = ratio_ism_idx[band][hMasa->data.nchan_ism - 1]; - ratio_ism_idx[band][hMasa->data.nchan_ism - 1] = ratio_ism_idx[band][0]; + tmp = ratio_ism_idx[band][nchan_ism - 1]; + ratio_ism_idx[band][nchan_ism - 1] = ratio_ism_idx[band][0]; ratio_ism_idx[band][0] = tmp; } } @@ -3738,10 +3759,10 @@ static void ivas_encode_masaism_metadata( } } - calculate_nbits_meta( hMasa->data.nchan_ism, hMasa->data.q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); + calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hQMetaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); /* quantize directions */ - for ( obj = 0; obj < hMasa->data.nchan_ism; obj++ ) + for ( obj = 0; obj < nchan_ism; obj++ ) { if ( bits_ism[obj] < 8 ) { diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 503eeb4732..72a10f7675 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -50,9 +50,9 @@ * Local function prototypes *------------------------------------------------------------------------*/ -static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], float diffuseness_m[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); +static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float energyRatio[MASA_FREQUENCY_BANDS], float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float surroundingCoherence[MASA_FREQUENCY_BANDS], float diffuseness_m[MASA_FREQUENCY_BANDS], const int16_t input_frame, const int16_t nchan_inp ); -static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, MASA_ENCODER_HANDLE hMasa, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); +static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, float data_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_inp ); static void ivas_omasa_dmx( float data_in_f[][L_FRAME48k], float data_out_f[][L_FRAME48k], const int16_t input_frame, const int16_t nchan_transport, const int16_t nchan_ism, ISM_METADATA_HANDLE hIsmMeta[], float prev_gains[][MASA_MAX_TRANSPORT_CHANNELS], const float interpolator[L_FRAME48k] ); @@ -80,7 +80,7 @@ ivas_error ivas_omasa_enc_open( assert( st_ivas->hMasa != NULL && "MASA encoder handle is not present" ); - if ( ( hOMasa = (OMASA_ENC_HANDLE) malloc( sizeof( OMASA_ENC_DATA ) ) ) == NULL ) + if ( ( hOMasa = (OMASA_ENC_HANDLE) malloc( sizeof( OMASA_ENC_STATE ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA encoder\n" ) ); } @@ -538,7 +538,7 @@ void ivas_omasa_enc( /* Estimate MASA parameters from the objects */ /* NB: only first direction is populated */ /* NB2: in energy_ratios and surround_coherence only first sub-frame contains valid data */ - ivas_omasa_param_est_enc( hOMasa, hMasa, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], + ivas_omasa_param_est_enc( hOMasa, hMasa->data.hOmasaData, hIsmMeta, data_in_f, hOMasaMeta->directional_meta[0].elevation, hOMasaMeta->directional_meta[0].azimuth, hOMasaMeta->directional_meta[0].energy_ratio[0], hOMasaMeta->directional_meta[0].spread_coherence, hOMasaMeta->common_meta.surround_coherence[0], hOMasaMeta->common_meta.diffuse_to_total_ratio[0], input_frame, nchan_ism ); /* copy energy_ratios and surrCoh from first sub-frame to the remaining ones */ @@ -567,7 +567,7 @@ void ivas_omasa_enc( else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* Estimate energies and ratios */ - ivas_omasa_energy_and_ratio_est( hOMasa, hMasa, data_in_f, input_frame, nchan_ism ); + ivas_omasa_energy_and_ratio_est( hOMasa, hMasa->data.hOmasaData, data_in_f, input_frame, nchan_ism ); } /* Move the ISM metadata to the first entry for encoding in the MASA_ONE_OBJ mode */ @@ -763,7 +763,7 @@ int16_t ivas_omasa_ener_brate( /* Estimate MASA parameters from the objects */ static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, - MASA_ENCODER_HANDLE hMasa, + OMASA_ENCODER_DATA_HANDLE hOmasaData, ISM_METADATA_HANDLE hIsmMeta[], float data_f[][L_FRAME48k], float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], @@ -822,7 +822,7 @@ static void ivas_omasa_param_est_enc( hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = 0.0f; } - set_zero( hMasa->data.energy_ism[block_m_idx], num_freq_bands ); + set_zero( hOmasaData->energy_ism[block_m_idx], num_freq_bands ); for ( ts = mrange[0]; ts < mrange[1]; ts++ ) { @@ -840,7 +840,7 @@ static void ivas_omasa_param_est_enc( { for ( k = 0; k < nchan_ism; k++ ) { - hMasa->data.energy_ism[block_m_idx][i] += Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; + hOmasaData->energy_ism[block_m_idx][i] += Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; } } } @@ -920,8 +920,10 @@ static void ivas_omasa_param_est_enc( { dir_v[d] = hOMasa->direction_vector_m[d][block_m_idx][band_m_idx]; } + ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); } + /* Set coherences to zero, as this mode is used at lowest bit rates where the coherences are not transmitted */ for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { @@ -952,10 +954,10 @@ static void ivas_omasa_param_est_enc( /* Estimate energies and ratios */ static void ivas_omasa_energy_and_ratio_est( OMASA_ENC_HANDLE hOMasa, - MASA_ENCODER_HANDLE hMasa, + OMASA_ENCODER_DATA_HANDLE hOmasaData, float data_f[][L_FRAME48k], const int16_t input_frame, - const int16_t nchan_inp ) + const int16_t nchan_ism ) { int16_t ts, i, j, k; int16_t num_freq_bands; @@ -979,14 +981,14 @@ static void ivas_omasa_energy_and_ratio_est( /* Reset variable */ for ( i = 0; i < hOMasa->nbands; i++ ) { - set_zero( hMasa->data.energy_ratio_ism[block_m_idx][i], nchan_inp ); + set_zero( hOmasaData->energy_ratio_ism[block_m_idx][i], nchan_ism ); } - set_zero( hMasa->data.energy_ism[block_m_idx], num_freq_bands ); + set_zero( hOmasaData->energy_ism[block_m_idx], num_freq_bands ); /* Compute CLDFB */ for ( ts = mrange[0]; ts < mrange[1]; ts++ ) { - for ( i = 0; i < nchan_inp; i++ ) + for ( i = 0; i < nchan_ism; i++ ) { cldfbAnalysis_ts( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); } @@ -998,11 +1000,11 @@ static void ivas_omasa_energy_and_ratio_est( brange[1] = hOMasa->band_grouping[i + 1]; for ( j = brange[0]; j < brange[1]; j++ ) { - for ( k = 0; k < nchan_inp; k++ ) + for ( k = 0; k < nchan_ism; k++ ) { tftile_energy = Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; - hMasa->data.energy_ism[block_m_idx][i] += tftile_energy; - hMasa->data.energy_ratio_ism[block_m_idx][i][k] += tftile_energy; + hOmasaData->energy_ism[block_m_idx][i] += tftile_energy; + hOmasaData->energy_ratio_ism[block_m_idx][i][k] += tftile_energy; } } } @@ -1012,22 +1014,21 @@ static void ivas_omasa_energy_and_ratio_est( for ( i = 0; i < num_freq_bands; i++ ) { ism_ratio_sum = 0.0f; - for ( j = 0; j < nchan_inp; j++ ) + for ( j = 0; j < nchan_ism; j++ ) { - hMasa->data.energy_ratio_ism[block_m_idx][i][j] /= ( hMasa->data.energy_ism[block_m_idx][i] + EPSILON ); - ism_ratio_sum += hMasa->data.energy_ratio_ism[block_m_idx][i][j]; + hOmasaData->energy_ratio_ism[block_m_idx][i][j] /= ( hOmasaData->energy_ism[block_m_idx][i] + EPSILON ); + ism_ratio_sum += hOmasaData->energy_ratio_ism[block_m_idx][i][j]; } if ( ism_ratio_sum == 0.0f ) { - float temp_ism_ratio = 1.0f / ( (float) nchan_inp ); - for ( j = 0; j < nchan_inp; j++ ) + float temp_ism_ratio = 1.0f / ( (float) nchan_ism ); + for ( j = 0; j < nchan_ism; j++ ) { - hMasa->data.energy_ratio_ism[block_m_idx][i][j] = temp_ism_ratio; + hOmasaData->energy_ratio_ism[block_m_idx][i][j] = temp_ism_ratio; } } } - hMasa->data.nchan_ism = nchan_inp; } return; @@ -1050,7 +1051,6 @@ static void ivas_omasa_dmx( float gains[MASA_MAX_TRANSPORT_CHANNELS]; float g1, g2; - for ( i = 0; i < nchan_transport; i++ ) { set_zero( data_out_f[i], input_frame ); diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 07ba653dcd..2193c892fb 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -217,7 +217,7 @@ ivas_error ivas_sce_enc( if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); + set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; } diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3e280d6efb..d5aec62a0d 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -753,6 +753,59 @@ typedef struct ivas_mc_paramupmix_enc_data_structure } MC_PARAMUPMIX_ENC_DATA, *MC_PARAMUPMIX_ENC_HANDLE; + +#ifdef MASA_AND_OBJECTS +/*----------------------------------------------------------------------------------* + * Object MASA (OMASA) encoder structure + *----------------------------------------------------------------------------------*/ + +typedef struct ivas_omasa_enc_state_structure +{ + uint8_t nbands; + uint8_t nCodingBands; + uint8_t nSubframes; + + /* CLDFB analysis */ + int16_t num_Cldfb_instances; + HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; + + /* DirAC parameter estimation */ + float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ + int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; + int16_t block_grouping[5]; + + /* diffuseness */ + int16_t index_buffer_intensity; + float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; + float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; + + float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; + + float interpolator[L_FRAME48k]; + + float prev_object_dm_gains[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; + float broadband_energy_sm[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + float broadband_energy_prev[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; + int16_t prev_selected_object; + uint8_t changing_object; + float fade_out_gain[L_FRAME48k]; + float fade_in_gain[L_FRAME48k]; + +} OMASA_ENC_STATE, *OMASA_ENC_HANDLE; + + +typedef struct ivas_omasa_encoder_one_data_struct +{ + float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: Make an own MASAISM struct for these, and reserve it only for OMASA */ + float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + float lp_noise_CPE; /* LP filterend total noise estimation */ + int16_t omasa_stereo_sw_cnt; + +} OMASA_ENCODER_DATA_STATE, *OMASA_ENCODER_DATA_HANDLE; +#endif + + /*----------------------------------------------------------------------------------* * MASA encoder structures *----------------------------------------------------------------------------------*/ @@ -780,15 +833,6 @@ typedef struct ivas_masa_sync_struct typedef struct ivas_masa_encoder_data_struct { float energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; -#ifdef MASA_AND_OBJECTS - float energy_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* TODO Nokia: Make an own MASAISM struct for these, and reserve it only for OMASA */ - float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; - int16_t nchan_ism; - float lp_noise_CPE; /* LP filterend total noise estimation */ - int16_t omasa_stereo_sw_cnt; - int16_t omasa_stereo_sw_cnt2; -#endif int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_ENC_CLDFB_INSTANCES]; @@ -807,6 +851,10 @@ typedef struct ivas_masa_encoder_data_struct MASA_DIR_ALIGN_STATE dir_align_state; +#ifdef MASA_AND_OBJECTS + OMASA_ENCODER_DATA_HANDLE hOmasaData; +#endif + } MASA_ENCODER_DATA; typedef struct ivas_masa_encoder_struct @@ -876,46 +924,6 @@ typedef struct ivas_mcmasa_enc_data_structure } MCMASA_ENC_DATA, *MCMASA_ENC_HANDLE; -#ifdef MASA_AND_OBJECTS -/*----------------------------------------------------------------------------------* - * Object MASA (OMASA) encoder structure - *----------------------------------------------------------------------------------*/ - -typedef struct ivas_omasa_enc_data_structure -{ - uint8_t nbands; - uint8_t nCodingBands; - uint8_t nSubframes; - - /* CLDFB analysis */ - int16_t num_Cldfb_instances; - HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MAX_NUM_OBJECTS]; - - /* DirAC parameter estimation */ - float **direction_vector_m[DIRAC_NUM_DIMS]; /* Average direction vector */ - int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; - int16_t block_grouping[5]; - - /* diffuseness */ - int16_t index_buffer_intensity; - float *buffer_intensity_real[DIRAC_NUM_DIMS][DIRAC_NO_COL_AVG_DIFF]; - float buffer_energy[DIRAC_NO_COL_AVG_DIFF * MASA_FREQUENCY_BANDS]; - - float chnlToFoaMtx[DIRAC_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; - - float interpolator[L_FRAME48k]; - - float prev_object_dm_gains[MAX_NUM_OBJECTS][MASA_MAX_TRANSPORT_CHANNELS]; - float broadband_energy_sm[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - float broadband_energy_prev[MAX_NUM_OBJECTS + MASA_MAX_TRANSPORT_CHANNELS]; - int16_t prev_selected_object; - uint8_t changing_object; - float fade_out_gain[L_FRAME48k]; - float fade_in_gain[L_FRAME48k]; - -} OMASA_ENC_DATA, *OMASA_ENC_HANDLE; -#endif - /*----------------------------------------------------------------------------------* * Stereo CNG handle -- GitLab From b30035cdb02eb707e40bbccac3fcb1006db456c5 Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 1 Aug 2023 12:52:35 +0300 Subject: [PATCH 160/173] remove EDIT_ISM and correct the nr of indices --- apps/decoder.c | 58 +-------------------------------------------- lib_com/bitstream.c | 14 +++++------ lib_com/options.h | 4 +--- lib_dec/lib_dec.c | 28 ---------------------- lib_dec/lib_dec.h | 8 ------- 5 files changed, 9 insertions(+), 103 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index cb39dd0f1e..1796a9be97 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -156,12 +156,6 @@ typedef struct uint16_t frontendFetchSizeMs; #endif #endif -#ifdef MASAISM_EDIT_OBJECTS - bool editing_ism_enabled; - int16_t index_of_edited_ism; - int16_t azimuth_edited_ism; - int16_t elevation_edited_ism; -#endif } DecArguments; @@ -684,16 +678,6 @@ int main( } } -#ifdef MASAISM_EDIT_OBJECTS - /*------------------------------------------------------------------------------------------* - * Set edited object positions - *------------------------------------------------------------------------------------------*/ - - if ( arg.editing_ism_enabled ) - { - IVAS_DEC_SetEditedIsmPositions( hIvasDec, arg.index_of_edited_ism, arg.azimuth_edited_ism, arg.elevation_edited_ism ); - } -#endif /*-----------------------------------------------------------------* * Decoding @@ -911,9 +895,7 @@ static bool parseCmdlIVAS_dec( { int16_t i; char argv_to_upper[FILENAME_MAX]; -#ifdef MASAISM_EDIT_OBJECTS - int32_t tmp1; -#endif + #ifdef DEBUGGING float ftmp; @@ -983,12 +965,6 @@ static bool parseCmdlIVAS_dec( #endif #endif -#ifdef MASAISM_EDIT_OBJECTS - arg->editing_ism_enabled = false; - arg->index_of_edited_ism = 0; - arg->azimuth_edited_ism = 0; - arg->elevation_edited_ism = 0; -#endif /*-----------------------------------------------------------------* * Initialization @@ -1351,38 +1327,6 @@ static bool parseCmdlIVAS_dec( } } -#ifdef MASAISM_EDIT_OBJECTS - else if ( strcmp( argv_to_upper, "-EDIT_ISM" ) == 0 ) /* Edit ISM position: objectID, azimuth (deg), elevation (deg) */ - { - arg->editing_ism_enabled = true; - i++; - - if ( argc - i <= 6 || argv[i][0] == '-' ) - { - fprintf( stderr, "Error: Edited ISM position parameters not defined! \n\n" ); - usage_dec(); - return false; - } - - if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) - { - arg->index_of_edited_ism = (int16_t) tmp1; - i++; - } - - if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) - { - arg->azimuth_edited_ism = (int16_t) tmp1; - i++; - } - - if ( sscanf( argv[i], "%d", &tmp1 ) > 0 ) - { - arg->elevation_edited_ism = (int16_t) tmp1; - i++; - } - } -#endif /*-----------------------------------------------------------------* * Option not recognized diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 604ddc2b96..e69240d1fe 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -545,31 +545,31 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_48k ) { - return 650; + return 750; } else if ( ivas_total_brate <= IVAS_80k ) { - return 750; + return 950; } else if ( ivas_total_brate <= IVAS_160k ) { - return 850; + return 1150; } else if ( ivas_total_brate <= IVAS_192k ) { - return 950; + return 1250; } else if ( ivas_total_brate <= IVAS_256k ) { - return 1300; + return 1400; } else if ( ivas_total_brate <= IVAS_384k ) { - return 1450; + return 1650; } else { - return 1650; + return 1850; } } #endif diff --git a/lib_com/options.h b/lib_com/options.h index 6043962403..26c638e283 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -207,9 +207,7 @@ #define FIX_549_PARAM_ISM_BIN_GAIN /* FhG: Issue 549 : fix too quiet binaural output in ParamISM */ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ -#ifdef MASA_AND_OBJECTS -#define MASAISM_EDIT_OBJECTS /* Nokia: Temporary command line editing of object directions in the decoder */ -#endif + /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 64a3a2b2af..1d608cc6f4 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1447,34 +1447,6 @@ ivas_error IVAS_DEC_GetHrtfCRendHandle( } -#ifdef MASAISM_EDIT_OBJECTS -/*---------------------------------------------------------------------* - * IVAS_DEC_SetEditedIsmPositions( ) - * - * - *---------------------------------------------------------------------*/ - -ivas_error IVAS_DEC_SetEditedIsmPositions( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t index_of_edited_ism, /* i : Index of edited ISM */ - int16_t azimuth_edited_ism, /* i : Azimuth */ - int16_t elevation_edited_ism /* i : Elevation */ -) -{ - if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) - { - return IVAS_ERR_UNEXPECTED_NULL_POINTER; - } - - hIvasDec->st_ivas->editing_ism_enabled = 1; - hIvasDec->st_ivas->index_of_edited_ism = index_of_edited_ism; - hIvasDec->st_ivas->azimuth_edited = azimuth_edited_ism; - hIvasDec->st_ivas->elevation_edited = elevation_edited_ism; - - return IVAS_ERR_OK; -} -#endif - /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfFastConvHandle( ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 52155ec89e..0444037351 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -370,14 +370,6 @@ ivas_error IVAS_DEC_GetHrtfParamBinHandle( IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin /* o : Parametric binauralizer HRTF handle */ ); -#ifdef MASAISM_EDIT_OBJECTS -ivas_error IVAS_DEC_SetEditedIsmPositions( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - int16_t index_of_edited_ism, /* i : Index of edited ISM */ - int16_t azimuth_edited_ism, /* i : Azimuth */ - int16_t elevation_edited_ism /* i : Elevation */ -); -#endif /*! r: error code*/ ivas_error IVAS_DEC_GetRenderConfig( -- GitLab From 0f1d92138d175c9bbf9b72d8b5287971730f2a77 Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 1 Aug 2023 13:23:05 +0300 Subject: [PATCH 161/173] fix clang --- lib_com/bitstream.c | 4 ++-- lib_dec/lib_dec.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index e69240d1fe..940d8ff59a 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -545,11 +545,11 @@ int16_t get_ivas_max_num_indices( } else if ( ivas_total_brate <= IVAS_48k ) { - return 750; + return 650; } else if ( ivas_total_brate <= IVAS_80k ) { - return 950; + return 750; } else if ( ivas_total_brate <= IVAS_160k ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 1d608cc6f4..8458bb867a 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1447,7 +1447,6 @@ ivas_error IVAS_DEC_GetHrtfCRendHandle( } - /*---------------------------------------------------------------------* * IVAS_DEC_GetHrtfFastConvHandle( ) * -- GitLab From e7d355e1c7f9fcaae9d2e8e04bef925f38994f23 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 1 Aug 2023 12:40:39 +0200 Subject: [PATCH 162/173] formatting --- lib_com/ivas_prot.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 3080698450..827638d213 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5619,7 +5619,7 @@ void ivas_filter_process( *---------------------------------------------------------------------------------*/ ivas_error ivas_omasa_enc_open( - Encoder_Struct* st_ivas /* i/o: IVAS encoder handle */ + Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); void ivas_omasa_enc_close( @@ -5723,7 +5723,7 @@ void ivas_merge_masa_transports( ); ivas_error ivas_masa_ism_data_open( - Decoder_Struct* st_ivas /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); void ivas_masa_ism_data_close( @@ -5760,15 +5760,15 @@ void preProcessStereoTransportsForMovedObjects( ); ivas_error ivas_masa_ism_separate_object_renderer_open( - Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_masa_ism_separate_object_renderer_close( - Decoder_Struct* st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_masa_ism_separate_object_render( - Decoder_Struct* st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float input_f[][L_FRAME48k], /* i : separated object signal */ float output_f[][L_FRAME48k], /* i/o: output signals */ const int16_t output_frame /* i : output frame length per channel */ @@ -5787,8 +5787,8 @@ void encode_masa_to_total( ); void decode_masa_to_total( - uint16_t* bit_stream, - int16_t* index, + uint16_t *bit_stream, + int16_t *index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const int16_t nbands, const int16_t nblocks -- GitLab From 64200ac089a09035d6bcb113d1c859febd1e964e Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 13:59:22 +0200 Subject: [PATCH 163/173] fix memory leak of the newly introduced hOmasaData handle --- lib_enc/ivas_masa_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6b2db322ca..5e5fcc672f 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -229,7 +229,7 @@ void ivas_masa_enc_close( } #ifdef MASA_AND_OBJECTS - if ( ( *hMasa )->data.hOmasaData == NULL ) + if ( ( *hMasa )->data.hOmasaData != NULL ) { free( ( *hMasa )->data.hOmasaData ); ( *hMasa )->data.hOmasaData = NULL; -- GitLab From 4588f712d995b34eb8a7a15c92fc5b866683bfac Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 1 Aug 2023 14:23:04 +0200 Subject: [PATCH 164/173] harmonize OMASA function names --- lib_com/ivas_masa_com.c | 6 ++--- lib_com/ivas_prot.h | 28 +++++++++----------- lib_dec/ivas_dec.c | 2 +- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_init_dec.c | 10 +++---- lib_dec/ivas_ism_renderer.c | 12 ++++----- lib_dec/ivas_masa_dec.c | 8 +++--- lib_dec/ivas_omasa_dec.c | 22 +++++++-------- lib_dec/ivas_qmetadata_dec.c | 4 +-- lib_enc/ivas_ism_metadata_enc.c | 2 +- lib_enc/ivas_masa_enc.c | 4 +-- lib_enc/ivas_omasa_enc.c | 4 +-- lib_enc/ivas_qmetadata_enc.c | 4 +-- lib_enc/ivas_sce_enc.c | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 7 ++--- 15 files changed, 58 insertions(+), 59 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 94d537494e..2746b05a21 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -883,14 +883,14 @@ void reconstruct_ism_ratios( /*--------------------------------------------------------------- - * modify_masa_energy_ratios() + * ivas_omasa_modify_masa_energy_ratios() * * Updates energy ratios by taking into account the MASA content contribution * to the total audio scene *---------------------------------------------------------------*/ -void modify_masa_energy_ratios( - IVAS_QMETADATA_HANDLE hQMetaData /* i/o: Metadata handle */ +void ivas_omasa_modify_masa_energy_ratios( + IVAS_QMETADATA_HANDLE hQMetaData /* i/o: q_metadata handle */ ) { int16_t i, m, d, b; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 78d3920199..8432cef489 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5685,7 +5685,7 @@ void ivas_set_surplus_brate_dec( int32_t *ism_total_brate /* i : ISM total bitrate */ ); -void set_ism_importance_interformat( +void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ const int16_t nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ @@ -5694,7 +5694,6 @@ void set_ism_importance_interformat( int16_t ism_imp[] /* o : ISM importance flags */ ); -#ifdef MASA_AND_OBJECTS /*! r: flag for using less bitrate for objects in OMASA */ int16_t ivas_omasa_ener_brate( const int16_t nchan_ism, /* i : number of ISMs */ @@ -5702,7 +5701,6 @@ int16_t ivas_omasa_ener_brate( float data_f[][L_FRAME48k], /* i : Input / transport audio signals */ const int16_t input_frame /* i : Input frame size */ ); -#endif /*! r: adjusted bitrate */ int32_t ivas_interformat_brate( @@ -5740,11 +5738,11 @@ void ivas_merge_masa_transports( const int16_t num_transport_channels /* i : Number of transport audio signals */ ); -ivas_error ivas_masa_ism_data_open( +ivas_error ivas_omasa_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); -void ivas_masa_ism_data_close( +void ivas_omasa_data_close( MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ); @@ -5769,34 +5767,34 @@ void ivas_omasa_dirac_rend( const int16_t output_frame /* i : output frame length per channel */ ); -void preProcessStereoTransportsForMovedObjects( - Decoder_Struct* st_ivas, +void ivas_omasa_preProcessStereoTransportsForMovedObjects( + Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nBins, const int16_t subframe ); -ivas_error ivas_masa_ism_separate_object_renderer_open( +ivas_error ivas_omasa_separate_object_renderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_masa_ism_separate_object_renderer_close( +void ivas_omasa_separate_object_renderer_close( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void ivas_masa_ism_separate_object_render( +void ivas_omasa_separate_object_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float input_f[][L_FRAME48k], /* i : separated object signal */ float output_f[][L_FRAME48k], /* i/o: output signals */ const int16_t output_frame /* i : output frame length per channel */ ); -void ivas_masa_ism_set_edited_objects( +void ivas_omasa_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -void encode_masa_to_total( +void ivas_omasa_encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, @@ -5804,7 +5802,7 @@ void encode_masa_to_total( const int16_t nblocks ); -void decode_masa_to_total( +void ivas_omasa_decode_masa_to_total( uint16_t *bit_stream, int16_t *index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], @@ -5812,8 +5810,8 @@ void decode_masa_to_total( const int16_t nblocks ); -void modify_masa_energy_ratios( - IVAS_QMETADATA_HANDLE hQMetaData +void ivas_omasa_modify_masa_energy_ratios( + IVAS_QMETADATA_HANDLE hQMetaData /* i/o: q_metadata handle */ ); #endif diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index e605d2e8cf..abc2e9a72c 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -568,7 +568,7 @@ ivas_error ivas_dec( } /* Set edited object positions, if editing enabled */ - ivas_masa_ism_set_edited_objects( st_ivas ); + ivas_omasa_set_edited_objects( st_ivas ); /* Rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ed17e9f090..9dc36c272c 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1975,7 +1975,7 @@ void ivas_dirac_dec_render_sf( if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { - preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, hSpatParamRendCom->num_freq_bands, subframe_idx ); + ivas_omasa_preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_Temp, Cldfb_ImagBuffer_Temp, hSpatParamRendCom->num_freq_bands, subframe_idx ); } } #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d5bd182137..393d331f31 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1173,7 +1173,7 @@ ivas_error ivas_init_decoder( return error; } - if ( ( error = ivas_masa_ism_data_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_data_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1662,7 +1662,7 @@ ivas_error ivas_init_decoder( } /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -1671,7 +1671,7 @@ ivas_error ivas_init_decoder( if ( st_ivas->renderer_type == RENDERER_DIRAC && ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -2214,8 +2214,8 @@ void ivas_destroy_dec( } #ifdef MASA_AND_OBJECTS - /* MASA ISM structure */ - ivas_masa_ism_data_close( &st_ivas->hMasaIsmData ); + /* OMASA structure */ + ivas_omasa_data_close( &st_ivas->hMasaIsmData ); #endif /* Head track data handle */ diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 6e776d3577..33d3598e0e 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -342,12 +342,12 @@ void ivas_ism_get_stereo_gains( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------------* - * ivas_masa_ism_separate_object_renderer_open() + * ivas_masa_oism_separate_object_renderer_open() * * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ -ivas_error ivas_masa_ism_separate_object_renderer_open( +ivas_error ivas_omasa_separate_object_renderer_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { @@ -413,12 +413,12 @@ ivas_error ivas_masa_ism_separate_object_renderer_open( /*-------------------------------------------------------------------------* - * ivas_masa_ism_separate_object_renderer_close() + * ivas_omasa_separate_object_renderer_close() * * Close structures, free memory. *-------------------------------------------------------------------------*/ -void ivas_masa_ism_separate_object_renderer_close( +void ivas_omasa_separate_object_renderer_close( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { @@ -459,13 +459,13 @@ void ivas_masa_ism_separate_object_renderer_close( /*-------------------------------------------------------------------------* - * ivas_masa_ism_separate_object_render() + * ivas_omasa_separate_object_render() * * Rendering separated objects and mixing them to the parametrically rendered signals *-------------------------------------------------------------------------*/ // Todo OMASA JBM: This might need adjustments -void ivas_masa_ism_separate_object_render( +void ivas_omasa_separate_object_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float input_f[][L_FRAME48k], /* i : separated object signal */ float output_f[][L_FRAME48k], /* i/o: output signals */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 62b642f449..07818ec8a2 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -383,7 +383,7 @@ ivas_error ivas_masa_decode( if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ - modify_masa_energy_ratios( hQMetaData ); + ivas_omasa_modify_masa_energy_ratios( hQMetaData ); } #endif @@ -2314,7 +2314,7 @@ static int16_t ivas_decode_masaism_metadata( nblocks = hQMetaData->q_direction->cfg.nblocks; /* To do: what if other value than 4? */ /* Read MASA-to-total energy ratios */ - decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands, nblocks ); + ivas_omasa_decode_masa_to_total( bit_stream, next_bit_pos, hQMetaData->masa_to_total_energy_ratio, nbands, nblocks ); if ( nchan_ism > 1 ) { /* read ISM ratios */ @@ -2436,12 +2436,12 @@ static int16_t ivas_decode_masaism_metadata( /*-------------------------------------------------------------------* - * ivas_masa_ism_set_edited_objects() + * ivas_omasa_set_edited_objects() * * *-------------------------------------------------------------------*/ -void ivas_masa_ism_set_edited_objects( +void ivas_omasa_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 3a41019ccb..5e1126a315 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -44,12 +44,12 @@ #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------* - * ivas_masa_ism_data_open() + * ivas_omasa_data_open() * * Allocate and initialize MASA_ISM rendering handle *-------------------------------------------------------------------*/ -ivas_error ivas_masa_ism_data_open( +ivas_error ivas_omasa_data_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { @@ -103,12 +103,12 @@ ivas_error ivas_masa_ism_data_open( /*-------------------------------------------------------------------* - * ivas_masa_ism_data_close() + * ivas_omasa_data_close() * * Deallocate MASA_ISM rendering handle *-------------------------------------------------------------------*/ -void ivas_masa_ism_data_close( +void ivas_omasa_data_close( MASA_ISM_DATA_HANDLE *hMasaIsmData /* i/o: MASA_ISM rendering handle */ ) { @@ -201,7 +201,7 @@ ivas_error ivas_omasa_dec_config( /* OMASA reconfig. */ if ( st_ivas->hMasaIsmData == NULL && st_ivas->ivas_format == MASA_ISM_FORMAT ) { - if ( ( error = ivas_masa_ism_data_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_data_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -297,7 +297,7 @@ ivas_error ivas_omasa_dec_config( /* objects renderer reconfig. */ if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) { - ivas_masa_ism_data_close( &( st_ivas->hMasaIsmData ) ); + ivas_omasa_data_close( &( st_ivas->hMasaIsmData ) ); } if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) @@ -311,7 +311,7 @@ ivas_error ivas_omasa_dec_config( } /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -330,7 +330,7 @@ ivas_error ivas_omasa_dec_config( } /* ISM renderer handle + ISM data handle */ - ivas_masa_ism_separate_object_renderer_close( st_ivas ); + ivas_omasa_separate_object_renderer_close( st_ivas ); } } @@ -344,7 +344,7 @@ ivas_error ivas_omasa_dec_config( if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - if ( ( error = ivas_masa_ism_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -352,7 +352,7 @@ ivas_error ivas_omasa_dec_config( else { /* ISM renderer handle + ISM data handle */ - ivas_masa_ism_separate_object_renderer_close( st_ivas ); + ivas_omasa_separate_object_renderer_close( st_ivas ); } } @@ -577,7 +577,7 @@ void ivas_omasa_dirac_rend( st_ivas->hSpatParamRendCom->dirac_read_idx = dirac_read_idx; /* Original read index is needed for the next function which will update it again */ - ivas_masa_ism_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); + ivas_omasa_separate_object_render( st_ivas, data_separated_objects, output, output_frame ); return; } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 1dfba8f212..7b465ed3bf 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -4510,11 +4510,11 @@ static void read_stream_dct_coeffs_omasa( /*------------------------------------------------------------------------- - * decode_masa_to_total() + * ivas_omasa_decode_masa_to_total() * *------------------------------------------------------------------------*/ -void decode_masa_to_total( +void ivas_omasa_decode_masa_to_total( uint16_t *bit_stream, int16_t *index, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 301576d870..3154eb56a7 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -233,7 +233,7 @@ ivas_error ivas_ism_metadata_enc( * Rate importance of particular ISM streams in combined format coding *----------------------------------------------------------------*/ - set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + ivas_set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); } else { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6b2db322ca..177768c9d7 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -600,7 +600,7 @@ ivas_error ivas_masa_encode( if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ - modify_masa_energy_ratios( hQMetaData ); + ivas_omasa_modify_masa_energy_ratios( hQMetaData ); } #endif @@ -3641,7 +3641,7 @@ static void ivas_encode_masaism_metadata( } } - encode_masa_to_total( hQMetaData, hMetaData, low_bitrate_mode, numCodingBands, numSf ); + ivas_omasa_encode_masa_to_total( hQMetaData, hMetaData, low_bitrate_mode, numCodingBands, numSf ); /* quantize ism_ratios */ if ( nchan_ism > 1 ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 72a10f7675..ea782115bb 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -588,12 +588,12 @@ void ivas_omasa_enc( /*-------------------------------------------------------------------------* - * set_ism_importance_interformat() + * ivas_set_ism_importance_interformat() * * Set the importance of particular ISM streams in combined-format coding *-------------------------------------------------------------------------*/ -void set_ism_importance_interformat( +void ivas_set_ism_importance_interformat( const int32_t ism_total_brate, /* i/o: ISms total bitrate */ const int16_t nchan_transport, /* i : number of transported channels */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 3ba709b939..6be126ac83 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6396,11 +6396,11 @@ static int16_t write_stream_dct_coeffs_omasa( /*------------------------------------------------------------------------- - * encode_masa_to_total() + * ivas_omasa_encode_masa_to_total() * *------------------------------------------------------------------------*/ -void encode_masa_to_total( +void ivas_omasa_encode_masa_to_total( IVAS_QMETADATA_HANDLE hQMetaData, BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 2193c892fb..ed6d74c71a 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -217,7 +217,7 @@ ivas_error ivas_sce_enc( if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); + ivas_set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 3208b77ba3..30f99d065c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -787,7 +787,7 @@ static void ivas_dirac_dec_binaural_internal( #ifdef MASA_AND_OBJECTS if ( st_ivas->ivas_format == MASA_ISM_FORMAT && nchan_transport == 2 && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) { - preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, subframe ); + ivas_omasa_preProcessStereoTransportsForMovedObjects( st_ivas, Cldfb_RealBuffer_in, Cldfb_ImagBuffer_in, nBins, subframe ); } #endif @@ -2568,12 +2568,13 @@ float configure_reqularization_factor( #ifdef MASA_AND_OBJECTS /*-------------------------------------------------------------------* - * preProcessStereoTransportsForMovedObjects() + * ivas_omasa_preProcessStereoTransportsForMovedObjects() * * *-------------------------------------------------------------------*/ + // Todo OMASA JBM: This might need further adjustments -void preProcessStereoTransportsForMovedObjects( +void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], -- GitLab From 3526ff892c67ad4578e2f030c355593cfd51aa7b Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 1 Aug 2023 15:33:46 +0300 Subject: [PATCH 165/173] Add fix to decorrelator pointer assignment to satiate USAN. --- lib_rend/ivas_dirac_dec_binaural_functions.c | 28 ++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 30f99d065c..3cf1103655 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1746,16 +1746,28 @@ static void ivas_dirac_dec_binaural_process_output( /* Processing of the first / HRTF part of the binaural output. */ for ( chB = 0; chB < numInChannels; chB++ ) { - if ( hDiracDecBin->useTdDecorr ) - { - decSlotRePointer = inRe[chB + 2][slot]; - decSlotImPointer = inIm[chB + 2][slot]; - } - else +#ifdef MASA_AND_OBJECTS + if ( chB < BINAURAL_CHANNELS ) { - decSlotRePointer = decSlotRe[chB]; - decSlotImPointer = decSlotIm[chB]; + /* Decorrelator signal for TD decorrelation is stored in two input channels above the two normal inputs. + * It should be noted that TD decorrelation is used only in cases where numInChannels is 2. If this + * changes, additional adjustments are required. When using CLDFB decorrelator, we simply assign the + * pointers to buffers. */ +#endif + if ( hDiracDecBin->useTdDecorr ) + { + decSlotRePointer = inRe[chB + 2][slot]; + decSlotImPointer = inIm[chB + 2][slot]; + } + else + { + decSlotRePointer = decSlotRe[chB]; + decSlotImPointer = decSlotIm[chB]; + } +#ifdef MASA_AND_OBJECTS } +#endif + for ( bin = 0; bin < nBins; bin++ ) { -- GitLab From 265c846a5ec3e6b9bb314ba3237d6e7147d453d7 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 15:17:10 +0200 Subject: [PATCH 166/173] fix over-indexing of frequency bands --- lib_dec/ivas_masa_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 07818ec8a2..001465bf51 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -503,7 +503,7 @@ ivas_error ivas_masa_decode( // Todo OMASA JBM: This might need adjustments meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; - for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) + for ( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] -= st_ivas->hMasaIsmData->energy_ratio_ism[i][meta_write_index][b]; } @@ -514,7 +514,7 @@ ivas_error ivas_masa_decode( { meta_write_index = ( dirac_bs_md_write_idx + block ) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; - for ( b = 0; b < CLDFB_NO_CHANNELS_MAX; b++ ) + for ( b = 0; b < st_ivas->hSpatParamRendCom->num_freq_bands; b++ ) { st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] = max( 0.0f, st_ivas->hSpatParamRendCom->diffuseness_vector[meta_write_index][b] ); } -- GitLab From 7bf4f6d7a03ef92a1ed513e7fe715030e822d68c Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 1 Aug 2023 16:19:48 +0300 Subject: [PATCH 167/173] fix usan error in masa config for omasa cases --- lib_com/ivas_masa_com.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 2746b05a21..b270285f1b 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -256,7 +256,15 @@ void ivas_masa_set_coding_config( if ( ivas_total_brate <= ivas_brate_tbl[i + SIZE_IVAS_BRATE_TBL - IVAS_NUM_ACTIVE_BRATES] ) { int16_t idx_bands; - idx_bands = i; + if ( ivas_total_brate < IVAS_48k && nchan_transport == 2 && i > 3 ) + { + /* because it uses the bitallocation for the lower bit rates from 'masa_bits_LR_stereo' and it has 4 elements */ + idx_bands = 3; + } + else + { + idx_bands = i; + } if ( config->numberOfDirections > 1 ) { -- GitLab From 7ec2f581fbffb66cc191f6c6446e6a144daeef27 Mon Sep 17 00:00:00 2001 From: advasila Date: Tue, 1 Aug 2023 17:08:19 +0300 Subject: [PATCH 168/173] correct fix for usan --- lib_com/ivas_masa_com.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index b270285f1b..ca188d6239 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -259,12 +259,10 @@ void ivas_masa_set_coding_config( if ( ivas_total_brate < IVAS_48k && nchan_transport == 2 && i > 3 ) { /* because it uses the bitallocation for the lower bit rates from 'masa_bits_LR_stereo' and it has 4 elements */ - idx_bands = 3; - } - else - { - idx_bands = i; + i = 3; } + idx_bands = i; + if ( config->numberOfDirections > 1 ) { -- GitLab From 14edcd272e08a64a8ef56346efce2b5870950041 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 16:16:29 +0200 Subject: [PATCH 169/173] fix Win build warning of potentially uninitialized variables --- lib_rend/ivas_dirac_dec_binaural_functions.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 3cf1103655..d118334fe3 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1766,6 +1766,11 @@ static void ivas_dirac_dec_binaural_process_output( } #ifdef MASA_AND_OBJECTS } + else + { + decSlotRePointer = NULL; /* below these pointers are used only for chB < 2 */ + decSlotImPointer = NULL; + } #endif -- GitLab From 66792433bf3ba9a91958b133a04d065f10c69511 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 18:02:56 +0200 Subject: [PATCH 170/173] allocate structures only when necessary --- lib_dec/ivas_ism_renderer.c | 48 ++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 33d3598e0e..dd2b9b14ed 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -354,10 +354,14 @@ ivas_error ivas_omasa_separate_object_renderer_open( int16_t interpolator_length; int16_t i; int16_t init_interpolator_length; + int16_t delayBuffer_nchan_new; - if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) + if ( st_ivas->hIsmRendererData == NULL ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); + if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); + } } for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -376,6 +380,12 @@ ivas_error ivas_omasa_separate_object_renderer_open( init_interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); interpolator_length = init_interpolator_length; } + + if ( st_ivas->hIsmRendererData->interpolator != NULL ) + { + free( st_ivas->hIsmRendererData->interpolator ); + st_ivas->hIsmRendererData->interpolator = NULL; + } st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * init_interpolator_length ); for ( i = 0; i < interpolator_length; i++ ) @@ -387,24 +397,46 @@ ivas_error ivas_omasa_separate_object_renderer_open( if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - st_ivas->hMasaIsmData->delayBuffer_nchan = 1; + delayBuffer_nchan_new = 1; } else { - st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; + delayBuffer_nchan_new = st_ivas->nchan_ism; } - if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) + if ( st_ivas->hMasaIsmData->delayBuffer != NULL && delayBuffer_nchan_new != st_ivas->hMasaIsmData->delayBuffer_nchan ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { + if ( st_ivas->hMasaIsmData->delayBuffer[i] != NULL ) + { + free( st_ivas->hMasaIsmData->delayBuffer[i] ); + st_ivas->hMasaIsmData->delayBuffer[i] = NULL; + } + } + free( st_ivas->hMasaIsmData->delayBuffer ); + st_ivas->hMasaIsmData->delayBuffer = NULL; } - for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + st_ivas->hMasaIsmData->delayBuffer_nchan = delayBuffer_nchan_new; + + if ( st_ivas->hMasaIsmData->delayBuffer == NULL ) { - if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) + if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { + if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); + } + } + } + + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) + { set_zero( st_ivas->hMasaIsmData->delayBuffer[i], st_ivas->hMasaIsmData->delayBuffer_size ); } -- GitLab From 2415360625a7398cc4d2d8cb8d214827bc273c58 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 16:21:49 +0000 Subject: [PATCH 171/173] Revert "allocate structures only when necessary" This reverts commit 66792433bf3ba9a91958b133a04d065f10c69511 --- lib_dec/ivas_ism_renderer.c | 48 +++++++------------------------------ 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index dd2b9b14ed..33d3598e0e 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -354,14 +354,10 @@ ivas_error ivas_omasa_separate_object_renderer_open( int16_t interpolator_length; int16_t i; int16_t init_interpolator_length; - int16_t delayBuffer_nchan_new; - if ( st_ivas->hIsmRendererData == NULL ) + if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) { - if ( ( st_ivas->hIsmRendererData = (ISM_RENDERER_HANDLE) malloc( sizeof( ISM_RENDERER_DATA ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); - } + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer \n" ) ); } for ( i = 0; i < MAX_NUM_OBJECTS; i++ ) @@ -380,12 +376,6 @@ ivas_error ivas_omasa_separate_object_renderer_open( init_interpolator_length = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ); interpolator_length = init_interpolator_length; } - - if ( st_ivas->hIsmRendererData->interpolator != NULL ) - { - free( st_ivas->hIsmRendererData->interpolator ); - st_ivas->hIsmRendererData->interpolator = NULL; - } st_ivas->hIsmRendererData->interpolator = (float *) malloc( sizeof( float ) * init_interpolator_length ); for ( i = 0; i < interpolator_length; i++ ) @@ -397,46 +387,24 @@ ivas_error ivas_omasa_separate_object_renderer_open( if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { - delayBuffer_nchan_new = 1; + st_ivas->hMasaIsmData->delayBuffer_nchan = 1; } else { - delayBuffer_nchan_new = st_ivas->nchan_ism; + st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; } - if ( st_ivas->hMasaIsmData->delayBuffer != NULL && delayBuffer_nchan_new != st_ivas->hMasaIsmData->delayBuffer_nchan ) + if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) { - for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) - { - if ( st_ivas->hMasaIsmData->delayBuffer[i] != NULL ) - { - free( st_ivas->hMasaIsmData->delayBuffer[i] ); - st_ivas->hMasaIsmData->delayBuffer[i] = NULL; - } - } - free( st_ivas->hMasaIsmData->delayBuffer ); - st_ivas->hMasaIsmData->delayBuffer = NULL; + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } - st_ivas->hMasaIsmData->delayBuffer_nchan = delayBuffer_nchan_new; - - if ( st_ivas->hMasaIsmData->delayBuffer == NULL ) + for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) { - if ( ( st_ivas->hMasaIsmData->delayBuffer = (float **) malloc( st_ivas->hMasaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL ) + if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); } - for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) - { - if ( ( st_ivas->hMasaIsmData->delayBuffer[i] = (float *) malloc( st_ivas->hMasaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM delay buffer \n" ) ); - } - } - } - - for ( i = 0; i < st_ivas->hMasaIsmData->delayBuffer_nchan; i++ ) - { set_zero( st_ivas->hMasaIsmData->delayBuffer[i], st_ivas->hMasaIsmData->delayBuffer_size ); } -- GitLab From b61b381c581761aeb9b235aec33b5ee860c35053 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 1 Aug 2023 18:29:21 +0200 Subject: [PATCH 172/173] full renderer close instead of trying to be conservative --- lib_dec/ivas_omasa_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 5e1126a315..9ba6877cfb 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -295,9 +295,9 @@ ivas_error ivas_omasa_dec_config( } /* objects renderer reconfig. */ - if ( st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_PARAM_ONE_OBJ && st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->hIsmRendererData != NULL ) + if ( st_ivas->hMasaIsmData != NULL ) { - ivas_omasa_data_close( &( st_ivas->hMasaIsmData ) ); + ivas_omasa_separate_object_renderer_close( st_ivas ); } if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) -- GitLab From 5f7d8124d036bbc4be707d34f8c547dc2f91cb58 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Tue, 1 Aug 2023 19:52:47 +0300 Subject: [PATCH 173/173] Apply clang format --- lib_com/ivas_masa_com.c | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index ca188d6239..0ca65e4da3 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -262,7 +262,7 @@ void ivas_masa_set_coding_config( i = 3; } idx_bands = i; - + if ( config->numberOfDirections > 1 ) { diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index d118334fe3..ab6241c4f9 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1768,7 +1768,7 @@ static void ivas_dirac_dec_binaural_process_output( } else { - decSlotRePointer = NULL; /* below these pointers are used only for chB < 2 */ + decSlotRePointer = NULL; /* below these pointers are used only for chB < 2 */ decSlotImPointer = NULL; } #endif -- GitLab