From f776073315601cbe2952b0c7542e2c4b76c781cc Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Sep 2024 18:12:51 +0200 Subject: [PATCH 01/27] fix memory issue when HRTFs are loaded from a binary file; under FIX_HRTF_LOAD --- apps/decoder.c | 262 ++++++++++++++++++++++++++ lib_com/common_api_types.h | 3 + lib_com/ivas_prot.h | 6 + lib_com/options.h | 2 + lib_dec/ivas_init_dec.c | 275 +++++++++++++++++++++++++++ lib_dec/lib_dec.c | 366 ++++++++++++++++++++++++++++++++++++ lib_dec/lib_dec.h | 25 +++ lib_util/hrtf_file_reader.c | 249 ++++++++++++++++++------ 8 files changed, 1128 insertions(+), 60 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index fc003928e9..4f53296965 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -161,6 +161,23 @@ typedef struct } DecArguments; +#ifdef FIX_HRTF_LOAD + +typedef struct +{ + hrtfFileReader *hrtfReader; + char *hrtfFileName; + + IVAS_DEC_HRTF_HANDLE *hHrtfTD; + IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF; + IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics; + + ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; + ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old; + +} IVAS_DEC_HRTF_WRAPPER; + +#endif /*------------------------------------------------------------------------------------------* * Local functions prototypes @@ -168,8 +185,15 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); +#ifdef FIX_HRTF_LOAD +static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#else static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +#endif static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); +#ifdef FIX_HRTF_LOAD +static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtf, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); +#endif #ifdef DEBUGGING static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); @@ -205,9 +229,13 @@ int main( RenderConfigReader *renderConfigReader = NULL; int16_t *pcmBuf = NULL; IVAS_RENDER_FRAMESIZE asked_frame_size; +#ifdef FIX_HRTF_LOAD + IVAS_DEC_HRTF_WRAPPER hHrtf; +#else IVAS_DEC_HRTF_HANDLE *hHrtfTD = NULL; IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF = NULL; IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics = NULL; +#endif #ifdef DEBUGGING int32_t noClipping; int32_t cnt_frames_limited; @@ -224,6 +252,13 @@ int main( reset_mem( USE_BYTES ); #endif +#ifdef FIX_HRTF_LOAD + hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; + hHrtf.hHrtfTD = NULL; /* just to avoid compilation warning */ + hHrtf.hSetOfHRTF = NULL; /* just to avoid compilation warning */ + hHrtf.hHrtfStatistics = NULL; /* just to avoid compilation warning */ +#endif + splitRendBits.bits_buf = splitRendBitsBuf; /*------------------------------------------------------------------------------------------* @@ -721,6 +756,21 @@ int main( if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_HRTF_LOAD + hHrtf.hrtfReader = hrtfReader; + hHrtf.hrtfFileName = arg.hrtfFileName; + + if ( arg.voipMode ) + { + hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; + hHrtf.binaural_renderer_old = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; + if ( ( error = IVAS_DEC_LoadHrtfFromFile( &hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } +#else if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -817,6 +867,7 @@ int main( destroy_hrtf_statistics( hHrtfStatistics ); } } +#endif } /*------------------------------------------------------------------------------------------* @@ -842,7 +893,11 @@ int main( } else { +#ifdef FIX_HRTF_LOAD + error = decodeG192( arg, hBsReader, &hHrtf, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); +#else error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); +#endif } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -894,6 +949,11 @@ cleanup: #endif if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_HRTF_LOAD + destroy_td_hrtf( hHrtf.hHrtfTD ); + destroy_SetOfHRTF( hHrtf.hSetOfHRTF ); + destroy_hrtf_statistics( hHrtf.hHrtfStatistics ); +#else IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ); destroy_td_hrtf( hHrtfTD ); @@ -902,6 +962,7 @@ cleanup: IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ); destroy_hrtf_statistics( hHrtfStatistics ); +#endif } IVAS_DEC_Close( &hIvasDec ); @@ -2094,6 +2155,9 @@ static ivas_error initOnFirstGoodFrame( static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, +#ifdef FIX_HRTF_LOAD + IVAS_DEC_HRTF_WRAPPER *hHrtf, +#endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, @@ -2465,6 +2529,34 @@ static ivas_error decodeG192( fprintf( stderr, "\nError: could not feed frame to decoder: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } + +#ifdef FIX_HRTF_LOAD + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Placeholder for memory reallocation */ + + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { + if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + + /* decode transport channels, do TSM and feed to renderer */ + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } + +#endif #ifdef OBJ_EDITING_API #ifdef OBJ_EDITING_EXAMPLE if ( arg.objEditEnabled ) @@ -3705,4 +3797,174 @@ static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( } #endif +#ifdef FIX_HRTF_LOAD + +/*---------------------------------------------------------------------* + * IVAS_DEC_LoadHrtfFromFile() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error IVAS_DEC_LoadHrtfFromFile( + IVAS_DEC_HRTF_WRAPPER *hHrtf, + IVAS_DEC_HANDLE hIvasDec, + const int32_t output_Fs ) +{ + ivas_error error; + ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; + + if ( hHrtf == NULL || hIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + binaural_renderer = hHrtf->binaural_renderer; + + if ( ( binaural_renderer != hHrtf->binaural_renderer_old ) || ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + /*------------------------------------------------------------------------------------------* + * Release HRTF binary data + *------------------------------------------------------------------------------------------*/ + + if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + destroy_td_hrtf( hHrtf->hHrtfTD ); + } + + if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + destroy_SetOfHRTF( hHrtf->hSetOfHRTF ); + } + + if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtf->binaural_renderer_old ) ) != IVAS_ERR_OK ) + { + return error; + } + + /*------------------------------------------------------------------------------------------* + * Load HRTF binary data + *------------------------------------------------------------------------------------------*/ + + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + { + if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtf->hHrtfTD ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = load_HRTF_binary( *hHrtf->hHrtfTD, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + return error; + } + else + { + destroy_td_hrtf( hHrtf->hHrtfTD ); + } + } + } + + if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + { + if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtf->hSetOfHRTF ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = create_SetOfHRTF_from_binary( *hHrtf->hSetOfHRTF, hHrtf->hrtfReader, output_Fs ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + return error; + } + else + { + destroy_SetOfHRTF( hHrtf->hSetOfHRTF ); + } + } + } + + if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + { + IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; + if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + return error; + } + else + { + destroy_fastconv_hrtf( hHrtfFastConv ); + } + } + } + + if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + { + IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; + if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + return error; + } + else + { + destroy_parambin_hrtf( hHrtfParambin ); + } + } + } + } + + if ( hHrtf->hHrtfStatistics == NULL ) + { + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtf->hHrtfStatistics ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + if ( ( error = load_reverb_binary( *hHrtf->hHrtfStatistics, output_Fs, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + { + if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) + { + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + return error; + } + else + { + destroy_hrtf_statistics( hHrtf->hHrtfStatistics ); + } + } + } + + return IVAS_ERR_OK; +} +#endif + #undef WMC_TOOL_SKIP diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 8cbdfcb3cd..cb85cceb4a 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -253,6 +253,9 @@ typedef enum typedef enum { +#ifdef FIX_HRTF_LOAD // VE: rename the enum -> IVAS_RENDERER_xx + ISAR_SPLIT_REND_RENDERER_SELECTION_NONE, +#endif ISAR_SPLIT_REND_RENDERER_SELECTION_CREND, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV, ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN, diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 700a9cc75c..8ee1c30bc6 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -318,6 +318,12 @@ ivas_error ivas_dec( int16_t *data /* o : output synthesis signal */ ); +#ifdef FIX_HRTF_LOAD +ivas_error ivas_dec_get_format( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +#endif ivas_error ivas_dec_setup( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ diff --git a/lib_com/options.h b/lib_com/options.h index ff1bc4ed7a..e436decc39 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,8 @@ #define FIX_1158_FASTCONV_REVERB_HRTF /* Philips: issue 1158: Rendering with FastConv to BINAURAL_ROOM_REVERB uses BRIR convolution instead of HRTF */ +#define FIX_HRTF_LOAD /* VA: fix memory issue when HRTFs are loaded from a binary file */ + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 63f3cc026d..cc46ad7f9a 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -89,6 +89,277 @@ static AUDIO_CONFIG ivas_set_audio_config_from_sba_order( return output_config; } +#ifdef FIX_HRTF_LOAD + +/*---------------------------------------------------------------------* + * ivas_dec_get_format( ) + * + * Read main parameters from the bitstream to set-up the decoder: + * - IVAS format + * - IVAS format specific signaling + *---------------------------------------------------------------------*/ + +ivas_error ivas_dec_get_format( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + int16_t k, idx, num_bits_read; + int16_t nchan_ism, element_mode_flag; + int16_t sba_order, sba_planar, sba_analysis_order; + int32_t ivas_total_brate; + uint16_t *bit_stream_orig; + ivas_error error; + + error = IVAS_ERR_OK; + + num_bits_read = 0; + element_mode_flag = 0; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + bit_stream_orig = st_ivas->bit_stream; + + /*-------------------------------------------------------------------* + * Read IVAS format + *-------------------------------------------------------------------*/ + + ivas_read_format( st_ivas, &num_bits_read ); + + /*-------------------------------------------------------------------* + * Read other signaling (ISM/MC mode, number of channels, etc.) + *-------------------------------------------------------------------*/ + + if ( is_DTXrate( ivas_total_brate ) == 0 ) + { + /*-------------------------------------------------------------------* + * Read IVAS format related signaling: + * - in ISM : read number of objects + * - in SBA : read SBA planar flag and SBA order + * - in MASA : read number of TC + * - in MC : read LS setup + *-------------------------------------------------------------------*/ + + if ( st_ivas->ivas_format == STEREO_FORMAT ) + { + element_mode_flag = 1; + } + else if ( st_ivas->ivas_format == ISM_FORMAT ) + { + /* read the number of objects */ + st_ivas->nchan_transport = 1; + nchan_ism = 1; + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) + { + nchan_ism++; + k--; + } + + st_ivas->nchan_ism = nchan_ism; + } + else if ( st_ivas->ivas_format == SBA_FORMAT ) + { + /* read Ambisonic (SBA) planar flag */ + sba_planar = st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_PLANAR_BITS; + + /* read Ambisonic (SBA) order */ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order ); + } + else if ( st_ivas->ivas_format == MASA_FORMAT ) + { + /* read number of MASA transport channels */ + if ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] ) + { + st_ivas->nchan_transport = 2; + element_mode_flag = 1; + } + else + { + st_ivas->nchan_transport = 1; + } + + /* this should be non-zero if original input format was MASA_ISM_FORMAT */ + st_ivas->nchan_ism = st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2]; + + if ( st_ivas->nchan_ism > 0 ) + { + /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ + /* info about the number of objects: + '00' - MASA format at the encoder + '01' - MASA_ISM_FORMAT at the encoder, with 4 objects + '10' - MASA_ISM_FORMAT at the encoder, with 3 objects + '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects + reading if 1 or 2 objects is performed later + */ + st_ivas->nchan_ism = 5 - st_ivas->nchan_ism; + if ( st_ivas->nchan_transport == 1 && st_ivas->nchan_ism == 2 ) + { + st_ivas->nchan_ism = 1; + } + + /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ + st_ivas->nchan_transport = 2; + element_mode_flag = 1; + } + } + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ + + /* the number of objects are written at the end of the bitstream */ + st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + } + else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + /* the number of objects is written at the end of the bitstream, in the SBA metadata */ + st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + + /* read Ambisonic (SBA) planar flag */ + sba_planar = st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_PLANAR_BITS; + + /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + if ( ivas_total_brate < IVAS_24k4 ) + { + sba_order = st_ivas->bit_stream[num_bits_read + 1]; + sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + num_bits_read += SBA_ORDER_BITS; + } + + st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); + st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order ); + } + else if ( st_ivas->ivas_format == MC_FORMAT ) + { + /* read MC configuration */ + idx = 0; + for ( k = 0; k < MC_LS_SETUP_BITS; k++ ) + { + if ( st_ivas->bit_stream[num_bits_read + k] ) + { + idx += 1 << ( MC_LS_SETUP_BITS - 1 - k ); + } + } + num_bits_read += MC_LS_SETUP_BITS; + + /* set transported MC LS setup */ + st_ivas->transport_config = ivas_mc_map_ls_setup_to_output_config( idx ); + } + + /*-------------------------------------------------------------------* + * Read element mode + *-------------------------------------------------------------------*/ + + if ( st_ivas->ini_frame == 0 && element_mode_flag ) + { + /* read stereo technology info */ + if ( ivas_total_brate < MIN_BRATE_MDCT_STEREO ) + { + /* 1 bit */ + if ( st_ivas->bit_stream[num_bits_read] ) + { + st_ivas->element_mode_init = 1 + IVAS_CPE_DFT; + } + else + { + st_ivas->element_mode_init = 0 + IVAS_CPE_DFT; + } + } + else + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + } + } + else if ( ivas_total_brate == IVAS_SID_5k2 ) + { + switch ( st_ivas->sid_format ) + { + case SID_DFT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_DFT; + break; + case SID_MDCT_STEREO: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + case SID_ISM: + st_ivas->element_mode_init = IVAS_SCE; + break; + case SID_MASA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + st_ivas->nchan_transport = 1; + break; + case SID_MASA_2TC: + if ( st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS] == 1 ) + { + st_ivas->element_mode_init = IVAS_CPE_MDCT; + } + else + { + st_ivas->element_mode_init = IVAS_CPE_DFT; + } + st_ivas->nchan_transport = 2; + break; + case SID_SBA_1TC: + st_ivas->element_mode_init = IVAS_SCE; + break; + case SID_SBA_2TC: + st_ivas->element_mode_init = IVAS_CPE_MDCT; + break; + } + + if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format == SBA_FORMAT ) + { + } + + if ( st_ivas->ivas_format == ISM_FORMAT ) + { + /* read the number of objects */ + st_ivas->nchan_transport = 1; + nchan_ism = 1; + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS ); + while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) + { + nchan_ism++; + k--; + } + k--; + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); + } + + st_ivas->nchan_ism = nchan_ism; + + /* read ism_mode */ + st_ivas->ism_mode = ISM_MODE_DISC; + if ( nchan_ism > 2 ) + { + k -= nchan_ism; /* SID metadata flags */ + idx = st_ivas->bit_stream[k]; + st_ivas->ism_mode = (ISM_MODE) ( idx + 1 ); + } + } + } + + st_ivas->bit_stream = bit_stream_orig; + + return IVAS_ERR_OK; +} + +#endif /*-------------------------------------------------------------------* * ivas_dec_setup() @@ -846,7 +1117,11 @@ ivas_error ivas_init_decoder_front( * Allocate HRTF binary handle *--------------------------------------------------------------------*/ +#ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->hDecoderConfig->Opt_tsm ) +#else if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) +#endif { if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index a3d3c7492a..f8f908e768 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -910,6 +910,15 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; #ifdef OBJ_EDITING_API +#ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + { + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#else /* Decode TCs, do TSM and feed to renderer. If TSM is generally enabled, we have to wait for the first good frame. Otherwise, we directly decode the first frame in any case. @@ -1031,10 +1040,239 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } #endif +#endif + + return IVAS_ERR_OK; +} + +#ifdef FIX_HRTF_LOAD + +/*---------------------------------------------------------------------* + * IVAS_DEC_ReadFormat( ) + * + * Read main parameters from the bitstream to set-up the decoder: + * - IVAS fromat + * - IVAS format specific signaling + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_ReadFormat( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer /* o : binaural renderer type */ +) +{ + ivas_error error; + Decoder_Struct *st_ivas; + IVAS_FORMAT ivas_format_old; + ISM_MODE ism_mode_old; + int16_t nchan_transport_old; + AUDIO_CONFIG intern_config_old; + RENDERER_TYPE renderer_type_old; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + st_ivas = hIvasDec->st_ivas; + ivas_format_old = st_ivas->ivas_format; + ism_mode_old = st_ivas->ism_mode; + nchan_transport_old = st_ivas->nchan_transport; + intern_config_old = st_ivas->intern_config; + renderer_type_old = st_ivas->renderer_type; + + if ( st_ivas->ivas_format == MONO_FORMAT ) + { + return IVAS_ERR_OK; + } + + if ( st_ivas->bfi == 0 ) + { + if ( ( error = ivas_dec_get_format( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( ivas_format_old != st_ivas->ivas_format && st_ivas->ini_frame > 0 && !( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) ) + { + return ( IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "IVAS format switching is not allowed." ) ); + } + + ivas_renderer_select( st_ivas ); + + switch ( st_ivas->renderer_type ) + { + case RENDERER_BINAURAL_OBJECTS_TD: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND; + break; + case RENDERER_BINAURAL_MIXER_CONV: + case RENDERER_BINAURAL_MIXER_CONV_ROOM: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_CREND; + break; + case RENDERER_BINAURAL_FASTCONV: + case RENDERER_BINAURAL_FASTCONV_ROOM: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; + break; + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN; + break; + default: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; + break; + } + } + + st_ivas->ism_mode = ism_mode_old; + st_ivas->nchan_transport = nchan_transport_old; + st_ivas->intern_config = intern_config_old; + st_ivas->renderer_type = renderer_type_old; + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * IVAS_DEC_GetSamplesDecoder( ) + * + * Main function to decode transport channels, do TSM and feed to renderer. + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_GetSamplesDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t isSplitRend, /* i : split rendering enabled flag */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +) +{ + ivas_error error; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /* If TSM is generally enabled, we have to wait for the first good frame. + Otherwise, we directly decode the first frame in any case. */ + if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + { + uint16_t l_ts, nTimeScalerOutSamples; + uint8_t nTransportChannels, nOutChannels; + int16_t nResidualSamples, nSamplesTcsScaled, nOutSamplesElse; + + if ( isSplitRend ) + { + if ( ( error = isar_set_split_rend_setup( hIvasDec->st_ivas->hSplitBinRend, &hIvasDec->st_ivas->hRenderConfig->split_rend_config, hIvasDec->st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &hIvasDec->nSamplesFlushed, hIvasDec->pcmType, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && nTransportChannels != hIvasDec->nTransportChannelsOld ) + { + if ( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* IVAS TC decoder */ + if ( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, &nOutSamplesElse ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* JBM */ + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + { + if ( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) + { + return IVAS_ERR_UNKNOWN; + } + + if ( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, hIvasDec->nSamplesFrame * nTransportChannels, (uint16_t) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) + { + return IVAS_ERR_UNKNOWN; + } + + assert( nTimeScalerOutSamples <= APA_BUF ); + nSamplesTcsScaled = nTimeScalerOutSamples / nTransportChannels; + hIvasDec->timeScalingDone = 1; + } + else + { + nSamplesTcsScaled = hIvasDec->nSamplesFrame; + } + + /* Feed decoded transport channels samples to the renderer */ + if ( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) + { + /* feed residual samples to TSM for the next call */ + if ( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 ) + { + return IVAS_ERR_UNKNOWN; + } + } + hIvasDec->hasBeenFedFrame = false; + } + hIvasDec->hasBeenPreparedRendering = false; + + if ( hIvasDec->st_ivas->hIsmMetaData[0] ) + { + if ( hIvasDec->st_ivas->ivas_format == ISM_FORMAT || hIvasDec->st_ivas->ivas_format == MASA_ISM_FORMAT || hIvasDec->st_ivas->ivas_format == SBA_ISM_FORMAT ) + { +#ifdef OMASA_OBJECT_EDITING + if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) +#else + if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_MASA_MODE_DISC || hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) +#endif + { + int16_t obj; + ISM_METADATA_HANDLE *hIsmMetaData = hIvasDec->st_ivas->hIsmMetaData; + for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ ) + { + hIsmMetaData[obj]->edited_azimuth = hIsmMetaData[obj]->azimuth; + hIsmMetaData[obj]->edited_elevation = hIsmMetaData[obj]->elevation; + hIsmMetaData[obj]->edited_yaw = hIsmMetaData[obj]->yaw; + hIsmMetaData[obj]->edited_pitch = hIsmMetaData[obj]->pitch; + hIsmMetaData[obj]->edited_radius = hIsmMetaData[obj]->radius; + hIsmMetaData[obj]->edited_gain = 1.0f; + } + + if ( hIvasDec->st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + hIvasDec->st_ivas->hSbaIsmData->gain_bed = 1.0f; + } + } + } + } + + if ( hIvasDec->st_ivas->hParamIsmDec != NULL ) + { + if ( hIvasDec->st_ivas->ism_mode == ISM_MODE_PARAM ) + { + int16_t obj = 0; + PARAM_ISM_DEC_HANDLE hParamIsmDec = hIvasDec->st_ivas->hParamIsmDec; + for ( obj = 0; obj < hIvasDec->st_ivas->nchan_ism; obj++ ) + { + hParamIsmDec->edited_azimuth_values[obj] = hParamIsmDec->azimuth_values[obj]; + hParamIsmDec->edited_elevation_values[obj] = hParamIsmDec->elevation_values[obj]; + } + } + } return IVAS_ERR_OK; } +#endif #ifdef OBJ_EDITING_API /*---------------------------------------------------------------------* @@ -2681,6 +2919,134 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( return IVAS_ERR_OK; } +#ifdef FIX_HRTF_LOAD + +/*---------------------------------------------------------------------* + * IVAS_DEC_HRTF_binary_open( ) + * + * Allocate HRTF binary handles + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_HRTF_binary_open( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer /* i : binaural renderer type */ +) +{ + ivas_error error; + Decoder_Struct *st_ivas; + + st_ivas = hIvasDec->st_ivas; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + { + if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfTD == NULL ) + { + if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hSetOfHRTF == NULL ) + { + if ( ( error = ivas_HRTF_CRend_binary_open( &( st_ivas->hSetOfHRTF ) ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfFastConv == NULL ) + { + if ( ( error = ivas_HRTF_fastconv_binary_open( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfParambin == NULL ) + { + if ( ( error = ivas_HRTF_parambin_binary_open( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( st_ivas->hHrtfStatistics == NULL ) + { + if ( ( error = ivas_HRTF_statistics_binary_open( &st_ivas->hHrtfStatistics ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * IVAS_DEC_HRTF_binary_close( ) + * + * + *---------------------------------------------------------------------*/ + +ivas_error IVAS_DEC_HRTF_binary_close( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old /* i : previous binaural renderer type */ +) +{ + Decoder_Struct *st_ivas; + + st_ivas = hIvasDec->st_ivas; + + if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + { +#if 0 + if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); + } + + if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + /* CRend binaural renderer handle */ + ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); + } +#endif + + if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + + /* Fastconv HRTF memories */ + ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv ); + + /* Fastconv HRTF filters */ + ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); + } + + if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + { + + /* Parametric binauralizer HRTF filters */ + ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); + } + } + + return IVAS_ERR_OK; +} + +#endif + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index dafae6518e..e93d4df13c 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -157,6 +157,19 @@ ivas_error IVAS_DEC_FeedFrame_Serial( #endif ); +#ifdef FIX_HRTF_LOAD +ivas_error IVAS_DEC_ReadFormat( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer /* o : binaural renderer type */ +); + +ivas_error IVAS_DEC_GetSamplesDecoder( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const int16_t isSplitRend, /* i : split rendering enabled flag */ + ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */ +); + +#endif #ifdef OBJ_EDITING_API ivas_error IVAS_DEC_GetEditableParameters( IVAS_DEC_HANDLE hIvasDec, @@ -451,6 +464,18 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */ ); +#ifdef FIX_HRTF_LOAD +ivas_error IVAS_DEC_HRTF_binary_open( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer /* i : binaural renderer type */ +); + +ivas_error IVAS_DEC_HRTF_binary_close( + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old /* i : previous binaural renderer type */ +); + +#endif /*! r: error code*/ ivas_error IVAS_DEC_GetRenderConfig( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 640f2721e6..7f3dc57cca 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -967,6 +967,13 @@ ivas_error load_HRTF_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_HRTF_LOAD + if ( hHrtf == NULL ) + { + return IVAS_ERR_OK; + } + +#endif fseek( hrtfReader->file, 0, SEEK_SET ); return TDREND_MIX_LoadHRTF( hrtfReader->file, hHrtf ); @@ -1437,6 +1444,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" ); } + /* HRIR */ if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { @@ -1450,10 +1458,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal != NULL ) +#endif { - ( *hHRTF )->leftHRIRReal[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) + { + ( *hHRTF )->leftHRIRReal[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1462,10 +1475,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal != NULL ) +#endif { - ( *hHRTF )->leftHRIRImag[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) + { + ( *hHRTF )->leftHRIRImag[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1474,10 +1492,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal != NULL ) +#endif { - ( *hHRTF )->rightHRIRReal[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) + { + ( *hHRTF )->rightHRIRReal[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1486,10 +1509,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal != NULL ) +#endif { - ( *hHRTF )->rightHRIRImag[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) + { + ( *hHRTF )->rightHRIRImag[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1507,10 +1535,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) +#endif { - ( *hHRTF )->leftHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) + { + ( *hHRTF )->leftHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1519,10 +1552,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) +#endif { - ( *hHRTF )->leftHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) + { + ( *hHRTF )->leftHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1531,10 +1569,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) +#endif { - ( *hHRTF )->rightHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) + { + ( *hHRTF )->rightHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1543,10 +1586,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) +#endif { - ( *hHRTF )->rightHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) + { + ( *hHRTF )->rightHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1564,10 +1612,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) +#endif { - ( *hHRTF )->leftHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) + { + ( *hHRTF )->leftHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1576,10 +1629,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) +#endif { - ( *hHRTF )->leftHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) + { + ( *hHRTF )->leftHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1588,10 +1646,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) +#endif { - ( *hHRTF )->rightHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) + { + ( *hHRTF )->rightHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1600,10 +1663,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) +#endif { - ( *hHRTF )->rightHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) + { + ( *hHRTF )->rightHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1621,10 +1689,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) +#endif { - ( *hHRTF )->leftHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) + { + ( *hHRTF )->leftHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1633,10 +1706,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) +#endif { - ( *hHRTF )->leftHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) + { + ( *hHRTF )->leftHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1645,10 +1723,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) +#endif { - ( *hHRTF )->rightHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) + { + ( *hHRTF )->rightHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1657,10 +1740,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) +#endif { - ( *hHRTF )->rightHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) + { + ( *hHRTF )->rightHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1679,10 +1767,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftBRIRReal != NULL ) +#endif { - ( *hHRTF )->leftBRIRReal[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) + { + ( *hHRTF )->leftBRIRReal[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1691,10 +1784,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftBRIRReal != NULL ) +#endif { - ( *hHRTF )->leftBRIRImag[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) + { + ( *hHRTF )->leftBRIRImag[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1703,10 +1801,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftBRIRReal != NULL ) +#endif { - ( *hHRTF )->rightBRIRReal[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) + { + ( *hHRTF )->rightBRIRReal[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1715,10 +1818,15 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) +#ifdef FIX_HRTF_LOAD + if ( ( *hHRTF )->leftBRIRReal != NULL ) +#endif { - ( *hHRTF )->rightBRIRImag[i][j][k] = ptW16[k] * scaleFactor; + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) + { + ( *hHRTF )->rightBRIRImag[i][j][k] = ptW16[k] * scaleFactor; + } } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1903,6 +2011,13 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_HRTF_LOAD + if ( hHrtfFastConv == NULL ) + { + return IVAS_ERR_OK; + } + +#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) @@ -1992,6 +2107,13 @@ ivas_error load_parambin_HRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_HRTF_LOAD + if ( hHrtfParamBin == NULL ) + { + return IVAS_ERR_OK; + } + +#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) @@ -2083,6 +2205,13 @@ ivas_error create_SetOfHRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } +#ifdef FIX_HRTF_LOAD + if ( hSetOfHRTF == NULL ) + { + return IVAS_ERR_OK; + } + +#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) -- GitLab From 5197c31f0d3e59b51cee3edc4823ed976af29dec Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Sep 2024 18:56:02 +0200 Subject: [PATCH 02/27] fix compilation warnings --- lib_dec/ivas_init_dec.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index cc46ad7f9a..7f463472ff 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -105,12 +105,9 @@ ivas_error ivas_dec_get_format( { int16_t k, idx, num_bits_read; int16_t nchan_ism, element_mode_flag; - int16_t sba_order, sba_planar, sba_analysis_order; + int16_t sba_order, sba_analysis_order; int32_t ivas_total_brate; uint16_t *bit_stream_orig; - ivas_error error; - - error = IVAS_ERR_OK; num_bits_read = 0; element_mode_flag = 0; @@ -159,7 +156,7 @@ ivas_error ivas_dec_get_format( else if ( st_ivas->ivas_format == SBA_FORMAT ) { /* read Ambisonic (SBA) planar flag */ - sba_planar = st_ivas->bit_stream[num_bits_read]; + /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ num_bits_read += SBA_PLANAR_BITS; /* read Ambisonic (SBA) order */ @@ -220,7 +217,7 @@ ivas_error ivas_dec_get_format( st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; /* read Ambisonic (SBA) planar flag */ - sba_planar = st_ivas->bit_stream[num_bits_read]; + /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ num_bits_read += SBA_PLANAR_BITS; /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ -- GitLab From d477fa65ec3e1d4a797707490652520c0314ba28 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Sep 2024 20:08:56 +0200 Subject: [PATCH 03/27] fix MC brate switching --- lib_dec/ivas_init_dec.c | 5 +++-- lib_dec/lib_dec.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 7f463472ff..ce6d2f4f3a 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -108,6 +108,7 @@ ivas_error ivas_dec_get_format( int16_t sba_order, sba_analysis_order; int32_t ivas_total_brate; uint16_t *bit_stream_orig; + AUDIO_CONFIG signaled_config; num_bits_read = 0; element_mode_flag = 0; @@ -251,8 +252,8 @@ ivas_error ivas_dec_get_format( } num_bits_read += MC_LS_SETUP_BITS; - /* set transported MC LS setup */ - st_ivas->transport_config = ivas_mc_map_ls_setup_to_output_config( idx ); + signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); } /*-------------------------------------------------------------------* diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f8f908e768..b00594b61c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1064,6 +1064,7 @@ ivas_error IVAS_DEC_ReadFormat( Decoder_Struct *st_ivas; IVAS_FORMAT ivas_format_old; ISM_MODE ism_mode_old; + MC_MODE mc_mode_old; int16_t nchan_transport_old; AUDIO_CONFIG intern_config_old; RENDERER_TYPE renderer_type_old; @@ -1076,6 +1077,7 @@ ivas_error IVAS_DEC_ReadFormat( st_ivas = hIvasDec->st_ivas; ivas_format_old = st_ivas->ivas_format; ism_mode_old = st_ivas->ism_mode; + mc_mode_old = st_ivas->mc_mode; nchan_transport_old = st_ivas->nchan_transport; intern_config_old = st_ivas->intern_config; renderer_type_old = st_ivas->renderer_type; @@ -1123,6 +1125,7 @@ ivas_error IVAS_DEC_ReadFormat( } st_ivas->ism_mode = ism_mode_old; + st_ivas->mc_mode = mc_mode_old; st_ivas->nchan_transport = nchan_transport_old; st_ivas->intern_config = intern_config_old; st_ivas->renderer_type = renderer_type_old; -- GitLab From 23aa7e8db4399b268245fdf7853822962f2a436a Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Sep 2024 12:17:27 +0200 Subject: [PATCH 04/27] fix ISM brate switching issue --- lib_dec/ivas_init_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ce6d2f4f3a..cc11314d42 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -153,6 +153,7 @@ ivas_error ivas_dec_get_format( } st_ivas->nchan_ism = nchan_ism; + st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); } else if ( st_ivas->ivas_format == SBA_FORMAT ) { -- GitLab From 971dbb625a45c1da564959e27390c64ca2deb221 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Sep 2024 17:00:45 +0200 Subject: [PATCH 05/27] optimizations for FastConv renderer --- apps/decoder.c | 9 +- apps/renderer.c | 4 + lib_dec/lib_dec.c | 16 ++- lib_dec/lib_dec.h | 4 +- lib_util/hrtf_file_reader.c | 263 ++++++++++-------------------------- lib_util/hrtf_file_reader.h | 6 +- 6 files changed, 107 insertions(+), 195 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 4f53296965..1ab16eaf21 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -175,6 +175,9 @@ typedef struct ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old; + IVAS_AUDIO_CONFIG intern_audio_config; + int16_t room_reverb_flag; + } IVAS_DEC_HRTF_WRAPPER; #endif @@ -257,6 +260,8 @@ int main( hHrtf.hHrtfTD = NULL; /* just to avoid compilation warning */ hHrtf.hSetOfHRTF = NULL; /* just to avoid compilation warning */ hHrtf.hHrtfStatistics = NULL; /* just to avoid compilation warning */ + hHrtf.room_reverb_flag = 0; + hHrtf.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; #endif splitRendBits.bits_buf = splitRendBitsBuf; @@ -2533,7 +2538,7 @@ static ivas_error decodeG192( #ifdef FIX_HRTF_LOAD /* Read main parameters from the bitstream to set-up the decoder */ hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) { return error; } @@ -3903,7 +3908,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtf->room_reverb_flag, hHrtf->intern_audio_config, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/apps/renderer.c b/apps/renderer.c index 52d6e81d09..9500c8d500 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -945,7 +945,11 @@ int main( goto cleanup; } +#ifdef FIX_HRTF_LOAD + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, 0, IVAS_AUDIO_CONFIG_INVALID, hrtfFileReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hrtfFileReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b00594b61c..0be9653197 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1056,8 +1056,10 @@ ivas_error IVAS_DEC_FeedFrame_Serial( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_ReadFormat( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer /* o : binaural renderer type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer, /* o : binaural renderer type */ + int16_t *room_reverb_flag, /* o : room reverb flag */ + IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ) { ivas_error error; @@ -1111,6 +1113,14 @@ ivas_error IVAS_DEC_ReadFormat( *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_CREND; break; case RENDERER_BINAURAL_FASTCONV: + *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; + + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + { + *room_reverb_flag = 1; + } + + break; case RENDERER_BINAURAL_FASTCONV_ROOM: *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; break; @@ -1122,6 +1132,8 @@ ivas_error IVAS_DEC_ReadFormat( *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; break; } + + *intern_audio_config = st_ivas->intern_config; } st_ivas->ism_mode = ism_mode_old; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index e93d4df13c..c06e67e4be 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -160,7 +160,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial( #ifdef FIX_HRTF_LOAD ivas_error IVAS_DEC_ReadFormat( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer /* o : binaural renderer type */ + ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer, /* o : binaural renderer type */ + int16_t *room_reverb_flag, /* o : room reverb flag */ + IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ); ivas_error IVAS_DEC_GetSamplesDecoder( diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 7f3dc57cca..04a611df30 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -967,13 +967,6 @@ ivas_error load_HRTF_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_HRTF_LOAD - if ( hHrtf == NULL ) - { - return IVAS_ERR_OK; - } - -#endif fseek( hrtfReader->file, 0, SEEK_SET ); return TDREND_MIX_LoadHRTF( hrtfReader->file, hHrtf ); @@ -1458,15 +1451,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) - { - ( *hHRTF )->leftHRIRReal[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRReal[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1475,15 +1463,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) - { - ( *hHRTF )->leftHRIRImag[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRImag[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1492,15 +1475,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) - { - ( *hHRTF )->rightHRIRReal[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRReal[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1509,15 +1487,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir; k++ ) - { - ( *hHRTF )->rightHRIRImag[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRImag[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir * sizeof( Word16 ); } @@ -1535,15 +1508,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) - { - ( *hHRTF )->leftHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1552,15 +1520,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) - { - ( *hHRTF )->leftHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1569,15 +1532,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) - { - ( *hHRTF )->rightHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRReal_HOA3[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1586,15 +1544,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA3_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA3 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa3; k++ ) - { - ( *hHRTF )->rightHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRImag_HOA3[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa3 * sizeof( Word16 ); } @@ -1612,15 +1565,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) - { - ( *hHRTF )->leftHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1629,15 +1577,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) - { - ( *hHRTF )->leftHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1646,15 +1589,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) - { - ( *hHRTF )->rightHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRReal_HOA2[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1663,15 +1601,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HOA2_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_HOA2 != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_hoa2; k++ ) - { - ( *hHRTF )->rightHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRImag_HOA2[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_hoa2 * sizeof( Word16 ); } @@ -1689,15 +1622,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) - { - ( *hHRTF )->leftHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1706,15 +1634,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) - { - ( *hHRTF )->leftHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1723,15 +1646,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) - { - ( *hHRTF )->rightHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRReal_FOA[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1740,15 +1658,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < FOA_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftHRIRReal_FOA != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_hrir_foa; k++ ) - { - ( *hHRTF )->rightHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightHRIRImag_FOA[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_hrir_foa * sizeof( Word16 ); } @@ -1767,15 +1680,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftBRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) - { - ( *hHRTF )->leftBRIRReal[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftBRIRReal[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1784,15 +1692,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftBRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) - { - ( *hHRTF )->leftBRIRImag[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->leftBRIRImag[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1801,15 +1704,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftBRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) - { - ( *hHRTF )->rightBRIRReal[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightBRIRReal[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1818,15 +1716,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { -#ifdef FIX_HRTF_LOAD - if ( ( *hHRTF )->leftBRIRReal != NULL ) -#endif + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) { - ptW16 = (Word16 *) hrtf_data_rptr; - for ( k = 0; k < ( *hHRTF )->ntaps_brir; k++ ) - { - ( *hHRTF )->rightBRIRImag[i][j][k] = ptW16[k] * scaleFactor; - } + ( *hHRTF )->rightBRIRImag[i][j][k] = ptW16[k] * scaleFactor; } hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } @@ -1994,7 +1887,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( ivas_error load_fastconv_HRTF_from_binary( IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv, /* i/o: FastConv HRTF handle */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ +#ifdef FIX_HRTF_LOAD + int16_t room_reverb_flag, /* i : room reverb flag */ + const IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ +#endif + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ) { FILE *f_hrtf; @@ -2011,13 +1908,6 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_HRTF_LOAD - if ( hHrtfFastConv == NULL ) - { - return IVAS_ERR_OK; - } - -#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) @@ -2049,7 +1939,16 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } +#ifdef FIX_HRTF_LOAD + if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && + ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) || + ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && room_reverb_flag == 1 ) ) || + ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) +#else if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) ) +#endif { if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { @@ -2107,13 +2006,6 @@ ivas_error load_parambin_HRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_HRTF_LOAD - if ( hHrtfParamBin == NULL ) - { - return IVAS_ERR_OK; - } - -#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) @@ -2205,13 +2097,6 @@ ivas_error create_SetOfHRTF_from_binary( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } -#ifdef FIX_HRTF_LOAD - if ( hSetOfHRTF == NULL ) - { - return IVAS_ERR_OK; - } - -#endif f_hrtf = hrtfReader->file; if ( ( header_check_result = read_and_check_hrtf_binary_file_header( &hrtfs_file_header, f_hrtf ) ) != IVAS_ERR_OK ) diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index dbb38c3d88..fadad4516e 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -132,7 +132,11 @@ void destroy_SetOfHRTF( ivas_error load_fastconv_HRTF_from_binary( IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv, /* i/o: FastConv HRTF handle */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ +#ifdef FIX_HRTF_LOAD + int16_t room_reverb_flag, /* i : room reverb flag */ + IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ +#endif + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ); /*---------------------------------------------------------------------* -- GitLab From 976e33084c623e8956852398ad112075844842fb Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Sep 2024 17:53:54 +0200 Subject: [PATCH 06/27] fix warning --- lib_util/hrtf_file_reader.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 04a611df30..4bb5f764b5 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1941,10 +1941,10 @@ ivas_error load_fastconv_HRTF_from_binary( #ifdef FIX_HRTF_LOAD if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && - ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || - ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || - ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) || - ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && room_reverb_flag == 1 ) ) || + ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) ) || + ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && room_reverb_flag == 1 ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #else if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) ) -- GitLab From 7efd7ac4aa0f8a1d5910d4bbb18a7820e3ec4ac0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Sep 2024 18:21:00 +0200 Subject: [PATCH 07/27] reintroduce room_re to ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV --- lib_dec/lib_dec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0be9653197..064ccdde11 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1123,6 +1123,7 @@ ivas_error IVAS_DEC_ReadFormat( break; case RENDERER_BINAURAL_FASTCONV_ROOM: *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; + *room_reverb_flag = 1; break; case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: -- GitLab From b24d9d29fdcbe5f7316e84d7a636d0a78dd8b514 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 14 Oct 2024 17:30:48 +0200 Subject: [PATCH 08/27] add FIX_HRTF_LOAD_JBM --- apps/decoder.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++- lib_com/options.h | 1 + lib_dec/lib_dec.c | 43 +++++++++++++++++++++++++++++++++++- lib_dec/lib_dec.h | 6 ++++++ 4 files changed, 103 insertions(+), 2 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index dbe54f26e5..b599e5e66c 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -193,7 +193,11 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS #else static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); #endif +#ifdef FIX_HRTF_LOAD_JBM +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); +#else static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); +#endif #ifdef FIX_HRTF_LOAD static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtf, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); #endif @@ -774,7 +778,7 @@ int main( #ifdef FIX_HRTF_LOAD hHrtf.hrtfReader = hrtfReader; hHrtf.hrtfFileName = arg.hrtfFileName; - +#ifndef FIX_HRTF_LOAD_JBM if ( arg.voipMode ) { hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; @@ -785,6 +789,7 @@ int main( goto cleanup; } } +#endif #else if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) { @@ -904,7 +909,11 @@ int main( if ( arg.voipMode ) { +#ifdef FIX_HRTF_LOAD_JBM + error = decodeVoIP( arg, hBsReader, &hHrtf, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); +#else error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); +#endif } else { @@ -2534,10 +2543,12 @@ static ivas_error decodeG192( #endif /* Feed into decoder */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi +#ifndef FIX_HRTF_LOAD_JBM #ifdef OBJ_EDITING_API , isSplitRend, splitRendBits +#endif #endif ) ) != IVAS_ERR_OK ) { @@ -2554,6 +2565,7 @@ static ivas_error decodeG192( } /* Placeholder for memory reallocation */ + /* ... */ /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) @@ -3138,6 +3150,9 @@ static ivas_error writeJbmTraceFileFrameWrapper( const void *data, void *writer static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, +#ifdef FIX_HRTF_LOAD_JBM + IVAS_DEC_HRTF_WRAPPER *hHrtf, +#endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, @@ -3188,6 +3203,10 @@ static ivas_error decodeVoIP( int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; +#ifdef FIX_HRTF_LOAD_JBM + bool bitstreamReadDone = false; +#endif + #ifdef OBJ_EDITING_API bool parameterAvailableForEditing = false; uint16_t nSamplesRendered = 0; @@ -3481,6 +3500,10 @@ static ivas_error decodeVoIP( #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter +#ifdef FIX_HRTF_LOAD_JBM + , + &bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , &nSamplesRendered, ¶meterAvailableForEditing @@ -3488,6 +3511,10 @@ static ivas_error decodeVoIP( ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered, ¶meterAvailableForEditing +#ifdef FIX_HRTF_LOAD_JBM + , + &bitstreamReadDone +#endif #ifdef OBJ_EDITING_API & nSamplesRendered, ¶meterAvailableForEditing @@ -3498,6 +3525,32 @@ static ivas_error decodeVoIP( fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } +#ifdef FIX_HRTF_LOAD_JBM + + if ( bitstreamReadDone == true ) + { + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Placeholder for memory reallocation */ + /* ... */ + + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { + if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + goto cleanup; + } + } + } + +#endif #ifdef OBJ_EDITING_API if ( parameterAvailableForEditing == true ) { diff --git a/lib_com/options.h b/lib_com/options.h index a11a6b9e28..a77b1d0cb1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -174,6 +174,7 @@ #define FIX_VOIP_FUNCTIONS /* VA: fix data type mismatch in IVAS_DEC_VoIP_SetScale() + add sanity checks to API functions */ #define FIX_HRTF_LOAD /* VA: fix memory issue when HRTFs are loaded from a binary file */ +#define FIX_HRTF_LOAD_JBM /* #################### End BE switches ################################## */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f8b8d2c62d..566f16830b 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -838,11 +838,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial( uint16_t *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */ const uint16_t num_bits, /* i : number of bits in input bitstream */ int16_t bfi /* i : bad frame indicator flag */ +#ifndef FIX_HRTF_LOAD_JBM #ifdef OBJ_EDITING_API , int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits #endif +#endif ) { ivas_error error; @@ -920,6 +922,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; #ifdef OBJ_EDITING_API +#ifndef FIX_HRTF_LOAD_JBM #ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { @@ -928,6 +931,8 @@ ivas_error IVAS_DEC_FeedFrame_Serial( return error; } } +#endif +#endif #else /* Decode TCs, do TSM and feed to renderer. If TSM is generally enabled, we have to wait for the first good frame. @@ -1049,7 +1054,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } } -#endif #endif return IVAS_ERR_OK; @@ -1178,7 +1182,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( /* If TSM is generally enabled, we have to wait for the first good frame. Otherwise, we directly decode the first frame in any case. */ +#ifdef FIX_HRTF_LOAD_JBM + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) +#else if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) +#endif { uint16_t l_ts, nTimeScalerOutSamples; uint8_t nTransportChannels, nOutChannels; @@ -3646,6 +3654,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter #endif +#ifdef FIX_HRTF_LOAD_JBM + , + bool *bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , uint16_t *nSamplesRendered, @@ -3769,24 +3781,32 @@ ivas_error IVAS_DEC_VoIP_GetSamples( if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 +#ifndef FIX_HRTF_LOAD_JBM #if defined( OBJ_EDITING_API ) , 0, 0 +#endif #endif ) ) != IVAS_ERR_OK ) { return error; } +#ifdef FIX_HRTF_LOAD_JBM + + *bitstreamReadDone = true; +#endif } else if ( hIvasDec->hasDecodedFirstGoodFrame ) { /* Decoder has been initialized with first good frame - do PLC */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 +#ifndef FIX_HRTF_LOAD_JBM #if defined( OBJ_EDITING_API ) , 0, 0 +#endif #endif ) ) != IVAS_ERR_OK ) { @@ -3822,6 +3842,14 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } +#ifdef FIX_HRTF_LOAD_JBM + if ( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true ) + { + /* new bitstream was feeded, return for reconfiguration */ + return IVAS_ERR_OK; + } + +#endif if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; @@ -3859,6 +3887,19 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { int16_t nSamplesToRender, nSamplesRendered_loop; bool tmp; + +#ifdef FIX_HRTF_LOAD_JBM + if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) + { + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + + *bitstreamReadDone = false; + } +#endif + #ifdef OBJ_EDITING_API nSamplesToRender = nSamplesPerChannel - *nSamplesRendered; #else diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index cb1ff35606..72aa7cf399 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -150,11 +150,13 @@ ivas_error IVAS_DEC_FeedFrame_Serial( uint16_t *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */ const uint16_t num_bits, /* i : number of bits in input bitstream */ int16_t bfi /* i : bad frame indicator flag */ +#ifndef FIX_HRTF_LOAD_JBM #if defined( OBJ_EDITING_API ) , int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits #endif +#endif ); #ifdef FIX_HRTF_LOAD @@ -319,6 +321,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( , JbmTraceFileWriterFn jbmWriterFn, void* jbmWriter #endif +#ifdef FIX_HRTF_LOAD_JBM + , + bool *bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , uint16_t *nSamplesRendered, -- GitLab From 3ecf34f4f17eb9a8450c05f550516f006d3dabd1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 11:26:57 +0200 Subject: [PATCH 09/27] more within FIX_HRTF_LOAD_JBM; fix compilation warnings --- apps/decoder.c | 4 ++- lib_com/ivas_prot.h | 30 +++++++++++++---- lib_dec/ivas_init_dec.c | 71 +++++++++++++++++++++++++++++++++------- lib_dec/ivas_ism_dec.c | 28 +++++++++++++--- lib_dec/ivas_masa_dec.c | 9 ++++- lib_dec/ivas_mct_dec.c | 24 ++++++++++++-- lib_dec/ivas_omasa_dec.c | 9 ++++- lib_dec/ivas_sba_dec.c | 11 ++++++- lib_dec/lib_dec.c | 58 +++++++++++++++++++++++++++++--- 9 files changed, 210 insertions(+), 34 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b599e5e66c..6e5873bb9d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3516,7 +3516,7 @@ static ivas_error decodeVoIP( &bitstreamReadDone #endif #ifdef OBJ_EDITING_API - & nSamplesRendered, + & nSamplesRendered, ¶meterAvailableForEditing #endif ) ) != IVAS_ERR_OK ) @@ -3536,6 +3536,8 @@ static ivas_error decodeVoIP( return error; } + //nSamplesRendered += hIvasDec->nSamplesFlushed; + /* Placeholder for memory reallocation */ /* ... */ diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 8ee1c30bc6..416d1dddd4 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -325,10 +325,13 @@ ivas_error ivas_dec_get_format( #endif ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ); ivas_error create_sce_dec( @@ -666,10 +669,13 @@ ivas_error ivas_mc_enc_config( ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t idx, /* i : LS config. index */ + const int16_t idx /* i : LS config. index */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ + #endif ); /*! r: MC format mode (MCT, McMASA, ParamMC) */ @@ -1083,10 +1089,13 @@ ivas_error ivas_ism_enc_config( ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ + const ISM_MODE last_ism_mode /* i/o: last ISM mode */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed on renderer change*/ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ); ivas_error ivas_param_ism_dec_open( @@ -3477,10 +3486,13 @@ void ivas_sba_set_cna_cng_flag( ); ivas_error ivas_sba_dec_reconfigure( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesFlushed, /* o : number of samples flushed */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ); ivas_error ivas_sba_digest_tc( @@ -4935,10 +4947,13 @@ void ivas_masa_enc_reconfigure( ); ivas_error ivas_masa_dec_reconfigure( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ + #endif ); ivas_error ivas_masa_encode( @@ -5640,10 +5655,13 @@ ivas_error ivas_omasa_enc_config( ); ivas_error ivas_omasa_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ); void ivas_omasa_set_config( diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index cc11314d42..37ea12d2db 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -143,7 +143,9 @@ ivas_error ivas_dec_get_format( else if ( st_ivas->ivas_format == ISM_FORMAT ) { /* read the number of objects */ +#ifndef FIX_HRTF_LOAD_JBM st_ivas->nchan_transport = 1; +#endif nchan_ism = 1; k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) @@ -154,6 +156,13 @@ ivas_error ivas_dec_get_format( st_ivas->nchan_ism = nchan_ism; st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); +#ifdef FIX_HRTF_LOAD_JBM + st_ivas->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } +#endif } else if ( st_ivas->ivas_format == SBA_FORMAT ) { @@ -318,14 +327,12 @@ ivas_error ivas_dec_get_format( break; } - if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format == SBA_FORMAT ) - { - } - if ( st_ivas->ivas_format == ISM_FORMAT ) { /* read the number of objects */ +#ifndef FIX_HRTF_LOAD_JBM st_ivas->nchan_transport = 1; +#endif nchan_ism = 1; k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) @@ -335,11 +342,6 @@ ivas_error ivas_dec_get_format( } k--; - if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) - { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong number of objects signalled!" ); - } - st_ivas->nchan_ism = nchan_ism; /* read ism_mode */ @@ -350,6 +352,14 @@ ivas_error ivas_dec_get_format( idx = st_ivas->bit_stream[k]; st_ivas->ism_mode = (ISM_MODE) ( idx + 1 ); } + +#ifdef FIX_HRTF_LOAD_JBM + st_ivas->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } +#endif } } @@ -367,10 +377,13 @@ ivas_error ivas_dec_get_format( *-------------------------------------------------------------------*/ ivas_error ivas_dec_setup( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { int16_t k, idx, num_bits_read; @@ -424,7 +437,11 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = nchan_ism; +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_ism_dec_config( st_ivas, st_ivas->ism_mode ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_ism_dec_config( st_ivas, st_ivas->ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -442,7 +459,11 @@ ivas_error ivas_dec_setup( num_bits_read += SBA_ORDER_BITS; if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -504,8 +525,11 @@ ivas_error ivas_dec_setup( } else { - +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -513,7 +537,11 @@ ivas_error ivas_dec_setup( } else { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -534,7 +562,11 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -562,9 +594,14 @@ ivas_error ivas_dec_setup( st_ivas->sba_order += 2 * st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_ORDER_BITS; } + if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -610,7 +647,11 @@ ivas_error ivas_dec_setup( num_bits_read += MC_LS_SETUP_BITS; /* select MC format mode; reconfigure the MC format decoder */ +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_mc_dec_config( st_ivas, idx ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_mc_dec_config( st_ivas, idx, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -695,7 +736,11 @@ ivas_error ivas_dec_setup( st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; } +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -741,7 +786,11 @@ ivas_error ivas_dec_setup( last_ism_mode = st_ivas->ism_mode; } +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_ism_dec_config( st_ivas, last_ism_mode ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_ism_dec_config( st_ivas, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 36945f8155..f6e695e152 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -47,12 +47,15 @@ *-------------------------------------------------------------------------*/ static ivas_error ivas_ism_bitrate_switching_dec( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t nchan_transport_old, /* i : last number of transport channels */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nchan_transport_old, /* i : last number of transport channels */ + const ISM_MODE last_ism_mode /* i : last ISM mode */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples rendered */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { ivas_error error; @@ -142,10 +145,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef FIX_HRTF_LOAD_JBM + /* flush already done in IVAS_DEC_ReadFormat() */ +#else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) @@ -373,11 +380,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( *-------------------------------------------------------------------------*/ ivas_error ivas_ism_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const ISM_MODE last_ism_mode, /* i/o: last ISM mode */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const ISM_MODE last_ism_mode /* i/o: last ISM mode */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { int32_t ivas_total_brate; @@ -415,7 +425,11 @@ ivas_error ivas_ism_dec_config( /* ISM bit-rate switching */ if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hDecoderConfig->ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -437,7 +451,11 @@ ivas_error ivas_ism_dec_config( /* ISM mode switching */ if ( st_ivas->ism_mode != last_ism_mode ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 2335f14147..6275b868de 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1305,10 +1305,13 @@ static int16_t decode_lfe_to_total_energy_ratio( *-------------------------------------------------------------------*/ ivas_error ivas_masa_dec_reconfigure( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { int16_t n, tmp, num_bits; @@ -1517,10 +1520,14 @@ ivas_error ivas_masa_dec_reconfigure( { if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef FIX_HRTF_LOAD_JBM + /* flush already done in IVAS_DEC_ReadFormat() */ +#else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) { return error; } +#endif } } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 08e2de73cd..426040e893 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -54,7 +54,11 @@ * Local function prototypes *-----------------------------------------------------------------------*/ +#ifdef FIX_HRTF_LOAD_JBM +static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas ); +#else static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamplesRendered, const PCM_RESOLUTION pcm_resolution, void *data ); +#endif /*--------------------------------------------------------------------------* @@ -661,11 +665,14 @@ void ivas_mct_dec_close( /*! r : MC format mode */ ivas_error ivas_mc_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t idx, /* i : LS config. index */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t idx /* i : LS config. index */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { AUDIO_CONFIG signaled_config; @@ -700,7 +707,11 @@ ivas_error ivas_mc_dec_config( { if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || last_mc_mode != st_ivas->mc_mode ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_mc_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -721,10 +732,13 @@ ivas_error ivas_mc_dec_config( *-------------------------------------------------------------------------*/ static ivas_error ivas_mc_dec_reconfig( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, sba_dirac_stereo_flag_old, nchan_hp20_old; @@ -808,10 +822,14 @@ static ivas_error ivas_mc_dec_reconfig( tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef FIX_HRTF_LOAD_JBM + /* flush already done in IVAS_DEC_ReadFormat() */ +#else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) { return error; } +#endif } /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 3ab3757688..63bbbc3394 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -220,10 +220,13 @@ void ivas_omasa_data_close( *--------------------------------------------------------------------------*/ ivas_error ivas_omasa_dec_config( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { #ifdef OMASA_OBJECT_EDITING @@ -271,7 +274,11 @@ ivas_error ivas_omasa_dec_config( { st_ivas->hCPE[0]->nchan_out = 1; } +#ifdef FIX_HRTF_LOAD_JBM + else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#else else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9a6df407d4..8f6ceaca12 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -101,10 +101,13 @@ void ivas_sba_set_cna_cng_flag( *-------------------------------------------------------------------*/ ivas_error ivas_sba_dec_reconfigure( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#ifndef FIX_HRTF_LOAD_JBM + , uint16_t *nSamplesFlushed, /* o : number of samples flushed */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; @@ -161,7 +164,9 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); +#ifndef FIX_HRTF_LOAD_JBM *nSamplesFlushed = 0; +#endif granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /* we may need to flush only for binaural and OSBA and TSM */ @@ -209,6 +214,9 @@ ivas_error ivas_sba_dec_reconfigure( /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#ifdef FIX_HRTF_LOAD_JBM + /* flush already done in IVAS_DEC_ReadFormat() */ +#else /* write back info for correct rendering of the flushable samples */ st_ivas->sba_analysis_order = sba_analysis_order_old_flush; st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; @@ -221,6 +229,7 @@ ivas_error ivas_sba_dec_reconfigure( /* restore correct values for the current frame*/ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; +#endif } else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) { diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 566f16830b..394ada9636 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -122,7 +122,11 @@ static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSampl static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ); +#ifdef FIX_HRTF_LOAD_JBM +static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels ); +#else static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data ); +#endif static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, int16_t *nOutSamples ); static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const int16_t nSamplesForRendering, int16_t *nSamplesResidual, float *pcmBuf ); static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const uint16_t nSamplesForRendering, uint16_t *nSamplesRendered, uint16_t *nSamplesAvailableNext, const IVAS_DEC_PCM_TYPE pcmType, void *pcmBuf ); @@ -1149,6 +1153,25 @@ ivas_error IVAS_DEC_ReadFormat( } *intern_audio_config = st_ivas->intern_config; + +#ifdef FIX_HRTF_LOAD_JBM + if ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) + { + /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv + render what still fits in the new granularity */ + int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + + // st_ivas->nchan_transport = nchan_transport_old; // ToDo: commented for the moment to kepp the changes bit-exact but this is likely a bug in the main + + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, pcm_type_API_to_internal( hIvasDec->pcmType ), hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#endif } st_ivas->ism_mode = ism_mode_old; @@ -1189,7 +1212,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( #endif { uint16_t l_ts, nTimeScalerOutSamples; +#ifdef FIX_HRTF_LOAD_JBM + uint8_t nTransportChannels; +#else uint8_t nTransportChannels, nOutChannels; +#endif int16_t nResidualSamples, nSamplesTcsScaled, nOutSamplesElse; if ( isSplitRend ) @@ -1200,7 +1227,11 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } } +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &hIvasDec->nSamplesFlushed, hIvasDec->pcmType, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2121,30 +2152,38 @@ ivas_error IVAS_DEC_GetSplitBinauralBitstream( *---------------------------------------------------------------------*/ static ivas_error IVAS_DEC_Setup( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ - uint8_t *nTransportChannels, /* o : number of decoded transport PCM channels */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ + uint8_t *nTransportChannels /* o : number of decoded transport PCM channels */ +#ifndef FIX_HRTF_LOAD_JBM + , uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ const IVAS_DEC_PCM_TYPE pcmType, /* i : type for the decoded PCM resolution */ void *data /* o : output synthesis signal */ +#endif ) { ivas_error error; +#ifndef FIX_HRTF_LOAD_JBM *nSamplesRendered = 0; - +#endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) { if ( hIvasDec->st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) { *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; +#ifndef FIX_HRTF_LOAD_JBM *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; +#endif } else { *nTransportChannels = 1; +#ifndef FIX_HRTF_LOAD_JBM *nOutChannels = 1; +#endif } } else @@ -2163,7 +2202,11 @@ static ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { +#ifdef FIX_HRTF_LOAD_JBM + if ( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2171,8 +2214,9 @@ static ivas_error IVAS_DEC_Setup( *nTransportChannels = (uint8_t) st_ivas->hTcBuffer->nchan_transport_jbm; *nTcBufferGranularity = (uint16_t) st_ivas->hTcBuffer->n_samples_granularity; +#ifndef FIX_HRTF_LOAD_JBM *nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; - +#endif /*-----------------------------------------------------------------* * ISAR: @@ -3891,11 +3935,15 @@ ivas_error IVAS_DEC_VoIP_GetSamples( #ifdef FIX_HRTF_LOAD_JBM if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) { + uint16_t nSamplesFlushed_ref = hIvasDec->nSamplesFlushed; + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) { return error; } + hIvasDec->nSamplesFlushed = nSamplesFlushed_ref; + *bitstreamReadDone = false; } #endif -- GitLab From 99787728784dca82d5a170b9712084d446328602 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 11:47:48 +0200 Subject: [PATCH 10/27] formatting, comments --- apps/decoder.c | 2 -- lib_com/options.h | 2 +- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 2 +- lib_dec/lib_dec.c | 5 ++--- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6e5873bb9d..465b240410 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -3536,8 +3536,6 @@ static ivas_error decodeVoIP( return error; } - //nSamplesRendered += hIvasDec->nSamplesFlushed; - /* Placeholder for memory reallocation */ /* ... */ diff --git a/lib_com/options.h b/lib_com/options.h index a77b1d0cb1..a181fccb98 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -173,7 +173,7 @@ #define FIX_587_DEFAULT_REVERB /* Philips: issue 587: inconsistent default reverb parameters across renderers */ #define FIX_VOIP_FUNCTIONS /* VA: fix data type mismatch in IVAS_DEC_VoIP_SetScale() + add sanity checks to API functions */ -#define FIX_HRTF_LOAD /* VA: fix memory issue when HRTFs are loaded from a binary file */ +#define FIX_HRTF_LOAD /* VA: issue 1187: fix memory issue when HRTFs are loaded from a binary file */ #define FIX_HRTF_LOAD_JBM /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6275b868de..b6063e377c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1305,7 +1305,7 @@ static int16_t decode_lfe_to_total_energy_ratio( *-------------------------------------------------------------------*/ ivas_error ivas_masa_dec_reconfigure( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ #ifndef FIX_HRTF_LOAD_JBM , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 63bbbc3394..6591cda42b 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -220,7 +220,7 @@ void ivas_omasa_data_close( *--------------------------------------------------------------------------*/ ivas_error ivas_omasa_dec_config( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ #ifndef FIX_HRTF_LOAD_JBM , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 394ada9636..a69c6994eb 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -926,8 +926,8 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; #ifdef OBJ_EDITING_API -#ifndef FIX_HRTF_LOAD_JBM #ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed +#ifndef FIX_HRTF_LOAD_JBM if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) @@ -936,7 +936,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } #endif -#endif #else /* Decode TCs, do TSM and feed to renderer. If TSM is generally enabled, we have to wait for the first good frame. @@ -1059,7 +1058,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( } } #endif - +#endif return IVAS_ERR_OK; } -- GitLab From f3650acf42634056afb21fa304e1fadf59f48aa8 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 11:55:11 +0200 Subject: [PATCH 11/27] rename 'hHrtf' to 'hHrtfBinary' --- apps/decoder.c | 89 +++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 465b240410..b0fd3994bf 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -162,7 +162,6 @@ typedef struct } DecArguments; #ifdef FIX_HRTF_LOAD - typedef struct { hrtfFileReader *hrtfReader; @@ -199,7 +198,7 @@ static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #endif #ifdef FIX_HRTF_LOAD -static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtf, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); +static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); #endif #ifdef DEBUGGING @@ -237,7 +236,7 @@ int main( int16_t *pcmBuf = NULL; IVAS_RENDER_FRAMESIZE asked_frame_size; #ifdef FIX_HRTF_LOAD - IVAS_DEC_HRTF_WRAPPER hHrtf; + IVAS_DEC_HRTF_WRAPPER hHrtfBinary; #else IVAS_DEC_HRTF_HANDLE *hHrtfTD = NULL; IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF = NULL; @@ -260,12 +259,9 @@ int main( #endif #ifdef FIX_HRTF_LOAD - hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; - hHrtf.hHrtfTD = NULL; /* just to avoid compilation warning */ - hHrtf.hSetOfHRTF = NULL; /* just to avoid compilation warning */ - hHrtf.hHrtfStatistics = NULL; /* just to avoid compilation warning */ - hHrtf.room_reverb_flag = 0; - hHrtf.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; + hHrtfBinary.hHrtfTD = NULL; /* just to avoid compilation warning */ + hHrtfBinary.hSetOfHRTF = NULL; /* just to avoid compilation warning */ + hHrtfBinary.hHrtfStatistics = NULL; /* just to avoid compilation warning */ #endif splitRendBits.bits_buf = splitRendBitsBuf; @@ -776,14 +772,17 @@ int main( if ( arg.hrtfReaderEnabled ) { #ifdef FIX_HRTF_LOAD - hHrtf.hrtfReader = hrtfReader; - hHrtf.hrtfFileName = arg.hrtfFileName; + hHrtfBinary.hrtfReader = hrtfReader; + hHrtfBinary.hrtfFileName = arg.hrtfFileName; + hHrtfBinary.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; + hHrtfBinary.room_reverb_flag = 0; + hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; #ifndef FIX_HRTF_LOAD_JBM if ( arg.voipMode ) { hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; hHrtf.binaural_renderer_old = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; - if ( ( error = IVAS_DEC_LoadHrtfFromFile( &hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_LoadHrtfFromFile( &hHrtfBinary, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -910,7 +909,7 @@ int main( if ( arg.voipMode ) { #ifdef FIX_HRTF_LOAD_JBM - error = decodeVoIP( arg, hBsReader, &hHrtf, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); #else error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); #endif @@ -918,7 +917,7 @@ int main( else { #ifdef FIX_HRTF_LOAD - error = decodeG192( arg, hBsReader, &hHrtf, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); + error = decodeG192( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); #else error = decodeG192( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, &splitRendBits, hIvasDec, pcmBuf ); #endif @@ -974,9 +973,9 @@ cleanup: if ( arg.hrtfReaderEnabled ) { #ifdef FIX_HRTF_LOAD - destroy_td_hrtf( hHrtf.hHrtfTD ); - destroy_SetOfHRTF( hHrtf.hSetOfHRTF ); - destroy_hrtf_statistics( hHrtf.hHrtfStatistics ); + destroy_td_hrtf( hHrtfBinary.hHrtfTD ); + destroy_SetOfHRTF( hHrtfBinary.hSetOfHRTF ); + destroy_hrtf_statistics( hHrtfBinary.hHrtfStatistics ); #else IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ); destroy_td_hrtf( hHrtfTD ); @@ -2180,7 +2179,7 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, #ifdef FIX_HRTF_LOAD - IVAS_DEC_HRTF_WRAPPER *hHrtf, + IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, #endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, @@ -2558,8 +2557,8 @@ static ivas_error decodeG192( #ifdef FIX_HRTF_LOAD /* Read main parameters from the bitstream to set-up the decoder */ - hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) + hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK ) { return error; } @@ -2570,7 +2569,7 @@ static ivas_error decodeG192( /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { - if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtfBinary, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3874,21 +3873,21 @@ static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( *---------------------------------------------------------------------*/ static ivas_error IVAS_DEC_LoadHrtfFromFile( - IVAS_DEC_HRTF_WRAPPER *hHrtf, + IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ) { ivas_error error; ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; - if ( hHrtf == NULL || hIvasDec == NULL ) + if ( hHrtfBinary == NULL || hIvasDec == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - binaural_renderer = hHrtf->binaural_renderer; + binaural_renderer = hHrtfBinary->binaural_renderer; - if ( ( binaural_renderer != hHrtf->binaural_renderer_old ) || ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) { /*------------------------------------------------------------------------------------------* * Release HRTF binary data @@ -3896,15 +3895,15 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) { - destroy_td_hrtf( hHrtf->hHrtfTD ); + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) { - destroy_SetOfHRTF( hHrtf->hSetOfHRTF ); + destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); } - if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtf->binaural_renderer_old ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->binaural_renderer_old ) ) != IVAS_ERR_OK ) { return error; } @@ -3920,44 +3919,44 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) { - if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtf->hHrtfTD ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_HRTF_binary( *hHrtf->hHrtfTD, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_HRTF_binary( *hHrtfBinary->hHrtfTD, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } else { - destroy_td_hrtf( hHrtf->hHrtfTD ); + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } } } if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) { - if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtf->hSetOfHRTF ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfBinary->hSetOfHRTF ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = create_SetOfHRTF_from_binary( *hHrtf->hSetOfHRTF, hHrtf->hrtfReader, output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = create_SetOfHRTF_from_binary( *hHrtfBinary->hSetOfHRTF, hHrtfBinary->hrtfReader, output_Fs ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } else { - destroy_SetOfHRTF( hHrtf->hSetOfHRTF ); + destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); } } } @@ -3971,11 +3970,11 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } - if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtf->room_reverb_flag, hHrtf->intern_audio_config, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtfBinary->room_reverb_flag, hHrtfBinary->intern_audio_config, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } else @@ -3994,11 +3993,11 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } - if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_parambin_HRTF_from_binary( *hHrtfParambin, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } else @@ -4009,24 +4008,24 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } - if ( hHrtf->hHrtfStatistics == NULL ) + if ( hHrtfBinary->hHrtfStatistics == NULL ) { - if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtf->hHrtfStatistics ) ) != IVAS_ERR_OK ) + if ( ( error = IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfBinary->hHrtfStatistics ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); return error; } - if ( ( error = load_reverb_binary( *hHrtf->hHrtfStatistics, output_Fs, hHrtf->hrtfReader ) ) != IVAS_ERR_OK ) + if ( ( error = load_reverb_binary( *hHrtfBinary->hHrtfStatistics, output_Fs, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { - fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtf->hrtfFileName ); + fprintf( stderr, "\nError in loading HRTF binary file %s \n\n", hHrtfBinary->hrtfFileName ); return error; } else { - destroy_hrtf_statistics( hHrtf->hHrtfStatistics ); + destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); } } } -- GitLab From fed0cff0b418918a1d09ab81eb0b0437b97fe55b Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 11:56:51 +0200 Subject: [PATCH 12/27] rename 'hHrtf' to 'hHrtfBinary' --- apps/decoder.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index b0fd3994bf..6f19a4e3a4 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -177,7 +177,7 @@ typedef struct IVAS_AUDIO_CONFIG intern_audio_config; int16_t room_reverb_flag; -} IVAS_DEC_HRTF_WRAPPER; +} IVAS_DEC_HRTF_BINARY_WRAPPER; #endif @@ -188,17 +188,17 @@ typedef struct static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); #ifdef FIX_HRTF_LOAD -static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); +static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); #else static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); #endif #ifdef FIX_HRTF_LOAD_JBM -static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); +static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #else static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #endif #ifdef FIX_HRTF_LOAD -static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); +static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); #endif #ifdef DEBUGGING @@ -236,7 +236,7 @@ int main( int16_t *pcmBuf = NULL; IVAS_RENDER_FRAMESIZE asked_frame_size; #ifdef FIX_HRTF_LOAD - IVAS_DEC_HRTF_WRAPPER hHrtfBinary; + IVAS_DEC_HRTF_BINARY_WRAPPER hHrtfBinary; #else IVAS_DEC_HRTF_HANDLE *hHrtfTD = NULL; IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF = NULL; @@ -2179,7 +2179,7 @@ static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, #ifdef FIX_HRTF_LOAD - IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, #endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, @@ -3150,7 +3150,7 @@ static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, #ifdef FIX_HRTF_LOAD_JBM - IVAS_DEC_HRTF_WRAPPER *hHrtf, + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, #endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, @@ -3873,7 +3873,7 @@ static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( *---------------------------------------------------------------------*/ static ivas_error IVAS_DEC_LoadHrtfFromFile( - IVAS_DEC_HRTF_WRAPPER *hHrtfBinary, + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ) { -- GitLab From f02f257dd33821164063e2c9348c9644a10dde70 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 12:03:12 +0200 Subject: [PATCH 13/27] fix 'variable set but not used' compilation warnings --- lib_dec/ivas_ism_dec.c | 6 +++++- lib_dec/ivas_mct_dec.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index f6e695e152..6fcf0d1f27 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -67,9 +67,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; int16_t nchan_out_buff, nchan_out_buff_old; +#ifndef FIX_HRTF_LOAD_JBM AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; +#endif error = IVAS_ERR_OK; nCPE_old = st_ivas->nCPE; @@ -107,12 +109,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } +#ifndef FIX_HRTF_LOAD_JBM /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; hIntSetupOld = st_ivas->hIntSetup; tc_granularity_new = 1; renderer_type_old = st_ivas->renderer_type; +#endif /*-----------------------------------------------------------------* * Initialize the needed renderer struct and destroy the unnecessary renderer struct *-----------------------------------------------------------------*/ @@ -368,7 +372,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } - return error; + return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 426040e893..d708528cb9 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -752,8 +752,10 @@ static ivas_error ivas_mc_dec_reconfig( int16_t tc_nchan_tc_new; int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; +#ifndef FIX_HRTF_LOAD_JBM AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; +#endif int16_t nchan_out_buff_old, nchan_out_buff; error = IVAS_ERR_OK; @@ -784,11 +786,13 @@ static ivas_error ivas_mc_dec_reconfig( } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); +#ifndef FIX_HRTF_LOAD_JBM /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; hIntSetupOld = st_ivas->hIntSetup; tc_granularity_new = 1; +#endif /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; ivas_renderer_select( st_ivas ); -- GitLab From 8269b26ddd27d69b06636f58560998f5aef25920 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 14:47:14 +0200 Subject: [PATCH 14/27] formatting --- lib_dec/ivas_ism_dec.c | 79 +++++++++++++++------------- lib_dec/ivas_masa_dec.c | 7 ++- lib_dec/ivas_mct_dec.c | 109 ++++++++++++++++++++------------------- lib_dec/ivas_omasa_dec.c | 1 - lib_dec/ivas_sba_dec.c | 4 ++ 5 files changed, 110 insertions(+), 90 deletions(-) diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 6fcf0d1f27..63de2c5096 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -73,7 +73,9 @@ static ivas_error ivas_ism_bitrate_switching_dec( RENDERER_TYPE renderer_type_old; #endif +#ifndef FIX_HRTF_LOAD_JBM error = IVAS_ERR_OK; +#endif nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; @@ -322,57 +324,58 @@ static ivas_error ivas_ism_bitrate_switching_dec( * floating-point output audio buffers *-----------------------------------------------------------------*/ - { - nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; } /*-----------------------------------------------------------------* * JBM TC buffers *-----------------------------------------------------------------*/ - { - int16_t tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; + int16_t tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; - if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - tc_nchan_full_new = 0; - } - /* reconfigure buffer */ - if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || - hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new ) + if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + tc_nchan_full_new = 0; + } + + /* reconfigure buffer */ + if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || + hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) { - if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) - { - return error; - } + return error; } + } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } +#ifdef FIX_HRTF_LOAD_JBM return IVAS_ERR_OK; +#else + return error; +#endif } @@ -398,7 +401,9 @@ ivas_error ivas_ism_dec_config( ivas_error error; int16_t nchan_transport_old; +#ifndef FIX_HRTF_LOAD_JBM error = IVAS_ERR_OK; +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* Assumes that num of input objects are constant */ @@ -427,7 +432,7 @@ ivas_error ivas_ism_dec_config( if ( st_ivas->ini_active_frame != 0 ) { /* ISM bit-rate switching */ - if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hDecoderConfig->ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) + if ( ( st_ivas->ism_mode != last_ism_mode ) || ( ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { #ifdef FIX_HRTF_LOAD_JBM if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode ) ) != IVAS_ERR_OK ) @@ -485,5 +490,9 @@ ivas_error ivas_ism_dec_config( break; } +#ifdef FIX_HRTF_LOAD_JBM + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b6063e377c..ea924f45ff 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1324,8 +1324,9 @@ ivas_error ivas_masa_dec_reconfigure( int16_t pos_idx; int32_t ism_total_brate; +#ifndef FIX_HRTF_LOAD_JBM error = IVAS_ERR_OK; - +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; @@ -1568,7 +1569,11 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef FIX_HRTF_LOAD_JBM + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index d708528cb9..de145c9a57 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -758,7 +758,9 @@ static ivas_error ivas_mc_dec_reconfig( #endif int16_t nchan_out_buff_old, nchan_out_buff; +#ifndef FIX_HRTF_LOAD_JBM error = IVAS_ERR_OK; +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); @@ -1322,68 +1324,65 @@ static ivas_error ivas_mc_dec_reconfig( * JBM TC buffers *-----------------------------------------------------------------*/ - { - int16_t tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; + int16_t tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; - tc_nchan_full_new = tc_nchan_allocate_new; - } + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + tc_nchan_full_new = tc_nchan_allocate_new; + } - if ( st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) - { - tc_nchan_full_new = 0; - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + if ( st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) + { + tc_nchan_full_new = 0; + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; + tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) { - tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; - tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) - { - tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; - tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; - tc_nchan_allocate_new = tc_nchan_tc_new; - } - tc_nchan_full_new = tc_nchan_allocate_new; + tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; + tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; + tc_nchan_allocate_new = tc_nchan_tc_new; } + tc_nchan_full_new = tc_nchan_allocate_new; + } - /* reconfigure buffer */ - if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || - hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new || - tc_granularity_new != hTcBuffer->n_samples_granularity ) - { - if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) - { - return error; - } - } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } - else if ( st_ivas->hParamMC != NULL ) + /* reconfigure buffer */ + if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || + hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new || + tc_granularity_new != hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) { - st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + return error; } } - + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + else if ( st_ivas->hParamMC != NULL ) + { + st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } /*-----------------------------------------------------------------* * floating-point output audio buffers @@ -1396,5 +1395,9 @@ static ivas_error ivas_mc_dec_reconfig( return error; } +#ifdef FIX_HRTF_LOAD_JBM + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 6591cda42b..636e371013 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -554,7 +554,6 @@ ivas_error ivas_omasa_dec_config( } } - return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 8f6ceaca12..f0cc8e1237 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -667,7 +667,11 @@ ivas_error ivas_sba_dec_reconfigure( return error; } +#ifdef FIX_HRTF_LOAD_JBM + return IVAS_ERR_OK; +#else return error; +#endif } -- GitLab From d5bc65896c68d9dc9f479ae6eea73efcf69fefd6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 16:06:09 +0200 Subject: [PATCH 15/27] fixes --- lib_dec/ivas_init_dec.c | 1 + lib_dec/ivas_jbm_dec.c | 2 +- lib_dec/lib_dec.c | 29 +++++++++++++++++++---------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 37ea12d2db..2a9d505487 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -191,6 +191,7 @@ ivas_error ivas_dec_get_format( } /* this should be non-zero if original input format was MASA_ISM_FORMAT */ + st_ivas->ism_mode = ISM_MODE_NONE; st_ivas->nchan_ism = st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2]; if ( st_ivas->nchan_ism > 0 ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 29b2cd1403..4cb5aac155 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -1547,7 +1547,7 @@ ivas_error ivas_jbm_dec_render( /*--------------------------------------------------------------------------* - * ivas_jbm_dec_dec_flush_renderer() + * ivas_jbm_dec_flush_renderer() * * Flush samples if renderer granularity changes on a bitrate change *--------------------------------------------------------------------------*/ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 9fdeda3b23..4018bd2f8b 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1154,13 +1154,19 @@ ivas_error IVAS_DEC_ReadFormat( *intern_audio_config = st_ivas->intern_config; #ifdef FIX_HRTF_LOAD_JBM - if ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) + if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) || + ( st_ivas->ini_active_frame > 0 && ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) ) { /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv render what still fits in the new granularity */ int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - // st_ivas->nchan_transport = nchan_transport_old; // ToDo: commented for the moment to kepp the changes bit-exact but this is likely a bug in the main + // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main + + if ( st_ivas->ivas_format == MASA_FORMAT ) + { + st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main + } if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { @@ -3956,18 +3962,21 @@ ivas_error IVAS_DEC_VoIP_GetSamples( bool tmp; #ifdef FIX_HRTF_LOAD_JBM - if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { - uint16_t nSamplesFlushed_ref = hIvasDec->nSamplesFlushed; - - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) + if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) { - return error; - } + uint16_t nSamplesFlushed_ref = hIvasDec->nSamplesFlushed; + + if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } - hIvasDec->nSamplesFlushed = nSamplesFlushed_ref; + hIvasDec->nSamplesFlushed = nSamplesFlushed_ref; - *bitstreamReadDone = false; + *bitstreamReadDone = false; + } } #endif -- GitLab From 922ef1b883ba0dcf7e184ae23cd9f9c4b57a0369 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Oct 2024 17:40:03 +0200 Subject: [PATCH 16/27] merge FIX_HRTF_LOAD_JBM into FIX_HRTF_LOAD --- apps/decoder.c | 36 +++--------- lib_com/ivas_prot.h | 12 ++-- lib_com/options.h | 2 +- lib_dec/ivas_init_dec.c | 31 ++++------ lib_dec/ivas_ism_dec.c | 87 ++++++++++++++-------------- lib_dec/ivas_masa_dec.c | 8 +-- lib_dec/ivas_mct_dec.c | 121 ++++++++++++++++++++------------------- lib_dec/ivas_omasa_dec.c | 4 +- lib_dec/ivas_sba_dec.c | 8 +-- lib_dec/lib_dec.c | 52 +++++++---------- lib_dec/lib_dec.h | 4 +- 11 files changed, 166 insertions(+), 199 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6f19a4e3a4..4725661ed5 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -189,18 +189,12 @@ static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); #ifdef FIX_HRTF_LOAD static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#else -static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); -#endif -#ifdef FIX_HRTF_LOAD_JBM static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); +static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); #else +static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, ISAR_SPLIT_REND_BITS_DATA *splitRendBits, IVAS_DEC_HANDLE hIvasDec, int16_t *pcmBuf ); static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, Vector3PairFileReader *referenceVectorReader, IVAS_DEC_HANDLE hIvasDec ); #endif -#ifdef FIX_HRTF_LOAD -static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ); -#endif - #ifdef DEBUGGING static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); static int16_t app_own_random( int16_t *seed ); @@ -777,18 +771,6 @@ int main( hHrtfBinary.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; hHrtfBinary.room_reverb_flag = 0; hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; -#ifndef FIX_HRTF_LOAD_JBM - if ( arg.voipMode ) - { - hHrtf.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; - hHrtf.binaural_renderer_old = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; - if ( ( error = IVAS_DEC_LoadHrtfFromFile( &hHrtfBinary, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) - { - fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); - goto cleanup; - } - } -#endif #else if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) { @@ -908,7 +890,7 @@ int main( if ( arg.voipMode ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); #else error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); @@ -2542,7 +2524,7 @@ static ivas_error decodeG192( #endif /* Feed into decoder */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD #ifdef OBJ_EDITING_API , isSplitRend, @@ -3149,7 +3131,7 @@ static ivas_error writeJbmTraceFileFrameWrapper( const void *data, void *writer static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, #endif RotFileReader *headRotReader, @@ -3202,7 +3184,7 @@ static ivas_error decodeVoIP( int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD bool bitstreamReadDone = false; #endif @@ -3499,7 +3481,7 @@ static ivas_error decodeVoIP( #ifdef SUPPORT_JBM_TRACEFILE if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD , &bitstreamReadDone #endif @@ -3510,7 +3492,7 @@ static ivas_error decodeVoIP( ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered, ¶meterAvailableForEditing -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD , &bitstreamReadDone #endif @@ -3524,7 +3506,7 @@ static ivas_error decodeVoIP( fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( bitstreamReadDone == true ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 416d1dddd4..c8d1a8169a 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -326,7 +326,7 @@ ivas_error ivas_dec_get_format( #endif ivas_error ivas_dec_setup( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -670,7 +670,7 @@ ivas_error ivas_mc_enc_config( ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx /* i : LS config. index */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -1090,7 +1090,7 @@ ivas_error ivas_ism_enc_config( ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode /* i/o: last ISM mode */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed on renderer change*/ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -3487,7 +3487,7 @@ void ivas_sba_set_cna_cng_flag( ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesFlushed, /* o : number of samples flushed */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -4948,7 +4948,7 @@ void ivas_masa_enc_reconfigure( ivas_error ivas_masa_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -5656,7 +5656,7 @@ ivas_error ivas_omasa_enc_config( ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ diff --git a/lib_com/options.h b/lib_com/options.h index 54664ebfef..9a5eaf513f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -174,7 +174,7 @@ #define FIX_VOIP_FUNCTIONS /* VA: fix data type mismatch in IVAS_DEC_VoIP_SetScale() + add sanity checks to API functions */ #define FIX_HRTF_LOAD /* VA: issue 1187: fix memory issue when HRTFs are loaded from a binary file */ -#define FIX_HRTF_LOAD_JBM + /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 2a9d505487..1b72a89c2b 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -143,9 +143,6 @@ ivas_error ivas_dec_get_format( else if ( st_ivas->ivas_format == ISM_FORMAT ) { /* read the number of objects */ -#ifndef FIX_HRTF_LOAD_JBM - st_ivas->nchan_transport = 1; -#endif nchan_ism = 1; k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) @@ -156,13 +153,12 @@ ivas_error ivas_dec_get_format( st_ivas->nchan_ism = nchan_ism; st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); -#ifdef FIX_HRTF_LOAD_JBM + st_ivas->nchan_transport = nchan_ism; if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; } -#endif } else if ( st_ivas->ivas_format == SBA_FORMAT ) { @@ -331,9 +327,6 @@ ivas_error ivas_dec_get_format( if ( st_ivas->ivas_format == ISM_FORMAT ) { /* read the number of objects */ -#ifndef FIX_HRTF_LOAD_JBM - st_ivas->nchan_transport = 1; -#endif nchan_ism = 1; k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS ); while ( st_ivas->bit_stream[k] && nchan_ism < MAX_NUM_OBJECTS ) @@ -354,13 +347,11 @@ ivas_error ivas_dec_get_format( st_ivas->ism_mode = (ISM_MODE) ( idx + 1 ); } -#ifdef FIX_HRTF_LOAD_JBM st_ivas->nchan_transport = nchan_ism; if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; } -#endif } } @@ -379,7 +370,7 @@ ivas_error ivas_dec_get_format( ivas_error ivas_dec_setup( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -438,7 +429,7 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = nchan_ism; -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_ism_dec_config( st_ivas, st_ivas->ism_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_dec_config( st_ivas, st_ivas->ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -460,7 +451,7 @@ ivas_error ivas_dec_setup( num_bits_read += SBA_ORDER_BITS; if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -526,7 +517,7 @@ ivas_error ivas_dec_setup( } else { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -538,7 +529,7 @@ ivas_error ivas_dec_setup( } else { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -563,7 +554,7 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -598,7 +589,7 @@ ivas_error ivas_dec_setup( if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->last_active_ivas_total_brate ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -648,7 +639,7 @@ ivas_error ivas_dec_setup( num_bits_read += MC_LS_SETUP_BITS; /* select MC format mode; reconfigure the MC format decoder */ -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_mc_dec_config( st_ivas, idx ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_mc_dec_config( st_ivas, idx, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -737,7 +728,7 @@ ivas_error ivas_dec_setup( st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_sba_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -787,7 +778,7 @@ ivas_error ivas_dec_setup( last_ism_mode = st_ivas->ism_mode; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_ism_dec_config( st_ivas, last_ism_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_dec_config( st_ivas, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 63de2c5096..67f189e299 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -50,7 +50,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nchan_transport_old, /* i : last number of transport channels */ const ISM_MODE last_ism_mode /* i : last ISM mode */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples rendered */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -67,13 +67,13 @@ static ivas_error ivas_ism_bitrate_switching_dec( int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; int16_t nchan_out_buff, nchan_out_buff_old; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; #endif -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; #endif nCPE_old = st_ivas->nCPE; @@ -111,7 +111,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; hIntSetupOld = st_ivas->hIntSetup; @@ -151,7 +151,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD /* flush already done in IVAS_DEC_ReadFormat() */ #else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, MC_MODE_NONE, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -324,54 +324,57 @@ static ivas_error ivas_ism_bitrate_switching_dec( * floating-point output audio buffers *-----------------------------------------------------------------*/ - nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) { - return error; + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } } /*-----------------------------------------------------------------* * JBM TC buffers *-----------------------------------------------------------------*/ + { + int16_t tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - int16_t tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; - if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) - { - tc_nchan_full_new = 0; - } + if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + tc_nchan_full_new = 0; + } - /* reconfigure buffer */ - if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || - hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new ) - { - if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + /* reconfigure buffer */ + if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || + hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new ) { - return error; + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } } - } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD return IVAS_ERR_OK; #else return error; @@ -389,7 +392,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( ivas_error ivas_ism_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const ISM_MODE last_ism_mode /* i/o: last ISM mode */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed when the renderer granularity changes */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -401,7 +404,7 @@ ivas_error ivas_ism_dec_config( ivas_error error; int16_t nchan_transport_old; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; #endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -434,7 +437,7 @@ ivas_error ivas_ism_dec_config( /* ISM bit-rate switching */ if ( ( st_ivas->ism_mode != last_ism_mode ) || ( ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -460,7 +463,7 @@ ivas_error ivas_ism_dec_config( /* ISM mode switching */ if ( st_ivas->ism_mode != last_ism_mode ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_ism_bitrate_switching_dec( st_ivas, nchan_transport_old, last_ism_mode, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -490,7 +493,7 @@ ivas_error ivas_ism_dec_config( break; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD return IVAS_ERR_OK; #else return error; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index ea924f45ff..f0eb77a512 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1306,7 +1306,7 @@ static int16_t decode_lfe_to_total_energy_ratio( ivas_error ivas_masa_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -1324,7 +1324,7 @@ ivas_error ivas_masa_dec_reconfigure( int16_t pos_idx; int32_t ism_total_brate; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; #endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -1521,7 +1521,7 @@ ivas_error ivas_masa_dec_reconfigure( { if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD /* flush already done in IVAS_DEC_ReadFormat() */ #else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -1569,7 +1569,7 @@ ivas_error ivas_masa_dec_reconfigure( } } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD return IVAS_ERR_OK; #else return error; diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index de145c9a57..fe2ca5dbaa 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -54,7 +54,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas ); #else static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamplesRendered, const PCM_RESOLUTION pcm_resolution, void *data ); @@ -667,7 +667,7 @@ void ivas_mct_dec_close( ivas_error ivas_mc_dec_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t idx /* i : LS config. index */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : samples flushed from last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -707,7 +707,7 @@ ivas_error ivas_mc_dec_config( { if ( st_ivas->hDecoderConfig->last_ivas_total_brate != st_ivas->hDecoderConfig->ivas_total_brate || last_mc_mode != st_ivas->mc_mode ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_mc_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_mc_dec_reconfig( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -733,7 +733,7 @@ ivas_error ivas_mc_dec_config( static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -752,13 +752,13 @@ static ivas_error ivas_mc_dec_reconfig( int16_t tc_nchan_tc_new; int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; #endif int16_t nchan_out_buff_old, nchan_out_buff; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; #endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -788,7 +788,7 @@ static ivas_error ivas_mc_dec_reconfig( } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; hIntSetupOld = st_ivas->hIntSetup; @@ -828,7 +828,7 @@ static ivas_error ivas_mc_dec_reconfig( tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD /* flush already done in IVAS_DEC_ReadFormat() */ #else if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) @@ -1323,65 +1323,66 @@ static ivas_error ivas_mc_dec_reconfig( /*-----------------------------------------------------------------* * JBM TC buffers *-----------------------------------------------------------------*/ + { + int16_t tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - int16_t tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; - - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; - tc_nchan_full_new = tc_nchan_tc_new; + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_tc_new; - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) - { - tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; - tc_nchan_full_new = tc_nchan_allocate_new; - } + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + tc_nchan_full_new = tc_nchan_allocate_new; + } - if ( st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) - { - tc_nchan_full_new = 0; - } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) - { - tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; - tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) + if ( st_ivas->mc_mode == MC_MODE_PARAMMC && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) { - tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; - tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; - tc_nchan_allocate_new = tc_nchan_tc_new; + tc_nchan_full_new = 0; + } + else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + { + tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; + tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) + { + tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; + tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; + tc_nchan_allocate_new = tc_nchan_tc_new; + } + tc_nchan_full_new = tc_nchan_allocate_new; } - tc_nchan_full_new = tc_nchan_allocate_new; - } - /* reconfigure buffer */ - if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || - hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new || - tc_granularity_new != hTcBuffer->n_samples_granularity ) - { - if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + /* reconfigure buffer */ + if ( hTcBuffer->tc_buffer_mode != tc_buffer_mode_new || hTcBuffer->nchan_transport_jbm != tc_nchan_tc_new || + hTcBuffer->nchan_buffer_full != tc_nchan_full_new || hTcBuffer->nchan_transport_internal != tc_nchan_allocate_new || + tc_granularity_new != hTcBuffer->n_samples_granularity ) { - return error; + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + else if ( st_ivas->hParamMC != NULL ) + { + st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - if ( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); - } - else if ( st_ivas->hParamMC != NULL ) - { - st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; - st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /*-----------------------------------------------------------------* @@ -1395,7 +1396,7 @@ static ivas_error ivas_mc_dec_reconfig( return error; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD return IVAS_ERR_OK; #else return error; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 636e371013..d1e34f20c5 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -221,7 +221,7 @@ void ivas_omasa_data_close( ivas_error ivas_omasa_dec_config( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -274,7 +274,7 @@ ivas_error ivas_omasa_dec_config( { st_ivas->hCPE[0]->nchan_out = 1; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #else else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, pcm_resolution, data ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index f0cc8e1237..0f3dfba4c0 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -102,7 +102,7 @@ void ivas_sba_set_cna_cng_flag( ivas_error ivas_sba_dec_reconfigure( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint16_t *nSamplesFlushed, /* o : number of samples flushed */ const PCM_RESOLUTION pcm_resolution, /* i : type for the decoded PCM resolution */ @@ -164,7 +164,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD *nSamplesFlushed = 0; #endif granularity_new = st_ivas->hTcBuffer->n_samples_granularity; @@ -214,7 +214,7 @@ ivas_error ivas_sba_dec_reconfigure( /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD /* flush already done in IVAS_DEC_ReadFormat() */ #else /* write back info for correct rendering of the flushable samples */ @@ -667,7 +667,7 @@ ivas_error ivas_sba_dec_reconfigure( return error; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD return IVAS_ERR_OK; #else return error; diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 4018bd2f8b..0304ef265d 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -122,7 +122,7 @@ static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const int16_t nOutSampl static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, int16_t *bitstream_format_internal, int16_t *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const uint16_t nTransportChannels, const uint16_t l_ts ); -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels ); #else static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, uint16_t *nTcBufferGranularity, uint8_t *nTransportChannels, uint8_t *nOutChannels, uint16_t *nSamplesRendered, const IVAS_DEC_PCM_TYPE pcmType, void *data ); @@ -842,7 +842,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( uint16_t *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */ const uint16_t num_bits, /* i : number of bits in input bitstream */ int16_t bfi /* i : bad frame indicator flag */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD #ifdef OBJ_EDITING_API , int16_t isSplitRend, @@ -926,17 +926,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; #ifdef OBJ_EDITING_API -#ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed -#ifndef FIX_HRTF_LOAD_JBM - if ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) - { - if ( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK ) - { - return error; - } - } -#endif -#else +#ifndef FIX_HRTF_LOAD /* Decode TCs, do TSM and feed to renderer. If TSM is generally enabled, we have to wait for the first good frame. Otherwise, we directly decode the first frame in any case. @@ -1153,7 +1143,7 @@ ivas_error IVAS_DEC_ReadFormat( *intern_audio_config = st_ivas->intern_config; -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) || ( st_ivas->ini_active_frame > 0 && ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) ) { @@ -1161,11 +1151,11 @@ ivas_error IVAS_DEC_ReadFormat( render what still fits in the new granularity */ int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main + // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue 1200 if ( st_ivas->ivas_format == MASA_FORMAT ) { - st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main + st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue 1199 } if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) @@ -1210,14 +1200,14 @@ ivas_error IVAS_DEC_GetSamplesDecoder( /* If TSM is generally enabled, we have to wait for the first good frame. Otherwise, we directly decode the first frame in any case. */ -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) #else if ( ( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && hIvasDec->hasBeenFedFirstGoodFrame ) || !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) #endif { uint16_t l_ts, nTimeScalerOutSamples; -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD uint8_t nTransportChannels; #else uint8_t nTransportChannels, nOutChannels; @@ -1232,7 +1222,7 @@ ivas_error IVAS_DEC_GetSamplesDecoder( } } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels ) ) != IVAS_ERR_OK ) #else if ( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &hIvasDec->nSamplesFlushed, hIvasDec->pcmType, hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) @@ -2160,7 +2150,7 @@ static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ uint16_t *nTcBufferGranularity, /* o : granularity of the TC Buffer */ uint8_t *nTransportChannels /* o : number of decoded transport PCM channels */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD , uint8_t *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */ uint16_t *nSamplesRendered, /* o : number of samples flushed from the last frame */ @@ -2171,7 +2161,7 @@ static ivas_error IVAS_DEC_Setup( { ivas_error error; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD *nSamplesRendered = 0; #endif if ( hIvasDec->mode == IVAS_DEC_MODE_EVS ) @@ -2179,14 +2169,14 @@ static ivas_error IVAS_DEC_Setup( if ( hIvasDec->st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) { *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; #endif } else { *nTransportChannels = 1; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD *nOutChannels = 1; #endif } @@ -2207,7 +2197,7 @@ static ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK ) #else if ( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, pcm_type_API_to_internal( pcmType ), data ) ) != IVAS_ERR_OK ) @@ -2219,7 +2209,7 @@ static ivas_error IVAS_DEC_Setup( *nTransportChannels = (uint8_t) st_ivas->hTcBuffer->nchan_transport_jbm; *nTcBufferGranularity = (uint16_t) st_ivas->hTcBuffer->n_samples_granularity; -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD *nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; #endif @@ -3727,7 +3717,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter #endif -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD , bool *bitstreamReadDone #endif @@ -3854,7 +3844,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD #if defined( OBJ_EDITING_API ) , 0, @@ -3865,7 +3855,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { return error; } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD *bitstreamReadDone = true; #endif @@ -3874,7 +3864,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { /* Decoder has been initialized with first good frame - do PLC */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD #if defined( OBJ_EDITING_API ) , 0, @@ -3915,7 +3905,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true ) { /* new bitstream was feeded, return for reconfiguration */ @@ -3961,7 +3951,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( int16_t nSamplesToRender, nSamplesRendered_loop; bool tmp; -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { if ( hIvasDec->nSamplesAvailableNext == 0 || hIvasDec->nSamplesAvailableNext == hIvasDec->nSamplesFrame ) diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 72aa7cf399..ff8decd427 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -150,7 +150,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( uint16_t *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */ const uint16_t num_bits, /* i : number of bits in input bitstream */ int16_t bfi /* i : bad frame indicator flag */ -#ifndef FIX_HRTF_LOAD_JBM +#ifndef FIX_HRTF_LOAD #if defined( OBJ_EDITING_API ) , int16_t isSplitRend, @@ -321,7 +321,7 @@ ivas_error IVAS_DEC_VoIP_GetSamples( , JbmTraceFileWriterFn jbmWriterFn, void* jbmWriter #endif -#ifdef FIX_HRTF_LOAD_JBM +#ifdef FIX_HRTF_LOAD , bool *bitstreamReadDone #endif -- GitLab From 4fd3247316587a29f9aba37a5d7802d5c8fe0c4a Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 13:00:05 +0200 Subject: [PATCH 17/27] address remaining todos --- apps/decoder.c | 22 +++++++------- apps/renderer.c | 4 +++ lib_com/common_api_types.h | 21 +++++++++++-- lib_dec/ivas_init_dec.c | 7 ++--- lib_dec/lib_dec.c | 52 ++++++++++++++++----------------- lib_dec/lib_dec.h | 10 +++---- lib_isar/lib_isar_post_rend.c | 4 +++ lib_rend/ivas_render_config.c | 4 +++ lib_rend/lib_rend.c | 26 ++++++++++++++++- lib_util/hrtf_file_reader.c | 2 +- lib_util/hrtf_file_reader.h | 2 +- lib_util/render_config_reader.c | 16 ++++++++++ 12 files changed, 117 insertions(+), 53 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 4725661ed5..185e0ccb7d 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -171,8 +171,8 @@ typedef struct IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF; IVAS_DEC_HRTF_STATISTICS_HANDLE *hHrtfStatistics; - ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; - ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old; + IVAS_BIN_RENDERER_TYPE binaural_renderer; + IVAS_BIN_RENDERER_TYPE binaural_renderer_old; IVAS_AUDIO_CONFIG intern_audio_config; int16_t room_reverb_flag; @@ -768,7 +768,7 @@ int main( #ifdef FIX_HRTF_LOAD hHrtfBinary.hrtfReader = hrtfReader; hHrtfBinary.hrtfFileName = arg.hrtfFileName; - hHrtfBinary.binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; + hHrtfBinary.binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; hHrtfBinary.room_reverb_flag = 0; hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; #else @@ -3860,7 +3860,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( const int32_t output_Fs ) { ivas_error error; - ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer; + IVAS_BIN_RENDERER_TYPE binaural_renderer; if ( hHrtfBinary == NULL || hIvasDec == NULL ) { @@ -3869,18 +3869,18 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( binaural_renderer = hHrtfBinary->binaural_renderer; - if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { /*------------------------------------------------------------------------------------------* * Release HRTF binary data *------------------------------------------------------------------------------------------*/ - if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } - if ( !( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); } @@ -3899,7 +3899,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } - if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { @@ -3921,7 +3921,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } - if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { if ( ( error = IVAS_DEC_GetHrtfCRendHandle( hIvasDec, &hHrtfBinary->hSetOfHRTF ) ) != IVAS_ERR_OK ) { @@ -3943,7 +3943,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } - if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv = NULL; if ( ( error = IVAS_DEC_GetHrtfFastConvHandle( hIvasDec, &hHrtfFastConv ) ) != IVAS_ERR_OK ) @@ -3966,7 +3966,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } } - if ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin = NULL; if ( ( error = IVAS_DEC_GetHrtfParamBinHandle( hIvasDec, &hHrtfParambin ) ) != IVAS_ERR_OK ) diff --git a/apps/renderer.c b/apps/renderer.c index b9e7e212f7..767d4bb60d 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -615,7 +615,11 @@ static int16_t get_cldfb_in_flag( int16_t cldfb_in_flag; cldfb_in_flag = 0; +#ifdef FIX_HRTF_LOAD + if ( renderConfig->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( renderConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { #ifdef DEBUGGING cldfb_in_flag = 1; diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index dde21f92e9..53b03e4e1f 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -213,6 +213,18 @@ typedef struct _IVAS_JBM_TRACE_DATA } IVAS_JBM_TRACE_DATA; +#ifdef FIX_HRTF_LOAD +typedef enum _ivas_binaural_renderer_type +{ + IVAS_BIN_RENDERER_TYPE_NONE, + IVAS_BIN_RENDERER_TYPE_CREND, + IVAS_BIN_RENDERER_TYPE_FASTCONV, + IVAS_BIN_RENDERER_TYPE_PARAMBIN, + IVAS_BIN_RENDERER_TYPE_TDREND, + IVAS_BIN_RENDERER_TYPE_DEFAULT, + +} IVAS_BIN_RENDERER_TYPE; +#endif /*----------------------------------------------------------------------------------* * Split rendering API constants, structures, and enums @@ -251,11 +263,9 @@ typedef enum } ISAR_SPLIT_REND_CODEC; +#ifndef FIX_HRTF_LOAD typedef enum { -#ifdef FIX_HRTF_LOAD // VE: rename the enum -> IVAS_RENDERER_xx - ISAR_SPLIT_REND_RENDERER_SELECTION_NONE, -#endif ISAR_SPLIT_REND_RENDERER_SELECTION_CREND, ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV, ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN, @@ -263,6 +273,7 @@ typedef enum ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT, } ISAR_SPLIT_REND_RENDERER_SELECTION; +#endif typedef struct _ISAR_SPLIT_REND_BITS_DATA { @@ -294,7 +305,11 @@ typedef struct _ISAR_SPLIT_REND_CONFIG int16_t codec_frame_size_ms; /* Codec frame size in milliseconds, only relevant with LC3plus */ ISAR_SPLIT_REND_POSE_CORRECTION_MODE poseCorrectionMode; ISAR_SPLIT_REND_CODEC codec; +#ifdef FIX_HRTF_LOAD + IVAS_BIN_RENDERER_TYPE rendererSelection; +#else ISAR_SPLIT_REND_RENDERER_SELECTION rendererSelection; +#endif int16_t lc3plus_highres; } ISAR_SPLIT_REND_CONFIG_DATA, *ISAR_SPLIT_REND_CONFIG_HANDLE; diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 1b72a89c2b..8ee5c1f74a 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1153,15 +1153,12 @@ ivas_error ivas_init_decoder_front( } } +#ifndef FIX_HRTF_LOAD /*-------------------------------------------------------------------* * Allocate HRTF binary handle *--------------------------------------------------------------------*/ -#ifdef FIX_HRTF_LOAD // VE: TODO - JBM decoder path to be addressed - if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->hDecoderConfig->Opt_tsm ) -#else if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) -#endif { if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { @@ -1187,7 +1184,7 @@ ivas_error ivas_init_decoder_front( return error; } } - +#endif /*-------------------------------------------------------------------* * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 0304ef265d..021e27cfd8 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1063,10 +1063,10 @@ ivas_error IVAS_DEC_FeedFrame_Serial( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_ReadFormat( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer, /* o : binaural renderer type */ - int16_t *room_reverb_flag, /* o : room reverb flag */ - IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ + int16_t *room_reverb_flag, /* o : room reverb flag */ + IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ) { ivas_error error; @@ -1113,14 +1113,14 @@ ivas_error IVAS_DEC_ReadFormat( switch ( st_ivas->renderer_type ) { case RENDERER_BINAURAL_OBJECTS_TD: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_TDREND; break; case RENDERER_BINAURAL_MIXER_CONV: case RENDERER_BINAURAL_MIXER_CONV_ROOM: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_CREND; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_CREND; break; case RENDERER_BINAURAL_FASTCONV: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { @@ -1129,21 +1129,20 @@ ivas_error IVAS_DEC_ReadFormat( break; case RENDERER_BINAURAL_FASTCONV_ROOM: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; *room_reverb_flag = 1; break; case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_PARAMBIN; break; default: - *binaural_renderer = ISAR_SPLIT_REND_RENDERER_SELECTION_NONE; + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; break; } *intern_audio_config = st_ivas->intern_config; -#ifdef FIX_HRTF_LOAD if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) || ( st_ivas->ini_active_frame > 0 && ( st_ivas->ivas_format == MASA_FORMAT || st_ivas->ivas_format == MASA_ISM_FORMAT ) && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) ) { @@ -1166,7 +1165,6 @@ ivas_error IVAS_DEC_ReadFormat( } } } -#endif } st_ivas->ism_mode = ism_mode_old; @@ -3022,8 +3020,8 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_HRTF_binary_open( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer /* i : binaural renderer type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_BIN_RENDERER_TYPE binaural_renderer /* i : binaural renderer type */ ) { ivas_error error; @@ -3038,7 +3036,8 @@ ivas_error IVAS_DEC_HRTF_binary_open( if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { - if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfTD == NULL ) + /* TD binaural renderer */ + if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfTD == NULL ) { if ( ( error = ivas_HRTF_binary_open( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK ) { @@ -3046,7 +3045,8 @@ ivas_error IVAS_DEC_HRTF_binary_open( } } - if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hSetOfHRTF == NULL ) + /* Crend binaural renderer */ + if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hSetOfHRTF == NULL ) { if ( ( error = ivas_HRTF_CRend_binary_open( &( st_ivas->hSetOfHRTF ) ) ) != IVAS_ERR_OK ) { @@ -3054,7 +3054,8 @@ ivas_error IVAS_DEC_HRTF_binary_open( } } - if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfFastConv == NULL ) + /* FastConv binaural renderer */ + if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfFastConv == NULL ) { if ( ( error = ivas_HRTF_fastconv_binary_open( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) { @@ -3062,7 +3063,8 @@ ivas_error IVAS_DEC_HRTF_binary_open( } } - if ( ( binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) && st_ivas->hHrtfParambin == NULL ) + /* Parametric binaural renderer */ + if ( ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && st_ivas->hHrtfParambin == NULL ) { if ( ( error = ivas_HRTF_parambin_binary_open( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { @@ -3090,8 +3092,8 @@ ivas_error IVAS_DEC_HRTF_binary_open( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_HRTF_binary_close( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old /* i : previous binaural renderer type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_BIN_RENDERER_TYPE binaural_renderer_old /* i : previous binaural renderer type */ ) { Decoder_Struct *st_ivas; @@ -3105,20 +3107,18 @@ ivas_error IVAS_DEC_HRTF_binary_close( if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) { -#if 0 - if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); } - if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_CREND || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { /* CRend binaural renderer handle */ ivas_HRTF_CRend_binary_close( &st_ivas->hSetOfHRTF ); } -#endif - if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { /* Fastconv HRTF memories */ @@ -3128,7 +3128,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); } - if ( !( binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN || binaural_renderer_old == ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT ) ) + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { /* Parametric binauralizer HRTF filters */ diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index ff8decd427..93ef686236 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -162,7 +162,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( #ifdef FIX_HRTF_LOAD ivas_error IVAS_DEC_ReadFormat( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - ISAR_SPLIT_REND_RENDERER_SELECTION *binaural_renderer, /* o : binaural renderer type */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ int16_t *room_reverb_flag, /* o : room reverb flag */ IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ); @@ -474,13 +474,13 @@ ivas_error IVAS_DEC_GetHrtfStatisticsHandle( #ifdef FIX_HRTF_LOAD ivas_error IVAS_DEC_HRTF_binary_open( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer /* i : binaural renderer type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_BIN_RENDERER_TYPE binaural_renderer /* i : binaural renderer type */ ); ivas_error IVAS_DEC_HRTF_binary_close( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const ISAR_SPLIT_REND_RENDERER_SELECTION binaural_renderer_old /* i : previous binaural renderer type */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_BIN_RENDERER_TYPE binaural_renderer_old /* i : previous binaural renderer type */ ); #endif diff --git a/lib_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index 101768bb34..38c25ff21a 100644 --- a/lib_isar/lib_isar_post_rend.c +++ b/lib_isar/lib_isar_post_rend.c @@ -1116,7 +1116,11 @@ ivas_error ISAR_POST_REND_InitConfig( hIvasRend->splitRenderConfig.isar_frame_size_ms = 0; /* 0 means "use default for selected codec" */ hIvasRend->splitRenderConfig.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; hIvasRend->splitRenderConfig.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB; +#ifdef FIX_HRTF_LOAD + hIvasRend->splitRenderConfig.rendererSelection = IVAS_BIN_RENDERER_TYPE_DEFAULT; +#else hIvasRend->splitRenderConfig.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; +#endif } return IVAS_ERR_OK; diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index eabaf2d4cb..950e9ee8bf 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -148,7 +148,11 @@ ivas_error ivas_render_config_init_from_rom( ( *hRenderConfig )->split_rend_config.codec_frame_size_ms = 0; /* 0 means "use default for selected codec" */ ( *hRenderConfig )->split_rend_config.codec = ISAR_SPLIT_REND_CODEC_DEFAULT; ( *hRenderConfig )->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB; +#ifdef FIX_HRTF_LOAD + ( *hRenderConfig )->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_DEFAULT; +#else ( *hRenderConfig )->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT; +#endif ( *hRenderConfig )->split_rend_config.lc3plus_highres = 0; return IVAS_ERR_OK; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 64c2009f10..111c1698df 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -2509,7 +2509,11 @@ static ivas_error updateSbaPanGains( case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED: case IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM: { +#ifdef FIX_HRTF_LOAD + if ( hRendCfg->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( hRendCfg->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { assert( *rendCtx.pOutSampleRate == 48000 && "split binaural fast conv mode is currently supported with 48k sampling rate only" ); if ( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) @@ -2529,7 +2533,11 @@ static ivas_error updateSbaPanGains( } case IVAS_AUDIO_CONFIG_BINAURAL: case IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB: +#ifdef FIX_HRTF_LOAD + if ( hRendCfg->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( hRendCfg->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { if ( ( error = ivas_rend_openCldfbRend( &inputSba->cldfbRendWrapper, inConfig, outConfig, &rendCtx.pSplitRendWrapper->multiBinPoseData, *rendCtx.pOutSampleRate ) ) != IVAS_ERR_OK ) { @@ -3372,7 +3380,11 @@ static int16_t getCldfbRendFlag( { isCldfbRend = 0; } +#ifdef FIX_HRTF_LOAD + else if ( ( numMasaInputs > 0 ) || ( numSbaInputs > 0 && hIvasRend->hRendererConfig->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) ) +#else else if ( ( numMasaInputs > 0 ) || ( numSbaInputs > 0 && hIvasRend->hRendererConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) ) +#endif { isCldfbRend = 1; } @@ -3892,7 +3904,11 @@ ivas_error IVAS_REND_GetDelay( { if ( hIvasRend->splitRendWrapper != NULL && hIvasRend->splitRendWrapper->hBinHrSplitPreRend != NULL ) { +#ifdef FIX_HRTF_LOAD + if ( hIvasRend->hRendererConfig->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( hIvasRend->hRendererConfig->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { latency_ns = hIvasRend->inputsSba[i].cldfbRendWrapper.binaural_latency_ns; } @@ -6564,7 +6580,11 @@ static ivas_error renderSbaToSplitBinaural( push_wmops( "renderSbaToSplitBinaural" ); +#ifdef FIX_HRTF_LOAD + if ( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { renderSbaToMultiBinauralCldfb( sbaInput, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, 1, getNumSubframesInBuffer( &outAudio, *sbaInput->base.ctx.pOutSampleRate ) ); @@ -6601,7 +6621,11 @@ static ivas_error renderSbaToBinaural( int16_t subframe_idx; push_wmops( "renderSbaToBinaural" ); +#ifdef FIX_HRTF_LOAD + if ( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection == IVAS_BIN_RENDERER_TYPE_FASTCONV ) +#else if ( sbaInput->base.ctx.hhRendererConfig[0]->split_rend_config.rendererSelection == ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV ) +#endif { float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; @@ -7515,7 +7539,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 4bb5f764b5..15c4bdb09c 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1888,7 +1888,7 @@ static ivas_error create_parambin_HRTF_from_rawdata( ivas_error load_fastconv_HRTF_from_binary( IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv, /* i/o: FastConv HRTF handle */ #ifdef FIX_HRTF_LOAD - int16_t room_reverb_flag, /* i : room reverb flag */ + const int16_t room_reverb_flag, /* i : room reverb flag */ const IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ #endif const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index fadad4516e..0ea25d323e 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -133,7 +133,7 @@ void destroy_SetOfHRTF( ivas_error load_fastconv_HRTF_from_binary( IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv, /* i/o: FastConv HRTF handle */ #ifdef FIX_HRTF_LOAD - int16_t room_reverb_flag, /* i : room reverb flag */ + const int16_t room_reverb_flag, /* i : room reverb flag */ IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ #endif const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index e07660f4d7..8ad75acdd2 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -2649,19 +2649,35 @@ ivas_error RenderConfigReader_read( { if ( strcmp( pValue, "CREND" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_CREND; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_CREND; +#endif } else if ( strcmp( pValue, "FASTCONV" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_FASTCONV; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_FASTCONV; +#endif } else if ( strcmp( pValue, "PARAMBIN" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_PARAMBIN; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_PARAMBIN; +#endif } else if ( strcmp( pValue, "TDREND" ) == 0 ) { +#ifdef FIX_HRTF_LOAD + hRenderConfig->split_rend_config.rendererSelection = IVAS_BIN_RENDERER_TYPE_TDREND; +#else hRenderConfig->split_rend_config.rendererSelection = ISAR_SPLIT_REND_RENDERER_SELECTION_TDREND; +#endif } else { -- GitLab From f91cfc667a0434ec2bd7376a0abb5be8c2cdfacb Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 13:08:18 +0200 Subject: [PATCH 18/27] clang-format --- lib_rend/lib_rend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 111c1698df..1d16f0d2f0 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7539,7 +7539,7 @@ static ivas_error getSamplesInternal( &bits, Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, - (const int16_t) ( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), + ( const int16_t )( ( BINAURAL_MAXBANDS * hIvasRend->sampleRateOut ) / 48000 ), tmpBinaural, 1, cldfb_in_flag, -- GitLab From b52ecbbbf741d0432f0cb270dcfdc28befa9b41d Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 17:07:53 +0200 Subject: [PATCH 19/27] fix for OMASA - load also TD renderer HRTF data --- apps/decoder.c | 31 ++++++++++++++++++++------ lib_dec/ivas_objectRenderer_internal.c | 9 ++++++++ lib_dec/lib_dec.c | 22 ++++++++++++------ lib_dec/lib_dec.h | 3 ++- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 185e0ccb7d..6188c209b1 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -173,6 +173,8 @@ typedef struct IVAS_BIN_RENDERER_TYPE binaural_renderer; IVAS_BIN_RENDERER_TYPE binaural_renderer_old; + IVAS_BIN_RENDERER_TYPE binaural_renderer_sec; + IVAS_BIN_RENDERER_TYPE binaural_renderer_sec_old; IVAS_AUDIO_CONFIG intern_audio_config; int16_t room_reverb_flag; @@ -769,6 +771,7 @@ int main( hHrtfBinary.hrtfReader = hrtfReader; hHrtfBinary.hrtfFileName = arg.hrtfFileName; hHrtfBinary.binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; + hHrtfBinary.binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE; hHrtfBinary.room_reverb_flag = 0; hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; #else @@ -918,7 +921,11 @@ int main( } else { +#ifdef FIX_HRTF_LOAD + fprintf( stderr, "\nDecoding finished prematurely: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); +#else fprintf( stdout, "Decoding finished prematurely\n\n" ); +#endif goto cleanup; } @@ -2540,7 +2547,8 @@ static ivas_error decodeG192( #ifdef FIX_HRTF_LOAD /* Read main parameters from the bitstream to set-up the decoder */ hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK ) + hHrtfBinary->binaural_renderer_sec_old = hHrtfBinary->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK ) { return error; } @@ -3512,7 +3520,8 @@ static ivas_error decodeVoIP( { /* Read main parameters from the bitstream to set-up the decoder */ hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; - if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) + hHrtf->binaural_renderer_sec_old = hHrtf->binaural_renderer_sec; + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) { return error; } @@ -3860,7 +3869,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( const int32_t output_Fs ) { ivas_error error; - IVAS_BIN_RENDERER_TYPE binaural_renderer; + IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; if ( hHrtfBinary == NULL || hIvasDec == NULL ) { @@ -3868,19 +3877,22 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( } binaural_renderer = hHrtfBinary->binaural_renderer; + binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; - if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + if ( ( binaural_renderer != hHrtfBinary->binaural_renderer_old ) || + ( binaural_renderer_sec != hHrtfBinary->binaural_renderer_sec_old ) || + ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { /*------------------------------------------------------------------------------------------* * Release HRTF binary data *------------------------------------------------------------------------------------------*/ - if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && binaural_renderer_sec != IVAS_BIN_RENDERER_TYPE_TDREND && hHrtfBinary->hHrtfTD != NULL ) { destroy_td_hrtf( hHrtfBinary->hHrtfTD ); } - if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + if ( !( binaural_renderer == IVAS_BIN_RENDERER_TYPE_CREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && hHrtfBinary->hSetOfHRTF != NULL ) { destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); } @@ -3899,7 +3911,12 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } - if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) + if ( ( error = IVAS_DEC_HRTF_binary_open( hIvasDec, binaural_renderer_sec ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( binaural_renderer == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_sec == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer == IVAS_BIN_RENDERER_TYPE_DEFAULT ) { if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfBinary->hHrtfTD ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 77d89242a9..74ee8420a3 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -61,6 +61,15 @@ ivas_error ivas_td_binaural_open( num_src = st_ivas->nchan_ism; } +#ifdef FIX_HRTF_LOAD + if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary && + ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx + ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); + } +#endif + return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, num_src, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hRenderConfig->distAtt, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 021e27cfd8..b5a470ef43 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1063,10 +1063,11 @@ ivas_error IVAS_DEC_FeedFrame_Serial( *---------------------------------------------------------------------*/ ivas_error IVAS_DEC_ReadFormat( - IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ - int16_t *room_reverb_flag, /* o : room reverb flag */ - IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer_sec, /* o : secondary binaural renderer type */ + int16_t *room_reverb_flag, /* o : room reverb flag */ + IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ) { ivas_error error; @@ -1141,6 +1142,12 @@ ivas_error IVAS_DEC_ReadFormat( break; } + *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE; + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL ) + { + *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_TDREND; + } + *intern_audio_config = st_ivas->intern_config; if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) || @@ -3105,9 +3112,11 @@ ivas_error IVAS_DEC_HRTF_binary_close( return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - if ( st_ivas->hDecoderConfig->Opt_HRTF_binary ) + if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 ) { - if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && + ( hIvasDec->st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx + ) { ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); } @@ -3120,7 +3129,6 @@ ivas_error IVAS_DEC_HRTF_binary_close( if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_FASTCONV || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) { - /* Fastconv HRTF memories */ ivas_binaural_hrtf_close( &st_ivas->hHrtfFastConv ); diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 93ef686236..65ae6cc68b 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -162,7 +162,8 @@ ivas_error IVAS_DEC_FeedFrame_Serial( #ifdef FIX_HRTF_LOAD ivas_error IVAS_DEC_ReadFormat( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer, /* o : binaural renderer type */ + IVAS_BIN_RENDERER_TYPE *binaural_renderer_sec,/* o: secondary binaural renderer type */ int16_t *room_reverb_flag, /* o : room reverb flag */ IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ ); -- GitLab From f4fda707448eb2f4406588582767ed7efb8e34b9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 18:42:30 +0200 Subject: [PATCH 20/27] fix for MC format with HR + sanity checks for invalid bitstream signaling --- lib_dec/ivas_objectRenderer_internal.c | 2 +- lib_dec/lib_dec.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 74ee8420a3..1ecfe86db1 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -63,7 +63,7 @@ ivas_error ivas_td_binaural_open( #ifdef FIX_HRTF_LOAD if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary && - ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx + ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 ) { return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index b5a470ef43..81d5034626 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1076,7 +1076,7 @@ ivas_error IVAS_DEC_ReadFormat( ISM_MODE ism_mode_old; MC_MODE mc_mode_old; int16_t nchan_transport_old; - AUDIO_CONFIG intern_config_old; + AUDIO_CONFIG intern_config_old, transport_config_old; RENDERER_TYPE renderer_type_old; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -1090,6 +1090,7 @@ ivas_error IVAS_DEC_ReadFormat( mc_mode_old = st_ivas->mc_mode; nchan_transport_old = st_ivas->nchan_transport; intern_config_old = st_ivas->intern_config; + transport_config_old = st_ivas->transport_config; renderer_type_old = st_ivas->renderer_type; if ( st_ivas->ivas_format == MONO_FORMAT ) @@ -1157,11 +1158,11 @@ ivas_error IVAS_DEC_ReadFormat( render what still fits in the new granularity */ int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); - // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue 1200 + // st_ivas->nchan_transport = nchan_transport_old; // ToDo: temporarily deactivated to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue #1200 if ( st_ivas->ivas_format == MASA_FORMAT ) { - st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue 1199 + st_ivas->nchan_ism = 0; // ToDo: temporary hack to keep FIX_HRTF_LOAD bit-exact but this is likely a bug in the main -> see issue #1199 } if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) @@ -1178,6 +1179,7 @@ ivas_error IVAS_DEC_ReadFormat( st_ivas->mc_mode = mc_mode_old; st_ivas->nchan_transport = nchan_transport_old; st_ivas->intern_config = intern_config_old; + st_ivas->transport_config = transport_config_old; st_ivas->renderer_type = renderer_type_old; return IVAS_ERR_OK; @@ -3115,7 +3117,7 @@ ivas_error IVAS_DEC_HRTF_binary_close( if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 ) { if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && - ( hIvasDec->st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #xx + ( hIvasDec->st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 ) { ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); -- GitLab From 9bb06dc968bd6d2946200c642e8c792230bee661 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 19:01:43 +0200 Subject: [PATCH 21/27] fix for MC format with HR + sanity checks for invalid bitstream signaling --- lib_dec/ivas_init_dec.c | 114 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 8ee5c1f74a..d731e83790 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -105,7 +105,7 @@ ivas_error ivas_dec_get_format( { int16_t k, idx, num_bits_read; int16_t nchan_ism, element_mode_flag; - int16_t sba_order, sba_analysis_order; + int16_t sba_order, sba_planar, sba_analysis_order; int32_t ivas_total_brate; uint16_t *bit_stream_orig; AUDIO_CONFIG signaled_config; @@ -122,6 +122,16 @@ ivas_error ivas_dec_get_format( ivas_read_format( st_ivas, &num_bits_read ); + if ( st_ivas->ini_frame > 0 && st_ivas->ivas_format != st_ivas->last_ivas_format && + !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_ISM_FORMAT ) && + !( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + /*-------------------------------------------------------------------* * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ @@ -151,6 +161,14 @@ ivas_error ivas_dec_get_format( k--; } + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + st_ivas->nchan_ism = nchan_ism; st_ivas->ism_mode = ivas_ism_mode_select( nchan_ism, ivas_total_brate ); @@ -163,13 +181,29 @@ ivas_error ivas_dec_get_format( else if ( st_ivas->ivas_format == SBA_FORMAT ) { /* read Ambisonic (SBA) planar flag */ - /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ + sba_planar = st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_PLANAR_BITS; + if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); + } + /* read Ambisonic (SBA) order */ sba_order = st_ivas->bit_stream[num_bits_read + 1]; sba_order += 2 * st_ivas->bit_stream[num_bits_read]; + if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } + sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); st_ivas->nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_analysis_order ); } @@ -188,9 +222,9 @@ ivas_error ivas_dec_get_format( /* this should be non-zero if original input format was MASA_ISM_FORMAT */ st_ivas->ism_mode = ISM_MODE_NONE; - st_ivas->nchan_ism = st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2]; + nchan_ism = st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2]; - if ( st_ivas->nchan_ism > 0 ) + if ( nchan_ism > 0 ) { /* the input_ivas_format should be MASA_ISM_FORMAT, but we cannot initialize it now */ /* info about the number of objects: @@ -200,34 +234,76 @@ ivas_error ivas_dec_get_format( '11' - MASA_ISM_FORMAT at the encoder, with 1 or 2 objects reading if 1 or 2 objects is performed later */ - st_ivas->nchan_ism = 5 - st_ivas->nchan_ism; - if ( st_ivas->nchan_transport == 1 && st_ivas->nchan_ism == 2 ) + nchan_ism = 5 - nchan_ism; + if ( st_ivas->nchan_transport == 1 && nchan_ism == 2 ) { - st_ivas->nchan_ism = 1; + nchan_ism = 1; } /* for MASA_ISM_FORMAT at input the number of MASA transport channels is always 2 and the corresponding bit is not used here*/ st_ivas->nchan_transport = 2; element_mode_flag = 1; } + else + { + nchan_ism = 5; + } + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + + st_ivas->nchan_ism = nchan_ism; } else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { st_ivas->nchan_transport = 2; /* always 2 MASA transport channels */ /* the number of objects are written at the end of the bitstream */ - st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + + st_ivas->nchan_ism = nchan_ism; } else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) { /* the number of objects is written at the end of the bitstream, in the SBA metadata */ - st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; + + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + + st_ivas->nchan_ism = nchan_ism; /* read Ambisonic (SBA) planar flag */ - /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ + sba_planar = st_ivas->bit_stream[num_bits_read]; num_bits_read += SBA_PLANAR_BITS; + if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); + } + /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ sba_order = st_ivas->bit_stream[num_bits_read + 1]; sba_order += 2 * st_ivas->bit_stream[num_bits_read]; @@ -241,6 +317,14 @@ ivas_error ivas_dec_get_format( num_bits_read += SBA_ORDER_BITS; } + if ( st_ivas->ini_frame > 0 && sba_order != st_ivas->sba_order ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the SBA order is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA order signalled!" ); + } + st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, sba_order ); @@ -260,7 +344,17 @@ ivas_error ivas_dec_get_format( num_bits_read += MC_LS_SETUP_BITS; signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + + if ( st_ivas->ini_frame > 0 && st_ivas->transport_config != signaled_config ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Switching of MC configurations is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "wrong MC configuration signalled!" ); + } + st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->transport_config = signaled_config; } /*-------------------------------------------------------------------* -- GitLab From 90333f35c00661f79a392fa342e5643fef4068fe Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 20:43:39 +0200 Subject: [PATCH 22/27] fixes for sanity checks --- lib_dec/ivas_init_dec.c | 23 ++++++++++++++++++----- lib_dec/ivas_masa_dec.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index d731e83790..32aadba1a5 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -244,10 +244,6 @@ ivas_error ivas_dec_get_format( st_ivas->nchan_transport = 2; element_mode_flag = 1; } - else - { - nchan_ism = 5; - } if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { @@ -265,7 +261,7 @@ ivas_error ivas_dec_get_format( /* the number of objects are written at the end of the bitstream */ nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, nchan_ism ); if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) { @@ -430,6 +426,14 @@ ivas_error ivas_dec_get_format( } k--; + if ( st_ivas->ini_frame > 0 && nchan_ism != st_ivas->nchan_ism ) + { +#ifdef DEBUGGING + fprintf( stderr, "\nError: Changing the number of ISMs is not supported!\n" ); +#endif + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong number of objects signalled!" ); + } + st_ivas->nchan_ism = nchan_ism; /* read ism_mode */ @@ -1004,6 +1008,15 @@ static ivas_error ivas_read_format( if ( st_ivas->sba_order == 0 ) { st_ivas->ivas_format = SBA_ISM_FORMAT; + +#ifdef FIX_HRTF_LOAD + /* read the real Ambisonic order when the above bits are used to signal OSBA format */ + if ( ivas_total_brate < IVAS_24k4 ) + { + st_ivas->sba_order = st_ivas->bit_stream[*num_bits_read + 2 + SBA_PLANAR_BITS + SBA_ORDER_BITS]; + st_ivas->sba_order += 2 * st_ivas->bit_stream[*num_bits_read + 1 + SBA_PLANAR_BITS + SBA_ORDER_BITS]; + } +#endif } } ( *num_bits_read )++; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index f0eb77a512..49ee7753f3 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -151,12 +151,28 @@ ivas_error ivas_masa_decode( { if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { +#ifdef FIX_HRTF_LOAD + if ( ivas_format == MASA_FORMAT ) + { + /* re-read the number of objects, needed in case of bad frame */ + ch = 5 - ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2] ); + + if ( ch == 5 ) + { + ch = 0; + } + st_ivas->nchan_ism = ch; + } + + if ( ivas_format == MASA_FORMAT && st_ivas->nchan_ism > 0 ) +#else if ( ivas_format == MASA_FORMAT ) { /* re-read the number of objects, needed in case of bad frame */ st_ivas->nchan_ism = 5 - ( st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 3] + 2 * st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 2] ); } if ( ivas_format == MASA_FORMAT && st_ivas->nchan_ism != 5 ) +#endif { /* there was OMASA in the input */ hMasa->config.input_ivas_format = MASA_ISM_FORMAT; -- GitLab From 77ba3c67d844eabb56edf57505049ff86ac830ca Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 22:02:22 +0200 Subject: [PATCH 23/27] fixes --- lib_dec/ivas_init_dec.c | 10 +--------- lib_util/hrtf_file_reader.c | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 32aadba1a5..a7262093c0 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -289,17 +289,9 @@ ivas_error ivas_dec_get_format( st_ivas->nchan_ism = nchan_ism; /* read Ambisonic (SBA) planar flag */ - sba_planar = st_ivas->bit_stream[num_bits_read]; + /*sba_planar = st_ivas->bit_stream[num_bits_read];*/ num_bits_read += SBA_PLANAR_BITS; - if ( st_ivas->ini_frame > 0 && sba_planar != st_ivas->sba_planar ) - { -#ifdef DEBUGGING - fprintf( stderr, "\nError: Changing the SBA planar/3D layout is not supported!\n" ); -#endif - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Wrong SBA planar flag signalled!" ); - } - /* read Ambisonic (SBA) order (0 for signaling OSBA format at low bitrates)*/ sba_order = st_ivas->bit_stream[num_bits_read + 1]; sba_order += 2 * st_ivas->bit_stream[num_bits_read]; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 15c4bdb09c..0304f8d1db 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1944,7 +1944,7 @@ ivas_error load_fastconv_HRTF_from_binary( ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) ) || - ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && room_reverb_flag == 1 ) || + ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && room_reverb_flag == 1 ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #else if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) ) -- GitLab From d720a79b76c060dcd070b0a1468e37ac20a31081 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 22:19:13 +0200 Subject: [PATCH 24/27] fix --- lib_util/hrtf_file_reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 0304f8d1db..2cda692b25 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1944,7 +1944,7 @@ ivas_error load_fastconv_HRTF_from_binary( ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) ) || - ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && room_reverb_flag == 1 ) || + ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && room_reverb_flag == 1 ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #else if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) || ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) ) -- GitLab From 775f0b98676b1f8c0c6df59a490b1024bc79dde5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 22:55:30 +0200 Subject: [PATCH 25/27] fix --- lib_dec/ivas_binRenderer_internal.c | 9 +++++++++ lib_util/hrtf_file_reader.c | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index fdf9f8ed8a..222af3db95 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1144,6 +1144,15 @@ ivas_error ivas_binRenderer_open( hBinRenderer->render_lfe = 1; } +#ifdef FIX_HRTF_LOAD + if ( ( st_ivas->hHrtfFastConv == NULL ) && st_ivas->hDecoderConfig->Opt_HRTF_binary && + ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 + ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); + } +#endif + /* Load HRTF tables */ if ( ( error = ivas_binaural_hrtf_open( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ) != IVAS_ERR_OK ) { diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 2cda692b25..07cd85ed4b 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1943,7 +1943,8 @@ ivas_error load_fastconv_HRTF_from_binary( if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || - ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) ) ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED && intern_audio_config == IVAS_AUDIO_CONFIG_7_1_4 ) ) ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && room_reverb_flag == 1 ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #else -- GitLab From aa820d02a0a771bed5f3523d1873ae7adccbeb83 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 17 Oct 2024 23:14:01 +0200 Subject: [PATCH 26/27] fix --- lib_util/hrtf_file_reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 07cd85ed4b..b4a0b24ea9 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1944,7 +1944,7 @@ ivas_error load_fastconv_HRTF_from_binary( ( ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA3 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 && intern_audio_config == IVAS_AUDIO_CONFIG_HOA2 ) || ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA && intern_audio_config == IVAS_AUDIO_CONFIG_FOA ) || - ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED && intern_audio_config == IVAS_AUDIO_CONFIG_7_1_4 ) ) ) || + ( hrtf_header.input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) ) ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && room_reverb_flag == 1 ) || ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV || hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) && intern_audio_config == IVAS_AUDIO_CONFIG_INVALID ) ) #else -- GitLab From d1e5418ba7981199e8fa1fef4365932431d733c7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 18 Oct 2024 08:46:35 +0200 Subject: [PATCH 27/27] sanity-check --- lib_dec/ivas_binRenderer_internal.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 222af3db95..269c6bff98 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1145,11 +1145,9 @@ ivas_error ivas_binRenderer_open( } #ifdef FIX_HRTF_LOAD - if ( ( st_ivas->hHrtfFastConv == NULL ) && st_ivas->hDecoderConfig->Opt_HRTF_binary && - ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 - ) + if ( st_ivas->hHrtfFastConv == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary ) { - return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); + return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in FastConv renderer" ); } #endif -- GitLab