diff --git a/apps/decoder.c b/apps/decoder.c index 7c28adcfce044e3b60c61b00f64e3714da85f19e..01d4cf3356171c2876cf01b773c452d61e1707f3 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -161,6 +161,27 @@ 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; + + 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; + +} IVAS_DEC_HRTF_BINARY_WRAPPER; + +#endif /*------------------------------------------------------------------------------------------* * Local functions prototypes @@ -168,9 +189,14 @@ 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_BINARY_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 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 DEBUGGING static ivas_error printBitstreamInfoVoip( DecArguments arg, BS_READER_HANDLE hBsReader, IVAS_DEC_HANDLE hIvasDec ); static int16_t app_own_random( int16_t *seed ); @@ -205,9 +231,13 @@ int main( RenderConfigReader *renderConfigReader = NULL; int16_t *pcmBuf = NULL; IVAS_RENDER_FRAMESIZE asked_frame_size; +#ifdef FIX_HRTF_LOAD + IVAS_DEC_HRTF_BINARY_WRAPPER hHrtfBinary; +#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 +254,12 @@ int main( reset_mem( USE_BYTES ); #endif +#ifdef FIX_HRTF_LOAD + 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; /*------------------------------------------------------------------------------------------* @@ -704,6 +740,14 @@ int main( if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_HRTF_LOAD + 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 if ( ( error = IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -800,6 +844,7 @@ int main( destroy_hrtf_statistics( hHrtfStatistics ); } } +#endif } /*------------------------------------------------------------------------------------------* @@ -821,11 +866,19 @@ int main( if ( arg.voipMode ) { +#ifdef FIX_HRTF_LOAD + error = decodeVoIP( arg, hBsReader, &hHrtfBinary, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); +#else error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); +#endif } else { +#ifdef FIX_HRTF_LOAD + 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 } if ( error == IVAS_ERR_OK || error == IVAS_ERR_END_OF_FILE ) @@ -841,7 +894,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; } @@ -877,6 +934,11 @@ cleanup: #endif if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_HRTF_LOAD + destroy_td_hrtf( hHrtfBinary.hHrtfTD ); + destroy_SetOfHRTF( hHrtfBinary.hSetOfHRTF ); + destroy_hrtf_statistics( hHrtfBinary.hHrtfStatistics ); +#else IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ); destroy_td_hrtf( hHrtfTD ); @@ -885,6 +947,7 @@ cleanup: IVAS_DEC_GetHrtfStatisticsHandle( hIvasDec, &hHrtfStatistics ); destroy_hrtf_statistics( hHrtfStatistics ); +#endif } IVAS_DEC_Close( &hIvasDec ); @@ -2077,6 +2140,9 @@ static ivas_error initOnFirstGoodFrame( static ivas_error decodeG192( DecArguments arg, BS_READER_HANDLE hBsReader, +#ifdef FIX_HRTF_LOAD + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, +#endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, @@ -2438,16 +2504,48 @@ static ivas_error decodeG192( #endif /* Feed into decoder */ if ( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, bit_stream, num_bits, bfi +#ifndef FIX_HRTF_LOAD #ifdef OBJ_EDITING_API , isSplitRend, splitRendBits +#endif #endif ) ) != IVAS_ERR_OK ) { 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 */ + hHrtfBinary->binaural_renderer_old = hHrtfBinary->binaural_renderer; + 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; + } + + /* Placeholder for memory reallocation */ + /* ... */ + + /* Load HRTF binary file data */ + if ( arg.hrtfReaderEnabled ) + { + 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; + } + } + + /* 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 ) @@ -3014,6 +3112,9 @@ static ivas_error writeJbmTraceFileFrameWrapper( const void *data, void *writer static ivas_error decodeVoIP( DecArguments arg, BS_READER_HANDLE hBsReader, +#ifdef FIX_HRTF_LOAD + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtf, +#endif RotFileReader *headRotReader, RotFileReader *externalOrientationFileReader, RotFileReader *refRotReader, @@ -3064,6 +3165,10 @@ static ivas_error decodeVoIP( int16_t vec_pos_update, vec_pos_len; int16_t nOutSamples = 0; +#ifdef FIX_HRTF_LOAD + bool bitstreamReadDone = false; +#endif + #ifdef OBJ_EDITING_API bool parameterAvailableForEditing = false; uint16_t nSamplesRendered = 0; @@ -3357,6 +3462,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 + , + &bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , &nSamplesRendered, ¶meterAvailableForEditing @@ -3364,8 +3473,12 @@ 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 + , + &bitstreamReadDone +#endif #ifdef OBJ_EDITING_API - & nSamplesRendered, + & nSamplesRendered, ¶meterAvailableForEditing #endif ) ) != IVAS_ERR_OK ) @@ -3374,6 +3487,33 @@ static ivas_error decodeVoIP( fprintf( stderr, "\nError in IVAS_DEC_VoIP_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } +#ifdef FIX_HRTF_LOAD + + if ( bitstreamReadDone == true ) + { + /* Read main parameters from the bitstream to set-up the decoder */ + hHrtf->binaural_renderer_old = hHrtf->binaural_renderer; + 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; + } + + /* 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 ) { @@ -3688,4 +3828,182 @@ static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( } #endif +#ifdef FIX_HRTF_LOAD + +/*---------------------------------------------------------------------* + * IVAS_DEC_LoadHrtfFromFile() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error IVAS_DEC_LoadHrtfFromFile( + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, + IVAS_DEC_HANDLE hIvasDec, + const int32_t output_Fs ) +{ + ivas_error error; + IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; + + if ( hHrtfBinary == NULL || hIvasDec == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + binaural_renderer = hHrtfBinary->binaural_renderer; + binaural_renderer_sec = hHrtfBinary->binaural_renderer_sec; + + 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 ) && 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 ) && hHrtfBinary->hSetOfHRTF != NULL ) + { + destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); + } + + if ( ( error = IVAS_DEC_HRTF_binary_close( hIvasDec, hHrtfBinary->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 ( ( 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 ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + 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", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_td_hrtf( hHrtfBinary->hHrtfTD ); + } + } + } + + 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 ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfCRendHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + 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", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_SetOfHRTF( hHrtfBinary->hSetOfHRTF ); + } + } + } + + 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 ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfFastConvHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + 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", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_fastconv_hrtf( hHrtfFastConv ); + } + } + } + + 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 ) + { + fprintf( stderr, "\nIVAS_DEC_GetHrtfParamBinHandle failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); + return error; + } + + 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", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_parambin_hrtf( hHrtfParambin ); + } + } + } + } + + if ( hHrtfBinary->hHrtfStatistics == NULL ) + { + 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( *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", hHrtfBinary->hrtfFileName ); + return error; + } + else + { + destroy_hrtf_statistics( hHrtfBinary->hHrtfStatistics ); + } + } + } + + return IVAS_ERR_OK; +} +#endif + #undef WMC_TOOL_SKIP diff --git a/apps/renderer.c b/apps/renderer.c index 5ca8e170fee5554f950ba63aab073fd94fef8d02..767d4bb60d6567193d6299324a5d0b86135a0678 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; @@ -945,7 +949,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_com/common_api_types.h b/lib_com/common_api_types.h index 7890d25379f124b02d8a73255429605fca2bd17a..53b03e4e1f62034739b70a9949eed896e00e8dc5 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,6 +263,7 @@ typedef enum } ISAR_SPLIT_REND_CODEC; +#ifndef FIX_HRTF_LOAD typedef enum { ISAR_SPLIT_REND_RENDERER_SELECTION_CREND, @@ -260,6 +273,7 @@ typedef enum ISAR_SPLIT_REND_RENDERER_SELECTION_DEFAULT, } ISAR_SPLIT_REND_RENDERER_SELECTION; +#endif typedef struct _ISAR_SPLIT_REND_BITS_DATA { @@ -291,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_com/ivas_prot.h b/lib_com/ivas_prot.h index 700a9cc75cb2420b0466364d1c2e35169d78cdc8..c8d1a8169a17a7293d5a425a0a87e9059c02ef68 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -318,11 +318,20 @@ 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 */ + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#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 */ void *data /* o : output synthesis signal */ +#endif ); ivas_error create_sce_dec( @@ -660,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 + , 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) */ @@ -1077,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 + , 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( @@ -3471,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 + , 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( @@ -4929,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 + , 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( @@ -5634,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 + , 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_com/options.h b/lib_com/options.h index 97c422b0236bdb052ebad7abf4e1b99924eea77c..97feb76cc3594cedaec5a5b4c2785af11f948d66 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,9 @@ #define FIX_587_DEFAULT_REVERB /* Philips: issue 587: inconsistent default reverb parameters across renderers */ +#define FIX_HRTF_LOAD /* VA: issue 1187: fix memory issue when HRTFs are loaded from a binary file */ + + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index fdf9f8ed8af94d499b49294a150a95832d9c4efd..269c6bff981ab0720112b7dd1ffc170c09ff4ed1 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1144,6 +1144,13 @@ ivas_error ivas_binRenderer_open( hBinRenderer->render_lfe = 1; } +#ifdef FIX_HRTF_LOAD + 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 FastConv 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_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 63f3cc026d327b309d856672f04889041192d474..a7262093c0177c0755751553061da72b9bb2927c 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -89,6 +89,368 @@ 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; + AUDIO_CONFIG signaled_config; + + 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 ); + + 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.) + *-------------------------------------------------------------------*/ + + 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 */ + 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--; + } + + 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 ); + + st_ivas->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } + } + 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; + + 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 ); + } + 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->ism_mode = ISM_MODE_NONE; + 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 ( 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 + */ + nchan_ism = 5 - nchan_ism; + if ( st_ivas->nchan_transport == 1 && nchan_ism == 2 ) + { + 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; + } + + 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 */ + 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, 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 */ + 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];*/ + 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; + } + + 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 ); + 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; + + 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; + } + + /*-------------------------------------------------------------------* + * 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->ivas_format == ISM_FORMAT ) + { + /* read the number of objects */ + 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 ) + { +#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 */ + 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->nchan_transport = nchan_ism; + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + { + st_ivas->nchan_transport = MAX_PARAM_ISM_WAVE; + } + } + } + + st_ivas->bit_stream = bit_stream_orig; + + return IVAS_ERR_OK; +} + +#endif /*-------------------------------------------------------------------* * ivas_dec_setup() @@ -97,10 +459,13 @@ static AUDIO_CONFIG ivas_set_audio_config_from_sba_order( *-------------------------------------------------------------------*/ 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 + , 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; @@ -154,7 +519,11 @@ ivas_error ivas_dec_setup( st_ivas->nchan_ism = nchan_ism; +#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 ) +#endif { return error; } @@ -172,7 +541,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 + 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; } @@ -234,8 +607,11 @@ ivas_error ivas_dec_setup( } else { - +#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 ) +#endif { return error; } @@ -243,7 +619,11 @@ ivas_error ivas_dec_setup( } else { +#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 ) +#endif { return error; } @@ -264,7 +644,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 + 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; } @@ -292,9 +676,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 + 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; } @@ -340,7 +729,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 + 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; } @@ -425,7 +818,11 @@ ivas_error ivas_dec_setup( st_ivas->hDecoderConfig->ivas_total_brate = IVAS_24k4; } +#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 ) +#endif { return error; } @@ -471,7 +868,11 @@ ivas_error ivas_dec_setup( last_ism_mode = st_ivas->ism_mode; } +#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 ) +#endif { return error; } @@ -599,6 +1000,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 )++; @@ -842,6 +1252,7 @@ ivas_error ivas_init_decoder_front( } } +#ifndef FIX_HRTF_LOAD /*-------------------------------------------------------------------* * Allocate HRTF binary handle *--------------------------------------------------------------------*/ @@ -872,7 +1283,7 @@ ivas_error ivas_init_decoder_front( return error; } } - +#endif /*-------------------------------------------------------------------* * Allocate and initialize Binaural Renderer configuration handle *--------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 36945f81550f347f6e8e3813bd2456fca27036bb..67f189e29958f2742eada992dde248f3ccb8dcfb 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 + , 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; @@ -64,11 +67,15 @@ 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 AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; +#endif +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; +#endif nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; @@ -104,12 +111,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } +#ifndef FIX_HRTF_LOAD /* 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 *-----------------------------------------------------------------*/ @@ -142,10 +151,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { +#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 ) { 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 ) @@ -361,7 +374,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( } } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } @@ -373,18 +390,23 @@ 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 + , 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; ivas_error error; int16_t nchan_transport_old; +#ifndef FIX_HRTF_LOAD error = IVAS_ERR_OK; +#endif ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* Assumes that num of input objects are constant */ @@ -413,9 +435,13 @@ 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 + 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 +463,11 @@ ivas_error ivas_ism_dec_config( /* ISM mode switching */ if ( st_ivas->ism_mode != last_ism_mode ) { +#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 ) +#endif { return error; } @@ -463,5 +493,9 @@ ivas_error ivas_ism_dec_config( break; } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 29b2cd140379307b64145cbcc49e58f3a2c17567..4cb5aac155ba8cd41a4e54518e2b2cbdabec47fa 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/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 2335f14147dfc7019f32222f4530f52878485daa..49ee7753f31733f486489d1b987cf0f86fe8ebec 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; @@ -1305,10 +1321,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 + , 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; @@ -1321,8 +1340,9 @@ ivas_error ivas_masa_dec_reconfigure( int16_t pos_idx; int32_t ism_total_brate; +#ifndef FIX_HRTF_LOAD 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; @@ -1517,10 +1537,14 @@ ivas_error ivas_masa_dec_reconfigure( { if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) { +#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 ) { return error; } +#endif } } } @@ -1561,7 +1585,11 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef FIX_HRTF_LOAD + 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 08e2de73cd7cefff2f6e4d5c872d5550a2127888..fe2ca5dbaaf3356cdd37c1cbe47f992d2aeb29b1 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 +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 + , 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 + 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 + , 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; @@ -738,11 +752,15 @@ 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 AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; +#endif int16_t nchan_out_buff_old, nchan_out_buff; +#ifndef FIX_HRTF_LOAD 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 ); @@ -770,11 +788,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 /* 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 ); @@ -808,10 +828,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 + /* 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 ) @@ -1299,7 +1323,6 @@ static ivas_error ivas_mc_dec_reconfig( /*-----------------------------------------------------------------* * JBM TC buffers *-----------------------------------------------------------------*/ - { int16_t tc_nchan_full_new; DECODER_TC_BUFFER_HANDLE hTcBuffer; @@ -1362,7 +1385,6 @@ static ivas_error ivas_mc_dec_reconfig( } } - /*-----------------------------------------------------------------* * floating-point output audio buffers *-----------------------------------------------------------------*/ @@ -1374,5 +1396,9 @@ static ivas_error ivas_mc_dec_reconfig( return error; } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 77d89242a923d89bf808127443ea22cb32a839fa..1ecfe86db1b47fbecc0a997975ab7931a3b332b7 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 #1202 + ) + { + 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/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b75ca1d93dbc30caba7785d636764c77ead9ecdf..243b5cf44a6dbd9a51adb0967fb979a2ea8fb144 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 + , 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 + 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; } @@ -565,7 +572,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 9a6df407d4ed569dfd5ab38276ea27287616c2e8..0f3dfba4c01202bd2369e4bd959126c7d9f255e2 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 + , 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 *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 + /* 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 ) { @@ -658,7 +667,11 @@ ivas_error ivas_sba_dec_reconfigure( return error; } +#ifdef FIX_HRTF_LOAD + return IVAS_ERR_OK; +#else return error; +#endif } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 00a81cb14d8cae81aa767e151ae902d6f60233c3..5611f70fba6c62b04d45ea532e1594f3f84d20ac 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 +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 ); @@ -824,11 +828,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 #ifdef OBJ_EDITING_API , int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits #endif +#endif ) { ivas_error error; @@ -906,6 +912,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; #ifdef OBJ_EDITING_API +#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. @@ -1027,10 +1034,298 @@ 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 */ + 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; + 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, transport_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; + 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 ) + { + 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 = IVAS_BIN_RENDERER_TYPE_TDREND; + break; + case RENDERER_BINAURAL_MIXER_CONV: + case RENDERER_BINAURAL_MIXER_CONV_ROOM: + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_CREND; + break; + case RENDERER_BINAURAL_FASTCONV: + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_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 = IVAS_BIN_RENDERER_TYPE_FASTCONV; + *room_reverb_flag = 1; + break; + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_PARAMBIN; + break; + default: + *binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; + 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 ) || + ( 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: 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 + } + + 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; + } + } + } + } + + 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->transport_config = transport_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. */ +#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 + uint8_t nTransportChannels; +#else + uint8_t nTransportChannels, nOutChannels; +#endif + 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; + } + } + +#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 ) +#endif + { + 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 /*---------------------------------------------------------------------* @@ -1843,30 +2138,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 + , 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 *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 *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; +#endif } else { *nTransportChannels = 1; +#ifndef FIX_HRTF_LOAD *nOutChannels = 1; +#endif } } else @@ -1885,7 +2188,11 @@ static ivas_error IVAS_DEC_Setup( if ( st_ivas->bfi == 0 ) { +#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 ) +#endif { return error; } @@ -1893,8 +2200,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 *nOutChannels = (uint8_t) st_ivas->hDecoderConfig->nchan_out; - +#endif /*-----------------------------------------------------------------* * ISAR: @@ -2692,6 +3000,137 @@ 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 IVAS_BIN_RENDERER_TYPE 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 ) + { + /* 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 ) + { + return error; + } + } + + /* 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 ) + { + return error; + } + } + + /* 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 ) + { + return error; + } + } + + /* 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 ) + { + 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 IVAS_BIN_RENDERER_TYPE 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 && 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 #1202 + ) + { + ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); + } + + 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 ); + } + + 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 ); + + /* Fastconv HRTF filters */ + ivas_HRTF_fastconv_binary_close( &st_ivas->hHrtfFastConv ); + } + + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_PARAMBIN || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) + { + + /* Parametric binauralizer HRTF filters */ + ivas_HRTF_parambin_binary_close( &st_ivas->hHrtfParambin ); + } + } + + return IVAS_ERR_OK; +} + +#endif + /*---------------------------------------------------------------------* * copyRendererConfigStruct( ) * @@ -3250,6 +3689,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JbmTraceFileWriterFn jbmWriterFn, void *jbmWriter #endif +#ifdef FIX_HRTF_LOAD + , + bool *bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , uint16_t *nSamplesRendered, @@ -3371,24 +3814,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 #if defined( OBJ_EDITING_API ) , 0, 0 +#endif #endif ) ) != IVAS_ERR_OK ) { return error; } +#ifdef FIX_HRTF_LOAD + + *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 #if defined( OBJ_EDITING_API ) , 0, 0 +#endif #endif ) ) != IVAS_ERR_OK ) { @@ -3424,6 +3875,14 @@ ivas_error IVAS_DEC_VoIP_GetSamples( JB4_FreeDataUnit( hVoIP->hJBM, dataUnit ); } +#ifdef FIX_HRTF_LOAD + if ( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true ) + { + /* new bitstream was feeded, return for reconfiguration */ + return IVAS_ERR_OK; + } + +#endif if ( !hIvasDec->hasBeenFedFirstGoodFrame ) { hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame; @@ -3461,6 +3920,26 @@ ivas_error IVAS_DEC_VoIP_GetSamples( { int16_t nSamplesToRender, nSamplesRendered_loop; bool tmp; + +#ifdef FIX_HRTF_LOAD + if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) + { + 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 + #ifdef OBJ_EDITING_API nSamplesToRender = nSamplesPerChannel - *nSamplesRendered; #else diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index ce6eff71a3e2f85b9a7543d0a6fc00fdb93287f8..64f6b883d42d4aafbdb740078e7d1f9c4b00cb05 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -150,13 +150,31 @@ 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 #if defined( OBJ_EDITING_API ) , int16_t isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits #endif +#endif ); +#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_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 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, @@ -304,6 +322,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples( , JbmTraceFileWriterFn jbmWriterFn, void* jbmWriter #endif +#ifdef FIX_HRTF_LOAD + , + bool *bitstreamReadDone +#endif #ifdef OBJ_EDITING_API , uint16_t *nSamplesRendered, @@ -451,6 +473,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 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 IVAS_BIN_RENDERER_TYPE 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_isar/lib_isar_post_rend.c b/lib_isar/lib_isar_post_rend.c index 101768bb3468183213a7f80db644c3510499abf9..38c25ff21ae4c65dbc75874e129e72d2a5066dcd 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 eabaf2d4cbae004d5418ffe9e1e532437a4df283..950e9ee8bf39ad0c202da42702914dd8ab0408cc 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 64c2009f101a296d60a73aafd83651aa02ae3c21..1d16f0d2f07e04618b54a4ef6ae9be6eea4bfcae 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]; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 640f2721e68a61972fa020f2ec9b6e009ed2949c..b4a0b24ea9fdbe1b63a805f5b5f4554eb45541d8 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -1437,6 +1437,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 ) { @@ -1886,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 + 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 */ ) { FILE *f_hrtf; @@ -1934,7 +1939,17 @@ 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.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 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 ) { diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index dbb38c3d888719c629203f58aad3c21184d4a36a..0ea25d323e478fbf3aae715acdac1601038577f9 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 + 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 e07660f4d7314dad740455abbd15b68532557a22..8ad75acdd201427fe6a9bbaa8378ca0078075a72 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 {