From 2b63ba4559bb9d69a5a70a6ebe12ece910e2a3af Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 2 Jun 2023 12:00:18 +0200 Subject: [PATCH 01/17] detect mono input in SBA encoder and signal this to the decoder in the bitstream --- lib_com/ivas_prot.h | 7 ++++ lib_com/ivas_stat_com.h | 3 ++ lib_com/options.h | 2 ++ lib_dec/ivas_dirac_dec.c | 16 +++++++++ lib_enc/ivas_dirac_enc.c | 69 +++++++++++++++++++++++++++++++++++++-- lib_enc/ivas_mcmasa_enc.c | 7 +++- lib_enc/ivas_stat_enc.h | 1 + 7 files changed, 102 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index f455c552a5..4c8d84b26e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3399,6 +3399,9 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const uint8_t useLowerRes, +#ifdef FIX_527_SBA_MONO_INPUT + int16_t *dirac_mono_flag, +#endif float data_f[][L_FRAME48k], float **pp_fr_real, float **pp_fr_imag, @@ -5578,6 +5581,10 @@ void computeReferencePower_enc( #endif , const int16_t nchan_ana /* i : number of analysis channels */ +#ifdef FIX_527_SBA_MONO_INPUT + , + int16_t *dirac_mono_flag +#endif ); ivas_error ivas_mono_dmx_renderer_open( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index cc0fbf89b3..3edd4910fc 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -546,6 +546,9 @@ typedef struct ivas_masa_qmetadata_frame_struct int16_t metadata_max_bits; /* maximum allowed number of bits for metadata per frame */ uint8_t useLowerRes; uint8_t useLowerBandRes; +#ifdef FIX_527_SBA_MONO_INPUT + int16_t dirac_mono_flag; +#endif IVAS_SURROUND_COHERENCE_BAND_DATA *surcoh_band_data; /* Additional helper values to include all data required for writing to output file */ diff --git a/lib_com/options.h b/lib_com/options.h index 3a4a9e926f..8d0d6017f8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -234,6 +234,8 @@ #define FIX_TODO_NON_DIEGETIC_PAN_NOT_IMPLELENTED_IN_RENDERER /* ..\apps\renderer.c(240): .... (todo: implementation)",*/ #define REMOVE_OBS_CODE /* FhG: Remove unnecessary assignement after LFE cleanup (Issue #451)*/ +#define FIX_527_SBA_MONO_INPUT /* FhG: fix issue 527, artifacts in mono signals coded in SBA mode */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 502420781f..4f420e985a 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1783,6 +1783,11 @@ void ivas_dirac_dec_read_BS( b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; +#ifdef FIX_527_SBA_MONO_INPUT + hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits )++; +#endif + #ifndef SBA_MODE_CLEAN_UP if ( sba_mode != SBA_MODE_SPAR ) { @@ -1945,6 +1950,17 @@ void ivas_dirac_dec_read_BS( if ( hDirAC != NULL ) { +#ifdef FIX_527_SBA_MONO_INPUT + printf( "%d\n", hQMetaData->dirac_mono_flag ); + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } +#endif #ifndef SBA_MODE_CLEAN_UP ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, ivas_total_brate, sba_mode, hodirac_flag, diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 5aa872e434..87f7e2c210 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -588,7 +588,24 @@ void ivas_dirac_enc( int16_t i, j, b, i_ts; push_wmops( "ivas_dirac_enc" ); - ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS ); +#ifdef FIX_527_SBA_MONO_INPUT + hQMetaData->dirac_mono_flag = 0; +#endif + + ivas_dirac_param_est_enc( + hDirAC, + hQMetaData->q_direction, + hQMetaData->useLowerRes, +#ifdef FIX_527_SBA_MONO_INPUT + &hQMetaData->dirac_mono_flag, +#endif + data_f, + ppIn_FR_real, + ppIn_FR_imag, + input_frame, + ivas_format, + hodirac_flag, + hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS ); if ( hQMetaData->q_direction->cfg.nbands > 0 ) { @@ -599,6 +616,11 @@ void ivas_dirac_enc( /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); +#ifdef FIX_527_SBA_MONO_INPUT + /* flag to indicate a mono input signal */ + push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); +#endif + ivas_qmetadata_enc_encode( hMetaData, hQMetaData, hodirac_flag ); } else @@ -636,9 +658,26 @@ void ivas_dirac_enc( /* 1 bit to indicate mode MD coding : temp solution*/ push_next_indice( hMetaData, 1, 1 ); +#ifdef FIX_527_SBA_MONO_INPUT + /* flag to indicate a mono input signal */ + push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); +#endif + /* encode SID parameters */ ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); } +#ifdef FIX_527_SBA_MONO_INPUT + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + { + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 1.0f; + } + } + } +#endif for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { @@ -699,6 +738,10 @@ void computeReferencePower_enc( #endif , const int16_t nchan_ana /* i : number of analysis channels */ +#ifdef FIX_527_SBA_MONO_INPUT + , + int16_t *dirac_mono_flag +#endif ) { int16_t brange[2]; @@ -706,6 +749,13 @@ void computeReferencePower_enc( float reference_power_W[DIRAC_MAX_NBANDS]; +#ifdef FIX_527_SBA_MONO_INPUT + if ( dirac_mono_flag != NULL ) + { + *dirac_mono_flag = 1; + } +#endif + for ( i = 0; i < num_freq_bands; i++ ) { brange[0] = band_grouping[i + enc_param_start_band]; @@ -727,6 +777,13 @@ void computeReferencePower_enc( reference_power[i] += ( Cldfb_RealBuffer[ch_idx][j] * Cldfb_RealBuffer[ch_idx][j] ) + ( Cldfb_ImagBuffer[ch_idx][j] * Cldfb_ImagBuffer[ch_idx][j] ); } } + +#ifdef FIX_527_SBA_MONO_INPUT + if ( reference_power[i] - reference_power_W[i] > EPSILON && dirac_mono_flag != NULL ) + { + *dirac_mono_flag = 0; + } +#endif } v_multc( reference_power, 0.5f, reference_power, num_freq_bands ); @@ -756,6 +813,9 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const uint8_t useLowerRes, +#ifdef FIX_527_SBA_MONO_INPUT + int16_t *dirac_mono_flag, +#endif float data_f[][L_FRAME48k], float **pp_fr_real, float **pp_fr_imag, @@ -879,7 +939,12 @@ void ivas_dirac_param_est_enc( ivas_format, hodirac_flag ? 0 : 1, #endif - FOA_CHANNELS ); + FOA_CHANNELS +#ifdef FIX_527_SBA_MONO_INPUT + , + dirac_mono_flag +#endif + ); computeIntensityVector_enc( hDirAC, diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 09fe5e3f40..bfc4409767 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -993,7 +993,12 @@ void ivas_mcmasa_param_est_enc( MC_FORMAT, 0, #endif - FOA_CHANNELS ); + FOA_CHANNELS +#ifdef FIX_527_SBA_MONO_INPUT + , + NULL +#endif + ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 7690ac5b30..f243e07623 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -602,6 +602,7 @@ typedef struct ivas_dirac_enc_data_structure float diffuseness_m[DIRAC_MAX_NBANDS]; int16_t band_grouping[DIRAC_MAX_NBANDS + 1]; int16_t block_grouping[5]; + #ifdef FIX_485_STATIC_BUFFERS int16_t firstrun_sector_params; -- GitLab From c6e037f3fab9b7071bb08f0c4cefe895bdb4ad47 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 2 Jun 2023 12:16:14 +0200 Subject: [PATCH 02/17] add temporary assert to stop when mono content is detected, only for debugging --- lib_dec/ivas_dirac_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 4f420e985a..fafbe8acdf 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1951,9 +1951,9 @@ void ivas_dirac_dec_read_BS( if ( hDirAC != NULL ) { #ifdef FIX_527_SBA_MONO_INPUT - printf( "%d\n", hQMetaData->dirac_mono_flag ); if ( hQMetaData->dirac_mono_flag ) { + assert( 00 && "We do not want to decode mono now!" ); for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -- GitLab From 86f80f223264f11d587a9f8b0ee8bf33ad3dece3 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 2 Jun 2023 14:15:33 +0200 Subject: [PATCH 03/17] delete temporary assert in sba mono handling --- lib_dec/ivas_dirac_dec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index fafbe8acdf..9716e0edde 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1953,7 +1953,6 @@ void ivas_dirac_dec_read_BS( #ifdef FIX_527_SBA_MONO_INPUT if ( hQMetaData->dirac_mono_flag ) { - assert( 00 && "We do not want to decode mono now!" ); for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); -- GitLab From b0b0f1c9cced1b490704080806bb40902ffd60e7 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 2 Jun 2023 16:43:48 +0200 Subject: [PATCH 04/17] read mono signaling bit in DTX case --- lib_dec/ivas_dirac_dec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 9716e0edde..21d67c5f11 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1891,9 +1891,16 @@ void ivas_dirac_dec_read_BS( /* 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 ); + /* 1 bit flag for SPAR/DirAC, already read in read format function */ b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; + +#ifdef FIX_527_SBA_MONO_INPUT + hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits )++; +#endif + hQMetaData->sba_inactive_mode = 1; orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; @@ -1951,6 +1958,7 @@ void ivas_dirac_dec_read_BS( if ( hDirAC != NULL ) { #ifdef FIX_527_SBA_MONO_INPUT + assert( hQMetaData->dirac_mono_flag == 0 && "There should be no mono content here!" ); if ( hQMetaData->dirac_mono_flag ) { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) -- GitLab From dfacbddcac4bc1a84c8ff60000aea0f840b2ea5a Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 2 Jun 2023 16:49:09 +0200 Subject: [PATCH 05/17] delete temporary assert for debugging detection of mono input in SBA --- lib_dec/ivas_dirac_dec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 21d67c5f11..05d4b911c4 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1958,7 +1958,6 @@ void ivas_dirac_dec_read_BS( if ( hDirAC != NULL ) { #ifdef FIX_527_SBA_MONO_INPUT - assert( hQMetaData->dirac_mono_flag == 0 && "There should be no mono content here!" ); if ( hQMetaData->dirac_mono_flag ) { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) -- GitLab From fb20ff901da6d0e5f66a998846d21680fab16607 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 12 Jun 2023 09:30:50 +0200 Subject: [PATCH 06/17] fix formatting --- lib_dec/ivas_dirac_dec.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 39069a17f1..f1ab42dbb6 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -391,7 +391,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->slot_size = ( int16_t )( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + 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; @@ -461,7 +461,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->num_freq_bands = ( int16_t )( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + 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 ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -1707,7 +1707,7 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); /* 1 bit flag for signaling metadata to read */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -1781,7 +1781,7 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); /* 1 bit flag for SPAR/DirAC, already read in read format function */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -2137,13 +2137,13 @@ void ivas_qmetadata_to_dirac( if ( hodirac_flag ) { - azi = ( int16_t )( azimuth + 0.5f ); - ele = ( int16_t )( elevation + 0.5f ); + 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 ); + 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 ); @@ -2584,10 +2584,10 @@ void ivas_dirac_dec_render_sf( { for ( i = 0; i < output_frame; i++ ) { - tmp[nchan_transport * i + n] = ( int16_t )( output_f[n][i] + 0.5f ); + 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 ) ); + 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 @@ -4287,8 +4287,8 @@ static void computeDirectionAngles( 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 ); + 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; @@ -4573,8 +4573,8 @@ static void rotateAziEle_DirAC( 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 ); + 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(); -- GitLab From d235e032abe5325c088a214aaf22613a558947f1 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Wed, 14 Jun 2023 08:41:36 +0200 Subject: [PATCH 07/17] fix merge error in diffuseness setting for SBA mono input --- lib_enc/ivas_dirac_enc.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 66ae855fc7..66cd223d76 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -377,18 +377,6 @@ void ivas_dirac_enc( /* encode SID parameters */ ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); } -#ifdef FIX_527_SBA_MONO_INPUT - if ( hQMetaData->dirac_mono_flag ) - { - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) - { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) - { - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 1.0f; - } - } - } -#endif for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) { @@ -421,6 +409,19 @@ void ivas_dirac_enc( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } + +#ifdef FIX_527_SBA_MONO_INPUT + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + { + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; + } + } + } +#endif } pop_wmops(); -- GitLab From 550242fed20634aefca6e39e484e01a26d39c9fc Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 15 Jun 2023 09:31:05 +0200 Subject: [PATCH 08/17] zero out energy ratio for mono also when hDirAC is NULL --- lib_dec/ivas_dirac_dec.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index d39792acae..9c81e96470 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1830,19 +1830,20 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } - if ( hDirAC != NULL ) - { #ifdef FIX_527_SBA_MONO_INPUT - if ( hQMetaData->dirac_mono_flag ) + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { - for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); - } + set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); } + } #endif + if ( hDirAC != NULL ) + { + ivas_qmetadata_to_dirac( hQMetaData, hDirAC, NULL, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); -- GitLab From 0b29b0be6fce1527c69ed9359f82c6f1f7783d26 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 15 Jun 2023 10:43:54 +0200 Subject: [PATCH 09/17] move code to set diffuseness in case of mono input to ivas_spar_enc_process --- lib_enc/ivas_dirac_enc.c | 13 ------------- lib_enc/ivas_spar_encoder.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 66cd223d76..cbcd733387 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -409,19 +409,6 @@ void ivas_dirac_enc( hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; } - -#ifdef FIX_527_SBA_MONO_INPUT - if ( hQMetaData->dirac_mono_flag ) - { - for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) - { - for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) - { - hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; - } - } - } -#endif } pop_wmops(); diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 436a649f46..c9fbd86ccb 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -518,6 +518,18 @@ static ivas_error ivas_spar_enc_process( hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); ivas_dirac_enc( st_ivas->hDirAC, hQMetaData, hMetaData, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ); +#ifdef FIX_527_SBA_MONO_INPUT + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + { + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; + } + } + } +#endif /*-----------------------------------------------------------------------------------------* * Set SPAR bitrates -- GitLab From ac28ce6ffc03c2e6a371b23ade36149a523ba105 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Thu, 15 Jun 2023 16:42:30 +0200 Subject: [PATCH 10/17] sketch experimental heuristic for mono input detection under the disabled define FIX_527_MONO_HEURISTICSd --- lib_com/ivas_prot.h | 4 + lib_com/options.h | 2 +- lib_enc/ivas_spar_encoder.c | 339 +++++++++++++++++++----------------- lib_enc/ivas_spar_md_enc.c | 46 ++++- 4 files changed, 224 insertions(+), 167 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index bb988732c3..54d07c4589 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4455,6 +4455,10 @@ ivas_error ivas_spar_md_enc_process( const int16_t nchan_inp, const int16_t sba_order, /* i : Ambisonic (SBA) order */ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i : prior mixer_matrix */ +#ifdef FIX_527_MONO_HEURISTICS + , + int16_t *dirac_mono_flag +#endif ); void ivas_compute_spar_params( diff --git a/lib_com/options.h b/lib_com/options.h index 5d8871861b..762df7055f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -159,7 +159,7 @@ #define FIX_527_SBA_MONO_INPUT /* FhG: fix issue 527, artifacts in mono signals coded in SBA mode */ - +/*#define FIX_527_MONO_HEURISTICS*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index c9fbd86ccb..e5ece388f9 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -426,7 +426,7 @@ static ivas_error ivas_spar_enc_process( ivas_total_brate = hEncoderConfig->ivas_total_brate; num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); @@ -518,6 +518,7 @@ static ivas_error ivas_spar_enc_process( hodirac_flag = ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ); ivas_dirac_enc( st_ivas->hDirAC, hQMetaData, hMetaData, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, dtx_vad, hEncoderConfig->ivas_format, hodirac_flag ); + #ifdef FIX_527_SBA_MONO_INPUT if ( hQMetaData->dirac_mono_flag ) { @@ -576,7 +577,12 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_hoa_md_flag == 0 ) { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer ); + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer +#ifdef FIX_527_MONO_HEURISTICS + , + &hQMetaData->dirac_mono_flag +#endif + ); } if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) @@ -624,137 +630,142 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_hoa_md_flag ) { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer ); + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer +#ifdef FIX_527_MONO_HEURISTICS + , + &hQMetaData->dirac_mono_flag +#endif + ); } #ifdef DEBUG_LBR_SBA - /* Dumping SPAR Coefficients */ - char f_name[100]; - int16_t nbands = 6; - int16_t num_subframes = 1; - int16_t num_elements = 6; - int16_t num_block_group = 1; - int16_t byte_size = sizeof( float ); - - sprintf( f_name, "SBA_MD_values.bin" ); - ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - - for ( b = 0; b < nbands; b++ ) - { - for ( int16_t sf = 0; sf < num_subframes; sf++ ) + /* Dumping SPAR Coefficients */ + char f_name[100]; + int16_t nbands = 6; + int16_t num_subframes = 1; + int16_t num_elements = 6; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) { - for ( int16_t bl = 0; bl < num_block_group; bl++ ) + for ( int16_t sf = 0; sf < num_subframes; sf++ ) { - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); - // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } } } - } #endif #ifdef DEBUG_LBR_SBA - /* Dumping SPAR Coefficients */ - nbands = 6; - num_subframes = 1; - num_elements = 6; - num_block_group = 1; - byte_size = sizeof( float ); - - sprintf( f_name, "SBA_MD_values_quant.bin" ); - ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - - for ( b = 0; b < nbands; b++ ) - { - for ( int16_t sf = 0; sf < num_subframes; sf++ ) + /* Dumping SPAR Coefficients */ + nbands = 6; + num_subframes = 1; + num_elements = 6; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_quant.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) { - for ( int16_t bl = 0; bl < num_block_group; bl++ ) + for ( int16_t sf = 0; sf < num_subframes; sf++ ) { - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[2], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[2], byte_size, 1, 1, f_name ); - // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + for ( int16_t bl = 0; bl < num_block_group; bl++ ) + { + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); + } } } - } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ - ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); + ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); #ifdef DEBUG_SBA_MD_DUMP - { - int16_t k; - static FILE *f_mat = 0; + { + int16_t k; + static FILE *f_mat = 0; - if ( f_mat == 0 ) - f_mat = fopen( "mixer_mat_enc", "w" ); + if ( f_mat == 0 ) + f_mat = fopen( "mixer_mat_enc", "w" ); - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) { - for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) { - fprintf( f_mat, "%f\n", hSpar->hMdEnc->mixer_mat[i][j][k] ); - - if ( ( in_out_mixer_map[i][j] == 0 ) && ( fabs( hSpar->hMdEnc->mixer_mat[i][j][k] ) > 1e-20 ) ) + for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) { - assert( 0 && "Non zero value in unexpected mixer map!!!" ); + fprintf( f_mat, "%f\n", hSpar->hMdEnc->mixer_mat[i][j][k] ); + + if ( ( in_out_mixer_map[i][j] == 0 ) && ( fabs( hSpar->hMdEnc->mixer_mat[i][j][k] ) > 1e-20 ) ) + { + assert( 0 && "Non zero value in unexpected mixer map!!!" ); + } } } } } - } #endif #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS - { - static FILE *fid = 0; - int16_t band = 9; - if ( !fid ) { - fid = fopen( "pred_coeffs_enc.txt", "wt" ); + static FILE *fid = 0; + int16_t band = 9; + if ( !fid ) + { + fid = fopen( "pred_coeffs_enc.txt", "wt" ); + } + fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); } - fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); - } #endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); #ifdef DEBUG_SBA_AUDIO_DUMP - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[1], "ivas_fb_mixer_process()" ); + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[1], "ivas_fb_mixer_process()" ); #endif - if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) - { - /* delayed W */ - mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); - mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); - - for ( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) { - int idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; + /* delayed W */ + mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); + mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); + + for ( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + int idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; - /* delayed, reorderd and accumulated with (negative) prediction from W */ - v_add( wyzx_del_buf[idx], p_pcm_tmp[i], p_pcm_tmp[i], num_del_samples ); - v_add( data_f[idx], p_pcm_tmp[i] + num_del_samples, p_pcm_tmp[i] + num_del_samples, input_frame - num_del_samples ); + /* delayed, reorderd and accumulated with (negative) prediction from W */ + v_add( wyzx_del_buf[idx], p_pcm_tmp[i], p_pcm_tmp[i], num_del_samples ); + v_add( data_f[idx], p_pcm_tmp[i] + num_del_samples, p_pcm_tmp[i] + num_del_samples, input_frame - num_del_samples ); + } } - } #if 0 /* SBA_TD_RESIDUAL */ { @@ -779,39 +790,39 @@ static ivas_error ivas_spar_enc_process( } } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * PCA encoder *-----------------------------------------------------------------------------------------*/ - if ( hSpar->hPCA != NULL ) - { - ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); - } - else - { - if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) + if ( hSpar->hPCA != NULL ) { - /* write PCA bypass bit */ - push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); + ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); + } + else + { + if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) + { + /* write PCA bypass bit */ + push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); + } } - } #ifdef DEBUG_LBR_SBA - for ( int t = 0; t < 960; t++ ) - { - for ( int c = 0; c < hSpar->hFbMixer->fb_cfg->num_out_chans; c++ ) + for ( int t = 0; t < 960; t++ ) { - float val = p_pcm_tmp[c][t]; // / MAX16B_FLT; - dbgwrite( &val, sizeof( float ), 1, 1, "int_enc_dmx.raw" ); + for ( int c = 0; c < hSpar->hFbMixer->fb_cfg->num_out_chans; c++ ) + { + float val = p_pcm_tmp[c][t]; // / MAX16B_FLT; + dbgwrite( &val, sizeof( float ), 1, 1, "int_enc_dmx.raw" ); + } } - } #endif #ifdef DEBUG_SBA_AUDIO_DUMP - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[0], "ivas_pca_enc()" ); + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[0], "ivas_pca_enc()" ); #endif #ifdef SPAR_HOA_DBG - /*FILE *fp = fopen("int_enc_dmx.raw", "ab"); + /*FILE *fp = fopen("int_enc_dmx.raw", "ab"); for (int16_t t = 0; t < 960; t++) { for (int16_t c = 0; c < hSpar->hFbMixer->filterbank_num_out_chans; c++) @@ -824,87 +835,87 @@ static ivas_error ivas_spar_enc_process( } fclose( fp );*/ #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * AGC *-----------------------------------------------------------------------------------------*/ - if ( dtx_vad == 1 ) - { - if ( hSpar->AGC_Enable != 0 ) + if ( dtx_vad == 1 ) { - ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); - } - else - { - /* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is + if ( hSpar->AGC_Enable != 0 ) + { + ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); + } + else + { + /* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is * removed. * On the decoder side, ivas_agc_enc_get_flag could be used instead to determine if AGC is on or not. The * ivas_agc_enc_get_flag function should be moved to ivas_agc_com.c and renamed when this occurs. */ - push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, 0, 1 ); + } } - } #ifdef DEBUG_SBA_AUDIO_DUMP - /* Dump audio signal after ivas_agc_enc_process */ - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[2], "ivas_agc_enc_process()" ); + /* Dump audio signal after ivas_agc_enc_process */ + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[2], "ivas_agc_enc_process()" ); #endif #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC - { - static FILE *fid_enc = 0; - static float delay_buf[576 * 4] = { 0 }; - int16_t smp, ch, buf_idx, framelen = input_frame, delay = 576; - if ( !fid_enc ) { - fid_enc = fopen( "evs_input_float.raw", "wb" ); - } + static FILE *fid_enc = 0; + static float delay_buf[576 * 4] = { 0 }; + int16_t smp, ch, buf_idx, framelen = input_frame, delay = 576; + if ( !fid_enc ) + { + fid_enc = fopen( "evs_input_float.raw", "wb" ); + } - /* write out buffer */ - for ( smp = 0; smp < delay * nchan_transport; smp++ ) - { - fwrite( &delay_buf[smp], sizeof( float ), 1, fid_enc ); - } + /* write out buffer */ + for ( smp = 0; smp < delay * nchan_transport; smp++ ) + { + fwrite( &delay_buf[smp], sizeof( float ), 1, fid_enc ); + } - for ( smp = 0; smp < framelen - delay; smp++ ) - { - for ( ch = 0; ch < nchan_transport; ch++ ) + for ( smp = 0; smp < framelen - delay; smp++ ) { - fwrite( &p_pcm_tmp[ch][smp], sizeof( float ), 1, fid_enc ); + for ( ch = 0; ch < nchan_transport; ch++ ) + { + fwrite( &p_pcm_tmp[ch][smp], sizeof( float ), 1, fid_enc ); + } } - } - /* update delay buffer*/ - buf_idx = 0; - for ( ; smp < framelen; smp++ ) - { - for ( ch = 0; ch < nchan_transport; ch++ ) + /* update delay buffer*/ + buf_idx = 0; + for ( ; smp < framelen; smp++ ) { - delay_buf[buf_idx++] = p_pcm_tmp[ch][smp]; + for ( ch = 0; ch < nchan_transport; ch++ ) + { + delay_buf[buf_idx++] = p_pcm_tmp[ch][smp]; + } } } - } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * Re-order the dmx back to ACN/SN3D format *-----------------------------------------------------------------------------------------*/ - order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; - for ( j = 0; j < nchan_transport; j++ ) - { - mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); - } - for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) - { - set_f( data_f[order[j]], 0.0f, input_frame ); - } + for ( j = 0; j < nchan_transport; j++ ) + { + mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); + } + for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) + { + set_f( data_f[order[j]], 0.0f, input_frame ); + } - pop_wmops(); + pop_wmops(); - /* ToDo: Commented for now */ - /*total_md_bits = hMetaData->nb_bits_tot - start_nb_bits; + /* ToDo: Commented for now */ + /*total_md_bits = hMetaData->nb_bits_tot - start_nb_bits; total_sba_bits = ivas_sba_get_max_md_bits( st_ivas ); assert( total_md_bits <= total_sba_bits );*/ - return error; -} + return error; + } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index dbca3809cc..6fcb722531 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -566,6 +566,10 @@ ivas_error ivas_spar_md_enc_process( const int16_t nchan_inp, const int16_t sba_order, /* i : Ambisonic (SBA) order */ float *prior_mixer[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH] /* i : prior mixer_matrix */ +#ifdef FIX_527_MONO_HEURISTICS + , + int16_t *dirac_mono_flag +#endif ) { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -1005,6 +1009,44 @@ ivas_error ivas_spar_md_enc_process( } } +#ifdef FIX_527_MONO_HEURISTICS + { + *dirac_mono_flag = 1; + for ( b = 0; b < SPAR_DIRAC_SPLIT_START_BAND; b++ ) + { + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + ndec = hMdEnc->spar_md_cfg.num_decorr_per_band[b * bands_bw]; + + for ( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) + { + if ( hMdEnc->spar_md.band_coeffs[b].pred_quant_re[i] != 0.0f ) + { + *dirac_mono_flag = 0; + } + } + + for ( i = 0; i < num_ch - ndm; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + if ( hMdEnc->spar_md.band_coeffs[0].C_quant_re[i][j] != 0.f ) + { + *dirac_mono_flag = 0; + } + } + } + + for ( i = ndm; i < num_ch; i++ ) + { + if ( hMdEnc->spar_md.band_coeffs[0].P_re[i] != 0.f ) + { + *dirac_mono_flag = 0; + } + } + } + } +#endif + #ifdef DEBUGGING if ( dtx_vad == 1 ) { @@ -1976,7 +2018,7 @@ static void ivas_write_parameter_bitstream_dtx( pr -= idx; pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); - value = (uint16_t) ( pr * pd_q_lvls + pd ); + value = ( uint16_t )( pr * pd_q_lvls + pd ); push_next_indice( hMetaData, value, pr_pd_bits ); } @@ -2000,7 +2042,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1]; pr_idx2 -= idx; - value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 ); + value = ( uint16_t )( pr_idx2 * pr_q_lvls1 + pr_idx1 ); pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 ); -- GitLab From bed1365a48316270be299109afabab503cd888f1 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 16 Jun 2023 09:49:45 +0200 Subject: [PATCH 11/17] implement decoder-side part of mono-detection heuristic --- lib_dec/ivas_spar_md_dec.c | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 92e18c5c2c..d6f65cc035 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -678,6 +678,47 @@ void ivas_spar_md_dec_process( ivas_spar_br_table_consts[hMdDec->table_idx].usePlanarCoeff, st_ivas->hQMetaData->sba_inactive_mode, st_ivas->last_active_ivas_total_brate ); +#ifdef FIX_527_MONO_HEURISTICS + { + int16_t ndm, ndec,i,j; + + st_ivas->hQMetaData->dirac_mono_flag = 1; + for ( b = 0; b < SPAR_DIRAC_SPLIT_START_BAND; b++ ) + { + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b * bw]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[b * bw]; + + for ( i = 0; i < DIRAC_TO_SPAR_HBR_PRED_CHS; i++ ) + { + if ( hMdDec->spar_md.band_coeffs[b].pred_quant_re[i] != 0.0f ) + { + st_ivas->hQMetaData->dirac_mono_flag = 0; + } + } + + for ( i = 0; i < num_md_chs - ndm; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + if ( hMdDec->spar_md.band_coeffs[0].C_quant_re[i][j] != 0.f ) + { + st_ivas->hQMetaData->dirac_mono_flag = 0; + } + } + } + + for ( i = ndm; i < num_md_chs; i++ ) + { + if ( hMdDec->spar_md.band_coeffs[0].P_re[i] != 0.f ) + { + st_ivas->hQMetaData->dirac_mono_flag = 0; + } + } + } + } +#endif + + #if 0 { char f_name[100]; -- GitLab From 4d066b7954141d82a573e1ddc17bac7284fda8ec Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 16 Jun 2023 14:31:02 +0200 Subject: [PATCH 12/17] disable code for energy-based mono detection under FIX_527_MONO_HEURISTICS --- lib_com/ivas_prot.h | 4 ++-- lib_com/options.h | 2 +- lib_dec/ivas_dirac_dec.c | 35 ++++++++++++++++++----------------- lib_dec/ivas_spar_md_dec.c | 11 ++++++++++- lib_enc/ivas_dirac_enc.c | 18 +++++++++--------- lib_enc/ivas_mcmasa_enc.c | 2 +- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 54d07c4589..a210df0cf0 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3350,7 +3350,7 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const uint8_t useLowerRes, -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) int16_t *dirac_mono_flag, #endif float data_f[][L_FRAME48k], @@ -5420,7 +5420,7 @@ void computeReferencePower_enc( const IVAS_FORMAT ivas_format, /* i : ivas_format */ int16_t ref_power_w, /* i : use 0 if hodirac is enabled */ const int16_t nchan_ana /* i : number of analysis channels */ -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) , int16_t *dirac_mono_flag #endif diff --git a/lib_com/options.h b/lib_com/options.h index 3c192098ab..f4989c9a4a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #define IGF_TUNING_96 /* FhG: Issue 546: slight tuning of IGF config used in 96 kbps stereo, 128 kbps SBA and others */ #define FIX_527_SBA_MONO_INPUT /* FhG: fix issue 527, artifacts in mono signals coded in SBA mode */ -/*#define FIX_527_MONO_HEURISTICS*/ +#define FIX_527_MONO_HEURISTICS /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index c5785fd58b..d91262eb49 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -391,7 +391,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + 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; @@ -461,7 +461,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + 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 ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -1666,13 +1666,13 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 ); /* 1 bit flag for signaling metadata to read */ b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; #endif @@ -1740,13 +1740,13 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); /* 1 bit flag for SPAR/DirAC, already read in read format function */ b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; #endif @@ -1789,7 +1789,7 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) if ( hQMetaData->dirac_mono_flag ) { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) @@ -1808,6 +1808,7 @@ void ivas_dirac_dec_read_BS( dirac_to_spar_md_bands ); } + return; } @@ -2058,13 +2059,13 @@ void ivas_qmetadata_to_dirac( if ( hodirac_flag ) { - azi = (int16_t) ( azimuth + 0.5f ); - ele = (int16_t) ( elevation + 0.5f ); + 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 ); + 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 ); @@ -2432,10 +2433,10 @@ void ivas_dirac_dec_render_sf( { for ( i = 0; i < output_frame; i++ ) { - tmp[nchan_transport * i + n] = (int16_t) ( output_f[n][i] + 0.5f ); + 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 ) ); + 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 @@ -3981,8 +3982,8 @@ static void computeDirectionAngles( 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 ); + 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; @@ -4267,8 +4268,8 @@ static void rotateAziEle_DirAC( 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 ); + 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(); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index d6f65cc035..922a884176 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -680,7 +680,7 @@ void ivas_spar_md_dec_process( #ifdef FIX_527_MONO_HEURISTICS { - int16_t ndm, ndec,i,j; + int16_t ndm, ndec,i; st_ivas->hQMetaData->dirac_mono_flag = 1; for ( b = 0; b < SPAR_DIRAC_SPLIT_START_BAND; b++ ) @@ -716,6 +716,15 @@ void ivas_spar_md_dec_process( } } } + + if ( st_ivas->hQMetaData->dirac_mono_flag ) + { + for ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } #endif diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index cbcd733387..1209ed4096 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -125,7 +125,7 @@ ivas_error ivas_dirac_enc_open( } } - hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hDirAC->no_col_avg_diff = ( int16_t )( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { if ( ( hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) @@ -307,7 +307,7 @@ void ivas_dirac_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) &hQMetaData->dirac_mono_flag, #endif data_f, @@ -327,7 +327,7 @@ void ivas_dirac_enc( /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) /* flag to indicate a mono input signal */ push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); #endif @@ -369,7 +369,7 @@ void ivas_dirac_enc( /* 1 bit to indicate mode MD coding : temp solution*/ push_next_indice( hMetaData, 1, 1 ); -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) /* flag to indicate a mono input signal */ push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); #endif @@ -431,7 +431,7 @@ void computeReferencePower_enc( const IVAS_FORMAT ivas_format, /* i : ivas_format */ int16_t ref_power_w, /* i : use 0 if hodirac is enabled */ const int16_t nchan_ana /* i : number of analysis channels */ -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) , int16_t *dirac_mono_flag #endif @@ -442,7 +442,7 @@ void computeReferencePower_enc( float reference_power_W[DIRAC_MAX_NBANDS]; -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) if ( dirac_mono_flag != NULL ) { *dirac_mono_flag = 1; @@ -471,7 +471,7 @@ void computeReferencePower_enc( } } -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) if ( reference_power[i] - reference_power_W[i] > EPSILON && dirac_mono_flag != NULL ) { *dirac_mono_flag = 0; @@ -502,7 +502,7 @@ void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, const uint8_t useLowerRes, -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) int16_t *dirac_mono_flag, #endif float data_f[][L_FRAME48k], @@ -620,7 +620,7 @@ void ivas_dirac_param_est_enc( ivas_format, hodirac_flag ? 0 : 1, FOA_CHANNELS -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) , dirac_mono_flag #endif diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index dda0155085..4bd7b0100c 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -980,7 +980,7 @@ void ivas_mcmasa_param_est_enc( MC_FORMAT, 0, FOA_CHANNELS -#ifdef FIX_527_SBA_MONO_INPUT +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) , NULL #endif -- GitLab From acaa4cc550145123ebb8ef8df79c7d8a4b06f1f3 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 16 Jun 2023 15:23:27 +0200 Subject: [PATCH 13/17] set mono flag based on SPAR data in previous frame --- lib_com/ivas_qmetadata_com.c | 4 ++++ lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_spar_md_dec.c | 23 +++++++++-------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 32b4653d2f..d580149d41 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -74,6 +74,10 @@ ivas_error ivas_qmetadata_open( ( *hQMetaData )->surcoh_band_data = NULL; ( *hQMetaData )->bandMap = NULL; +#ifdef FIX_527_MONO_HEURISTICS + ( *hQMetaData )->dirac_mono_flag = 0; +#endif + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index d91262eb49..7d6e9a29c8 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1789,7 +1789,7 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) +#if defined( FIX_527_SBA_MONO_INPUT ) if ( hQMetaData->dirac_mono_flag ) { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 922a884176..9a72324251 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -680,9 +680,12 @@ void ivas_spar_md_dec_process( #ifdef FIX_527_MONO_HEURISTICS { - int16_t ndm, ndec,i; + int16_t lmf; + int16_t ndm; + int16_t ndec; + int16_t i; - st_ivas->hQMetaData->dirac_mono_flag = 1; + lmf = 1; for ( b = 0; b < SPAR_DIRAC_SPLIT_START_BAND; b++ ) { ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b * bw]; @@ -692,7 +695,7 @@ void ivas_spar_md_dec_process( { if ( hMdDec->spar_md.band_coeffs[b].pred_quant_re[i] != 0.0f ) { - st_ivas->hQMetaData->dirac_mono_flag = 0; + lmf = 0; } } @@ -702,7 +705,7 @@ void ivas_spar_md_dec_process( { if ( hMdDec->spar_md.band_coeffs[0].C_quant_re[i][j] != 0.f ) { - st_ivas->hQMetaData->dirac_mono_flag = 0; + lmf = 0; } } } @@ -711,19 +714,11 @@ void ivas_spar_md_dec_process( { if ( hMdDec->spar_md.band_coeffs[0].P_re[i] != 0.f ) { - st_ivas->hQMetaData->dirac_mono_flag = 0; + lmf = 0; } } } - } - - if ( st_ivas->hQMetaData->dirac_mono_flag ) - { - for ( b = 0; b < st_ivas->hQMetaData->q_direction[0].cfg.nbands; b++ ) - { - set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); - set_zero( st_ivas->hQMetaData->q_direction[0].band_data[b].energy_ratio, MAX_PARAM_SPATIAL_SUBFRAMES ); - } + st_ivas->hQMetaData->dirac_mono_flag = lmf; } #endif -- GitLab From da35a8c801ce70a6add785573435f54fae53e68f Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 16 Jun 2023 15:34:25 +0200 Subject: [PATCH 14/17] disable FIX_527_MONO_HEURISTICS --- 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 f4989c9a4a..3c192098ab 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,7 +160,7 @@ #define IGF_TUNING_96 /* FhG: Issue 546: slight tuning of IGF config used in 96 kbps stereo, 128 kbps SBA and others */ #define FIX_527_SBA_MONO_INPUT /* FhG: fix issue 527, artifacts in mono signals coded in SBA mode */ -#define FIX_527_MONO_HEURISTICS +/*#define FIX_527_MONO_HEURISTICS*/ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ -- GitLab From 5a84a44a26b8da15de5c8d65bedfdf8c4d6ba339 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 16 Jun 2023 15:56:22 +0200 Subject: [PATCH 15/17] fix formatting --- lib_dec/ivas_dirac_dec.c | 30 ++-- lib_dec/ivas_spar_md_dec.c | 4 +- lib_enc/ivas_dirac_enc.c | 2 +- lib_enc/ivas_spar_encoder.c | 348 ++++++++++++++++++------------------ lib_enc/ivas_spar_md_enc.c | 4 +- 5 files changed, 194 insertions(+), 194 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 7d6e9a29c8..8250480f07 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -391,7 +391,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->slot_size = ( int16_t )( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); + 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; @@ -461,7 +461,7 @@ ivas_error ivas_dirac_dec_config( if ( flag_config == DIRAC_OPEN ) { - hDirAC->num_freq_bands = ( int16_t )( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + 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 ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -1666,7 +1666,7 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); /* 1 bit flag for signaling metadata to read */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -1740,7 +1740,7 @@ void ivas_dirac_dec_read_BS( 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 ); + st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); /* 1 bit flag for SPAR/DirAC, already read in read format function */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -1789,7 +1789,7 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } -#if defined( FIX_527_SBA_MONO_INPUT ) +#if defined( FIX_527_SBA_MONO_INPUT ) if ( hQMetaData->dirac_mono_flag ) { for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) @@ -2059,13 +2059,13 @@ void ivas_qmetadata_to_dirac( if ( hodirac_flag ) { - azi = ( int16_t )( azimuth + 0.5f ); - ele = ( int16_t )( elevation + 0.5f ); + 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 ); + 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 ); @@ -2433,10 +2433,10 @@ void ivas_dirac_dec_render_sf( { for ( i = 0; i < output_frame; i++ ) { - tmp[nchan_transport * i + n] = ( int16_t )( output_f[n][i] + 0.5f ); + 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 ) ); + 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 @@ -3982,8 +3982,8 @@ static void computeDirectionAngles( 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 ); + 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; @@ -4268,8 +4268,8 @@ static void rotateAziEle_DirAC( 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 ); + 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(); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 9a72324251..c833b5b013 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -682,8 +682,8 @@ void ivas_spar_md_dec_process( { int16_t lmf; int16_t ndm; - int16_t ndec; - int16_t i; + int16_t ndec; + int16_t i; lmf = 1; for ( b = 0; b < SPAR_DIRAC_SPLIT_START_BAND; b++ ) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 1209ed4096..310765f083 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -125,7 +125,7 @@ ivas_error ivas_dirac_enc_open( } } - hDirAC->no_col_avg_diff = ( int16_t )( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); + hDirAC->no_col_avg_diff = (int16_t) ( DIRAC_NO_COL_AVG_DIFF_NS / dirac_slot_ns ); for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) { if ( ( hDirAC->buffer_intensity_real[i] = (float **) malloc( hDirAC->no_col_avg_diff * sizeof( float * ) ) ) == NULL ) diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index e5ece388f9..d945569321 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -426,7 +426,7 @@ static ivas_error ivas_spar_enc_process( ivas_total_brate = hEncoderConfig->ivas_total_brate; num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; - input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); @@ -582,7 +582,7 @@ static ivas_error ivas_spar_enc_process( , &hQMetaData->dirac_mono_flag #endif - ); + ); } if ( hSpar->hMdEnc->spar_hoa_dirac2spar_md_flag ) @@ -630,142 +630,142 @@ static ivas_error ivas_spar_enc_process( if ( hSpar->hMdEnc->spar_hoa_md_flag ) { - ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer + ivas_spar_md_enc_process( hSpar->hMdEnc, hEncoderConfig, cov_real, cov_dtx_real, hMetaData, dtx_vad, nchan_inp, sba_order, hSpar->hFbMixer->prior_mixer #ifdef FIX_527_MONO_HEURISTICS , &hQMetaData->dirac_mono_flag #endif - ); + ); } #ifdef DEBUG_LBR_SBA - /* Dumping SPAR Coefficients */ - char f_name[100]; - int16_t nbands = 6; - int16_t num_subframes = 1; - int16_t num_elements = 6; - int16_t num_block_group = 1; - int16_t byte_size = sizeof( float ); - - sprintf( f_name, "SBA_MD_values.bin" ); - ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - - for ( b = 0; b < nbands; b++ ) + /* Dumping SPAR Coefficients */ + char f_name[100]; + int16_t nbands = 6; + int16_t num_subframes = 1; + int16_t num_elements = 6; + int16_t num_block_group = 1; + int16_t byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) { - for ( int16_t sf = 0; sf < num_subframes; sf++ ) + for ( int16_t bl = 0; bl < num_block_group; bl++ ) { - for ( int16_t bl = 0; bl < num_block_group; bl++ ) - { - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); - // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); - } + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); } } + } #endif #ifdef DEBUG_LBR_SBA - /* Dumping SPAR Coefficients */ - nbands = 6; - num_subframes = 1; - num_elements = 6; - num_block_group = 1; - byte_size = sizeof( float ); - - sprintf( f_name, "SBA_MD_values_quant.bin" ); - ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; - ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; - - for ( b = 0; b < nbands; b++ ) + /* Dumping SPAR Coefficients */ + nbands = 6; + num_subframes = 1; + num_elements = 6; + num_block_group = 1; + byte_size = sizeof( float ); + + sprintf( f_name, "SBA_MD_values_quant.bin" ); + ( frame == 0 ) ? dbgwrite( &nbands, sizeof( nbands ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_elements, sizeof( num_elements ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_subframes, sizeof( num_subframes ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &num_block_group, sizeof( num_block_group ), 1, 1, f_name ) : false; + ( frame == 0 ) ? dbgwrite( &byte_size, sizeof( byte_size ), 1, 1, f_name ) : false; + + for ( b = 0; b < nbands; b++ ) + { + for ( int16_t sf = 0; sf < num_subframes; sf++ ) { - for ( int16_t sf = 0; sf < num_subframes; sf++ ) + for ( int16_t bl = 0; bl < num_block_group; bl++ ) { - for ( int16_t bl = 0; bl < num_block_group; bl++ ) - { - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[2], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[0], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[1], byte_size, 1, 1, f_name ); - dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[2], byte_size, 1, 1, f_name ); - // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); - } + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].pred_quant_re[2], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[0], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[1], byte_size, 1, 1, f_name ); + dbgwrite( &hSpar->hMdEnc->spar_md.band_coeffs[b].P_quant_re[2], byte_size, 1, 1, f_name ); + // fprintf(stdout, "%f\t%f\t%f\t%d\t%d\n", dirac_md_kbps, spar_md_kbps, sba_md_kbps, qsi, code_strat ); } } + } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * FB mixer *-----------------------------------------------------------------------------------------*/ - ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); + ivas_fb_mixer_get_in_out_mapping( hSpar->hFbMixer->fb_cfg, nchan_transport, ENC, remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order], in_out_mixer_map ); #ifdef DEBUG_SBA_MD_DUMP - { - int16_t k; - static FILE *f_mat = 0; + { + int16_t k; + static FILE *f_mat = 0; - if ( f_mat == 0 ) - f_mat = fopen( "mixer_mat_enc", "w" ); + if ( f_mat == 0 ) + f_mat = fopen( "mixer_mat_enc", "w" ); - for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + for ( i = 0; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) { - for ( j = 0; j < hSpar->hFbMixer->fb_cfg->num_in_chans; j++ ) + for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) { - for ( k = 0; k < hSpar->hFbMixer->pFb->filterbank_num_bands; k++ ) - { - fprintf( f_mat, "%f\n", hSpar->hMdEnc->mixer_mat[i][j][k] ); + fprintf( f_mat, "%f\n", hSpar->hMdEnc->mixer_mat[i][j][k] ); - if ( ( in_out_mixer_map[i][j] == 0 ) && ( fabs( hSpar->hMdEnc->mixer_mat[i][j][k] ) > 1e-20 ) ) - { - assert( 0 && "Non zero value in unexpected mixer map!!!" ); - } + if ( ( in_out_mixer_map[i][j] == 0 ) && ( fabs( hSpar->hMdEnc->mixer_mat[i][j][k] ) > 1e-20 ) ) + { + assert( 0 && "Non zero value in unexpected mixer map!!!" ); } } } } + } #endif #ifdef DEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PARS + { + static FILE *fid = 0; + int16_t band = 9; + if ( !fid ) { - static FILE *fid = 0; - int16_t band = 9; - if ( !fid ) - { - fid = fopen( "pred_coeffs_enc.txt", "wt" ); - } - fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); + fid = fopen( "pred_coeffs_enc.txt", "wt" ); } + fprintf( fid, "%.6f\n", hSpar->hMdEnc->mixer_mat[1][0][band] ); + } #endif - ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); + ivas_fb_mixer_process( hSpar->hFbMixer, hSpar->hMdEnc->mixer_mat, p_pcm_tmp, input_frame, in_out_mixer_map ); #ifdef DEBUG_SBA_AUDIO_DUMP - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[1], "ivas_fb_mixer_process()" ); + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[1], "ivas_fb_mixer_process()" ); #endif - if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) - { - /* delayed W */ - mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); - mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); + if ( hSpar->hFbMixer->fb_cfg->active_w_mixing == 0 ) + { + /* delayed W */ + mvr2r( wyzx_del_buf[0], p_pcm_tmp[0], num_del_samples ); + mvr2r( data_f[0], p_pcm_tmp[0] + num_del_samples, input_frame - num_del_samples ); - for ( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) - { - int idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; + for ( i = 1; i < hSpar->hFbMixer->fb_cfg->num_out_chans; i++ ) + { + int idx = hSpar->hFbMixer->fb_cfg->remix_order[i]; - /* delayed, reorderd and accumulated with (negative) prediction from W */ - v_add( wyzx_del_buf[idx], p_pcm_tmp[i], p_pcm_tmp[i], num_del_samples ); - v_add( data_f[idx], p_pcm_tmp[i] + num_del_samples, p_pcm_tmp[i] + num_del_samples, input_frame - num_del_samples ); - } + /* delayed, reorderd and accumulated with (negative) prediction from W */ + v_add( wyzx_del_buf[idx], p_pcm_tmp[i], p_pcm_tmp[i], num_del_samples ); + v_add( data_f[idx], p_pcm_tmp[i] + num_del_samples, p_pcm_tmp[i] + num_del_samples, input_frame - num_del_samples ); } + } #if 0 /* SBA_TD_RESIDUAL */ { @@ -790,132 +790,132 @@ static ivas_error ivas_spar_enc_process( } } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * PCA encoder *-----------------------------------------------------------------------------------------*/ - if ( hSpar->hPCA != NULL ) - { - ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); - } - else + if ( hSpar->hPCA != NULL ) + { + ivas_pca_enc( hEncoderConfig, hSpar->hPCA, hMetaData, p_pcm_tmp, input_frame, FOA_CHANNELS ); + } + else + { + if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) { - if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) - { - /* write PCA bypass bit */ - push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); - } + /* write PCA bypass bit */ + push_next_indice( hMetaData, PCA_MODE_INACTIVE, 1 ); } + } #ifdef DEBUG_LBR_SBA - for ( int t = 0; t < 960; t++ ) + for ( int t = 0; t < 960; t++ ) + { + for ( int c = 0; c < hSpar->hFbMixer->fb_cfg->num_out_chans; c++ ) { - for ( int c = 0; c < hSpar->hFbMixer->fb_cfg->num_out_chans; c++ ) - { - float val = p_pcm_tmp[c][t]; // / MAX16B_FLT; - dbgwrite( &val, sizeof( float ), 1, 1, "int_enc_dmx.raw" ); - } + float val = p_pcm_tmp[c][t]; // / MAX16B_FLT; + dbgwrite( &val, sizeof( float ), 1, 1, "int_enc_dmx.raw" ); } + } #endif #ifdef DEBUG_SBA_AUDIO_DUMP - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[0], "ivas_pca_enc()" ); + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[0], "ivas_pca_enc()" ); #endif #ifdef SPAR_HOA_DBG - /*FILE *fp = fopen("int_enc_dmx.raw", "ab"); - for (int16_t t = 0; t < 960; t++) + /*FILE *fp = fopen("int_enc_dmx.raw", "ab"); +for (int16_t t = 0; t < 960; t++) +{ + for (int16_t c = 0; c < hSpar->hFbMixer->filterbank_num_out_chans; c++) { - for (int16_t c = 0; c < hSpar->hFbMixer->filterbank_num_out_chans; c++) + for ( k = 0; k < 2; k++ ) { - for ( k = 0; k < 2; k++ ) - { - fb_mixer_in_buf.ppMixer[i][j][k] = hSpar->hMdEnc->mixer_mat[i][j]; - } + fb_mixer_in_buf.ppMixer[i][j][k] = hSpar->hMdEnc->mixer_mat[i][j]; } } - fclose( fp );*/ +} +fclose( fp );*/ #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * AGC *-----------------------------------------------------------------------------------------*/ - if ( dtx_vad == 1 ) + if ( dtx_vad == 1 ) + { + if ( hSpar->AGC_Enable != 0 ) { - if ( hSpar->AGC_Enable != 0 ) - { - ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); - } - else - { - /* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is + ivas_agc_enc_process( hSpar->hAgcEnc, hMetaData, p_pcm_tmp, p_pcm_tmp, hSpar->hFbMixer->fb_cfg->num_out_chans, hEncoderConfig ); + } + else + { + /* IVAS_fmToDo: This AGC on/off bit should be removed when the command line option to force enable/disable AGC is * removed. * On the decoder side, ivas_agc_enc_get_flag could be used instead to determine if AGC is on or not. The * ivas_agc_enc_get_flag function should be moved to ivas_agc_com.c and renamed when this occurs. */ - push_next_indice( hMetaData, 0, 1 ); - } + push_next_indice( hMetaData, 0, 1 ); } + } #ifdef DEBUG_SBA_AUDIO_DUMP - /* Dump audio signal after ivas_agc_enc_process */ - ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[2], "ivas_agc_enc_process()" ); + /* Dump audio signal after ivas_agc_enc_process */ + ivas_spar_dump_signal_wav( input_frame, p_pcm_tmp, NULL, nchan_transport, spar_foa_enc_wav[2], "ivas_agc_enc_process()" ); #endif #ifdef DEBUG_SPAR_BYPASS_EVS_CODEC + { + static FILE *fid_enc = 0; + static float delay_buf[576 * 4] = { 0 }; + int16_t smp, ch, buf_idx, framelen = input_frame, delay = 576; + if ( !fid_enc ) { - static FILE *fid_enc = 0; - static float delay_buf[576 * 4] = { 0 }; - int16_t smp, ch, buf_idx, framelen = input_frame, delay = 576; - if ( !fid_enc ) - { - fid_enc = fopen( "evs_input_float.raw", "wb" ); - } + fid_enc = fopen( "evs_input_float.raw", "wb" ); + } - /* write out buffer */ - for ( smp = 0; smp < delay * nchan_transport; smp++ ) - { - fwrite( &delay_buf[smp], sizeof( float ), 1, fid_enc ); - } + /* write out buffer */ + for ( smp = 0; smp < delay * nchan_transport; smp++ ) + { + fwrite( &delay_buf[smp], sizeof( float ), 1, fid_enc ); + } - for ( smp = 0; smp < framelen - delay; smp++ ) + for ( smp = 0; smp < framelen - delay; smp++ ) + { + for ( ch = 0; ch < nchan_transport; ch++ ) { - for ( ch = 0; ch < nchan_transport; ch++ ) - { - fwrite( &p_pcm_tmp[ch][smp], sizeof( float ), 1, fid_enc ); - } + fwrite( &p_pcm_tmp[ch][smp], sizeof( float ), 1, fid_enc ); } + } - /* update delay buffer*/ - buf_idx = 0; - for ( ; smp < framelen; smp++ ) + /* update delay buffer*/ + buf_idx = 0; + for ( ; smp < framelen; smp++ ) + { + for ( ch = 0; ch < nchan_transport; ch++ ) { - for ( ch = 0; ch < nchan_transport; ch++ ) - { - delay_buf[buf_idx++] = p_pcm_tmp[ch][smp]; - } + delay_buf[buf_idx++] = p_pcm_tmp[ch][smp]; } } + } #endif - /*-----------------------------------------------------------------------------------------* + /*-----------------------------------------------------------------------------------------* * Re-order the dmx back to ACN/SN3D format *-----------------------------------------------------------------------------------------*/ - order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; - for ( j = 0; j < nchan_transport; j++ ) - { - mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); - } - for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) - { - set_f( data_f[order[j]], 0.0f, input_frame ); - } + for ( j = 0; j < nchan_transport; j++ ) + { + mvr2r( p_pcm_tmp[j], data_f[order[j]], input_frame ); + } + for ( ; j < IVAS_SPAR_MAX_DMX_CHS; j++ ) + { + set_f( data_f[order[j]], 0.0f, input_frame ); + } - pop_wmops(); + pop_wmops(); - /* ToDo: Commented for now */ - /*total_md_bits = hMetaData->nb_bits_tot - start_nb_bits; - total_sba_bits = ivas_sba_get_max_md_bits( st_ivas ); - assert( total_md_bits <= total_sba_bits );*/ + /* ToDo: Commented for now */ + /*total_md_bits = hMetaData->nb_bits_tot - start_nb_bits; +total_sba_bits = ivas_sba_get_max_md_bits( st_ivas ); +assert( total_md_bits <= total_sba_bits );*/ - return error; - } + return error; +} diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 6fcb722531..11b14b24e3 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -2018,7 +2018,7 @@ static void ivas_write_parameter_bitstream_dtx( pr -= idx; pr_pd_bits = ivas_get_bits_to_encode( pd_q_lvls * pr_q_lvls ); - value = ( uint16_t )( pr * pd_q_lvls + pd ); + value = (uint16_t) ( pr * pd_q_lvls + pd ); push_next_indice( hMetaData, value, pr_pd_bits ); } @@ -2042,7 +2042,7 @@ static void ivas_write_parameter_bitstream_dtx( pr_idx2 = pSpar_md->band_coeffs_idx[i].pred_index_re[pr_idx_2 - 1]; pr_idx2 -= idx; - value = ( uint16_t )( pr_idx2 * pr_q_lvls1 + pr_idx1 ); + value = (uint16_t) ( pr_idx2 * pr_q_lvls1 + pr_idx1 ); pr_pr_bits = ivas_get_bits_to_encode( pr_q_lvls1 * pr_q_lvls2 ); -- GitLab From 6e2b1c2cf80070f456123ea2b288e4f2c225ef6d Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 19 Jun 2023 15:57:18 +0200 Subject: [PATCH 16/17] implement mono signaling via the sba_order bits under FIX_527_SBA_MONO_INPUT_ORDER_BIT, currently disabled --- lib_com/bitstream.c | 22 +++++++++++----------- lib_com/ivas_qmetadata_com.c | 2 +- lib_com/options.h | 2 ++ lib_dec/ivas_dirac_dec.c | 4 ++-- lib_dec/ivas_init_dec.c | 26 +++++++++++++++++++++++--- lib_dec/ivas_stat_dec.h | 4 ++++ lib_enc/ivas_dirac_enc.c | 4 ++-- lib_enc/ivas_enc.c | 13 +++++++++++-- 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index a95775590a..bb561cc4e3 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -259,7 +259,7 @@ ivas_error ind_list_realloc( } /* get the current position inside the old list */ - ind_list_pos = (int16_t) ( hBstr->ind_list - ( *hBstr->ivas_ind_list_zero ) ); + ind_list_pos = ( int16_t )( hBstr->ind_list - ( *hBstr->ivas_ind_list_zero ) ); /* free the old list */ free( ( *hBstr->ivas_ind_list_zero ) ); @@ -1304,7 +1304,7 @@ void push_next_bits( for ( i = 0; i < nb_bits_m15; i += 16 ) { - code = (uint16_t) ( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); + code = ( uint16_t )( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); #ifdef IND_LIST_DYN /* check the limits of the list of indices */ @@ -1359,7 +1359,7 @@ void push_next_bits( } #ifndef IND_LIST_DYN - hBstr->next_ind = (int16_t) ( ptr - hBstr->ind_list ); + hBstr->next_ind = ( int16_t )( ptr - hBstr->ind_list ); #endif hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits; @@ -2061,7 +2061,7 @@ ivas_error write_indices_ivas( write_indices_element( st_ivas, &pt_stream, 0, n ); } - *num_bits = (uint16_t) ( pt_stream - bit_stream ); + *num_bits = ( uint16_t )( pt_stream - bit_stream ); return error; } @@ -2830,7 +2830,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hSCE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += (int16_t) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += ( int16_t )( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); } /* set bitstream pointers for CPEs */ @@ -2838,7 +2838,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hCPE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += (int16_t) ( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += ( int16_t )( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); } return; @@ -2868,7 +2868,7 @@ ivas_error preview_indices( error = IVAS_ERR_OK; /* convert the frame length to total bitrate */ - total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC ); + total_brate = ( int32_t )( num_bits * FRAMES_PER_SEC ); if ( st_ivas->ivas_format != MONO_FORMAT && is_DTXrate( total_brate ) == 0 ) { @@ -3034,7 +3034,7 @@ ivas_error preview_indices( /* read number of objects from the bitstream */ st_ivas->nchan_transport = 1; - k = (int16_t) ( ( total_brate / FRAMES_PER_SEC ) - 1 ); + k = ( int16_t )( ( total_brate / FRAMES_PER_SEC ) - 1 ); while ( bit_stream[k] == 1 && st_ivas->nchan_transport < MAX_NUM_OBJECTS ) { st_ivas->nchan_transport++; @@ -3112,7 +3112,7 @@ ivas_error read_indices( #endif /* convert the frame length to total bitrate */ - total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC ); + total_brate = ( int32_t )( num_bits * FRAMES_PER_SEC ); /* verify that a valid num bits value is present in the G.192 file */ /* only AMRWB, EVS or IVAS bitrates or 0(NO DATA) are allowed in G.192 file frame reading */ @@ -3529,7 +3529,7 @@ static void get_rfFrameType( ) { int16_t num_bits; - num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); + num_bits = ( int16_t )( st->total_brate / FRAMES_PER_SEC ); if ( st->rf_flag == 1 ) { /* the last three bits in a packet is the RF frame type */ @@ -3610,7 +3610,7 @@ static void get_rf_fec_offset( ) { int16_t num_bits, tmp; - num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); + num_bits = ( int16_t )( st->total_brate / FRAMES_PER_SEC ); if ( st->rf_flag == 1 ) { /* the two bits before the RF frame type contains the FEC offset */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index d580149d41..57f9e75bc7 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -74,7 +74,7 @@ ivas_error ivas_qmetadata_open( ( *hQMetaData )->surcoh_band_data = NULL; ( *hQMetaData )->bandMap = NULL; -#ifdef FIX_527_MONO_HEURISTICS +#if defined( FIX_527_MONO_HEURISTICS ) || defined(FIX_527_SBA_MONO_INPUT_ORDER_BIT) ( *hQMetaData )->dirac_mono_flag = 0; #endif diff --git a/lib_com/options.h b/lib_com/options.h index 634eec11f5..498b17ef2b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,8 @@ #define FIX_527_SBA_MONO_INPUT /* FhG: fix issue 527, artifacts in mono signals coded in SBA mode */ /*#define FIX_527_MONO_HEURISTICS*/ +/*#define FIX_527_SBA_MONO_INPUT_ORDER_BIT*/ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 8250480f07..b54bb4aa39 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1672,7 +1672,7 @@ void ivas_dirac_dec_read_BS( b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; #endif @@ -1746,7 +1746,7 @@ void ivas_dirac_dec_read_BS( b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b746baf47b..6ddedc08fb 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -105,7 +105,7 @@ ivas_error ivas_dec_setup( /* read the number of objects */ st_ivas->nchan_transport = 1; nchan_ism = 1; - k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + k = ( int16_t )( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) { nchan_ism++; @@ -129,6 +129,26 @@ ivas_error ivas_dec_setup( st_ivas->sba_order = st_ivas->bit_stream[num_bits_read + 1]; st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; +#ifdef FIX_527_SBA_MONO_INPUT_ORDER_BIT + if ( st_ivas->hQMetaData != NULL ) + { + st_ivas->hQMetaData->dirac_mono_flag = 0; + if ( st_ivas->sba_order == 0 ) + { + st_ivas->hQMetaData->dirac_mono_flag = 1; + st_ivas->sba_order = st_ivas->sba_order_nonmono; + } + else + { + st_ivas->sba_order_nonmono = st_ivas->sba_order; + } + } + else + { + st_ivas->sba_order_nonmono = st_ivas->sba_order; + } +#endif + /* set Ambisonic (SBA) order used for analysis and coding */ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); @@ -453,7 +473,7 @@ static ivas_error ivas_read_format( if ( st_ivas->ivas_format == SBA_FORMAT ) { int16_t tc_mode_offset; - tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); + tc_mode_offset = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 ); idx = st_ivas->bit_stream[tc_mode_offset]; if ( st_ivas->sba_analysis_order == 0 ) { @@ -921,7 +941,7 @@ ivas_error ivas_init_decoder( st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; } - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + 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 ); diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 27375db6fa..2de4edc8f5 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -1320,6 +1320,10 @@ typedef struct Decoder_Struct int16_t ism_extmeta_active; /* Extended metadata active in decoder */ int16_t ism_extmeta_cnt; /* Change frame counter for extended metadata */ +#ifdef FIX_527_SBA_MONO_INPUT_ORDER_BIT + int16_t sba_order_nonmono; +#endif + } Decoder_Struct; /* clang-format on */ diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 310765f083..66bf0b3d88 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -327,7 +327,7 @@ void ivas_dirac_enc( /* WB 4TC mode bit : disable for now*/ push_next_indice( hMetaData, 0, 1 ); -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) /* flag to indicate a mono input signal */ push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); #endif @@ -369,7 +369,7 @@ void ivas_dirac_enc( /* 1 bit to indicate mode MD coding : temp solution*/ push_next_indice( hMetaData, 1, 1 ); -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) /* flag to indicate a mono input signal */ push_next_indice( hMetaData, hQMetaData->dirac_mono_flag, 1 ); #endif diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index da553657a9..39a45f979c 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -80,7 +80,7 @@ ivas_error ivas_enc( nchan_inp = hEncoderConfig->nchan_inp; ivas_total_brate = hEncoderConfig->ivas_total_brate; - input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); + input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE ); @@ -207,7 +207,16 @@ ivas_error ivas_enc( push_indice( st->hBstr, IND_SMODE, hEncoderConfig->sba_planar, SBA_PLANAR_BITS ); /* Write SBA order */ - push_indice( st->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); +#ifdef FIX_527_SBA_MONO_INPUT_ORDER_BIT + if ( st_ivas->hQMetaData->dirac_mono_flag == 1 ) + { + push_indice( st->hBstr, IND_SMODE, 0, SBA_ORDER_BITS ); + } + else +#endif + { + push_indice( st->hBstr, IND_SMODE, hEncoderConfig->sba_order, SBA_ORDER_BITS ); + } } else { -- GitLab From 7b9fafa367c5262029a25ea2e1941ba874222fa5 Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Mon, 19 Jun 2023 16:03:45 +0200 Subject: [PATCH 17/17] fix formatting --- lib_com/bitstream.c | 22 +++++++++++----------- lib_com/ivas_qmetadata_com.c | 2 +- lib_dec/ivas_dirac_dec.c | 2 +- lib_dec/ivas_init_dec.c | 6 +++--- lib_enc/ivas_enc.c | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index bb561cc4e3..a95775590a 100755 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -259,7 +259,7 @@ ivas_error ind_list_realloc( } /* get the current position inside the old list */ - ind_list_pos = ( int16_t )( hBstr->ind_list - ( *hBstr->ivas_ind_list_zero ) ); + ind_list_pos = (int16_t) ( hBstr->ind_list - ( *hBstr->ivas_ind_list_zero ) ); /* free the old list */ free( ( *hBstr->ivas_ind_list_zero ) ); @@ -1304,7 +1304,7 @@ void push_next_bits( for ( i = 0; i < nb_bits_m15; i += 16 ) { - code = ( uint16_t )( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); + code = (uint16_t) ( ( bits[i] << 15 ) | ( ( bits[i + 1] << 14 ) | ( ( bits[i + 2] << 13 ) | ( ( bits[i + 3] << 12 ) | ( ( bits[i + 4] << 11 ) | ( ( bits[i + 5] << 10 ) | ( ( bits[i + 6] << 9 ) | ( ( bits[i + 7] << 8 ) | ( ( bits[i + 8] << 7 ) | ( ( bits[i + 9] << 6 ) | ( ( bits[i + 10] << 5 ) | ( ( bits[i + 11] << 4 ) | ( ( bits[i + 12] << 3 ) | ( ( bits[i + 13] << 2 ) | ( ( bits[i + 14] << 1 ) | bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) ); #ifdef IND_LIST_DYN /* check the limits of the list of indices */ @@ -1359,7 +1359,7 @@ void push_next_bits( } #ifndef IND_LIST_DYN - hBstr->next_ind = ( int16_t )( ptr - hBstr->ind_list ); + hBstr->next_ind = (int16_t) ( ptr - hBstr->ind_list ); #endif hBstr->nb_bits_tot = hBstr->nb_bits_tot + nb_bits; @@ -2061,7 +2061,7 @@ ivas_error write_indices_ivas( write_indices_element( st_ivas, &pt_stream, 0, n ); } - *num_bits = ( uint16_t )( pt_stream - bit_stream ); + *num_bits = (uint16_t) ( pt_stream - bit_stream ); return error; } @@ -2830,7 +2830,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hSCE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += ( int16_t )( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += (int16_t) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); } /* set bitstream pointers for CPEs */ @@ -2838,7 +2838,7 @@ void ivas_set_bitstream_pointers( { sts = st_ivas->hCPE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; - num_bits += ( int16_t )( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); + num_bits += (int16_t) ( st_ivas->hCPE[k]->element_brate / FRAMES_PER_SEC ); } return; @@ -2868,7 +2868,7 @@ ivas_error preview_indices( error = IVAS_ERR_OK; /* convert the frame length to total bitrate */ - total_brate = ( int32_t )( num_bits * FRAMES_PER_SEC ); + total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC ); if ( st_ivas->ivas_format != MONO_FORMAT && is_DTXrate( total_brate ) == 0 ) { @@ -3034,7 +3034,7 @@ ivas_error preview_indices( /* read number of objects from the bitstream */ st_ivas->nchan_transport = 1; - k = ( int16_t )( ( total_brate / FRAMES_PER_SEC ) - 1 ); + k = (int16_t) ( ( total_brate / FRAMES_PER_SEC ) - 1 ); while ( bit_stream[k] == 1 && st_ivas->nchan_transport < MAX_NUM_OBJECTS ) { st_ivas->nchan_transport++; @@ -3112,7 +3112,7 @@ ivas_error read_indices( #endif /* convert the frame length to total bitrate */ - total_brate = ( int32_t )( num_bits * FRAMES_PER_SEC ); + total_brate = (int32_t) ( num_bits * FRAMES_PER_SEC ); /* verify that a valid num bits value is present in the G.192 file */ /* only AMRWB, EVS or IVAS bitrates or 0(NO DATA) are allowed in G.192 file frame reading */ @@ -3529,7 +3529,7 @@ static void get_rfFrameType( ) { int16_t num_bits; - num_bits = ( int16_t )( st->total_brate / FRAMES_PER_SEC ); + num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); if ( st->rf_flag == 1 ) { /* the last three bits in a packet is the RF frame type */ @@ -3610,7 +3610,7 @@ static void get_rf_fec_offset( ) { int16_t num_bits, tmp; - num_bits = ( int16_t )( st->total_brate / FRAMES_PER_SEC ); + num_bits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); if ( st->rf_flag == 1 ) { /* the two bits before the RF frame type contains the FEC offset */ diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index 57f9e75bc7..65ae24da1d 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -74,7 +74,7 @@ ivas_error ivas_qmetadata_open( ( *hQMetaData )->surcoh_band_data = NULL; ( *hQMetaData )->bandMap = NULL; -#if defined( FIX_527_MONO_HEURISTICS ) || defined(FIX_527_SBA_MONO_INPUT_ORDER_BIT) +#if defined( FIX_527_MONO_HEURISTICS ) || defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) ( *hQMetaData )->dirac_mono_flag = 0; #endif diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index b54bb4aa39..fe62b8bef8 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1746,7 +1746,7 @@ void ivas_dirac_dec_read_BS( b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; -#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) +#if defined( FIX_527_SBA_MONO_INPUT ) && !defined( FIX_527_MONO_HEURISTICS ) && !defined( FIX_527_SBA_MONO_INPUT_ORDER_BIT ) hQMetaData->dirac_mono_flag = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 6ddedc08fb..7d22ac3ae6 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -105,7 +105,7 @@ ivas_error ivas_dec_setup( /* read the number of objects */ st_ivas->nchan_transport = 1; nchan_ism = 1; - k = ( int16_t )( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) { nchan_ism++; @@ -473,7 +473,7 @@ static ivas_error ivas_read_format( if ( st_ivas->ivas_format == SBA_FORMAT ) { int16_t tc_mode_offset; - tc_mode_offset = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 ); + tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); idx = st_ivas->bit_stream[tc_mode_offset]; if ( st_ivas->sba_analysis_order == 0 ) { @@ -941,7 +941,7 @@ ivas_error ivas_init_decoder( st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; } - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, ( int16_t )( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + 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 ); diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index 39a45f979c..e356794719 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -80,7 +80,7 @@ ivas_error ivas_enc( nchan_inp = hEncoderConfig->nchan_inp; ivas_total_brate = hEncoderConfig->ivas_total_brate; - input_frame = ( int16_t )( input_Fs / FRAMES_PER_SEC ); + input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); n_samples_chan = n_samples / nchan_inp; set_s( nb_bits_metadata, 0, MAX_SCE ); -- GitLab