diff --git a/apps/decoder.c b/apps/decoder.c index 49a4028376f6bab6c4fa5c64bd5f6b2b9529ff83..2b18205f8745e89761dabe694017fb56f75880fb 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -168,8 +168,12 @@ typedef struct IVAS_BIN_RENDERER_TYPE binaural_renderer_sec; IVAS_BIN_RENDERER_TYPE binaural_renderer_sec_old; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + IVAS_AUDIO_CONFIG hrtf_set_audio_cfg; +#else IVAS_AUDIO_CONFIG intern_audio_config; int16_t room_reverb_flag; +#endif } IVAS_DEC_HRTF_BINARY_WRAPPER; @@ -182,7 +186,11 @@ static bool parseCmdlIVAS_dec( int16_t argc, char **argv, DecArguments *arg ); static void usage_dec( void ); 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 ); +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +static ivas_error load_hrtf_from_file( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const IVAS_AUDIO_CONFIG OutputConfig, const int32_t output_Fs ); +#else 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 ); @@ -712,7 +720,7 @@ int main( } /*------------------------------------------------------------------------------------------* - * Load HRTF binary file data + * Initialize HRTF binary file data *------------------------------------------------------------------------------------------*/ if ( arg.hrtfReaderEnabled ) @@ -721,8 +729,12 @@ int main( hHrtfBinary.hrtfFileName = arg.hrtfFileName; hHrtfBinary.binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; hHrtfBinary.binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + hHrtfBinary.hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_INVALID; +#else hHrtfBinary.room_reverb_flag = 0; hHrtfBinary.intern_audio_config = IVAS_AUDIO_CONFIG_INVALID; +#endif } /*------------------------------------------------------------------------------------------* @@ -2353,7 +2365,11 @@ static ivas_error decodeG192( /* 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; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtfBinary->binaural_renderer, &hHrtfBinary->binaural_renderer_sec, &hHrtfBinary->room_reverb_flag, &hHrtfBinary->intern_audio_config ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -2364,7 +2380,11 @@ static ivas_error decodeG192( /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = load_hrtf_from_file( hHrtfBinary, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtfBinary, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3260,7 +3280,11 @@ static ivas_error decodeVoIP( /* 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; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->hrtf_set_audio_cfg ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_ReadFormat( hIvasDec, &hHrtf->binaural_renderer, &hHrtf->binaural_renderer_sec, &hHrtf->room_reverb_flag, &hHrtf->intern_audio_config ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -3271,7 +3295,11 @@ static ivas_error decodeVoIP( /* Load HRTF binary file data */ if ( arg.hrtfReaderEnabled ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = load_hrtf_from_file( hHrtf, hIvasDec, arg.outputConfig, arg.output_Fs ) ) != IVAS_ERR_OK ) +#else if ( ( error = IVAS_DEC_LoadHrtfFromFile( hHrtf, hIvasDec, arg.output_Fs ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nIVAS_DEC_LoadHrtfFromFile failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; @@ -3662,6 +3690,20 @@ static IVAS_DEC_FORCED_REND_MODE parseForcedRendModeDec( #endif +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +/*---------------------------------------------------------------------* + * load_hrtf_from_file() + * + * Load HRTF coefficients from external binary file + *---------------------------------------------------------------------*/ + +static ivas_error load_hrtf_from_file( + IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, /* i/o: HRTF binary wrapper handle */ + IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ + const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ + const int32_t output_Fs /* i : output sampling rate */ +) +#else /*---------------------------------------------------------------------* * IVAS_DEC_LoadHrtfFromFile() * @@ -3672,6 +3714,7 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( IVAS_DEC_HRTF_BINARY_WRAPPER *hHrtfBinary, IVAS_DEC_HANDLE hIvasDec, const int32_t output_Fs ) +#endif { ivas_error error; IVAS_BIN_RENDERER_TYPE binaural_renderer, binaural_renderer_sec; @@ -3774,7 +3817,11 @@ static ivas_error IVAS_DEC_LoadHrtfFromFile( return error; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, OutputConfig, hHrtfBinary->hrtf_set_audio_cfg, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, hHrtfBinary->room_reverb_flag, hHrtfBinary->intern_audio_config, hHrtfBinary->hrtfReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/apps/renderer.c b/apps/renderer.c index 3aa0a474280ff1bd960bfc10d9e718ef41d3a2f6..dc779ada5a7cd3c0e2038813ea09673e9a0d23d1 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -945,7 +945,11 @@ int main( goto cleanup; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, args.outConfig.audioConfig, args.inConfig.ambisonicsBuses->audioConfig, hrtfFileReader ) ) != IVAS_ERR_OK ) +#else if ( ( error = load_fastconv_HRTF_from_binary( *hHrtfFastConv, 0, IVAS_AUDIO_CONFIG_INVALID, hrtfFileReader ) ) != IVAS_ERR_OK ) +#endif { if ( error != IVAS_ERR_BINARY_FILE_WITHOUT_BINAURAL_RENDERER_DATA ) { diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index db01bdfe894233951cc49a8e2f8153a44f8cb5ac..786a6d436b0665309802221619a0be173a179bb9 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1495,6 +1495,7 @@ typedef enum #define BINAURAL_COHERENCE_DIFFERENCE_BINS 9 /* Number of bins for direction-dependent diffuse-field binaural coherence */ +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM typedef enum { BINAURAL_INPUT_AUDIO_CONFIG_INVALID, @@ -1506,6 +1507,7 @@ typedef enum } BINAURAL_INPUT_AUDIO_CONFIG; +#endif #define HEADROT_ORDER 3 #define HEADROT_SHMAT_DIM ( ( HEADROT_ORDER + 1 ) * ( HEADROT_ORDER + 1 ) ) #define HEADROT_SHMAT_DIM2 ( HEADROT_SHMAT_DIM * HEADROT_SHMAT_DIM ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 418d49267ff84d622ee2b3bdadd76fad0e93dbdc..3513df00a49118ac63ae8764156448142edb4ce6 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5135,10 +5135,14 @@ void ivas_init_binaural_hrtf( ); ivas_error ivas_allocate_binaural_hrtf( - HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ + HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + const int16_t n_channels, /* i : number of input channels */ +#else const AUDIO_CONFIG input_config, /* i : input audio configuration */ const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ const RENDERER_TYPE renderer_type, /* i : renderer type */ +#endif const int16_t allocate_init_flag /* i : Memory allocation flag */ ); diff --git a/lib_com/options.h b/lib_com/options.h index 51db29c99c91e00c1888a00c7fcb2ecc3cfadf4f..3228086c64eae34917e8e2eb1674468091db6bc9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,6 +160,7 @@ /*#define FIX_I4_OL_PITCH*/ /* fix open-loop pitch used for EVS core switching */ #define TMP_FIX_1119_SPLIT_RENDERING_VOIP /* FhG: Add error check for unsupported config: split rendering with VoIP mode */ +#define FIX_1226_FASTCONV_HRTF_LOADING_OPTIM /* VA: issue 1226: for FastConv binaural renderer in decoder, load only HTRT coefficient set that is needed */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 587f2c7b2b7e3b776f25adde362d689df02fcbea..a9075b1f0dcb257079e210f1ed52266eb3642695 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -165,10 +165,16 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + hBinRenConvModule->numTaps = hHrtf->ntaps; +#endif + if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM hBinRenConvModule->numTaps = hHrtf->ntaps_brir; +#endif /* Use variable order filtering */ bandIdx = 0; for ( ; bandIdx < 5; bandIdx++ ) @@ -194,6 +200,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( } else { +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM if ( hBinRenderer->ivas_format == SBA_FORMAT ) { if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) @@ -218,6 +225,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->numTaps = hHrtf->ntaps_hrir; } +#endif /* Use fixed order filtering */ bandIdx = 0; for ( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) @@ -326,6 +334,9 @@ static ivas_error ivas_binRenderer_convModuleOpen( { int16_t tmp = 0; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + tmp = chIdx; +#endif if ( isLoudspeaker ) { if ( input_config == IVAS_AUDIO_CONFIG_5_1 ) @@ -356,6 +367,12 @@ static ivas_error ivas_binRenderer_convModuleOpen( #endif } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftImag[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightImag[bandIdx][tmp]; +#else if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { @@ -415,6 +432,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( } } } +#endif } } @@ -449,6 +467,17 @@ void ivas_init_binaural_hrtf( { int16_t i; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal = NULL; + HrtfFastConv->leftImag = NULL; + HrtfFastConv->rightReal = NULL; + HrtfFastConv->rightImag = NULL; + HrtfFastConv->FASTCONV_latency_s = 0x00; + + HrtfFastConv->n_channels = 0; + HrtfFastConv->allocate_init_flag = 0x00; + HrtfFastConv->ntaps = 0; +#else HrtfFastConv->leftHRIRReal_HOA3 = NULL; HrtfFastConv->leftHRIRImag_HOA3 = NULL; HrtfFastConv->rightHRIRReal_HOA3 = NULL; @@ -485,6 +514,7 @@ void ivas_init_binaural_hrtf( HrtfFastConv->ntaps_hrir_hoa2 = BINAURAL_NTAPS_SBA; HrtfFastConv->ntaps_hrir_hoa3 = BINAURAL_NTAPS_SBA; HrtfFastConv->ntaps_brir = BINAURAL_NTAPS_MAX; +#endif for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { @@ -548,13 +578,44 @@ static ivas_error ivas_alloc_pppMem( *-------------------------------------------------------------------------*/ ivas_error ivas_allocate_binaural_hrtf( - HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ + HRTFS_FASTCONV *HrtfFastConv, /* i/o: FASTCONV HRTF structure */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + const int16_t n_channels, /* i : number of input channels */ +#else const AUDIO_CONFIG input_config, /* i : input audio configuration */ const BINAURAL_INPUT_AUDIO_CONFIG bin_input_config, /* i : binaural input audio config */ const RENDERER_TYPE renderer_type, /* i : renderer type */ - const int16_t allocate_init_flag /* i : Memory allocation flag */ +#endif + const int16_t allocate_init_flag /* i : Memory allocation flag */ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->n_channels = n_channels; + + if ( ( HrtfFastConv->leftReal != NULL ) && ( HrtfFastConv->leftImag != NULL ) && ( HrtfFastConv->rightReal != NULL ) && ( HrtfFastConv->rightImag != NULL ) ) + { + return IVAS_ERR_OK; + } + else + { + if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftReal, BINAURAL_CONVBANDS, n_channels, HrtfFastConv->ntaps, allocate_init_flag ) ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HrtfFastConv->leftReal" ); + } + if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->leftImag, BINAURAL_CONVBANDS, n_channels, HrtfFastConv->ntaps, allocate_init_flag ) ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HrtfFastConv->leftImag" ); + } + if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightReal, BINAURAL_CONVBANDS, n_channels, HrtfFastConv->ntaps, allocate_init_flag ) ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HrtfFastConv->rightReal" ); + } + if ( IVAS_ERR_OK != ivas_alloc_pppMem( &HrtfFastConv->rightImag, BINAURAL_CONVBANDS, n_channels, HrtfFastConv->ntaps, allocate_init_flag ) ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HrtfFastConv->rightImag" ); + } + } +#else if ( input_config == IVAS_AUDIO_CONFIG_HOA3 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) { if ( ( HrtfFastConv->leftHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3 != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3 != NULL ) ) @@ -681,6 +742,7 @@ ivas_error ivas_allocate_binaural_hrtf( } } } +#endif return IVAS_ERR_OK; } @@ -700,7 +762,9 @@ static ivas_error ivas_binaural_hrtf_open( { int16_t i, j; ivas_error error; - +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + int16_t n_channels; +#endif if ( hHrtfFastConv != NULL && *hHrtfFastConv != NULL ) { @@ -721,83 +785,195 @@ static ivas_error ivas_binaural_hrtf_open( if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->FASTCONV_latency_s = FASTCONV_HRIR_latency_s; + HrtfFastConv->ntaps = BINAURAL_NTAPS; +#else HrtfFastConv->FASTCONV_HRIR_latency_s = FASTCONV_HRIR_latency_s; +#endif } if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->FASTCONV_latency_s = FASTCONV_HOA2_latency_s; + HrtfFastConv->ntaps = BINAURAL_NTAPS_SBA; +#else HrtfFastConv->FASTCONV_HOA2_latency_s = FASTCONV_HOA2_latency_s; +#endif } if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->FASTCONV_latency_s = FASTCONV_HOA3_latency_s; + HrtfFastConv->ntaps = BINAURAL_NTAPS_SBA; +#else HrtfFastConv->FASTCONV_HOA3_latency_s = FASTCONV_HOA3_latency_s; +#endif } if ( input_config == IVAS_AUDIO_CONFIG_FOA ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->FASTCONV_latency_s = FASTCONV_FOA_latency_s; + HrtfFastConv->ntaps = BINAURAL_NTAPS_SBA; +#else HrtfFastConv->FASTCONV_FOA_latency_s = FASTCONV_FOA_latency_s; +#endif } if ( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->FASTCONV_latency_s = FASTCONV_BRIR_latency_s; + HrtfFastConv->ntaps = BINAURAL_NTAPS_MAX; +#else HrtfFastConv->FASTCONV_BRIR_latency_s = FASTCONV_BRIR_latency_s; +#endif } HrtfFastConv->allocate_init_flag = 1; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + n_channels = 0; + if ( ( renderer_type == RENDERER_BINAURAL_FASTCONV || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && input_config != IVAS_AUDIO_CONFIG_INVALID ) + { + n_channels = HRTF_LS_CHANNELS; + } + + if ( renderer_type == RENDERER_BINAURAL_FASTCONV ) + { + if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + { + n_channels = HOA3_CHANNELS; + } + else if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + { + n_channels = HOA2_CHANNELS; + } + else if ( input_config == IVAS_AUDIO_CONFIG_FOA ) + { + n_channels = FOA_CHANNELS; + } + } + + if ( ( error = ivas_allocate_binaural_hrtf( HrtfFastConv, n_channels, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_allocate_binaural_hrtf( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) +#endif { return error; } for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( renderer_type == RENDERER_BINAURAL_FASTCONV && HrtfFastConv->n_channels == HRTF_LS_CHANNELS ) +#else if ( renderer_type == RENDERER_BINAURAL_FASTCONV ) +#endif { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal[i][j] = leftHRIRReal[i][j]; + HrtfFastConv->leftImag[i][j] = leftHRIRImag[i][j]; + HrtfFastConv->rightReal[i][j] = rightHRIRReal[i][j]; + HrtfFastConv->rightImag[i][j] = rightHRIRImag[i][j]; +#else HrtfFastConv->leftHRIRReal[i][j] = leftHRIRReal[i][j]; HrtfFastConv->leftHRIRImag[i][j] = leftHRIRImag[i][j]; HrtfFastConv->rightHRIRReal[i][j] = rightHRIRReal[i][j]; HrtfFastConv->rightHRIRImag[i][j] = rightHRIRImag[i][j]; +#endif } } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + else if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && HrtfFastConv->n_channels == HRTF_LS_CHANNELS ) +#else else if ( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) +#endif { for ( j = 0; j < HRTF_LS_CHANNELS; j++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal[i][j] = leftBRIRReal[i][j]; + HrtfFastConv->leftImag[i][j] = leftBRIRImag[i][j]; + HrtfFastConv->rightReal[i][j] = rightBRIRReal[i][j]; + HrtfFastConv->rightImag[i][j] = rightBRIRImag[i][j]; +#else HrtfFastConv->leftBRIRReal[i][j] = leftBRIRReal[i][j]; HrtfFastConv->leftBRIRImag[i][j] = leftBRIRImag[i][j]; HrtfFastConv->rightBRIRReal[i][j] = rightBRIRReal[i][j]; HrtfFastConv->rightBRIRImag[i][j] = rightBRIRImag[i][j]; +#endif } } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( input_config == IVAS_AUDIO_CONFIG_HOA3 && HrtfFastConv->n_channels == HOA3_CHANNELS ) +#else if ( input_config == IVAS_AUDIO_CONFIG_HOA3 ) +#endif { for ( j = 0; j < HOA3_CHANNELS; j++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal[i][j] = leftHRIRReal_HOA3[i][j]; + HrtfFastConv->leftImag[i][j] = leftHRIRImag_HOA3[i][j]; + HrtfFastConv->rightReal[i][j] = rightHRIRReal_HOA3[i][j]; + HrtfFastConv->rightImag[i][j] = rightHRIRImag_HOA3[i][j]; +#else HrtfFastConv->leftHRIRReal_HOA3[i][j] = leftHRIRReal_HOA3[i][j]; HrtfFastConv->leftHRIRImag_HOA3[i][j] = leftHRIRImag_HOA3[i][j]; HrtfFastConv->rightHRIRReal_HOA3[i][j] = rightHRIRReal_HOA3[i][j]; HrtfFastConv->rightHRIRImag_HOA3[i][j] = rightHRIRImag_HOA3[i][j]; +#endif } } + +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + /* Note: IVAS_AUDIO_CONFIG_HOA2 and IVAS_AUDIO_CONFIG_FOA input configs. are not relevant in internal renderer + as SBA to binaural always synthesizes HOA3 output for binauralization. However, the external renderer can use them. */ +#endif +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( input_config == IVAS_AUDIO_CONFIG_HOA2 && HrtfFastConv->n_channels == HOA2_CHANNELS ) +#else if ( input_config == IVAS_AUDIO_CONFIG_HOA2 ) +#endif { for ( j = 0; j < HOA2_CHANNELS; j++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal[i][j] = leftHRIRReal_HOA2[i][j]; + HrtfFastConv->leftImag[i][j] = leftHRIRImag_HOA2[i][j]; + HrtfFastConv->rightReal[i][j] = rightHRIRReal_HOA2[i][j]; + HrtfFastConv->rightImag[i][j] = rightHRIRImag_HOA2[i][j]; +#else HrtfFastConv->leftHRIRReal_HOA2[i][j] = leftHRIRReal_HOA2[i][j]; HrtfFastConv->leftHRIRImag_HOA2[i][j] = leftHRIRImag_HOA2[i][j]; HrtfFastConv->rightHRIRReal_HOA2[i][j] = rightHRIRReal_HOA2[i][j]; HrtfFastConv->rightHRIRImag_HOA2[i][j] = rightHRIRImag_HOA2[i][j]; +#endif } } + +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( input_config == IVAS_AUDIO_CONFIG_FOA && HrtfFastConv->n_channels == FOA_CHANNELS ) +#else if ( input_config == IVAS_AUDIO_CONFIG_FOA ) +#endif { for ( j = 0; j < FOA_CHANNELS; j++ ) { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + HrtfFastConv->leftReal[i][j] = leftHRIRReal_FOA[i][j]; + HrtfFastConv->leftImag[i][j] = leftHRIRImag_FOA[i][j]; + HrtfFastConv->rightReal[i][j] = rightHRIRReal_FOA[i][j]; + HrtfFastConv->rightImag[i][j] = rightHRIRImag_FOA[i][j]; +#else HrtfFastConv->leftHRIRReal_FOA[i][j] = leftHRIRReal_FOA[i][j]; HrtfFastConv->leftHRIRImag_FOA[i][j] = leftHRIRImag_FOA[i][j]; HrtfFastConv->rightHRIRReal_FOA[i][j] = rightHRIRReal_FOA[i][j]; HrtfFastConv->rightHRIRImag_FOA[i][j] = rightHRIRImag_FOA[i][j]; +#endif } } } @@ -1036,6 +1212,9 @@ ivas_error ivas_rend_openCldfbRend( return error; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + pCldfbRend->binaural_latency_ns = (int32_t) ( pCldfbRend->hHrtfFastConv->FASTCONV_latency_s * 1000000000.f ); +#else if ( inConfig == IVAS_AUDIO_CONFIG_FOA ) { pCldfbRend->binaural_latency_ns = (int32_t) ( pCldfbRend->hHrtfFastConv->FASTCONV_FOA_latency_s * 1000000000.f ); @@ -1053,6 +1232,8 @@ ivas_error ivas_rend_openCldfbRend( /* should never happen for SBA */ return IVAS_ERR_INVALID_OUTPUT_FORMAT; } +#endif + hBinRenderer->hReverb = NULL; hBinRenderer->hEFAPdata = NULL; @@ -1174,7 +1355,11 @@ ivas_error ivas_binRenderer_open( } hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_latency_s * 1000000000.f ); +#else st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f ); +#endif } else { @@ -1184,6 +1369,9 @@ ivas_error ivas_binRenderer_open( return error; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_latency_s * 1000000000.f ); +#else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { if ( hBinRenderer->ivas_format == MC_FORMAT ) @@ -1215,6 +1403,7 @@ ivas_error ivas_binRenderer_open( /* same value for MC or HOA both use MC BRIR*/ st_ivas->binaural_latency_ns = (int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f ); } +#endif } /* Allocate memories needed for reverb module */ @@ -1436,6 +1625,9 @@ void ivas_binaural_hrtf_close( ) { int16_t allocate_init_flag; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + int16_t n_channels; +#endif if ( hHrtfFastConv == NULL || *hHrtfFastConv == NULL ) { @@ -1443,6 +1635,14 @@ void ivas_binaural_hrtf_close( } allocate_init_flag = ( *hHrtfFastConv )->allocate_init_flag; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + n_channels = ( *hHrtfFastConv )->n_channels; + + ivas_free_pppHrtfMem( &( *hHrtfFastConv )->leftReal, n_channels, allocate_init_flag ); + ivas_free_pppHrtfMem( &( *hHrtfFastConv )->leftImag, n_channels, allocate_init_flag ); + ivas_free_pppHrtfMem( &( *hHrtfFastConv )->rightReal, n_channels, allocate_init_flag ); + ivas_free_pppHrtfMem( &( *hHrtfFastConv )->rightImag, n_channels, allocate_init_flag ); +#else ivas_free_pppHrtfMem( &( *hHrtfFastConv )->leftHRIRReal, HRTF_LS_CHANNELS, allocate_init_flag ); ivas_free_pppHrtfMem( &( *hHrtfFastConv )->leftHRIRImag, HRTF_LS_CHANNELS, allocate_init_flag ); @@ -1468,6 +1668,7 @@ void ivas_binaural_hrtf_close( ivas_free_pppHrtfMem( &( *hHrtfFastConv )->leftHRIRImag_FOA, FOA_CHANNELS, allocate_init_flag ); ivas_free_pppHrtfMem( &( *hHrtfFastConv )->rightHRIRReal_FOA, FOA_CHANNELS, allocate_init_flag ); ivas_free_pppHrtfMem( &( *hHrtfFastConv )->rightHRIRImag_FOA, FOA_CHANNELS, allocate_init_flag ); +#endif return; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 1a5b990930213313765915fbc096734ac1638a0b..baa70ce54afcf5d7047ff543c09f9c1f1e17178e 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -906,11 +906,15 @@ 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 */ - 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_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 */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + IVAS_AUDIO_CONFIG *hrtf_set_audio_cfg /* o : HRTF set audio config. */ +#else + int16_t *room_reverb_flag, /* o : room reverb flag */ + IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ +#endif ) { ivas_error error; @@ -919,7 +923,11 @@ ivas_error IVAS_DEC_ReadFormat( ISM_MODE ism_mode_old; MC_MODE mc_mode_old; int16_t nchan_transport_old; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + AUDIO_CONFIG intern_config_old, transport_config_old, output_config; +#else AUDIO_CONFIG intern_config_old, transport_config_old; +#endif RENDERER_TYPE renderer_type_old; if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) @@ -936,6 +944,11 @@ ivas_error IVAS_DEC_ReadFormat( transport_config_old = st_ivas->transport_config; renderer_type_old = st_ivas->renderer_type; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + output_config = st_ivas->hDecoderConfig->output_config; + +#endif + if ( st_ivas->ivas_format == MONO_FORMAT ) { return IVAS_ERR_OK; @@ -966,16 +979,18 @@ ivas_error IVAS_DEC_ReadFormat( break; case RENDERER_BINAURAL_FASTCONV: *binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; - +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { *room_reverb_flag = 1; } - +#endif break; case RENDERER_BINAURAL_FASTCONV_ROOM: *binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM *room_reverb_flag = 1; +#endif break; case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: @@ -987,12 +1002,46 @@ ivas_error IVAS_DEC_ReadFormat( } *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_NONE; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && output_config == IVAS_AUDIO_CONFIG_BINAURAL ) +#else 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 ) +#endif { *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_TDREND; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_INVALID; + if ( *binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV ) + { + if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + /* SHD HRIRs */ + *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_HOA3; + + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + { + /* BRIRs */ + *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4; + } + } + else if ( st_ivas->ivas_format == MC_FORMAT ) + { + /* HRIRs */ + *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4; + + if ( ( st_ivas->hDecoderConfig->Opt_Headrotation ) && + !( st_ivas->mc_mode == MC_MODE_PARAMUPMIX && output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) + { + /* SHD HRIRs for low complexity rotation */ + *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_HOA3; + } + } + } +#else *intern_audio_config = st_ivas->intern_config; +#endif 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 ) ) @@ -1042,7 +1091,7 @@ 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. */ + Otherwise, we directly decode the first frame in any case. */ if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) { uint16_t l_ts, nTimeScalerOutSamples; diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index 666a08bdb2a02ed95c8142d8ec67a4818566e048..48794851a8ffc585af9f9b11a7d9120677a81925 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -157,8 +157,12 @@ 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 */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + IVAS_AUDIO_CONFIG *hrtf_set_audio_cfg /* o : HRTF set audio config. */ +#else int16_t *room_reverb_flag, /* o : room reverb flag */ IVAS_AUDIO_CONFIG *intern_audio_config /* o : internal audio configuration */ +#endif ); /*! r: decoder error code */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index f1d777699c83a970215f125106add0b5ba8d14d0..f24ff2ca3fef3645dd8ca245c89225ee5a2330b5 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1257,6 +1257,14 @@ typedef struct ivas_hrtfs_crend_structure /* Fastconv binaural data structure */ typedef struct ivas_hrtfs_fastconv_struct { +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + float FASTCONV_latency_s; + float ***leftReal; + float ***leftImag; + float ***rightReal; + float ***rightImag; + int16_t n_channels; +#else float FASTCONV_HOA3_latency_s; float ***leftHRIRReal_HOA3; float ***leftHRIRImag_HOA3; @@ -1286,13 +1294,18 @@ typedef struct ivas_hrtfs_fastconv_struct float ***rightHRIRReal_FOA; float ***rightHRIRImag_FOA; float FASTCONV_FOA_latency_s; +#endif int16_t allocate_init_flag; /*Memory allocation flag 0: if the hrtf pointers are allocated at application level , 1: of allocated at ivas_binaural_hrtf_open() */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + uint16_t ntaps; +#else uint16_t ntaps_hrir; uint16_t ntaps_hrir_hoa3; uint16_t ntaps_hrir_hoa2; uint16_t ntaps_hrir_foa; uint16_t ntaps_brir; +#endif float fastconvReverberationTimes[CLDFB_NO_CHANNELS_MAX]; float fastconvReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX]; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 3c19a8c268c7d9989d949439a6db267fabae6c66..7cb6c6725759d047230dc50d295e66410914e0df 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7652,6 +7652,9 @@ void IVAS_REND_Close( for ( i = 0; i < RENDERER_MAX_SBA_INPUTS; ++i ) { clearInputSba( &hIvasRend->inputsSba[i] ); +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + hIvasRend->hHrtfs.hHrtfFastConv = NULL; +#endif } for ( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 5979e0a251178c6ac33681f2a48b0511b1ce58d0..f8816b75e9c0506bc092df544433bff01a0d2b81 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -56,6 +56,19 @@ typedef struct ivas_hrtfs_file_header_t } ivas_hrtfs_file_header_t; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM +typedef enum +{ + BINAURAL_INPUT_AUDIO_CONFIG_INVALID, + BINAURAL_INPUT_AUDIO_CONFIG_COMBINED, /* 5_1, 5_1_2, 5_1_4, 7_1, 7_1_4 */ + BINAURAL_INPUT_AUDIO_CONFIG_HOA3, /* HOA3 */ + BINAURAL_INPUT_AUDIO_CONFIG_HOA2, /* HOA2 */ + BINAURAL_INPUT_AUDIO_CONFIG_FOA, /* FOA */ + BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED /* Not used */ + +} BINAURAL_INPUT_AUDIO_CONFIG; + +#endif /*---------------------------------------------------------------------* * hrtfFileReader_open() @@ -238,6 +251,43 @@ static ivas_error read_hrtf_binary_header( return IVAS_ERR_END_OF_FILE; } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + +/*-------------------------------------------------------------------* + * audio_cfg_2_binaural_cfg() + * + * Convert audio config. to HRTF binaural config + --------------------------------------------------------------------*/ + +static BINAURAL_INPUT_AUDIO_CONFIG audio_cfg_2_binaural_cfg( + const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg ) +{ + BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; + + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_UNDEFINED; + + switch ( hrtf_set_audio_cfg ) + { + case IVAS_AUDIO_CONFIG_7_1_4: + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_COMBINED; + break; + case IVAS_AUDIO_CONFIG_FOA: + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_FOA; + break; + case IVAS_AUDIO_CONFIG_HOA2: + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_HOA2; + break; + case IVAS_AUDIO_CONFIG_HOA3: + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_HOA3; + break; + default: + hrtf_set_binaural_cfg = BINAURAL_INPUT_AUDIO_CONFIG_INVALID; + break; + } + + return hrtf_set_binaural_cfg; +} +#endif /*-------------------------------------------------------------------* * LoadBSplineBinaryITD() @@ -1324,10 +1374,10 @@ static ivas_error create_HRTF_from_rawdata( *---------------------------------------------------------------------*/ static ivas_error create_fastconv_HRTF_from_rawdata( - HRTFS_FASTCONV_HANDLE *hHRTF, /* i/o: HRTF FastConv handle */ - char *hrtf_data, /* i : pointer to binary file */ - HRTF_READER_RENDERER_TYPE rend_type, /* i : Renderer type */ - BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i : Input binaural config */ + HRTFS_FASTCONV_HANDLE *hHRTF, /* i/o: HRTF FastConv handle */ + char *hrtf_data, /* i : pointer to binary file */ + HRTF_READER_RENDERER_TYPE rend_type, /* i : Renderer type */ + const BINAURAL_INPUT_AUDIO_CONFIG input_cfg /* i : Input binaural config */ ) { int16_t i, j, k; @@ -1369,14 +1419,23 @@ static ivas_error create_fastconv_HRTF_from_rawdata( ntaps = *( (uint16_t *) ( hrtf_data_rptr ) ); hrtf_data_rptr += sizeof( uint16_t ); +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + ( *hHRTF )->ntaps = ntaps; + ( *hHRTF )->FASTCONV_latency_s = latency_s; + + ( *hHRTF )->n_channels = nbchan; +#endif + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { if ( HRTF_LS_CHANNELS != nbchan ) { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); } +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM ( *hHRTF )->ntaps_hrir = ntaps; ( *hHRTF )->FASTCONV_HRIR_latency_s = latency_s; +#endif } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) { @@ -1384,8 +1443,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA3_CHANNELS)" ); } +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM ( *hHRTF )->ntaps_hrir_hoa3 = ntaps; ( *hHRTF )->FASTCONV_HOA3_latency_s = latency_s; +#endif } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) { @@ -1393,8 +1454,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HOA2_CHANNELS)" ); } +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM ( *hHRTF )->ntaps_hrir_hoa2 = ntaps; ( *hHRTF )->FASTCONV_HOA2_latency_s = latency_s; +#endif } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) { @@ -1402,8 +1465,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (FOA_CHANNELS)" ); } +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM ( *hHRTF )->ntaps_hrir_foa = ntaps; ( *hHRTF )->FASTCONV_FOA_latency_s = latency_s; +#endif } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { @@ -1411,8 +1476,10 @@ static ivas_error create_fastconv_HRTF_from_rawdata( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "HRTF binary file not compliant (HRTF_LS_CHANNELS)" ); } +#ifndef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM ( *hHRTF )->ntaps_brir = ntaps; ( *hHRTF )->FASTCONV_BRIR_latency_s = latency_s; +#endif } else { @@ -1421,14 +1488,22 @@ static ivas_error create_fastconv_HRTF_from_rawdata( if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV ) { - if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, nbchan, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, IVAS_AUDIO_CONFIG_INVALID, input_cfg, RENDERER_BINAURAL_FASTCONV, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#endif { return error; } } else if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM ) { - if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, 0, input_cfg, RENDERER_BINAURAL_FASTCONV_ROOM, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, nbchan, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#else + if ( ( error = ivas_allocate_binaural_hrtf( *hHRTF, IVAS_AUDIO_CONFIG_INVALID, input_cfg, RENDERER_BINAURAL_FASTCONV_ROOM, ( *hHRTF )->allocate_init_flag ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1438,6 +1513,65 @@ static ivas_error create_fastconv_HRTF_from_rawdata( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "renderer type not compliant" ); } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + /* HRIR/BRIR Q factor*/ + factorQ = *( (Word16 *) ( hrtf_data_rptr ) ); + hrtf_data_rptr += sizeof( Word16 ); + scaleFactor = powf( 2.f, -1.f * factorQ ); + + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < nbchan; j++ ) + { + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ntaps; k++ ) + { + ( *hHRTF )->leftReal[i][j][k] = ptW16[k] * scaleFactor; + } + hrtf_data_rptr += ntaps * sizeof( Word16 ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < nbchan; j++ ) + { + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ntaps; k++ ) + { + ( *hHRTF )->leftImag[i][j][k] = ptW16[k] * scaleFactor; + } + hrtf_data_rptr += ntaps * sizeof( Word16 ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < nbchan; j++ ) + { + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ntaps; k++ ) + { + ( *hHRTF )->rightReal[i][j][k] = ptW16[k] * scaleFactor; + } + hrtf_data_rptr += ntaps * sizeof( Word16 ); + } + } + for ( i = 0; i < BINAURAL_CONVBANDS; i++ ) + { + for ( j = 0; j < nbchan; j++ ) + { + ptW16 = (Word16 *) hrtf_data_rptr; + for ( k = 0; k < ntaps; k++ ) + { + ( *hHRTF )->rightImag[i][j][k] = ptW16[k] * scaleFactor; + } + hrtf_data_rptr += ntaps * sizeof( Word16 ); + } + } + + /* BRIR */ + if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + { +#else /* HRIR */ if ( rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && input_cfg == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) { @@ -1724,6 +1858,7 @@ static ivas_error create_fastconv_HRTF_from_rawdata( hrtf_data_rptr += ( *hHRTF )->ntaps_brir * sizeof( Word16 ); } } +#endif /* Reverb Parameters */ if ( CLDFB_NO_CHANNELS_MAX != *( (uint16_t *) ( hrtf_data_rptr ) ) ) @@ -1887,9 +2022,14 @@ 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_1226_FASTCONV_HRTF_LOADING_OPTIM + const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ + const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ +#else const int16_t room_reverb_flag, /* i : room reverb flag */ const IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ +#endif + const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ ) { FILE *f_hrtf; @@ -1900,6 +2040,13 @@ ivas_error load_fastconv_HRTF_from_binary( ivas_hrtfs_file_header_t hrtfs_file_header; int16_t hrtf_id; int16_t asFastconv = 0; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + bool load = false; + BINAURAL_INPUT_AUDIO_CONFIG hrtf_set_binaural_cfg; + + /* convert audio config. to HRTF binaural config */ + hrtf_set_binaural_cfg = audio_cfg_2_binaural_cfg( hrtf_set_audio_cfg ); +#endif if ( hrtfReader == NULL || hrtfReader->file == NULL ) { @@ -1937,6 +2084,18 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "HRTF binary file not compliant (number of HRTF)" ); } +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + if ( ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && /* HRIRs */ + ( OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL || OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) || + ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV_ROOM && /* BRIRs */ + OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || + ( hrtf_header.rend_type == HRTF_READER_RENDERER_BINAURAL_FASTCONV && ( OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || OutputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) ) + { + load = ( (BINAURAL_INPUT_AUDIO_CONFIG) hrtf_header.input_cfg == hrtf_set_binaural_cfg ) ? true : false; + } + + if ( load ) +#else 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 ) || @@ -1944,6 +2103,7 @@ ivas_error load_fastconv_HRTF_from_binary( ( 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 ) ) +#endif { if ( fread( hrtf_data, 1, hrtf_header.data_size, f_hrtf ) != hrtf_header.data_size ) { @@ -1957,6 +2117,9 @@ ivas_error load_fastconv_HRTF_from_binary( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Could not create FastConv HRTF from binary file" ); } asFastconv = 1; +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + break; /* read just one set */ +#endif } else { diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index b98cbbd03ae50f1b15b127d2db139f324e1e89cd..c8507f49005b21aa60d11646954ccb2776b5d9ca 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -132,9 +132,14 @@ void destroy_SetOfHRTF( ivas_error load_fastconv_HRTF_from_binary( IVAS_DEC_HRTF_FASTCONV_HANDLE hHrtfFastConv, /* i/o: FastConv HRTF handle */ - const int16_t room_reverb_flag, /* i : room reverb flag */ - IVAS_AUDIO_CONFIG intern_audio_config, /* i : internal audio configuration */ - const hrtfFileReader *hrtfReader /* i : pointer to hrtfFileReader handle */ +#ifdef FIX_1226_FASTCONV_HRTF_LOADING_OPTIM + const IVAS_AUDIO_CONFIG OutputConfig, /* i : output audio configuration */ + const IVAS_AUDIO_CONFIG hrtf_set_audio_cfg, /* i : HRTF set audio config. */ +#else + 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 */ ); /*---------------------------------------------------------------------*