Loading lib_isar/lib_isar_pre_rend.c 0 → 100644 +439 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ #include <stdint.h> #include "options.h" #include <math.h> #include "ivas_prot.h" #include "prot.h" #include "ivas_cnst.h" #include "isar_rom_post_rend.h" #include "lib_isar_pre_rend.h" #include "isar_prot.h" #ifdef DEBUGGING #include "debug.h" #endif #include "wmc_auto.h" #ifndef SPLIT_REND_WITH_HEAD_ROT int isar_pre_void_func( void ) { return 0; } #else /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local types *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ /*------------------------------------------------------------------------- * Function isar_pre_rend_open() * * *------------------------------------------------------------------------*/ ivas_error isar_pre_rend_open( SPLIT_REND_WRAPPER *hSplitRendWrapper, ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, const int32_t OutSampleRate, const int16_t cldfb_in_flag, const int16_t pcm_out_flag, const int16_t num_subframes, const int16_t mixed_td_cldfb_flag ) { ivas_error error, ch, num_ch; uint8_t isCldfbNeeded = 0; int16_t cldfb_in_flag_local = cldfb_in_flag; if ( ( error = isar_split_rend_choose_default_codec( &( pSplitRendConfig->codec ), &pSplitRendConfig->codec_frame_size_ms, cldfb_in_flag_local, pcm_out_flag, (int16_t) num_subframes ) ) != IVAS_ERR_OK ) { return error; } if ( mixed_td_cldfb_flag ) { cldfb_in_flag_local = 0; } if ( ( error = isar_split_rend_validate_config( pSplitRendConfig, pcm_out_flag ) ) != IVAS_ERR_OK ) { return error; } if ( cldfb_in_flag_local == 0 ) { isCldfbNeeded = 1; } else if ( pSplitRendConfig->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS && cldfb_in_flag_local ) { isCldfbNeeded = 1; } else if ( pcm_out_flag && cldfb_in_flag_local ) { isCldfbNeeded = 1; } hSplitRendWrapper->hCldfbHandles = NULL; if ( isCldfbNeeded ) { if ( ( hSplitRendWrapper->hCldfbHandles = (CLDFB_HANDLES_WRAPPER_HANDLE) malloc( sizeof( CLDFB_HANDLES_WRAPPER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB handles\n" ) ); } num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL; } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL; } num_ch = hSplitRendWrapper->multiBinPoseData.num_poses * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { if ( ( error = openCldfb( &( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ), CLDFB_ANALYSIS, OutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { if ( ( error = openCldfb( &( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ), CLDFB_SYNTHESIS, OutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } if ( pSplitRendConfig->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { if ( ( error = isar_splitBinPreRendOpen( &hSplitRendWrapper->hBinHrSplitPreRend, &hSplitRendWrapper->multiBinPoseData #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG , OutSampleRate #endif ) ) != IVAS_ERR_OK ) { return error; } } if ( pcm_out_flag == 0 ) { if ( pSplitRendConfig->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) { if ( ( error = split_renderer_open_lc3plus( hSplitRendWrapper, pSplitRendConfig, OutSampleRate, num_subframes ) ) != IVAS_ERR_OK ) { return error; } } else { int16_t iNumBlocksPerFrame; iNumBlocksPerFrame = ( CLDFB_NO_COL_MAX * pSplitRendConfig->codec_frame_size_ms ) / 20; if ( ( error = isar_splitBinLCLDEncOpen( &hSplitRendWrapper->hSplitBinLCLDEnc, OutSampleRate, BINAURAL_CHANNELS, isar_get_lcld_bitrate( pSplitRendConfig->splitRendBitRate, hSplitRendWrapper->multiBinPoseData.poseCorrectionMode ), iNumBlocksPerFrame, 1 ) ) != IVAS_ERR_OK ) { return error; } } } return IVAS_ERR_OK; } /*------------------------------------------------------------------------- * Function isar_pre_rend_close() * * *------------------------------------------------------------------------*/ void isar_pre_rend_close( SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_REND_AudioBuffer *pSplitRendEncBuffer ) { int16_t i; if ( hSplitBinRend->hBinHrSplitPreRend != NULL ) { ivas_splitBinPreRendClose( &hSplitBinRend->hBinHrSplitPreRend ); } if ( hSplitBinRend->hSplitBinLCLDEnc != NULL ) { isar_splitBinLCLDEncClose( &hSplitBinRend->hSplitBinLCLDEnc ); } if ( hSplitBinRend->hCldfbHandles != NULL ) { int16_t num_ch, ch; num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { if ( hSplitBinRend->hCldfbHandles->cldfbAna[ch] != NULL ) { deleteCldfb( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); hSplitBinRend->hCldfbHandles->cldfbAna[ch] = NULL; } } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { if ( hSplitBinRend->hCldfbHandles->cldfbSyn[ch] != NULL ) { deleteCldfb( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); hSplitBinRend->hCldfbHandles->cldfbSyn[ch] = NULL; } } free( hSplitBinRend->hCldfbHandles ); hSplitBinRend->hCldfbHandles = NULL; } if ( hSplitBinRend->hLc3plusEnc != NULL ) { IVAS_LC3PLUS_ENC_Close( &hSplitBinRend->hLc3plusEnc ); } for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { if ( hSplitBinRend->lc3plusDelayBuffers[i] != NULL ) { free( hSplitBinRend->lc3plusDelayBuffers[i] ); hSplitBinRend->lc3plusDelayBuffers[i] = NULL; } } if ( pSplitRendEncBuffer != NULL ) { if ( pSplitRendEncBuffer->data != NULL ) { free( pSplitRendEncBuffer->data ); pSplitRendEncBuffer->data = NULL; } pSplitRendEncBuffer->config.numChannels = 0; pSplitRendEncBuffer->config.numSamplesPerChannel = 0; } return; } /*-------------------------------------------------------------------------* * isar_pre_rend_GetMultiBinPoseData() * * *-------------------------------------------------------------------------*/ void isar_pre_rend_GetMultiBinPoseData( const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, const ISAR_SPLIT_REND_ROT_AXIS rot_axis ) { isar_renderSplitGetMultiBinPoseData( pSplit_rend_config, pMultiBinPoseData, rot_axis ); } /*------------------------------------------------------------------------- * Function isar_pre_rend_MultiBinToSplitBinaural() * * *------------------------------------------------------------------------*/ ivas_error isar_pre_rend_MultiBinToSplitBinaural( SPLIT_REND_WRAPPER *hSplitBin, const IVAS_QUATERNION headPosition, const int32_t SplitRendBitRate, ISAR_SPLIT_REND_CODEC splitCodec, int16_t codec_frame_size_ms, ISAR_SPLIT_REND_BITS_HANDLE pBits, float Cldfb_In_BinReal[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_In_BinImag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], const int16_t max_bands, float *output[], const int16_t low_res_pre_rend_rot, const int16_t cldfb_in_flag, const int16_t pcm_out_flag, const int16_t ro_md_flag ) { ivas_error error; int32_t bit_len, target_md_bits, actual_md_bits, available_bits; error = IVAS_ERR_OK; push_wmops( "isar_pre_rend_MultiBinToSplitBinaural" ); if ( hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { set_fix_rotation_mat( hSplitBin->hBinHrSplitPreRend->fix_pos_rot_mat, &hSplitBin->multiBinPoseData ); set_pose_types( hSplitBin->hBinHrSplitPreRend->pose_type, &hSplitBin->multiBinPoseData ); } if ( cldfb_in_flag == 0 ) { /*TD input*/ /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/ error = ivas_renderMultiTDBinToSplitBinaural( hSplitBin, headPosition, SplitRendBitRate, codec_frame_size_ms, pBits, max_bands, output, low_res_pre_rend_rot, pcm_out_flag, ro_md_flag ); pop_wmops(); return error; } if ( splitCodec == ISAR_SPLIT_REND_CODEC_LC3PLUS && hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { /* Time-align pose correction to delay of LC3plus */ lc3plusTimeAlignCldfbPoseCorr( hSplitBin, Cldfb_In_BinReal, Cldfb_In_BinImag ); } actual_md_bits = pBits->bits_written; if ( hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { target_md_bits = isar_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out_flag ) * L_FRAME48k / 48000; actual_md_bits = pBits->bits_written; isar_rend_CldfbSplitPreRendProcess( hSplitBin->hBinHrSplitPreRend, headPosition, &hSplitBin->multiBinPoseData, Cldfb_In_BinReal, Cldfb_In_BinImag, pBits, target_md_bits, low_res_pre_rend_rot, ro_md_flag ); } if ( pcm_out_flag == 0 ) { pBits->codec = splitCodec; pBits->pose_correction = hSplitBin->multiBinPoseData.poseCorrectionMode; if ( splitCodec == ISAR_SPLIT_REND_CODEC_LCLD ) { available_bits = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); actual_md_bits = pBits->bits_written - actual_md_bits; available_bits -= actual_md_bits; pBits->codec_frame_size_ms = codec_frame_size_ms; isar_splitBinLCLDEncProcess( hSplitBin->hSplitBinLCLDEnc, Cldfb_In_BinReal, Cldfb_In_BinImag, available_bits, pBits ); } else { int16_t ch, slot_idx, num_slots, ivas_fs; ivas_fs = (int16_t) hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; num_slots = (int16_t) ( CLDFB_NO_COL_MAX * ivas_fs ) / 20; /* CLDFB synthesis of main pose */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { float *Cldfb_In_BinReal_p[CLDFB_NO_COL_MAX]; float *Cldfb_In_BinImag_p[CLDFB_NO_COL_MAX]; for ( slot_idx = 0; slot_idx < num_slots; slot_idx++ ) { Cldfb_In_BinReal_p[slot_idx] = Cldfb_In_BinReal[ch][slot_idx]; Cldfb_In_BinImag_p[slot_idx] = Cldfb_In_BinImag[ch][slot_idx]; } cldfbSynthesis( Cldfb_In_BinReal_p, Cldfb_In_BinImag_p, output[ch], hSplitBin->hCldfbHandles->cldfbSyn[0]->no_channels * num_slots, hSplitBin->hCldfbHandles->cldfbSyn[ch] ); } if ( ( error = splitRendLc3plusEncodeAndWrite( hSplitBin, pBits, SplitRendBitRate, output ) ) != IVAS_ERR_OK ) { return error; } } } else { int16_t ch, slot_idx; /* CLDFB synthesis of main pose */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { float *Cldfb_In_BinReal_p[CLDFB_NO_COL_MAX]; float *Cldfb_In_BinImag_p[CLDFB_NO_COL_MAX]; for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ ) { Cldfb_In_BinReal_p[slot_idx] = Cldfb_In_BinReal[ch][slot_idx]; Cldfb_In_BinImag_p[slot_idx] = Cldfb_In_BinImag[ch][slot_idx]; } cldfbSynthesis( Cldfb_In_BinReal_p, Cldfb_In_BinImag_p, output[ch], hSplitBin->hCldfbHandles->cldfbSyn[0]->no_channels * CLDFB_NO_COL_MAX, hSplitBin->hCldfbHandles->cldfbSyn[ch] ); } pBits->pose_correction = hSplitBin->multiBinPoseData.poseCorrectionMode; pBits->codec = ISAR_SPLIT_REND_CODEC_NONE; } /*zero pad*/ if ( pcm_out_flag ) { bit_len = SplitRendBitRate / FRAMES_PER_SEC; } else { if ( splitCodec == ISAR_SPLIT_REND_CODEC_LCLD ) { bit_len = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); } else { bit_len = hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; bit_len = SplitRendBitRate * bit_len / 1000; } } while ( pBits->bits_written < bit_len ) { ISAR_SPLIT_REND_BITStream_write_int32( pBits, 0L, 1 ); } pop_wmops(); return error; } #endif Loading
lib_isar/lib_isar_pre_rend.c 0 → 100644 +439 −0 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ #include <stdint.h> #include "options.h" #include <math.h> #include "ivas_prot.h" #include "prot.h" #include "ivas_cnst.h" #include "isar_rom_post_rend.h" #include "lib_isar_pre_rend.h" #include "isar_prot.h" #ifdef DEBUGGING #include "debug.h" #endif #include "wmc_auto.h" #ifndef SPLIT_REND_WITH_HEAD_ROT int isar_pre_void_func( void ) { return 0; } #else /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local types *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ /*------------------------------------------------------------------------- * Function isar_pre_rend_open() * * *------------------------------------------------------------------------*/ ivas_error isar_pre_rend_open( SPLIT_REND_WRAPPER *hSplitRendWrapper, ISAR_SPLIT_REND_CONFIG_DATA *pSplitRendConfig, const int32_t OutSampleRate, const int16_t cldfb_in_flag, const int16_t pcm_out_flag, const int16_t num_subframes, const int16_t mixed_td_cldfb_flag ) { ivas_error error, ch, num_ch; uint8_t isCldfbNeeded = 0; int16_t cldfb_in_flag_local = cldfb_in_flag; if ( ( error = isar_split_rend_choose_default_codec( &( pSplitRendConfig->codec ), &pSplitRendConfig->codec_frame_size_ms, cldfb_in_flag_local, pcm_out_flag, (int16_t) num_subframes ) ) != IVAS_ERR_OK ) { return error; } if ( mixed_td_cldfb_flag ) { cldfb_in_flag_local = 0; } if ( ( error = isar_split_rend_validate_config( pSplitRendConfig, pcm_out_flag ) ) != IVAS_ERR_OK ) { return error; } if ( cldfb_in_flag_local == 0 ) { isCldfbNeeded = 1; } else if ( pSplitRendConfig->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS && cldfb_in_flag_local ) { isCldfbNeeded = 1; } else if ( pcm_out_flag && cldfb_in_flag_local ) { isCldfbNeeded = 1; } hSplitRendWrapper->hCldfbHandles = NULL; if ( isCldfbNeeded ) { if ( ( hSplitRendWrapper->hCldfbHandles = (CLDFB_HANDLES_WRAPPER_HANDLE) malloc( sizeof( CLDFB_HANDLES_WRAPPER ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB handles\n" ) ); } num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL; } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL; } num_ch = hSplitRendWrapper->multiBinPoseData.num_poses * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { if ( ( error = openCldfb( &( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ), CLDFB_ANALYSIS, OutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { if ( ( error = openCldfb( &( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ), CLDFB_SYNTHESIS, OutSampleRate, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) { return error; } } } if ( pSplitRendConfig->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { if ( ( error = isar_splitBinPreRendOpen( &hSplitRendWrapper->hBinHrSplitPreRend, &hSplitRendWrapper->multiBinPoseData #ifdef SPLIT_REND_WITH_HEAD_ROT_DEBUG , OutSampleRate #endif ) ) != IVAS_ERR_OK ) { return error; } } if ( pcm_out_flag == 0 ) { if ( pSplitRendConfig->codec == ISAR_SPLIT_REND_CODEC_LC3PLUS ) { if ( ( error = split_renderer_open_lc3plus( hSplitRendWrapper, pSplitRendConfig, OutSampleRate, num_subframes ) ) != IVAS_ERR_OK ) { return error; } } else { int16_t iNumBlocksPerFrame; iNumBlocksPerFrame = ( CLDFB_NO_COL_MAX * pSplitRendConfig->codec_frame_size_ms ) / 20; if ( ( error = isar_splitBinLCLDEncOpen( &hSplitRendWrapper->hSplitBinLCLDEnc, OutSampleRate, BINAURAL_CHANNELS, isar_get_lcld_bitrate( pSplitRendConfig->splitRendBitRate, hSplitRendWrapper->multiBinPoseData.poseCorrectionMode ), iNumBlocksPerFrame, 1 ) ) != IVAS_ERR_OK ) { return error; } } } return IVAS_ERR_OK; } /*------------------------------------------------------------------------- * Function isar_pre_rend_close() * * *------------------------------------------------------------------------*/ void isar_pre_rend_close( SPLIT_REND_WRAPPER *hSplitBinRend, IVAS_REND_AudioBuffer *pSplitRendEncBuffer ) { int16_t i; if ( hSplitBinRend->hBinHrSplitPreRend != NULL ) { ivas_splitBinPreRendClose( &hSplitBinRend->hBinHrSplitPreRend ); } if ( hSplitBinRend->hSplitBinLCLDEnc != NULL ) { isar_splitBinLCLDEncClose( &hSplitBinRend->hSplitBinLCLDEnc ); } if ( hSplitBinRend->hCldfbHandles != NULL ) { int16_t num_ch, ch; num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; for ( ch = 0; ch < num_ch; ch++ ) { if ( hSplitBinRend->hCldfbHandles->cldfbAna[ch] != NULL ) { deleteCldfb( &hSplitBinRend->hCldfbHandles->cldfbAna[ch] ); hSplitBinRend->hCldfbHandles->cldfbAna[ch] = NULL; } } for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { if ( hSplitBinRend->hCldfbHandles->cldfbSyn[ch] != NULL ) { deleteCldfb( &hSplitBinRend->hCldfbHandles->cldfbSyn[ch] ); hSplitBinRend->hCldfbHandles->cldfbSyn[ch] = NULL; } } free( hSplitBinRend->hCldfbHandles ); hSplitBinRend->hCldfbHandles = NULL; } if ( hSplitBinRend->hLc3plusEnc != NULL ) { IVAS_LC3PLUS_ENC_Close( &hSplitBinRend->hLc3plusEnc ); } for ( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i ) { if ( hSplitBinRend->lc3plusDelayBuffers[i] != NULL ) { free( hSplitBinRend->lc3plusDelayBuffers[i] ); hSplitBinRend->lc3plusDelayBuffers[i] = NULL; } } if ( pSplitRendEncBuffer != NULL ) { if ( pSplitRendEncBuffer->data != NULL ) { free( pSplitRendEncBuffer->data ); pSplitRendEncBuffer->data = NULL; } pSplitRendEncBuffer->config.numChannels = 0; pSplitRendEncBuffer->config.numSamplesPerChannel = 0; } return; } /*-------------------------------------------------------------------------* * isar_pre_rend_GetMultiBinPoseData() * * *-------------------------------------------------------------------------*/ void isar_pre_rend_GetMultiBinPoseData( const ISAR_SPLIT_REND_CONFIG_DATA *pSplit_rend_config, MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData, const ISAR_SPLIT_REND_ROT_AXIS rot_axis ) { isar_renderSplitGetMultiBinPoseData( pSplit_rend_config, pMultiBinPoseData, rot_axis ); } /*------------------------------------------------------------------------- * Function isar_pre_rend_MultiBinToSplitBinaural() * * *------------------------------------------------------------------------*/ ivas_error isar_pre_rend_MultiBinToSplitBinaural( SPLIT_REND_WRAPPER *hSplitBin, const IVAS_QUATERNION headPosition, const int32_t SplitRendBitRate, ISAR_SPLIT_REND_CODEC splitCodec, int16_t codec_frame_size_ms, ISAR_SPLIT_REND_BITS_HANDLE pBits, float Cldfb_In_BinReal[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], float Cldfb_In_BinImag[][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], const int16_t max_bands, float *output[], const int16_t low_res_pre_rend_rot, const int16_t cldfb_in_flag, const int16_t pcm_out_flag, const int16_t ro_md_flag ) { ivas_error error; int32_t bit_len, target_md_bits, actual_md_bits, available_bits; error = IVAS_ERR_OK; push_wmops( "isar_pre_rend_MultiBinToSplitBinaural" ); if ( hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { set_fix_rotation_mat( hSplitBin->hBinHrSplitPreRend->fix_pos_rot_mat, &hSplitBin->multiBinPoseData ); set_pose_types( hSplitBin->hBinHrSplitPreRend->pose_type, &hSplitBin->multiBinPoseData ); } if ( cldfb_in_flag == 0 ) { /*TD input*/ /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/ error = ivas_renderMultiTDBinToSplitBinaural( hSplitBin, headPosition, SplitRendBitRate, codec_frame_size_ms, pBits, max_bands, output, low_res_pre_rend_rot, pcm_out_flag, ro_md_flag ); pop_wmops(); return error; } if ( splitCodec == ISAR_SPLIT_REND_CODEC_LC3PLUS && hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { /* Time-align pose correction to delay of LC3plus */ lc3plusTimeAlignCldfbPoseCorr( hSplitBin, Cldfb_In_BinReal, Cldfb_In_BinImag ); } actual_md_bits = pBits->bits_written; if ( hSplitBin->multiBinPoseData.poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) { target_md_bits = isar_get_split_rend_md_target_brate( SplitRendBitRate, pcm_out_flag ) * L_FRAME48k / 48000; actual_md_bits = pBits->bits_written; isar_rend_CldfbSplitPreRendProcess( hSplitBin->hBinHrSplitPreRend, headPosition, &hSplitBin->multiBinPoseData, Cldfb_In_BinReal, Cldfb_In_BinImag, pBits, target_md_bits, low_res_pre_rend_rot, ro_md_flag ); } if ( pcm_out_flag == 0 ) { pBits->codec = splitCodec; pBits->pose_correction = hSplitBin->multiBinPoseData.poseCorrectionMode; if ( splitCodec == ISAR_SPLIT_REND_CODEC_LCLD ) { available_bits = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); actual_md_bits = pBits->bits_written - actual_md_bits; available_bits -= actual_md_bits; pBits->codec_frame_size_ms = codec_frame_size_ms; isar_splitBinLCLDEncProcess( hSplitBin->hSplitBinLCLDEnc, Cldfb_In_BinReal, Cldfb_In_BinImag, available_bits, pBits ); } else { int16_t ch, slot_idx, num_slots, ivas_fs; ivas_fs = (int16_t) hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; num_slots = (int16_t) ( CLDFB_NO_COL_MAX * ivas_fs ) / 20; /* CLDFB synthesis of main pose */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { float *Cldfb_In_BinReal_p[CLDFB_NO_COL_MAX]; float *Cldfb_In_BinImag_p[CLDFB_NO_COL_MAX]; for ( slot_idx = 0; slot_idx < num_slots; slot_idx++ ) { Cldfb_In_BinReal_p[slot_idx] = Cldfb_In_BinReal[ch][slot_idx]; Cldfb_In_BinImag_p[slot_idx] = Cldfb_In_BinImag[ch][slot_idx]; } cldfbSynthesis( Cldfb_In_BinReal_p, Cldfb_In_BinImag_p, output[ch], hSplitBin->hCldfbHandles->cldfbSyn[0]->no_channels * num_slots, hSplitBin->hCldfbHandles->cldfbSyn[ch] ); } if ( ( error = splitRendLc3plusEncodeAndWrite( hSplitBin, pBits, SplitRendBitRate, output ) ) != IVAS_ERR_OK ) { return error; } } } else { int16_t ch, slot_idx; /* CLDFB synthesis of main pose */ for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { float *Cldfb_In_BinReal_p[CLDFB_NO_COL_MAX]; float *Cldfb_In_BinImag_p[CLDFB_NO_COL_MAX]; for ( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ ) { Cldfb_In_BinReal_p[slot_idx] = Cldfb_In_BinReal[ch][slot_idx]; Cldfb_In_BinImag_p[slot_idx] = Cldfb_In_BinImag[ch][slot_idx]; } cldfbSynthesis( Cldfb_In_BinReal_p, Cldfb_In_BinImag_p, output[ch], hSplitBin->hCldfbHandles->cldfbSyn[0]->no_channels * CLDFB_NO_COL_MAX, hSplitBin->hCldfbHandles->cldfbSyn[ch] ); } pBits->pose_correction = hSplitBin->multiBinPoseData.poseCorrectionMode; pBits->codec = ISAR_SPLIT_REND_CODEC_NONE; } /*zero pad*/ if ( pcm_out_flag ) { bit_len = SplitRendBitRate / FRAMES_PER_SEC; } else { if ( splitCodec == ISAR_SPLIT_REND_CODEC_LCLD ) { bit_len = ( SplitRendBitRate * hSplitBin->hSplitBinLCLDEnc->iNumBlocks * hSplitBin->hSplitBinLCLDEnc->iNumIterations ) / ( 16 * FRAMES_PER_SEC ); } else { bit_len = hSplitBin->hLc3plusEnc->config.ivas_frame_duration_us / 1000; bit_len = SplitRendBitRate * bit_len / 1000; } } while ( pBits->bits_written < bit_len ) { ISAR_SPLIT_REND_BITStream_write_int32( pBits, 0L, 1 ); } pop_wmops(); return error; } #endif